Beispiel #1
0
		public WorkerWrapper(IInvokeHandler invokeHandler,
		                     NodeConfiguration nodeConfiguration,
		                     TrySendNodeStartUpNotificationToManagerTimer nodeStartUpNotificationToManagerTimer,
		                     Timer pingToManagerTimer,
		                     TrySendJobDoneStatusToManagerTimer trySendJobDoneStatusToManagerTimer,
		                     TrySendJobCanceledToManagerTimer trySendJobCanceledStatusToManagerTimer,
		                     TrySendJobFaultedToManagerTimer trySendJobFaultedStatusToManagerTimer,
		                     TrySendJobDetailToManagerTimer trySendJobDetailToManagerTimer)
		{
			_handler = invokeHandler;
			_nodeConfiguration = nodeConfiguration;
			WhoamI = _nodeConfiguration.CreateWhoIAm(Environment.MachineName);

			_nodeStartUpNotificationToManagerTimer = nodeStartUpNotificationToManagerTimer;
			_nodeStartUpNotificationToManagerTimer.TrySendNodeStartUpNotificationSucceded +=
				NodeStartUpNotificationToManagerTimer_TrySendNodeStartUpNotificationSucceded;

			_pingToManagerTimer = pingToManagerTimer;
			_trySendJobDoneStatusToManagerTimer = trySendJobDoneStatusToManagerTimer;
			_trySendJobCanceledStatusToManagerTimer = trySendJobCanceledStatusToManagerTimer;
			_trySendJobFaultedStatusToManagerTimer = trySendJobFaultedStatusToManagerTimer;
			_trySendJobDetailToManagerTimer = trySendJobDetailToManagerTimer;

			isWorking = false;

			_trySendJobDetailToManagerTimer.Start();
			_nodeStartUpNotificationToManagerTimer.Start();
		}
 /// <summary>
 /// Configures the specified property info.
 /// </summary>
 /// <param name="propertyInfo">The property info.</param>
 /// <param name="config">The config.</param>
 public void Configure(PropertyInfo propertyInfo, NodeConfiguration config)
 {
     config.Id = this.Id;
     config.IsLazy = this.IsLazy;
     config.Path = this.Path;
     
     base.Configure(propertyInfo, config);
 }
 public void OnStartup(NodeConfiguration configuration)
 {
     configuration.DataAccess.Default
         .OnNative(db =>
         {
             db.EnsureUniqueIndexFor<User>(u => u.Name);
             db.EnsureUniqueIndexFor<Post>(u => u.Created);
         });
 }
		public TrySendJobCanceledToManagerTimer(NodeConfiguration nodeConfiguration,
												TrySendJobDetailToManagerTimer sendJobDetailToManagerTimer,
												IHttpSender httpSender,
												double interval = 500) : base(nodeConfiguration,
		                                                                        nodeConfiguration.GetManagerJobHasBeenCanceledTemplateUri(),
																				sendJobDetailToManagerTimer,
																				httpSender,
																				interval)
		{
		}
		public TrySendJobDoneStatusToManagerTimer(NodeConfiguration nodeConfiguration,
												  TrySendJobDetailToManagerTimer sendJobDetailToManagerTimer,
												  IHttpSender httpSender,
												  double interval = 500) : base(nodeConfiguration,
		                                                                          nodeConfiguration.GetManagerJobDoneTemplateUri(),
																				  sendJobDetailToManagerTimer,
																				  httpSender,
																				  interval)
		{
		}
		public PingToManagerTimer(NodeConfiguration nodeConfiguration,
		                          IHttpSender httpSender) : base(nodeConfiguration.PingToManagerSeconds*1000)
		{
			_cancellationTokenSource = new CancellationTokenSource();

			_nodeConfiguration = nodeConfiguration;
			_httpSender = httpSender;
			_whoAmI = nodeConfiguration.CreateWhoIAm(Environment.MachineName);

			Elapsed += OnTimedEvent;
		}
		public TrySendJobFaultedToManagerTimer(NodeConfiguration nodeConfiguration,
		                                       TrySendJobDetailToManagerTimer sendJobDetailToManagerTimer,
		                                       IHttpSender httpSender,
		                                       double interval = 500) : base(nodeConfiguration,
		                                                                     nodeConfiguration
			                                                                     .GetManagerJobHasFailedTemplatedUri(),
		                                                                     sendJobDetailToManagerTimer,
		                                                                     httpSender,
		                                                                     interval)
		{
			_httpSender = httpSender;
		}
		public TrySendJobDetailToManagerTimer(NodeConfiguration nodeConfiguration,
		                                        IHttpSender httpSender,
		                                        double interval = 500) : base(interval)
		{
			_httpSender = httpSender;
			_cancellationTokenSource = new CancellationTokenSource();
			_jobDetails = new ConcurrentDictionary<Guid, JobDetailEntity>();
			_uriBuilder = new UriBuilder(nodeConfiguration.ManagerLocation);
			_uriBuilder.Path += ManagerRouteConstants.JobProgress;

			Elapsed += OnTimedEvent;
		}
 public void OnStartup(NodeConfiguration configuration)
 {
     configuration
         .WcfProxyFactory
         .Start<IUserService>()
         .ImplementedBy<UserService>()
         .ConfiguredWith(c =>
         {
             c.BaseAddress(Configured.From.AppSettings("UserServiceUrl"));
             c.Endpoint(Bound.To(new BasicHttpBinding()));
             c.PublishedMetadata();
         });
 }
		public TrySendStatusToManagerTimer(NodeConfiguration nodeConfiguration,
		                                   Uri callbackTemplateUri,
		                                   TrySendJobDetailToManagerTimer sendJobDetailToManagerTimer,
		                                   IHttpSender httpSender, double interval = 500) : base(interval)
		{
			_cancellationTokenSource = new CancellationTokenSource();
			_whoAmI = nodeConfiguration.CreateWhoIAm(Environment.MachineName);
			_sendJobDetailToManagerTimer = sendJobDetailToManagerTimer;
			_httpSender = httpSender;
			CallbackTemplateUri = callbackTemplateUri;

			Elapsed += OnTimedEvent;
			AutoReset = true;
		}
		public TrySendNodeStartUpNotificationToManagerTimer(NodeConfiguration nodeConfiguration,
		                                                    IHttpSender httpSender,
		                                                    double interval = 5000,
		                                                    bool autoReset = true) : base(interval)
		{
			var callbackToManagerTemplateUri = nodeConfiguration.GetManagerNodeHasBeenInitializedUri();
			_cancellationTokenSource = new CancellationTokenSource();
			_nodeConfiguration = nodeConfiguration;
			_callbackToManagerTemplateUri = callbackToManagerTemplateUri;
			_httpSender = httpSender;
			_whoAmI = _nodeConfiguration.CreateWhoIAm(Environment.MachineName);

			Elapsed += OnTimedEvent;
			AutoReset = autoReset;
		}
 public void OnStartup(NodeConfiguration configuration)
 {
     configuration
         .Container
         .Put(Binding.Use(AllTypes.BasedOn<IQuery>(From.ThisAssembly)).With(Lifecycle.Unmanaged));
 }
Beispiel #13
0
 public SiloAssemblyLoader(NodeConfiguration nodeConfig)
     : this(nodeConfig.AdditionalAssemblyDirectories)
 {
 }
Beispiel #14
0
 public NodeTaskRunner(NodeConfiguration nodeConfiguration)
 {
     this.NodeConfiguration = nodeConfiguration;
 }
Beispiel #15
0
 public ClusterConfig(NodeConfiguration conf, params string[] seedNodes) : this(conf.Name, conf.Address, seedNodes)
 {
 }
