Search in sources :

Example 1 with SecretResolutionFailureException

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);
    }
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) RulesViolationException(com.thoughtworks.go.server.exceptions.RulesViolationException) SecretResolutionFailureException(com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile)

Example 2 with SecretResolutionFailureException

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);
    }
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) HashMap(java.util.HashMap) ModelAndView(spark.ModelAndView) RulesViolationException(com.thoughtworks.go.server.exceptions.RulesViolationException) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) DataRetrievalFailureException(org.springframework.dao.DataRetrievalFailureException) SecretResolutionFailureException(com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException) RulesViolationException(com.thoughtworks.go.server.exceptions.RulesViolationException) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) SecretResolutionFailureException(com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException) DataRetrievalFailureException(org.springframework.dao.DataRetrievalFailureException)

Example 3 with SecretResolutionFailureException

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());
        }
    }
}
Also used : RulesViolationException(com.thoughtworks.go.server.exceptions.RulesViolationException) SecretResolutionFailureException(com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) RulesViolationException(com.thoughtworks.go.server.exceptions.RulesViolationException) SecretResolutionFailureException(com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException) Result(com.thoughtworks.go.plugin.api.response.Result) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) LocalizedOperationResult(com.thoughtworks.go.server.service.result.LocalizedOperationResult) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)

Example 4 with SecretResolutionFailureException

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();
    }
}
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 5 with SecretResolutionFailureException

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());
        }
    }
}
Also used : RulesViolationException(com.thoughtworks.go.server.exceptions.RulesViolationException) SecretResolutionFailureException(com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) RulesViolationException(com.thoughtworks.go.server.exceptions.RulesViolationException) SecretResolutionFailureException(com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException) Result(com.thoughtworks.go.plugin.api.response.Result) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) LocalizedOperationResult(com.thoughtworks.go.server.service.result.LocalizedOperationResult) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)

Aggregations

SecretResolutionFailureException (com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)6 RulesViolationException (com.thoughtworks.go.server.exceptions.RulesViolationException)5 Test (org.junit.jupiter.api.Test)5 EntityConfigUpdateCommand (com.thoughtworks.go.config.commands.EntityConfigUpdateCommand)2 ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)2 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)2 Configuration (com.thoughtworks.go.domain.config.Configuration)2 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)2 Result (com.thoughtworks.go.plugin.api.response.Result)2 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)2 Username (com.thoughtworks.go.server.domain.Username)2 PackageMaterialTestHelper.assertPackageConfiguration (com.thoughtworks.go.server.service.materials.PackageMaterialTestHelper.assertPackageConfiguration)2 LocalizedOperationResult (com.thoughtworks.go.server.service.result.LocalizedOperationResult)2 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)1 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)1 JobInstance (com.thoughtworks.go.domain.JobInstance)1 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)1