internal static Task<CreateAppResponse> CustomCreateApp(CloudController.V2.Client.Base.AbstractAppsEndpoint arg1, CreateAppRequest arg2) { return Task.Factory.StartNew<CreateAppResponse>(() => { return new CreateAppResponse() { EntityMetadata = new Metadata(), Name = "testApp" }; }); }
public static void ClassInit(TestContext context) { Directory.CreateDirectory(tempAppPath); client = TestUtil.GetClient(); CloudCredentials credentials = new CloudCredentials(); credentials.User = TestUtil.User; credentials.Password = TestUtil.Password; try { client.Login(credentials).Wait(); } catch (Exception ex) { Assert.Fail("Error while logging in" + ex.ToString()); } PagedResponseCollection<ListAllSpacesResponse> spaces = client.Spaces.ListAllSpaces().Result; Guid spaceGuid = Guid.Empty; foreach (ListAllSpacesResponse space in spaces) { spaceGuid = space.EntityMetadata.Guid; break; } if (spaceGuid == Guid.Empty) { throw new Exception("No spaces found"); } PagedResponseCollection<ListAllAppsResponse> apps = client.Apps.ListAllApps().Result; foreach (ListAllAppsResponse app in apps) { if (app.Name.StartsWith("logTest")) { client.Apps.DeleteApp(app.EntityMetadata.Guid).Wait(); break; } } apprequest = new CreateAppRequest(); apprequest.Name = "logTest" + Guid.NewGuid().ToString(); apprequest.Memory = 512; apprequest.Instances = 1; apprequest.SpaceGuid = spaceGuid; apprequest.Buildpack = "https://github.com/ryandotsmith/null-buildpack.git"; apprequest.EnvironmentJson = new Dictionary<string, string>() { { "env-test-1234", "env-test-value-1234" } }; apprequest.Command = "export; cat content.txt; sleep 5000;"; client.Apps.PushProgress += Apps_PushProgress; File.WriteAllText(Path.Combine(tempAppPath, "content.txt"), "dummy content"); }
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 TestCreateAppRequest() { string json = @"{ ""name"": ""my_super_app"", ""space_guid"": ""2aa270a4-568a-4861-b072-4bbb153c4a09"" }"; CreateAppRequest request = new CreateAppRequest(); request.Name = "my_super_app"; request.SpaceGuid = new Guid("2aa270a4-568a-4861-b072-4bbb153c4a09"); string result = JsonConvert.SerializeObject(request, Formatting.None); Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result); }
/// <summary> /// Creating an App /// <para>For detailed information, see online documentation at: "http://apidocs.cloudfoundry.org/195/apps/creating_an_app.html"</para> /// </summary> public async Task<CreateAppResponse> CreateApp(CreateAppRequest value) { UriBuilder uriBuilder = new UriBuilder(this.Client.CloudTarget); uriBuilder.Path = "/v2/apps"; var client = this.GetHttpClient(); client.Uri = uriBuilder.Uri; client.Method = HttpMethod.Post; 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<CreateAppResponse>(await response.ReadContentAsStringAsync()); }
public void CreateAppTest() { using (ShimsContext.Create()) { MockClients clients = new MockClients(); string json = @"{ ""metadata"": { ""guid"": ""7f309471-80da-4acc-9181-485f1c9d1041"", ""url"": ""/v2/apps/7f309471-80da-4acc-9181-485f1c9d1041"", ""created_at"": ""2015-05-19T15:27:06+00:00"", ""updated_at"": null }, ""entity"": { ""name"": ""my_super_app"", ""production"": false, ""space_guid"": ""2aa270a4-568a-4861-b072-4bbb153c4a09"", ""stack_guid"": ""a22cb008-1cda-43c3-b7d1-e406088a2a09"", ""buildpack"": null, ""detected_buildpack"": null, ""environment_json"": { }, ""memory"": 1024, ""instances"": 1, ""disk_quota"": 1024, ""state"": ""STOPPED"", ""version"": ""48f92a70-bc4b-4fa9-a716-faf2975dcef0"", ""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"": null, ""detected_start_command"": """", ""space_url"": ""/v2/spaces/2aa270a4-568a-4861-b072-4bbb153c4a09"", ""stack_url"": ""/v2/stacks/a22cb008-1cda-43c3-b7d1-e406088a2a09"", ""events_url"": ""/v2/apps/7f309471-80da-4acc-9181-485f1c9d1041/events"", ""service_bindings_url"": ""/v2/apps/7f309471-80da-4acc-9181-485f1c9d1041/service_bindings"", ""routes_url"": ""/v2/apps/7f309471-80da-4acc-9181-485f1c9d1041/routes"" } }"; clients.JsonResponse = json; clients.ExpectedStatusCode = (HttpStatusCode)201; var cfClient = clients.CreateCloudFoundryClient(); CreateAppRequest value = new CreateAppRequest(); var obj = cfClient.Apps.CreateApp(value).Result; Assert.AreEqual("7f309471-80da-4acc-9181-485f1c9d1041", TestUtil.ToTestableString(obj.EntityMetadata.Guid), true); Assert.AreEqual("/v2/apps/7f309471-80da-4acc-9181-485f1c9d1041", TestUtil.ToTestableString(obj.EntityMetadata.Url), true); Assert.AreEqual("2015-05-19T15:27:06+00:00", TestUtil.ToTestableString(obj.EntityMetadata.CreatedAt), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.EntityMetadata.UpdatedAt), true); Assert.AreEqual("my_super_app", TestUtil.ToTestableString(obj.Name), true); Assert.AreEqual("false", TestUtil.ToTestableString(obj.Production), true); Assert.AreEqual("2aa270a4-568a-4861-b072-4bbb153c4a09", TestUtil.ToTestableString(obj.SpaceGuid), true); Assert.AreEqual("a22cb008-1cda-43c3-b7d1-e406088a2a09", TestUtil.ToTestableString(obj.StackGuid), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.Buildpack), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.DetectedBuildpack), 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("48f92a70-bc4b-4fa9-a716-faf2975dcef0", 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("", TestUtil.ToTestableString(obj.PackageUpdatedAt), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.DetectedStartCommand), true); Assert.AreEqual("/v2/spaces/2aa270a4-568a-4861-b072-4bbb153c4a09", TestUtil.ToTestableString(obj.SpaceUrl), true); Assert.AreEqual("/v2/stacks/a22cb008-1cda-43c3-b7d1-e406088a2a09", TestUtil.ToTestableString(obj.StackUrl), true); Assert.AreEqual("/v2/apps/7f309471-80da-4acc-9181-485f1c9d1041/events", TestUtil.ToTestableString(obj.EventsUrl), true); Assert.AreEqual("/v2/apps/7f309471-80da-4acc-9181-485f1c9d1041/service_bindings", TestUtil.ToTestableString(obj.ServiceBindingsUrl), true); Assert.AreEqual("/v2/apps/7f309471-80da-4acc-9181-485f1c9d1041/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 static void ClassInit(TestContext context) { client = TestUtil.GetClient(); CloudCredentials credentials = new CloudCredentials(); credentials.User = TestUtil.User; credentials.Password = TestUtil.Password; try { client.Login(credentials).Wait(); } catch (Exception ex) { Assert.Fail("Error while loging in" + ex.ToString()); } PagedResponseCollection<ListAllSpacesResponse> spaces = client.Spaces.ListAllSpaces().Result; Guid spaceGuid = Guid.Empty; foreach (ListAllSpacesResponse space in spaces) { spaceGuid = space.EntityMetadata.Guid; break; } if (spaceGuid == Guid.Empty) { throw new Exception("No spaces found"); } PagedResponseCollection<ListAllStacksResponse> stacks = client.Stacks.ListAllStacks().Result; var winStack = Guid.Empty; foreach (ListAllStacksResponse stack in stacks) { if (stack.Name == "win2012r2" || stack.Name == "win2012") { winStack = stack.EntityMetadata.Guid; break; } } if (winStack == Guid.Empty) { throw new Exception("Could not test on a deployment without a windows 2012 stack"); } PagedResponseCollection<ListAllAppsResponse> apps = client.Apps.ListAllApps().Result; foreach (ListAllAppsResponse app in apps) { if (app.Name.StartsWith("simplePushTest")) { client.Apps.DeleteApp(app.EntityMetadata.Guid).Wait(); break; } } apprequest = new CreateAppRequest(); apprequest.Memory = 512; apprequest.Instances = 1; apprequest.SpaceGuid = spaceGuid; apprequest.StackGuid = winStack; client.Apps.PushProgress += Apps_PushProgress; }