Beispiel #16
0
        static void Main(string[] args)
        {
            var config = NodeConfiguration.GetDefault();

            using (var core = new CrossStitchCore(config))
            {
                var stitchesConfiguration = StitchesConfiguration.GetDefault();
                var stitches = new StitchesModule(core, stitchesConfiguration);
                core.AddModule(stitches);

                var log     = Common.Logging.LogManager.GetLogger("CrossStitch");
                var logging = new LoggingModule(core, log);
                core.AddModule(logging);

                core.Start();

                // First stitch is a processV1
                var group1         = new StitchGroupName("StitchStart", "Client", "1");
                var packageResult1 = core.MessageBus.Request <DataRequest <PackageFile>, DataResponse <PackageFile> >(DataRequest <PackageFile> .Save(new PackageFile
                {
                    Id        = group1.ToString(),
                    GroupName = group1,
                    Adaptor   = new InstanceAdaptorDetails
                    {
                        Type       = AdaptorType.ProcessV1,
                        Parameters = new Dictionary <string, string>
                        {
                            { Parameters.DirectoryPath, "." },
                            { Parameters.ExecutableName, "StitchStart.Client.exe" }
                        },
                        RequiresPackageUnzip = false
                    }
                }, true));
                var createResult1 = core.MessageBus.Request <LocalCreateInstanceRequest, LocalCreateInstanceResponse>(new LocalCreateInstanceRequest
                {
                    Name              = "StitchStart.Client",
                    GroupName         = group1,
                    NumberOfInstances = 1,
                });
                core.MessageBus.Request <InstanceRequest, InstanceResponse>(InstanceRequest.ChannelStart, new InstanceRequest
                {
                    Id = createResult1.CreatedIds.FirstOrDefault()
                });

                // Second stitch is a built-in class
                var group2         = new StitchGroupName("StitchStart", "BuiltIn", "1");
                var packageResult2 = core.MessageBus.Request <DataRequest <PackageFile>, DataResponse <PackageFile> >(DataRequest <PackageFile> .Save(new PackageFile
                {
                    Id        = group2.ToString(),
                    GroupName = group2,
                    Adaptor   = new InstanceAdaptorDetails
                    {
                        Type       = AdaptorType.BuildInClassV1,
                        Parameters = new Dictionary <string, string>
                        {
                            { CrossStitch.Stitch.BuiltInClassV1.Parameters.TypeName, typeof(StitchStartBuiltInStitch).AssemblyQualifiedName }
                        }
                    },
                }, true));
                var createResult2 = core.MessageBus.Request <LocalCreateInstanceRequest, LocalCreateInstanceResponse>(new LocalCreateInstanceRequest
                {
                    Name              = "StitchStart.BuiltIn",
                    GroupName         = group2,
                    NumberOfInstances = 1
                });
                core.MessageBus.Request <InstanceRequest, InstanceResponse>(InstanceRequest.ChannelStart, new InstanceRequest
                {
                    Id = createResult2.CreatedIds.FirstOrDefault()
                });

                Console.ReadKey();
                core.Stop();
            }
        }
Beispiel #17
0
 internal MembershipEntry CreateNewMembershipEntry(NodeConfiguration nodeConf, SiloStatus myStatus)
 {
     return(CreateNewMembershipEntry(nodeConf, MyAddress, MyHostname, myStatus, SiloStartTime));
 }
