diff --git a/api/api-elastic-profile-v1/src/main/java/com/thoughtworks/go/apiv1/elasticprofile/representers/ElasticProfileRepresenter.java b/api/api-elastic-profile-v1/src/main/java/com/thoughtworks/go/apiv1/elasticprofile/representers/ElasticProfileRepresenter.java index 528cbbf1a3f..a773daca73d 100644 --- a/api/api-elastic-profile-v1/src/main/java/com/thoughtworks/go/apiv1/elasticprofile/representers/ElasticProfileRepresenter.java +++ b/api/api-elastic-profile-v1/src/main/java/com/thoughtworks/go/apiv1/elasticprofile/representers/ElasticProfileRepresenter.java @@ -48,7 +48,8 @@ public static void toJSON(OutputWriter outputWriter, ElasticProfile elasticProfi public static ElasticProfile fromJSON(JsonReader jsonReader) { ElasticProfile elasticProfile = new ElasticProfile( jsonReader.getString("id"), - jsonReader.getString("plugin_id")); + jsonReader.getString("plugin_id"), + null); elasticProfile.addConfigurations(ConfigurationPropertyRepresenter.fromJSONArray(jsonReader, "properties")); return elasticProfile; } diff --git a/base/src/main/java/com/thoughtworks/go/util/GoConstants.java b/base/src/main/java/com/thoughtworks/go/util/GoConstants.java index c6a4f798140..37ce0dd22fc 100644 --- a/base/src/main/java/com/thoughtworks/go/util/GoConstants.java +++ b/base/src/main/java/com/thoughtworks/go/util/GoConstants.java @@ -54,7 +54,7 @@ public class GoConstants { public static final String PRODUCT_NAME = "go"; - public static final int CONFIG_SCHEMA_VERSION = 117; + public static final int CONFIG_SCHEMA_VERSION = 118; public static final String APPROVAL_SUCCESS = "success"; public static final String APPROVAL_MANUAL = "manual"; diff --git a/common/src/test/java/com/thoughtworks/go/domain/AgentInstanceTest.java b/common/src/test/java/com/thoughtworks/go/domain/AgentInstanceTest.java index b7a8bfb58de..3242ba2e417 100644 --- a/common/src/test/java/com/thoughtworks/go/domain/AgentInstanceTest.java +++ b/common/src/test/java/com/thoughtworks/go/domain/AgentInstanceTest.java @@ -652,7 +652,7 @@ public void shouldNotMatchJobPlanIfJobRequiresElasticAgent_MatchingIsManagedByBu agentConfig.setElasticPluginId(elasticPluginId); AgentInstance agentInstance = new AgentInstance(agentConfig, REMOTE, mock(SystemEnvironment.class), null); DefaultJobPlan jobPlan1 = new DefaultJobPlan(); - jobPlan1.setElasticProfile(new ElasticProfile("foo", elasticPluginId)); + jobPlan1.setElasticProfile(new ElasticProfile("foo", elasticPluginId, "prod-cluster")); List jobPlans = asList(jobPlan1, new DefaultJobPlan()); assertThat(agentInstance.firstMatching(jobPlans), is(nullValue())); @@ -666,7 +666,7 @@ public void shouldNotMatchJobPlanIfTheAgentWasLaunchedByADifferentPluginFromThat agentConfig.setElasticPluginId(elasticPluginId); AgentInstance agentInstance = new AgentInstance(agentConfig, REMOTE, mock(SystemEnvironment.class), null); DefaultJobPlan jobPlan1 = new DefaultJobPlan(); - jobPlan1.setElasticProfile(new ElasticProfile("foo", "elastic-plugin-id-2")); + jobPlan1.setElasticProfile(new ElasticProfile("foo", "elastic-plugin-id-2", "prod-cluster")); List jobPlans = asList(jobPlan1, new DefaultJobPlan()); assertThat(agentInstance.firstMatching(jobPlans), is(nullValue())); diff --git a/config/config-api/src/main/java/com/thoughtworks/go/config/elastic/ElasticProfile.java b/config/config-api/src/main/java/com/thoughtworks/go/config/elastic/ElasticProfile.java index 9560a859319..d733ae11c7e 100644 --- a/config/config-api/src/main/java/com/thoughtworks/go/config/elastic/ElasticProfile.java +++ b/config/config-api/src/main/java/com/thoughtworks/go/config/elastic/ElasticProfile.java @@ -16,12 +16,14 @@ package com.thoughtworks.go.config.elastic; +import com.thoughtworks.go.config.ConfigAttribute; import com.thoughtworks.go.config.ConfigCollection; import com.thoughtworks.go.config.ConfigTag; import com.thoughtworks.go.config.PluginProfile; import com.thoughtworks.go.domain.config.ConfigurationProperty; import com.thoughtworks.go.plugin.access.elastic.ElasticAgentMetadataStore; import com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo; +import org.apache.commons.lang3.StringUtils; import java.util.Collection; @@ -29,16 +31,24 @@ @ConfigCollection(value = ConfigurationProperty.class) public class ElasticProfile extends PluginProfile { + @ConfigAttribute(value = "clusterProfileId", allowNull = false) + protected String clusterProfileId; + public ElasticProfile() { super(); } - public ElasticProfile(String id, String pluginId, ConfigurationProperty... props) { + public ElasticProfile(String id, String pluginId, String clusterProfileId, ConfigurationProperty... props) { super(id, pluginId, props); + this.clusterProfileId = StringUtils.isBlank(clusterProfileId) ? "default" : clusterProfileId; + } + + public ElasticProfile(String id, String pluginId, String clusterProfileId, Collection configProperties) { + this(id, pluginId, clusterProfileId, configProperties.toArray(new ConfigurationProperty[0])); } - public ElasticProfile(String id, String pluginId, Collection configProperties) { - this(id, pluginId, configProperties.toArray(new ConfigurationProperty[0])); + public String getClusterProfileId() { + return clusterProfileId; } @Override diff --git a/config/config-api/src/test/java/com/thoughtworks/go/config/ConfigSaveValidationContextTest.java b/config/config-api/src/test/java/com/thoughtworks/go/config/ConfigSaveValidationContextTest.java index 606fd9f5f07..af87fe05bb1 100644 --- a/config/config-api/src/test/java/com/thoughtworks/go/config/ConfigSaveValidationContextTest.java +++ b/config/config-api/src/test/java/com/thoughtworks/go/config/ConfigSaveValidationContextTest.java @@ -142,7 +142,7 @@ public void shouldCheckForExistenceOfPackage() throws Exception { public void isValidProfileIdShouldBeValidInPresenceOfElasticProfile() { BasicCruiseConfig cruiseConfig = new BasicCruiseConfig(); ElasticConfig elasticConfig = new ElasticConfig(); - elasticConfig.setProfiles(new ElasticProfiles(new ElasticProfile("docker.unit-test", "docker"))); + elasticConfig.setProfiles(new ElasticProfiles(new ElasticProfile("docker.unit-test", "docker", "prod-cluster"))); cruiseConfig.setElasticConfig(elasticConfig); ValidationContext context = ConfigSaveValidationContext.forChain(cruiseConfig); @@ -153,7 +153,7 @@ public void isValidProfileIdShouldBeValidInPresenceOfElasticProfile() { public void isValidProfileIdShouldBeInValidInAbsenceOfElasticProfileForTheGivenId() { BasicCruiseConfig cruiseConfig = new BasicCruiseConfig(); ElasticConfig elasticConfig = new ElasticConfig(); - elasticConfig.setProfiles(new ElasticProfiles(new ElasticProfile("docker.unit-test", "docker"))); + elasticConfig.setProfiles(new ElasticProfiles(new ElasticProfile("docker.unit-test", "docker", "prod-cluster"))); cruiseConfig.setElasticConfig(elasticConfig); ValidationContext context = ConfigSaveValidationContext.forChain(cruiseConfig); diff --git a/config/config-api/src/test/java/com/thoughtworks/go/config/PipelineConfigSaveValidationContextTest.java b/config/config-api/src/test/java/com/thoughtworks/go/config/PipelineConfigSaveValidationContextTest.java index 28b6262239c..d457c26e8be 100644 --- a/config/config-api/src/test/java/com/thoughtworks/go/config/PipelineConfigSaveValidationContextTest.java +++ b/config/config-api/src/test/java/com/thoughtworks/go/config/PipelineConfigSaveValidationContextTest.java @@ -194,7 +194,7 @@ public void shouldCheckForExistenceOfPackage() throws Exception { public void isValidProfileIdShouldBeValidInPresenceOfElasticProfile() { BasicCruiseConfig cruiseConfig = new BasicCruiseConfig(); ElasticConfig elasticConfig = new ElasticConfig(); - elasticConfig.setProfiles(new ElasticProfiles(new ElasticProfile("docker.unit-test", "docker"))); + elasticConfig.setProfiles(new ElasticProfiles(new ElasticProfile("docker.unit-test", "docker", "prod-cluster"))); cruiseConfig.setElasticConfig(elasticConfig); ValidationContext context = PipelineConfigSaveValidationContext.forChain(true, "group", cruiseConfig, new PipelineConfig()); @@ -205,7 +205,7 @@ public void isValidProfileIdShouldBeValidInPresenceOfElasticProfile() { public void isValidProfileIdShouldBeInValidInAbsenceOfElasticProfileForTheGivenId() { BasicCruiseConfig cruiseConfig = new BasicCruiseConfig(); ElasticConfig elasticConfig = new ElasticConfig(); - elasticConfig.setProfiles(new ElasticProfiles(new ElasticProfile("docker.unit-test", "docker"))); + elasticConfig.setProfiles(new ElasticProfiles(new ElasticProfile("docker.unit-test", "docker", "prod-cluster"))); cruiseConfig.setElasticConfig(elasticConfig); ValidationContext context = PipelineConfigSaveValidationContext.forChain(true, "group", cruiseConfig, new PipelineConfig()); diff --git a/config/config-api/src/test/java/com/thoughtworks/go/config/elastic/ElasticProfileTest.java b/config/config-api/src/test/java/com/thoughtworks/go/config/elastic/ElasticProfileTest.java index e544fdf42f1..6196de14595 100644 --- a/config/config-api/src/test/java/com/thoughtworks/go/config/elastic/ElasticProfileTest.java +++ b/config/config-api/src/test/java/com/thoughtworks/go/config/elastic/ElasticProfileTest.java @@ -58,7 +58,7 @@ public void shouldNotAllowNullPluginIdOrProfileId() throws Exception { @Test public void shouldValidateElasticPluginIdPattern() throws Exception { - ElasticProfile profile = new ElasticProfile("!123", "docker"); + ElasticProfile profile = new ElasticProfile("!123", "docker", "prod-cluster"); profile.validate(null); assertThat(profile.errors().size(), is(1)); assertThat(profile.errors().on(ElasticProfile.ID), is("Invalid id '!123'. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters.")); @@ -68,7 +68,7 @@ public void shouldValidateElasticPluginIdPattern() throws Exception { public void shouldValidateConfigPropertyNameUniqueness() throws Exception { ConfigurationProperty prop1 = ConfigurationPropertyMother.create("USERNAME"); ConfigurationProperty prop2 = ConfigurationPropertyMother.create("USERNAME"); - ElasticProfile profile = new ElasticProfile("docker.unit-test", "cd.go.elastic-agent.docker", prop1, prop2); + ElasticProfile profile = new ElasticProfile("docker.unit-test", "cd.go.elastic-agent.docker", "prod-cluster", prop1, prop2); profile.validate(null); @@ -85,7 +85,7 @@ public void shouldValidateConfigPropertyNameUniqueness() throws Exception { public void addConfigurations_shouldAddConfigurationsWithValue() throws Exception { ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("username"), new ConfigurationValue("some_name")); - ElasticProfile profile = new ElasticProfile("id", "plugin_id"); + ElasticProfile profile = new ElasticProfile("id", "plugin_id", "prod-cluster"); profile.addConfigurations(Arrays.asList(property)); assertThat(profile.size(), is(1)); @@ -96,7 +96,7 @@ public void addConfigurations_shouldAddConfigurationsWithValue() throws Exceptio public void addConfigurations_shouldAddConfigurationsWithEncryptedValue() throws Exception { ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("username"), new EncryptedConfigurationValue("some_name")); - ElasticProfile profile = new ElasticProfile("id", "plugin_id"); + ElasticProfile profile = new ElasticProfile("id", "plugin_id", "prod-cluster"); profile.addConfigurations(Arrays.asList(property)); assertThat(profile.size(), is(1)); @@ -109,7 +109,7 @@ public void addConfiguration_shouldEncryptASecureVariable() throws Exception { ElasticAgentPluginInfo pluginInfo = new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), profileSettings, null, null, null); store.setPluginInfo(pluginInfo); - ElasticProfile profile = new ElasticProfile("id", "plugin_id"); + ElasticProfile profile = new ElasticProfile("id", "plugin_id", "prod-cluster"); profile.addConfigurations(Arrays.asList(new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass")))); assertThat(profile.size(), is(1)); @@ -121,7 +121,7 @@ public void addConfiguration_shouldIgnoreEncryptionInAbsenceOfCorrespondingConfi ElasticAgentPluginInfo pluginInfo = new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), new PluggableInstanceSettings(new ArrayList<>()), null, null, null); store.setPluginInfo(pluginInfo); - ElasticProfile profile = new ElasticProfile("id", "plugin_id"); + ElasticProfile profile = new ElasticProfile("id", "plugin_id", "prod-cluster"); profile.addConfigurations(Arrays.asList(new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass")))); assertThat(profile.size(), is(1)); @@ -135,7 +135,7 @@ public void postConstruct_shouldEncryptSecureConfigurations() { ElasticAgentPluginInfo pluginInfo = new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), profileSettings, null, null, null); store.setPluginInfo(pluginInfo); - ElasticProfile profile = new ElasticProfile("id", "plugin_id", new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass"))); + ElasticProfile profile = new ElasticProfile("id", "plugin_id", "prod-cluster", new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass"))); profile.encryptSecureConfigurations(); @@ -145,7 +145,7 @@ public void postConstruct_shouldEncryptSecureConfigurations() { @Test public void postConstruct_shouldIgnoreEncryptionIfPluginInfoIsNotDefined() { - ElasticProfile profile = new ElasticProfile("id", "plugin_id", new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass"))); + ElasticProfile profile = new ElasticProfile("id", "plugin_id", "prod-cluster", new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass"))); profile.encryptSecureConfigurations(); diff --git a/config/config-api/src/test/java/com/thoughtworks/go/config/elastic/ElasticProfilesTest.java b/config/config-api/src/test/java/com/thoughtworks/go/config/elastic/ElasticProfilesTest.java index a33e38b34c7..f7a5e859ed1 100644 --- a/config/config-api/src/test/java/com/thoughtworks/go/config/elastic/ElasticProfilesTest.java +++ b/config/config-api/src/test/java/com/thoughtworks/go/config/elastic/ElasticProfilesTest.java @@ -26,14 +26,14 @@ public class ElasticProfilesTest { @Test public void shouldFindProfileById() throws Exception { assertThat(new ElasticProfiles().find("foo"), is(nullValue())); - ElasticProfile profile = new ElasticProfile("foo", "docker"); + ElasticProfile profile = new ElasticProfile("foo", "docker", "prod-cluster"); assertThat(new ElasticProfiles(profile).find("foo"), is(profile)); } @Test public void shouldNotAllowMultipleProfilesWithSameId() throws Exception { - ElasticProfile profile1 = new ElasticProfile("foo", null); - ElasticProfile profile2 = new ElasticProfile("foo", null); + ElasticProfile profile1 = new ElasticProfile("foo", null, "prod-cluster"); + ElasticProfile profile2 = new ElasticProfile("foo", null, "prod-cluster"); ElasticProfiles profiles = new ElasticProfiles(profile1, profile2); profiles.validate(null); diff --git a/config/config-server/src/main/resources/cruise-config.xsd b/config/config-server/src/main/resources/cruise-config.xsd index 68cff7628a5..1e3e420046c 100644 --- a/config/config-server/src/main/resources/cruise-config.xsd +++ b/config/config-server/src/main/resources/cruise-config.xsd @@ -89,7 +89,7 @@ - + @@ -310,7 +310,7 @@ - + @@ -325,12 +325,12 @@ - + - + @@ -348,6 +348,14 @@ + + + + + + + + diff --git a/config/config-server/src/main/resources/schemas/117_cruise-config.xsd b/config/config-server/src/main/resources/schemas/117_cruise-config.xsd new file mode 100644 index 00000000000..68cff7628a5 --- /dev/null +++ b/config/config-server/src/main/resources/schemas/117_cruise-config.xsd @@ -0,0 +1,1119 @@ + + + + + + + Configuration schema for Go. Copyright (c) 2017 ThoughtWorks, Inc. + www.thoughtworks.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/config-server/src/main/resources/upgrades/118.xsl b/config/config-server/src/main/resources/upgrades/118.xsl new file mode 100644 index 00000000000..9ebce1a21e6 --- /dev/null +++ b/config/config-server/src/main/resources/upgrades/118.xsl @@ -0,0 +1,49 @@ + + + + + + 118 + + + + + + + + + + + + + + + Key + Value + + + + + + + + + default + + + + diff --git a/domain/src/main/java/com/thoughtworks/go/domain/DefaultJobPlan.java b/domain/src/main/java/com/thoughtworks/go/domain/DefaultJobPlan.java index 0005cb4799e..3624ed828b4 100644 --- a/domain/src/main/java/com/thoughtworks/go/domain/DefaultJobPlan.java +++ b/domain/src/main/java/com/thoughtworks/go/domain/DefaultJobPlan.java @@ -216,7 +216,7 @@ public boolean requiresElasticAgent() { } public void setElasticProfile(ElasticProfile elasticProfile) { - this.elasticProfile = new ElasticProfile(elasticProfile.getId(), elasticProfile.getPluginId(), elasticProfile); + this.elasticProfile = new ElasticProfile(elasticProfile.getId(), elasticProfile.getPluginId(), elasticProfile.getClusterProfileId(), elasticProfile); } @Override diff --git a/domain/src/test/java/com/thoughtworks/go/helper/JobInstanceMother.java b/domain/src/test/java/com/thoughtworks/go/helper/JobInstanceMother.java index 0e024c40771..16eceedbda4 100644 --- a/domain/src/test/java/com/thoughtworks/go/helper/JobInstanceMother.java +++ b/domain/src/test/java/com/thoughtworks/go/helper/JobInstanceMother.java @@ -265,7 +265,7 @@ public static JobPlan createJobPlan(JobConfig jobConfig, JobIdentifier jobIdenti public static JobPlan jobPlanWithAssociatedEntities(String jobName, long id, List artifactPlans, List artifactPropertiesGenerators) { ConfigurationProperty configurationProperty = new ConfigurationProperty(new ConfigurationKey("image"), new ConfigurationValue("elastic-agent")); - ElasticProfile elasticProfile = new ElasticProfile("elastic", "plugin", configurationProperty); + ElasticProfile elasticProfile = new ElasticProfile("elastic", "plugin", "prod-cluster", configurationProperty); EnvironmentVariables variables = new EnvironmentVariables(); variables.add("some_var", "blah"); diff --git a/server/config/cruise-config.xml b/server/config/cruise-config.xml index 2d4d343d324..c79b52cd5ef 100755 --- a/server/config/cruise-config.xml +++ b/server/config/cruise-config.xml @@ -1,5 +1,5 @@ - + diff --git a/server/src/main/java/com/thoughtworks/go/domain/JobAgentMetadata.java b/server/src/main/java/com/thoughtworks/go/domain/JobAgentMetadata.java index b9c89e3d46e..8f8a0603bbf 100644 --- a/server/src/main/java/com/thoughtworks/go/domain/JobAgentMetadata.java +++ b/server/src/main/java/com/thoughtworks/go/domain/JobAgentMetadata.java @@ -45,18 +45,21 @@ public JobAgentMetadata(long jobId, ElasticProfile profile) { public ElasticProfile elasticProfile() { Gson gson = new Gson(); Map map = gson.fromJson(metadata, LinkedHashMap.class); + String clusterProfileId = (String) map.get("clusterProfileId"); String pluginId = (String) map.get("pluginId"); String id = (String) map.get("id"); + Map properties = (Map) map.get("properties"); Collection configProperties = properties.entrySet().stream().map(entry -> new ConfigurationProperty(new ConfigurationKey(entry.getKey()), new ConfigurationValue(entry.getValue()))).collect(Collectors.toList()); - return new ElasticProfile(id, pluginId, configProperties); + return new ElasticProfile(id, pluginId, clusterProfileId, configProperties); } private static String toJSON(ElasticProfile elasticProfile) { Gson gson = new Gson(); Map map = new LinkedHashMap<>(); + map.put("clusterProfileId", elasticProfile.getPluginId()); map.put("pluginId", elasticProfile.getPluginId()); map.put("id", elasticProfile.getId()); map.put("properties", elasticProfile.getConfigurationAsMap(true)); diff --git a/server/src/test-integration/java/com/thoughtworks/go/config/GoConfigMigrationIntegrationTest.java b/server/src/test-integration/java/com/thoughtworks/go/config/GoConfigMigrationIntegrationTest.java index 8be2f2aaaf3..fa6a6f8d4ee 100644 --- a/server/src/test-integration/java/com/thoughtworks/go/config/GoConfigMigrationIntegrationTest.java +++ b/server/src/test-integration/java/com/thoughtworks/go/config/GoConfigMigrationIntegrationTest.java @@ -1234,7 +1234,7 @@ public void shouldCreateProfilesFromAgentConfig_asPartOfMigration86And87() throw ElasticProfiles profiles = migratedConfig.getElasticConfig().getProfiles(); assertThat(profiles.size(), is(1)); - ElasticProfile expectedProfile = new ElasticProfile(jobConfig.getElasticProfileId(), "docker", + ElasticProfile expectedProfile = new ElasticProfile(jobConfig.getElasticProfileId(), "docker", "prod-cluster", new ConfigurationProperty(new ConfigurationKey("instance-type"), new ConfigurationValue("m1.small"))); ElasticProfile elasticProfile = profiles.get(0); @@ -1290,11 +1290,11 @@ public void shouldCreateProfilesFromMultipleAgentConfigs_asPartOfMigration86And8 ElasticProfiles profiles = migratedConfig.getElasticConfig().getProfiles(); assertThat(profiles.size(), is(2)); - ElasticProfile expectedDockerProfile = new ElasticProfile(jobs.get(0).getElasticProfileId(), "docker", + ElasticProfile expectedDockerProfile = new ElasticProfile(jobs.get(0).getElasticProfileId(), "docker", "prod-cluster", new ConfigurationProperty(new ConfigurationKey("instance-type"), new ConfigurationValue("m1.small"))); assertThat(profiles.get(0), is(expectedDockerProfile)); - ElasticProfile expectedAWSProfile = new ElasticProfile(jobs.get(1).getElasticProfileId(), "aws", + ElasticProfile expectedAWSProfile = new ElasticProfile(jobs.get(1).getElasticProfileId(), "aws", "prod-cluster", new ConfigurationProperty(new ConfigurationKey("ami"), new ConfigurationValue("some.ami")), new ConfigurationProperty(new ConfigurationKey("ram"), new ConfigurationValue("1024")), new ConfigurationProperty(new ConfigurationKey("diskSpace"), new ConfigurationValue("10G"))); @@ -1363,17 +1363,17 @@ public void shouldCreateProfilesFromMultipleAgentConfigsAcrossStages_asPartOfMig ElasticProfiles profiles = migratedConfig.getElasticConfig().getProfiles(); assertThat(profiles.size(), is(3)); - ElasticProfile expectedDockerProfile = new ElasticProfile(buildJobs.get(0).getElasticProfileId(), "docker", + ElasticProfile expectedDockerProfile = new ElasticProfile(buildJobs.get(0).getElasticProfileId(), "docker", "prod-cluster", new ConfigurationProperty(new ConfigurationKey("instance-type"), new ConfigurationValue("m1.small"))); assertThat(profiles.get(0), is(expectedDockerProfile)); - ElasticProfile expectedAWSProfile = new ElasticProfile(buildJobs.get(1).getElasticProfileId(), "aws", + ElasticProfile expectedAWSProfile = new ElasticProfile(buildJobs.get(1).getElasticProfileId(), "aws", "prod-cluster", new ConfigurationProperty(new ConfigurationKey("ami"), new ConfigurationValue("some.ami")), new ConfigurationProperty(new ConfigurationKey("ram"), new ConfigurationValue("1024")), new ConfigurationProperty(new ConfigurationKey("diskSpace"), new ConfigurationValue("10G"))); assertThat(profiles.get(1), is(expectedAWSProfile)); - ElasticProfile expectedSecondDockerProfile = new ElasticProfile(distJobs.get(0).getElasticProfileId(), "docker", + ElasticProfile expectedSecondDockerProfile = new ElasticProfile(distJobs.get(0).getElasticProfileId(), "docker", "prod-cluster", new ConfigurationProperty(new ConfigurationKey("instance-type"), new ConfigurationValue("m1.small"))); assertThat(profiles.get(2), is(expectedSecondDockerProfile)); } @@ -1438,11 +1438,11 @@ public void shouldCreateProfilesFromMultipleAgentConfigsAcrossPipelines_asPartOf ElasticProfiles profiles = migratedConfig.getElasticConfig().getProfiles(); assertThat(profiles.size(), is(2)); - ElasticProfile expectedDockerProfile = new ElasticProfile(up42Jobs.get(0).getElasticProfileId(), "docker", + ElasticProfile expectedDockerProfile = new ElasticProfile(up42Jobs.get(0).getElasticProfileId(), "docker", "prod-cluster", new ConfigurationProperty(new ConfigurationKey("instance-type"), new ConfigurationValue("m1.small"))); assertThat(profiles.get(0), is(expectedDockerProfile)); - ElasticProfile expectedAWSProfile = new ElasticProfile(up43Jobs.get(0).getElasticProfileId(), "aws", + ElasticProfile expectedAWSProfile = new ElasticProfile(up43Jobs.get(0).getElasticProfileId(), "aws", "prod-cluster", new ConfigurationProperty(new ConfigurationKey("ami"), new ConfigurationValue("some.ami")), new ConfigurationProperty(new ConfigurationKey("ram"), new ConfigurationValue("1024")), new ConfigurationProperty(new ConfigurationKey("diskSpace"), new ConfigurationValue("10G"))); @@ -1782,7 +1782,7 @@ public void shouldMigrateElasticProfilesOutOfServerConfig_asPartOf100To101Migrat assertThat(cruiseConfig.server().artifactsDir(), is("artifactsDir")); assertThat(cruiseConfig.getElasticConfig().getProfiles(), hasSize(1)); assertThat(cruiseConfig.getElasticConfig().getProfiles().get(0), is( - new ElasticProfile("dev-build", "cd.go.contrib.elastic-agent.docker-swarm", + new ElasticProfile("dev-build", "cd.go.contrib.elastic-agent.docker-swarm", "prod-cluster", ConfigurationPropertyMother.create("Image", false, "bar"), ConfigurationPropertyMother.create("ReservedMemory", false, "3GB"), ConfigurationPropertyMother.create("MaxMemory", false, "3GB") @@ -1856,7 +1856,7 @@ public void shouldSkipParamResoulutionForElasticConfig_asPartOf100To101Migration final CruiseConfig cruiseConfig = migrateConfigAndLoadTheNewConfig(configXml, 100); assertThat(cruiseConfig.getElasticConfig().getProfiles().get(0), is( - new ElasticProfile("dev-build", "cd.go.contrib.elastic-agent.docker-swarm", + new ElasticProfile("dev-build", "cd.go.contrib.elastic-agent.docker-swarm", "prod-cluster", ConfigurationPropertyMother.create("Image", false, "#bar") ) ) @@ -2460,6 +2460,33 @@ public void shouldOnlyUpdateSchemaVersionForMigration116() throws NoSuchMethodEx assertThat(migratedContent, containsString(configContent)); } + @Test + public void shouldAddDefaultClusterProfileIdOnAgentProfilesAsOfMigration118() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { + String configContent = "\n" + + " \n" + + " \n" + + " \n" + + " Image\n" + + " asdf\n" + + " " + + " " + + " " + + " "; + + String configXml = "" + + "\n" + + configContent + + ""; + + String defaultCluster = "Imageasdf"; + + String migratedContent = migrateXmlString(configXml, 117, 118); + + assertThat(migratedContent, containsString("")); + assertThat(migratedContent, containsString(defaultCluster)); + } + private void assertStringsIgnoringCarriageReturnAreEqual(String expected, String actual) { assertEquals(expected.replaceAll("\\r", ""), actual.replaceAll("\\r", "")); } diff --git a/server/src/test-integration/java/com/thoughtworks/go/server/controller/JobControllerIntegrationTest.java b/server/src/test-integration/java/com/thoughtworks/go/server/controller/JobControllerIntegrationTest.java index cc737c952eb..a61996b4a6d 100644 --- a/server/src/test-integration/java/com/thoughtworks/go/server/controller/JobControllerIntegrationTest.java +++ b/server/src/test-integration/java/com/thoughtworks/go/server/controller/JobControllerIntegrationTest.java @@ -183,7 +183,7 @@ public void jobDetailModel_shouldHaveTheElasticProfilePluginIdWhenAgentIsNotAssi GoPluginDescriptor descriptor = new GoPluginDescriptor("plugin_id", null, about, null, null, false); ElasticAgentMetadataStore.instance().setPluginInfo(new ElasticAgentPluginInfo(descriptor, null, null, null, new Capabilities(false, true))); - fixture.addJobAgentMetadata(new JobAgentMetadata(job.getId(), new ElasticProfile("profile_id", "plugin_id", Collections.EMPTY_LIST))); + fixture.addJobAgentMetadata(new JobAgentMetadata(job.getId(), new ElasticProfile("profile_id", "plugin_id", "prod-cluster", Collections.EMPTY_LIST))); ModelAndView modelAndView = controller.jobDetail(pipeline.getName(), String.valueOf(pipeline.getCounter()), stage.getName(), String.valueOf(stage.getCounter()), job.getName()); @@ -201,7 +201,7 @@ public void jobDetailModel_shouldHaveTheElasticPluginIdAndElasticAgentIdWhenAgen GoPluginDescriptor descriptor = new GoPluginDescriptor("plugin_id", null, about, null, null, false); ElasticAgentMetadataStore.instance().setPluginInfo(new ElasticAgentPluginInfo(descriptor, null, null, null, new Capabilities(false, true))); - fixture.addJobAgentMetadata(new JobAgentMetadata(job.getId(), new ElasticProfile("profile_id", "plugin_id", Collections.EMPTY_LIST))); + fixture.addJobAgentMetadata(new JobAgentMetadata(job.getId(), new ElasticProfile("profile_id", "plugin_id", "prod-cluster", Collections.EMPTY_LIST))); final AgentConfig agentConfig = new AgentConfig(job.getAgentUuid()); agentConfig.setElasticAgentId("elastic_agent_id"); diff --git a/server/src/test-integration/java/com/thoughtworks/go/server/dao/JobAgentMetadataSqlMapDaoIntegrationTest.java b/server/src/test-integration/java/com/thoughtworks/go/server/dao/JobAgentMetadataSqlMapDaoIntegrationTest.java index e439da195ec..def7941ce57 100644 --- a/server/src/test-integration/java/com/thoughtworks/go/server/dao/JobAgentMetadataSqlMapDaoIntegrationTest.java +++ b/server/src/test-integration/java/com/thoughtworks/go/server/dao/JobAgentMetadataSqlMapDaoIntegrationTest.java @@ -75,7 +75,7 @@ public void tearDown() throws Exception { @Test public void shouldSaveElasticAgentPropertyOnJob() throws Exception { - ElasticProfile profile = new ElasticProfile("elastic", "plugin", new ConfigurationProperty()); + ElasticProfile profile = new ElasticProfile("elastic", "plugin", "prod-cluster", new ConfigurationProperty()); JobAgentMetadata jobAgentMetadata = new JobAgentMetadata(jobId, profile); dao.save(jobAgentMetadata); @@ -86,7 +86,7 @@ public void shouldSaveElasticAgentPropertyOnJob() throws Exception { @Test public void shouldDeleteElasticAgentPropertySetToJob() throws Exception { - ElasticProfile profile = new ElasticProfile("elastic", "plugin", new ConfigurationProperty()); + ElasticProfile profile = new ElasticProfile("elastic", "plugin", "prod-cluster", new ConfigurationProperty()); JobAgentMetadata jobAgentMetadata = new JobAgentMetadata(jobId, profile); dao.save(jobAgentMetadata); diff --git a/server/src/test-integration/java/com/thoughtworks/go/server/dao/JobInstanceSqlMapDaoIntegrationTest.java b/server/src/test-integration/java/com/thoughtworks/go/server/dao/JobInstanceSqlMapDaoIntegrationTest.java index b7b9c7b090f..7e60d5aa083 100644 --- a/server/src/test-integration/java/com/thoughtworks/go/server/dao/JobInstanceSqlMapDaoIntegrationTest.java +++ b/server/src/test-integration/java/com/thoughtworks/go/server/dao/JobInstanceSqlMapDaoIntegrationTest.java @@ -782,7 +782,7 @@ public void shouldSaveResources() { public void shouldSaveJobAgentMetadata() { JobInstance instance = jobInstanceDao.save(stageId, new JobInstance(JOB_NAME)); instance.setIdentifier(new JobIdentifier(savedPipeline, savedStage, instance)); - ElasticProfile elasticProfile = new ElasticProfile("foo", "cd.go.elastic-agent:docker", Arrays.asList(new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value")))); + ElasticProfile elasticProfile = new ElasticProfile("foo", "cd.go.elastic-agent:docker", "prod-cluster", Arrays.asList(new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value")))); JobPlan plan = new DefaultJobPlan(new Resources("something"), new ArrayList<>(), new ArrayList<>(), instance.getId(), instance.getIdentifier(), null, new EnvironmentVariables(), new EnvironmentVariables(), elasticProfile); jobInstanceDao.save(instance.getId(), plan);