Search in sources :

Example 1 with ElasticProfiles

use of com.thoughtworks.go.config.elastic.ElasticProfiles in project gocd by gocd.

the class GoConfigMigrationIntegrationTest method shouldCreateProfilesFromAgentConfig_asPartOfMigration86And87.

@Test
public void shouldCreateProfilesFromAgentConfig_asPartOfMigration86And87() throws Exception {
    String configXml = "<cruise schemaVersion='85'>" + "  <server serverId='dev-id'>" + "  </server>" + "  <pipelines group='first'>" + "    <pipeline name='up42'>" + "      <materials>" + "        <hg url='../manual-testing/ant_hg/dummy' />" + "      </materials>" + "  <stage name='dist'>" + "    <jobs>" + "      <job name='test'>" + "       <agentConfig pluginId='docker'>" + "         <property>" + "           <key>instance-type</key>" + "           <value>m1.small</value>" + "         </property>" + "       </agentConfig>" + "      </job>" + "    </jobs>" + "  </stage>" + "   </pipeline>" + "  </pipelines>" + "</cruise>";
    CruiseConfig migratedConfig = migrateConfigAndLoadTheNewConfig(configXml, 85);
    PipelineConfig pipelineConfig = migratedConfig.pipelineConfigByName(new CaseInsensitiveString("up42"));
    JobConfig jobConfig = pipelineConfig.getStages().get(0).getJobs().get(0);
    assertThat(migratedConfig.schemaVersion(), greaterThan(86));
    ElasticProfiles profiles = migratedConfig.getElasticConfig().getProfiles();
    assertThat(profiles.size(), is(1));
    ElasticProfile expectedProfile = new ElasticProfile(jobConfig.getElasticProfileId(), "docker", new ConfigurationProperty(new ConfigurationKey("instance-type"), new ConfigurationValue("m1.small")));
    ElasticProfile elasticProfile = profiles.get(0);
    assertThat(elasticProfile, is(expectedProfile));
}
Also used : ElasticProfiles(com.thoughtworks.go.config.elastic.ElasticProfiles) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 2 with ElasticProfiles

use of com.thoughtworks.go.config.elastic.ElasticProfiles in project gocd by gocd.

the class GoConfigMigratorIntegrationTest method shouldCreateProfilesFromMultipleAgentConfigs_asPartOfMigration86And87.

@Test
public void shouldCreateProfilesFromMultipleAgentConfigs_asPartOfMigration86And87() throws Exception {
    String configXml = "<cruise schemaVersion='85'>" + "  <server serverId='dev-id'>" + "  </server>" + "  <pipelines group='first'>" + "    <pipeline name='up42'>" + "      <materials>" + "        <hg url='manual-testing/ant_hg/dummy' />" + "      </materials>" + "  <stage name='dist'>" + "    <jobs>" + "      <job name='test1'><tasks><exec command='echo'><runif status='passed' /></exec></tasks>" + "       <agentConfig pluginId='docker'>" + "         <property>" + "           <key>instance-type</key>" + "           <value>m1.small</value>" + "         </property>" + "       </agentConfig>" + "      </job>" + "      <job name='test2'><tasks><exec command='echo'><runif status='passed' /></exec></tasks>" + "       <agentConfig pluginId='aws'>" + "         <property>" + "           <key>ami</key>" + "           <value>some.ami</value>" + "         </property>" + "         <property>" + "           <key>ram</key>" + "           <value>1024</value>" + "         </property>" + "         <property>" + "           <key>diskSpace</key>" + "           <value>10G</value>" + "         </property>" + "       </agentConfig>" + "      </job>" + "    </jobs>" + "  </stage>" + "   </pipeline>" + "  </pipelines>" + "</cruise>";
    CruiseConfig migratedConfig = migrateConfigAndLoadTheNewConfig(configXml);
    PipelineConfig pipelineConfig = migratedConfig.pipelineConfigByName(new CaseInsensitiveString("up42"));
    JobConfigs jobs = pipelineConfig.getStages().get(0).getJobs();
    ElasticProfiles profiles = migratedConfig.getElasticConfig().getProfiles();
    assertThat(profiles.size()).isEqualTo(2);
    ElasticProfile expectedDockerProfile = new ElasticProfile(jobs.get(0).getElasticProfileId(), "no-op-cluster-for-docker", new ConfigurationProperty(new ConfigurationKey("instance-type"), new ConfigurationValue("m1.small")));
    assertThat(profiles.get(0)).isEqualTo(expectedDockerProfile);
    ElasticProfile expectedAWSProfile = new ElasticProfile(jobs.get(1).getElasticProfileId(), "no-op-cluster-for-aws", 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)).isEqualTo(expectedAWSProfile);
}
Also used : ElasticProfiles(com.thoughtworks.go.config.elastic.ElasticProfiles) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.jupiter.api.Test)

