Search in sources :

Example 21 with ClusterProfile

use of com.thoughtworks.go.config.elastic.ClusterProfile 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 22 with ClusterProfile

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

the class JobAgentMetadataSqlMapDaoIntegrationTest method shouldSaveElasticAgentPropertyOnJob.

@Test
public void shouldSaveElasticAgentPropertyOnJob() throws Exception {
    ElasticProfile profile = new ElasticProfile("elastic", "clusterProfileId");
    ClusterProfile clusterProfile = new ClusterProfile("clusterProfileId", "plugin");
    JobAgentMetadata jobAgentMetadata = new JobAgentMetadata(jobId, profile, clusterProfile);
    dao.save(jobAgentMetadata);
    JobAgentMetadata metadataFromDb = dao.load(jobId);
    assertThat(metadataFromDb.elasticProfile(), is(profile));
    assertThat(metadataFromDb.clusterProfile(), is(clusterProfile));
    assertThat(metadataFromDb, is(jobAgentMetadata));
}
Also used : JobAgentMetadata(com.thoughtworks.go.domain.JobAgentMetadata) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 23 with ClusterProfile

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

the class JobInstanceSqlMapDaoIntegrationTest method shouldSaveJobAgentMetadata_WhenClusterProfileIsAssociatedWithElasticAgentProfile.

