Search in sources :

Example 16 with CoreException

use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.

the class DefaultBuildCoordinator method cancelSet.

@Override
public boolean cancelSet(int buildSetTaskId) {
    BuildConfigSetRecord record = datastoreAdapter.getBuildCongigSetRecordById(buildSetTaskId);
    if (record == null) {
        log.error("Could not find buildConfigSetRecord with id : {}", buildSetTaskId);
        return false;
    }
    log.debug("Cancelling Build Configuration Set: {}", buildSetTaskId);
    getSubmittedBuildTasks().stream().filter(Objects::nonNull).filter(t -> t.getBuildSetTask() != null && t.getBuildSetTask().getId().equals(buildSetTaskId)).forEach(buildTask -> {
        try {
            MDCUtils.addBuildContext(getMDCMeta(buildTask));
            log.debug("Received cancel request for buildTaskId: {}.", buildTask.getId());
            cancel(buildTask.getId());
        } catch (CoreException e) {
            log.error("Unable to cancel the build [" + buildTask.getId() + "].", e);
        } finally {
            MDCUtils.removeBuildContext();
        }
    });
    record.setStatus(BuildStatus.CANCELLED);
    record.setEndTime(Date.from(Instant.now()));
    try {
        datastoreAdapter.saveBuildConfigSetRecord(record);
    } catch (DatastoreException e) {
        log.error("Failed to update BuildConfigSetRecord (id: {} ) with status CANCELLED", record.getId(), e);
    }
    return true;
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) ScheduledFuture(java.util.concurrent.ScheduledFuture) BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) GroupBuildMapper(org.jboss.pnc.mapper.api.GroupBuildMapper) MDCUtils(org.jboss.pnc.common.logging.MDCUtils) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) Map(java.util.Map) CollectionUtils.hasCycle(org.jboss.pnc.common.util.CollectionUtils.hasCycle) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) User(org.jboss.pnc.model.User) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) BuildCoordinationException(org.jboss.pnc.coordinator.BuildCoordinationException) EnumMap(java.util.EnumMap) ExpiresDate(org.jboss.pnc.common.Date.ExpiresDate) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildResult(org.jboss.pnc.spi.BuildResult) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) Instant(java.time.Instant) BuildStatus(org.jboss.pnc.enums.BuildStatus) Objects(java.util.Objects) List(java.util.List) CoreException(org.jboss.pnc.spi.exception.CoreException) MDCExecutors(org.jboss.pnc.common.concurrent.MDCExecutors) PostConstruct(javax.annotation.PostConstruct) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) NamedThreadFactory(org.jboss.pnc.common.concurrent.NamedThreadFactory) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) DefaultBuildSetStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildSetStatusChangedEvent) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) AlignmentPreference(org.jboss.pnc.api.enums.AlignmentPreference) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) RepourResult(org.jboss.pnc.spi.repour.RepourResult) Quicksort(org.jboss.pnc.common.util.Quicksort) ExecutorService(java.util.concurrent.ExecutorService) Event(javax.enterprise.event.Event) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) Logger(org.slf4j.Logger) BuildTaskContext(org.jboss.pnc.common.logging.BuildTaskContext) BuildRecord(org.jboss.pnc.model.BuildRecord) ProcessStageUtils(org.jboss.pnc.common.util.ProcessStageUtils) PollingMonitor(org.jboss.pnc.common.monitor.PollingMonitor) TimeUnit(java.util.concurrent.TimeUnit) Build(org.jboss.pnc.dto.Build) Sequence(org.jboss.pnc.common.concurrent.Sequence) CoreException(org.jboss.pnc.spi.exception.CoreException) Objects(java.util.Objects) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord)

Example 17 with CoreException

use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.

the class RepositoryCreationTask method getProcessParameters.

@Override
protected Serializable getProcessParameters() throws CoreException {
    try {
        HashMap<String, Object> params = new HashMap<>();
        params.put("pncBaseUrl", globalConfig.getPncUrl());
        params.put("repourBaseUrl", globalConfig.getExternalRepourUrl());
        params.put("jobType", jobType.toString());
        if (isJsonEncodedProcessParameters()) {
            params.put("taskData", MAPPER.writeValueAsString(repositoryCreationProcessRest));
        } else {
            params.put("taskData", repositoryCreationProcessRest);
        }
        return params;
    } catch (JsonProcessingException e) {
        throw new CoreException("Could not get the parameters.", e);
    }
}
Also used : CoreException(org.jboss.pnc.spi.exception.CoreException) HashMap(java.util.HashMap) ToString(lombok.ToString) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 18 with CoreException

use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.

the class BpmManager method startTask.

