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();
}
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());
}
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);
}
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);
}
}
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());
}
Aggregations