Search in sources :

Example 1 with CompletionStatus

use of org.jboss.pnc.spi.coordinator.CompletionStatus in project pnc by project-ncl.

the class DefaultBuildExecutionSession 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 SYSTEM_ERROR:
                    completionStatus = CompletionStatus.SYSTEM_ERROR;
                    break;
                case COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER_COMPLETED_WITH_ERROR:
                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 2 with CompletionStatus

use of org.jboss.pnc.spi.coordinator.CompletionStatus in project pnc by project-ncl.

the class DatastoreAdapterTest method shouldStoreRepositoryManagerError.

@Test
public void shouldStoreRepositoryManagerError() throws DatastoreException {
    // given
    DatastoreMock datastore = new DatastoreMock();
    DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastore);
    BuildStatus buildStatus = BuildStatus.SUCCESS;
    CompletionStatus completionStatus = CompletionStatus.FAILED;
    // when
    storeResult(datastoreAdapter, buildStatus, completionStatus);
    // then
    List<BuildRecord> buildRecords = datastore.getBuildRecords();
    Assert.assertEquals(1, buildRecords.size());
    BuildRecord buildRecord = buildRecords.get(0);
    Assert.assertEquals(BuildStatus.FAILED, buildRecord.getStatus());
    Assert.assertTrue(buildRecord.getBuildLog().contains(BUILD_LOG));
    Assert.assertTrue(buildRecord.getBuildLog().contains(REPOSITORY_MANAGER_LOG));
}
Also used : CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) BuildStatus(org.jboss.pnc.enums.BuildStatus) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 3 with CompletionStatus

use of org.jboss.pnc.spi.coordinator.CompletionStatus in project pnc by project-ncl.

the class BuildResultMapper method toDTO.

public BuildResultRest toDTO(BuildResult buildResult) {
    CompletionStatus completionStatus = buildResult.getCompletionStatus();
    ProcessException processException = buildResult.getProcessException().orElse(null);
    String processLog = buildResult.getProcessLog();
    BuildExecutionConfigurationRest buildExecutionConfiguration;
    if (buildResult.getBuildExecutionConfiguration().isPresent()) {
        BuildExecutionConfiguration bec = buildResult.getBuildExecutionConfiguration().get();
        buildExecutionConfiguration = new BuildExecutionConfigurationRest(bec);
    } else {
        buildExecutionConfiguration = null;
    }
    BuildDriverResultRest buildDriverResult;
    if (buildResult.getBuildDriverResult().isPresent()) {
        BuildDriverResult result = buildResult.getBuildDriverResult().get();
        buildDriverResult = new BuildDriverResultRest(result);
    } else {
        buildDriverResult = null;
    }
    RepositoryManagerResultRest repositoryManagerResult;
    if (buildResult.getRepositoryManagerResult().isPresent()) {
        RepositoryManagerResult result = buildResult.getRepositoryManagerResult().get();
        repositoryManagerResult = repositoryManagerResultMapper.toDTO(result);
    } else {
        repositoryManagerResult = null;
    }
    EnvironmentDriverResult environmentDriverResult;
    if (buildResult.getEnvironmentDriverResult().isPresent()) {
        environmentDriverResult = buildResult.getEnvironmentDriverResult().get();
    } else {
        environmentDriverResult = null;
    }
    RepourResult repourResult = buildResult.getRepourResult().orElse(null);
    return new BuildResultRest(completionStatus, processException, processLog, buildExecutionConfiguration, buildDriverResult, repositoryManagerResult, environmentDriverResult, repourResult);
}
Also used : BuildResultRest(org.jboss.pnc.bpm.model.BuildResultRest) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResultRest(org.jboss.pnc.bpm.model.RepositoryManagerResultRest) EnvironmentDriverResult(org.jboss.pnc.spi.environment.EnvironmentDriverResult) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) BuildExecutionConfigurationRest(org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest) RepourResult(org.jboss.pnc.spi.repour.RepourResult) BuildDriverResultRest(org.jboss.pnc.bpm.model.BuildDriverResultRest)

Example 4 with CompletionStatus

use of org.jboss.pnc.spi.coordinator.CompletionStatus in project pnc by project-ncl.

the class RepositoryManagerResultMapper method toEntity.

