Search in sources :

Example 1 with BuildImportRequest

use of org.jboss.pnc.api.causeway.dto.push.BuildImportRequest in project pnc by project-ncl.

the class BuildResultPushManager method push.

public Result push(BuildPushOperation buildPushOperation, String authToken) {
    logger.info("Pushing to causeway {}", buildPushOperation.toString());
    boolean added = inProgress.add(buildPushOperation.getBuildRecord().getId(), buildPushOperation.getTagPrefix(), buildPushOperation.getPushResultId().toString());
    String externalBuildId = BuildMapper.idMapper.toDto(buildPushOperation.getBuildRecord().getId());
    if (!added) {
        logger.warn("Push for build.id {} already running.", externalBuildId);
        return new Result(buildPushOperation.getPushResultId().toString(), externalBuildId, BuildPushStatus.REJECTED, "A push for this buildRecord is already running.");
    }
    BuildPushStatus pushStatus;
    String message;
    try {
        BuildImportRequest buildImportRequest = createCausewayPushRequest(buildPushOperation.getBuildRecord(), buildPushOperation.getTagPrefix(), URI.create(String.format(buildPushOperation.getCompleteCallbackUrlTemplate(), externalBuildId)), authToken, buildPushOperation.getPushResultId(), buildPushOperation.isReImport());
        boolean successfullyStarted = causewayClient.importBuild(buildImportRequest, authToken);
        if (successfullyStarted) {
            pushStatus = BuildPushStatus.ACCEPTED;
            message = "";
        } else {
            pushStatus = BuildPushStatus.SYSTEM_ERROR;
            message = "Failed to push to Causeway.";
        }
    } catch (RuntimeException ex) {
        logger.error("Failed to push to Causeway.", ex);
        pushStatus = BuildPushStatus.SYSTEM_ERROR;
        message = "Failed to push to Causeway: " + ex.getMessage();
    }
    if (!BuildPushStatus.ACCEPTED.equals(pushStatus)) {
        inProgress.remove(buildPushOperation.getBuildRecord().getId());
    }
    return new Result(buildPushOperation.getPushResultId().toString(), externalBuildId, pushStatus, message);
}
Also used : BuildPushStatus(org.jboss.pnc.enums.BuildPushStatus) BuildImportRequest(org.jboss.pnc.api.causeway.dto.push.BuildImportRequest) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult)

Example 2 with BuildImportRequest

use of org.jboss.pnc.api.causeway.dto.push.BuildImportRequest in project pnc by project-ncl.

the class BuildResultPushManager method createCausewayPushRequest.

