Search in sources :

Example 11 with BuildExecutionStatusChangedEvent

use of org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent in project pnc by project-ncl.

the class EarlyCancellationTest method testBuild.

private void testBuild(BuildExecutionStatus cancelAfter, BuildExecutionStatus[] expectedStatuses, BuildExecutionStatus[] unexpectedStatuses) throws ExecutorException, TimeoutException, InterruptedException, BuildDriverException, ConfigurationParseException {
    BuildConfiguration buildConfiguration = configurationBuilder.build(1, "c1-java");
    Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
    ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
    DefaultBuildExecutor executor = new DefaultBuildExecutor(repositoryManagerFactory, buildDriverFactory, environmentDriverFactory, new Configuration(), null);
    Consumer<BuildExecutionStatusChangedEvent> cancel = (e) -> {
        if (cancelAfter.equals(e.getNewStatus())) {
            try {
                log.info("Cancelling build ...");
                executor.cancel("1");
            } catch (ExecutorException e0) {
                e0.printStackTrace();
            }
        }
    };
    runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper, cancel, executor);
    // check build statuses
    checkBuildStatuses(statusChangedEvents, Arrays.asList(expectedStatuses));
    buildStatusesShouldNotContain(statusChangedEvents, Arrays.asList(unexpectedStatuses));
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Arrays(java.util.Arrays) BuildDriverException(org.jboss.pnc.spi.builddriver.exception.BuildDriverException) Arquillian(org.jboss.arquillian.junit.Arquillian) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) RepositoryManagerFactory(org.jboss.pnc.executor.servicefactories.RepositoryManagerFactory) Inject(javax.inject.Inject) HashSet(java.util.HashSet) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) Logger(org.slf4j.Logger) BuildDriverFactory(org.jboss.pnc.executor.servicefactories.BuildDriverFactory) BuildResult(org.jboss.pnc.spi.BuildResult) Set(java.util.Set) Test(org.junit.Test) Configuration(org.jboss.pnc.common.Configuration) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) Consumer(java.util.function.Consumer) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) EnvironmentDriverFactory(org.jboss.pnc.executor.servicefactories.EnvironmentDriverFactory) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) BuildResult(org.jboss.pnc.spi.BuildResult) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Configuration(org.jboss.pnc.common.Configuration) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) HashSet(java.util.HashSet)

Example 12 with BuildExecutionStatusChangedEvent

use of org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent 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 13 with BuildExecutionStatusChangedEvent

use of org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent in project pnc by project-ncl.

the class BuildExecutionTest method shouldNotContinueBuildOnMavenError.

@Test
public void shouldNotContinueBuildOnMavenError() throws ExecutorException, InterruptedException, TimeoutException {
    BuildConfiguration buildConfiguration = configurationBuilder.buildFailingConfiguration(3, "build-failed-on-maven", null);
    Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
    ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
    runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper);
    checkBuildStatuses(statusChangedEvents, Arrays.asList(DONE_WITH_ERRORS, BUILD_ENV_DESTROYED, BUILD_ENV_DESTROYING));
    assertNoState(statusChangedEvents, BuildExecutionStatus.COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER);
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildResult(org.jboss.pnc.spi.BuildResult) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with BuildExecutionStatusChangedEvent

use of org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent 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 15 with BuildExecutionStatusChangedEvent

use of org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent 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

BuildExecutionStatusChangedEvent (org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)15 BuildResult (org.jboss.pnc.spi.BuildResult)11 ExecutorException (org.jboss.pnc.spi.executor.exceptions.ExecutorException)10 BuildExecutionStatus (org.jboss.pnc.enums.BuildExecutionStatus)9 Consumer (java.util.function.Consumer)8 ObjectWrapper (org.jboss.pnc.common.util.ObjectWrapper)8 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 HashSet (java.util.HashSet)7 Inject (javax.inject.Inject)7 Test (org.junit.Test)7 BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)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