Exemplo n.º 1
0
        private StitchInstance CreateSingleNewInstanceInternal(PackageFile packageFile, LocalCreateInstanceRequest request)
        {
            // Insert the new instance to the data module
            var instance = new StitchInstanceMapper(_core.NodeId, _core.Name).Map(request);

            instance = _data.Insert(instance);
            if (instance == null)
            {
                _log.LogError("Could not save new stitch instance");
                return(null);
            }

            if (packageFile.Adaptor.RequiresPackageUnzip)
            {
                // Unzip a copy of the version from the library into the running base
                var result = _fileSystem.UnzipLibraryPackageToRunningBase(instance.GroupName, instance.Id);
                if (!result.Success)
                {
                    _log.LogError("Could not unzip library package for new stitch {0}", instance.GroupName);
                    return(null);
                }
                // TODO: We should move this into a class specific to ProcessV1 types.
                _data.Update <PackageFile>(packageFile.Id, pf => pf.Adaptor.Parameters[Parameters.RunningDirectory] = result.Path);
            }

            _data.Save(instance);
            _log.LogInformation("Created stitch instance Id={0} GroupName={1}", instance.Id, request.GroupName);
            _notifier.StitchCreated(instance);

            // StitchInstanceManager auto-creates the necessary adaptor on Start. We don't need to do anything for it here.
            return(instance);
        }
Exemplo n.º 2
0
        public void StitchInstancesOnStitchStateChanged(object sender, StitchProcessEventArgs e)
        {
            var channel = e.IsRunning ? StitchInstanceEvent.ChannelStarted : StitchInstanceEvent.ChannelStopped;

            _messageBus.Publish(channel, new StitchInstanceEvent
            {
                InstanceId = e.InstanceId
            });

            _log.LogInformation("Stitch instance {0} is {1}", e.InstanceId, e.IsRunning ? "started" : "stopped");
        }
Exemplo n.º 3
0
        public void StitchStateChanged(string instanceId, bool isRunning, bool wasRequested)
        {
            var channel = isRunning ? StitchInstanceEvent.ChannelStarted : StitchInstanceEvent.ChannelStopped;

            _messageBus.Publish(channel, new StitchInstanceEvent
            {
                InstanceId = instanceId
            });

            _log.LogInformation("Stitch instance {0} is {1}", instanceId, isRunning ? "started" : "stopped");
            if (isRunning == false)
            {
                _data.Update <StitchInstance>(instanceId, instance => instance.State = InstanceStateType.Stopped);
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var nodeConfig = NodeConfiguration.GetDefault();

            nodeConfig.NodeId   = "ServerA";
            nodeConfig.NodeName = "StitchIntegration.ServerA";
            using (var core = new CrossStitchCore(nodeConfig))
            {
                Console.Title = core.Name;
                _testLog      = new ModuleLog(core.MessageBus, "ServerA");
                core.AddModule(new BackplaneModule(core));
                core.AddModule(new StitchesModule(core));
                var logger = new LoggerFactory().AddConsole(LogLevel.Debug).CreateLogger <Program>();
                core.AddModule(new LoggingModule(core, logger));

                core.Start();

                _testLog.LogInformation("Waiting for ServerB");
                // Wait until we get a node joined event with ServerB. Kick off the test and unsubscribe
                core.MessageBus.Subscribe <ClusterMemberEvent>(b => b
                                                               .WithTopic(ClusterMemberEvent.EnteringEvent)
                                                               .Invoke(m => TestStep1(core.MessageBus, m.NodeId, m.NetworkNodeId))
                                                               .OnThreadPool()
                                                               .MaximumEvents(1));

                Console.ReadKey();

                core.Stop();
            }
        }
Exemplo n.º 5
0
        private static void TestStep1(IMessageBus messageBus, string serverBNodeId, string serverBNetworkId)
        {
            Thread.Sleep(5000);
            _testLog.LogInformation("ServerB has joined the cluster.");

            // Zip up the Stitch.js file
            _testLog.LogInformation("Zipping the stitch");
            var stream = new MemoryStream();

            using (var zip = new ZipArchive(stream, ZipArchiveMode.Create, true))
            {
                var entry = zip.CreateEntry("Stitch.js");

                using (var entryStream = entry.Open())
                    using (var writer = new StreamWriter(entryStream))
                    {
                        writer.Write(File.ReadAllText(".\\Stitch.js"));
                    }
            }
            stream.Seek(0, SeekOrigin.Begin);

            // Subscribe to the Job complete event, so we can move to the next step as soon as it is ready
            messageBus.Subscribe <JobCompleteEvent>(b => b
                                                    .WithTopic(JobCompleteEvent.ChannelSuccess)
                                                    .Invoke(m => TestStep2(messageBus, m))
                                                    .OnThreadPool()
                                                    .MaximumEvents(1));

            // "Upload" the stitch file to ServerA, which will broadcast to ServerB
            _testLog.LogInformation("Uploading the Stitch.zip package file");
            var response = messageBus.RequestWait <PackageFileUploadRequest, PackageFileUploadResponse>(new PackageFileUploadRequest
            {
                Contents  = stream,
                FileName  = "Stitch.zip",
                GroupName = new StitchGroupName("StitchIntegration.Stitch"),
                LocalOnly = false,
                Adaptor   = new InstanceAdaptorDetails
                {
                    RequiresPackageUnzip = true,
                    Type       = AdaptorType.ProcessV1,
                    Parameters = new Dictionary <string, string>
                    {
                        { Parameters.ArgumentsFormat, "{ExecutableName} {CoreArgs} -- {CustomArgs}" },
                        { Parameters.ExecutableFormat, "C:\\Program Files\\nodejs\\node.exe" },
                        { Parameters.ExecutableName, "Stitch.js" }
                    }
                },
            });

            _groupName = response.GroupName;
            _testLog.LogInformation("Uploaded version {0}", _groupName);

            if (!response.IsSuccess)
            {
                _testLog.LogError("Could not upload package file");
            }
        }