public System.Diagnostics.Process Create(ProcessParameters parameters) { var process = CreateNewProcessInternal(parameters); try { if (!process.Start()) { _log.LogError("Process could not be started but there was no error. The process may already exist."); process.Dispose(); return(null); } return(process); } catch (Exception e) { var sb = new StringBuilder(); sb.AppendLine("Process could not be started because of an error"); sb.AppendLine($" FileName={process.StartInfo.FileName}"); sb.AppendLine($" CurrentDirectory={System.IO.Directory.GetCurrentDirectory()}"); _log.LogError(e, sb.ToString()); return(null); } }
public bool Start() { try { //var data = _stitchInstance.GetAdaptorDataObject<ProcessAdaptorData>() ?? new ProcessAdaptorData(); // TODO: Need a strategy to handle a zombified child process from the previous attempt // Do we try to re-attach? Force-kill it? Alert? Wait? //if (data.Pid > 0) // _process = AttachExistingProcess(data.Pid, _parameters.ChannelType); //if (_process == null) _process = _processFactory.Create(_parameters); if (_process == null) { _log.LogError("Could not create process"); return(false); } _process.Exited += ProcessOnExited; PersistProcessData(); SetupChannel(_parameters.ChannelType, _parameters.SerializerType); _observer.StitchStateChanged(_stitchInstance.Id, true, true); return(true); } catch (Exception e) { _log.LogError(e, "Could not create or start process."); _observer.StitchStateChanged(_stitchInstance.Id, false, false); return(false); } }
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"); } }
public void SendHeartbeat(long id) { try { var handles = _stitchObject as IHandlesHeartbeat; if (handles == null || handles.ReceiveHeartbeat(id)) { Observer.HeartbeatSyncReceived(_instance.Id, id); } } catch (Exception e) { _log.LogError(e, "Could not handle heartbeat"); } }
// TODO: Get/GetAll with a Filter predicate that we can execute on the Data thread and only // return values which match. public DataResponse <TEntity> HandleRequest <TEntity>(DataRequest <TEntity> request) where TEntity : class, IDataEntity { if (!request.IsValid()) { return(DataResponse <TEntity> .BadRequest()); } try { switch (request.Type) { case DataRequestType.GetAll: var all = _storage.GetAll <TEntity>(); return(DataResponse <TEntity> .FoundAll(all)); case DataRequestType.Get: return(HandleGetRequest(request)); case DataRequestType.Delete: return(HandleDeleteRequest(request)); case DataRequestType.Save: return(HandleSaveRequest(request)); default: return(DataResponse <TEntity> .BadRequest()); } } catch (Exception e) { _log.LogError(e, "Error handling data request"); return(DataResponse <TEntity> .BadRequest()); } }
public void SaveNodeStatus(NodeStatus status) { if (status == null) { return; } // TODO: Make sure the values are filled in. bool ok = _data.Save(status, true); if (!ok) { _log.LogError("Could not save NodeStatus from NodeId={0}", status.Id); } else { _log.LogDebug("Received NodeStatus from NodeId={0} and saved it", status.Id); } }
public PackageFileUploadResponse UploadStitchPackageFile(PackageFileUploadRequest request) { if (!request.IsValidLocalRequest()) { return(new PackageFileUploadResponse(false, null, null)); } // Save the file and generate a unique Version name var result = _fileSystem.SavePackageToLibrary(request.GroupName.Application, request.GroupName.Component, request.Contents); var groupName = new StitchGroupName(request.GroupName.Application, request.GroupName.Component, result.Version); var packageFile = new PackageFile { Id = groupName.ToString(), Adaptor = request.Adaptor, FileName = request.FileName, GroupName = groupName }; bool ok = _data.Save(packageFile, true); if (!ok) { _log.LogError("Could not save PackageFile Id={0}", groupName.ToString()); } _log.LogDebug("Uploaded package file {0}", groupName); return(new PackageFileUploadResponse(ok, groupName, result.FilePath)); }
// Creates an unzipped copy of the executable for the Stitch, and any other resource // allocation. Call StartInstance to start the instance public LocalCreateInstanceResponse CreateNewInstance(LocalCreateInstanceRequest request) { try { var response = new LocalCreateInstanceResponse(); if (request == null || !request.IsValid() || request.NumberOfInstances <= 0) { response.IsSuccess = false; return(response); } var packageFile = _data.Get <PackageFile>(request.GroupName.ToString()); if (packageFile == null) { response.IsSuccess = false; return(response); } for (int i = 0; i < request.NumberOfInstances; i++) { var instance = CreateSingleNewInstanceInternal(packageFile, request); if (instance != null) { response.CreatedIds.Add(instance.Id); } } response.IsSuccess = response.CreatedIds.Count == request.NumberOfInstances; return(response); } catch (Exception e) { _log.LogError(e, "Could not create new stitch instance"); return(null); } }