Ejemplo n.º 1
0
        public override bool Execute()
        {
            this.CFOrganization = this.CFOrganization.Trim();
            this.CFSpace        = this.CFSpace.Trim();

            this.Logger = new TaskLogger(this);
            var app = LoadAppFromManifest();

            try
            {
                CloudFoundryClient client = InitClient();

                Guid?spaceGuid = null;

                if ((!string.IsNullOrWhiteSpace(this.CFSpace)) && (!string.IsNullOrWhiteSpace(this.CFOrganization)))
                {
                    spaceGuid = Utils.GetSpaceGuid(client, this.Logger, this.CFOrganization, this.CFSpace);
                    if (spaceGuid == null)
                    {
                        return(false);
                    }
                }

                var appGuid = Utils.GetAppGuid(client, app.Name, spaceGuid.Value);

                if (appGuid.HasValue)
                {
                    PagedResponseCollection <ListAllDomainsDeprecatedResponse> domainInfoList = client.DomainsDeprecated.ListAllDomainsDeprecated().Result;

                    foreach (string domain in app.Domains)
                    {
                        foreach (string host in app.Hosts)
                        {
                            Logger.LogMessage("Unbinding route {0}.{1} from app {2}", host, domain, app.Name);

                            ListAllDomainsDeprecatedResponse domainInfo = domainInfoList.Where(o => o.Name == domain).FirstOrDefault();
                            var routeGuid = Utils.GetRouteGuid(client, host, domainInfo.EntityMetadata.Guid.ToGuid());
                            if (routeGuid.HasValue)
                            {
                                client.Routes.RemoveAppFromRoute(routeGuid.Value, appGuid.Value);
                            }
                        }
                    }
                }
                else
                {
                    Logger.LogError("App {0} not found in space {1}", app.Name, this.CFSpace);
                    return(false);
                }
            }
            catch (Exception exception)
            {
                this.Logger.LogError("Unbind Route failed", exception);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public override bool Execute()
        {
            this.CFOrganization = this.CFOrganization.Trim();
            this.CFSpace        = this.CFSpace.Trim();

            this.Logger = new TaskLogger(this);

            var app = LoadAppFromManifest();

            try
            {
                CloudFoundryClient client = InitClient();

                PagedResponseCollection <ListAllStacksResponse> stackList = client.Stacks.ListAllStacks().Result;

                var stackInfo = stackList.Where(o => o.Name == app.StackName).FirstOrDefault();

                if (stackInfo == null)
                {
                    this.Logger.LogError("Stack {0} not found", app.StackName);
                    return(false);
                }

                Guid?spaceGuid = Utils.GetSpaceGuid(client, this.Logger, this.CFOrganization, this.CFSpace);

                if (spaceGuid.HasValue == false)
                {
                    this.Logger.LogError("Invalid space and organization");
                    return(false);
                }

                PagedResponseCollection <ListAllDomainsDeprecatedResponse> domainInfoList = client.DomainsDeprecated.ListAllDomainsDeprecated().Result;

                foreach (string domain in app.Domains)
                {
                    this.Logger.LogMessage("Validating domain {0}", domain);

                    ListAllDomainsDeprecatedResponse domainInfo = domainInfoList.Where(o => o.Name.ToUpperInvariant() == domain.ToUpperInvariant()).FirstOrDefault();

                    if (domainInfo == null)
                    {
                        this.Logger.LogError("Domain {0} not found", domain);
                        return(false);
                    }
                }
            }
            catch (Exception exception)
            {
                this.Logger.LogError("Validate failed", exception);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public override bool Execute()
        {
            this.CFOrganization = this.CFOrganization.Trim();
            this.CFSpace        = this.CFSpace.Trim();

            this.Logger = new TaskLogger(this);

            var app = LoadAppFromManifest();

            try
            {
                CloudFoundryClient client = InitClient();

                PagedResponseCollection <ListAllDomainsDeprecatedResponse> domainInfoList = client.DomainsDeprecated.ListAllDomainsDeprecated().Result;

                foreach (string domain in app.Domains)
                {
                    foreach (string host in app.Hosts)
                    {
                        ListAllDomainsDeprecatedResponse domainInfo = domainInfoList.Where(o => o.Name == domain).FirstOrDefault();
                        var routeGuid = Utils.GetRouteGuid(client, host, domainInfo.EntityMetadata.Guid.ToGuid());
                        if (routeGuid.HasValue)
                        {
                            client.Routes.DeleteRoute(routeGuid.Value, true).Wait();
                        }
                        else
                        {
                            Logger.LogError("Route {0}.{1} not found", host, domain);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                this.Logger.LogError("Delete Route failed", exception);
                return(false);
            }

            return(true);
        }
        private void CreateRoute(CloudFoundryClient client, Guid? spaceGuid, List<string> createdGuid, string host, ListAllDomainsDeprecatedResponse domainInfo)
        {
            CreateRouteRequest req = new CreateRouteRequest();
            req.DomainGuid = new Guid(domainInfo.EntityMetadata.Guid);
            req.SpaceGuid = spaceGuid;
            req.Host = host;
            try
            {

                var routes = client.Routes.ListAllRoutes(new RequestOptions() { Query = string.Format(CultureInfo.InvariantCulture, "host:{0}&domain_guid:{1}", host, domainInfo.EntityMetadata.Guid) }).Result;

                if (routes.Count() > 0)
                {
                    ListAllRoutesResponse routeInfo = routes.FirstOrDefault();
                    logger.LogMessage("Route {0}.{1} already exists", routeInfo.Host, routeInfo.DomainUrl);
                    if (routeInfo != null)
                    {
                        createdGuid.Add(routeInfo.EntityMetadata.Guid);
                    }
                }
                else
                {
                    CreateRouteResponse response = client.Routes.CreateRoute(req).Result;
                    createdGuid.Add(response.EntityMetadata.Guid);
                }
            }
            catch (AggregateException ex)
            {
                foreach (Exception e in ex.Flatten().InnerExceptions)
                {
                    if (e is CloudFoundryException)
                    {
                        logger.LogWarning(e.Message);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public override bool Execute()
        {
            this.CFOrganization = this.CFOrganization.Trim();
            this.CFSpace        = this.CFSpace.Trim();

            var app = LoadAppFromManifest();

            this.Logger = new TaskLogger(this);

            try
            {
                CloudFoundryClient client = InitClient();

                Guid?spaceGuid = null;

                if ((!string.IsNullOrWhiteSpace(this.CFSpace)) && (!string.IsNullOrWhiteSpace(this.CFOrganization)))
                {
                    spaceGuid = Utils.GetSpaceGuid(client, this.Logger, this.CFOrganization, this.CFSpace);

                    if (spaceGuid == null)
                    {
                        return(false);
                    }
                }

                List <string> createdGuid = new List <string>();
                PagedResponseCollection <ListAllDomainsDeprecatedResponse> domainInfoList = client.DomainsDeprecated.ListAllDomainsDeprecated().Result;

                if (spaceGuid.HasValue)
                {
                    foreach (string domain in app.Domains)
                    {
                        foreach (string host in app.Hosts)
                        {
                            if (string.IsNullOrWhiteSpace(host) == false)
                            {
                                Logger.LogMessage("Creating route {0}.{1}", host, domain);

                                ListAllDomainsDeprecatedResponse domainInfo = domainInfoList.Where(o => o.Name == domain).FirstOrDefault();

                                if (domainInfo == null)
                                {
                                    Logger.LogError("Domain {0} not found", domain);
                                    continue;
                                }

                                this.CreateRoute(client, spaceGuid, createdGuid, host, domainInfo);
                            }
                        }
                    }

                    this.CFRouteGuids = createdGuid.ToArray();
                }
                else
                {
                    Logger.LogError("Space {0} not found", this.CFSpace);
                    return(false);
                }
            }
            catch (Exception exception)
            {
                this.Logger.LogError("Create Route failed", exception);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 7
0
        private void CreateRoute(CloudFoundryClient client, Guid?spaceGuid, List <string> createdGuid, string host, ListAllDomainsDeprecatedResponse domainInfo)
        {
            CreateRouteRequest req = new CreateRouteRequest();

            req.DomainGuid = new Guid(domainInfo.EntityMetadata.Guid);
            req.SpaceGuid  = spaceGuid;
            req.Host       = host;
            try
            {
                var routes = client.Routes.ListAllRoutes(new RequestOptions()
                {
                    Query = string.Format(CultureInfo.InvariantCulture, "host:{0}&domain_guid:{1}", host, domainInfo.EntityMetadata.Guid)
                }).Result;

                if (routes.Count() > 0)
                {
                    ListAllRoutesResponse routeInfo = routes.FirstOrDefault();
                    Logger.LogMessage("Route {0}.{1} already exists", routeInfo.Host, domainInfo.Name);
                    if (routeInfo != null)
                    {
                        createdGuid.Add(routeInfo.EntityMetadata.Guid);
                    }
                }
                else
                {
                    CreateRouteResponse response = client.Routes.CreateRoute(req).Result;
                    createdGuid.Add(response.EntityMetadata.Guid);
                }
            }
            catch (AggregateException ex)
            {
                foreach (Exception e in ex.Flatten().InnerExceptions)
                {
                    if (e is CloudFoundryException)
                    {
                        Logger.LogWarning(e.Message);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 8
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 <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);
        }
Ejemplo n.º 9
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);
        }