private BuildImportRequest createCausewayPushRequest(BuildRecord buildRecord, String tagPrefix, URI callBackUrl, String authToken, Long pushResultId, boolean reimport) {
    BuildEnvironment buildEnvironment = buildRecord.getBuildConfigurationAudited().getBuildEnvironment();
    logger.debug("BuildRecord: {}", buildRecord.getId());
    logger.debug("BuildEnvironment: {}", buildEnvironment);
    BuildRoot buildRoot = BuildRoot.builder().container("DOCKER_IMAGE").containerArchitecture(// TODO set based on env, some env has native build tools
    "x86_64").host("rhel").hostArchitecture("x86_64").tools(buildEnvironment.getAttributes()).build();
    List<Artifact> builtArtifactEntities = artifactRepository.queryWithPredicates(ArtifactPredicates.withBuildRecordId(buildRecord.getId()));
    List<Artifact> dependencyEntities = artifactRepository.queryWithPredicates(ArtifactPredicates.withDependantBuildRecordId(buildRecord.getId()));
    logger.debug("Preparing BuildImportRequest containing {} built artifacts and {} dependencies.", builtArtifactEntities.size(), dependencyEntities.size());
    BuildType buildType = buildRecord.getBuildConfigurationAudited().getBuildType();
    Set<Dependency> dependencies = collectDependencies(dependencyEntities);
    Set<BuiltArtifact> builtArtifacts = collectBuiltArtifacts(builtArtifactEntities, buildType);
    Map<String, String> callbackHeaders = Collections.singletonMap(MDCUtils.getMDCToHeaderMappings().get(MDCKeys.PROCESS_CONTEXT_KEY), pushResultId.toString());
    Request callbackTarget = Request.builder().method(Request.Method.POST).authTokenHeader(authToken).uri(callBackUrl).header(MDCUtils.getMDCToHeaderMappings().get(MDCKeys.PROCESS_CONTEXT_KEY), pushResultId.toString()).build();
    String executionRootName = buildRecord.getExecutionRootName();
    // prefer execution root name from generic parameters
    BuildConfigurationAudited buildConfigurationAudited = buildConfigurationAuditedRepository.queryById(buildRecord.getBuildConfigurationAuditedIdRev());
    Map<String, String> genericParameters = buildConfigurationAudited.getGenericParameters();
    if (executionRootName == null) {
        if (genericParameters.containsKey(BREW_BUILD_NAME.name())) {
            executionRootName = genericParameters.get(BREW_BUILD_NAME.name());
        } else {
            throw new IllegalArgumentException("Provided build " + buildRecord.getId() + " is missing brew name. Please set build attribute " + BUILD_BREW_NAME + ".");
        }
    }
    Build build = getBuild(buildRecord, tagPrefix, buildRoot, dependencies, builtArtifacts, executionRootName, buildType);
    return new BuildImportRequest(callbackTarget, build, reimport);
}
Also used : BuildImportRequest(org.jboss.pnc.api.causeway.dto.push.BuildImportRequest) Request(org.jboss.pnc.api.dto.Request) BuildImportRequest(org.jboss.pnc.api.causeway.dto.push.BuildImportRequest) Dependency(org.jboss.pnc.api.causeway.dto.push.Dependency) Artifact(org.jboss.pnc.model.Artifact) BuiltArtifact(org.jboss.pnc.api.causeway.dto.push.BuiltArtifact) MavenBuiltArtifact(org.jboss.pnc.api.causeway.dto.push.MavenBuiltArtifact) NpmBuiltArtifact(org.jboss.pnc.api.causeway.dto.push.NpmBuiltArtifact) BuiltArtifact(org.jboss.pnc.api.causeway.dto.push.BuiltArtifact) MavenBuiltArtifact(org.jboss.pnc.api.causeway.dto.push.MavenBuiltArtifact) NpmBuiltArtifact(org.jboss.pnc.api.causeway.dto.push.NpmBuiltArtifact) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildEnvironment(org.jboss.pnc.model.BuildEnvironment) Build(org.jboss.pnc.api.causeway.dto.push.Build) MavenBuild(org.jboss.pnc.api.causeway.dto.push.MavenBuild) NpmBuild(org.jboss.pnc.api.causeway.dto.push.NpmBuild) BuildType(org.jboss.pnc.enums.BuildType) BuildRoot(org.jboss.pnc.api.causeway.dto.push.BuildRoot)

Aggregations

BuildImportRequest (org.jboss.pnc.api.causeway.dto.push.BuildImportRequest)2 Build (org.jboss.pnc.api.causeway.dto.push.Build)1 BuildRoot (org.jboss.pnc.api.causeway.dto.push.BuildRoot)1 BuiltArtifact (org.jboss.pnc.api.causeway.dto.push.BuiltArtifact)1 Dependency (org.jboss.pnc.api.causeway.dto.push.Dependency)1 MavenBuild (org.jboss.pnc.api.causeway.dto.push.MavenBuild)1 MavenBuiltArtifact (org.jboss.pnc.api.causeway.dto.push.MavenBuiltArtifact)1 NpmBuild (org.jboss.pnc.api.causeway.dto.push.NpmBuild)1 NpmBuiltArtifact (org.jboss.pnc.api.causeway.dto.push.NpmBuiltArtifact)1 Request (org.jboss.pnc.api.dto.Request)1 BuildPushResult (org.jboss.pnc.dto.BuildPushResult)1 BuildPushStatus (org.jboss.pnc.enums.BuildPushStatus)1 BuildType (org.jboss.pnc.enums.BuildType)1 Artifact (org.jboss.pnc.model.Artifact)1 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)1 BuildEnvironment (org.jboss.pnc.model.BuildEnvironment)1 BuildRecordPushResult (org.jboss.pnc.model.BuildRecordPushResult)1