コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #5
0
        public override bool Execute()
        {
            this.CFOrganization = this.CFOrganization.Trim();
            this.CFSpace        = this.CFSpace.Trim();

            var app = LoadAppFromManifest();

            this.Logger = new TaskLogger(this);
            CloudFoundryClient client = InitClient();

            Guid?spaceGuid = null;
            Guid?stackGuid = null;

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

                if (!string.IsNullOrWhiteSpace(app.StackName))
                {
                    PagedResponseCollection <ListAllStacksResponse> stackList = client.Stacks.ListAllStacks().Result;

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

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

                    stackGuid = new Guid(stackInfo.EntityMetadata.Guid);
                }

                if (stackGuid.HasValue && spaceGuid.HasValue)
                {
                    PagedResponseCollection <ListAllAppsForSpaceResponse> apps = client.Spaces.ListAllAppsForSpace(spaceGuid, new RequestOptions()
                    {
                        Query = "name:" + app.Name
                    }).Result;

                    if (apps.Count() > 0)
                    {
                        this.CFAppGuid = apps.FirstOrDefault().EntityMetadata.Guid;

                        UpdateAppRequest request = new UpdateAppRequest();
                        request.SpaceGuid = spaceGuid;
                        request.StackGuid = stackGuid;

                        request.EnvironmentJson = app.EnvironmentVariables;

                        request.Memory = (int)app.Memory;

                        request.Instances = app.InstanceCount;

                        request.Buildpack = app.BuildpackUrl;

                        request.Command = app.Command;

                        if (app.DiskQuota.HasValue)
                        {
                            request.DiskQuota = app.DiskQuota.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
                        }

                        UpdateAppResponse response = client.Apps.UpdateApp(new Guid(this.CFAppGuid), request).Result;
                        Logger.LogMessage("Updated app {0} with guid {1}", response.Name, response.EntityMetadata.Guid);
                    }
                    else
                    {
                        CreateAppRequest request = new CreateAppRequest();
                        request.Name      = app.Name;
                        request.SpaceGuid = spaceGuid;
                        request.StackGuid = stackGuid;

                        request.EnvironmentJson = app.EnvironmentVariables;

                        request.Memory = (int)app.Memory;

                        request.Instances = app.InstanceCount;

                        request.Buildpack = app.BuildpackUrl;

                        request.Command = app.Command;

                        if (app.DiskQuota.HasValue)
                        {
                            request.DiskQuota = Convert.ToInt32(app.DiskQuota.Value, System.Globalization.CultureInfo.InvariantCulture);
                        }

                        CreateAppResponse response = client.Apps.CreateApp(request).Result;
                        this.CFAppGuid = response.EntityMetadata.Guid;
                        Logger.LogMessage("Created app {0} with guid {1}", app.Name, this.CFAppGuid);
                    }
                }
            }
            catch (Exception exception)
            {
                this.Logger.LogError("Create App failed", exception);
                return(false);
            }

            return(true);
        }
コード例 #6
0
        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);
        }
コード例 #7
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);
        }
コード例 #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);
        }
コード例 #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);
        }