Search in sources :

Example 6 with ElasticAgentInformation

use of com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation in project gocd by gocd.

the class ElasticAgentExtensionConverterV5Test method shouldGetRequestBodyForMigrateCall_withNewConfig.

@Test
public void shouldGetRequestBodyForMigrateCall_withNewConfig() throws CryptoException {
    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<>();
    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 EncryptedConfigurationValue(new GoCipher().encrypt("some_value2")))));
    ElasticAgentInformation elasticAgentInformation = new ElasticAgentInformation(pluginSettings, clusterProfiles, elasticAgentProfiles);
    ElasticAgentInformationDTO elasticAgentInformationDTO = new ElasticAgentExtensionConverterV5().getElasticAgentInformationDTO(elasticAgentInformation);
    String requestBody = elasticAgentInformationDTO.toJSON().toString();
    String expectedRequestBody = "{" + "    \"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";
    assertThatJson(expectedRequestBody).isEqualTo(requestBody);
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) ElasticAgentInformation(com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 7 with ElasticAgentInformation

use of com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation in project gocd by gocd.

the class ElasticAgentExtensionConverterV5Test method shouldGetRequestBodyForMigrateCall_withOldConfig.

@Test
public void shouldGetRequestBodyForMigrateCall_withOldConfig() throws CryptoException {
    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("prod-cluster", "plugin_id"));
    List<ElasticProfile> elasticAgentProfiles = new ArrayList<>();
    elasticAgentProfiles.add(new ElasticProfile("profile_id", "prod-cluster", new ConfigurationProperty(new ConfigurationKey("some_key"), new ConfigurationValue("some_value")), new ConfigurationProperty(new ConfigurationKey("some_key2"), new EncryptedConfigurationValue(new GoCipher().encrypt("some_value2")))));
    ElasticAgentInformation elasticAgentInformation = new ElasticAgentInformation(pluginSettings, clusterProfiles, elasticAgentProfiles);
    ElasticAgentInformationDTO elasticAgentInformationDTO = new ElasticAgentExtensionConverterV5().getElasticAgentInformationDTO(elasticAgentInformation);
    String requestBody = elasticAgentInformationDTO.toJSON().toString();
    String expectedRequestBody = "{" + "    \"plugin_settings\":{" + "        \"key2\":\"password\", " + "        \"key\":\"value\"" + "    }," + "    \"cluster_profiles\":[" + "        {" + "            \"id\":\"prod-cluster\"," + "            \"plugin_id\":\"plugin_id\"," + "            \"properties\":{" + "            }" + "        }" + "    ]," + "    \"elastic_agent_profiles\":[" + "        {" + "            \"id\":\"profile_id\"," + "            \"plugin_id\":\"plugin_id\"," + "            \"cluster_profile_id\": \"prod-cluster\"," + "            \"properties\":{" + "                \"some_key\":\"some_value\", " + "                \"some_key2\":\"some_value2\"" + "            }" + "        }" + "    ]" + "}\n";
    assertThatJson(expectedRequestBody).isEqualTo(requestBody);
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) ElasticAgentInformation(com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 8 with ElasticAgentInformation

use of com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation in project gocd by gocd.

the class ReplaceElasticAgentInformationCommandTest method shouldUpdateGoCDConfigWithPluginReturnedMigratedConfig.

@Test
void shouldUpdateGoCDConfigWithPluginReturnedMigratedConfig() throws Exception {
    ElasticConfig elasticConfig = new ElasticConfig();
    assertThat(elasticConfig.getProfiles()).hasSize(0);
    assertThat(elasticConfig.getClusterProfiles()).hasSize(0);
    CruiseConfig basicCruiseConfig = replaceElasticAgentInformationCommand.update(this.basicCruiseConfig);
    verify(elasticAgentExtension).migrateConfig(pluginId, new ElasticAgentInformation(Collections.emptyMap(), clusterProfiles, elasticProfiles));
    assertThat(basicCruiseConfig.getElasticConfig().getProfiles()).hasSize(1);
    assertThat(basicCruiseConfig.getElasticConfig().getProfiles()).isEqualTo(elasticProfiles);
    assertThat(basicCruiseConfig.getElasticConfig().getClusterProfiles()).hasSize(1);
    assertThat(basicCruiseConfig.getElasticConfig().getClusterProfiles()).isEqualTo(clusterProfiles);
}
Also used : ElasticAgentInformation(com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) Test(org.junit.jupiter.api.Test)

Example 9 with ElasticAgentInformation

use of com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation in project gocd by gocd.

the class ReplaceElasticAgentInformationCommandTest method setUp.

@BeforeEach
void setUp() {
    basicCruiseConfig = new BasicCruiseConfig();
    pluginId = "plugin-id";
    pluginSettings = new HashMap<>();
    clusterProfiles = new ClusterProfiles();
    clusterProfiles.add(new ClusterProfile("prod-cluster", pluginId));
    elasticProfiles = new ElasticProfiles();
    elasticProfiles.add(new ElasticProfile("profile-id", "prod-cluster"));
    replaceElasticAgentInformationCommand = new ReplaceElasticAgentInformationCommand(clusterProfilesService, elasticProfileService, elasticAgentExtension, pluginDescriptor, pluginSettings);
    when(pluginDescriptor.id()).thenReturn(pluginId);
    when(clusterProfilesService.getPluginProfiles()).thenReturn(clusterProfiles);
    when(elasticProfileService.findElasticAgentProfilesByPluginId(pluginId)).thenReturn(elasticProfiles);
    when(elasticAgentExtension.migrateConfig(eq(pluginId), any())).thenReturn(new ElasticAgentInformation(Collections.emptyMap(), clusterProfiles, elasticProfiles));
    lenient().when(goConfigService.getElasticConfig()).thenReturn(new ElasticConfig());
}
Also used : ElasticAgentInformation(com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with ElasticAgentInformation

use of com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation in project gocd by gocd.

the class ReplaceElasticAgentInformationCommandTest method shouldMakeCallToElasticAgentExtensionToMigrateElasticAgentRelatedConfig.

@Test
void shouldMakeCallToElasticAgentExtensionToMigrateElasticAgentRelatedConfig() throws Exception {
    replaceElasticAgentInformationCommand.update(basicCruiseConfig);
    verify(elasticAgentExtension).migrateConfig(pluginId, new ElasticAgentInformation(Collections.emptyMap(), clusterProfiles, elasticProfiles));
}
Also used : ElasticAgentInformation(com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation) Test(org.junit.jupiter.api.Test)

Aggregations

ElasticAgentInformation (com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation)10 Test (org.junit.jupiter.api.Test)8 ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)4 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)4 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)3 GoCipher (com.thoughtworks.go.security.GoCipher)3 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)2 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)1 ElasticAgentMetadataStore (com.thoughtworks.go.plugin.access.elastic.ElasticAgentMetadataStore)1 AgentMetadata (com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata)1 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)1 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)1 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)1 HashMap (java.util.HashMap)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1