Search in sources :

Example 1 with ElasticAgentInformation

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

the class ReplaceElasticAgentInformationCommand method update.

@Override
public CruiseConfig update(CruiseConfig preprocessedConfig) throws Exception {
    String pluginId = pluginDescriptor.id();
    List<ClusterProfile> clusterProfiles = clusterProfilesService.getPluginProfiles().findByPluginId(pluginId);
    List<ElasticProfile> elasticAgentProfiles = elasticProfileService.findElasticAgentProfilesByPluginId(pluginId);
    ElasticAgentInformation elasticAgentInformation = new ElasticAgentInformation(pluginSettings, clusterProfiles, elasticAgentProfiles);
    ElasticAgentInformation migratedElasticAgentInformation = elasticAgentExtension.migrateConfig(pluginId, elasticAgentInformation);
    List<ClusterProfile> migratedClusterProfiles = migratedElasticAgentInformation.getClusterProfiles();
    List<ElasticProfile> migratedElasticAgentProfiles = migratedElasticAgentInformation.getElasticAgentProfiles();
    preprocessedConfig.getElasticConfig().getClusterProfiles().removeAll(clusterProfiles);
    preprocessedConfig.getElasticConfig().getClusterProfiles().addAll(migratedClusterProfiles);
    preprocessedConfig.getElasticConfig().getProfiles().removeAll(elasticAgentProfiles);
    preprocessedConfig.getElasticConfig().getProfiles().addAll(migratedElasticAgentProfiles);
    return preprocessedConfig;
}
Also used : ElasticAgentInformation(com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile)

Example 2 with ElasticAgentInformation

use of com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation 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)

Example 3 with ElasticAgentInformation

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

the class ElasticAgentExtensionV5Test method shouldMigrateElasticAgentInformation.

@Test
public void shouldMigrateElasticAgentInformation() {
    String responseBody = "{" + "    \"plugin_settings\":{}," + "    \"cluster_profiles\":[]," + "    \"elastic_agent_profiles\":[]" + "}\n";
    when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ELASTIC_AGENT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody));
    ElasticAgentInformation elasticAgentInformation = new ElasticAgentInformation(Collections.emptyMap(), Collections.emptyList(), Collections.emptyList());
    extensionV5.migrateConfig(PLUGIN_ID, elasticAgentInformation);
    final String expectedRequestBody = responseBody;
    assertExtensionRequest("5.0", REQUEST_MIGRATE_CONFIGURATION, expectedRequestBody);
}
Also used : ElasticAgentInformation(com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation) Test(org.junit.jupiter.api.Test)

Example 4 with ElasticAgentInformation

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

the class ReplaceElasticAgentInformationCommandTest method shouldMakeCallToElasticAgentExtensionToMigrateElasticAgentRelatedConfig_WhenNoPluginSettingsAreConfigured.

@Test
void shouldMakeCallToElasticAgentExtensionToMigrateElasticAgentRelatedConfig_WhenNoPluginSettingsAreConfigured() throws Exception {
    replaceElasticAgentInformationCommand = new ReplaceElasticAgentInformationCommand(clusterProfilesService, elasticProfileService, elasticAgentExtension, pluginDescriptor, new HashMap<>());
    replaceElasticAgentInformationCommand.update(basicCruiseConfig);
    verify(elasticAgentExtension).migrateConfig(pluginId, new ElasticAgentInformation(Collections.emptyMap(), clusterProfiles, elasticProfiles));
}
Also used : HashMap(java.util.HashMap) ElasticAgentInformation(com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation) Test(org.junit.jupiter.api.Test)

Example 5 with ElasticAgentInformation

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

the class ElasticAgentExtensionV4Test method shouldMigrateElasticAgentInformation.

@Test
public void shouldMigrateElasticAgentInformation() {
    ElasticAgentInformation elasticAgentInformation = new ElasticAgentInformation(Collections.emptyMap(), Collections.emptyList(), Collections.emptyList());
    ElasticAgentInformation responseElasticAgentInformation = extensionV4.migrateConfig(PLUGIN_ID, elasticAgentInformation);
    assertThat(responseElasticAgentInformation, is(elasticAgentInformation));
    assertThat(requestArgumentCaptor.getAllValues(), is(Collections.emptyList()));
}
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