public RepositoryManagerResult toEntity(RepositoryManagerResultRest dto) {
    List<org.jboss.pnc.model.Artifact> builtArtifacts = dto.getBuiltArtifacts().stream().map(artifactRest -> artifactMapper.toEntityWithTransientTargetRepository(artifactRest)).collect(Collectors.toList());
    List<org.jboss.pnc.model.Artifact> dependencies = dto.getDependencies().stream().map(artifactRest -> artifactMapper.toEntityWithTransientTargetRepository(artifactRest)).collect(Collectors.toList());
    String buildContentId = dto.getBuildContentId();
    String log = dto.getLog();
    CompletionStatus completionStatus = dto.getCompletionStatus();
    return new GenericRepositoryManagerResult(builtArtifacts, dependencies, buildContentId, log, completionStatus);
}
Also used : Inject(javax.inject.Inject) GenericRepositoryManagerResult(org.jboss.pnc.bpm.model.RepositoryManagerResultRest.GenericRepositoryManagerResult) List(java.util.List) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) RepositoryManagerResultRest(org.jboss.pnc.bpm.model.RepositoryManagerResultRest) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Artifact(org.jboss.pnc.dto.Artifact) ArtifactMapper(org.jboss.pnc.mapper.api.ArtifactMapper) Collectors(java.util.stream.Collectors) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) GenericRepositoryManagerResult(org.jboss.pnc.bpm.model.RepositoryManagerResultRest.GenericRepositoryManagerResult) Artifact(org.jboss.pnc.dto.Artifact)

Example 5 with CompletionStatus

use of org.jboss.pnc.spi.coordinator.CompletionStatus in project pnc by project-ncl.

the class IndyRepositorySession method extractBuildArtifacts.

/**
 * Retrieve tracking report from repository manager. Add each tracked download to the dependencies of the build
 * result. Add each tracked upload to the built artifacts of the build result. Promote uploaded artifacts to the
 * product-level storage. Finally delete the group associated with the completed build.
 *
 * @param liveBuild {@inheritDoc} - if true, the promotion of the collected artifacts and dependencies is done,
 *        tracking report is sealed and the build group is removed, if false it only reads the data without any
 *        actions
 */
