示例#1
0
        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);
        }
示例#2
0
        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);
        }
        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()
 {
     try
     {
         InitClient();
     }
     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);
 }
示例#5
0
        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 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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        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);

            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);
        }
示例#13
0
        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);
        }
        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);
        }
示例#15
0
        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);
        }