/// <summary> /// Loads MicroService from XML file and add it to the TaskHub /// </summary> /// <param name="configFiles">List of configuration files for services.</param> /// <returns></returns> public ICollection <MicroserviceInstance> LoadServicesFromXml(string[] configFiles, IEnumerable <Type> knownTypes, out ICollection <Microservice> microservices) { microservices = new List <Microservice>(); foreach (var filePath in configFiles) { Microservice microservice = deserializeService(filePath, knownTypes); microservices.Add(microservice); } return(LoadServices(microservices)); }
/// <summary> /// Gets the numer of running instances. /// </summary> /// <param name="microservice"></param> /// <returns>Gets the numer of running instances of the service.</returns> public int GetNumOfRunningInstances(Microservice microservice) { var byNameQuery = new OrchestrationStateQuery(); byNameQuery.AddStatusFilter(OrchestrationStatus.Running); byNameQuery.AddNameVersionFilter(microservice.Orchestration.FullName); var result = m_HubClient.QueryOrchestrationStates(byNameQuery); var cnt = result.Count(svc => svc.OrchestrationStatus == OrchestrationStatus.Running); return(cnt); }
/// <summary> /// Gets the number of running instances. /// </summary> /// <param name="microservice"></param> /// <returns>Gets the number of running instances of the service. /// If m_StorageConnectionString is not confiogured this method returns 0.</returns> public int GetNumOfRunningInstances(Microservice microservice) { if (String.IsNullOrEmpty(this.m_StorageConnectionString)) { return(0); } var byNameQuery = new OrchestrationStateQuery(); byNameQuery.AddStatusFilter(OrchestrationStatus.Running); byNameQuery.AddNameVersionFilter(microservice.Orchestration.FullName); var result = m_HubClient.QueryOrchestrationStates(byNameQuery); return(result.Count()); }
/// <summary> /// Adds the service orchestration to task hub worker. /// </summary> /// <param name="serviceConfiguraton">The configuration of the service.</param> /// <returns></returns> public ICollection <MicroserviceInstance> LoadService(Microservice serviceConfiguraton) { loadTypesFromQualifiedNames(new List <Microservice> { serviceConfiguraton }); m_TaskHubWorker.AddTaskOrchestrations(serviceConfiguraton.Orchestration); if (serviceConfiguraton.Activities != null && serviceConfiguraton.Activities.Length > 0) { m_TaskHubWorker.AddTaskActivities(serviceConfiguraton.Activities); } RegisterServiceConfiguration(serviceConfiguraton); List <MicroserviceInstance> runningInstances; bool isRunning = loadRunningInstances(serviceConfiguraton.OrchestrationQName, out runningInstances); return(runningInstances); }
/// <summary> /// Adds or updates the service configuration. /// </summary> /// <param name="service"></param> protected void RegisterServiceConfiguration(Microservice service) { lock (m_SvcConfigs) { string svcKey = getConfigKey(String.Empty, service.Orchestration); if (!m_SvcConfigs.ContainsKey(svcKey)) { var svcDict = new Dictionary <string, object>(); svcDict.Add(svcKey, service); if (service.ActivityConfiguration == null) { service.ActivityConfiguration = new Dictionary <string, object>(); } foreach (var activityConfig in service.ActivityConfiguration) { Type actTp = Type.GetType(activityConfig.Key); if (actTp == null) { throw new InvalidOperationException(String.Format("Type '{0}' of Activity (Task) cannot be loaded.", actTp.AssemblyQualifiedName)); } string actKey = getConfigKey(String.Empty, actTp); if (m_SvcConfigs.ContainsKey(actKey)) { throw new InvalidOperationException(String.Format("Activity {0} is already registered.", actKey)); } else { svcDict.Add(actKey, activityConfig.Value); } } m_SvcConfigs.Add(svcKey, svcDict); } } }
///// <summary> ///// Adds or updates the service configuration. ///// </summary> ///// <param name="activity">Type of activity (task) for which configuration is registering.</param> ///// <param name="activityConfig">The configuration of activity.</param> //protected void RegisterActivityConfiguration(Type activity, object activityConfig) //{ // lock (m_SvcConfigs) // { // if (m_SvcConfigs.ContainsKey(activity)) // { // m_SvcConfigs[activity] = activityConfig; // } // else // m_SvcConfigs.Add(activity, activityConfig); // } //} /// <summary> /// Gets the configuration of the given microservice (orchestration). /// </summary> /// <param name="serviceInstanceName">Name of the type instance. Every activity is identified by its type and its name.</param> /// <param name="typeName">Type of the activity (task).</param> /// <returns></returns> public static Microservice GetServiceConfiguration(string serviceInstanceName, Type typeName) { lock (m_SvcConfigs) { string key = getConfigKey(serviceInstanceName, typeName); if (m_SvcConfigs.ContainsKey(key)) { var dict = m_SvcConfigs[key]; Microservice svcConfig = dict[key] as Microservice; if (svcConfig == null) { throw new ArgumentException("Specified microservice (orchestration) type is not registered."); } else { return(svcConfig); } } else { throw new ArgumentException("Specified microservice (orchestration) type is not registerd."); } } }
public CompositeApplication AddService(Microservice service) { this.Services.Add(service); return(this); }
/// <summary> /// Loads MicroService from XML file and add it to the TaskHub /// </summary> /// <param name="filePath"></param> /// <returns></returns> public ICollection <MicroserviceInstance> LoadServiceFromXml(string filePath, IEnumerable <Type> knownTypes, out Microservice microservice) { microservice = deserializeService(filePath, knownTypes); return(LoadService(microservice)); }
/// <summary> /// Loads MicroService from JSON file and add it to the TaskHub /// </summary> /// <param name="filePath"></param> /// <returns></returns> public ICollection <MicroserviceInstance> LoadServiceFromJson(string filePath, out Microservice microservice) { var jsonText = File.ReadAllText(filePath); microservice = Newtonsoft.Json.JsonConvert.DeserializeObject <Microservice>(jsonText); return(LoadService(microservice)); }