Search in sources :

Example 1 with BuildResultRest

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

the class BuildResultRestTest method shouldGetLimitedToStringWithNulls.

@Test
public void shouldGetLimitedToStringWithNulls() {
    BuildResultRest buildResultRest = new BuildResultRest();
    buildResultRest.toString();
}
Also used : BuildResultRest(org.jboss.pnc.bpm.model.BuildResultRest) Test(org.junit.Test)

Example 2 with BuildResultRest

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

the class BuildResultSerializationTest method serializeAndDeserializeBuildResult.

@Test
public void serializeAndDeserializeBuildResult() throws IOException, BuildDriverException {
    BuildResult buildResult = BuildResultMock.mock(BuildStatus.SUCCESS);
    BuildResultRest buildResultRest = buildResultMapper.toDTO(buildResult);
    String buildResultJson = buildResultRest.toFullLogString();
    log.debug("BuildResultJson : {}", buildResultJson);
    BuildResultRest buildResultRestFromJson = JsonOutputConverterMapper.readValue(buildResultJson, BuildResultRest.class);
    BuildResult buildResultFromJson = buildResultMapper.toEntity(buildResultRestFromJson);
    String message = "Deserialized object does not match the original.";
    Assert.assertEquals(message, buildResult.hasFailed(), buildResultFromJson.hasFailed());
    Assert.assertEquals(message, buildResult.getCompletionStatus(), buildResultFromJson.getCompletionStatus());
    Assert.assertEquals(message, buildResult.getProcessException().get().getMessage(), buildResultFromJson.getProcessException().get().getMessage());
    Assert.assertEquals(message, buildResult.getBuildExecutionConfiguration().get().getId(), buildResultFromJson.getBuildExecutionConfiguration().get().getId());
    Assert.assertEquals(message, buildResult.getRepositoryManagerResult().get().getBuildContentId(), buildResultFromJson.getRepositoryManagerResult().get().getBuildContentId());
    Assert.assertEquals(message, buildResult.getRepositoryManagerResult().get().getBuiltArtifacts().get(0).getId(), buildResultFromJson.getRepositoryManagerResult().get().getBuiltArtifacts().get(0).getId());
    Assert.assertEquals(message, buildResult.getBuildDriverResult().get().getBuildLog(), buildResultFromJson.getBuildDriverResult().get().getBuildLog());
    Assert.assertEquals(message, buildResult.getBuildDriverResult().get().getBuildStatus(), buildResultFromJson.getBuildDriverResult().get().getBuildStatus());
    Assert.assertEquals(message, buildResult.getRepourResult().get().getCompletionStatus(), buildResultFromJson.getRepourResult().get().getCompletionStatus());
    Assert.assertEquals(message, buildResult.getRepourResult().get().getExecutionRootName(), buildResultFromJson.getRepourResult().get().getExecutionRootName());
    Assert.assertEquals(message, buildResult.getEnvironmentDriverResult().get().getCompletionStatus(), buildResultFromJson.getEnvironmentDriverResult().get().getCompletionStatus());
    Assert.assertEquals(message, buildResult.getEnvironmentDriverResult().get().getSshCredentials().get().getCommand(), buildResultFromJson.getEnvironmentDriverResult().get().getSshCredentials().get().getCommand());
}
Also used : BuildResultRest(org.jboss.pnc.bpm.model.BuildResultRest) BuildResult(org.jboss.pnc.spi.BuildResult) Test(org.junit.Test)

Example 3 with BuildResultRest

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

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

the class BpmNotifier method sendBuildExecutionCompleted.

public void sendBuildExecutionCompleted(String uri, BuildResult buildResult, String accessToken) {
    log.debug("Preparing to send build result to BPM {}.", buildResult);
    BuildResultRest buildResultRest = null;
    String errMessage = "";
    try {
        buildResultRest = mapper.toDTO(buildResult);
        if (log.isTraceEnabled()) {
            log.trace("Sending build result to BPM {}.", buildResultRest.toFullLogString());
        } else {
            log.debug("Sending build result to BPM {}.", buildResultRest);
        }
    } catch (Throwable e) {
        log.error("Cannot construct rest result.", e);
        errMessage = "Cannot construct rest result: " + e.getMessage();
    }
    boolean isNewBpmProcess = false;
    if (buildResult.getBuildExecutionConfiguration().isPresent()) {
        BuildExecutionConfiguration buildExecutionConfiguration = buildResult.getBuildExecutionConfiguration().get();
        isNewBpmProcess = ConnectorSelector.useNewProcessForBuild(buildExecutionConfiguration.getGenericParameters(), bpmConfig.isNewBpmForced());
    } else {
        log.error("Missing BuildExecutionConfiguration!");
    }
    HttpPost request = new HttpPost(uri);
    String jsonEntity = buildResultRest != null ? buildResultRest.toFullLogString() : "{\"error\", \"" + errMessage + "\"}";
    if (isNewBpmProcess) {
        StringEntity entity = new StringEntity(jsonEntity, StandardCharsets.UTF_8);
        if (entity != null) {
            request.setEntity(entity);
            log.debug("Json response entity set to the post request for uri: " + uri);
        } else {
            log.error("Missing json response entity to post to: " + uri);
        }
        configureRequestNewBPM(accessToken, request);
    } else {
        List<NameValuePair> parameters = new ArrayList<>();
        parameters.add(new BasicNameValuePair("event", jsonEntity));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters, StandardCharsets.UTF_8);
        if (entity != null) {
            request.setEntity(entity);
            log.debug("Urlencoded response entity set to the post request for uri: " + uri);
        } else {
            log.error("Missing urlencoded response entity to post to: " + uri);
        }
        request.addHeader("Authorization", getAuthHeader());
    }
    // get id for logging
    String buildExecutionConfigurationId;
    if (buildResult.getBuildExecutionConfiguration().isPresent()) {
        BuildExecutionConfiguration buildExecutionConfiguration = buildResult.getBuildExecutionConfiguration().get();
        buildExecutionConfigurationId = buildExecutionConfiguration.getId() + "";
    } else {
        buildExecutionConfigurationId = "NO BuildExecutionConfiguration.";
    }
    log.info("Sending buildResult of buildExecutionConfiguration.id " + buildExecutionConfigurationId + ": " + request.getRequestLine());
    try (CloseableHttpClient httpClient = HttpUtils.getPermissiveHttpClient()) {
        try (CloseableHttpResponse response = httpClient.execute(request)) {
            log.info(response.getStatusLine().toString());
            try {
                if (response.getStatusLine().getStatusCode() != 200) {
                    InputStream content = response.getEntity().getContent();
                    StringWriter writer = new StringWriter();
                    IOUtils.copy(content, writer);
                    log.debug("Received message: " + writer.toString());
                }
            } catch (Exception e) {
                log.warn("Cannot write http response message to log.", e);
            }
        }
    } catch (IOException e) {
        log.error("Error occurred executing the callback.", 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) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) IOException(java.io.IOException) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) IOException(java.io.IOException) BuildResultRest(org.jboss.pnc.bpm.model.BuildResultRest) StringEntity(org.apache.http.entity.StringEntity) StringWriter(java.io.StringWriter) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 5 with BuildResultRest

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