Beispiel #18
0
 private void InitializeLogger(NodeConfiguration nodeCfg)
 {
     TraceLogger.Initialize(nodeCfg);
     logger = TraceLogger.GetLogger("OrleansSiloHost", TraceLogger.LoggerType.Runtime);
 }
        public void MultidatabaseNodesToDifferentDatabaseSetTest()
        {
            Require.ProviderIs(StorageProvider.SqlServer);

            var masterConnectionInfo = BuildConnectionToMaster(DomainConfigurationFactory.Create().ConnectionInfo);
            var configuration        = new DomainConfiguration(masterConnectionInfo);

            configuration.Types.Register(typeof(part1.TestEntity1));
            configuration.Types.Register(typeof(part2.TestEntity2));
            configuration.UpgradeMode     = DomainUpgradeMode.Recreate;
            configuration.DefaultSchema   = "dbo";
            configuration.DefaultDatabase = "DO-Tests-1";
            configuration.MappingRules.Map(typeof(part1.TestEntity1).Namespace).ToDatabase("DO-Tests-1");
            configuration.MappingRules.Map(typeof(part2.TestEntity2).Namespace).ToDatabase("DO-Tests-2");

            using (var domain = Domain.Build(configuration)) {
                var domainCopyNode = new NodeConfiguration("1");
                domainCopyNode.ConnectionInfo = masterConnectionInfo;
                domainCopyNode.SchemaMapping.Add("dbo", "dbo");
                domainCopyNode.DatabaseMapping.Add("DO-Tests-1", "DO-Tests-1");
                domainCopyNode.DatabaseMapping.Add("DO-Tests-2", "DO-Tests-2");
                domainCopyNode.UpgradeMode = DomainUpgradeMode.Recreate;
                domain.StorageNodeManager.AddNode(domainCopyNode);

                var anotherDatabaseNode = new NodeConfiguration("2");
                anotherDatabaseNode.ConnectionInfo = masterConnectionInfo;
                anotherDatabaseNode.SchemaMapping.Add("dbo", "dbo");
                anotherDatabaseNode.DatabaseMapping.Add("DO-Tests-1", "DO-Tests-3");
                anotherDatabaseNode.DatabaseMapping.Add("DO-Tests-2", "DO-Tests-4");
                anotherDatabaseNode.UpgradeMode = DomainUpgradeMode.Recreate;
                domain.StorageNodeManager.AddNode(anotherDatabaseNode);

                var testEntity1Type = domain.Model.Types[typeof(part1.TestEntity1)];
                var testEntity2Type = domain.Model.Types[typeof(part2.TestEntity2)];

                var defaultNode = domain.StorageNodeManager.GetNode(WellKnown.DefaultNodeId);
                var table       = defaultNode.Mapping[testEntity1Type];
                Assert.That(table.Schema.Name, Is.EqualTo("dbo"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-1"));
                table = defaultNode.Mapping[testEntity2Type];
                Assert.That(table.Schema.Name, Is.EqualTo("dbo"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-2"));

                var node1 = domain.StorageNodeManager.GetNode("1");
                table = node1.Mapping[testEntity1Type];
                Assert.That(table.Schema.Name, Is.EqualTo("dbo"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-1"));
                table = node1.Mapping[testEntity2Type];
                Assert.That(table.Schema.Name, Is.EqualTo("dbo"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-2"));

                var node2 = domain.StorageNodeManager.GetNode("2");
                table = node2.Mapping[testEntity1Type];
                Assert.That(table.Schema.Name, Is.EqualTo("dbo"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-3"));
                table = node2.Mapping[testEntity2Type];
                Assert.That(table.Schema.Name, Is.EqualTo("dbo"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-4"));
            }

            configuration = new DomainConfiguration(masterConnectionInfo);
            configuration.Types.Register(typeof(part1.TestEntity1));
            configuration.Types.Register(typeof(part2.TestEntity2));
            configuration.UpgradeMode     = DomainUpgradeMode.Skip;
            configuration.DefaultSchema   = "dbo";
            configuration.DefaultDatabase = "DO-Tests-1";
            configuration.MappingRules.Map(typeof(part1.TestEntity1).Namespace).ToDatabase("DO-Tests-1");
            configuration.MappingRules.Map(typeof(part2.TestEntity2).Namespace).ToDatabase("DO-Tests-2");

            using (var domain = Domain.Build(configuration)) {
                var domainCopyNode = new NodeConfiguration("1");
                domainCopyNode.ConnectionInfo = masterConnectionInfo;
                domainCopyNode.SchemaMapping.Add("dbo", "dbo");
                domainCopyNode.DatabaseMapping.Add("DO-Tests-1", "DO-Tests-1");
                domainCopyNode.DatabaseMapping.Add("DO-Tests-2", "DO-Tests-2");
                domainCopyNode.UpgradeMode = DomainUpgradeMode.Skip;
                domain.StorageNodeManager.AddNode(domainCopyNode);

                var anotherDatabaseNode = new NodeConfiguration("2");
                anotherDatabaseNode.ConnectionInfo = masterConnectionInfo;
                anotherDatabaseNode.SchemaMapping.Add("dbo", "dbo");
                anotherDatabaseNode.DatabaseMapping.Add("DO-Tests-1", "DO-Tests-3");
                anotherDatabaseNode.DatabaseMapping.Add("DO-Tests-2", "DO-Tests-4");
                anotherDatabaseNode.UpgradeMode = DomainUpgradeMode.Skip;
                domain.StorageNodeManager.AddNode(anotherDatabaseNode);

                var testEntity1Type = domain.Model.Types[typeof(part1.TestEntity1)];
                var testEntity2Type = domain.Model.Types[typeof(part2.TestEntity2)];

                var defaultNode = domain.StorageNodeManager.GetNode(WellKnown.DefaultNodeId);
                var table       = defaultNode.Mapping[testEntity1Type];
                Assert.That(table.Schema.Name, Is.EqualTo("dbo"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-1"));
                table = defaultNode.Mapping[testEntity2Type];
                Assert.That(table.Schema.Name, Is.EqualTo("dbo"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-2"));

                var node1 = domain.StorageNodeManager.GetNode("1");
                table = node1.Mapping[testEntity1Type];
                Assert.That(table.Schema.Name, Is.EqualTo("dbo"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-1"));
                table = node1.Mapping[testEntity2Type];
                Assert.That(table.Schema.Name, Is.EqualTo("dbo"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-2"));

                var node2 = domain.StorageNodeManager.GetNode("2");
                table = node2.Mapping[testEntity1Type];
                Assert.That(table.Schema.Name, Is.EqualTo("dbo"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-3"));
                table = node2.Mapping[testEntity2Type];
                Assert.That(table.Schema.Name, Is.EqualTo("dbo"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-4"));
            }
        }
        public void MultischemaWithDatabaseSwitchingTest()
        {
            Require.ProviderIs(StorageProvider.SqlServer);
            var masterConnection = BuildConnectionToMaster(DomainConfigurationFactory.Create().ConnectionInfo);
            var configuration    = new DomainConfiguration(masterConnection);

            configuration.Types.Register(typeof(part1.TestEntity1));
            configuration.UpgradeMode   = DomainUpgradeMode.Recreate;
            configuration.DefaultSchema = "dbo";
            configuration.ConnectionInitializationSql = "USE [DO-Tests-1]";
            using (var domain = Domain.Build(configuration)) {
                var domainCopyNode = new NodeConfiguration("1");
                domainCopyNode.ConnectionInfo = masterConnection;
                domainCopyNode.ConnectionInitializationSql = "USE [DO-Tests-1]";
                domainCopyNode.SchemaMapping.Add("dbo", "dbo");
                domainCopyNode.UpgradeMode = DomainUpgradeMode.Recreate;
                domain.StorageNodeManager.AddNode(domainCopyNode);

                var anotherDatabaseNode = new NodeConfiguration("2");
                anotherDatabaseNode.ConnectionInfo = masterConnection;
                anotherDatabaseNode.ConnectionInitializationSql = "USE [DO-Tests-2]";
                anotherDatabaseNode.SchemaMapping.Add("dbo", "dbo");
                anotherDatabaseNode.UpgradeMode = DomainUpgradeMode.Recreate;
                domain.StorageNodeManager.AddNode(anotherDatabaseNode);

                var thirdDatabaseNode = new NodeConfiguration("3");
                thirdDatabaseNode.ConnectionInfo = masterConnection;
                thirdDatabaseNode.ConnectionInitializationSql = "USE [DO-Tests-3]";
                thirdDatabaseNode.SchemaMapping.Add("dbo", "Model1");
                thirdDatabaseNode.UpgradeMode = DomainUpgradeMode.Recreate;
                domain.StorageNodeManager.AddNode(thirdDatabaseNode);
            }

            configuration = new DomainConfiguration(masterConnection);
            configuration.Types.Register(typeof(part1.TestEntity1));
            configuration.DefaultSchema = "dbo";
            configuration.UpgradeMode   = DomainUpgradeMode.Skip;
            configuration.ConnectionInitializationSql = "USE [DO-Tests-1]";
            using (var domain = Domain.Build(configuration)) {
                var domainCopyNode = new NodeConfiguration("1");
                domainCopyNode.ConnectionInfo = masterConnection;
                domainCopyNode.ConnectionInitializationSql = "USE [DO-Tests-1]";
                domainCopyNode.SchemaMapping.Add("dbo", "dbo");
                domainCopyNode.UpgradeMode = DomainUpgradeMode.Skip;
                domain.StorageNodeManager.AddNode(domainCopyNode);

                var anotherDatabaseNode = new NodeConfiguration("2");
                anotherDatabaseNode.ConnectionInfo = masterConnection;
                anotherDatabaseNode.ConnectionInitializationSql = "USE [DO-Tests-2]";
                anotherDatabaseNode.SchemaMapping.Add("dbo", "dbo");
                anotherDatabaseNode.UpgradeMode = DomainUpgradeMode.Skip;
                domain.StorageNodeManager.AddNode(anotherDatabaseNode);

                var thirdDatabaseNode = new NodeConfiguration("3");
                thirdDatabaseNode.ConnectionInfo = masterConnection;
                thirdDatabaseNode.ConnectionInitializationSql = "USE [DO-Tests-3]";
                thirdDatabaseNode.SchemaMapping.Add("dbo", "Model1");
                thirdDatabaseNode.UpgradeMode = DomainUpgradeMode.Skip;
                domain.StorageNodeManager.AddNode(thirdDatabaseNode);

                var testEntity1Type = domain.Model.Types[typeof(part1.TestEntity1)];
                var defaultNode     = domain.StorageNodeManager.GetNode(WellKnown.DefaultNodeId);
                var table           = defaultNode.Mapping[testEntity1Type];
                Assert.That(table.Schema.Name, Is.EqualTo("dbo"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-1"));

                var node1 = domain.StorageNodeManager.GetNode("1");
                table = node1.Mapping[testEntity1Type];
                Assert.That(table.Schema.Name, Is.EqualTo("dbo"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-1"));

                var node2 = domain.StorageNodeManager.GetNode("2");
                table = node2.Mapping[testEntity1Type];
                Assert.That(table.Schema.Name, Is.EqualTo("dbo"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-2"));

                var node3 = domain.StorageNodeManager.GetNode("3");
                table = node3.Mapping[testEntity1Type];
                Assert.That(table.Schema.Name, Is.EqualTo("Model1"));
                Assert.That(table.Schema.Catalog.Name, Is.EqualTo("DO-Tests-3"));
            }
        }
Beispiel #21
0
        public static SiloHandle StartOrleansSilo(TestCluster cluster, Silo.SiloType type, ClusterConfiguration clusterConfig, NodeConfiguration nodeConfig)
        {
            if (cluster == null)
            {
                throw new ArgumentNullException(nameof(cluster));
            }
            var siloName = nodeConfig.SiloName;

            cluster.WriteLog("Starting a new silo in app domain {0} with config {1}", siloName, clusterConfig.ToString(siloName));
            AppDomain appDomain;
            Silo      silo = cluster.LoadSiloInNewAppDomain(siloName, type, clusterConfig, out appDomain);

            silo.Start();

            SiloHandle retValue = new SiloHandle
            {
                Name = siloName,
                Silo = silo,
                NodeConfiguration = nodeConfig,
                Endpoint          = silo.SiloAddress.Endpoint,
                AppDomain         = appDomain,
            };

            cluster.ImportGeneratedAssemblies(retValue);
            return(retValue);
        }
Beispiel #22
0
 public OrleansTaskScheduler(GlobalConfiguration globalConfig, NodeConfiguration config)
     : this(config.MaxActiveThreads, config.DelayWarningThreshold, config.ActivationSchedulingQuantum,
            config.TurnWarningLengthThreshold, config.InjectMoreWorkerThreads)
 {
 }
Beispiel #23
0
 private SiloHandle LoadSiloInNewAppDomain(string siloName, Silo.SiloType type, ClusterConfiguration config, NodeConfiguration nodeConfiguration)
 {
     return(AppDomainSiloHandle.Create(siloName, type, this.siloBuilderFactoryType, config, nodeConfiguration));
 }
Beispiel #24
0
        public static SiloHandle StartOrleansSilo(TestingSiloHost host, Silo.SiloType type, TestingSiloOptions options, int instanceCount, AppDomain shared = null)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            // Load initial config settings, then apply some overrides below.
            ClusterConfiguration config = new ClusterConfiguration();

            try
            {
                if (options.SiloConfigFile == null)
                {
                    config.StandardLoad();
                }
                else
                {
                    config.LoadFromFile(options.SiloConfigFile.FullName);
                }
            }
            catch (FileNotFoundException)
            {
                if (options.SiloConfigFile != null &&
                    !string.Equals(options.SiloConfigFile.Name, TestingSiloOptions.DEFAULT_SILO_CONFIG_FILE, StringComparison.InvariantCultureIgnoreCase))
                {
                    // if the user is not using the defaults, then throw because the file was legitimally not found
                    throw;
                }

                config = ClusterConfiguration.LocalhostPrimarySilo();
                config.AddMemoryStorageProvider("Default");
                config.AddMemoryStorageProvider("MemoryStore");
            }

            int basePort = options.BasePort < 0 ? BasePort : options.BasePort;


            if (config.Globals.SeedNodes.Count > 0 && options.BasePort < 0)
            {
                config.PrimaryNode = config.Globals.SeedNodes[0];
            }
            else
            {
                config.PrimaryNode = new IPEndPoint(IPAddress.Loopback, basePort);
            }
            config.Globals.SeedNodes.Clear();
            config.Globals.SeedNodes.Add(config.PrimaryNode);

            if (!String.IsNullOrEmpty(host.DeploymentId))
            {
                config.Globals.DeploymentId = host.DeploymentId;
            }

            config.Defaults.PropagateActivityId = options.PropagateActivityId;
            if (options.LargeMessageWarningThreshold > 0)
            {
                config.Defaults.LargeMessageWarningThreshold = options.LargeMessageWarningThreshold;
            }

            config.Globals.LivenessType        = options.LivenessType;
            config.Globals.ReminderServiceType = options.ReminderServiceType;
            if (!String.IsNullOrEmpty(options.DataConnectionString))
            {
                config.Globals.DataConnectionString = options.DataConnectionString;
            }

            host.Globals = config.Globals;

            string siloName;

            switch (type)
            {
            case Silo.SiloType.Primary:
                siloName = "Primary";
                break;

            default:
                siloName = "Secondary_" + instanceCount.ToString(CultureInfo.InvariantCulture);
                break;
            }

            NodeConfiguration nodeConfig = config.GetOrCreateNodeConfigurationForSilo(siloName);

            nodeConfig.HostNameOrIPAddress = "loopback";
            nodeConfig.Port = basePort + instanceCount;
            nodeConfig.DefaultTraceLevel   = config.Defaults.DefaultTraceLevel;
            nodeConfig.PropagateActivityId = config.Defaults.PropagateActivityId;
            nodeConfig.BulkMessageLimit    = config.Defaults.BulkMessageLimit;

            if (nodeConfig.ProxyGatewayEndpoint != null && nodeConfig.ProxyGatewayEndpoint.Address != null)
            {
                int proxyBasePort = options.ProxyBasePort < 0 ? ProxyBasePort : options.ProxyBasePort;
                nodeConfig.ProxyGatewayEndpoint = new IPEndPoint(nodeConfig.ProxyGatewayEndpoint.Address, proxyBasePort + instanceCount);
            }

            config.Globals.ExpectedClusterSize = 2;

            config.Overrides[siloName] = nodeConfig;

            AdjustForTest(config, options);

            WriteLog("Starting a new silo in app domain {0} with config {1}", siloName, config.ToString(siloName));
            AppDomain appDomain;
            Silo      silo = host.LoadSiloInNewAppDomain(siloName, type, config, out appDomain);

            silo.Start();

            SiloHandle retValue = new SiloHandle
            {
                Name      = siloName,
                Silo      = silo,
                Options   = options,
                Endpoint  = silo.SiloAddress.Endpoint,
                AppDomain = appDomain,
            };

            host.ImportGeneratedAssemblies(retValue);
            return(retValue);
        }
Beispiel #25
0
        internal Silo(string name, SiloType siloType, ClusterConfiguration config, ILocalDataStore keyStore)
        {
            SystemStatus.Current = SystemStatus.Creating;

            CurrentSilo = this;

            var startTime = DateTime.UtcNow;

            this.siloType = siloType;
            Name          = name;

            siloTerminatedEvent = new ManualResetEvent(false);

            OrleansConfig = config;
            globalConfig  = config.Globals;
            config.OnConfigChange("Defaults", () => nodeConfig = config.GetConfigurationForNode(name));

            if (!TraceLogger.IsInitialized)
            {
                TraceLogger.Initialize(nodeConfig);
            }

            config.OnConfigChange("Defaults/Tracing", () => TraceLogger.Initialize(nodeConfig, true), false);
            LimitManager.Initialize(nodeConfig);
            ActivationData.Init(config);
            StatisticsCollector.Initialize(nodeConfig);
            SerializationManager.Initialize(globalConfig.UseStandardSerializer);
            initTimeout = globalConfig.MaxJoinAttemptTime;
            if (Debugger.IsAttached)
            {
                initTimeout = StandardExtensions.Max(TimeSpan.FromMinutes(10), globalConfig.MaxJoinAttemptTime);
                stopTimeout = initTimeout;
            }

            IPEndPoint here       = nodeConfig.Endpoint;
            int        generation = nodeConfig.Generation;

            if (generation == 0)
            {
                generation            = SiloAddress.AllocateNewGeneration();
                nodeConfig.Generation = generation;
            }
            TraceLogger.MyIPEndPoint = here;
            logger = TraceLogger.GetLogger("Silo", TraceLogger.LoggerType.Runtime);
            logger.Info(ErrorCode.SiloInitializing, "-------------- Initializing {0} silo on {1} at {2}, gen {3} --------------", siloType, nodeConfig.DNSHostName, here, generation);
            logger.Info(ErrorCode.SiloInitConfig, "Starting silo {0} with runtime Version='{1}' Config= " + Environment.NewLine + "{2}", name, RuntimeVersion.Current, config.ToString(name));

            if (keyStore != null)
            {
                // Re-establish reference to shared local key store in this app domain
                LocalDataStoreInstance.LocalDataStore = keyStore;
            }
            healthCheckParticipants = new List <IHealthCheckParticipant>();

            BufferPool.InitGlobalBufferPool(globalConfig);
            PlacementStrategy.Initialize(globalConfig);

            UnobservedExceptionsHandlerClass.SetUnobservedExceptionHandler(UnobservedExceptionHandler);
            AppDomain.CurrentDomain.UnhandledException +=
                (obj, ev) => DomainUnobservedExceptionHandler(obj, (Exception)ev.ExceptionObject);

            typeManager = new GrainTypeManager(here.Address.Equals(IPAddress.Loopback));

            // Performance metrics
            siloStatistics = new SiloStatisticsManager(globalConfig, nodeConfig);
            config.OnConfigChange("Defaults/LoadShedding", () => siloStatistics.MetricsTable.NodeConfig = nodeConfig, false);

            // The scheduler
            scheduler = new OrleansTaskScheduler(globalConfig, nodeConfig);
            healthCheckParticipants.Add(scheduler);

            // Initialize the message center
            var mc = new MessageCenter(here, generation, globalConfig, siloStatistics.MetricsTable);

            if (nodeConfig.IsGatewayNode)
            {
                mc.InstallGateway(nodeConfig.ProxyGatewayEndpoint);
            }

            messageCenter = mc;

            // Now the router/directory service
            // This has to come after the message center //; note that it then gets injected back into the message center.;
            localGrainDirectory = new LocalGrainDirectory(this);

            // Now the activation directory.
            // This needs to know which router to use so that it can keep the global directory in synch with the local one.
            activationDirectory = new ActivationDirectory();

            // Now the consistent ring provider
            RingProvider = GlobalConfig.UseVirtualBucketsConsistentRing ?
                           (IConsistentRingProvider) new VirtualBucketsRingProvider(SiloAddress, GlobalConfig.NumVirtualBucketsConsistentRing)
                : new ConsistentRingProvider(SiloAddress);

            Action <Dispatcher> setDispatcher;

            catalog = new Catalog(Constants.CatalogId, SiloAddress, Name, LocalGrainDirectory, typeManager, scheduler, activationDirectory, config, out setDispatcher);
            var dispatcher = new Dispatcher(scheduler, messageCenter, catalog, config);

            setDispatcher(dispatcher);

            RuntimeClient.Current = new InsideRuntimeClient(
                dispatcher,
                catalog,
                LocalGrainDirectory,
                SiloAddress,
                config,
                RingProvider,
                typeManager);
            messageCenter.RerouteHandler       = InsideRuntimeClient.Current.RerouteMessage;
            messageCenter.SniffIncomingMessage = InsideRuntimeClient.Current.SniffIncomingMessage;
            messageCenter.ClientDropHandler    = grainIds =>
            {
                catalog.DeleteGrainsLocal(grainIds).Ignore();
                scheduler.RunOrQueueAction(() =>
                {
                    // Consider: batch delete
                    foreach (var id in grainIds)
                    {
                        LocalGrainDirectory.DeleteGrain(id).Ignore();
                    }
                }, catalog.SchedulingContext);
            };

            siloStatistics.MetricsTable.Scheduler           = scheduler;
            siloStatistics.MetricsTable.ActivationDirectory = activationDirectory;
            siloStatistics.MetricsTable.ActivationCollector = catalog.ActivationCollector;
            siloStatistics.MetricsTable.MessageCenter       = messageCenter;

            DeploymentLoadPublisher.CreateDeploymentLoadPublisher(this, globalConfig);
            PlacementDirectorsManager.CreatePlacementDirectorsManager(globalConfig);

            // Now the incoming message agents
            incomingSystemAgent = new IncomingMessageAgent(Message.Categories.System, messageCenter, activationDirectory, scheduler, dispatcher);
            incomingPingAgent   = new IncomingMessageAgent(Message.Categories.Ping, messageCenter, activationDirectory, scheduler, dispatcher);
            incomingAgent       = new IncomingMessageAgent(Message.Categories.Application, messageCenter, activationDirectory, scheduler, dispatcher);

            membershipFactory = new MembershipFactory();
            reminderFactory   = new LocalReminderServiceFactory();

            SystemStatus.Current = SystemStatus.Created;

            StringValueStatistic.FindOrCreate(StatisticNames.SILO_START_TIME,
                                              () => TraceLogger.PrintDate(startTime)); // this will help troubleshoot production deployment when looking at MDS logs.

            TestHookup = new TestHookups(this);

            logger.Info(ErrorCode.SiloInitializingFinished, "-------------- Started silo {0}, ConsistentHashCode {1:X} --------------", SiloAddress.ToLongString(), SiloAddress.GetConsistentHashCode());
        }
Beispiel #26
0
        public static ClusterConfig NonSeedNode(NodeConfiguration address, INodeNetworkAddress[] seedNodesAddresses)
        {
            var seedNodes = seedNodesAddresses.Select(s => GetSeedNetworkAddress(address.Name, s)).ToArray();

            return(new ClusterConfig(address.Name, new NodeNetworkAddress(address.Address.Host, 0), seedNodes));
        }
 public void OnShutdown(NodeConfiguration configuration)
 {
     _shutdownAction(configuration);
 }
Beispiel #28
0
 private SiloHandle LoadSiloInNewAppDomain(string siloName, Silo.SiloType type, ClusterConfiguration config, NodeConfiguration nodeConfiguration)
 {
     return(AppDomainSiloHandle.Create(siloName, type, config, nodeConfiguration, this.additionalAssemblies));
 }
 public override void Run(NodeConfiguration config, NodeFileSystem fileSystem) =>
 WriteFileIfNotExist(Path.Combine(fileSystem.ElasticsearchHome, "run.bat"), @"bin\elasticsearch.bat");
Beispiel #30
0
 /// <summary>
 /// Base Node constructor.
 /// </summary>
 protected Node()
 {
     Current = this;
     Configuration = new NodeConfiguration();
 }
        public async Task CreateOpcEventPublishingData(string testFilename, int configuredSessions,
                                                       int configuredSubscriptions, int configuredMonitoredItems, int configuredMonitoredEvents)
        {
            string methodName     = UnitTestHelper.GetMethodName();
            string fqTempFilename = string.Empty;
            string fqTestFilename = $"{Directory.GetCurrentDirectory()}/testdata/event/{testFilename}";

            fqTempFilename = $"{Directory.GetCurrentDirectory()}/tempdata/{methodName}_{testFilename}";
            if (File.Exists(fqTempFilename))
            {
                File.Delete(fqTempFilename);
            }
            File.Copy(fqTestFilename, fqTempFilename);
            PublisherNodeConfiguration.PublisherNodeConfigurationFilename = fqTempFilename;
            _output.WriteLine($"now testing: {PublisherNodeConfiguration.PublisherNodeConfigurationFilename}");
            Assert.True(File.Exists(PublisherNodeConfiguration.PublisherNodeConfigurationFilename));

            UnitTestHelper.SetPublisherDefaults();

            try
            {
                NodeConfiguration = PublisherNodeConfiguration.Instance;
                Assert.True(NodeConfiguration.OpcSessions.Count == configuredSessions, "wrong # of sessions");
                Assert.True(NodeConfiguration.NumberOfOpcSessionsConfigured == configuredSessions, "wrong # of sessions");
                Assert.True(NodeConfiguration.NumberOfOpcSubscriptionsConfigured == configuredSubscriptions, "wrong # of subscriptions");
                Assert.True(NodeConfiguration.NumberOfOpcEventMonitoredItemsConfigured == configuredMonitoredEvents, "wrong # of events");
                Assert.True(NodeConfiguration.NumberOfOpcDataChangeMonitoredItemsConfigured == configuredMonitoredItems, "wrong # of monitored items");
                _output.WriteLine($"sessions configured {NodeConfiguration.NumberOfOpcSessionsConfigured}, connected {NodeConfiguration.NumberOfOpcSessionsConnected}");
                _output.WriteLine($"subscriptions configured {NodeConfiguration.NumberOfOpcSubscriptionsConfigured}, connected {NodeConfiguration.NumberOfOpcSubscriptionsConnected}");
                _output.WriteLine($"items configured {NodeConfiguration.NumberOfOpcDataChangeMonitoredItemsConfigured}, monitored {NodeConfiguration.NumberOfOpcDataChangeMonitoredItemsMonitored}, " +
                                  $"toRemove {NodeConfiguration.NumberOfOpcDataChangeMonitoredItemsToRemove}, events configured {NodeConfiguration.NumberOfOpcEventMonitoredItemsConfigured}, " +
                                  $"monitored {NodeConfiguration.NumberOfOpcEventMonitoredItemsMonitored}");

                await NodeConfiguration.UpdateNodeConfigurationFileAsync().ConfigureAwait(false);

                _configurationFileEntries = new List <PublisherConfigurationFileEntryLegacyModel>();
                _configurationFileEntries = JsonConvert.DeserializeObject <List <PublisherConfigurationFileEntryLegacyModel> >(File.ReadAllText(PublisherNodeConfiguration.PublisherNodeConfigurationFilename));

                Assert.True(_configurationFileEntries[0].OpcEvents.Count == 1);
                Assert.True(_configurationFileEntries[0].OpcEvents[0].Id == "i=2253");
                Assert.True(_configurationFileEntries[0].OpcEvents[0].DisplayName == "SimpleEventServerEvents");
                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses.Count == 4);
                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[0].TypeId == "i=2041");
                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[0].IotCentralEventPublishMode ==
                            IotCentralEventPublishMode.Property);
                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[0].BrowsePaths[0] == "EventId");

                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[1].TypeId == "i=2041");
                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[1].IotCentralEventPublishMode ==
                            IotCentralEventPublishMode.Default);
                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[1].BrowsePaths[0] == "Message");

                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[2].TypeId == "nsu=http://opcfoundation.org/Quickstarts/SimpleEvents;i=235");
                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[2].IotCentralEventPublishMode ==
                            IotCentralEventPublishMode.Default);
                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[2].BrowsePaths[0] == "/2:CycleId");

                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[3].TypeId == "nsu=http://opcfoundation.org/Quickstarts/SimpleEvents;i=235");
                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[3].IotCentralEventPublishMode ==
                            IotCentralEventPublishMode.Default);
                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[3].BrowsePaths[0] == "/2:CurrentStep");

                Assert.True(_configurationFileEntries[0].OpcEvents[0].WhereClause.Count == 1);
                Assert.True(_configurationFileEntries[0].OpcEvents[0].WhereClause[0].Operator == "OfType");
                Assert.True(_configurationFileEntries[0].OpcEvents[0].WhereClause[0].Operands.Count == 1);
                Assert.True(_configurationFileEntries[0].OpcEvents[0].WhereClause[0].Operands[0].Literal == "ns=2;i=235");
            }
            finally
            {
                NodeConfiguration.Dispose();
                NodeConfiguration = null;
            }
        }
Beispiel #32
0
        /// <summary>
        /// Handles the NodeConfiguration packet.
        /// </summary>
        private void HandleNodeConfiguration(NodeConfiguration configuration)
        {
            // Grab the system parameters.
            _buildParameters = configuration.BuildParameters;

            _buildParameters.ProjectRootElementCache = s_projectRootElementCacheBase;

            // Snapshot the current environment
            _savedEnvironment = CommunicationsUtilities.GetEnvironmentVariables();

            // Change to the startup directory
            try
            {
                NativeMethodsShared.SetCurrentDirectory(BuildParameters.StartupDirectory);
            }
            catch (DirectoryNotFoundException)
            {
                // Somehow the startup directory vanished. This can happen if build was started from a USB Key and it was removed.
                NativeMethodsShared.SetCurrentDirectory(BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory);
            }

            // Replicate the environment.  First, unset any environment variables set by the previous configuration.
            if (_currentConfiguration != null)
            {
                foreach (string key in _currentConfiguration.BuildParameters.BuildProcessEnvironment.Keys)
                {
                    Environment.SetEnvironmentVariable(key, null);
                }
            }

            // Now set the new environment
            foreach (KeyValuePair <string, string> environmentPair in _buildParameters.BuildProcessEnvironment)
            {
                Environment.SetEnvironmentVariable(environmentPair.Key, environmentPair.Value);
            }

            // We want to make sure the global project collection has the toolsets which were defined on the parent
            // so that any custom toolsets defined can be picked up by tasks who may use the global project collection but are
            // executed on the child node.
            ICollection <Toolset> parentToolSets = _buildParameters.ToolsetProvider.Toolsets;

            if (parentToolSets != null)
            {
                ProjectCollection.GlobalProjectCollection.RemoveAllToolsets();

                foreach (Toolset toolSet in parentToolSets)
                {
                    ProjectCollection.GlobalProjectCollection.AddToolset(toolSet);
                }
            }

            // Set the culture.
            CultureInfo.CurrentCulture   = _buildParameters.Culture;
            CultureInfo.CurrentUICulture = _buildParameters.UICulture;

            // Get the node ID.
            _buildParameters.NodeId      = configuration.NodeId;
            _buildParameters.IsOutOfProc = true;

#if FEATURE_APPDOMAIN
            // And the AppDomainSetup
            _buildParameters.AppDomainSetup = configuration.AppDomainSetup;
#endif

            // Set up the logging service.
            LoggingServiceFactory loggingServiceFactory = new LoggingServiceFactory(LoggerMode.Asynchronous, configuration.NodeId);
            _componentFactories.ReplaceFactory(BuildComponentType.LoggingService, loggingServiceFactory.CreateInstance);

            _loggingService = _componentFactories.GetComponent(BuildComponentType.LoggingService) as ILoggingService;

            BuildEventArgTransportSink sink = new BuildEventArgTransportSink(SendPacket);

            _shutdownException = null;

            if (configuration.LoggingNodeConfiguration.IncludeEvaluationMetaprojects)
            {
                _loggingService.IncludeEvaluationMetaprojects = true;
            }
            if (configuration.LoggingNodeConfiguration.IncludeEvaluationProfiles)
            {
                _loggingService.IncludeEvaluationProfile = true;
            }

            if (configuration.LoggingNodeConfiguration.IncludeTaskInputs)
            {
                _loggingService.IncludeTaskInputs = true;
            }

            try
            {
                // If there are no node loggers to initialize dont do anything
                if (configuration.LoggerDescriptions?.Length > 0)
                {
                    _loggingService.InitializeNodeLoggers(configuration.LoggerDescriptions, sink, configuration.NodeId);
                }
            }
            catch (Exception ex)
            {
                if (ExceptionHandling.IsCriticalException(ex))
                {
                    throw;
                }

                OnEngineException(ex);
            }

            _loggingService.OnLoggingThreadException += OnLoggingThreadException;

            string   forwardPropertiesFromChild = Environment.GetEnvironmentVariable("MSBUILDFORWARDPROPERTIESFROMCHILD");
            string[] propertyListToSerialize    = null;

            // Get a list of properties which should be serialized
            if (!String.IsNullOrEmpty(forwardPropertiesFromChild))
            {
                propertyListToSerialize = forwardPropertiesFromChild.Split(MSBuildConstants.SemicolonChar, StringSplitOptions.RemoveEmptyEntries);
            }

            _loggingService.PropertiesToSerialize = propertyListToSerialize;
            _loggingService.RunningOnRemoteNode   = true;

            string forwardAllProperties = Environment.GetEnvironmentVariable("MSBUILDFORWARDALLPROPERTIESFROMCHILD");
            if (String.Equals(forwardAllProperties, "1", StringComparison.OrdinalIgnoreCase) || _buildParameters.LogInitialPropertiesAndItems)
            {
                _loggingService.SerializeAllProperties = true;
            }
            else
            {
                _loggingService.SerializeAllProperties = false;
            }

            // Now prep the buildRequestEngine for the build.
            _loggingContext = new NodeLoggingContext(_loggingService, configuration.NodeId, false /* inProcNode */);

            if (_shutdownException != null)
            {
                HandleShutdown(out Exception exception);
                throw exception;
            }

            _buildRequestEngine.InitializeForBuild(_loggingContext);

            // Finally store off this configuration packet.
            _currentConfiguration = configuration;
        }
Beispiel #33
0
        private SiloHandle _StartOrleansSilo(Silo.SiloType type, UnitTestSiloOptions options, AppDomain shared = null)
        {
            // Load initial config settings, then apply some overrides below.
            ClusterConfiguration config = new ClusterConfiguration();

            if (options.SiloConfigFile == null)
            {
                config.StandardLoad();
            }
            else
            {
                config.LoadFromFile(options.SiloConfigFile.FullName);
            }

            int basePort = options.BasePort >= 0 ? options.BasePort : BasePort;

            if (config.Globals.SeedNodes.Count > 0 && options.BasePort < 0)
            {
                config.PrimaryNode = config.Globals.SeedNodes[0];
            }
            else
            {
                config.PrimaryNode = new IPEndPoint(IPAddress.Loopback, basePort);
            }
            config.Globals.SeedNodes.Clear();
            config.Globals.SeedNodes.Add(config.PrimaryNode);

            if (!String.IsNullOrEmpty(DeploymentId))
            {
                config.Globals.DeploymentId = DeploymentId;
            }
            config.Defaults.PropagateActivityId = options.PropagateActivityId;
            if (options.LargeMessageWarningThreshold > 0)
            {
                config.Defaults.LargeMessageWarningThreshold = options.LargeMessageWarningThreshold;
            }

            config.Globals.LivenessType = options.LivenessType;

            globalConfig = config.Globals;

            string siloName;

            switch (type)
            {
            case Silo.SiloType.Primary:
                siloName = "Primary";
                break;

            default:
                siloName = "Secondary_" + InstanceCounter.ToString(CultureInfo.InvariantCulture);
                break;
            }

            NodeConfiguration nodeConfig = config.GetConfigurationForNode(siloName);

            nodeConfig.HostNameOrIPAddress = "loopback";
            nodeConfig.Port = basePort + InstanceCounter;
            nodeConfig.DefaultTraceLevel   = config.Defaults.DefaultTraceLevel;
            nodeConfig.PropagateActivityId = config.Defaults.PropagateActivityId;
            nodeConfig.BulkMessageLimit    = config.Defaults.BulkMessageLimit;

            config.Globals.ExpectedClusterSize = 2;

            config.Overrides[siloName] = nodeConfig;

            InstanceCounter++;

            Console.WriteLine("Starting a new silo in app domain {0} with config {1}", siloName, config.ToString(siloName));
            AppDomain appDomain;
            Silo      silo = _LoadSiloInNewAppDomain(siloName, type, config, out appDomain);

            silo.Start();

            SiloHandle retValue = new SiloHandle
            {
                Name      = siloName,
                Silo      = silo,
                Options   = options,
                Endpoint  = silo.SiloAddress.Endpoint,
                AppDomain = appDomain,
            };

            return(retValue);
        }
Beispiel #34
0
        /// <summary>Creates a new silo in a remote app domain and returns a handle to it.</summary>
        public static SiloHandle Create(string siloName, Silo.SiloType type, ClusterConfiguration config, NodeConfiguration nodeConfiguration, IDictionary <string, GeneratedAssembly> additionalAssemblies, string applicationBase = null)
        {
            AppDomainSetup setup = GetAppDomainSetupInfo(applicationBase);

            var appDomain = AppDomain.CreateDomain(siloName, null, setup);

            try
            {
                // Load each of the additional assemblies.
                AppDomainSiloHost.CodeGeneratorOptimizer optimizer = null;
                foreach (var assembly in additionalAssemblies.Where(asm => asm.Value != null))
                {
                    if (optimizer == null)
                    {
                        optimizer =
                            (AppDomainSiloHost.CodeGeneratorOptimizer)
                            appDomain.CreateInstanceAndUnwrap(
                                typeof(AppDomainSiloHost.CodeGeneratorOptimizer).Assembly.FullName, typeof(AppDomainSiloHost.CodeGeneratorOptimizer).FullName, false,
                                BindingFlags.Default,
                                null,
                                null,
                                CultureInfo.CurrentCulture,
                                new object[] { });
                    }

                    optimizer.AddCachedAssembly(assembly.Key, assembly.Value);
                }

                var args = new object[] { siloName, type, config };

                var siloHost = (AppDomainSiloHost)appDomain.CreateInstanceAndUnwrap(
                    typeof(AppDomainSiloHost).Assembly.FullName, typeof(AppDomainSiloHost).FullName, false,
                    BindingFlags.Default, null, args, CultureInfo.CurrentCulture,
                    new object[] { });

                appDomain.UnhandledException += ReportUnobservedException;

                siloHost.Start();

                var retValue = new AppDomainSiloHandle
                {
                    Name                 = siloName,
                    SiloHost             = siloHost,
                    NodeConfiguration    = nodeConfiguration,
                    SiloAddress          = siloHost.SiloAddress,
                    Type                 = type,
                    AppDomain            = appDomain,
                    additionalAssemblies = additionalAssemblies,
                    AppDomainTestHook    = siloHost.AppDomainTestHook,
                };

                retValue.ImportGeneratedAssemblies();

                return(retValue);
            }
            catch (Exception)
            {
                UnloadAppDomain(appDomain);
                throw;
            }
        }
 public OrleansTaskScheduler(GlobalConfiguration globalConfig, NodeConfiguration config)
     : this(config.MaxActiveThreads, config.DelayWarningThreshold, config.ActivationSchedulingQuantum,
            config.TurnWarningLengthThreshold, config.InjectMoreWorkerThreads, config.LimitManager.GetLimit(LimitNames.LIMIT_MAX_PENDING_ITEMS))
 {
 }
Beispiel #36
0
 public NodeInfoMessage(NodeConfiguration nodeConfiguration, Hash receiverNodeId) : base(NodeMessageTypes.NodeInfo, nodeConfiguration, receiverNodeId)
 {
 }
 public void OnConfigure(NodeConfiguration configuration)
 {
     _configurationAction(configuration);
 }
Beispiel #38
0
 public static void Init(ClusterConfiguration config, NodeConfiguration nodeConfig)
 {
     // Consider adding a config parameter for this
     maxRequestProcessingTime = config.Globals.ResponseTimeout.Multiply(5);
     nodeConfiguration        = nodeConfig;
 }
Beispiel #39
0
 public abstract void Validate(IElasticClient client, NodeConfiguration configuration);
Beispiel #40
0
        private SiloHandle StartOrleansSilo(Silo.SiloType type, TestingSiloOptions options, int instanceCount, AppDomain shared = null)
        {
            // Load initial config settings, then apply some overrides below.
            ClusterConfiguration config = new ClusterConfiguration();

            if (options.SiloConfigFile == null)
            {
                config.StandardLoad();
            }
            else
            {
                config.LoadFromFile(options.SiloConfigFile.FullName);
            }

            int basePort = options.BasePort < 0 ? BasePort : options.BasePort;


            if (config.Globals.SeedNodes.Count > 0 && options.BasePort < 0)
            {
                config.PrimaryNode = config.Globals.SeedNodes[0];
            }
            else
            {
                config.PrimaryNode = new IPEndPoint(IPAddress.Loopback, basePort);
            }
            config.Globals.SeedNodes.Clear();
            config.Globals.SeedNodes.Add(config.PrimaryNode);

            if (!String.IsNullOrEmpty(DeploymentId))
            {
                config.Globals.DeploymentId = DeploymentId;
            }
            config.Defaults.PropagateActivityId = options.PropagateActivityId;
            if (options.LargeMessageWarningThreshold > 0)
            {
                config.Defaults.LargeMessageWarningThreshold = options.LargeMessageWarningThreshold;
            }

            config.Globals.LivenessType        = options.LivenessType;
            config.Globals.ReminderServiceType = options.ReminderServiceType;
            if (!String.IsNullOrEmpty(options.DataConnectionString))
            {
                config.Globals.DataConnectionString = options.DataConnectionString;
            }

            _livenessStabilizationTime = GetLivenessStabilizationTime(config.Globals);

            string siloName;

            switch (type)
            {
            case Silo.SiloType.Primary:
                siloName = "Primary";
                break;

            default:
                siloName = "Secondary_" + instanceCount.ToString(CultureInfo.InvariantCulture);
                break;
            }

            NodeConfiguration nodeConfig = config.GetConfigurationForNode(siloName);

            nodeConfig.HostNameOrIPAddress = "loopback";
            nodeConfig.Port = basePort + instanceCount;
            nodeConfig.DefaultTraceLevel   = config.Defaults.DefaultTraceLevel;
            nodeConfig.PropagateActivityId = config.Defaults.PropagateActivityId;
            nodeConfig.BulkMessageLimit    = config.Defaults.BulkMessageLimit;

            if (nodeConfig.ProxyGatewayEndpoint != null && nodeConfig.ProxyGatewayEndpoint.Address != null)
            {
                nodeConfig.ProxyGatewayEndpoint = new IPEndPoint(nodeConfig.ProxyGatewayEndpoint.Address, ProxyBasePort + instanceCount);
            }

            config.Globals.ExpectedClusterSize = 2;

            config.Overrides[siloName] = nodeConfig;

            AdjustForTest(config);

            WriteLog("Starting a new silo in app domain {0} with config {1}", siloName, config.ToString(siloName));
            AppDomain appDomain;
            Silo      silo = LoadSiloInNewAppDomain(siloName, type, config, out appDomain);

            silo.Start();

            SiloHandle retValue = new SiloHandle
            {
                Name      = siloName,
                Silo      = silo,
                Options   = options,
                Endpoint  = silo.SiloAddress.Endpoint,
                AppDomain = appDomain,
            };

            ImportGeneratedAssemblies(retValue);
            return(retValue);
        }
Beispiel #41
0
 public static string ToRootSelectionPath(this NodeConfiguration adr)
 {
     return($"akka.tcp://{adr.Name}@{adr.Address.Host}:{adr.Address.PortNumber}/user");
 }
 public void OnStartup(NodeConfiguration configuration)
 {
     configuration
         .WcfProxyFactory
         .Consume<IUserService>(Bound.To(new BasicHttpBinding()).AtUrl(Configured.From.AppSettings("UserServiceUrl")));
 }
Beispiel #43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OrleansFabricEndpoints" /> class.
 /// </summary>
 /// <param name="config">
 /// The node configuration to initialize from.
 /// </param>
 public OrleansFabricEndpoints(NodeConfiguration config)
 {
     this.Silo    = SiloAddress.New(config.Endpoint, config.Generation).ToParsableString();
     this.Gateway = SiloAddress.New(config.ProxyGatewayEndpoint, config.Generation).ToParsableString();
 }
Beispiel #44
0
 private SiloHandle StartOrleansSilo(Silo.SiloType type, ClusterConfiguration clusterConfig, NodeConfiguration nodeConfig)
 {
     return(StartOrleansSilo(this, type, clusterConfig, nodeConfig));
 }
Beispiel #45
0
        /// <summary>
        /// Start a new silo in the target cluster
        /// </summary>
        /// <param name="cluster">The TestCluster in which the silo should be deployed</param>
        /// <param name="type">The type of the silo to deploy</param>
        /// <param name="clusterConfig">The cluster config to use</param>
        /// <param name="nodeConfig">The configuration for the silo to deploy</param>
        /// <returns>A handle to the silo deployed</returns>
        public static SiloHandle StartOrleansSilo(TestCluster cluster, Silo.SiloType type, ClusterConfiguration clusterConfig, NodeConfiguration nodeConfig)
        {
            if (cluster == null)
            {
                throw new ArgumentNullException(nameof(cluster));
            }
            var siloName = nodeConfig.SiloName;

            cluster.WriteLog("Starting a new silo in app domain {0} with config {1}", siloName, clusterConfig.ToString(siloName));
            var handle = cluster.LoadSiloInNewAppDomain(siloName, type, clusterConfig, nodeConfig);

            return(handle);
        }
 public void OnStartup(NodeConfiguration configuration)
 {
     _startupAction(configuration);
 }
Beispiel #47
0
        /// <summary>
        /// Handle method call to get list of configured nodes on a specific endpoint.
        /// </summary>
        public virtual Task <MethodResponse> HandleGetConfiguredEventsOnEndpointMethodAsync(MethodRequest methodRequest, object userContext)
        {
            const string logPrefix    = "HandleGetConfiguredEventsOnEndpointMethodAsync:";
            Guid         endpointId   = Guid.Empty;
            string       endpointName = null;
            string       endpointUrl  = null;
            GetConfiguredNodesOnEndpointMethodRequestModel getConfiguredEventNodesOnEndpointMethodRequest = null;
            uint nodeConfigVersion = 0;
            GetConfiguredEventNodesOnEndpointMethodResponseModel getConfiguredEventNodesOnEndpointMethodResponse = new GetConfiguredEventNodesOnEndpointMethodResponseModel();
            uint   actualNodeCount         = 0;
            uint   availableEventNodeCount = 0;
            var    opcEvents      = new List <OpcEventOnEndpointModel>();
            uint   startIndex     = 0;
            var    statusCode     = HttpStatusCode.OK;
            var    statusResponse = new List <string>();
            string statusMessage;

            try
            {
                Logger.Debug($"{logPrefix} called");
                getConfiguredEventNodesOnEndpointMethodRequest = JsonConvert.DeserializeObject <GetConfiguredNodesOnEndpointMethodRequestModel>(methodRequest.DataAsJson);
                if (getConfiguredEventNodesOnEndpointMethodRequest.EndpointId == null)
                {
                    statusMessage = $"New endpoint: there are no event nodes configured";
                    Logger.Information($"{logPrefix} {statusMessage}");
                    statusResponse.Add(statusMessage);
                    statusCode = HttpStatusCode.NoContent;
                }
                else
                {
                    endpointId = new Guid(getConfiguredEventNodesOnEndpointMethodRequest.EndpointId);
                }
            }
            catch (FormatException e)
            {
                statusMessage = $"Exception ({e.Message}) while parsing EndpointId '{getConfiguredEventNodesOnEndpointMethodRequest?.EndpointId}'";
                Logger.Error(e, $"{logPrefix} {statusMessage}");
                statusResponse.Add(statusMessage);
                statusCode = HttpStatusCode.InternalServerError;
            }
            catch (Exception e)
            {
                statusMessage = $"Exception ({e.Message}) while deserializing message payload";
                Logger.Error(e, $"{logPrefix} Exception");
                statusResponse.Add(statusMessage);
                statusCode = HttpStatusCode.InternalServerError;
            }

            if (statusCode == HttpStatusCode.OK)
            {
                // get the list of published nodes for the endpoint
                List <PublisherConfigurationFileEntryModel> configFileEntries = NodeConfiguration.GetPublisherConfigurationFileEntries(endpointId, false, out nodeConfigVersion);

                // return if there are no nodes configured for this endpoint
                if (configFileEntries.Count == 0)
                {
                    statusMessage = $"There are no event nodes configured for endpoint '{endpointId.ToString()}'";
                    Logger.Information($"{logPrefix} {statusMessage}");
                    statusResponse.Add(statusMessage);
                    statusCode = HttpStatusCode.NoContent;
                }
                else
                {
                    endpointName = configFileEntries.First().EndpointName;
                    endpointUrl  = configFileEntries.First().EndpointUrl.ToString();
                    foreach (var configFileEntry in configFileEntries)
                    {
                        if (configFileEntry?.OpcEvents != null)
                        {
                            opcEvents.AddRange(configFileEntry.OpcEvents);
                        }
                    }
                    uint configuredEventNodesOnEndpointCount = (uint)opcEvents.Count();

                    // validate version
                    startIndex = 0;
                    if (getConfiguredEventNodesOnEndpointMethodRequest?.ContinuationToken != null)
                    {
                        uint requestedNodeConfigVersion = (uint)(getConfiguredEventNodesOnEndpointMethodRequest.ContinuationToken >> 32);
                        if (nodeConfigVersion != requestedNodeConfigVersion)
                        {
                            statusMessage = $"The event node configuration has changed between calls. Requested version: {requestedNodeConfigVersion:X8}, Current version '{nodeConfigVersion:X8}'!";
                            Logger.Information($"{logPrefix} {statusMessage}");
                            statusResponse.Add(statusMessage);
                            statusCode = HttpStatusCode.Gone;
                        }
                        startIndex = (uint)(getConfiguredEventNodesOnEndpointMethodRequest.ContinuationToken & 0x0FFFFFFFFL);
                    }

                    if (statusCode == HttpStatusCode.OK)
                    {
                        // set count
                        var requestedEventNodeCount = configuredEventNodesOnEndpointCount - startIndex;
                        availableEventNodeCount = configuredEventNodesOnEndpointCount - startIndex;
                        actualNodeCount         = Math.Min(requestedEventNodeCount, availableEventNodeCount);
                        opcEvents.ForEach(x => x.OpcPublisherPublishState = OpcPublisherPublishState.Published);

                        // generate response
                        while (true)
                        {
                            string publishedNodesString    = JsonConvert.SerializeObject(opcEvents.GetRange((int)startIndex, (int)actualNodeCount));
                            var    publishedNodesByteArray = Encoding.UTF8.GetBytes(publishedNodesString);
                            if (publishedNodesByteArray.Length > MaxResponsePayloadLength)
                            {
                                actualNodeCount /= 2;
                                continue;
                            }

                            break;
                        }
                    }
                }
            }

            // build response
            string resultString;

            if (statusCode == HttpStatusCode.OK)
            {
                getConfiguredEventNodesOnEndpointMethodResponse.ContinuationToken = null;
                if (actualNodeCount < availableEventNodeCount)
                {
                    getConfiguredEventNodesOnEndpointMethodResponse.ContinuationToken = (ulong)nodeConfigVersion << 32 | actualNodeCount + startIndex;
                }

                // Todo: check if EventConfigurationModel mit endpointName = endpointUrl = null ok?
                getConfiguredEventNodesOnEndpointMethodResponse.EventNodes
                .AddRange(opcEvents
                          .GetRange((int)startIndex, (int)actualNodeCount)
                          .Select(n =>
                                  new OpcEventOnEndpointModel(
                                      new EventConfigurationModel(
                                          endpointId.ToString(),
                                          endpointName,
                                          endpointUrl,
                                          null,
                                          OpcAuthenticationMode.Anonymous,
                                          null,
                                          n.Id,
                                          n.DisplayName,
                                          n.SelectClauses,
                                          n.WhereClause,
                                          n.IotCentralEventPublishMode
                                          ),
                                      OpcPublisherPublishState.Published
                                      )
                                  )
                          );
                getConfiguredEventNodesOnEndpointMethodResponse.EndpointId = endpointId.ToString();
                resultString = JsonConvert.SerializeObject(getConfiguredEventNodesOnEndpointMethodResponse);
                Logger.Information($"{logPrefix} Success returning {actualNodeCount} event node(s) of {availableEventNodeCount} (start: {startIndex}) (node config version: {nodeConfigVersion:X8})!");
            }
            else if (statusCode == HttpStatusCode.NoContent)
            {
                resultString = JsonConvert.SerializeObject(getConfiguredEventNodesOnEndpointMethodResponse);
                Logger.Information($"{logPrefix} Success returning 0 event nodes.");
            }
            else
            {
                resultString = JsonConvert.SerializeObject(statusResponse);
            }
            byte[] result = Encoding.UTF8.GetBytes(resultString);
            if (result.Length > MaxResponsePayloadLength)
            {
                Logger.Error($"{logPrefix} Response size is too long");
                Array.Resize(ref result, result.Length > MaxResponsePayloadLength ? MaxResponsePayloadLength : result.Length);
            }
            MethodResponse methodResponse = new MethodResponse(result, (int)statusCode);

            Logger.Information($"{logPrefix} completed with result {statusCode.ToString()}");
            return(Task.FromResult(methodResponse));
        }