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);
}
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));
}
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));
}
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"));
}
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));
}
Aggregations