Represents an environment. Environments are user-defined and map to real world deployment environments such as development, staging, test and production. Projects are deployed to environments.
Inheritance: Resource, INamedResource
        private void CleanUpEnvironment(List<MachineResource> filteredMachines, EnvironmentResource environmentResource)
        {
            Log.Information("Found {MachineCount} machines in {Environment:l} with the status {Status:l}", filteredMachines.Count, environmentResource.Name, GetStateFilterDescription());

            if (filteredMachines.Any(m => m.EnvironmentIds.Count > 1))
            {
                Log.Information("Note: Some of these machines belong to multiple environments. Instead of being deleted, these machines will be removed from the {Environment:l} environment.", environmentResource.Name);
            }

            foreach (var machine in filteredMachines)
            {
                // If the machine belongs to more than one environment, we should remove the machine from the environment rather than delete it altogether.
                if (machine.EnvironmentIds.Count > 1)
                {
                    Log.Information("Removing {Machine:l} {Status} (ID: {Id:l}) from {Environment:l}", machine.Name, machine.Status, machine.Id,
                        environmentResource.Name);
                    machine.EnvironmentIds.Remove(environmentResource.Id);
                    Repository.Machines.Modify(machine);
                }
                else
                {
                    Log.Information("Deleting {Machine:l} {Status} (ID: {Id:l})", machine.Name, machine.Status, machine.Id);
                    Repository.Machines.Delete(machine);
                }
            }
        }
Esempio n. 2
0
 public FormResources(Entities.Form form, VariableCollection variables, EnvironmentResource environment, IEnumerable<MachineResource> machines,
     IEnumerable<string> roles, Dictionary<string, string> actions)
 {
     Form = form;
     Variables = variables;
     Environment = environment;
     Machines = machines;
     Roles = roles;
     Actions = actions;
 }
Esempio n. 3
0
        public void AddAutoDeployReleaseOverride(EnvironmentResource environment, TenantResource tenant, ReleaseResource release)
        {
            var autoDeployReleaseOverrideResource = new AutoDeployReleaseOverrideResource(environment.Id, tenant?.Id, release.Id);

            var existingAutoDeployReleaseOverride = AutoDeployReleaseOverrides.SingleOrDefault(x => x.EnvironmentId == environment.Id && x.TenantId == tenant?.Id);

            if (existingAutoDeployReleaseOverride != null)
            {
                AutoDeployReleaseOverrides.Remove(existingAutoDeployReleaseOverride);
            }

            AutoDeployReleaseOverrides.Add(autoDeployReleaseOverrideResource);
        }
        private void DeleteOverrideForEnvironment(ProjectResource project, EnvironmentResource environment)
        {
            var autoDeployOverride = project.AutoDeployReleaseOverrides.SingleOrDefault(
                o => o.EnvironmentId == environment.Id && o.TenantId == null);

            if (autoDeployOverride == null)
            {
                Log.Warning("Did not find an auto deploy override for the project {Project:l} and environment {Environment:l}", project.Name, environment.Name);
            }
            else
            {
                project.AutoDeployReleaseOverrides.Remove(autoDeployOverride);
                Log.Information("Deleted auto deploy release override for the project {Project:l} to the environment {Environment:l}", project.Name, environment.Name);
            }
        }
        public void SetUp()
        {
            createAutoDeployOverrideCommand = new CreateAutoDeployOverrideCommand(RepositoryFactory, Log, FileSystem, ClientFactory);

            environment = new EnvironmentResource { Name = "Production", Id = "Environments-001" };
            project = new ProjectResource("Projects-1", "OctoFx", "OctoFx");
            release = new ReleaseResource("1.2.0", "Projects-1", "Channels-1");
            octopusTenant = new TenantResource
            {
                Id = "Tenants-1",
                Name = "Octopus",
                ProjectEnvironments = { ["Projects-1"] = new ReferenceCollection("Environments-001") }
            };

            Repository.Environments.FindByName("Production").Returns(
                environment
            );

            Repository.Projects.FindByName("OctoFx").Returns(
                project
            );

            Repository.Projects.GetReleaseByVersion(Arg.Any<ProjectResource>(), "1.2.0").Returns(
                release
            );

            Repository.Tenants.FindByNames(Arg.Any<IEnumerable<string>>()).Returns(
                new List<TenantResource>
                {
                    octopusTenant
                }
            );
            Repository.Tenants.FindAll(null, Arg.Any<string[]>()).Returns(
                new List<TenantResource>
                {
                    octopusTenant
                }
            );

            Repository.Projects.When(x => x.Modify(Arg.Any<ProjectResource>()))
                .Do(x => savedProject = x.Args()[0] as ProjectResource);
        }
Esempio n. 6
0
 public void AddAutoDeployReleaseOverride(EnvironmentResource environment, ReleaseResource release)
 {
     AddAutoDeployReleaseOverride(environment, null, release);
 }
Esempio n. 7
0
 public MachineResource RemoveEnvironment(EnvironmentResource environment)
 {
     EnvironmentIds.Remove(environment.Id);
     return(this);
 }
        void AddOverrideForTenant(ProjectResource project, EnvironmentResource environment, TenantResource tenant, ReleaseResource release)
        {
            if (!tenant.ProjectEnvironments.ContainsKey(project.Id))
            {
                Log.Warning("The tenant {Tenant:l} was skipped because it has not been connected to the project {Project:l}", tenant.Name, project.Name);
                return;
            }
            if (!tenant.ProjectEnvironments[project.Id].Contains(environment.Id))
            {
                Log.Warning("The tenant {Tenant:l} was skipped because it has not been connected to the environment {Environment:l}", tenant.Name, environment.Name);
                return;
            }

            project.AddAutoDeployReleaseOverride(environment, tenant, release);
            Log.Information("Auto deploy will deploy version {Version:l} of the project {Project:l} to the environment {Environment:l} for the tenant {Tenant:l}", release.Version, project.Name, environment.Name, tenant.Name);
        }
 void AddOverrideForEnvironment(ProjectResource project, EnvironmentResource environment, ReleaseResource release)
 {
     project.AddAutoDeployReleaseOverride(environment, release);
     Log.Information("Auto deploy will deploy version {Version:l} of the project {Project:l} to the environment {Environment:l}", release.Version, project.Name, environment.Name);
 }
Esempio n. 10
0
 public MachineResource RemoveEnvironment(EnvironmentResource environment)
 {
     EnvironmentIds.Remove(environment.Id);
     return this;
 }
 private Task<List<MachineResource>> FilterByEnvironment(EnvironmentResource environmentResource)
 {
     Log.Debug("Loading machines...");
     return Repository.Machines.FindMany(x =>  x.EnvironmentIds.Any(environmentId => environmentId == environmentResource.Id));
 }