Beispiel #1
0
        protected ServiceConfiguration CreatePipelineWorkflow(ServiceConfiguration workflowConfig)
        {
            var profile = new ServiceProfile {
                Name = "Profile"
            };

            profile.Parameters["AccountID"]        = ACCOUNT_ID;
            profile.Parameters["ChannelID"]        = CHANNEL_ID;
            profile.Parameters["FileDirectory"]    = GetTestName();
            profile.Parameters["DeliveryFileName"] = "temp.txt";
            profile.Parameters["SourceUrl"]        = "http://google.com";
            profile.Parameters["UsePassive"]       = true;
            profile.Parameters["UseBinary"]        = false;
            profile.Parameters["UserID"]           = "edgedev";
            profile.Parameters["Password"]         = "******";

            return(profile.DeriveConfiguration(workflowConfig));
        }
        /// <summary>
        /// Load and translate the services from app.config
        /// </summary>
        private void LoadServicesFromConfigurationFile()
        {
            //base configuration
            foreach (ServiceElement serviceElement in EdgeServicesConfiguration.Current.Services)
            {
                ServiceConfiguration serviceConfiguration = new ServiceConfiguration()
                {
                    ConfigurationID = GuidFromString(serviceElement.Name),
                    ServiceName     = serviceElement.Name
                };

                foreach (var option in serviceElement.Options)
                {
                    serviceConfiguration.Parameters.Add(option.Key, option.Value);
                }

                serviceConfiguration.Limits.MaxConcurrentGlobal     = serviceElement.MaxInstances;
                serviceConfiguration.Limits.MaxConcurrentPerProfile = serviceElement.MaxInstancesPerAccount;
                serviceConfiguration.ServiceClass = serviceElement.Class;

                foreach (SchedulingRuleElement rule in serviceElement.SchedulingRules)
                {
                    serviceConfiguration.SchedulingRules.Add(new SchedulingRule()
                    {
                        Scope             = rule.CalendarUnit,
                        Days              = rule.SubUnits,
                        MaxDeviationAfter = rule.MaxDeviation,
                        Times             = rule.ExactTimes
                    });
                }

                ((ILockable)serviceConfiguration).Lock();

                _serviceBaseConfigurations.Add(serviceConfiguration.ServiceName, serviceConfiguration);
            }

            foreach (AccountElement account in EdgeServicesConfiguration.Current.Accounts)
            {
                // Create matching profile
                ServiceProfile profile = new ServiceProfile()
                {
                    ProfileID = GuidFromString(account.ID.ToString())
                };
                profile.Parameters.Add("AccountID", account.ID);
                profile.Parameters.Add("AccountName", account.Name);
                foreach (AccountServiceElement accountService in account.Services)
                {
                    ServiceElement serviceUse = accountService.Uses.Element;

                    ServiceConfiguration deriveConfiguration = profile.DeriveConfiguration(_serviceBaseConfigurations[serviceUse.Name]);
                    deriveConfiguration.ConfigurationID = GuidFromString(account.ID.ToString() + "___" + serviceUse.Name);


                    foreach (SchedulingRuleElement rule in serviceUse.SchedulingRules)
                    {
                        deriveConfiguration.SchedulingRules.Add(new SchedulingRule()
                        {
                            Scope             = rule.CalendarUnit,
                            Days              = rule.SubUnits,
                            MaxDeviationAfter = rule.MaxDeviation,
                            Times             = rule.ExactTimes
                        });
                    }
                    foreach (var option in serviceUse.Options)
                    {
                        deriveConfiguration.Parameters[option.Key] = option.Value;
                    }
                    deriveConfiguration.Limits.MaxConcurrentGlobal     = serviceUse.MaxInstances;
                    deriveConfiguration.Limits.MaxConcurrentPerProfile = serviceUse.MaxInstancesPerAccount;
                    _serviceConfigurationsToSchedule.Add(deriveConfiguration);
                    profile.Services.Add(deriveConfiguration);
                }
                _profiles.Add(profile);
            }
        }
        static void Main(string[] args)
        {
            // ..........................................................
            // STEP 1 - host

            var envConfig = new ServiceEnvironmentConfiguration()
            {
                DefaultHostName   = "Johnny",
                ConnectionString  = "Data Source=bi_rnd;Initial Catalog=EdgeSystem;Integrated Security=true",
                SP_HostListGet    = "Service_HostList",
                SP_HostRegister   = "Service_HostRegister",
                SP_HostUnregister = "Service_HostUnregister",
                SP_InstanceSave   = "Service_InstanceSave",
                SP_InstanceGet    = "Service_InstanceGet",
                SP_InstanceReset  = "Service_InstanceReset",
                SP_EnvironmentEventListenerListGet    = "Service_EnvironmentEventListenerListGet",
                SP_EnvironmentEventListenerRegister   = "Service_EnvironmentEventListenerRegister",
                SP_EnvironmentEventListenerUnregister = "Service_EnvironmentEventListenerUnregister"
            };

            var environment = ServiceEnvironment.Open("Test Host", envConfig);

            using (var host = new ServiceExecutionHost(environment.EnvironmentConfiguration.DefaultHostName, environment))
            {
                // Disabled for now - work in progress
                using (ServiceEnvironmentEventListener listener = environment.ListenForEvents(ServiceEnvironmentEventType.ServiceRequiresScheduling))
                {
                    listener.ServiceRequiresScheduling += new EventHandler <ServiceInstanceEventArgs>(Environment_ServiceRequiresScheduling);

                    // ..........................................................
                    // STEP 2 - service

                    var serviceTemplate = new ServiceConfiguration()
                    {
                        IsEnabled    = true,
                        ServiceName  = "Test",
                        ServiceClass = typeof(TestService).AssemblyQualifiedName,
                        HostName     = "Johnny"
                    };


                    #region workflow

                    // ..........................................................
                    // workflow example

                    var stepConfig = new ServiceConfiguration()
                    {
                        ServiceClass = typeof(WorkflowStepExample).AssemblyQualifiedName
                    };

                    var workflowConfig = new WorkflowServiceConfiguration()
                    {
                        ServiceName = "PipelineExample"
                    };
                    workflowConfig.Workflow = new WorkflowNodeGroup()
                    {
                        Mode  = WorkflowNodeGroupMode.Linear,
                        Nodes = new LockableList <WorkflowNode>()
                        {
                            new WorkflowStep()
                            {
                                Name = "Initializer", ServiceConfiguration = stepConfig
                            },
                            new WorkflowStep()
                            {
                                Name = "Retriever", ServiceConfiguration = stepConfig
                            },
                            new WorkflowStep()
                            {
                                Name = "Processor", ServiceConfiguration = stepConfig
                            },
                            new WorkflowStep()
                            {
                                Name = "Transform", ServiceConfiguration = stepConfig
                            },
                            new WorkflowStep()
                            {
                                Name = "Stage", ServiceConfiguration = stepConfig
                            },
                            new WorkflowStep()
                            {
                                Name = "Commit", ServiceConfiguration = stepConfig
                            },
                            new WorkflowStep()
                            {
                                Name = "Cubes", ServiceConfiguration = stepConfig
                            },
                        }
                    };

                    #endregion

                    // ..........................................................
                    var profile = new ServiceProfile()
                    {
                        Name = "Doron"
                    };
                    profile.Parameters["AccountID"] = 10035;

                    ServiceConfiguration profileService = profile.DeriveConfiguration(workflowConfig);

                    while (Console.ReadKey().Key != ConsoleKey.Escape)
                    {
                        ServiceInstance instance = environment.NewServiceInstance(profileService);
                        instance.StateChanged    += new EventHandler(instance_StateChanged);
                        instance.OutputGenerated += new EventHandler <ServiceOutputEventArgs>(instance_OutputGenerated);
                        instance.Start();
                    }
                }
            }
        }
