Search in sources :

Example 41 with ClusterProfile

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

the class ClusterProfilesChangedPluginNotifier method onEntityConfigChange.

@Override
public void onEntityConfigChange(ClusterProfile updatedClusterProfile) {
    try {
        LOGGER.debug("Resolving secrets for updated cluster profile: {}", updatedClusterProfile);
        secretParamResolver.resolve(updatedClusterProfile);
    } catch (RulesViolationException | SecretResolutionFailureException e) {
        logAndRaiseServerHealthMessage(updatedClusterProfile, e.getMessage());
        return;
    }
    Map<String, String> updatedClusterConfigMap = updatedClusterProfile.getConfigurationAsMap(true, true);
    if (goConfigService.getElasticConfig().getClusterProfiles().find(updatedClusterProfile.getId()) == null) {
        registry.notifyPluginAboutClusterProfileChanged(updatedClusterProfile.getPluginId(), ClusterProfilesChangedStatus.DELETED, updatedClusterConfigMap, null);
        updateClusterProfilesCopy();
        return;
    }
    ClusterProfile oldClusterProfile = existingClusterProfiles.find(updatedClusterProfile.getId());
    if (oldClusterProfile == null) {
        registry.notifyPluginAboutClusterProfileChanged(updatedClusterProfile.getPluginId(), ClusterProfilesChangedStatus.CREATED, null, updatedClusterConfigMap);
        updateClusterProfilesCopy();
        return;
    }
    try {
        LOGGER.debug("Resolving secrets for older cluster profile: {}", oldClusterProfile);
        secretParamResolver.resolve(oldClusterProfile);
    } catch (RulesViolationException | SecretResolutionFailureException e) {
        logAndRaiseServerHealthMessage(oldClusterProfile, e.getMessage());
        return;
    }
    // cluster profile has been updated without changing plugin id
    Map<String, String> olderClusterConfigMap = oldClusterProfile.getConfigurationAsMap(true, true);
    if (oldClusterProfile.getPluginId().equals(updatedClusterProfile.getPluginId())) {
        registry.notifyPluginAboutClusterProfileChanged(updatedClusterProfile.getPluginId(), ClusterProfilesChangedStatus.UPDATED, olderClusterConfigMap, updatedClusterConfigMap);
        updateClusterProfilesCopy();
    } else {
        // cluster profile has been updated including changing plugin id.
        // this internally results in deletion of a profile belonging to old plugin id and creation of the profile belonging to new plugin id
        registry.notifyPluginAboutClusterProfileChanged(updatedClusterProfile.getPluginId(), ClusterProfilesChangedStatus.CREATED, null, updatedClusterConfigMap);
        registry.notifyPluginAboutClusterProfileChanged(oldClusterProfile.getPluginId(), ClusterProfilesChangedStatus.DELETED, olderClusterConfigMap, null);
        updateClusterProfilesCopy();
    }
}
Also used : RulesViolationException(com.thoughtworks.go.server.exceptions.RulesViolationException) SecretResolutionFailureException(com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile)

Example 42 with ClusterProfile

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

the class ElasticAgentPluginService method heartbeat.

public void heartbeat() {
    LinkedMultiValueMap<String, ElasticAgentMetadata> elasticAgentsOfMissingPlugins = agentService.allElasticAgents();
    // pingMessage TTL is set lesser than elasticPluginHeartBeatInterval to ensure there aren't multiple ping request for the same plugin
    long pingMessageTimeToLive = elasticPluginHeartBeatInterval - 10000L;
    for (PluginDescriptor descriptor : elasticAgentPluginRegistry.getPlugins()) {
        elasticAgentsOfMissingPlugins.remove(descriptor.id());
        List<ClusterProfile> clusterProfiles = clusterProfilesService.getPluginProfiles().findByPluginId(descriptor.id());
        boolean secretsResolved = resolveSecrets(descriptor.id(), clusterProfiles);
        if (!secretsResolved)
            continue;
        serverPingQueue.post(new ServerPingMessage(descriptor.id(), clusterProfiles), pingMessageTimeToLive);
        serverHealthService.removeByScope(scope(descriptor.id()));
    }
    if (!elasticAgentsOfMissingPlugins.isEmpty()) {
        for (String pluginId : elasticAgentsOfMissingPlugins.keySet()) {
            Collection<String> uuids = elasticAgentsOfMissingPlugins.get(pluginId).stream().map(ElasticAgentMetadata::uuid).collect(toList());
            String description = format("Elastic agent plugin with identifier %s has gone missing, but left behind %s agent(s) with UUIDs %s.", pluginId, elasticAgentsOfMissingPlugins.get(pluginId).size(), uuids);
            serverHealthService.update(ServerHealthState.warning("Elastic agents with no matching plugins", description, general(scope(pluginId))));
            LOGGER.warn(description);
        }
    }
}
Also used : GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) PluginDescriptor(com.thoughtworks.go.plugin.api.info.PluginDescriptor) ServerPingMessage(com.thoughtworks.go.server.messaging.elasticagents.ServerPingMessage) ElasticAgentMetadata(com.thoughtworks.go.server.domain.ElasticAgentMetadata) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile)

Example 43 with ClusterProfile

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

the class DeleteClusterProfileCommandTest method setUp.

@BeforeEach
void setUp() {
    config = new BasicCruiseConfig();
    clusterProfile = new ClusterProfile("cluster-id", "plugin-id");
    config.getElasticConfig().getClusterProfiles().add(clusterProfile);
    username = new Username("Bob");
    result = new HttpLocalizedOperationResult();
    command = new DeleteClusterProfileCommand(extension, goConfigService, clusterProfile, username, result);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 44 with ClusterProfile

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

the class ElasticProfileServiceTest method setUp.

@BeforeEach
void setUp() throws Exception {
    pluginId = "cd.go.elastic.ecs";
    clusterProfileId = "prod-cluster";
    elasticAgentExtension = mock(ElasticAgentExtension.class);
    EntityHashingService hashingService = mock(EntityHashingService.class);
    goConfigService = mock(GoConfigService.class);
    secretParamResolver = mock(SecretParamResolver.class);
    elasticProfileService = new ElasticProfileService(goConfigService, hashingService, elasticAgentExtension, secretParamResolver);
    validator = mock(ElasticAgentProfileConfigurationValidator.class);
    elasticProfileService.setProfileConfigurationValidator(validator);
    ElasticConfig elasticConfig = new ElasticConfig();
    elasticConfig.getClusterProfiles().add(new ClusterProfile(clusterProfileId, pluginId));
    when(goConfigService.getElasticConfig()).thenReturn(elasticConfig);
    BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
    cruiseConfig.setElasticConfig(elasticConfig);
    when(goConfigService.getConfigForEditing()).thenReturn(cruiseConfig);
}
Also used : ElasticAgentProfileConfigurationValidator(com.thoughtworks.go.server.service.plugins.validators.elastic.ElasticAgentProfileConfigurationValidator) ElasticConfig(com.thoughtworks.go.config.elastic.ElasticConfig) ElasticAgentExtension(com.thoughtworks.go.plugin.access.elastic.ElasticAgentExtension) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 45 with ClusterProfile

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

the class ClusterProfilesServiceTest method setUp.

@BeforeEach
void setUp() {
    clusterProfile = new ClusterProfile("prod_cluster", "k8s.ea.plugin");
    clusterProfilesService = new ClusterProfilesService(goConfigService, hashingService, extension, secretParamResolver);
}
Also used : ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) BeforeEach(org.junit.jupiter.api.BeforeEach)

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