use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.
the class InstanceFactory method createJobPlan.
public JobPlan createJobPlan(JobConfig config, SchedulingContext context) {
JobIdentifier identifier = new JobIdentifier();
String elasticProfileId = config.getElasticProfileId();
String clusterProfileId = null;
ElasticProfile elasticProfile = null;
ClusterProfile clusterProfile = null;
if (elasticProfileId != null) {
elasticProfile = context.getElasticProfile(elasticProfileId);
clusterProfileId = elasticProfile.getClusterProfileId();
}
if (clusterProfileId != null) {
clusterProfile = context.getClusterProfile(clusterProfileId);
}
final EnvironmentVariables variables = EnvironmentVariables.toEnvironmentVariables(context.overrideEnvironmentVariables(config.getVariables()).getEnvironmentVariablesConfig());
return new DefaultJobPlan(new Resources(config.resourceConfigs()), ArtifactPlan.toArtifactPlans(config.artifactTypeConfigs()), -1, identifier, null, variables, new EnvironmentVariables(), elasticProfile, clusterProfile);
}
use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.
the class ConfigurationPropertyDTO method toDomainModel.
public ClusterProfile toDomainModel() {
ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>();
ConfigurationPropertyBuilder builder = new ConfigurationPropertyBuilder();
this.properties.forEach((key, valueObject) -> {
boolean isSecure = (boolean) valueObject.get("isSecure");
String value = isSecure ? null : (String) valueObject.get("value");
String encryptedValue = isSecure ? (String) valueObject.get("value") : null;
configurationProperties.add(builder.create(key, value, encryptedValue, isSecure));
});
return new ClusterProfile(this.id, this.pluginId, configurationProperties);
}
use of com.thoughtworks.go.config.elastic.ClusterProfile 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);
}
use of com.thoughtworks.go.config.elastic.ClusterProfile 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);
}
use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.
the class JobAgentMetadata method clusterProfile.
public ClusterProfile clusterProfile() {
Map map = GSON.fromJson(clusterProfileMetadata, LinkedHashMap.class);
if (map == null || map.isEmpty()) {
return null;
}
String pluginId = (String) map.get("pluginId");
String id = (String) map.get("id");
Map<String, String> properties = (Map<String, String>) map.get("properties");
Collection<ConfigurationProperty> configProperties = properties.entrySet().stream().map(entry -> new ConfigurationProperty(new ConfigurationKey(entry.getKey()), new ConfigurationValue(entry.getValue()))).collect(Collectors.toList());
return new ClusterProfile(id, pluginId, configProperties);
}
Aggregations