Exemplo n.º 1
0
        /// <summary>
        /// Async open service host.
        /// </summary>
        /// <param name="num"></param>
        /// <param name="taskInfo"></param>
        /// <param name="regPath"></param>
        /// <param name="svcName"></param>
        /// <returns></returns>
        private static async Task <ServiceTaskDispatcherInfo> OpenSvcHostAsync(
            string sessionId,
            ServiceTaskDispatcherInfo taskDispatcherInfo,
            string regPath,
            string svcName,
            Version svcVersion,
            Dictionary <string, string> environment,
            Dictionary <string, string> dependFilesInfo)
        {
            var invalidList = invalidIds;

            if (invalidList.Contains(taskDispatcherInfo.TaskId))
            {
                return(null);
            }
            string fileName = SoaRegistrationAuxModule.GetRegistrationFileName(svcName, svcVersion);

            BrokerTracing.TraceVerbose("[SvcHostHttpClient] Started send request, taskId is {0} and session id is {1}", taskDispatcherInfo.TaskId, sessionId);
            // HTTP POST
            var serviceInfo = new ServiceInfo(sessionId, taskDispatcherInfo.TaskId, taskDispatcherInfo.FirstCoreId, regPath + "\\", fileName, environment, dependFilesInfo);
            var result      = await SvcHostHttpClient.PostAsJsonAsync <ServiceInfo>(new Uri($"{Prefix}{taskDispatcherInfo.MachineName}:{Port}/{EndPointName}/api/{ApiName}"), serviceInfo);

            BrokerTracing.TraceVerbose("[OpenSvcHost].result:{0}", result);
            result.EnsureSuccessStatusCode();
            return(taskDispatcherInfo);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the xml file which config the service.
        /// </summary>
        /// <param name="fileName">Service config file name</param>
        /// <returns>Return file path, or return null if the file doesn't exist.</returns>
        public string GetServiceRegistrationPath(string filename)
        {
            Trace.TraceInformation($"[{nameof(ServiceRegistrationRepo)}] {nameof(GetServiceRegistrationPath)}: Try get file {filename}");
            if (this.centralPaths != null)
            {
                foreach (string centralPath in this.centralPaths)
                {
                    try
                    {
                        if (string.IsNullOrEmpty(centralPath) || IsRegistrationStoreToken(centralPath))
                        {
                            Trace.TraceInformation($"[{nameof(ServiceRegistrationRepo)}] {nameof(GetServiceRegistrationPath)}: Get from reliable registry");
                            string path;
                            if (this.ServiceRegistrationStore != null)
                            {
                                path = this.ServiceRegistrationStore.ExportToTempFileAsync(filename, null).GetAwaiter()
                                       .GetResult();
                            }
                            else
                            {
                                Trace.TraceWarning($"[{nameof(ServiceRegistrationRepo)}] {nameof(GetServiceRegistrationPath)}: Trying to get service registration from reliable registry while no ServiceRegistrationStore instance available");
                                continue;
                            }

                            if (!string.IsNullOrEmpty(path))
                            {
                                Trace.TraceInformation($"[{nameof(ServiceRegistrationRepo)}] {nameof(GetServiceRegistrationPath)}: Found file {path}");
                                path = this.MoveFileToFacadeFolder(path);
                                return(path);
                            }
                        }
                        else
                        {
                            string path = SoaRegistrationAuxModule.GetServiceRegistrationPath(centralPath, filename);
                            if (InternalFileExits(path))
                            {
                                Trace.TraceInformation($"[{nameof(ServiceRegistrationRepo)}] {nameof(GetServiceRegistrationPath)}: Found file {path}");
                                return(path);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError($"[{nameof(ServiceRegistrationRepo)}] {nameof(GetServiceRegistrationPath)}: Exception happened when find file {filename} in path {centralPath}:{Environment.NewLine}{ex.ToString()}");
                    }
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Async open service host.
        /// </summary>
        /// <param name="num"></param>
        /// <param name="ipAddress"></param>
        /// <param name="regPath"></param>
        /// <param name="svcName"></param>
        /// <returns></returns>
        private static async Task <TaskInfo> OpenSvcHostAsync(
            string sessionId,
            int num,
            string ipAddress,
            string regPath,
            string svcName,
            Version svcVersion,
            Dictionary <string, string> environment,
            Dictionary <string, string> dependFilesInfo)
        {
            var    ti       = CreateDummyTaskInfo(num, ipAddress);
            string fileName = SoaRegistrationAuxModule.GetRegistrationFileName(svcName, svcVersion);
            // HTTP POST
            var serviceInfo = new ServiceInfo(sessionId, ti.Id, ti.FirstCoreIndex, regPath + "\\", fileName, environment, dependFilesInfo);
            var result      = await SvcHostHttpClient.PostAsJsonAsync <ServiceInfo>(new Uri($"{Prefix}{ipAddress}:{Port}/{EndPointName}/api/{ApiName}"), serviceInfo);

            BrokerTracing.TraceVerbose("[OpenSvcHost].result:{0}", result);
            result.EnsureSuccessStatusCode();
            return(ti);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get service version from specified service registration folder.
        /// </summary>
        /// <param name="serviceRegistrationDir">service registration folder</param>
        /// <param name="serviceName">service name</param>
        /// <param name="addUnversionedService">add un-versioned service or not</param>
        /// <param name="versions">service versions</param>
        /// <param name="unversionedServiceAdded">is un-versioned service added or not</param>
        private void GetVersionFromRegistrationDir(string serviceRegistrationDir, string serviceName, bool addUnversionedService, List <Version> versions, ref bool unversionedServiceAdded)
        {
            if (string.IsNullOrEmpty(serviceRegistrationDir) || SoaRegistrationAuxModule.IsRegistrationStoreToken(serviceRegistrationDir))
            {
                List <string> services = this.ServiceRegistrationStore.EnumerateAsync().GetAwaiter().GetResult();
                Trace.TraceInformation("[SessionLauncher] GetVersionFromRegistration from reliable registry.");

                // If caller asked for unversioned service and it hasn't been found yet, check for it now
                if (addUnversionedService && !unversionedServiceAdded)
                {
                    if (services.Contains(serviceName))
                    {
                        this.AddSortedVersion(versions, Constant.VersionlessServiceVersion);
                        unversionedServiceAdded = true;
                    }
                }

                foreach (string service in services)
                {
                    try
                    {
                        Version version = ParseVersion(service, serviceName);
                        if (version != null)
                        {
                            this.AddSortedVersion(versions, version);
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.TraceError($"[SessionLauncher] GetVersionFromRegistrationDir: Failed to parse service name {service}. Exception:{e}");
                        continue;
                    }
                }
            }
            else
            {
                // If caller asked for unversioned service and it hasnt been found yet, check for it now
                if (addUnversionedService && !unversionedServiceAdded)
                {
                    string configFilePath = Path.Combine(serviceRegistrationDir, Path.ChangeExtension(serviceName, ".config"));

                    if (File.Exists(configFilePath))
                    {
                        this.AddSortedVersion(versions, Constant.VersionlessServiceVersion);
                        unversionedServiceAdded = true;
                    }
                }

                string[] files = Directory.GetFiles(serviceRegistrationDir, string.Format(Constant.ServiceConfigFileNameFormat, serviceName, '*'));

                foreach (string file in files)
                {
                    try
                    {
                        Version version = ParseVersion(Path.GetFileNameWithoutExtension(file), serviceName);
                        if (version != null)
                        {
                            this.AddSortedVersion(versions, version);
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.TraceError($"[SessionLauncher] GetVersionFromRegistrationDir: Failed to parse file name {file}. Exception:{e}");
                        continue;
                    }
                }
            }
        }
Exemplo n.º 5
0
 public ServiceRegistrationInfo(string serviceRegistration)
 {
     this.ServiceRegistration = serviceRegistration;
     this.Md5 = SoaRegistrationAuxModule.CalculateMd5Hash(serviceRegistration);
 }