use of com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfile in project gocd-ecs-elastic-agent by gocd.
the class MigrateConfigurationRequestExecutor method execute.
@Override
public GoPluginApiResponse execute() throws Exception {
LOG.info("[Migrate Config] Request for Config Migration Started...");
PluginSettings pluginSettings = migrateConfigurationRequest.getPluginSettings();
List<ClusterProfile> existingClusterProfiles = migrateConfigurationRequest.getClusterProfiles();
List<ElasticAgentProfile> existingElasticAgentProfiles = migrateConfigurationRequest.getElasticAgentProfiles();
if (!arePluginSettingsConfigured(pluginSettings)) {
LOG.info("[Migrate Config] No Plugin Settings are configured. Skipping Config Migration...");
return new DefaultGoPluginApiResponse(200, migrateConfigurationRequest.toJSON());
}
if (existingClusterProfiles.size() == 0) {
LOG.info("[Migrate Config] Did not find any Cluster Profile. Possibly, user just have configured plugin settings and haven't define any elastic agent profiles.");
String newClusterId = UUID.randomUUID().toString();
LOG.info("[Migrate Config] Migrating existing plugin settings to new cluster profile '{}'", newClusterId);
ClusterProfile clusterProfile = new ClusterProfile(newClusterId, Constants.PLUGIN_ID, pluginSettings);
return getGoPluginApiResponse(pluginSettings, Collections.singletonList(clusterProfile), existingElasticAgentProfiles);
}
LOG.info("[Migrate Config] Checking to perform migrations on Cluster Profiles '{}'.", existingClusterProfiles.stream().map(ClusterProfile::getId).collect(Collectors.toList()));
for (ClusterProfile clusterProfile : existingClusterProfiles) {
List<ElasticAgentProfile> associatedElasticAgentProfiles = findAssociatedElasticAgentProfiles(clusterProfile, existingElasticAgentProfiles);
if (associatedElasticAgentProfiles.size() == 0) {
LOG.info("[Migrate Config] Skipping migration for the cluster '{}' as no Elastic Agent Profiles are associated with it.", clusterProfile.getId());
continue;
}
if (!arePluginSettingsConfigured(clusterProfile.getClusterProfileProperties())) {
List<String> associatedProfileIds = associatedElasticAgentProfiles.stream().map(ElasticAgentProfile::getId).collect(Collectors.toList());
LOG.info("[Migrate Config] Found an empty cluster profile '{}' associated with '{}' elastic agent profiles.", clusterProfile.getId(), associatedProfileIds);
migrateConfigForCluster(pluginSettings, associatedElasticAgentProfiles, clusterProfile);
} else {
LOG.info("[Migrate Config] Skipping migration for the cluster '{}' as cluster has already been configured.", clusterProfile.getId());
}
}
return new DefaultGoPluginApiResponse(200, migrateConfigurationRequest.toJSON());
}
Aggregations