Search in sources :

Example 1 with ClusterProfile

use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.

the class ClusterProfileDTO method toDomainModel.

public ClusterProfile toDomainModel() {
    ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>();
    this.properties.forEach((key, value) -> {
        configurationProperties.add(new ConfigurationProperty(new ConfigurationKey(key), new ConfigurationValue(value)));
    });
    ClusterProfile clusterProfile = new ClusterProfile(this.id, this.pluginId);
    clusterProfile.addConfigurations(configurationProperties);
    return clusterProfile;
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) ArrayList(java.util.ArrayList) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile)

Example 2 with ClusterProfile

use of com.thoughtworks.go.config.elastic.ClusterProfile 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 3 with ClusterProfile

use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.

the class UpdateClusterProfileCommand method update.

@Override
public void update(CruiseConfig preprocessedConfig) throws Exception {
    ClusterProfile existingClusterProfile = findExistingProfile(preprocessedConfig);
    ClusterProfiles clusterProfiles = getPluginProfiles(preprocessedConfig);
    clusterProfiles.set(clusterProfiles.indexOf(existingClusterProfile), profile);
}
Also used : ClusterProfiles(com.thoughtworks.go.config.elastic.ClusterProfiles) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile)

Example 4 with ClusterProfile

use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.

the class InstanceFactoryTest method shouldAddElasticProfileAndClusterProfileOnJobPlan.

@Test
void shouldAddElasticProfileAndClusterProfileOnJobPlan() {
    ElasticProfile elasticProfile = new ElasticProfile("id", "clusterId");
    ClusterProfile clusterProfile = new ClusterProfile("clusterId", "pluginId");
    DefaultSchedulingContext context = new DefaultSchedulingContext("foo", new Agents(), ImmutableMap.of("id", elasticProfile), ImmutableMap.of("clusterId", clusterProfile));
    ArtifactTypeConfigs artifactTypeConfigs = new ArtifactTypeConfigs();
    JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("test"), null, artifactTypeConfigs);
    jobConfig.setElasticProfileId("id");
    JobPlan plan = instanceFactory.createJobPlan(jobConfig, context);
    assertThat(plan.getElasticProfile(), is(elasticProfile));
    assertThat(plan.getClusterProfile(), is(clusterProfile));
}
Also used : ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 5 with ClusterProfile

use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.

the class ClusterProfilesChangedPluginNotifierTest method shouldSendResolveConfigValuesForBothClusterProfile.

@Test
void shouldSendResolveConfigValuesForBothClusterProfile() {
    ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", "{{SECRET:[id][key1]}}");
    ConfigurationProperty k2 = ConfigurationPropertyMother.create("k2", "{{SECRET:[id][key2]}}");
    String newPluginId = "updated-plugin-id";
    newClusterProfile = new ClusterProfile("profile1", newPluginId, properties);
    oldClusterProfile.add(k1);
    newClusterProfile.add(k2);
    reset(goConfigService);
    ElasticConfig elasticConfig = new ElasticConfig();
    elasticConfig.getClusterProfiles().add(oldClusterProfile);
    when(goConfigService.getElasticConfig()).thenReturn(elasticConfig);
    doAnswer(invocation -> {
        k2.getSecretParams().get(0).setValue("new-resolved-value");
        return null;
    }).when(secretParamResolver).resolve(newClusterProfile);
    doAnswer(invocation -> {
        k1.getSecretParams().get(0).setValue("old-resolved-value");
        return null;
    }).when(secretParamResolver).resolve(oldClusterProfile);
    notifier = new ClusterProfilesChangedPluginNotifier(goConfigService, registry, secretParamResolver, serverHealthService);
    notifier.onEntityConfigChange(newClusterProfile);
    verify(secretParamResolver).resolve(newClusterProfile);
    verify(secretParamResolver).resolve(oldClusterProfile);
    verify(registry).notifyPluginAboutClusterProfileChanged(this.pluginId, ClusterProfilesChangedStatus.DELETED, oldClusterProfile.getConfigurationAsMap(true, true), null);
    verify(registry).notifyPluginAboutClusterProfileChanged(newPluginId, ClusterProfilesChangedStatus.CREATED, null, newClusterProfile.getConfigurationAsMap(true, true));
    verifyNoMoreInteractions(registry);
    verify(goConfigService, times(3)).getElasticConfig();
    verifyNoInteractions(serverHealthService);
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ElasticConfig(com.thoughtworks.go.config.elastic.ElasticConfig) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Aggregations

ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)69 Test (org.junit.jupiter.api.Test)39 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)32 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)14 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)12 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)10 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)10 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)10 ClusterProfiles (com.thoughtworks.go.config.elastic.ClusterProfiles)8 Username (com.thoughtworks.go.server.domain.Username)8 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 ElasticConfig (com.thoughtworks.go.config.elastic.ElasticConfig)6 Capabilities (com.thoughtworks.go.plugin.domain.elastic.Capabilities)6 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)5 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)5 JobAgentMetadata (com.thoughtworks.go.domain.JobAgentMetadata)4 ElasticAgentInformation (com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation)4 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)4 GoCipher (com.thoughtworks.go.security.GoCipher)4