public boolean startTask(BpmTask task) throws CoreException {
    try {
        task.setTaskId(getNextTaskId());
        task.setGlobalConfig(globalConfig);
        task.setBpmConfig(bpmConfig);
        if (!task.getConnector().isPresent()) {
            defineConnector(task);
        }
        String processId = task.getProcessId();
        Long processInstanceId = task.getConnector().get().startProcess(processId, task.getExtendedProcessParameters(), task.getAccessToken());
        task.setProcessInstanceId(processInstanceId);
        task.setProcessName(processId);
        tasks.put(task.getTaskId(), task);
        log.debug("Created new process linked to task: {}", task);
        return true;
    } catch (Exception e) {
        throw new CoreException("Could not start BPM task '" + task + "'.", e);
    }
}
Also used : CoreException(org.jboss.pnc.spi.exception.CoreException) CoreException(org.jboss.pnc.spi.exception.CoreException)

Example 19 with CoreException

use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.

the class BpmTask method getExtendedProcessParameters.

/**
 * Extend process parameters from the task with additional useful information, such as pncBaseUrl and taskId, needed
 * for notifications. Before use, taskId MUST be assigned.
 *
 * @throws CoreException
 */
public Map<String, Object> getExtendedProcessParameters() throws CoreException {
    Serializable processParameters = getProcessParameters();
    requireNonNull(processParameters);
    Map<String, Object> actualParameters = new HashMap<>();
    if (isJsonEncodedProcessParameters()) {
        try {
            actualParameters.put("processParameters", MAPPER.writeValueAsString(processParameters));
        } catch (JsonProcessingException e) {
            throw new CoreException("Could not serialize process processParameters '" + processParameters + "'.", e);
        }
    } else {
        actualParameters.put("processParameters", processParameters);
    }
    // global not process related parameters
    actualParameters.put("taskId", taskId);
    actualParameters.put("usersAuthToken", accessToken);
    MDCUtils.getUserId().ifPresent(v -> {
        log.debug("Setting process parameter userId: {}", v);
        actualParameters.put("userId", v);
    });
    MDCUtils.getRequestContext().ifPresent(v -> {
        log.debug("Setting process parameter logRequestContext: {}", v);
        actualParameters.put("logRequestContext", v);
    });
    MDCUtils.getProcessContext().ifPresent(v -> {
        log.debug("Setting process parameter logProcessContext: {}", v);
        actualParameters.put("logProcessContext", v);
    });
    return actualParameters;
}
Also used : Serializable(java.io.Serializable) CoreException(org.jboss.pnc.spi.exception.CoreException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 20 with CoreException

use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.

the class BuildExecutorTriggerer method executeBuild.

public BuildExecutionSession executeBuild(BuildExecutionConfiguration buildExecutionConfig, String callbackUrl, String accessToken) throws CoreException, ExecutorException {
    Consumer<BuildExecutionStatusChangedEvent> onExecutionStatusChange = (statusChangedEvent) -> {
        log.debug("Received BuildExecutionStatusChangedEvent: " + statusChangedEvent);
        if (statusChangedEvent.isFinal() && callbackUrl != null && !callbackUrl.isEmpty()) {
            statusChangedEvent.getBuildResult().ifPresent((buildResult) -> bpmNotifier.sendBuildExecutionCompleted(callbackUrl, buildResult, accessToken));
        }
    };
    BuildExecutionSession buildExecutionSession = buildExecutor.startBuilding(buildExecutionConfig, onExecutionStatusChange, accessToken);
    return buildExecutionSession;
}
Also used : Logger(org.slf4j.Logger) TaskStatusUpdateEvent(org.jboss.pnc.buildagent.api.TaskStatusUpdateEvent) BuildTaskContext(org.jboss.pnc.common.logging.BuildTaskContext) ExpiresDate(org.jboss.pnc.common.Date.ExpiresDate) BpmNotifier(org.jboss.pnc.bpm.notification.BpmNotifier) LoggerFactory(org.slf4j.LoggerFactory) BuildExecutor(org.jboss.pnc.spi.executor.BuildExecutor) Inject(javax.inject.Inject) Consumer(java.util.function.Consumer) CoreException(org.jboss.pnc.spi.exception.CoreException) Optional(java.util.Optional) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) ApplicationScoped(javax.enterprise.context.ApplicationScoped) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)

Aggregations

CoreException (org.jboss.pnc.spi.exception.CoreException)21 Inject (javax.inject.Inject)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 Consumer (java.util.function.Consumer)9 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)9 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)8 BuildCoordinator (org.jboss.pnc.spi.coordinator.BuildCoordinator)8 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)8 BuildStatus (org.jboss.pnc.enums.BuildStatus)7 BuildOptions (org.jboss.pnc.spi.BuildOptions)7 DatastoreException (org.jboss.pnc.spi.datastore.DatastoreException)7 BuildStatusChangedEvent (org.jboss.pnc.spi.events.BuildStatusChangedEvent)7 List (java.util.List)6 TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)6 Optional (java.util.Optional)5 Set (java.util.Set)5 BuildCoordinationStatus (org.jboss.pnc.enums.BuildCoordinationStatus)5 BuildSetStatus (org.jboss.pnc.spi.BuildSetStatus)5 BuildSetStatusChangedEvent (org.jboss.pnc.spi.events.BuildSetStatusChangedEvent)5