Search in sources :

Example 1 with BuildExecutionConfigurationRest

use of org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest 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 2 with BuildExecutionConfigurationRest

use of org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest in project pnc by project-ncl.

the class BuildTaskEndpointTest method shouldTriggerBuildExecution.

@Test
public void shouldTriggerBuildExecution() throws RemoteResourceException {
    HttpPost request = new HttpPost(url + BASE_REST_PATH + "/build-tasks/execute-build");
    request.addHeader(Credentials.USER.createAuthHeader(BasicHeader::new));
    BuildExecutionConfiguration buildExecutionConfig = BuildExecutionConfiguration.build("1", "test-content-id", "1", "mvn clean install", "12", "jboss-modules", "scm-url", "f18de64523d5054395d82e24d4e28473a05a3880", "1.0.0.redhat-1", "origin-scm-url", false, "dummy-docker-image-id", "dummy.repo.url/repo", SystemImageType.DOCKER_IMAGE, BuildType.MVN, false, null, new HashMap<>(), false, null, false, "-DdependencySource=REST -DrepoRemovalBackup=repositories-backup.xml -DversionSuffixStrip= -DreportNonAligned=true", AlignmentPreference.PREFER_PERSISTENT);
    BuildExecutionConfigurationRest buildExecutionConfigurationRest = new BuildExecutionConfigurationRest(buildExecutionConfig);
    List<NameValuePair> requestParameters = new ArrayList<>();
    requestParameters.add(new BasicNameValuePair("buildExecutionConfiguration", buildExecutionConfigurationRest.toString()));
    try {
        request.setEntity(new UrlEncodedFormEntity(requestParameters));
    } catch (UnsupportedEncodingException e) {
        log.error("Cannot prepare request.", e);
        Assert.fail("Cannot prepare request." + e.getMessage());
    }
    log.info("Executing request {} with parameters: {}", request.getRequestLine(), requestParameters);
    int statusCode = -1;
    try (CloseableHttpClient httpClient = HttpUtils.getPermissiveHttpClient()) {
        try (CloseableHttpResponse response = httpClient.execute(request)) {
            statusCode = response.getStatusLine().getStatusCode();
            Assert.assertEquals("Received error response code. Response: " + printEntity(response), 200, statusCode);
        }
    } catch (IOException e) {
        Assertions.fail("Cannot invoke remote endpoint.", e);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) IOException(java.io.IOException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BuildExecutionConfigurationRest(org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 3 with BuildExecutionConfigurationRest

use of org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest in project pnc by project-ncl.

the class BpmBuildTask method getBuildExecutionConfiguration.

private BuildExecutionConfigurationRest getBuildExecutionConfiguration(BuildTask buildTask) {
    BuildConfigurationAudited buildConfigurationAudited = buildTask.getBuildConfigurationAudited();
    String contentId = ContentIdentityManager.getBuildContentId(buildTask.getId());
    BuildExecutionConfiguration buildExecutionConfiguration = BuildExecutionConfiguration.build(buildTask.getId(), contentId, buildTask.getUser().getId().toString(), buildConfigurationAudited.getBuildScript(), buildConfigurationAudited.getId().toString(), buildConfigurationAudited.getName(), // TODO update to use also other parts or Repository Configuration
    buildConfigurationAudited.getRepositoryConfiguration().getInternalUrl(), buildConfigurationAudited.getScmRevision(), // SCM Tag is about to be set once it is created after the alignment phase
    null, buildConfigurationAudited.getRepositoryConfiguration().getExternalUrl(), buildConfigurationAudited.getRepositoryConfiguration().isPreBuildSyncEnabled(), buildConfigurationAudited.getBuildEnvironment().getSystemImageId(), buildConfigurationAudited.getBuildEnvironment().getSystemImageRepositoryUrl(), buildConfigurationAudited.getBuildEnvironment().getSystemImageType(), buildConfigurationAudited.getBuildConfiguration().getBuildType(), buildTask.getBuildOptions().isKeepPodOnFailure(), buildConfigurationAudited.getGenericParameters(), buildTask.getBuildOptions().isTemporaryBuild(), TimeUtils.generateTimestamp(buildTask.getBuildOptions().isTimestampAlignment(), buildTask.getBuildSetTask().getStartTime()), buildConfigurationAudited.isBrewPullActive(), buildConfigurationAudited.getDefaultAlignmentParams(), buildTask.getBuildOptions().getAlignmentPreference());
    return new BuildExecutionConfigurationRest(buildExecutionConfiguration);
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) ToString(lombok.ToString) BuildExecutionConfigurationRest(org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest)

Example 4 with BuildExecutionConfigurationRest

use of org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest in project pnc by project-ncl.

the class BuildExecutionConfigurationTest method serializeAndDeserializeBuildResult.

@Test
public void serializeAndDeserializeBuildResult() throws IOException, BuildDriverException {
    BuildExecutionConfiguration buildExecutionConfiguration = BuildExecutionConfiguration.build("1", "condent-id", "1", "mvn clean install", "configuration name", "12", "https://pathToRepo.git", "f18de64523d5054395d82e24d4e28473a05a3880", "1.0.0.Final-redhat-00001", "https://pathToOriginRepo.git", false, "abcd1234", "image.repo.url/repo", SystemImageType.DOCKER_IMAGE, BuildType.MVN, false, null, new HashMap<>(), false, null, false, "-DdependencySource=REST -DrepoRemovalBackup=repositories-backup.xml -DversionSuffixStrip= -DreportNonAligned=true", AlignmentPreference.PREFER_PERSISTENT);
    BuildExecutionConfigurationRest buildExecutionConfigurationREST = new BuildExecutionConfigurationRest(buildExecutionConfiguration);
    String buildExecutionConfigurationJson = buildExecutionConfigurationREST.toString();
    log.debug("Json : {}", buildExecutionConfigurationJson);
    BuildExecutionConfigurationRest buildExecutionConfigurationRestFromJson = JsonOutputConverterMapper.readValue(buildExecutionConfigurationJson, BuildExecutionConfigurationRest.class);
    BuildExecutionConfiguration buildExecutionConfigurationFromJson = buildExecutionConfigurationRestFromJson.toBuildExecutionConfiguration();
    String message = "Deserialized object does not match the original.";
    Assert.assertEquals(message, buildExecutionConfiguration.getId(), buildExecutionConfigurationFromJson.getId());
    Assert.assertEquals(message, buildExecutionConfiguration.getBuildScript(), buildExecutionConfigurationFromJson.getBuildScript());
    Assert.assertEquals(message, buildExecutionConfiguration.getName(), buildExecutionConfigurationFromJson.getName());
    Assert.assertEquals(message, buildExecutionConfiguration.getScmRepoURL(), buildExecutionConfigurationFromJson.getScmRepoURL());
    Assert.assertEquals(message, buildExecutionConfiguration.getScmRevision(), buildExecutionConfigurationFromJson.getScmRevision());
    Assert.assertEquals(message, buildExecutionConfiguration.getScmTag(), buildExecutionConfigurationFromJson.getScmTag());
    Assert.assertEquals(message, buildExecutionConfiguration.getOriginRepoURL(), buildExecutionConfigurationFromJson.getOriginRepoURL());
    Assert.assertEquals(message, buildExecutionConfiguration.isPreBuildSyncEnabled(), buildExecutionConfigurationFromJson.isPreBuildSyncEnabled());
    Assert.assertEquals(message, buildExecutionConfiguration.getUserId(), buildExecutionConfigurationFromJson.getUserId());
}
Also used : BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildExecutionConfigurationRest(org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest) Test(org.junit.Test)

Example 5 with BuildExecutionConfigurationRest

use of org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest in project pnc by project-ncl.

the class ComponentBuildParametersSerialization method shouldSerializeParameters.

@Test
public void shouldSerializeParameters() throws JsonProcessingException {
    BuildExecutionConfiguration buildExecutionConfiguration = BuildExecutionConfigurationMock.mock();
    BuildExecutionConfigurationRest buildExecutionConfigurationRest = new BuildExecutionConfigurationRest(buildExecutionConfiguration);
    ComponentBuildParameters processParameters = new ComponentBuildParameters("http://pncBaseUrl", "http://aproxBaseUrl", "http://repourBaseUrl", "http://daBaseUrl", false, true, buildExecutionConfigurationRest);
    String string = MAPPER.writeValueAsString(processParameters);
    log.debug("Serialized: {}", string);
    Assert.assertTrue(string.contains(BuildExecutionConfigurationMock.DEFAULT_SYSTEM_IMAGE_ID));
}
Also used : ComponentBuildParameters(org.jboss.pnc.bpm.model.ComponentBuildParameters) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildExecutionConfigurationRest(org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest) Test(org.junit.Test)

Aggregations

BuildExecutionConfigurationRest (org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest)5 BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)5 Test (org.junit.Test)3 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 ToString (lombok.ToString)1 NameValuePair (org.apache.http.NameValuePair)1 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1 BuildDriverResultRest (org.jboss.pnc.bpm.model.BuildDriverResultRest)1 BuildResultRest (org.jboss.pnc.bpm.model.BuildResultRest)1 ComponentBuildParameters (org.jboss.pnc.bpm.model.ComponentBuildParameters)1 RepositoryManagerResultRest (org.jboss.pnc.bpm.model.RepositoryManagerResultRest)1 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)1 BuildDriverResult (org.jboss.pnc.spi.builddriver.BuildDriverResult)1 CompletionStatus (org.jboss.pnc.spi.coordinator.CompletionStatus)1