public static GetPackageResponse Unmarshall(UnmarshallerContext context)
        {
            GetPackageResponse getPackageResponse = new GetPackageResponse();

            getPackageResponse.HttpResponse = context.HttpResponse;
            getPackageResponse.RequestId    = context.StringValue("GetPackage.RequestId");

            GetPackageResponse.GetPackage_Package package = new GetPackageResponse.GetPackage_Package();
            package.ProjectName        = context.StringValue("GetPackage.Package.ProjectName");
            package.PackageName        = context.StringValue("GetPackage.Package.PackageName");
            package.Creator            = context.StringValue("GetPackage.Package.Creator");
            package.Modifier           = context.StringValue("GetPackage.Package.Modifier");
            package.CreateTime         = context.LongValue("GetPackage.Package.CreateTime");
            package.ModifyTime         = context.LongValue("GetPackage.Package.ModifyTime");
            package.OriginName         = context.StringValue("GetPackage.Package.OriginName");
            package.Type               = context.StringValue("GetPackage.Package.Type");
            package.Md5                = context.StringValue("GetPackage.Package.Md5");
            package.Description        = context.StringValue("GetPackage.Package.Description");
            package.OssEndpoint        = context.StringValue("GetPackage.Package.OssEndpoint");
            package.OssBucket          = context.StringValue("GetPackage.Package.OssBucket");
            package.OssOwner           = context.StringValue("GetPackage.Package.OssOwner");
            package.OssPath            = context.StringValue("GetPackage.Package.OssPath");
            package.Tag                = context.StringValue("GetPackage.Package.Tag");
            getPackageResponse.Package = package;

            return(getPackageResponse);
        }
        public static GetPackageResponse Unmarshall(UnmarshallerContext context)
        {
            GetPackageResponse getPackageResponse = new GetPackageResponse();

            getPackageResponse.HttpResponse = context.HttpResponse;
            getPackageResponse.RequestId    = context.StringValue("GetPackage.RequestId");
            getPackageResponse.CertPackage  = context.StringValue("GetPackage.CertPackage");

            return(getPackageResponse);
        }
Beispiel #3
0
        public void CanConvertFromProto()
        {
            Com.Daml.Ledger.Api.V1.GetPackageResponse protoValue = new Com.Daml.Ledger.Api.V1.GetPackageResponse()
            {
                HashFunction = HashFunction.Sha256, Hash = "hash", ArchivePayload = ByteString.CopyFromUtf8("ArchivePayload")
            };

            GetPackageResponse response = GetPackageResponse.FromProto(protoValue);

            response.Hash.Should().Be("hash");
            Encoding.UTF8.GetString(response.ArchivePayload, 0, response.ArchivePayload.Length).Should().Be("ArchivePayload");
            response.Function.Should().Be(GetPackageResponse.HashFunction.ValueOf(0));
        }
        public void CanConvertFromProto()
        {
            Com.DigitalAsset.Ledger.Api.V1.GetPackageResponse protoValue = new Com.DigitalAsset.Ledger.Api.V1.GetPackageResponse()
            {
                HashFunction = HashFunction.Sha256, Hash = "hash", ArchivePayload = ByteString.CopyFromUtf8("ArchivePayload")
            };

            GetPackageResponse response = GetPackageResponse.FromProto(protoValue);

            Assert.AreEqual("hash", response.Hash);
            Assert.AreEqual("ArchivePayload", Encoding.UTF8.GetString(response.ArchivePayload, 0, response.ArchivePayload.Length));
            Assert.AreEqual(GetPackageResponse.HashFunction.ValueOf(0), response.Function);
        }
        public void TestGetPackageResponse()
        {
            string json = @"{
  ""guid"": ""67bfc1f1-46b1-4240-92cb-b7589a5a95ec"",
  ""type"": ""bits"",
  ""data"": {
    ""hash"": {
      ""type"": ""sha1"",
      ""value"": null
    },
    ""error"": null
  },
  ""state"": ""AWAITING_UPLOAD"",
  ""created_at"": ""2016-07-07T09:17:16Z"",
  ""updated_at"": null,
  ""links"": {
    ""self"": {
      ""href"": ""/v3/packages/7c838f50-6511-49c5-a5d1-2f923a0035b7""
    },
    ""upload"": {
      ""href"": ""/v3/packages/7c838f50-6511-49c5-a5d1-2f923a0035b7/upload"",
      ""method"": ""POST""
    },
    ""download"": {
      ""href"": ""/v3/packages/7c838f50-6511-49c5-a5d1-2f923a0035b7/download"",
      ""method"": ""GET""
    },
    ""stage"": {
      ""href"": ""/v3/packages/7c838f50-6511-49c5-a5d1-2f923a0035b7/droplets"",
      ""method"": ""POST""
    },
    ""app"": {
      ""href"": ""/v3/apps/c481c8ec-b1ac-4f81-8b0b-9a7f0e06cdff""
    }
  }
}";

            GetPackageResponse obj = Utilities.DeserializeJson <GetPackageResponse>(json);

            Assert.AreEqual("67bfc1f1-46b1-4240-92cb-b7589a5a95ec", TestUtil.ToTestableString(obj.Guid), true);
            Assert.AreEqual("bits", TestUtil.ToTestableString(obj.Type), true);
            Assert.AreEqual("AWAITING_UPLOAD", TestUtil.ToTestableString(obj.State), true);
            Assert.AreEqual("2016-07-07T09:17:16Z", TestUtil.ToTestableString(obj.CreatedAt), true);
            Assert.AreEqual("", TestUtil.ToTestableString(obj.UpdatedAt), true);
        }
