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 override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); 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(); return true; }
public override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); CloudFoundryClient client = InitClient(); logger.LogMessage("Deleting application {0} from space {1}", CFAppName, CFSpace); Guid? spaceGuid = null; if (CFSpace.Length > 0 && CFOrganization.Length > 0) { spaceGuid = Utils.GetSpaceGuid(client, logger, CFOrganization, CFSpace); if (spaceGuid == null) { return false; } } PagedResponseCollection<ListAllAppsForSpaceResponse> appList = client.Spaces.ListAllAppsForSpace(spaceGuid, new RequestOptions() { Query = "name:" + CFAppName }).Result; if (appList.Count() > 1) { logger.LogError("There are more applications named {0} in space {1}", CFAppName, CFSpace); return false; } Guid appGuid = new Guid(appList.FirstOrDefault().EntityMetadata.Guid); if (CFDeleteRoutes == true) { logger.LogMessage("Deleting routes associated with {0}", CFAppName); var routeList = client.Apps.ListAllRoutesForApp(appGuid).Result; foreach (var route in routeList) { client.Routes.DeleteRoute(new Guid(route.EntityMetadata.Guid)).Wait(); } } if (CFDeleteServices == true) { logger.LogMessage("Deleting services bound to {0}", CFAppName); var serviceBindingList = client.Apps.ListAllServiceBindingsForApp(appGuid).Result; foreach (var serviceBind in serviceBindingList) { client.ServiceBindings.DeleteServiceBinding(new Guid(serviceBind.EntityMetadata.Guid)).Wait(); try { client.ServiceInstances.DeleteServiceInstance(serviceBind.ServiceInstanceGuid).Wait(); } catch (AggregateException ex) { foreach (Exception e in ex.Flatten().InnerExceptions) { if (e is CloudFoundryException) { logger.LogWarning(e.Message); } else { throw; } } } } } client.Apps.DeleteApp(appGuid).Wait(); return true; }
public override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); try { CloudFoundryClient client = InitClient(); logger.LogMessage("Deleting application {0} from space {1}", CFAppName, CFSpace); Guid?spaceGuid = null; if (CFSpace.Length > 0 && CFOrganization.Length > 0) { spaceGuid = Utils.GetSpaceGuid(client, logger, CFOrganization, CFSpace); if (spaceGuid == null) { return(false); } } PagedResponseCollection <ListAllAppsForSpaceResponse> appList = client.Spaces.ListAllAppsForSpace(spaceGuid, new RequestOptions() { Query = "name:" + CFAppName }).Result; if (appList.Count() > 1) { logger.LogError("There are more applications named {0} in space {1}", CFAppName, CFSpace); return(false); } Guid appGuid = new Guid(appList.FirstOrDefault().EntityMetadata.Guid); if (CFDeleteRoutes == true) { logger.LogMessage("Deleting routes associated with {0}", CFAppName); var routeList = client.Apps.ListAllRoutesForApp(appGuid).Result; foreach (var route in routeList) { client.Routes.DeleteRoute(new Guid(route.EntityMetadata.Guid)).Wait(); } } if (CFDeleteServices == true) { logger.LogMessage("Deleting services bound to {0}", CFAppName); var serviceBindingList = client.Apps.ListAllServiceBindingsForApp(appGuid).Result; foreach (var serviceBind in serviceBindingList) { client.ServiceBindings.DeleteServiceBinding(new Guid(serviceBind.EntityMetadata.Guid)).Wait(); try { client.ServiceInstances.DeleteServiceInstance(serviceBind.ServiceInstanceGuid).Wait(); } catch (AggregateException ex) { foreach (Exception e in ex.Flatten().InnerExceptions) { if (e is CloudFoundryException) { logger.LogWarning(e.Message); } else { throw; } } } } } client.Apps.DeleteApp(appGuid).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); }
public override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); CloudFoundryClient client = InitClient(); Guid? spaceGuid = null; if (CFSpace.Length > 0 && CFOrganization.Length > 0) { spaceGuid = Utils.GetSpaceGuid(client, logger, CFOrganization, CFSpace); if (spaceGuid == null) { return false; } } List<ProvisionedService> servicesList = new List<ProvisionedService>(); try { string[] provServs = CFServices.Split(';'); foreach (string service in provServs) { if (string.IsNullOrWhiteSpace(service) == false) { string[] serviceInfo = service.Split(','); if (serviceInfo.Length != 3) { logger.LogError("Invalid service information in {0}", service); continue; } ProvisionedService serviceDetails = new ProvisionedService(); serviceDetails.Name = serviceInfo[0].Trim(); serviceDetails.Type = serviceInfo[1].Trim(); serviceDetails.Plan = serviceInfo[2].Trim(); servicesList.Add(serviceDetails); } } } catch(Exception ex) { logger.LogErrorFromException(ex); logger.LogWarning("Error trying to obtain service information, trying to deserialize as xml"); servicesList = Utils.Deserialize<List<ProvisionedService>>(CFServices); } List<string> serviceGuids = new List<string>(); foreach (ProvisionedService service in servicesList) { logger.LogMessage("Creating {0} service {1}", service.Type, service.Name); Guid? planGuid = null; PagedResponseCollection<ListAllServicesResponse> allServicesList = client.Services.ListAllServices(new RequestOptions() { Query = "label:" + service.Type }).Result; foreach (var serviceInfo in allServicesList) { var planList = client.Services.ListAllServicePlansForService(new Guid(serviceInfo.EntityMetadata.Guid)).Result; var plan = planList.Where(o => o.Name == service.Plan).FirstOrDefault(); if (plan != null) { planGuid = new Guid(plan.EntityMetadata.Guid); break; } } Guid? serviceInstanceGuid=null; if ((serviceInstanceGuid=Utils.CheckForExistingService(service.Name, planGuid, client)) != null) { logger.LogMessage("Service {0} - {1} already exists -> skipping", service.Name, service.Type); serviceGuids.Add(serviceInstanceGuid.Value.ToString()); continue; } CreateServiceInstanceRequest request = new CreateServiceInstanceRequest(); request.Name = service.Name; request.ServicePlanGuid = planGuid; request.SpaceGuid = spaceGuid; CreateServiceInstanceResponse result = client.ServiceInstances.CreateServiceInstance(request).Result; serviceGuids.Add(result.EntityMetadata.Guid); } CFServicesGuids = serviceGuids.ToArray(); return true; }
public override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); try { CloudFoundryClient client = InitClient(); Guid?spaceGuid = null; if (CFSpace.Length > 0 && CFOrganization.Length > 0) { spaceGuid = Utils.GetSpaceGuid(client, logger, CFOrganization, CFSpace); if (spaceGuid == null) { return(false); } } List <ProvisionedService> servicesList = new List <ProvisionedService>(); try { string[] provServs = CFServices.Split(';'); foreach (string service in provServs) { if (string.IsNullOrWhiteSpace(service) == false) { string[] serviceInfo = service.Split(','); if (serviceInfo.Length != 3) { logger.LogError("Invalid service information in {0}", service); continue; } ProvisionedService serviceDetails = new ProvisionedService(); serviceDetails.Name = serviceInfo[0].Trim(); serviceDetails.Type = serviceInfo[1].Trim(); serviceDetails.Plan = serviceInfo[2].Trim(); servicesList.Add(serviceDetails); } } } catch (Exception ex) { logger.LogErrorFromException(ex); logger.LogWarning("Error trying to obtain service information, trying to deserialize as xml"); servicesList = Utils.Deserialize <List <ProvisionedService> >(CFServices); } List <string> serviceGuids = new List <string>(); foreach (ProvisionedService service in servicesList) { logger.LogMessage("Creating {0} service {1}", service.Type, service.Name); Guid?planGuid = null; PagedResponseCollection <ListAllServicesResponse> allServicesList = client.Services.ListAllServices(new RequestOptions() { Query = "label:" + service.Type }).Result; foreach (var serviceInfo in allServicesList) { var planList = client.Services.ListAllServicePlansForService(new Guid(serviceInfo.EntityMetadata.Guid)).Result; var plan = planList.Where(o => o.Name == service.Plan).FirstOrDefault(); if (plan != null) { planGuid = new Guid(plan.EntityMetadata.Guid); break; } } Guid?serviceInstanceGuid = null; if ((serviceInstanceGuid = Utils.CheckForExistingService(service.Name, planGuid, client)) != null) { logger.LogMessage("Service {0} - {1} already exists -> skipping", service.Name, service.Type); serviceGuids.Add(serviceInstanceGuid.Value.ToString()); continue; } CreateServiceInstanceRequest request = new CreateServiceInstanceRequest(); request.Name = service.Name; request.ServicePlanGuid = planGuid; request.SpaceGuid = spaceGuid; CreateServiceInstanceResponse result = client.ServiceInstances.CreateServiceInstance(request).Result; serviceGuids.Add(result.EntityMetadata.Guid); } CFServicesGuids = serviceGuids.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); }