public void TestUpdateAppRequest() { string json = @"{ ""name"": ""new_name"" }"; UpdateAppRequest request = new UpdateAppRequest(); request.Name = "new_name"; string result = JsonConvert.SerializeObject(request, Formatting.None); Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result); }
/// <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="startApplication">True if the app should be started after upload is complete, false otherwise</param> public async Task Push(Guid appGuid, string appPath, bool startApplication) { if (appPath == null) { throw new ArgumentNullException("appPath"); } IAppPushTools pushTools = new AppPushTools(); int usedSteps = 1; // Step 1 - Check if application exists this.TriggerPushProgressEvent(usedSteps, "Checking if application exists"); RetrieveAppResponse app = await this.Client.Apps.RetrieveApp(appGuid); usedSteps += 1; // Step 2 - Compute fingerprints for local files this.TriggerPushProgressEvent(usedSteps, "Calculating file fingerprints ..."); Dictionary<string, List<FileFingerprint>> fingerprints = await pushTools.GetFileFingerprints(appPath, this.Client.CancellationToken); if (this.CheckCancellation()) { return; } usedSteps += 1; // Step 3 - Compare fingerprints of local files with what the server has this.TriggerPushProgressEvent(usedSteps, "Comparing file fingerprints ..."); HashSet<string> neededFiles = await this.FilterExistingFiles(fingerprints); if (this.CheckCancellation()) { return; } usedSteps += 1; // Step 4 - Zip all needed files and get a stream back from the PushTools this.TriggerPushProgressEvent(usedSteps, "Creating zip package ..."); using (Stream zippedPayload = await pushTools.GetZippedPayload(appPath, neededFiles, this.Client.CancellationToken)) { if (this.CheckCancellation()) { return; } usedSteps += 1; // Step 5 - Upload zip to CloudFoundry ... this.TriggerPushProgressEvent(usedSteps, "Uploading zip package ..."); List<FileFingerprint> fingerPrintList = fingerprints.Values.SelectMany(list => list).Where(fingerprint => !neededFiles.Contains(fingerprint.FileName)).ToList(); await this.UploadBits(appGuid, zippedPayload, fingerPrintList); if (this.CheckCancellation()) { return; } usedSteps += 1; } if (startApplication) { // Step 6 - Start Application UpdateAppRequest updateApp = new UpdateAppRequest() { State = "STARTED" }; UpdateAppResponse response = await this.UpdateApp(appGuid, updateApp); if (this.CheckCancellation()) { return; } usedSteps += 1; } // Step 7 - Done this.TriggerPushProgressEvent(usedSteps, "Application {0} pushed successfully", app.Name); }
/// <summary> /// Updating an App /// <para>For detailed information, see online documentation at: "http://apidocs.cloudfoundry.org/195/apps/updating_an_app.html"</para> /// </summary> public async Task<UpdateAppResponse> UpdateApp(Guid? guid, UpdateAppRequest value) { UriBuilder uriBuilder = new UriBuilder(this.Client.CloudTarget); uriBuilder.Path = string.Format(CultureInfo.InvariantCulture, "/v2/apps/{0}", guid); var client = this.GetHttpClient(); client.Uri = uriBuilder.Uri; client.Method = HttpMethod.Put; var authHeader = await BuildAuthenticationHeader(); if (!string.IsNullOrWhiteSpace(authHeader.Key)) { client.Headers.Add(authHeader); } client.ContentType = "application/x-www-form-urlencoded"; client.Content = JsonConvert.SerializeObject(value).ConvertToStream(); var expectedReturnStatus = 201; var response = await this.SendAsync(client, expectedReturnStatus); return Utilities.DeserializeJson<UpdateAppResponse>(await response.ReadContentAsStringAsync()); }
public void UpdateAppTest() { using (ShimsContext.Create()) { MockClients clients = new MockClients(); string json = @"{ ""metadata"": { ""guid"": ""0ef6eaf7-141d-4f30-85f5-5cfb652d45ef"", ""url"": ""/v2/apps/0ef6eaf7-141d-4f30-85f5-5cfb652d45ef"", ""created_at"": ""2015-05-19T15:27:06+00:00"", ""updated_at"": ""2015-05-19T15:27:06+00:00"" }, ""entity"": { ""name"": ""new_name"", ""production"": false, ""space_guid"": ""306f1578-1e05-4146-9631-840ecb4c3577"", ""stack_guid"": ""1a7850ba-3127-4d90-9d14-6ad87ade0e39"", ""buildpack"": null, ""detected_buildpack"": null, ""environment_json"": null, ""memory"": 1024, ""instances"": 1, ""disk_quota"": 1024, ""state"": ""STOPPED"", ""version"": ""287cc752-c0c3-463e-a048-c0c155fab90f"", ""command"": null, ""console"": false, ""debug"": null, ""staging_task_id"": null, ""package_state"": ""PENDING"", ""health_check_type"": ""port"", ""health_check_timeout"": null, ""staging_failed_reason"": null, ""docker_image"": null, ""package_updated_at"": ""2015-05-19T15:27:06+00:00"", ""detected_start_command"": """", ""space_url"": ""/v2/spaces/306f1578-1e05-4146-9631-840ecb4c3577"", ""stack_url"": ""/v2/stacks/1a7850ba-3127-4d90-9d14-6ad87ade0e39"", ""events_url"": ""/v2/apps/0ef6eaf7-141d-4f30-85f5-5cfb652d45ef/events"", ""service_bindings_url"": ""/v2/apps/0ef6eaf7-141d-4f30-85f5-5cfb652d45ef/service_bindings"", ""routes_url"": ""/v2/apps/0ef6eaf7-141d-4f30-85f5-5cfb652d45ef/routes"" } }"; clients.JsonResponse = json; clients.ExpectedStatusCode = (HttpStatusCode)201; var cfClient = clients.CreateCloudFoundryClient(); Guid? guid = Guid.NewGuid(); UpdateAppRequest value = new UpdateAppRequest(); var obj = cfClient.Apps.UpdateApp(guid, value).Result; Assert.AreEqual("0ef6eaf7-141d-4f30-85f5-5cfb652d45ef", TestUtil.ToTestableString(obj.EntityMetadata.Guid), true); Assert.AreEqual("/v2/apps/0ef6eaf7-141d-4f30-85f5-5cfb652d45ef", TestUtil.ToTestableString(obj.EntityMetadata.Url), true); Assert.AreEqual("2015-05-19T15:27:06+00:00", TestUtil.ToTestableString(obj.EntityMetadata.CreatedAt), true); Assert.AreEqual("2015-05-19T15:27:06+00:00", TestUtil.ToTestableString(obj.EntityMetadata.UpdatedAt), true); Assert.AreEqual("new_name", TestUtil.ToTestableString(obj.Name), true); Assert.AreEqual("false", TestUtil.ToTestableString(obj.Production), true); Assert.AreEqual("306f1578-1e05-4146-9631-840ecb4c3577", TestUtil.ToTestableString(obj.SpaceGuid), true); Assert.AreEqual("1a7850ba-3127-4d90-9d14-6ad87ade0e39", TestUtil.ToTestableString(obj.StackGuid), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.Buildpack), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.DetectedBuildpack), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.EnvironmentJson), true); Assert.AreEqual("1024", TestUtil.ToTestableString(obj.Memory), true); Assert.AreEqual("1", TestUtil.ToTestableString(obj.Instances), true); Assert.AreEqual("1024", TestUtil.ToTestableString(obj.DiskQuota), true); Assert.AreEqual("STOPPED", TestUtil.ToTestableString(obj.State), true); Assert.AreEqual("287cc752-c0c3-463e-a048-c0c155fab90f", TestUtil.ToTestableString(obj.Version), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.Command), true); Assert.AreEqual("false", TestUtil.ToTestableString(obj.Console), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.Debug), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.StagingTaskId), true); Assert.AreEqual("PENDING", TestUtil.ToTestableString(obj.PackageState), true); Assert.AreEqual("port", TestUtil.ToTestableString(obj.HealthCheckType), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.HealthCheckTimeout), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.StagingFailedReason), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.DockerImage), true); Assert.AreEqual("2015-05-19T15:27:06+00:00", TestUtil.ToTestableString(obj.PackageUpdatedAt), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.DetectedStartCommand), true); Assert.AreEqual("/v2/spaces/306f1578-1e05-4146-9631-840ecb4c3577", TestUtil.ToTestableString(obj.SpaceUrl), true); Assert.AreEqual("/v2/stacks/1a7850ba-3127-4d90-9d14-6ad87ade0e39", TestUtil.ToTestableString(obj.StackUrl), true); Assert.AreEqual("/v2/apps/0ef6eaf7-141d-4f30-85f5-5cfb652d45ef/events", TestUtil.ToTestableString(obj.EventsUrl), true); Assert.AreEqual("/v2/apps/0ef6eaf7-141d-4f30-85f5-5cfb652d45ef/service_bindings", TestUtil.ToTestableString(obj.ServiceBindingsUrl), true); Assert.AreEqual("/v2/apps/0ef6eaf7-141d-4f30-85f5-5cfb652d45ef/routes", TestUtil.ToTestableString(obj.RoutesUrl), true); } }
public override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); CloudFoundryClient client = InitClient(); Guid? spaceGuid = null; Guid? stackGuid = null; if (CFSpace.Length > 0 && CFOrganization.Length > 0) { spaceGuid = Utils.GetSpaceGuid(client, logger, CFOrganization, CFSpace); if (spaceGuid == null) { return false; } } if (CFStack.Length > 0) { PagedResponseCollection<ListAllStacksResponse> stackList = client.Stacks.ListAllStacks().Result; var stackInfo = stackList.Where(o => o.Name == CFStack).FirstOrDefault(); if (stackInfo == null) { logger.LogError("Stack {0} not found", CFStack); return false; } stackGuid = new Guid(stackInfo.EntityMetadata.Guid); } if (stackGuid.HasValue && spaceGuid.HasValue) { PagedResponseCollection<ListAllAppsForSpaceResponse> apps = client.Spaces.ListAllAppsForSpace(spaceGuid, new RequestOptions() { Query = "name:" + CFAppName }).Result; if (apps.Count() > 0) { CFAppGuid = apps.FirstOrDefault().EntityMetadata.Guid; UpdateAppRequest request = new UpdateAppRequest(); request.SpaceGuid = spaceGuid; request.StackGuid = stackGuid; if (CFEnvironmentJson != null) { request.EnvironmentJson = JsonConvert.DeserializeObject<Dictionary<string,string>>(CFEnvironmentJson); } if (CFAppMemory > 0) { request.Memory = CFAppMemory; } if (CFAppInstances > 0) { request.Instances = CFAppInstances; } if (CFAppBuildpack != null) { request.Buildpack = CFAppBuildpack; } UpdateAppResponse response = client.Apps.UpdateApp(new Guid(CFAppGuid), request).Result; logger.LogMessage("Updated app {0} with guid {1}", response.Name, response.EntityMetadata.Guid); } else { CreateAppRequest request = new CreateAppRequest(); request.Name = CFAppName; request.SpaceGuid = spaceGuid; request.StackGuid = stackGuid; if(CFEnvironmentJson !=null){ request.EnvironmentJson = JsonConvert.DeserializeObject<Dictionary<string,string>>(CFEnvironmentJson); } if (CFAppMemory > 0) { request.Memory = CFAppMemory; } if (CFAppInstances > 0) { request.Instances = CFAppInstances; } if (CFAppBuildpack != null) { request.Buildpack = CFAppBuildpack; } CreateAppResponse response = client.Apps.CreateApp(request).Result; CFAppGuid = response.EntityMetadata.Guid; logger.LogMessage("Created app {0} with guid {1}", CFAppName, CFAppGuid); } } return true; }
public void Application_test() { CreateAppResponse newApp = null; GetAppSummaryResponse readApp = null; UpdateAppResponse updateApp = null; CreateAppRequest app = new CreateAppRequest(); app.Name = Guid.NewGuid().ToString(); app.SpaceGuid = spaceGuid; app.Instances = 1; app.Memory = 256; app.StackGuid = stackGuid; try { newApp = client.Apps.CreateApp(app).Result; } catch (Exception ex) { Assert.Fail("Error creating app: {0}", ex.ToString()); } Assert.IsNotNull(newApp); try { readApp = client.Apps.GetAppSummary(newApp.EntityMetadata.Guid).Result; } catch (Exception ex) { Assert.Fail("Error reading app: {0}", ex.ToString()); } Assert.IsNotNull(readApp); Assert.AreEqual(app.Name, readApp.Name); UpdateAppRequest updateAppRequest = new UpdateAppRequest(); updateAppRequest.Memory = 512; try { updateApp = client.Apps.UpdateApp(newApp.EntityMetadata.Guid, updateAppRequest).Result; } catch (Exception ex) { Assert.Fail("Error updating app: {0}", ex.ToString()); } Assert.IsNotNull(updateApp); Assert.AreEqual(updateAppRequest.Memory, updateApp.Memory); try { client.Apps.DeleteApp(newApp.EntityMetadata.Guid).Wait(); } catch (Exception ex) { Assert.Fail("Error deleting app: {0}", ex.ToString()); } }
public void DoublePush() { apprequest.Name = "simplePushTest" + Guid.NewGuid().ToString("N"); CreateAppResponse app = client.Apps.CreateApp(apprequest).Result; client.Apps.Push(app.EntityMetadata.Guid, appPath, false).Wait(); UpdateAppRequest updateApp = new UpdateAppRequest(); updateApp.Name = app.Name; updateApp.Memory = 512; updateApp.Instances = 1; UpdateAppResponse updatedApp = client.Apps.UpdateApp(app.EntityMetadata.Guid, updateApp).Result; client.Apps.Push(app.EntityMetadata.Guid, appPath, false).Wait(); client.Apps.DeleteApp(app.EntityMetadata.Guid).Wait(); }
internal static Task<UpdateAppResponse> CustomUpdateApp(CloudController.V2.Client.Base.AbstractAppsEndpoint arg1, Guid? arg2, UpdateAppRequest arg3) { return Task.Factory.StartNew<UpdateAppResponse>(() => { return new UpdateAppResponse() { Name = "TestApp" }; }); }