Exemple #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();
            }
        }
Exemple #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();
            }
        }
Exemple #3
0
 public StitchAdaptorFactory(CrossStitchCore core, StitchesConfiguration configuration, StitchFileSystem fileSystem, IModuleLog log, IStitchEventObserver observer)
 {
     _core          = core;
     _configuration = configuration;
     _fileSystem    = fileSystem;
     _log           = log;
     _observer      = observer;
 }
Exemple #4
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();
            }
        }
Exemple #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>
                        {
                            { 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();
            }
        }
Exemple #6
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();
            }
        }
        public ProcessParameters(StitchesConfiguration configuration, StitchFileSystem fileSystem, StitchInstance stitch, PackageFile packageFile)
        {
            var parameters = packageFile.Adaptor.Parameters;
            // Use the dir if specified, otherwise default to the running dir from the file system
            var defaultRunningDir = fileSystem.GetInstanceRunningDirectory(stitch.Id);

            RunningDirectory = parameters.GetOrAdd(Parameters.RunningDirectory, defaultRunningDir);

            var defaultDataDir = fileSystem.GetInstanceDataDirectoryPath(stitch.Id);

            DataDirectory = parameters.GetOrAdd(Parameters.DataDirectory, defaultDataDir);

            // Executable name must be specified. Get it and validate
            ExecutableName = parameters.GetOrDefault(Parameters.ExecutableName);
            if (string.IsNullOrEmpty(ExecutableName))
            {
                throw new Exception("Stitch executable name is not specified");
            }

            // Custom args are optional
            ExecutableArguments = parameters.GetOrAdd(Parameters.ExecutableArguments, "") ?? "";

            string executableExt = Path.GetExtension(ExecutableName).ToLower();
            var    extConfig     = configuration.Extensions.GetOrDefault(executableExt, new StitchesExtensionConfiguration());

            // Use the format from the StitchInstance if specified, otherwise the one configured
            // for the extension, otherwise fall back to the default.
            string executableFormat = "{DirectoryPath}\\{ExecutableName}";

            if (!string.IsNullOrEmpty(extConfig.ExecutableFormat))
            {
                executableFormat = extConfig.ExecutableFormat;
            }
            executableFormat = FileSystem.FixPath(executableFormat);
            ExecutableFormat = parameters.GetOrAdd(Parameters.ExecutableFormat, executableFormat);

            // Use the format from the StitchInstance if specified, otherwise the one configured
            // for the extension, otherwise fall back to the default.
            string argsFormat = "{CoreArgs} -- {CustomArgs}";

            if (!string.IsNullOrEmpty(extConfig.ArgumentsFormat))
            {
                argsFormat = extConfig.ArgumentsFormat;
            }
            argsFormat      = FileSystem.FixPath(argsFormat);
            ArgumentsFormat = parameters.GetOrAdd(Parameters.ArgumentsFormat, argsFormat);

            ChannelType    = packageFile.Adaptor.Channel;
            SerializerType = packageFile.Adaptor.Serializer;
        }
Exemple #8
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();
            }
        }
        public ProcessStitchAdaptor(CrossStitchCore core, StitchesConfiguration configuration, StitchInstance stitchInstance, IStitchEventObserver observer, ProcessParameters parameters, IModuleLog log)
        {
            Assert.ArgNotNull(core, nameof(core));
            Assert.ArgNotNull(configuration, nameof(configuration));
            Assert.ArgNotNull(stitchInstance, nameof(stitchInstance));
            Assert.ArgNotNull(observer, nameof(observer));
            Assert.ArgNotNull(parameters, nameof(parameters));
            Assert.ArgNotNull(log, nameof(log));

            _core           = core;
            _stitchInstance = stitchInstance;
            _observer       = observer;
            _parameters     = parameters;
            _log            = log;

            _channelFactory    = new CoreMessageChannelFactory(core.NodeId, stitchInstance.Id);
            _serializerFactory = new MessageSerializerFactory();
            _processFactory    = new ProcessFactory(stitchInstance, core, log);
            _stopRequested     = false;
        }
        public ProcessV1Parameters(StitchesConfiguration configuration, StitchFileSystem fileSystem, StitchInstance stitch, Dictionary <string, string> parameters)
        {
            // Use the dir if specified, otherwise default to the running dir from the file system
            var defaultRunningDir = fileSystem.GetInstanceRunningDirectory(stitch.Id);

            DirectoryPath = parameters.GetOrAdd(Parameters.DirectoryPath, defaultRunningDir);

            // Executable name must be specified. Get it and validate
            ExecutableName = parameters.GetOrDefault(Parameters.ExecutableName);
            if (string.IsNullOrEmpty(ExecutableName))
            {
                throw new Exception("Stitch executable name is not specified");
            }

            // Custom args are optional
            ExecutableArguments = parameters.GetOrAdd(Parameters.ExecutableArguments, "") ?? "";

            string executableExt = Path.GetExtension(ExecutableName).ToLower();
            var    extConfig     = configuration.Extensions.GetOrDefault(executableExt, new StitchesExtensionConfiguration());

            // Use the format from the StitchInstance if specified, otherwise the one configured
            // for the extension, otherwise fall back to the default.
            string executableFormat = "{DirectoryPath}\\{ExecutableName}";

            if (!string.IsNullOrEmpty(extConfig.ExecutableFormat))
            {
                executableFormat = extConfig.ExecutableFormat;
            }
            ExecutableFormat = parameters.GetOrAdd(Parameters.ExecutableFormat, executableFormat);

            // Use the format from the StitchInstance if specified, otherwise the one configured
            // for the extension, otherwise fall back to the default.
            string argsFormat = "{CoreArgs} -- {CustomArgs}";

            if (!string.IsNullOrEmpty(extConfig.ArgumentsFormat))
            {
                argsFormat = extConfig.ArgumentsFormat;
            }
            ArgumentsFormat = parameters.GetOrAdd(Parameters.ArgumentsFormat, argsFormat);
        }
Exemple #11
0
        public ProcessV1StitchAdaptor(StitchesConfiguration configuration, StitchInstance stitchInstance, CoreStitchContext stitchContext, ProcessV1Parameters parameters)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (stitchInstance == null)
            {
                throw new ArgumentNullException(nameof(stitchInstance));
            }
            if (stitchContext == null)
            {
                throw new ArgumentNullException(nameof(stitchContext));
            }
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            _stitchInstance = stitchInstance;
            StitchContext   = stitchContext;
            _parameters     = parameters;
            _configuration  = configuration;
        }
Exemple #12
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();
            }
        }
Exemple #13
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();
            }
        }
 public StitchAdaptorFactory(StitchesConfiguration configuration, StitchFileSystem fileSystem)
 {
     _configuration = configuration;
     _fileSystem    = fileSystem;
 }