Search in sources :

Example 1 with EnvironmentConfig

use of com.thoughtworks.go.config.EnvironmentConfig in project gocd by gocd.

the class DeletePipelineConfigCommand method isValid.

@Override
public boolean isValid(CruiseConfig preprocessedConfig) {
    for (PipelineConfig pipeline : preprocessedConfig.getAllPipelineConfigs()) {
        if (pipeline.materialConfigs().hasDependencyMaterial(pipelineConfig)) {
            Localizable.CurryableLocalizable message = LocalizedMessage.string("CANNOT_DELETE_PIPELINE_USED_AS_MATERIALS", pipelineConfig.name(), String.format("%s (%s)", pipeline.name(), pipeline.getOriginDisplayName()));
            this.result.unprocessableEntity(message);
            return false;
        }
    }
    for (EnvironmentConfig environment : preprocessedConfig.getEnvironments()) {
        if (environment.getPipelineNames().contains(pipelineConfig.name())) {
            Localizable.CurryableLocalizable message = LocalizedMessage.string("CANNOT_DELETE_PIPELINE_IN_ENVIRONMENT", pipelineConfig.name(), environment.name());
            this.result.unprocessableEntity(message);
            return false;
        }
    }
    return true;
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) EnvironmentConfig(com.thoughtworks.go.config.EnvironmentConfig) Localizable(com.thoughtworks.go.i18n.Localizable)

Example 2 with EnvironmentConfig

use of com.thoughtworks.go.config.EnvironmentConfig in project gocd by gocd.

the class EnvironmentCommand method isValid.

@Override
public boolean isValid(CruiseConfig preprocessedConfig) {
    EnvironmentConfig config = preprocessedConfig.getEnvironments().find(this.environmentConfig.name());
    boolean isValid = config.validateTree(ConfigSaveValidationContext.forChain(preprocessedConfig), preprocessedConfig);
    if (!isValid) {
        String allErrors = new AllConfigErrors(preprocessedConfig.getAllErrors()).asString();
        result.unprocessableEntity(LocalizedMessage.composite(actionFailed, allErrors));
    }
    return isValid;
}
Also used : EnvironmentConfig(com.thoughtworks.go.config.EnvironmentConfig) AllConfigErrors(com.thoughtworks.go.domain.AllConfigErrors)

Example 3 with EnvironmentConfig

use of com.thoughtworks.go.config.EnvironmentConfig in project gocd by gocd.

the class UpdateEnvironmentCommand method isRequestFresh.

private boolean isRequestFresh(CruiseConfig cruiseConfig) {
    EnvironmentConfig config = cruiseConfig.getEnvironments().find(new CaseInsensitiveString(oldEnvironmentConfigName));
    if (config instanceof MergeEnvironmentConfig) {
        config = ((MergeEnvironmentConfig) config).getFirstEditablePart();
    }
    boolean freshRequest = hashingService.hashForEntity(config).equals(digest);
    if (!freshRequest) {
        result.stale(EntityType.Environment.staleConfig(oldEnvironmentConfigName));
    }
    return freshRequest;
}
Also used : EnvironmentConfig(com.thoughtworks.go.config.EnvironmentConfig) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 4 with EnvironmentConfig

use of com.thoughtworks.go.config.EnvironmentConfig in project gocd by gocd.

the class UpdateEnvironmentCommand method update.

@Override
public void update(CruiseConfig preprocessedConfig) {
    EnvironmentsConfig environments = preprocessedConfig.getEnvironments();
    EnvironmentConfig envToRemove = environments.find(new CaseInsensitiveString(oldEnvironmentConfigName));
    int index = environments.indexOf(envToRemove);
    environments.remove(index);
    environments.add(index, environmentConfig);
}
Also used : EnvironmentConfig(com.thoughtworks.go.config.EnvironmentConfig) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) EnvironmentsConfig(com.thoughtworks.go.config.EnvironmentsConfig)

Example 5 with EnvironmentConfig

use of com.thoughtworks.go.config.EnvironmentConfig in project gocd by gocd.

the class InternalEnvironmentsControllerV1 method updateAgentAssociation.

String updateAgentAssociation(Request request, Response response) {
    String envName = request.params("env_name");
    EnvironmentConfig envConfig = environmentConfigService.getEnvironmentConfig(envName);
    JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(request.body());
    JsonReader agents = jsonReader.readJsonObject("agents");
    List<String> uuidsToAssociate = agents.readStringArrayIfPresent("add").orElse(Collections.emptyList());
    List<String> uuidsToRemove = agents.readStringArrayIfPresent("remove").orElse(Collections.emptyList());
    if (!uuidsToAssociate.isEmpty() || !uuidsToRemove.isEmpty()) {
        agentService.updateAgentsAssociationOfEnvironment(envConfig, uuidsToAssociate, uuidsToRemove);
    }
    return renderMessage(response, 200, EntityType.Environment.updateSuccessful(envName));
}
Also used : EnvironmentConfig(com.thoughtworks.go.config.EnvironmentConfig) JsonReader(com.thoughtworks.go.api.representers.JsonReader)

Aggregations

EnvironmentConfig (com.thoughtworks.go.config.EnvironmentConfig)10 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 MergeEnvironmentConfig (com.thoughtworks.go.config.merge.MergeEnvironmentConfig)5 EnvironmentsConfig (com.thoughtworks.go.config.EnvironmentsConfig)2 Sets (com.google.common.collect.Sets)1 CurrentGoCDVersion.apiDocsUrl (com.thoughtworks.go.CurrentGoCDVersion.apiDocsUrl)1 OutputListWriter (com.thoughtworks.go.api.base.OutputListWriter)1 OutputWriter (com.thoughtworks.go.api.base.OutputWriter)1 JsonReader (com.thoughtworks.go.api.representers.JsonReader)1 EnvironmentAgentConfig (com.thoughtworks.go.config.EnvironmentAgentConfig)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 ConfigOrigin (com.thoughtworks.go.config.remote.ConfigOrigin)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 AllConfigErrors (com.thoughtworks.go.domain.AllConfigErrors)1 ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)1 Localizable (com.thoughtworks.go.i18n.Localizable)1 Routes (com.thoughtworks.go.spark.Routes)1 ExceptionUtils.bomb (com.thoughtworks.go.util.ExceptionUtils.bomb)1 java.util (java.util)1