@Override
public RepositoryManagerResult extractBuildArtifacts(final boolean liveBuild) throws RepositoryManagerException {
    TrackedContentDTO report = sealAndGetTrackingReport(liveBuild);
    Comparator<Artifact> comp = (one, two) -> one.getIdentifier().compareTo(two.getIdentifier());
    Uploads uploads = collectUploads(report);
    List<Artifact> uploadedArtifacts = uploads.getData();
    Collections.sort(uploadedArtifacts, comp);
    List<Artifact> downloadedArtifacts = null;
    String log = "";
    CompletionStatus status = CompletionStatus.SUCCESS;
    try {
        downloadedArtifacts = processDownloads(report, liveBuild);
        Collections.sort(downloadedArtifacts, comp);
    } catch (PromotionValidationException ex) {
        status = CompletionStatus.FAILED;
        log = ex.getMessage();
        logger.warn("Dependencies promotion failed. Error(s): {}", log);
        userLog.error("Dependencies promotion failed. Error(s): {}", log);
    }
    if (liveBuild) {
        deleteBuildGroup();
    }
    // if the promotion of dependencies succeeded...
    if (status == CompletionStatus.SUCCESS) {
        logger.info("Returning built artifacts / dependencies:\nUploads:\n  {}\n\nDownloads:\n  {}\n\n", StringUtils.join(uploads.getData(), "\n  "), StringUtils.join(downloadedArtifacts, "\n  "));
        if (liveBuild) {
            logger.info("BEGIN: promotion to build content set");
            StopWatch stopWatch = StopWatch.createStarted();
            try {
                promoteToBuildContentSet(uploads.getPromotion());
            } catch (PromotionValidationException ex) {
                status = CompletionStatus.FAILED;
                log = ex.getMessage();
                logger.warn("Built artifact promotion failed. Error(s): {}", log);
                userLog.error("Built artifact promotion failed. Error(s): {}", log);
            }
            logger.info("END: promotion to build content set, took: {} seconds", stopWatch.getTime(TimeUnit.SECONDS));
            stopWatch.reset();
        }
    }
    if (status == CompletionStatus.FAILED) {
        // prevent saving artifacts and dependencies to a failed build
        downloadedArtifacts = Collections.emptyList();
        uploadedArtifacts = Collections.emptyList();
    }
    return new IndyRepositoryManagerResult(uploadedArtifacts, downloadedArtifacts, buildContentId, log, status);
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Date(java.util.Date) ValidationResult(org.commonjava.indy.promote.model.ValidationResult) LoggerFactory(org.slf4j.LoggerFactory) AbstractPromoteResult(org.commonjava.indy.promote.model.AbstractPromoteResult) Map(java.util.Map) ConstraintViolation(javax.validation.ConstraintViolation) StoreKey(org.commonjava.indy.model.core.StoreKey) TargetRepository(org.jboss.pnc.model.TargetRepository) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) ArtifactPathInfo(org.commonjava.atlas.maven.ident.util.ArtifactPathInfo) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) NpmPackageRef(org.commonjava.atlas.npm.ident.ref.NpmPackageRef) SimpleArtifactRef(org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef) StringUtils.isEmpty(org.apache.commons.lang.StringUtils.isEmpty) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Artifact(org.jboss.pnc.model.Artifact) StoreType(org.commonjava.indy.model.core.StoreType) Validator(javax.validation.Validator) Set(java.util.Set) StopWatch(org.apache.commons.lang3.time.StopWatch) Instant(java.time.Instant) IndyContentClientModule(org.commonjava.indy.client.core.module.IndyContentClientModule) IndyPromoteClientModule(org.commonjava.indy.promote.client.IndyPromoteClientModule) IOUtils(org.apache.commons.io.IOUtils) RepositoryConnectionInfo(org.jboss.pnc.spi.repositorymanager.model.RepositoryConnectionInfo) List(java.util.List) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef) IndyClientException(org.commonjava.indy.client.core.IndyClientException) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) NPM_PKG_KEY(org.commonjava.indy.pkg.npm.model.NPMPackageTypeDescriptor.NPM_PKG_KEY) PackageURL(com.github.packageurl.PackageURL) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) ValidatorFactory(javax.validation.ValidatorFactory) HashMap(java.util.HashMap) SHARED_IMPORTS_ID(org.jboss.pnc.indyrepositorymanager.IndyRepositoryConstants.SHARED_IMPORTS_ID) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ReposiotryIdentifier(org.jboss.pnc.constants.ReposiotryIdentifier) MalformedPackageURLException(com.github.packageurl.MalformedPackageURLException) CollectionUtils(org.apache.commons.collections.CollectionUtils) RepositoryType(org.jboss.pnc.enums.RepositoryType) Validation(javax.validation.Validation) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) GENERIC_PKG_KEY(org.commonjava.indy.model.core.GenericPackageTypeDescriptor.GENERIC_PKG_KEY) Logger(org.slf4j.Logger) Indy(org.commonjava.indy.client.core.Indy) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) HostedRepository(org.commonjava.indy.model.core.HostedRepository) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) PackageURLBuilder(com.github.packageurl.PackageURLBuilder) BuildCategory(org.jboss.pnc.enums.BuildCategory) Comparator(java.util.Comparator) NpmPackagePathInfo(org.commonjava.atlas.npm.ident.util.NpmPackagePathInfo) Collections(java.util.Collections) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) Artifact(org.jboss.pnc.model.Artifact) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) StopWatch(org.apache.commons.lang3.time.StopWatch)

Aggregations

CompletionStatus (org.jboss.pnc.spi.coordinator.CompletionStatus)11 RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)6 ProcessException (org.jboss.pnc.spi.coordinator.ProcessException)5 EnvironmentDriverResult (org.jboss.pnc.spi.environment.EnvironmentDriverResult)4 List (java.util.List)3 RepositoryManagerResultRest (org.jboss.pnc.bpm.model.RepositoryManagerResultRest)3 BuildRecord (org.jboss.pnc.model.BuildRecord)3 Collectors (java.util.stream.Collectors)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Inject (javax.inject.Inject)2 BuildCoordinationException (org.jboss.pnc.coordinator.BuildCoordinationException)2 BuildStatus (org.jboss.pnc.enums.BuildStatus)2 BuildResult (org.jboss.pnc.spi.BuildResult)2 BuildDriverResult (org.jboss.pnc.spi.builddriver.BuildDriverResult)2 BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)2 ExecutorException (org.jboss.pnc.spi.executor.exceptions.ExecutorException)2 RepourResult (org.jboss.pnc.spi.repour.RepourResult)2 MalformedPackageURLException (com.github.packageurl.MalformedPackageURLException)1 PackageURL (com.github.packageurl.PackageURL)1 PackageURLBuilder (com.github.packageurl.PackageURLBuilder)1