private static List <DeployUnitInfoDTO> GetDeployUnits(IAsimovConfig config, string agentGroup = null)
        {
            var units = new List <DeployUnitInfoDTO>();

            foreach (var deployUnit in config.GetUnitsByGroup(agentGroup))
            {
                var unitInfo    = deployUnit.GetUnitInfo();
                var unitInfoDto = new DeployUnitInfoDTO
                {
                    name         = unitInfo.Name,
                    lastDeployed = unitInfo.LastDeployed
                };

                if (unitInfo.DeployStatus != DeployStatus.NA)
                {
                    unitInfoDto.status       = unitInfo.DeployStatus.ToString();
                    unitInfoDto.lastDeployed = "";
                }
                else
                {
                    unitInfoDto.status = unitInfo.Status.ToString();
                }

                unitInfoDto.url                 = unitInfo.Url;
                unitInfoDto.version             = unitInfo.Version.VersionNumber;
                unitInfoDto.branch              = unitInfo.Version.VersionBranch;
                unitInfoDto.hasDeployParameters = unitInfo.HasDeployParameters;
                unitInfoDto.actions             = deployUnit.Actions.OrderBy(x => x.Sort).Select(x => x.Name).ToArray();

                units.Add(unitInfoDto);
            }
            return(units);
        }
Exemple #2
0
        public DeployUnitModule(IAsimovConfig config)
        {
            Get["/units/list"] = _ =>
            {
                var units = new List <DeployUnitInfoDTO>();

                foreach (var deployUnit in config.Units)
                {
                    var unitInfo    = deployUnit.GetUnitInfo();
                    var unitInfoDto = new DeployUnitInfoDTO();
                    unitInfoDto.name         = unitInfo.Name;
                    unitInfoDto.lastDeployed = unitInfo.LastDeployed;

                    if (unitInfo.DeployStatus != DeployStatus.NA)
                    {
                        unitInfoDto.status       = unitInfo.DeployStatus.ToString();
                        unitInfoDto.lastDeployed = "";
                    }
                    else
                    {
                        unitInfoDto.status = unitInfo.Status.ToString();
                    }

                    unitInfoDto.url                 = unitInfo.Url;
                    unitInfoDto.version             = unitInfo.Version.VersionNumber;
                    unitInfoDto.branch              = unitInfo.Version.VersionBranch;
                    unitInfoDto.hasDeployParameters = unitInfo.HasDeployParameters;
                    unitInfoDto.actions             = deployUnit.Actions.OrderBy(x => x.Sort).Select(x => x.Name).ToArray();

                    units.Add(unitInfoDto);
                }

                return(Response.AsJson(units));
            };

            Get["/units/deploy-parameters/{unitName}"] = urlArgs =>
            {
                var deployUnit = config.GetUnitByName((string)urlArgs.unitName);
                if (deployUnit == null)
                {
                    return(404);
                }

                var parameters = new List <dynamic>();
                foreach (var deployParameter in deployUnit.DeployParameters)
                {
                    parameters.Add(deployParameter.GetDescriptor());
                }

                return(Response.AsJson(parameters));
            };
        }
        private static List <DeployUnitInfoDTO> GetDeployUnits(IAsimovConfig config, GetDeployUnitsRequestDto getDeployUnitsRequestDto)
        {
            var deployUnits = config.Units.AsEnumerable();

            if (getDeployUnitsRequestDto.AgentGroups != null && getDeployUnitsRequestDto.AgentGroups.Any())
            {
                var filteredByAgentGroups = getDeployUnitsRequestDto.AgentGroups.SelectMany(config.GetUnitsByAgentGroup);
                deployUnits = deployUnits.Intersect(filteredByAgentGroups);
            }

            if (getDeployUnitsRequestDto.UnitGroups != null && getDeployUnitsRequestDto.UnitGroups.Any())
            {
                var filteredByUnitGroups = getDeployUnitsRequestDto.UnitGroups.SelectMany(config.GetUnitsByUnitGroup);
                deployUnits = deployUnits.Intersect(filteredByUnitGroups);
            }

            if (getDeployUnitsRequestDto.UnitTypes != null && getDeployUnitsRequestDto.UnitTypes.Any())
            {
                var filteredByType = getDeployUnitsRequestDto.UnitTypes.SelectMany(config.GetUnitsByType);
                deployUnits = deployUnits.Intersect(filteredByType);
            }

            if (getDeployUnitsRequestDto.Tags != null && getDeployUnitsRequestDto.Tags.Any())
            {
                var filteredByTags = getDeployUnitsRequestDto.Tags.SelectMany(config.GetUnitsByTag);
                deployUnits = deployUnits.Intersect(filteredByTags);
            }

            if (getDeployUnitsRequestDto.Units != null && getDeployUnitsRequestDto.Units.Any())
            {
                var filteredByUnits = getDeployUnitsRequestDto.Units.SelectMany(config.GetUnitsByUnitName);
                deployUnits = deployUnits.Intersect(filteredByUnits);
            }

            if (getDeployUnitsRequestDto.UnitStatus != null && getDeployUnitsRequestDto.UnitStatus.Any())
            {
                var filteredByStatus = getDeployUnitsRequestDto.UnitStatus.SelectMany(s => config.GetUnitsByStatus(s, !getDeployUnitsRequestDto.SkipStatusRefresh));
                deployUnits = deployUnits.Intersect(filteredByStatus);
            }

            var list = new List <DeployUnitInfoDTO>();

            foreach (var deployUnit in deployUnits.ToList().Distinct())
            {
                var unitInfo    = deployUnit.GetUnitInfo(!getDeployUnitsRequestDto.SkipStatusRefresh);
                var unitInfoDto = new DeployUnitInfoDTO
                {
                    name         = unitInfo.Name,
                    group        = unitInfo.Group,
                    type         = deployUnit.UnitType,
                    status       = unitInfo.GetUnitStatus(),
                    lastDeployed = unitInfo.LastDeployed,
                    tags         = deployUnit.Tags.ToArray()
                };

                if (unitInfo.DeployStatus != DeployStatus.NA)
                {
                    unitInfoDto.lastDeployed = "";
                }

                unitInfoDto.url                 = unitInfo.Url;
                unitInfoDto.version             = unitInfo.Version.VersionNumber;
                unitInfoDto.branch              = unitInfo.Version.VersionBranch;
                unitInfoDto.hasDeployParameters = unitInfo.HasDeployParameters;
                unitInfoDto.actions             = deployUnit.Actions.OrderBy(x => x.Sort).Select(x => x.Name).ToArray();

                list.Add(unitInfoDto);
            }

            return(list);
        }