Example #1
0
        // 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)
                {
                    return(response.AsFailure());
                }

                var packageFile = _data.Get <PackageFile>(request.GroupName.ToString());
                if (packageFile == null)
                {
                    return(response.AsFailure());
                }

                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);
            }
        }
Example #2
0
 public StitchInstance Map(LocalCreateInstanceRequest request)
 {
     return(new StitchInstance
     {
         Id = null,
         StoreVersion = 0,
         GroupName = request.GroupName,
         Name = request.Name,
         OwnerNodeName = _nodeName,
         OwnerNodeId = _nodeId
     });
 }
Example #3
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);
        }