Beispiel #6
0
        public void TestGetPackageResponse()
        {
            string json = @"{
  ""guid"": ""guid-62a421aa-1e0b-4e4b-9c4b-51ff0a6057ce"",
  ""type"": ""bits"",
  ""hash"": null,
  ""url"": null,
  ""state"": ""AWAITING_UPLOAD"",
  ""error"": null,
  ""created_at"": ""2015-06-30T07:10:53Z"",
  ""updated_at"": null,
  ""_links"": {
    ""self"": {
      ""href"": ""/v3/packages/guid-62a421aa-1e0b-4e4b-9c4b-51ff0a6057ce""
    },
    ""upload"": {
      ""href"": ""/v3/packages/guid-62a421aa-1e0b-4e4b-9c4b-51ff0a6057ce/upload"",
      ""method"": ""POST""
    },
    ""app"": {
      ""href"": ""/v3/apps/guid-8361e7f5-a4d1-42d1-a74f-4a1da80d44c8""
    }
  }
}";

            GetPackageResponse obj = Utilities.DeserializeJson <GetPackageResponse>(json);

            Assert.AreEqual("guid-62a421aa-1e0b-4e4b-9c4b-51ff0a6057ce", TestUtil.ToTestableString(obj.Guid), true);
            Assert.AreEqual("bits", TestUtil.ToTestableString(obj.Type), true);
            Assert.AreEqual("", TestUtil.ToTestableString(obj.Hash), true);
            Assert.AreEqual("", TestUtil.ToTestableString(obj.Url), true);
            Assert.AreEqual("AWAITING_UPLOAD", TestUtil.ToTestableString(obj.State), true);
            Assert.AreEqual("", TestUtil.ToTestableString(obj.Error), true);
            Assert.AreEqual("2015-06-30T07:10:53Z", TestUtil.ToTestableString(obj.CreatedAt), true);
            Assert.AreEqual("", TestUtil.ToTestableString(obj.UpdatedAt), true);
        }
