use of com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException in project gocd by gocd.
the class ElasticAgentPluginService method jobCompleted.
public void jobCompleted(JobInstance job) {
AgentInstance agentInstance = agentService.findAgent(job.getAgentUuid());
if (!agentInstance.isElastic()) {
LOGGER.debug("Agent {} is not elastic. Skipping further execution.", agentInstance.getUuid());
return;
}
if (job.isAssignedToAgent()) {
jobCreationTimeMap.remove(job.getId());
}
String pluginId = agentInstance.elasticAgentMetadata().elasticPluginId();
String elasticAgentId = agentInstance.elasticAgentMetadata().elasticAgentId();
JobIdentifier jobIdentifier = job.getIdentifier();
ElasticProfile elasticProfile = job.getPlan().getElasticProfile();
ClusterProfile clusterProfile = job.getPlan().getClusterProfile();
try {
secretParamResolver.resolve(elasticProfile);
Map<String, String> elasticProfileConfiguration = elasticProfile.getConfigurationAsMap(true, true);
Map<String, String> clusterProfileConfiguration = emptyMap();
if (clusterProfile != null) {
secretParamResolver.resolve(clusterProfile);
clusterProfileConfiguration = clusterProfile.getConfigurationAsMap(true, true);
}
elasticAgentPluginRegistry.reportJobCompletion(pluginId, elasticAgentId, jobIdentifier, elasticProfileConfiguration, clusterProfileConfiguration);
} catch (RulesViolationException | SecretResolutionFailureException e) {
String description = format("The job completion call to the plugin for the job identifier [%s] failed for secrets resolution: %s ", jobIdentifier.toString(), e.getMessage());
ServerHealthState healthState = error("Failed to notify plugin", description, general(scopeForJob(jobIdentifier)));
healthState.setTimeout(Timeout.FIVE_MINUTES);
serverHealthService.update(healthState);
LOGGER.error(description);
}
}
use of com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException in project gocd by gocd.
the class StatusReportsController method agentStatusReport.
public ModelAndView agentStatusReport(Request request, Response response) throws Exception {
String pluginId = request.params("plugin_id");
String elasticAgentId = parseElasticAgentId(request);
String jobIdString = request.queryParams("job_id");
long jobId;
try {
jobId = Long.parseLong(jobIdString);
} catch (NumberFormatException e) {
return errorPage(response, HttpStatus.UNPROCESSABLE_ENTITY.value(), "Agent Status Report", "Please provide a valid job_id for Agent Status Report.");
}
try {
JobInstance jobInstance = jobInstanceService.buildById(jobId);
String agentStatusReport = elasticAgentPluginService.getAgentStatusReport(pluginId, jobInstance.getIdentifier(), elasticAgentId);
Map<Object, Object> object = new HashMap<>();
object.put("viewTitle", "Agent Status Report");
object.put("viewFromPlugin", agentStatusReport);
return new ModelAndView(object, "status_reports/index.ftlh");
} catch (RecordNotFoundException e) {
return errorPage(response, 404, "Agent Status Report", e.getMessage());
} catch (DataRetrievalFailureException | UnsupportedOperationException e) {
String message = String.format("Status Report for plugin with id: '%s' for agent '%s' is not found.", pluginId, elasticAgentId);
return errorPage(response, 404, "Agent Status Report", message);
} catch (RulesViolationException | SecretResolutionFailureException e) {
LOGGER.error(e.getMessage(), e);
return errorPage(response, 500, "Agent Status Report", e.getMessage());
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
return errorPage(response, 500, "Agent Status Report", UNKNOWN_ERROR_MESSAGE);
}
}
use of com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException in project gocd by gocd.
the class PackageDefinitionService method checkConnection.
public void checkConnection(final PackageDefinition packageDefinition, final LocalizedOperationResult result) {
try {
String pluginId = packageDefinition.getRepository().getPluginConfiguration().getId();
secretParamResolver.resolve(packageDefinition);
Result checkConnectionResult = packageRepositoryExtension.checkConnectionToPackage(pluginId, buildPackageConfigurations(packageDefinition), buildRepositoryConfigurations(packageDefinition.getRepository()));
String messages = checkConnectionResult.getMessagesForDisplay();
if (!checkConnectionResult.isSuccessful()) {
result.connectionError("Package check Failed. Reason(s): " + messages);
return;
}
result.setMessage("OK. " + messages);
} catch (Exception e) {
if (e instanceof RulesViolationException || e instanceof SecretResolutionFailureException) {
result.unprocessableEntity("Package check Failed. Reason(s): " + e.getMessage());
} else {
result.internalServerError("Package check Failed. Reason(s): " + e.getMessage());
}
}
}
use of com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException 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.plugin.access.exceptions.SecretResolutionFailureException in project gocd by gocd.
the class PackageRepositoryService method checkConnection.
public void checkConnection(final PackageRepository packageRepository, final LocalizedOperationResult result) {
try {
secretParamResolver.resolve(packageRepository);
Result checkConnectionResult = packageRepositoryExtension.checkConnectionToRepository(packageRepository.getPluginConfiguration().getId(), populateConfiguration(packageRepository.getConfiguration()));
String messages = checkConnectionResult.getMessagesForDisplay();
if (!checkConnectionResult.isSuccessful()) {
result.connectionError("Could not connect to package repository. Reason(s): " + messages);
return;
}
result.setMessage("Connection OK. " + messages);
return;
} catch (Exception e) {
if (e instanceof RulesViolationException || e instanceof SecretResolutionFailureException) {
result.unprocessableEntity("Could not connect to package repository. Reason(s): " + e.getMessage());
} else {
result.internalServerError("Could not connect to package repository. Reason(s): " + e.getMessage());
}
}
}
Aggregations