@Test
public void shouldSaveJobAgentMetadata_WhenClusterProfileIsAssociatedWithElasticAgentProfile() {
    JobInstance instance = jobInstanceDao.save(stageId, new JobInstance(JOB_NAME));
    instance.setIdentifier(new JobIdentifier(savedPipeline, savedStage, instance));
    ElasticProfile elasticProfile = new ElasticProfile("foo", "clusterId", Arrays.asList(new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value"))));
    ClusterProfile clusterProfile = new ClusterProfile("clusterId", "cd.go.elastic-agent:docker", Arrays.asList(new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value"))));
    JobPlan plan = new DefaultJobPlan(new Resources("something"), new ArrayList<>(), instance.getId(), instance.getIdentifier(), null, new EnvironmentVariables(), new EnvironmentVariables(), elasticProfile, clusterProfile);
    jobInstanceDao.save(instance.getId(), plan);
    JobPlan retrieved = jobInstanceDao.loadPlan(plan.getJobId());
    assertThat(retrieved.getElasticProfile(), is(elasticProfile));
    assertThat(retrieved.getClusterProfile(), is(clusterProfile));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 24 with ClusterProfile

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

the class JobControllerIntegrationTest method jobDetailModel_shouldHaveTheElasticProfilePluginIdWhenAgentIsNotAssigned.

@Test
public void jobDetailModel_shouldHaveTheElasticProfilePluginIdWhenAgentIsNotAssigned() throws Exception {
    Pipeline pipeline = fixture.createPipelineWithFirstStageAssigned();
    Stage stage = pipeline.getFirstStage();
    JobInstance job = stage.getFirstJob();
    GoPluginDescriptor.About about = GoPluginDescriptor.About.builder().name("name").version("0.1").targetGoVersion("17.3.0").description("desc").build();
    GoPluginDescriptor descriptor = GoPluginDescriptor.builder().id("plugin_id").about(about).build();
    ElasticAgentMetadataStore.instance().setPluginInfo(new ElasticAgentPluginInfo(descriptor, null, null, null, null, new Capabilities(false, true)));
    ElasticProfile profile = new ElasticProfile("profile_id", "cluster_profile_id", Collections.EMPTY_LIST);
    ClusterProfile clusterProfile = new ClusterProfile("cluster_profile_id", "plugin_id", Collections.EMPTY_LIST);
    fixture.addJobAgentMetadata(new JobAgentMetadata(job.getId(), profile, clusterProfile));
    ModelAndView modelAndView = controller.jobDetail(pipeline.getName(), String.valueOf(pipeline.getCounter()), stage.getName(), String.valueOf(stage.getCounter()), job.getName());
    assertThat(modelAndView.getModel().get("elasticAgentPluginId"), is("plugin_id"));
}
Also used : ElasticAgentPluginInfo(com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo) JobAgentMetadata(com.thoughtworks.go.domain.JobAgentMetadata) JobInstance(com.thoughtworks.go.domain.JobInstance) Capabilities(com.thoughtworks.go.plugin.domain.elastic.Capabilities) ModelAndView(org.springframework.web.servlet.ModelAndView) Stage(com.thoughtworks.go.domain.Stage) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.jupiter.api.Test)

Example 25 with ClusterProfile

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

the class ElasticAgentExtensionConverterV5Test method shouldGetTheElasticAgentInformationFromResponseBodyOfMigrateCall.

@Test
public void shouldGetTheElasticAgentInformationFromResponseBodyOfMigrateCall() throws CryptoException {
    String responseBody = "{" + "    \"plugin_settings\":{" + "        \"key2\":\"password\", " + "        \"key\":\"value\"" + "    }," + "    \"cluster_profiles\":[" + "        {" + "            \"id\":\"cluster_profile_id\"," + "            \"plugin_id\":\"plugin_id\"," + "            \"properties\":{" + "                \"some_key\":\"some_value\", " + "                \"some_key2\":\"some_value2\"" + "            }" + "         }" + "    ]," + "    \"elastic_agent_profiles\":[" + "        {" + "            \"id\":\"profile_id\"," + "            \"plugin_id\":\"plugin_id\"," + "            \"cluster_profile_id\":\"cluster_profile_id\"," + "            \"properties\":{" + "                \"some_key\":\"some_value\"," + "                \"some_key2\":\"some_value2\"" + "            }" + "        }" + "    ]" + "}\n";
    ElasticAgentMetadataStore store = ElasticAgentMetadataStore.instance();
    PluggableInstanceSettings elasticAgentProfileSettings = new PluggableInstanceSettings(Arrays.asList(new PluginConfiguration("some_key", new Metadata(true, true))));
    PluggableInstanceSettings clusterProfileSettings = new PluggableInstanceSettings(Arrays.asList(new PluginConfiguration("some_key2", new Metadata(true, true))));
    store.setPluginInfo(new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), elasticAgentProfileSettings, clusterProfileSettings, null, null, null));
    ElasticAgentInformation elasticAgentInformation = new ElasticAgentExtensionConverterV5().getElasticAgentInformationFromResponseBody(responseBody);
    ConfigurationProperty property1 = new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value"));
    ConfigurationProperty property2 = new ConfigurationProperty(new ConfigurationKey("key2"), new EncryptedConfigurationValue(new GoCipher().encrypt("password")));
    Configuration configuration = new Configuration();
    configuration.add(property1);
    configuration.add(property2);
    Map<String, String> pluginSettings = configuration.getConfigurationAsMap(true);
    List<ClusterProfile> clusterProfiles = new ArrayList<>();
    clusterProfiles.add(new ClusterProfile("cluster_profile_id", "plugin_id", new ConfigurationProperty(new ConfigurationKey("some_key"), new ConfigurationValue("some_value")), new ConfigurationProperty(new ConfigurationKey("some_key2"), new EncryptedConfigurationValue(new GoCipher().encrypt("some_value2")))));
    List<ElasticProfile> elasticAgentProfiles = new ArrayList<>();
    // do not worry about encryption, it is handled during config save (migrate-config) call
    elasticAgentProfiles.add(new ElasticProfile("profile_id", "cluster_profile_id", new ConfigurationProperty(new ConfigurationKey("some_key"), new ConfigurationValue("some_value")), new ConfigurationProperty(new ConfigurationKey("some_key2"), new ConfigurationValue("some_value2"))));
    ElasticAgentInformation expectedElasticAgentInformation = new ElasticAgentInformation(pluginSettings, clusterProfiles, elasticAgentProfiles);
    assertThat(elasticAgentInformation, is(expectedElasticAgentInformation));
}
Also used : ElasticAgentPluginInfo(com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo) GoCipher(com.thoughtworks.go.security.GoCipher) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) ElasticAgentMetadataStore(com.thoughtworks.go.plugin.access.elastic.ElasticAgentMetadataStore) ElasticAgentInformation(com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Aggregations

ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)69 Test (org.junit.jupiter.api.Test)39 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)32 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)14 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)12 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)10 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)10 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)10 ClusterProfiles (com.thoughtworks.go.config.elastic.ClusterProfiles)8 Username (com.thoughtworks.go.server.domain.Username)8 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 ElasticConfig (com.thoughtworks.go.config.elastic.ElasticConfig)6 Capabilities (com.thoughtworks.go.plugin.domain.elastic.Capabilities)6 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)5 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)5 JobAgentMetadata (com.thoughtworks.go.domain.JobAgentMetadata)4 ElasticAgentInformation (com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation)4 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)4 GoCipher (com.thoughtworks.go.security.GoCipher)4