public void Acquire() { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); while (stopWatch.ElapsedMilliseconds < _maxWait.TotalMilliseconds) { try { string leaseId = AcquireLeaseOnBlobAsync().GetAwaiter().GetResult(); _cancellationTokenSource = new CancellationTokenSource(); _leaseRenewalTask = Task.Run(() => { AutoRenewLeaseOnBlob(this, _accountName, _accountKey, _containerName, _blobName, leaseId, _leaseUrl, _log); }, _cancellationTokenSource.Token); _leaseId = leaseId; return; } catch (Exception e) { _log.LogMessage($"Retrying lease acquisition on {_blobName}, {e.Message}"); Thread.Sleep(_delay); } } ResetLeaseRenewalTaskState(); throw new Exception($"Unable to acquire lease on {_blobName}"); }
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); }
public override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); CloudFoundryClient client = InitClient(); logger.LogMessage("Deleting service {0} from space {1}", CFServiceName, CFSpace); Guid? spaceGuid = null; if (CFSpace.Length > 0 && CFOrganization.Length > 0) { spaceGuid = Utils.GetSpaceGuid(client, logger, CFOrganization, CFSpace); if (spaceGuid == null) { return false; } } var servicesList = client.Spaces.ListAllServiceInstancesForSpace(spaceGuid, new RequestOptions() { Query = "name:" + CFServiceName }).Result; if (servicesList.Count() > 1) { logger.LogError("There are more services named {0} in space {1}", CFServiceName, CFSpace); return false; } client.ServiceInstances.DeleteServiceInstance(new Guid(servicesList.First().EntityMetadata.Guid)).Wait(); return true; }
public override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); CloudFoundryClient client = InitClient(); logger.LogMessage("Deleting route {0}", CFRoute); string domain = string.Empty; string host = string.Empty; Utils.ExtractDomainAndHost(CFRoute, out domain, out host); if (domain.Length == 0 || host.Length == 0) { logger.LogError("Error extracting domain and host information from route {0}", CFRoute); return false; } PagedResponseCollection<ListAllDomainsDeprecatedResponse> domainInfoList = client.DomainsDeprecated.ListAllDomainsDeprecated().Result; ListAllDomainsDeprecatedResponse domainInfo = domainInfoList.Where(o => o.Name == domain).FirstOrDefault(); var routeList = client.Routes.ListAllRoutes(new RequestOptions() { Query = string.Format(CultureInfo.InvariantCulture,"host:{0}&domain_guid:{1}", host, domainInfo.EntityMetadata.Guid) }).Result; if (routeList.Count() > 1) { logger.LogError("There is more than one route that matches for deletion of route {0}", CFRoute); return false; } client.Routes.DeleteRoute(new Guid(routeList.FirstOrDefault().EntityMetadata.Guid)).Wait(); return true; }
public AutoBundleConfigProcessor(string projectPath, string packagePath, string entryPointOverride, List <string> filePaths, Encoding encoding, Microsoft.Build.Utilities.TaskLoggingHelper log = null, MessageImportance logLevel = MessageImportance.Low) { ProjectPath = projectPath; FilePaths = filePaths; OutputPath = projectPath; EntryOverride = entryPointOverride; this.encoding = encoding; this.Log = log; this.LogLevel = logLevel; if (!string.IsNullOrWhiteSpace(packagePath)) { OutputPath = packagePath; } EntryPoint = this.GetEntryPointPath(); Log?.LogMessage(LogLevel, "Autobundler initialized"); Log?.LogMessage(LogLevel, $" - Project path: {projectPath}"); Log?.LogMessage(LogLevel, $" - Package path: {packagePath}"); Log?.LogMessage(LogLevel, $" - EP Override : {entryPointOverride}"); Log?.LogMessage(LogLevel, $" - Encoding : {encoding.EncodingName}"); Log?.LogMessage(LogLevel, $" - Entrypoint : {EntryPoint}"); Log?.LogMessage(LogLevel, $" - Output path : {OutputPath}"); }
public override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); CloudFoundryClient client = InitClient(); logger.LogMessage("Unbinding route {0} from app {1}", CFRoute, CFAppName); string domain=string.Empty; string host = string.Empty; Utils.ExtractDomainAndHost(CFRoute, out domain, out host); if (domain.Length == 0 || host.Length == 0) { logger.LogError("Error extracting domain and host information from route {0}", CFRoute); return false; } PagedResponseCollection<ListAllDomainsDeprecatedResponse> domainInfoList = client.DomainsDeprecated.ListAllDomainsDeprecated().Result; ListAllDomainsDeprecatedResponse domainInfo = domainInfoList.Where(o => o.Name == domain).FirstOrDefault(); 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); PagedResponseCollection<ListAllRoutesForAppResponse> routeList = client.Apps.ListAllRoutesForApp(appGuid).Result; ListAllRoutesForAppResponse routeInfo = routeList.Where(o => o.Host == host && o.DomainGuid == new Guid(domainInfo.EntityMetadata.Guid)).FirstOrDefault(); if (routeInfo == null) { logger.LogError("Route {0} not found in {1}'s routes", CFRoute, CFAppName); return false; } client.Routes.RemoveAppFromRoute(new Guid(routeInfo.EntityMetadata.Guid), appGuid).Wait(); return true; }
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("Unbinding service {0} from app {1}", CFServiceName, CFAppName); Guid? spaceGuid = null; if (CFSpace.Length > 0 && CFOrganization.Length > 0) { spaceGuid = Utils.GetSpaceGuid(client, logger, CFOrganization, CFSpace); if (spaceGuid == null) { return false; } } var servicesList = client.Spaces.ListAllServiceInstancesForSpace(spaceGuid, new RequestOptions() { Query = "name:" + CFServiceName }).Result; if (servicesList.Count() > 1) { logger.LogError("There are more services named {0} in space {1}", CFServiceName, CFSpace); return false; } Guid serviceGuid=new Guid(servicesList.FirstOrDefault().EntityMetadata.Guid); 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); var bindingsList = client.Apps.ListAllServiceBindingsForApp(appGuid).Result; foreach (var bind in bindingsList) { if (bind.ServiceInstanceGuid.Value == serviceGuid) { client.Apps.RemoveServiceBindingFromApp(appGuid, new Guid(bind.EntityMetadata.Guid)).Wait(); } } return true; }
public override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); try { CloudFoundryClient client = InitClient(); logger.LogMessage("Deleting route {0}", CFRoute); string domain = string.Empty; string host = string.Empty; Utils.ExtractDomainAndHost(CFRoute, out domain, out host); if (domain.Length == 0 || host.Length == 0) { logger.LogError("Error extracting domain and host information from route {0}", CFRoute); return(false); } PagedResponseCollection <ListAllDomainsDeprecatedResponse> domainInfoList = client.DomainsDeprecated.ListAllDomainsDeprecated().Result; ListAllDomainsDeprecatedResponse domainInfo = domainInfoList.Where(o => o.Name == domain).FirstOrDefault(); var routeList = client.Routes.ListAllRoutes(new RequestOptions() { Query = string.Format(CultureInfo.InvariantCulture, "host:{0}&domain_guid:{1}", host, domainInfo.EntityMetadata.Guid) }).Result; if (routeList.Count() > 1) { logger.LogError("There is more than one route that matches for deletion of route {0}", CFRoute); return(false); } client.Routes.DeleteRoute(new Guid(routeList.FirstOrDefault().EntityMetadata.Guid)).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 bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); logger.LogMessage("Saving configuration to {0}", CFConfigurationFile); PushProperties Configuration = new PushProperties(); Configuration.AppDir = CFAppPath; Configuration.Applications = new Dictionary <string, AppDetails>(); Configuration.Applications.Add(CFAppPath, new AppDetails() { Name = CFAppName, Url = CFRoute }); Configuration.AutoscaleInfo = new Autoscale() { Cpu = new Cpu() { MaxCpu = CFMaxCpu, MinCpu = CFMinCpu }, Enabled = CFEnabled != null ? CFEnabled: "no", InstancesInfo = new Instances() { MaxInstances = CFMaxInstances != 0 ? CFMaxInstances : 1, MinInstances = CFMinInstances != 0 ? CFMinInstances : 1 } }; Configuration.Disk = CFDisk != 0 ? CFDisk : 1024; Configuration.Instances = CFInstancesNumber; Configuration.Memory = CFAppMemory; Configuration.Name = CFAppName; Configuration.PlacementZone = CFPlacementZone != null ? CFPlacementZone : "default"; if (CFServiceName != null) { Configuration.Services = new Dictionary <string, ServiceDetails>(); Configuration.Services.Add(CFServiceName, new ServiceDetails() { Plan = CFServicePlan, Type = CFServiceType }); } Configuration.SsoEnabled = CFSsoEnabled != null ? CFSsoEnabled : "no"; Configuration.Stack = CFStack; Utils.SerializeToFile(Configuration, CFConfigurationFile); return(true); }
public override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); try { CloudFoundryClient client = InitClient(); logger.LogMessage("Deleting service {0} from space {1}", CFServiceName, CFSpace); Guid?spaceGuid = null; if (CFSpace.Length > 0 && CFOrganization.Length > 0) { spaceGuid = Utils.GetSpaceGuid(client, logger, CFOrganization, CFSpace); if (spaceGuid == null) { return(false); } } var servicesList = client.Spaces.ListAllServiceInstancesForSpace(spaceGuid, new RequestOptions() { Query = "name:" + CFServiceName }).Result; if (servicesList.Count() > 1) { logger.LogError("There are more services named {0} in space {1}", CFServiceName, CFSpace); return(false); } client.ServiceInstances.DeleteServiceInstance(new Guid(servicesList.First().EntityMetadata.Guid)).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); }
private static void AutoRenewLeaseOnBlob(AzureBlobLease instance, string accountName, string accountKey, string containerName, string blob, string leaseId, string leaseUrl, Microsoft.Build.Utilities.TaskLoggingHelper log) { TimeSpan maxWait = TimeSpan.FromSeconds(s_MaxWaitDefault); TimeSpan delay = TimeSpan.FromMilliseconds(s_DelayDefault); TimeSpan waitFor = maxWait; CancellationToken token = instance._cancellationTokenSource.Token; while (true) { token.ThrowIfCancellationRequested(); try { log.LogMessage(MessageImportance.Low, $"Requesting lease for container/blob '{containerName}/{blob}'."); using (HttpClient client = new HttpClient()) { Tuple <string, string> leaseAction = new Tuple <string, string>("x-ms-lease-action", "renew"); Tuple <string, string> headerLeaseId = new Tuple <string, string>("x-ms-lease-id", leaseId); List <Tuple <string, string> > additionalHeaders = new List <Tuple <string, string> >() { leaseAction, headerLeaseId }; var request = Utility.AzureHelper.RequestMessage("PUT", leaseUrl, accountName, accountKey, additionalHeaders); using (HttpResponseMessage response = Utility.AzureHelper.RequestWithRetry(log, client, request).GetAwaiter().GetResult()) { if (!response.IsSuccessStatusCode) { throw new Exception("Unable to acquire lease."); } } } waitFor = maxWait; } catch (Exception e) { Console.WriteLine($"Rerying lease renewal on {containerName}, {e.Message}"); waitFor = delay; } token.ThrowIfCancellationRequested(); Thread.Sleep(waitFor); } }
public override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); 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(); } 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); if (CFAppGuid.Length == 0) { logger.LogError("Application guid must be specified"); return(false); } try { CloudFoundryClient client = InitClient(); UpdateAppRequest request = new UpdateAppRequest(); request.Name = CFAppName; request.Memory = CFAppMemory; request.Instances = CFAppInstances; request.Buildpack = CFAppBuildpack; request.State = CFAppState; if (CFEnvironmentJson != null) { request.EnvironmentJson = JsonConvert.DeserializeObject <Dictionary <string, string> >(CFEnvironmentJson); } UpdateAppResponse response = client.Apps.UpdateApp(new Guid(CFAppGuid), request).Result; logger.LogMessage("Updated app {0} with guid {1}", response.Name, CFAppGuid); } 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("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 bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); logger.LogMessage("Loading configuration from {0}", CFConfigurationFile); try { Configuration = Utils.DeserializeFromFile(CFConfigurationFile); CFStack = Configuration.Stack; CFAppName = Configuration.Name; CFAppPath = Configuration.AppDir; List<string> urlList = new List<string>(); foreach (var app in Configuration.Applications) { if (app.Value.Url.Contains(";")) { string[] appurls = app.Value.Url.Split(';'); urlList.AddRange(appurls); } else { urlList.Add(app.Value.Url); } } foreach (string s in urlList) { logger.LogMessage("Loaded url {0}", s); } CFRoutes = string.Join(";",urlList); CFAppMemory = Configuration.Memory; CFAppInstances = Configuration.Instances; CFAutoscale = Utils.Serialize<Autoscale>(Configuration.AutoscaleInfo); CFDisk = Configuration.Disk; if (Configuration.Services != null) { List<ProvisionedService> servicesList = new List<ProvisionedService>(); foreach (var service in Configuration.Services) { servicesList.Add(new ProvisionedService() { Name = service.Key, Plan = service.Value.Plan, Type = service.Value.Type }); } CFServices = Utils.Serialize<List<ProvisionedService>>(servicesList); } CFPlacementZone = Configuration.PlacementZone; CFSsoEnabled = Configuration.SsoEnabled; logger.LogMessage("Configuration loaded"); } catch (Exception ex) { logger.LogErrorFromException(ex); throw; } 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 <string> createdGuid = new List <string>(); PagedResponseCollection <ListAllDomainsDeprecatedResponse> domainInfoList = client.DomainsDeprecated.ListAllDomainsDeprecated().Result; if (spaceGuid.HasValue) { foreach (String Route in CFRoutes) { if (Route.Contains(';')) { foreach (var url in Route.Split(';')) { logger.LogMessage("Creating route {0}", url); string domain = string.Empty; string host = string.Empty; Utils.ExtractDomainAndHost(url, out domain, out host); if (domain.Length == 0 || host.Length == 0) { logger.LogError("Error extracting domain and host information from route {0}", url); continue; } ListAllDomainsDeprecatedResponse domainInfo = domainInfoList.Where(o => o.Name == domain).FirstOrDefault(); if (domainInfo == null) { logger.LogError("Domain {0} not found", domain); continue; } CreateRoute(client, spaceGuid, createdGuid, host, domainInfo); } } else { string domain = string.Empty; string host = string.Empty; Utils.ExtractDomainAndHost(Route, out domain, out host); if (domain.Length == 0 || host.Length == 0) { logger.LogError("Error extracting domain and host information from route {0}", Route); continue; } ListAllDomainsDeprecatedResponse domainInfo = domainInfoList.Where(o => o.Name == domain).FirstOrDefault(); if (domainInfo == null) { logger.LogError("Domain {0} not found", domain); continue; } CreateRoute(client, spaceGuid, createdGuid, host, domainInfo); } } CFRouteGuids = createdGuid.ToArray(); } else { logger.LogError("Space {0} not found", CFSpace); return(false); } } 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); 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); } } Guid?planGuid = null; PagedResponseCollection <ListAllServicesResponse> servicesList = client.Services.ListAllServices(new RequestOptions() { Query = "label:" + CFServiceType }).Result; foreach (var service in servicesList) { var planList = client.Services.ListAllServicePlansForService(new Guid(service.EntityMetadata.Guid)).Result; var plan = planList.Where(o => o.Name == CFServicePlan).FirstOrDefault(); if (plan != null) { planGuid = new Guid(plan.EntityMetadata.Guid); break; } } CreateServiceInstanceRequest request = new CreateServiceInstanceRequest(); request.Name = CFServiceName; request.ServicePlanGuid = planGuid; request.SpaceGuid = spaceGuid; CreateServiceInstanceResponse result = client.ServiceInstances.CreateServiceInstance(request).Result; CFServiceGuid = result.EntityMetadata.Guid; logger.LogMessage("Created {0} service {1}", CFServiceType, result.Name); } 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); logger.LogMessage("Restarting application {0}", CFAppGuid); try { if (CFAppGuid.Length == 0) { logger.LogError("Application Guid must be specified"); return(false); } CloudFoundryClient client = InitClient(); // ======= HOOKUP LOGGING ======= // TODO: detect logyard vs loggregator GetV1InfoResponse v1Info = client.Info.GetV1Info().Result; using (LogyardLog logyard = new LogyardLog(new Uri(v1Info.AppLogEndpoint), string.Format(CultureInfo.InvariantCulture, "bearer {0}", client.AuthorizationToken), null, CFSkipSslValidation)) { logyard.ErrorReceived += (sender, error) => { logger.LogErrorFromException(error.Error, true); }; 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(CFAppGuid, 0, true); GetAppSummaryResponse response = client.Apps.GetAppSummary(new Guid(CFAppGuid)).Result; if (response.State != "STOPPED") { UpdateAppRequest stopReq = new UpdateAppRequest(); stopReq.State = "STOPPED"; client.Apps.UpdateApp(new Guid(CFAppGuid), stopReq).Wait(); } UpdateAppRequest startReq = new UpdateAppRequest(); startReq.State = "STARTED"; client.Apps.UpdateApp(new Guid(CFAppGuid), startReq).Wait(); // ======= WAIT FOR APP TO COME ONLINE ======= while (true) { GetAppSummaryResponse appSummary = client.Apps.GetAppSummary(new Guid(CFAppGuid)).Result; if (appSummary.RunningInstances > 0) { break; } if (appSummary.PackageState == "FAILED") { logger.LogError("App staging failed."); return(false); } else if (appSummary.PackageState == "PENDING") { logger.LogMessage("App is staging ..."); } else if (appSummary.PackageState == "STAGED") { logger.LogMessage("App staged, waiting for it to come online ..."); } Thread.Sleep(3000); } logyard.StopLogStream(); } } 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); try { 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); } } } 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(); 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; } Guid? spaceGuid = Utils.GetSpaceGuid(client, logger, CFOrganization, CFSpace); if (spaceGuid.HasValue == false) { logger.LogError("Invalid space and organization"); return false; } PagedResponseCollection<ListAllDomainsDeprecatedResponse> domainInfoList = client.DomainsDeprecated.ListAllDomainsDeprecated().Result; foreach (String Route in CFRoutes) { foreach (var url in Route.Split(';')) { logger.LogMessage("Validating route {0}", url); string domain = string.Empty; string host = string.Empty; Utils.ExtractDomainAndHost(url, out domain, out host); if (domain.Length == 0 || host.Length == 0) { logger.LogError("Error extracting domain and host information from route {0}", url); continue; } ListAllDomainsDeprecatedResponse domainInfo = domainInfoList.Where(o => o.Name.ToUpperInvariant() == domain.ToUpperInvariant()).FirstOrDefault(); if (domainInfo == null) { logger.LogError("Domain {0} not found", domain); return false; } } } if (string.IsNullOrWhiteSpace(CFServices) == false) { if (ValidateServices(client, CFServices) == false) { logger.LogError("Error validating services"); return false; } } 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<string> createdGuid = new List<string>(); PagedResponseCollection<ListAllDomainsDeprecatedResponse> domainInfoList = client.DomainsDeprecated.ListAllDomainsDeprecated().Result; if (spaceGuid.HasValue) { foreach (String Route in CFRoutes) { if (Route.Contains(';')) { foreach (var url in Route.Split(';')) { logger.LogMessage("Creating route {0}", url); string domain = string.Empty; string host = string.Empty; Utils.ExtractDomainAndHost(url, out domain, out host); if (domain.Length == 0 || host.Length == 0) { logger.LogError("Error extracting domain and host information from route {0}", url); continue; } ListAllDomainsDeprecatedResponse domainInfo = domainInfoList.Where(o => o.Name == domain).FirstOrDefault(); if (domainInfo == null) { logger.LogError("Domain {0} not found", domain); continue; } CreateRoute(client, spaceGuid, createdGuid, host, domainInfo); } } else { string domain = string.Empty; string host = string.Empty; Utils.ExtractDomainAndHost(Route, out domain, out host); if (domain.Length == 0 || host.Length == 0) { logger.LogError("Error extracting domain and host information from route {0}", Route); continue; } ListAllDomainsDeprecatedResponse domainInfo = domainInfoList.Where(o => o.Name == domain).FirstOrDefault(); if (domainInfo == null) { logger.LogError("Domain {0} not found", domain); continue; } CreateRoute(client, spaceGuid, createdGuid, host, domainInfo); } } CFRouteGuids = createdGuid.ToArray(); } else { logger.LogError("Space {0} not found", CFSpace); return false; } return true; }
public bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); logger.LogMessage("Saving configuration to {0}", CFConfigurationFile); PushProperties Configuration = new PushProperties(); Configuration.AppDir = CFAppPath; Configuration.Applications = new Dictionary<string, AppDetails>(); Configuration.Applications.Add(CFAppPath, new AppDetails() { Name = CFAppName, Url = CFRoute }); Configuration.AutoscaleInfo = new Autoscale() { Cpu = new Cpu() { MaxCpu = CFMaxCpu, MinCpu = CFMinCpu }, Enabled = CFEnabled !=null ? CFEnabled: "no", InstancesInfo = new Instances() { MaxInstances = CFMaxInstances !=0 ? CFMaxInstances : 1, MinInstances = CFMinInstances != 0 ? CFMinInstances : 1 } }; Configuration.Disk = CFDisk!=0 ? CFDisk : 1024; Configuration.Instances = CFInstancesNumber; Configuration.Memory = CFAppMemory; Configuration.Name = CFAppName; Configuration.PlacementZone = CFPlacementZone !=null ? CFPlacementZone : "default"; if (CFServiceName != null) { Configuration.Services = new Dictionary<string, ServiceDetails>(); Configuration.Services.Add(CFServiceName, new ServiceDetails() { Plan = CFServicePlan, Type = CFServiceType }); } Configuration.SsoEnabled = CFSsoEnabled!=null ? CFSsoEnabled : "no"; Configuration.Stack = CFStack; Utils.SerializeToFile(Configuration, CFConfigurationFile); 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); }
private Bundle createBundleOf(AutoBundle autoBundle) { Log?.LogMessage(LogLevel, $"Creating bundle {autoBundle.Id} for {autoBundle.Includes.Count} includes at {autoBundle.OutputPath}"); var excludedFiles = new HashSet <string>(physicalPathsOf(autoBundle.Excludes), StringComparer.InvariantCultureIgnoreCase); Log?.LogMessage(LogLevel, $" - Identified {excludedFiles.Count} excluded files."); var files = physicalPathsOf(autoBundle.Includes, excludedFiles).Distinct().ToList(); Log?.LogMessage(LogLevel, $" - Looked up physical paths of {files.Count} files."); // check if provided paths make sense if (files.Count == 0 || files[0] == null) { throw new ArgumentException($"Error for autoBundle {autoBundle.Id}: " + "Provided list of includes: \"" + string.Join(";", autoBundle.Includes) + "\"" + (excludedFiles.Count > 0 ? (" without excludes: \"" + string.Join(";", excludedFiles)) + "\"" : "") + " results in empty autoBundle."); } var requiredFiles = enumerateDependenciesOf(files, excludedFiles); Log?.LogMessage(LogLevel, $" - Enumerated {requiredFiles.Count} dependencies."); var fileSpecList = requiredFilesByDependency(requiredFiles, excludedFiles, autoBundle.CompressionType); Log?.LogMessage(LogLevel, $" - Created {fileSpecList.Count} fileSpecLists."); foreach (var file in fileSpecList) { Log?.LogMessage(LogLevel, $" - {file.FileName}: {file.FileContent.Length} chars"); } return(new Bundle { Files = fileSpecList, Output = this.GetOutputPath(autoBundle.OutputPath, autoBundle.Id), ContainingConfig = autoBundle.ContainingConfig, BundleId = autoBundle.Id }); }
internal void Go(bool doStrongNameCheck) { VerifyCertificates(_log); if (_log.HasLoggedErrors) { return; } // Next remove public signing from all of the assemblies; it can interfere with the signing process. RemovePublicSign(); // Next sign all of the files if (!SignFiles()) { _log.LogError("Error during execution of signing process."); return; } if (!CopyFiles()) { return; } // Check that all files have a strong name signature if (doStrongNameCheck) { VerifyStrongNameSigning(); } // Validate the signing worked and produced actual signed binaries in all locations. // This is a recursive process since we process nested containers. foreach (var file in _batchData.FilesToSign) { VerifyAfterSign(file); } if (_log.HasLoggedErrors) { return; } _log.LogMessage(MessageImportance.High, "Build artifacts signed and validated."); }
public override bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); try { CloudFoundryClient client = InitClient(); logger.LogMessage("Unbinding route {0} from app {1}", CFRoute, CFAppName); string domain = string.Empty; string host = string.Empty; Utils.ExtractDomainAndHost(CFRoute, out domain, out host); if (domain.Length == 0 || host.Length == 0) { logger.LogError("Error extracting domain and host information from route {0}", CFRoute); return(false); } PagedResponseCollection <ListAllDomainsDeprecatedResponse> domainInfoList = client.DomainsDeprecated.ListAllDomainsDeprecated().Result; ListAllDomainsDeprecatedResponse domainInfo = domainInfoList.Where(o => o.Name == domain).FirstOrDefault(); 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); PagedResponseCollection <ListAllRoutesForAppResponse> routeList = client.Apps.ListAllRoutesForApp(appGuid).Result; ListAllRoutesForAppResponse routeInfo = routeList.Where(o => o.Host == host && o.DomainGuid == new Guid(domainInfo.EntityMetadata.Guid)).FirstOrDefault(); if (routeInfo == null) { logger.LogError("Route {0} not found in {1}'s routes", CFRoute, CFAppName); return(false); } client.Routes.RemoveAppFromRoute(new Guid(routeInfo.EntityMetadata.Guid), 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; 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; }
private Bundle createBundleOf(AutoBundle autoBundle) { Log?.LogMessage(LogLevel, $"Creating bundle {autoBundle.Id} for {autoBundle.Includes.Count} includes at {autoBundle.OutputPath}"); var excludedFiles = new HashSet <string>(physicalPathsOf(autoBundle.Excludes), StringComparer.InvariantCultureIgnoreCase); Log?.LogMessage(LogLevel, $" - Identified {excludedFiles.Count} excluded files."); var files = physicalPathsOf(autoBundle.Includes, excludedFiles).Distinct().ToList(); Log?.LogMessage(LogLevel, $" - Looked up physical paths of {files.Count} files."); var requiredFiles = enumerateDependenciesOf(files, excludedFiles); Log?.LogMessage(LogLevel, $" - Enumerated {requiredFiles.Count} dependencies."); var fileSpecList = requiredFilesByDependency(requiredFiles, excludedFiles, autoBundle.CompressionType); Log?.LogMessage(LogLevel, $" - Created {fileSpecList.Count} fileSpecLists."); foreach (var file in fileSpecList) { Log?.LogMessage(LogLevel, $" - {file.FileName}: {file.FileContent.Length} chars"); } return(new Bundle { Files = fileSpecList, Output = this.GetOutputPath(autoBundle.OutputPath, autoBundle.Id), ContainingConfig = autoBundle.ContainingConfig, BundleId = autoBundle.Id }); }
public bool Execute() { logger = new Microsoft.Build.Utilities.TaskLoggingHelper(this); logger.LogMessage("Loading configuration from {0}", CFConfigurationFile); try { Configuration = Utils.DeserializeFromFile(CFConfigurationFile); CFStack = Configuration.Stack; CFAppName = Configuration.Name; CFAppPath = Configuration.AppDir; List <string> urlList = new List <string>(); foreach (var app in Configuration.Applications) { if (app.Value.Url.Contains(";")) { string[] appurls = app.Value.Url.Split(';'); urlList.AddRange(appurls); } else { urlList.Add(app.Value.Url); } } foreach (string s in urlList) { logger.LogMessage("Loaded url {0}", s); } CFRoutes = string.Join(";", urlList); CFAppMemory = Configuration.Memory; CFAppInstances = Configuration.Instances; CFAutoscale = Utils.Serialize <Autoscale>(Configuration.AutoscaleInfo); CFDisk = Configuration.Disk; if (Configuration.Services != null) { List <ProvisionedService> servicesList = new List <ProvisionedService>(); foreach (var service in Configuration.Services) { servicesList.Add(new ProvisionedService() { Name = service.Key, Plan = service.Value.Plan, Type = service.Value.Type }); } CFServices = Utils.Serialize <List <ProvisionedService> >(servicesList); } CFPlacementZone = Configuration.PlacementZone; CFSsoEnabled = Configuration.SsoEnabled; logger.LogMessage("Configuration loaded"); } catch (Exception ex) { logger.LogErrorFromException(ex); throw; } 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; } } Guid? planGuid = null; PagedResponseCollection<ListAllServicesResponse> servicesList = client.Services.ListAllServices(new RequestOptions() { Query = "label:" + CFServiceType }).Result; foreach (var service in servicesList) { var planList = client.Services.ListAllServicePlansForService(new Guid(service.EntityMetadata.Guid)).Result; var plan = planList.Where(o => o.Name == CFServicePlan).FirstOrDefault(); if (plan != null) { planGuid = new Guid(plan.EntityMetadata.Guid); break; } } CreateServiceInstanceRequest request = new CreateServiceInstanceRequest(); request.Name = CFServiceName; request.ServicePlanGuid = planGuid; request.SpaceGuid = spaceGuid; CreateServiceInstanceResponse result = client.ServiceInstances.CreateServiceInstance(request).Result; CFServiceGuid = result.EntityMetadata.Guid; logger.LogMessage("Created {0} service {1}", CFServiceType, result.Name); 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(); logger.LogMessage("Unbinding service {0} from app {1}", CFServiceName, CFAppName); Guid?spaceGuid = null; if (CFSpace.Length > 0 && CFOrganization.Length > 0) { spaceGuid = Utils.GetSpaceGuid(client, logger, CFOrganization, CFSpace); if (spaceGuid == null) { return(false); } } var servicesList = client.Spaces.ListAllServiceInstancesForSpace(spaceGuid, new RequestOptions() { Query = "name:" + CFServiceName }).Result; if (servicesList.Count() > 1) { logger.LogError("There are more services named {0} in space {1}", CFServiceName, CFSpace); return(false); } Guid serviceGuid = new Guid(servicesList.FirstOrDefault().EntityMetadata.Guid); 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); var bindingsList = client.Apps.ListAllServiceBindingsForApp(appGuid).Result; foreach (var bind in bindingsList) { if (bind.ServiceInstanceGuid.Value == serviceGuid) { client.Apps.RemoveServiceBindingFromApp(appGuid, new Guid(bind.EntityMetadata.Guid)).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); }