Example 3 with ElasticProfiles

use of com.thoughtworks.go.config.elastic.ElasticProfiles in project gocd by gocd.

the class GoConfigMigratorIntegrationTest method shouldCreateProfilesFromAgentConfig_asPartOfMigration86And87.

@Test
public void shouldCreateProfilesFromAgentConfig_asPartOfMigration86And87() throws Exception {
    String configXml = "<cruise schemaVersion='85'>" + "  <server serverId='dev-id'>" + "  </server>" + "  <pipelines group='first'>" + "    <pipeline name='up42'>" + "      <materials>" + "        <hg url='manual-testing/ant_hg/dummy' />" + "      </materials>" + "  <stage name='dist'>" + "    <jobs>" + "      <job name='test'><tasks><exec command='echo'><runif status='passed' /></exec></tasks>" + "       <agentConfig pluginId='docker'>" + "         <property>" + "           <key>instance-type</key>" + "           <value>m1.small</value>" + "         </property>" + "       </agentConfig>" + "      </job>" + "    </jobs>" + "  </stage>" + "   </pipeline>" + "  </pipelines>" + "</cruise>";
    CruiseConfig migratedConfig = migrateConfigAndLoadTheNewConfig(configXml);
    PipelineConfig pipelineConfig = migratedConfig.pipelineConfigByName(new CaseInsensitiveString("up42"));
    JobConfig jobConfig = pipelineConfig.getStages().get(0).getJobs().get(0);
    assertThat(migratedConfig.schemaVersion()).isGreaterThan(86);
    ElasticProfiles profiles = migratedConfig.getElasticConfig().getProfiles();
    assertThat(profiles.size()).isEqualTo(1);
    ElasticProfile expectedProfile = new ElasticProfile(jobConfig.getElasticProfileId(), "no-op-cluster-for-docker", new ConfigurationProperty(new ConfigurationKey("instance-type"), new ConfigurationValue("m1.small")));
    ElasticProfile elasticProfile = profiles.get(0);
    assertThat(elasticProfile).isEqualTo(expectedProfile);
}
Also used : ElasticProfiles(com.thoughtworks.go.config.elastic.ElasticProfiles) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.jupiter.api.Test)

Example 4 with ElasticProfiles

use of com.thoughtworks.go.config.elastic.ElasticProfiles in project gocd by gocd.

the class GoConfigMigratorIntegrationTest method shouldDefineNoOpClustersAsPartOfMigration119.

