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