Beispiel #4
0
        private static SchedulerConfiguration GenerateConfigForScheduler()
        {
            var schedulerConfig = new SchedulerConfiguration
            {
                Percentile         = 80,
                Timeframe          = new TimeSpan(2, 0, 0),
                RescheduleInterval = new TimeSpan(0, 10, 0),
                ExecuteInterval    = new TimeSpan(0, 0, 1),
                ExecutionStatisticsRefreshInterval = new TimeSpan(23, 59, 0)
            };

            // create service configuration
            var serviceList = new List <ServiceConfiguration>
            {
                new ServiceConfiguration()
                {
                    IsEnabled    = true,
                    ServiceName  = "Dummy",
                    ServiceClass = typeof(DummyService).AssemblyQualifiedName,
                    HostName     = "Johnny"
                }
            };

            // add scheduling rule to service config
            serviceList[0].SchedulingRules.Add(new SchedulingRule
            {
                Scope = SchedulingScope.Day,
                Times = new TimeSpan[] { new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second) },
                MaxDeviationBefore = new TimeSpan(0, 0, 0),
                MaxDeviationAfter  = new TimeSpan(0, 10, 0)
            });
            // add service limits
            serviceList[0].Limits.MaxConcurrentPerTemplate = 1;
            serviceList[0].Limits.MaxConcurrentPerProfile  = 1;

            // create dummy profiles
            var profileCollection = new ProfilesCollection();

            var profile = new ServiceProfile {
                Name = "profile1"
            };

            profile.Parameters["AccountID"] = 1;
            profile.Services.Add(profile.DeriveConfiguration(serviceList[0]));
            profileCollection.Add(profile);

            profile = new ServiceProfile {
                Name = "profile2"
            };
            profile.Parameters["AccountID"] = 2;
            profile.Services.Add(profile.DeriveConfiguration(serviceList[0]));
            profile.Services[0].SchedulingRules[0].Times[0]          = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            profile.Services[0].SchedulingRules[0].MaxDeviationAfter = new TimeSpan(0, 2, 0);
            profileCollection.Add(profile);

            profile = new ServiceProfile {
                Name = "profile3"
            };
            profile.Parameters["AccountID"] = 3;
            profile.Services.Add(profile.DeriveConfiguration(serviceList[0]));
            profile.Services[0].SchedulingRules[0].Times[0]          = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            profile.Services[0].SchedulingRules[0].MaxDeviationAfter = new TimeSpan(0, 5, 0);
            profileCollection.Add(profile);

            schedulerConfig.Profiles = profileCollection;
            schedulerConfig.ServiceConfigurationList = serviceList;

            return(schedulerConfig);
        }