@Test
public void shouldDefineNoOpClustersAsPartOfMigration119() throws Exception {
    String configContent = " <elastic>\n" + "    <profiles>\n" + "      <profile id=\"profile1\" pluginId=\"cd.go.contrib.elastic-agent.docker\">\n" + "        <property>\n" + "          <key>Image</key>\n" + "          <value>alpine:latest</value>\n" + "        </property>\n" + "      </profile>" + "      <profile id=\"profile2\" pluginId=\"cd.go.contrib.elasticagent.kubernetes\">\n" + "        <property>\n" + "          <key>Image</key>\n" + "          <value>alpine:latest</value>\n" + "        </property>\n" + "      </profile>" + "      <profile id=\"profile3\" pluginId=\"cd.go.contrib.elastic-agent.docker\">\n" + "        <property>\n" + "          <key>Image</key>\n" + "          <value>alpine:latest</value>\n" + "        </property>\n" + "      </profile>" + "      <profile id=\"profile4\" pluginId=\"com.thoughtworks.gocd.elastic-agent.azure\">\n" + "        <property>\n" + "          <key>Image</key>\n" + "          <value>alpine:latest</value>\n" + "        </property>\n" + "      </profile>" + "      <profile id=\"profile5\" pluginId=\"com.thoughtworks.gocd.elastic-agent.azure\">\n" + "        <property>\n" + "          <key>Image</key>\n" + "          <value>alpine:latest</value>\n" + "        </property>\n" + "      </profile>" + "    </profiles>" + "  </elastic>";
    String configXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<cruise schemaVersion=\"118\">\n" + configContent + "</cruise>";
    ClusterProfile azureProfile = new ClusterProfile("no-op-cluster-for-com.thoughtworks.gocd.elastic-agent.azure", "com.thoughtworks.gocd.elastic-agent.azure");
    ClusterProfile dockerProfile = new ClusterProfile("no-op-cluster-for-cd.go.contrib.elastic-agent.docker", "cd.go.contrib.elastic-agent.docker");
    ClusterProfile kubernetesProfile = new ClusterProfile("no-op-cluster-for-cd.go.contrib.elasticagent.kubernetes", "cd.go.contrib.elasticagent.kubernetes");
    CruiseConfig migratedConfig = migrateConfigAndLoadTheNewConfig(configXml);
    ClusterProfiles newlyDefinedClusters = migratedConfig.getElasticConfig().getClusterProfiles();
    ElasticProfiles migratedElasticAgentProfiles = migratedConfig.getElasticConfig().getProfiles();
    assertThat(newlyDefinedClusters).hasSize(3);
    assertThat(newlyDefinedClusters.find("no-op-cluster-for-com.thoughtworks.gocd.elastic-agent.azure")).isEqualTo(azureProfile);
    assertThat(newlyDefinedClusters.find("no-op-cluster-for-cd.go.contrib.elastic-agent.docker")).isEqualTo(dockerProfile);
    assertThat(newlyDefinedClusters.find("no-op-cluster-for-cd.go.contrib.elasticagent.kubernetes")).isEqualTo(kubernetesProfile);
    ElasticProfile profile1 = new ElasticProfile("profile1", "no-op-cluster-for-cd.go.contrib.elastic-agent.docker", new ConfigurationProperty(new ConfigurationKey("Image"), new ConfigurationValue("alpine:latest")));
    ElasticProfile profile2 = new ElasticProfile("profile2", "no-op-cluster-for-cd.go.contrib.elasticagent.kubernetes", new ConfigurationProperty(new ConfigurationKey("Image"), new ConfigurationValue("alpine:latest")));
    ElasticProfile profile3 = new ElasticProfile("profile3", "no-op-cluster-for-cd.go.contrib.elastic-agent.docker", new ConfigurationProperty(new ConfigurationKey("Image"), new ConfigurationValue("alpine:latest")));
    ElasticProfile profile4 = new ElasticProfile("profile4", "no-op-cluster-for-com.thoughtworks.gocd.elastic-agent.azure", new ConfigurationProperty(new ConfigurationKey("Image"), new ConfigurationValue("alpine:latest")));
    ElasticProfile profile5 = new ElasticProfile("profile5", "no-op-cluster-for-com.thoughtworks.gocd.elastic-agent.azure", new ConfigurationProperty(new ConfigurationKey("Image"), new ConfigurationValue("alpine:latest")));
    assertThat(migratedElasticAgentProfiles.find("profile1")).isEqualTo(profile1);
    assertThat(migratedElasticAgentProfiles.find("profile2")).isEqualTo(profile2);
    assertThat(migratedElasticAgentProfiles.find("profile3")).isEqualTo(profile3);
    assertThat(migratedElasticAgentProfiles.find("profile4")).isEqualTo(profile4);
    assertThat(migratedElasticAgentProfiles.find("profile5")).isEqualTo(profile5);
}
Also used : ElasticProfiles(com.thoughtworks.go.config.elastic.ElasticProfiles) ClusterProfiles(com.thoughtworks.go.config.elastic.ClusterProfiles) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 5 with ElasticProfiles

