Search in sources :

Example 11 with ExecutorException

use of org.jboss.pnc.spi.executor.exceptions.ExecutorException in project pnc by project-ncl.

the class DefaultBuildExecutionSession method setStatus.

@Override
public void setStatus(BuildExecutionStatus status) {
    if (status.hasFailed() && failedReasonStatus == null) {
        if (status.equals(DONE_WITH_ERRORS) && executorException == null) {
            setException(new ExecutorException("FailedReasonStatus or executorException must be set before final DONE_WITH_ERRORS."));
        }
        log.debug("Setting status {} as failed reason for session {}.", status, getId());
        failedReasonStatus = status;
    }
    Optional<BuildResult> buildResult;
    if (status.isCompleted()) {
        buildResult = Optional.of(getBuildResult());
    } else {
        buildResult = Optional.empty();
    }
    BuildExecutionStatusChangedEvent statusChanged = new DefaultBuildExecutorStatusChangedEvent(this.status, status, getId(), null, buildResult, status.isCompleted());
    log.debug("Updating build execution task {} status to {}.", getId(), statusChanged);
    this.status = status;
    onBuildExecutionStatusChangedEvent.accept(statusChanged);
    log.debug("Fired events after build execution task {} update.", getId());
}
Also used : BuildResult(org.jboss.pnc.spi.BuildResult) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)

Example 12 with ExecutorException

use of org.jboss.pnc.spi.executor.exceptions.ExecutorException in project pnc by project-ncl.

the class BuildResultMock method mock.

public static BuildResult mock(BuildStatus status) {
    BuildExecutionConfiguration buildExecutionConfig = BuildExecutionConfigurationMock.mockConfig();
    BuildDriverResult buildDriverResult = BuildDriverResultMock.mockResult(status);
    RepositoryManagerResult repositoryManagerResult = RepositoryManagerResultMock.mockResult();
    ExecutorException exception = buildException();
    CompletionStatus completionStatus;
    if (status.completedSuccessfully()) {
        completionStatus = CompletionStatus.SUCCESS;
    } else {
        completionStatus = CompletionStatus.FAILED;
    }
    return new BuildResult(completionStatus, Optional.of(new ProcessException("Test Exception.")), "", Optional.ofNullable(buildExecutionConfig), Optional.ofNullable(buildDriverResult), Optional.ofNullable(repositoryManagerResult), Optional.of(EnvironmentDriverResultMock.mock()), Optional.of(RepourResultMock.mock()));
}
Also used : BuildResult(org.jboss.pnc.spi.BuildResult) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus)

Example 13 with ExecutorException

use of org.jboss.pnc.spi.executor.exceptions.ExecutorException in project pnc by project-ncl.

the class BuildExecutionSessionMock method setStatus.

@Override
public void setStatus(BuildExecutionStatus status) {
    if (status.hasFailed() && failedReasonStatus == null) {
        if (status.equals(DONE_WITH_ERRORS)) {
            setException(new ExecutorException("Missing failedReasonStatus. Failed reason must be sat before final DONE_WITH_ERRORS."));
        }
        log.debug("Setting status {} as failed reason for session {}.", status, getId());
        failedReasonStatus = status;
    }
    Optional<BuildResult> buildResult;
    if (status.isCompleted()) {
        buildResult = Optional.of(getBuildResult());
    } else {
        buildResult = Optional.empty();
    }
    BuildExecutionStatusChangedEvent statusChanged = new BuildExecutorStatusChangedEventMock(this.status, status, getId(), null, buildResult, status.isCompleted());
    log.debug("Updating build execution task {} status to {}.", getId(), statusChanged);
    this.status = status;
    onBuildExecutionStatusChangedEvent.accept(statusChanged);
    log.debug("Fired events after build execution task {} update.", getId());
}
Also used : BuildResult(org.jboss.pnc.spi.BuildResult) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)

Example 14 with ExecutorException

use of org.jboss.pnc.spi.executor.exceptions.ExecutorException in project pnc by project-ncl.

the class BuildExecutionSessionMock method getBuildResult.

private BuildResult getBuildResult() {
    EnvironmentDriverResult environmentDriverResult = null;
    DebugData debugData = getRunningEnvironment() != null ? getRunningEnvironment().getDebugData() : null;
    if (debugData != null && debugData.isDebugEnabled()) {
        environmentDriverResult = new EnvironmentDriverResult(CompletionStatus.SUCCESS, "", Optional.of(debugData.getSshCredentials()));
    }
    CompletionStatus completionStatus = CompletionStatus.SUCCESS;
    if (executorException == null) {
        if (failedReasonStatus != null) {
            switch(failedReasonStatus) {
                case BUILD_ENV_SETUP_COMPLETE_WITH_ERROR:
                case COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER_COMPLETED_WITH_ERROR:
                case SYSTEM_ERROR:
                    completionStatus = CompletionStatus.SYSTEM_ERROR;
                    break;
                case BUILD_COMPLETED_WITH_ERROR:
                    completionStatus = CompletionStatus.FAILED;
                    break;
                case CANCELLED:
                    completionStatus = CompletionStatus.CANCELLED;
                    break;
                case DONE_WITH_ERRORS:
                    executorException = new ExecutorException("DONE_WITH_ERRORS cannot be set as failed reason.");
                    break;
            }
        }
    }
    ProcessException processException = null;
    if (executorException != null) {
        processException = new ProcessException(executorException);
        completionStatus = CompletionStatus.SYSTEM_ERROR;
    }
    log.debug("Returning result of task {}.", getId());
    return new BuildResult(completionStatus, Optional.ofNullable(processException), "", Optional.ofNullable(buildExecutionConfiguration), Optional.ofNullable(buildDriverResult), Optional.ofNullable(repositoryManagerResult), Optional.ofNullable(environmentDriverResult), Optional.empty());
}
Also used : ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) BuildResult(org.jboss.pnc.spi.BuildResult) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) DebugData(org.jboss.pnc.spi.builddriver.DebugData) EnvironmentDriverResult(org.jboss.pnc.spi.environment.EnvironmentDriverResult) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus)

Example 15 with ExecutorException

use of org.jboss.pnc.spi.executor.exceptions.ExecutorException 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

ExecutorException (org.jboss.pnc.spi.executor.exceptions.ExecutorException)15 BuildResult (org.jboss.pnc.spi.BuildResult)10 BuildExecutionStatusChangedEvent (org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)10 Consumer (java.util.function.Consumer)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 Inject (javax.inject.Inject)7 BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)7 BuildExecutionStatus (org.jboss.pnc.enums.BuildExecutionStatus)6 Configuration (org.jboss.pnc.common.Configuration)5 BuildDriverFactory (org.jboss.pnc.executor.servicefactories.BuildDriverFactory)5 EnvironmentDriverFactory (org.jboss.pnc.executor.servicefactories.EnvironmentDriverFactory)5 RepositoryManagerFactory (org.jboss.pnc.executor.servicefactories.RepositoryManagerFactory)5 TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)5 BuildExecutor (org.jboss.pnc.spi.executor.BuildExecutor)5 Set (java.util.Set)4 ApplicationScoped (javax.enterprise.context.ApplicationScoped)4 ConfigurationParseException (org.jboss.pnc.common.json.ConfigurationParseException)4 ObjectWrapper (org.jboss.pnc.common.util.ObjectWrapper)4 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)4