Пример #1
0
        /// <summary>
        /// Loads MicroService from XML file and add it to the TaskHub
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public Microservice LoadServiceFromXml(string filePath, IEnumerable <Type> knownTypes)
        {
            Microservice microservice = deserializeService(filePath, knownTypes);

            LoadServices(new Microservice[] { microservice });

            return(microservice);
        }
Пример #2
0
        /// <summary>
        /// Adds the service orchestration to task hub worker.
        /// </summary>
        /// <param name="serviceConfiguraton">The configuration of the service.</param>
        /// <returns></returns>
        public void 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);
        }
Пример #3
0
        /// <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 List <Microservice> LoadServicesFromXml(string[] configFiles, IEnumerable <Type> knownTypes)
        {
            List <Microservice> microservices = new List <Microservice>();

            foreach (var filePath in configFiles)
            {
                Microservice microservice = deserializeService(filePath, knownTypes);
                microservices.Add(microservice);
            }

            LoadServices(microservices);

            return(microservices);
        }
Пример #4
0
        /// <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 async Task <int> GetNumOfRunningInstancesAsync(Microservice microservice)
        {
            if (m_InstanceStoreService == null)
            {
                return(-1);
            }

            //var byNameQuery = new OrchestrationStateQuery();
            //byNameQuery.AddStatusFilter(OrchestrationStatus.Running);
            //byNameQuery.AddNameVersionFilter(microservice.Orchestration.FullName);

            //var result = m_HubClient.QueryOrchestrationStates(byNameQuery);

            var res = await loadRunningInstancesAsync(microservice.OrchestrationQName);

            return(res.Count);
        }
Пример #5
0
        /// <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);
                }
            }
        }
Пример #6
0
        ///// <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 registered.");
                }
            }
        }
        public CompositeApplication AddService(Microservice service)
        {
            this.Services.Add(service);

            return(this);
        }