/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { CreatePackageResponse response = new CreatePackageResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("Arn", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.Arn = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("PackageId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.PackageId = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("StorageLocation", targetDepth)) { var unmarshaller = StorageLocationUnmarshaller.Instance; response.StorageLocation = unmarshaller.Unmarshall(context); continue; } } return(response); }
public void TestCreatePackageResponse() { string json = @"{ ""guid"": ""ea8759d4-00c1-45f9-bcaa-6f63cdb0097d"", ""type"": ""docker"", ""hash"": null, ""url"": ""docker://cloudfoundry/runtime-ci"", ""state"": ""READY"", ""error"": null, ""created_at"": ""2015-06-30T07:10:53Z"", ""updated_at"": null, ""_links"": { ""self"": { ""href"": ""/v3/packages/ea8759d4-00c1-45f9-bcaa-6f63cdb0097d"" }, ""app"": { ""href"": ""/v3/apps/guid-a19e1170-7a28-4ae4-b98e-69cce235f7a7"" } } }"; CreatePackageResponse obj = Utilities.DeserializeJson <CreatePackageResponse>(json); Assert.AreEqual("ea8759d4-00c1-45f9-bcaa-6f63cdb0097d", TestUtil.ToTestableString(obj.Guid), true); Assert.AreEqual("docker", TestUtil.ToTestableString(obj.Type), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.Hash), true); Assert.AreEqual("docker://cloudfoundry/runtime-ci", TestUtil.ToTestableString(obj.Url), true); Assert.AreEqual("READY", 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); }
public static CreatePackageResponse Unmarshall(UnmarshallerContext context) { CreatePackageResponse createPackageResponse = new CreatePackageResponse(); createPackageResponse.HttpResponse = context.HttpResponse; createPackageResponse.RequestId = context.StringValue("CreatePackage.RequestId"); return(createPackageResponse); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { CreatePackageResponse response = new CreatePackageResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("PackageDetails", targetDepth)) { var unmarshaller = PackageDetailsUnmarshaller.Instance; response.PackageDetails = unmarshaller.Unmarshall(context); continue; } } return(response); }
public void TestCreatePackageResponse() { string json = @"{ ""guid"": ""84120290-c0fd-4de6-bad5-baf52d968fd0"", ""type"": ""docker"", ""data"": { ""hash"": { ""type"": ""sha1"", ""value"": null }, ""error"": null, ""image"": ""registry/image:latest"", ""credentials"": { ""user"": ""user name"", ""email"": ""*****@*****.**"", ""password"": ""very secret password"", ""login_server"": ""https://index.docker.io/v1"" }, ""store_image"": true }, ""state"": ""READY"", ""created_at"": ""2016-07-07T09:17:16Z"", ""updated_at"": null, ""links"": { ""self"": { ""href"": ""/v3/packages/749fa305-e31b-4a77-b649-be9efabe82d9"" }, ""app"": { ""href"": ""/v3/apps/553def5a-3c79-4878-af65-8065994d9c5a"" } } }"; CreatePackageResponse obj = Utilities.DeserializeJson <CreatePackageResponse>(json); Assert.AreEqual("84120290-c0fd-4de6-bad5-baf52d968fd0", TestUtil.ToTestableString(obj.Guid), true); Assert.AreEqual("docker", TestUtil.ToTestableString(obj.Type), true); Assert.AreEqual("READY", TestUtil.ToTestableString(obj.State), true); Assert.AreEqual("2016-07-07T09:17:16Z", TestUtil.ToTestableString(obj.CreatedAt), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.UpdatedAt), true); }
public async Task CreatePackageAsync_ValidRequest_ShouldReturnCreatedPackage() { // Arrange var existingProject = new GetProjectPayload { Id = Guid.NewGuid().ToString(), }; var title = Guid.NewGuid().ToString(); var createPackageRequest = new CreatePackageRequest(title); var expectedPackage = new CreatePackageResponse { Title = title, }; var expectedResponseContent = new StringContent(JsonConvert.SerializeObject(expectedPackage, this.fixture.JsonSerializerSettings)); var expectedResponse = new HttpResponseMessage { Content = expectedResponseContent, }; var packageApi = this.fixture.GetPackageApi(expectedResponse); var createPackageResponse = default(CreatePackageResponse); // Act Func <Task> act = async() => createPackageResponse = await packageApi.CreatePackageAsync(existingProject.Id, createPackageRequest); // Assert await act.Should().NotThrowAsync(); createPackageResponse.Should().BeEquivalentTo(expectedPackage); }
/// <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); }