use of com.thoughtworks.go.config.elastic.ElasticProfiles in project gocd by gocd.

the class GoConfigMigrationIntegrationTest method shouldCreateProfilesFromMultipleAgentConfigsAcrossPipelines_asPartOfMigration86And87.

@Test
public void shouldCreateProfilesFromMultipleAgentConfigsAcrossPipelines_asPartOfMigration86And87() throws Exception {
    String configXml = "<cruise schemaVersion='85'>" + " <server serverId='dev-id'>" + " </server>" + " <pipelines group='first'>" + "   <pipeline name='up42'>" + "     <materials>" + "       <hg url='../manual-testing/ant_hg/dummy' />" + "     </materials>" + "  <stage name='build'>" + "    <jobs>" + "      <job name='test1'>" + "       <agentConfig pluginId='docker'>" + "         <property>" + "           <key>instance-type</key>" + "           <value>m1.small</value>" + "         </property>" + "       </agentConfig>" + "      </job>" + "    </jobs>" + "  </stage>" + "   </pipeline>" + "   <pipeline name='up43'>" + "     <materials>" + "       <hg url='../manual-testing/ant_hg/dummy' />" + "     </materials>" + "  <stage name='build'>" + "    <jobs>" + "      <job name='test2'>" + "       <agentConfig pluginId='aws'>" + "         <property>" + "           <key>ami</key>" + "           <value>some.ami</value>" + "         </property>" + "         <property>" + "           <key>ram</key>" + "           <value>1024</value>" + "         </property>" + "         <property>" + "           <key>diskSpace</key>" + "           <value>10G</value>" + "         </property>" + "       </agentConfig>" + "      </job>" + "    </jobs>" + "  </stage>" + "   </pipeline>" + "  </pipelines>" + "</cruise>";
    CruiseConfig migratedConfig = migrateConfigAndLoadTheNewConfig(configXml, 85);
    PipelineConfig up42 = migratedConfig.pipelineConfigByName(new CaseInsensitiveString("up42"));
    PipelineConfig up43 = migratedConfig.pipelineConfigByName(new CaseInsensitiveString("up43"));
    JobConfigs up42Jobs = up42.getStages().get(0).getJobs();
    JobConfigs up43Jobs = up43.getStages().get(0).getJobs();
    ElasticProfiles profiles = migratedConfig.getElasticConfig().getProfiles();
    assertThat(profiles.size(), is(2));
    ElasticProfile expectedDockerProfile = new ElasticProfile(up42Jobs.get(0).getElasticProfileId(), "docker", 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", 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));
}
Also used : ElasticProfiles(com.thoughtworks.go.config.elastic.ElasticProfiles) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

ElasticProfiles (com.thoughtworks.go.config.elastic.ElasticProfiles)13 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)12 Test (org.junit.jupiter.api.Test)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 Test (org.junit.Test)4 ElasticConfig (com.thoughtworks.go.config.elastic.ElasticConfig)2 ConfigSaveValidationContext (com.thoughtworks.go.config.ConfigSaveValidationContext)1 ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)1 ClusterProfiles (com.thoughtworks.go.config.elastic.ClusterProfiles)1 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)1 ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)1