use of org.jboss.pnc.buildagent.common.http.HttpClient 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.buildagent.common.http.HttpClient 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.buildagent.common.http.HttpClient in project pnc by project-ncl.
the class DefaultClientFactory method init.
@PostConstruct
public void init() throws IOException {
httpClient = new HttpClient();
logger.info("DefaultClientFactory initialized.");
}
Aggregations