Beispiel #7
0
        /// <summary>
        /// Pushes an application to the cloud.
        /// <remarks>
        /// This method is only available on the .NET 4.5 framework.
        /// Calling this method from a Windows Phone App or a Windows App will throw a <see cref="NotImplementedException"/>.
        /// </remarks>
        /// </summary>
        /// <exception cref="NotImplementedException"></exception>
        /// <param name="appGuid">Application guid</param>
        /// <param name="appPath">Path of origin from which the application will be deployed</param>
        /// <param name="stack">The name of the stack the app will be running on</param>
        /// <param name="buildpackGitUrl">Git URL of the buildpack</param>
        /// <param name="startApplication">True if the app should be started after upload is complete, false otherwise</param>
        /// <param name="diskLimit">Memory limit used to stage package</param>
        /// <param name="memoryLimit">Disk limit used to stage package</param>
        public async Task Push(Guid appGuid, string appPath, string stack, string buildpackGitUrl, bool startApplication, int memoryLimit, int diskLimit)
        {
            if (appPath == null)
            {
                throw new ArgumentNullException("appPath");
            }

            IAppPushTools pushTools = new AppPushTools(appPath);
            int           usedSteps = 1;

            // Step 1 - Check if application exists
            this.TriggerPushProgressEvent(usedSteps, "Checking if application exists");
            GetAppResponse app = await this.Client.AppsExperimental.GetApp(appGuid);

            usedSteps += 1;

            // Step 2 - Create package
            CreatePackageRequest createPackage = new CreatePackageRequest();

            createPackage.Type = "bits";
            CreatePackageResponse packageResponse = await this.Client.PackagesExperimental.CreatePackage(appGuid, createPackage);

            Guid packageId = new Guid(packageResponse.Guid.ToString());

            if (this.CheckCancellation())
            {
                return;
            }

            usedSteps += 1;

            // Step 3 - Zip all needed files and get a stream back from the PushTools
            this.TriggerPushProgressEvent(usedSteps, "Creating zip package ...");
            using (Stream zippedPayload = await pushTools.GetZippedPayload(this.Client.CancellationToken))
            {
                if (this.CheckCancellation())
                {
                    return;
                }

                usedSteps += 1;

                // Step 4 - Upload zip to CloudFoundry ...
                this.TriggerPushProgressEvent(usedSteps, "Uploading zip package ...");

                await this.Client.PackagesExperimental.UploadBits(packageId, zippedPayload);

                bool uploadProcessed = false;
                while (!uploadProcessed)
                {
                    GetPackageResponse getPackage = await this.Client.PackagesExperimental.GetPackage(packageId);

                    switch (getPackage.State)
                    {
                    case "FAILED":
                    {
                        throw new Exception(string.Format(CultureInfo.InvariantCulture, "Upload failed: {0}", getPackage.Data["error"]));
                    }

                    case "READY":
                    {
                        uploadProcessed = true;
                        break;
                    }

                    default: continue;
                    }

                    if (this.CheckCancellation())
                    {
                        return;
                    }

                    Task.Delay(500).Wait();
                }

                usedSteps += 1;
            }

            // Step 5 - Stage application
            StagePackageRequest stagePackage = new StagePackageRequest();

            stagePackage.Lifecycle = new Dictionary <string, dynamic>();
            Dictionary <string, string> data = new Dictionary <string, string>();

            data["buildpack"] = buildpackGitUrl;
            data["stack"]     = stack;
            stagePackage.Lifecycle["data"] = data;
            stagePackage.Lifecycle["type"] = "buildpack";
            stagePackage.MemoryLimit       = memoryLimit;
            stagePackage.DiskLimit         = diskLimit;

            StagePackageResponse stageResponse = await this.Client.PackagesExperimental.StagePackage(packageId, stagePackage);

            if (this.CheckCancellation())
            {
                return;
            }

            usedSteps += 1;
            if (startApplication)
            {
                bool staged = false;
                while (!staged)
                {
                    GetDropletResponse getDroplet = await this.Client.DropletsExperimental.GetDroplet(new Guid(stageResponse.Guid.ToString()));

                    switch (getDroplet.State)
                    {
                    case "FAILED":
                    {
                        throw new Exception(string.Format(CultureInfo.InvariantCulture, "Staging failed: {0}", getDroplet.Error));
                    }

                    case "STAGED":
                    {
                        staged = true;
                        break;
                    }

                    default: continue;
                    }

                    if (this.CheckCancellation())
                    {
                        return;
                    }

                    Task.Delay(500).Wait();
                }

                // Step 6 - Assign droplet
                AssignDropletAsAppsCurrentDropletRequest assignRequest = new AssignDropletAsAppsCurrentDropletRequest();
                assignRequest.DropletGuid = stageResponse.Guid;
                AssignDropletAsAppsCurrentDropletResponse assignDroplet = await this.AssignDropletAsAppsCurrentDroplet(appGuid, assignRequest);

                if (this.CheckCancellation())
                {
                    return;
                }

                usedSteps += 1;

                // Step 7 - Start Application
                StartingAppResponse response = await this.Client.AppsExperimental.StartingApp(appGuid);

                if (this.CheckCancellation())
                {
                    return;
                }

                usedSteps += 1;
            }

            // Step 8 - Done
            this.TriggerPushProgressEvent(usedSteps, "Application {0} pushed successfully", app.Name);
        }