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