Example #1
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 logger = new LoggerFactory().AddConsole(LogLevel.Debug).CreateLogger <Program>();
                core.AddModule(new LoggingModule(core, logger));

                core.Start();

                // First stitch is a Process, using STDIO
                StartProcessStitch(core, "Stdio", MessageChannelType.Stdio);

                // Second stitch is a Process using Pipes
                StartProcessStitch(core, "Pipes", MessageChannelType.Pipe);

                // Second stitch is a built -in class
                StartBuiltinStitch(core);

                Console.ReadKey();
                core.Stop();
            }
        }
Example #2
0
        private 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 logger = new LoggerFactory().AddConsole(LogLevel.Debug).CreateLogger <Program>();
                core.AddModule(new LoggingModule(core, logger));

                core.MessageBus.Subscribe <StitchHealthEvent>(b => b
                                                              .WithTopic(StitchHealthEvent.TopicUnhealthy)
                                                              .Invoke(e => core.Log.LogInformation("Stitch {0} is unhealthy", e.InstanceId)));
                core.MessageBus.Subscribe <StitchHealthEvent>(b => b
                                                              .WithTopic(StitchHealthEvent.TopicReturnToHealth)
                                                              .Invoke(e => core.Log.LogInformation("Stitch {0} is Healthy again", e.InstanceId)));

                core.Start();

                StartBuiltinStitch(core);

                Console.ReadKey();
                core.Stop();
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            var nodeConfig = NodeConfiguration.GetDefault();

            using (var core = new CrossStitchCore(nodeConfig))
            {
                // Setup an in-memory data store
                var store = new InMemoryDataStorage();
                core.AddModule(new DataModule(core.MessageBus, store));

                // Backplane so we can cluster
                core.AddModule(new BackplaneModule(core));

                // Stitches so we can host the stitch instances
                var stitchesConfig = StitchesConfiguration.GetDefault();
                core.AddModule(new StitchesModule(core, stitchesConfig));

                // Setup logging.
                var logger = new LoggerFactory().AddConsole(LogLevel.Debug).CreateLogger <Program>();
                core.AddModule(new LoggingModule(core, logger));

                // Create a stitch instance to run on startup
                var groupName   = new StitchGroupName("PenPal.StitchA.1");
                var packageFile = new PackageFile
                {
                    Id        = groupName.ToString(),
                    GroupName = groupName,
                    Adaptor   = new InstanceAdaptorDetails
                    {
                        Type       = AdaptorType.ProcessV1,
                        Parameters = new Dictionary <string, string>
                        {
                            { Parameters.RunningDirectory, "." },
                            { Parameters.ExecutableArguments, "" },
                            { Parameters.ExecutableName, "PenPal.StitchA.exe" }
                        }
                    },
                };
                store.Save(packageFile, true);
                var stitch = new StitchInstance
                {
                    Name          = "StitchA",
                    GroupName     = groupName,
                    OwnerNodeName = core.Name,
                    OwnerNodeId   = core.NodeId,
                    State         = InstanceStateType.Running
                };
                store.Save(stitch, true);

                core.Start();

                Console.ReadKey();

                core.Stop();
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            var nodeConfig = NodeConfiguration.GetDefault();


            using (var core = new CrossStitchCore(nodeConfig))
            {
                var httpServer = new NancyHttpModule(core.MessageBus);
                core.AddModule(httpServer);

                var dataStorage = new InMemoryDataStorage();
                var data        = new DataModule(core.MessageBus, dataStorage);
                core.AddModule(data);

                var stitchesConfiguration = StitchesConfiguration.GetDefault();
                var stitches = new StitchesModule(core, stitchesConfiguration);
                core.AddModule(stitches);

                var groupName = new StitchGroupName("HttpTest", "Stitch", "1");

                var packageFile = new PackageFile
                {
                    Id        = groupName.ToString(),
                    GroupName = groupName,
                    Adaptor   = new InstanceAdaptorDetails
                    {
                        Type       = AdaptorType.ProcessV1,
                        Parameters = new Dictionary <string, string>
                        {
                            { Parameters.RunningDirectory, "." },
                            { Parameters.ExecutableName, "HttpTest.Stitch.exe" },
                            //{ Parameters.ArgumentsFormat, "{ExecutableName} {CoreArgs} -- {CustomArgs}" },
                            //{ Parameters.ExecutableFormat, "dotnet" },
                        }
                    },
                };
                dataStorage.Save(packageFile, true);
                var stitch = new StitchInstance
                {
                    Name      = "HttpTest.Stitch",
                    GroupName = groupName,

                    State = InstanceStateType.Running
                };
                dataStorage.Save(stitch, true);

                var logger = new LoggerFactory().AddConsole(LogLevel.Debug).CreateLogger <Program>();
                core.AddModule(new LoggingModule(core, logger));

                core.Log.LogInformation("Started");
                core.Start();
                Console.ReadKey();
                core.Stop();
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            var nodeConfig = NodeConfiguration.GetDefault();

            using (var core = new CrossStitchCore(nodeConfig))
            {
                var httpServer = new NancyHttpModule(core.MessageBus);
                core.AddModule(httpServer);

                var dataStorage = new InMemoryDataStorage();
                var data        = new DataModule(core.MessageBus, dataStorage);
                core.AddModule(data);

                var stitchesConfiguration = StitchesConfiguration.GetDefault();
                var stitches = new StitchesModule(core, stitchesConfiguration);
                core.AddModule(stitches);

                var groupName = new StitchGroupName("HttpTest", "Stitch", "1");

                var packageFile = new PackageFile
                {
                    Id        = groupName.ToString(),
                    GroupName = groupName,
                    Adaptor   = new InstanceAdaptorDetails
                    {
                        Type       = AdaptorType.ProcessV1,
                        Parameters = new Dictionary <string, string>
                        {
                            { CrossStitch.Stitch.ProcessV1.Parameters.DirectoryPath, "." },
                            { CrossStitch.Stitch.ProcessV1.Parameters.ExecutableName, "HttpTest.Stitch.exe" }
                        }
                    },
                };
                dataStorage.Save(packageFile, true);
                var stitch = new StitchInstance
                {
                    Name      = "HttpTest.Stitch",
                    GroupName = groupName,

                    State = InstanceStateType.Running,
                    LastHeartbeatReceived = 0
                };
                dataStorage.Save(stitch, true);

                core.AddModule(new LoggingModule(core, Common.Logging.LogManager.GetLogger("CrossStitch")));

                core.Start();
                Console.ReadKey();
                core.Stop();
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            var config = NodeConfiguration.GetDefault();

            using (var core = new CrossStitchCore(config))
            {
                var dataStorage = new InMemoryDataStorage();
                var groupName   = new StitchGroupName("JsStitch", "Stitch", "1");
                dataStorage.Save(new PackageFile
                {
                    Id        = groupName.ToString(),
                    GroupName = groupName,
                    Adaptor   = new InstanceAdaptorDetails
                    {
                        Type       = AdaptorType.ProcessV1,
                        Parameters = new Dictionary <string, string>
                        {
                            { Parameters.RunningDirectory, "." },
                            { Parameters.ExecutableName, "JsStitch.Stitch.js" }
                        }
                    },
                }, true);
                dataStorage.Save(new StitchInstance
                {
                    Name      = "JsStitch.Stitch",
                    GroupName = groupName,
                    State     = InstanceStateType.Running
                }, true);

                var data = new DataModule(core.MessageBus, dataStorage);
                core.AddModule(data);

                var stitchesConfiguration = StitchesConfiguration.GetDefault();
                var stitches = new StitchesModule(core, stitchesConfiguration);
                core.AddModule(stitches);

                var logger = new LoggerFactory().AddConsole(LogLevel.Debug).CreateLogger <Program>();
                core.AddModule(new LoggingModule(core, logger));

                core.Start();
                Console.ReadKey();
                core.Stop();
            }
        }
Example #7
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();
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            var config = NodeConfiguration.GetDefault();

            using (var core = new CrossStitchCore(config))
            {
                var dataStorage = new InMemoryDataStorage();

                var pingGroup   = new StitchGroupName("PingPong", "Ping", "1");
                var pingPackage = new PackageFile
                {
                    Id        = pingGroup.ToString(),
                    GroupName = pingGroup,
                    Adaptor   = new InstanceAdaptorDetails
                    {
                        Type       = AdaptorType.ProcessV1,
                        Parameters = new Dictionary <string, string>
                        {
                            { Parameters.RunningDirectory, "." },
                            { Parameters.ExecutableName, "PingPong.Ping.exe" }
                        }
                    },
                };
                var ping = new StitchInstance
                {
                    Name      = "PingPong.Ping",
                    GroupName = pingGroup,
                    State     = InstanceStateType.Running
                };

                var pongGroup   = new StitchGroupName("PingPong", "Pong", "1");
                var pongPackage = new PackageFile
                {
                    Id        = pongGroup.ToString(),
                    GroupName = pongGroup,
                    Adaptor   = new InstanceAdaptorDetails
                    {
                        Type       = AdaptorType.ProcessV1,
                        Parameters = new Dictionary <string, string>
                        {
                            { Parameters.RunningDirectory, "." },
                            { Parameters.ExecutableName, "PingPong.Pong.exe" }
                        }
                    },
                };
                var pong = new StitchInstance
                {
                    Name      = "PingPong.Pong",
                    GroupName = pongGroup,
                    State     = InstanceStateType.Running
                };

                dataStorage.Save(pingPackage, true);
                dataStorage.Save(ping, true);
                dataStorage.Save(pongPackage, true);
                dataStorage.Save(pong, true);

                var data = new DataModule(core.MessageBus, dataStorage);
                core.AddModule(data);

                var stitchesConfiguration = StitchesConfiguration.GetDefault();
                var stitches = new StitchesModule(core, stitchesConfiguration);
                core.AddModule(stitches);

                var logger = new LoggerFactory().AddConsole(LogLevel.Debug).CreateLogger <Program>();
                core.AddModule(new LoggingModule(core, logger));

                // TODO: We need a way to start for initialization to complete, either having Start
                // block or providing an Initialized event which waits for all modules to report
                // being initialized
                core.Start();

                Console.ReadKey();
                core.Stop();
            }
        }