the class CancelledBuildByBpmTest method buildSingleProjectTestCase.

@Test(timeout = 5_000)
public void buildSingleProjectTestCase() throws Exception {
    // given
    DatastoreMock datastoreMock = new DatastoreMock();
    TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastoreMock);
    DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastoreMock);
    SystemConfig systemConfig = createConfiguration();
    BuildQueue queue = new BuildQueue(systemConfig);
    BlockingQueue<BuildStatusChangedEvent> receivedStatuses = new ArrayBlockingQueue<>(5);
    Consumer<BuildStatusChangedEvent> onStatusUpdate = receivedStatuses::add;
    EventListener buildStatusChangedEventNotifier = new EventListener(onStatusUpdate);
    BlockingQueue<BpmTask> task = new ArrayBlockingQueue<>(5);
    Consumer<BpmTask> onBpmTaskCreated = task::add;
    BuildSchedulerFactory buildSchedulerFactory = new BuildSchedulerFactory(onBpmTaskCreated);
    BuildCoordinator coordinator = new DefaultBuildCoordinator(datastoreAdapter, buildStatusChangedEventNotifier, null, buildSchedulerFactory, queue, systemConfig, groupBuildMapper, buildMapper);
    coordinator.start();
    queue.initSemaphore();
    coordinator.build(configurationBuilder.buildConfigurationToCancel(1, "c1-bpm"), MockUser.newTestUser(1), new BuildOptions());
    waitForStatus(receivedStatuses, BuildStatus.BUILDING);
    BpmTask bpmTask = task.poll(1, TimeUnit.SECONDS);
    BuildResultRest result = new BuildResultRest();
    result.setCompletionStatus(CompletionStatus.CANCELLED);
    // when
    bpmTask.notify(BUILD_COMPLETE, result);
    waitForStatus(receivedStatuses, BuildStatus.CANCELLED);
    // expect
    List<BuildRecord> buildRecords = datastoreMock.getBuildRecords();
    Assert.assertEquals("Too many build records in datastore: " + buildRecords, 1, buildRecords.size());
    BuildRecord buildRecord = buildRecords.get(0);
    Assert.assertNotNull(buildRecord.getSubmitTime());
    Assert.assertNotNull(buildRecord.getStartTime());
    Assert.assertNotNull(buildRecord.getEndTime());
    Assert.assertEquals(BuildStatus.CANCELLED, buildRecord.getStatus());
}
Also used : BuildQueue(org.jboss.pnc.coordinator.builder.BuildQueue) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) DefaultBuildCoordinator(org.jboss.pnc.coordinator.builder.DefaultBuildCoordinator) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) BpmTask(org.jboss.pnc.bpm.BpmTask) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildResultRest(org.jboss.pnc.bpm.model.BuildResultRest) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) BuildOptions(org.jboss.pnc.spi.BuildOptions) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) DefaultBuildCoordinator(org.jboss.pnc.coordinator.builder.DefaultBuildCoordinator) Test(org.junit.Test)

Aggregations

BuildResultRest (org.jboss.pnc.bpm.model.BuildResultRest)7 Test (org.junit.Test)5 IOException (java.io.IOException)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpPost (org.apache.http.client.methods.HttpPost)2 StringEntity (org.apache.http.entity.StringEntity)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 BuildDriverResultRest (org.jboss.pnc.bpm.model.BuildDriverResultRest)2 BuildDriverResult (org.jboss.pnc.spi.builddriver.BuildDriverResult)2 EnvironmentDriverResult (org.jboss.pnc.spi.environment.EnvironmentDriverResult)2 BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)2 RepourResult (org.jboss.pnc.spi.repour.RepourResult)2 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 NameValuePair (org.apache.http.NameValuePair)1 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1 BpmTask (org.jboss.pnc.bpm.BpmTask)1