internal CloudFoundryClient CreateCloudFoundryClient(CancellationToken cancellationToken) { System.Net.Http.Fakes.ShimHttpClient.AllInstances.SendAsyncHttpRequestMessageHttpCompletionOptionCancellationToken = sendHttpAsync; this.cfClient = new CloudFoundryClient(new Uri("http://127.0.0.1.co"), cancellationToken); return(cfClient); }
private CloudFoundryClient SetTargetInfoFromFile() { if (!File.Exists(TOKEN_FILE)) { throw new Exception("Token file not found. Please login first."); } string[] tokenFileInfo = File.ReadAllLines(TOKEN_FILE); this.api = tokenFileInfo[0]; this.token = tokenFileInfo[1]; this.skipSSL = Convert.ToBoolean(tokenFileInfo[2]); if (this.skipSSL) { new ConsoleString("Ignoring SSL errors.", ConsoleColor.Yellow).WriteLine(); System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true); } new ConsoleString(string.Format("Logging in to target {0} ...", this.api), ConsoleColor.DarkCyan).WriteLine(); CloudFoundryClient client = new CloudFoundryClient(new Uri(this.api), new System.Threading.CancellationToken()); client.Login(this.token).Wait(); new ConsoleString(string.Format("Logged in.", this.api), ConsoleColor.Green).WriteLine(); return(client); }
public void AppTest() { //Arrange GetAppSummaryResponse appResponse = new GetAppSummaryResponse() { Buildpack = "testBuildpack", DetectedBuildpack = "testDetectBuildpack", PackageUpdatedAt = "testCreation", Instances = 2, Memory = 256, Name = "testAppName", RunningInstances = 2 }; appResponse.Name = "testAppName"; appResponse.State = "STARTED"; CloudFoundryClient appClient = new CloudFoundryClient(new Uri("http://test.app.xip.io"), new System.Threading.CancellationToken()); //Act App testApp = new App(appResponse, appClient); //Assert Assert.IsTrue(testApp.Actions.Count > 0); Assert.IsTrue(testApp.Buildpack == "testBuildpack"); Assert.IsTrue(testApp.CreationDate == "testCreation"); Assert.IsTrue(testApp.DetectedBuildpack == "testDetectBuildpack"); Assert.IsNotNull(testApp.Icon); Assert.IsTrue(testApp.Instances > 0); Assert.IsTrue(testApp.Memory > 0); Assert.IsTrue(testApp.Name == "testAppName"); Assert.IsTrue(testApp.RunningInstances > 0); Assert.IsTrue(testApp.Text == "testAppName"); }
public override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); try { if (CFAppGuid.Length == 0) { logger.LogError("Application Guid must be specified"); return(false); } CloudFoundryClient client = InitClient(); logger.LogMessage("Binding routes to application {0}", CFAppGuid); foreach (string routeGuid in CFRouteGuids) { client.Apps.AssociateRouteWithApp(new Guid(CFAppGuid), new Guid(routeGuid)).Wait(); } } catch (AggregateException exception) { List <string> messages = new List <string>(); ErrorFormatter.FormatExceptionMessage(exception, messages); this.logger.LogError(string.Join(Environment.NewLine, messages)); return(false); } return(true); }
internal CloudFoundryClient CreateCloudFoundryClient(CancellationToken cancellationToken) { System.Net.Http.Fakes.ShimHttpClient.AllInstances.SendAsyncHttpRequestMessageHttpCompletionOptionCancellationToken = sendHttpAsync; this.cfClient = new CloudFoundryClient(new Uri("http://127.0.0.1.co"), cancellationToken); return cfClient; }
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 = 64; 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"); }
private void GetLogsUsingLogyard(CloudFoundryClient client, Guid?appGuid, GetV1InfoResponse info) { using (LogyardLog logyard = new LogyardLog(new Uri(info.AppLogEndpoint), string.Format(CultureInfo.InvariantCulture, "bearer {0}", client.AuthorizationToken), null, CFSkipSslValidation)) { logyard.ErrorReceived += (sender, error) => { Logger.LogErrorFromException(error.Error); }; logyard.StreamOpened += (sender, args) => { Logger.LogMessage("Log stream opened."); }; logyard.StreamClosed += (sender, args) => { Logger.LogMessage("Log stream closed."); }; logyard.MessageReceived += (sender, message) => { Logger.LogMessage("[{0}] - {1}: {2}", message.Message.Value.Source, message.Message.Value.HumanTime, message.Message.Value.Text); }; logyard.StartLogStream(appGuid.Value.ToString(), 0, true); this.MonitorApp(client, appGuid); logyard.StopLogStream(); } }
public void Login(LoginArgs loginArgs) { if (loginArgs.SkipSSL) { new ConsoleString("Ignoring SSL errors.", ConsoleColor.Yellow).WriteLine(); System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true); } CloudCredentials credentials = new CloudCredentials() { User = loginArgs.User, Password = loginArgs.Password.ConvertToNonsecureString() }; Console.WriteLine(); if (!loginArgs.Api.ToLower().StartsWith("http") && !loginArgs.Api.ToLower().StartsWith("https")) { loginArgs.Api = "https://" + loginArgs.Api; } new ConsoleString(string.Format("Connecting to {0} ...", loginArgs.Api), ConsoleColor.DarkCyan).WriteLine(); CloudFoundryClient client = new CloudFoundryClient(new Uri(loginArgs.Api), new System.Threading.CancellationToken()); SaveTokenFile( loginArgs.Api, client.Login(credentials).Result, loginArgs.SkipSSL); }
static void Main(string[] args) { { Console.WriteLine("Hello CF!"); var cloudFoundryClient = new CloudFoundryClient(new Uri("https://api.system.cf.singel.home"), CancellationToken.None); cloudFoundryClient.Login("feken", "***").Wait(); var createResponse = cloudFoundryClient.AppsExperimental.CreateApp("api-created-app", new Guid("ef1c944d-c7ec-4ceb-8177-317130a005da")).Result; var appResponse = cloudFoundryClient.AppsExperimental.GetApp(createResponse.guid).Result; cloudFoundryClient.AppsExperimental.PushProgress += AppsExperimental_PushProgress; cloudFoundryClient.AppsExperimental.Push(createResponse.guid.Value, @"C:\test\tozip\", null, null, true, 0, 0).Wait(); //cloudFoundryClient.AppsExperimental.DeleteApp(appResponse.Guid.Value).Wait(); var rep = cloudFoundryClient.AppsExperimental.GetApp(appResponse.guid.Value).Result; var fpa = cloudFoundryClient.AppsExperimental.ListAssociatedProcesses(appResponse.guid).Result; } }
public App(GetAppSummaryResponse app, bool?diego, CloudFoundryClient client) : base(CloudItemType.App) { this.client = client; this.app = app; isDiego = diego; }
private void InitServicesInformation(CloudFoundryClient client) { this.RefreshingServiceInformations = true; Task.Run(async() => { this.EnterInit(); var services = await client.Services.ListAllServices(); foreach (var service in services) { if (service.Active == true) { OnUIThread(() => { ServiceTypes.Add(service); }); } } var plans = await client.ServicePlans.ListAllServicePlans(); foreach (var plan in plans) { OnUIThread(() => { servicePlans.Add(plan); }); } }).ContinueWith((antecedent) => { if (antecedent.Exception != null) { this.ExitInit(antecedent.Exception); } else { this.ExitInit(); } }).Forget(); }
public void TestInit() { client = TestUtil.GetClient(); v3client = TestUtil.GetV3Client(); 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()); } try { v3client.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"); } CCV3.PagedResponseCollection <CCV3.Data.ListAllAppsResponse> apps = v3client.AppsExperimental.ListAllApps().Result; foreach (CCV3.Data.ListAllAppsResponse app in apps) { if (app.Name.StartsWith("simplePushTest")) { v3client.AppsExperimental.DeleteApp(app.Guid).Wait(); break; } } apprequest = new CCV3.Data.CreateAppRequest(); Dictionary <string, object> s = new Dictionary <string, object>(); s["guid"] = spaceGuid; apprequest.Relationships = new Dictionary <string, dynamic>(); apprequest.Relationships["space"] = s; client.Apps.PushProgress += Apps_PushProgress; }
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()); } CreateOrganizationRequest org = new CreateOrganizationRequest(); org.Name = "test_" + Guid.NewGuid().ToString(); var newOrg = client.Organizations.CreateOrganization(org).Result; orgGuid = newOrg.EntityMetadata.Guid; CreateSpaceRequest spc = new CreateSpaceRequest(); spc.Name = "test_" + Guid.NewGuid().ToString(); spc.OrganizationGuid = orgGuid; var newSpace = client.Spaces.CreateSpace(spc).Result; spaceGuid = newSpace.EntityMetadata.Guid; stackGuid = client.Stacks.ListAllStacks().Result[0].EntityMetadata.Guid; }
private void MonitorApp(CloudFoundryClient client, Guid?appGuid) { // ======= WAIT FOR APP TO COME ONLINE ======= while (true) { CCV2.Data.GetAppSummaryResponse appSummary = client.V2.Apps.GetAppSummary(appGuid).Result; if (appSummary.RunningInstances > 0) { break; } if (appSummary.PackageState == "FAILED") { throw new Exception("App staging failed."); } else if (appSummary.PackageState == "PENDING") { new ConsoleString("[cfcmd] - App is staging ...", ConsoleColor.DarkCyan).WriteLine(); } else if (appSummary.PackageState == "STAGED") { new ConsoleString("[cfcmd] - App staged, waiting for it to come online ...", ConsoleColor.DarkCyan).WriteLine(); } Thread.Sleep(2000); } }
private void GetLogsUsingLoggregator(CloudFoundryClient client, Guid?appGuid, GetInfoResponse detailedInfo) { using (Loggregator.Client.LoggregatorLog loggregator = new Loggregator.Client.LoggregatorLog(new Uri(detailedInfo.LoggingEndpoint), string.Format(CultureInfo.InvariantCulture, "bearer {0}", client.AuthorizationToken), null, this.CFSkipSslValidation)) { loggregator.ErrorReceived += (sender, error) => { Logger.LogErrorFromException(error.Error); }; loggregator.StreamOpened += (sender, args) => { Logger.LogMessage("Log stream opened."); }; loggregator.StreamClosed += (sender, args) => { Logger.LogMessage("Log stream closed."); }; loggregator.MessageReceived += (sender, message) => { long timeInMilliSeconds = message.LogMessage.Timestamp / 1000 / 1000; var logTimeStamp = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(timeInMilliSeconds); Logger.LogMessage("[{0}] - {1}: {2}", message.LogMessage.SourceName, logTimeStamp.ToString(), message.LogMessage.Message); }; loggregator.Tail(appGuid.Value.ToString()); this.MonitorApp(client, appGuid); loggregator.StopLogStream(); } }
public void RouteTest() { //Arrange using (ShimsContext.Create()) { ListAllRoutesForSpaceResponse response = new ListAllRoutesForSpaceResponse() { Host = "testText" }; RetrieveDomainDeprecatedResponse domain = new RetrieveDomainDeprecatedResponse() { Name = "testName" }; PagedResponseCollection <ListAllAppsForRouteResponse> responseList = new PagedResponseCollection <ListAllAppsForRouteResponse>(); CloudFoundry.CloudController.V2.Client.Fakes.ShimPagedResponseCollection <ListAllAppsForRouteResponse> .AllInstances.ResourcesGet = FakeRespone; CloudFoundryClient client = new CloudFoundryClient(new Uri("http://api.test.xip.io"), new System.Threading.CancellationToken()); //Act Route route = new Route(response, domain, responseList, client); //Assert Assert.IsTrue(route.Text == "testText"); Assert.IsTrue(route.Domain == "testName"); Assert.IsTrue(route.Apps == "testApp"); Assert.IsNotNull(route.Icon); Assert.IsTrue(route.Actions.Count > 0); } }
public void ClientWithCertificateValidation_test() { var client = new CloudFoundryClient(new Uri(TestUtil.ServerUrl), new CancellationToken(), null, false); var credentials = new CloudCredentials() { User = TestUtil.User, Password = TestUtil.Password }; System.Net.ServicePointManager.ServerCertificateValidationCallback = null; bool globalValidationInvoked = false; object lastSenderValidated = null; System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => { lastSenderValidated = sender; globalValidationInvoked = true; return(true); }; client.Login(credentials).Wait(); var response = client.Stacks.ListAllStacks().Result; Assert.IsNotNull(response); Assert.IsNotNull(lastSenderValidated); Assert.IsTrue(globalValidationInvoked); }
public override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); try { CloudFoundryClient client = InitClient(); if (!Directory.Exists(CFAppPath)) { logger.LogError("Directory {0} not found", CFAppPath); return(false); } client.Apps.PushProgress += Apps_PushProgress; client.Apps.Push(new Guid(CFAppGuid), CFAppPath, CFStart).Wait(); } catch (AggregateException exception) { List <string> messages = new List <string>(); ErrorFormatter.FormatExceptionMessage(exception, messages); this.logger.LogError(string.Join(Environment.NewLine, messages)); return(false); } return(true); }
protected override async Task <IEnumerable <CloudItem> > UpdateChildren() { CloudFoundryClient client = new CloudFoundryClient(this.target.TargetUrl, this.CancellationToken, null, this.target.IgnoreSSLErrors); string password = CloudCredentialsManager.GetPassword(this.target.TargetUrl, this.target.Email); var authenticationContext = await client.Login(new CloudCredentials() { User = this.target.Email, Password = password }); List <Organization> result = new List <Organization>(); PagedResponseCollection <ListAllOrganizationsResponse> orgs = await client.Organizations.ListAllOrganizations(); while (orgs != null && orgs.Properties.TotalResults != 0) { foreach (var org in orgs) { result.Add(new Organization(org, client)); } orgs = await orgs.GetNextPage(); } return(result); }
public override bool Execute() { this.CFOrganization = this.CFOrganization.Trim(); this.CFSpace = this.CFSpace.Trim(); this.Logger = new TaskLogger(this); var app = LoadAppFromManifest(); try { CloudFoundryClient client = InitClient(); Guid?spaceGuid = null; if ((!string.IsNullOrWhiteSpace(this.CFSpace)) && (!string.IsNullOrWhiteSpace(this.CFOrganization))) { spaceGuid = Utils.GetSpaceGuid(client, this.Logger, this.CFOrganization, this.CFSpace); if (spaceGuid == null) { return(false); } } var appGuid = Utils.GetAppGuid(client, app.Name, spaceGuid.Value); if (appGuid.HasValue == false) { Logger.LogError("Application {0} not found", app.Name); return(false); } Logger.LogMessage("Restarting application {0}", app.Name); // ======= HOOKUP LOGGING ======= GetInfoResponse detailedInfo = client.Info.GetInfo().Result; if (string.IsNullOrWhiteSpace(detailedInfo.DopplerLoggingEndpoint) == false) { this.GetLogsUsingDoppler(client, appGuid, detailedInfo); } else if (string.IsNullOrWhiteSpace(detailedInfo.LoggingEndpoint) == false) { this.GetLogsUsingLoggregator(client, appGuid, detailedInfo); } else { this.Logger.LogError("Could not retrieve application logs"); } } catch (Exception exception) { this.Logger.LogError("Restart App failed", exception); return(false); } return(true); }
public AppFolder(string fileName, string filePath, int instanceNumber, GetAppSummaryResponse app, CloudFoundryClient client) : base(CloudItemType.AppFolder) { this.fileName = fileName; this.filePath = filePath; this.client = client; this.app = app; this.instanceNumber = instanceNumber; }
public Route(ListAllRoutesForSpaceResponse route, RetrieveDomainDeprecatedResponse domain, PagedResponseCollection <ListAllAppsForRouteResponse> routeApps, CloudFoundryClient client) : base(CloudItemType.Route) { this.client = client; this.route = route; this.domain = domain; this.routeApps = routeApps; }
public override bool Execute() { this.CFOrganization = this.CFOrganization.Trim(); this.CFSpace = this.CFSpace.Trim(); this.Logger = new TaskLogger(this); var app = LoadAppFromManifest(); try { CloudFoundryClient client = InitClient(); Guid?spaceGuid = null; if ((!string.IsNullOrWhiteSpace(this.CFSpace)) && (!string.IsNullOrWhiteSpace(this.CFOrganization))) { spaceGuid = Utils.GetSpaceGuid(client, this.Logger, this.CFOrganization, this.CFSpace); if (spaceGuid == null) { return(false); } } var appGuid = Utils.GetAppGuid(client, app.Name, spaceGuid.Value); if (appGuid.HasValue) { PagedResponseCollection <ListAllDomainsDeprecatedResponse> domainInfoList = client.DomainsDeprecated.ListAllDomainsDeprecated().Result; foreach (string domain in app.Domains) { foreach (string host in app.Hosts) { Logger.LogMessage("Unbinding route {0}.{1} from app {2}", host, domain, app.Name); ListAllDomainsDeprecatedResponse domainInfo = domainInfoList.Where(o => o.Name == domain).FirstOrDefault(); var routeGuid = Utils.GetRouteGuid(client, host, domainInfo.EntityMetadata.Guid.ToGuid()); if (routeGuid.HasValue) { client.Routes.RemoveAppFromRoute(routeGuid.Value, appGuid.Value); } } } } else { Logger.LogError("App {0} not found in space {1}", app.Name, this.CFSpace); return(false); } } catch (Exception exception) { this.Logger.LogError("Unbind Route failed", exception); return(false); } return(true); }
internal CloudFoundryClient InitClient() { this.CFServerUri = this.CFServerUri.Trim(); this.CancelToken = new CancellationTokenSource(); CloudFoundryClient client = new CloudFoundryClient(new Uri(this.CFServerUri), this.CancelToken.Token, null, this.CFSkipSslValidation); if (string.IsNullOrWhiteSpace(this.CFUser) == false && (string.IsNullOrWhiteSpace(this.CFPassword) == false || this.CFSavedPassword)) { if (this.CFSkipSslValidation) { System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true); } this.CFUser = this.CFUser.Trim(); if (string.IsNullOrWhiteSpace(this.CFPassword)) { this.CFPassword = CloudCredentialsManager.GetPassword(new Uri(this.CFServerUri), this.CFUser); if (string.IsNullOrWhiteSpace(this.CFPassword)) { throw new AuthenticationException( string.Format( CultureInfo.InvariantCulture, "Could not find a password for user '{0}' and target '{1}' in your local credentials store. Either make sure the entry exists in your credentials store, or provide CFPassword.", this.CFUser, this.CFServerUri)); } } this.CFPassword = this.CFPassword; CloudCredentials creds = new CloudCredentials(); creds.User = this.CFUser; creds.Password = this.CFPassword; var authContext = client.Login(creds).Result; if (this is LoginTask) { if (authContext.Token != null) { ((LoginTask)this).CFRefreshToken = authContext.Token.RefreshToken; } } } else if (string.IsNullOrWhiteSpace(this.CFRefreshToken) == false) { this.CFRefreshToken = this.CFRefreshToken.Trim(); client.Login(this.CFRefreshToken).Wait(); } else { throw new AuthenticationException("Could not authenticate client without refresh token or credentials."); } return(client); }
public CreateServiceForm(CloudFoundryClient client, Guid workingSpace) { this.client = client; this.spaceGuid = workingSpace; this.InitializeComponent(); this.DataContext = new ServiceInstanceEditorResource(client); this.InfoMessage.Text = string.Empty; this.InfoSpinner.Visibility = System.Windows.Visibility.Hidden; }
internal static CloudFoundryClient GetClient(CancellationToken cancellationToken) { if (IgnoreCertificate) { IngoreGlobalCertificateValidation(); } CloudFoundryClient client = new CloudFoundryClient(new Uri(ServerUrl), cancellationToken, null, true); return(client); }
public override bool Execute() { this.CFOrganization = this.CFOrganization.Trim(); this.CFSpace = this.CFSpace.Trim(); this.Logger = new TaskLogger(this); var app = LoadAppFromManifest(); try { CloudFoundryClient client = InitClient(); PagedResponseCollection <ListAllStacksResponse> stackList = client.Stacks.ListAllStacks().Result; var stackInfo = stackList.Where(o => o.Name == app.StackName).FirstOrDefault(); if (stackInfo == null) { this.Logger.LogError("Stack {0} not found", app.StackName); return(false); } Guid?spaceGuid = Utils.GetSpaceGuid(client, this.Logger, this.CFOrganization, this.CFSpace); if (spaceGuid.HasValue == false) { this.Logger.LogError("Invalid space and organization"); return(false); } PagedResponseCollection <ListAllDomainsDeprecatedResponse> domainInfoList = client.DomainsDeprecated.ListAllDomainsDeprecated().Result; foreach (string domain in app.Domains) { this.Logger.LogMessage("Validating domain {0}", domain); ListAllDomainsDeprecatedResponse domainInfo = domainInfoList.Where(o => o.Name.ToUpperInvariant() == domain.ToUpperInvariant()).FirstOrDefault(); if (domainInfo == null) { this.Logger.LogError("Domain {0} not found", domain); return(false); } } } catch (Exception exception) { this.Logger.LogError("Validate failed", exception); return(false); } return(true); }
public void LoginWithInvlidCertificate_test() { var client = new CloudFoundryClient(new Uri(TestUtil.ServerUrl), new CancellationToken(), null, false); var credentials = new CloudCredentials() { User = TestUtil.User, Password = TestUtil.Password }; System.Net.ServicePointManager.ServerCertificateValidationCallback = null; client.Login(credentials).Wait(); }
public Service( ListAllServiceInstancesForSpaceResponse service, ICollection <GetAppSummaryResponse> appsSummary, RetrieveServicePlanResponse servicePlan, RetrieveServiceResponse systemService, CloudFoundryClient client) : base(CloudItemType.Service) { this.client = client; this.service = service; this.appsSummary = appsSummary; this.servicePlan = servicePlan; this.systemService = systemService; }
public override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); try { CloudFoundryClient client = InitClient(); logger.LogMessage("Binding services to app {0}", CFAppGuid); List <string> bindingGuids = new List <string>(); foreach (string serviceGuid in CFServicesGuids) { CreateServiceBindingRequest request = new CreateServiceBindingRequest(); request.AppGuid = new Guid(CFAppGuid); request.ServiceInstanceGuid = new Guid(serviceGuid); try { var result = client.ServiceBindings.CreateServiceBinding(request).Result; bindingGuids.Add(result.EntityMetadata.Guid); } catch (AggregateException ex) { foreach (Exception e in ex.Flatten().InnerExceptions) { if (e is CloudFoundryException) { logger.LogWarning(e.Message); } else { throw; } } } } CFBindingGuids = bindingGuids.ToArray(); } catch (AggregateException exception) { List <string> messages = new List <string>(); ErrorFormatter.FormatExceptionMessage(exception, messages); this.logger.LogError(string.Join(Environment.NewLine, messages)); return(false); } return(true); }
public void TestInit() { 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("uploadTest")) { client.Apps.DeleteApp(app.EntityMetadata.Guid).Wait(); break; } } apprequest = new CreateAppRequest(); apprequest.Name = "uploadTest" + Guid.NewGuid().ToString(); apprequest.SpaceGuid = spaceGuid; client.Apps.PushProgress += Apps_PushProgress; }