use of org.jboss.pnc.api.dto.Request 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);
}
use of org.jboss.pnc.api.dto.Request in project pnc by project-ncl.
the class DefaultClientFactory method createHttpBuildAgentClient.
@Override
public BuildAgentClient createHttpBuildAgentClient(String terminalUrl, String executionId, Map<String, String> callbackHeaders, List<Request.Header> requestHeaders) throws BuildAgentClientException {
List<Request.Header> headers = callbackHeaders.entrySet().stream().map(e -> new Request.Header(e.getKey(), e.getValue())).collect(Collectors.toList());
HttpClientConfiguration configuration = null;
try {
URL callbackUrl = new URL(StringUtils.stripEndingSlash(pncBaseUrl) + "/build-execution/" + executionId + "/completed");
Request callback = new Request(Request.Method.POST, callbackUrl.toURI(), headers);
configuration = HttpClientConfiguration.newBuilder().termBaseUrl(terminalUrl).callback(callback).livenessResponseTimeout(30000L).retryConfig(retryConfig).requestHeaders(requestHeaders).build();
} catch (MalformedURLException | URISyntaxException e) {
new BuildAgentClientException("Invalid callback URL.", e);
}
return new BuildAgentHttpClient(httpClient, configuration);
}
use of org.jboss.pnc.api.dto.Request in project pnc by project-ncl.
the class BuildExecutionTest method shouldReceiveBuildResultViaHttpCallback.
@Test(timeout = 10000L)
public void shouldReceiveBuildResultViaHttpCallback() throws IOException, NoSuchAlgorithmException, URISyntaxException, InterruptedException, ExecutionException, TimeoutException {
// given
TaskStatusUpdateEvent.Builder updateEventBuilder = TaskStatusUpdateEvent.newBuilder();
updateEventBuilder.taskId(UUID.randomUUID().toString()).newStatus(Status.COMPLETED).outputChecksum(Md5.digest("black"));
Credentials user = Credentials.USER;
List<Request.Header> headers = new ArrayList<>();
headers.add(new Request.Header(Headers.CONTENT_TYPE_STRING, MediaType.APPLICATION_JSON));
user.createAuthHeader((k, v) -> {
headers.add(new Request.Header(k, v));
return null;
});
String data = objectMapper.writeValueAsString(updateEventBuilder.build());
BlockingQueue<TaskStatusUpdateEvent> events = new ArrayBlockingQueue<>(10);
Consumer<TaskStatusUpdateEvent> statusChangeConsumer = (e) -> {
events.add(e);
};
BuildExecutionSession session = createFakeExectionSession(statusChangeConsumer);
// when
String executionId = "11";
((BuildExecutorMock) buildExecutor).addRunningExecution(executionId, session);
HttpClient httpClient = new HttpClient();
Request request = new Request(Request.Method.POST, URI.create("http://localhost:8080/pnc-rest/v2/build-execution/" + executionId + "/completed"), headers);
CompletableFuture<HttpClient.Response> responseFuture = httpClient.invoke(request, data);
// then
// event received
TaskStatusUpdateEvent event = events.take();
Assert.assertEquals(Status.COMPLETED, event.getNewStatus());
Assert.assertEquals(200, responseFuture.get(5, TimeUnit.SECONDS).getCode());
}
use of org.jboss.pnc.api.dto.Request in project pnc by project-ncl.
the class RestConnectorRequestSerializationTest method mockAnalyzeDeliverablesTask.
private AnalyzeDeliverablesTask mockAnalyzeDeliverablesTask() {
String url1 = "http://hello.com";
String url2 = "http://world.com";
List<String> urls = new ArrayList<>();
urls.add(url1);
urls.add(url2);
String operationId = Sequence.nextBase32Id();
AnalyzeDeliverablesBpmRequest request = new AnalyzeDeliverablesBpmRequest(operationId, "id", urls);
List<Request.Header> headers = new ArrayList<>();
headers.add(new Request.Header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON));
Request callback = new Request(Request.Method.POST, URI.create("http://mock.com/"), headers);
AnalyzeDeliverablesTask task = new AnalyzeDeliverablesTask(request, callback);
return task;
}
use of org.jboss.pnc.api.dto.Request in project pnc by project-ncl.
the class OperationsManagerImpl method getOperationCallback.
@Override
public Request getOperationCallback(Base32LongID operationId) {
String accessToken = userService.currentUserToken();
List<Request.Header> headers = new ArrayList<>();
addCommonHeaders(headers, accessToken);
addMDCHeaders(headers);
String actualEndpoint = String.format(callbackUrlTemplate, globalConfig.getPncUrl(), operationId.getId());
URI callbackURI = URI.create(actualEndpoint);
return new Request(Request.Method.POST, callbackURI, headers);
}
Aggregations