Search in sources :

Example 1 with Request

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);
}
Also used : BuildImportRequest(org.jboss.pnc.api.causeway.dto.push.BuildImportRequest) Request(org.jboss.pnc.api.dto.Request) BuildImportRequest(org.jboss.pnc.api.causeway.dto.push.BuildImportRequest) Dependency(org.jboss.pnc.api.causeway.dto.push.Dependency) Artifact(org.jboss.pnc.model.Artifact) BuiltArtifact(org.jboss.pnc.api.causeway.dto.push.BuiltArtifact) MavenBuiltArtifact(org.jboss.pnc.api.causeway.dto.push.MavenBuiltArtifact) NpmBuiltArtifact(org.jboss.pnc.api.causeway.dto.push.NpmBuiltArtifact) BuiltArtifact(org.jboss.pnc.api.causeway.dto.push.BuiltArtifact) MavenBuiltArtifact(org.jboss.pnc.api.causeway.dto.push.MavenBuiltArtifact) NpmBuiltArtifact(org.jboss.pnc.api.causeway.dto.push.NpmBuiltArtifact) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildEnvironment(org.jboss.pnc.model.BuildEnvironment) Build(org.jboss.pnc.api.causeway.dto.push.Build) MavenBuild(org.jboss.pnc.api.causeway.dto.push.MavenBuild) NpmBuild(org.jboss.pnc.api.causeway.dto.push.NpmBuild) BuildType(org.jboss.pnc.enums.BuildType) BuildRoot(org.jboss.pnc.api.causeway.dto.push.BuildRoot)

Example 2 with Request

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);
}
Also used : BuildAgentClient(org.jboss.pnc.buildagent.client.BuildAgentClient) GlobalModuleGroup(org.jboss.pnc.common.json.GlobalModuleGroup) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) StringUtils(org.jboss.pnc.common.util.StringUtils) Inject(javax.inject.Inject) BuildAgentSocketClient(org.jboss.pnc.buildagent.client.BuildAgentSocketClient) PreDestroy(javax.annotation.PreDestroy) RetryConfig(org.jboss.pnc.buildagent.api.httpinvoke.RetryConfig) Map(java.util.Map) BuildAgentHttpClient(org.jboss.pnc.buildagent.client.BuildAgentHttpClient) SocketClientConfiguration(org.jboss.pnc.buildagent.client.SocketClientConfiguration) HttpClientConfiguration(org.jboss.pnc.buildagent.client.HttpClientConfiguration) Logger(org.slf4j.Logger) TaskStatusUpdateEvent(org.jboss.pnc.buildagent.api.TaskStatusUpdateEvent) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) List(java.util.List) BuildAgentClientException(org.jboss.pnc.buildagent.client.BuildAgentClientException) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) Request(org.jboss.pnc.api.dto.Request) TermdBuildDriverModuleConfig(org.jboss.pnc.common.json.moduleconfig.TermdBuildDriverModuleConfig) ApplicationScoped(javax.enterprise.context.ApplicationScoped) HttpClient(org.jboss.pnc.buildagent.common.http.HttpClient) ResponseMode(org.jboss.pnc.buildagent.api.ResponseMode) MalformedURLException(java.net.MalformedURLException) BuildAgentHttpClient(org.jboss.pnc.buildagent.client.BuildAgentHttpClient) Request(org.jboss.pnc.api.dto.Request) BuildAgentClientException(org.jboss.pnc.buildagent.client.BuildAgentClientException) URISyntaxException(java.net.URISyntaxException) HttpClientConfiguration(org.jboss.pnc.buildagent.client.HttpClientConfiguration) URL(java.net.URL)

Example 3 with Request

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());
}
Also used : Arquillian(org.jboss.arquillian.junit.Arquillian) Credentials(org.jboss.pnc.integration.setup.Credentials) URISyntaxException(java.net.URISyntaxException) RunWith(org.junit.runner.RunWith) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) BuildExecutorMock(org.jboss.pnc.mock.executor.BuildExecutorMock) URI(java.net.URI) Deployments(org.jboss.pnc.integration.setup.Deployments) TaskStatusUpdateEvent(org.jboss.pnc.buildagent.api.TaskStatusUpdateEvent) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) IOException(java.io.IOException) BlockingQueue(java.util.concurrent.BlockingQueue) BuildExecutionSessionMock(org.jboss.pnc.mock.executor.BuildExecutionSessionMock) UUID(java.util.UUID) BuildExecutor(org.jboss.pnc.spi.executor.BuildExecutor) Category(org.junit.experimental.categories.Category) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) List(java.util.List) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Md5(org.jboss.pnc.common.security.Md5) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Headers(io.undertow.util.Headers) Request(org.jboss.pnc.api.dto.Request) Status(org.jboss.pnc.buildagent.api.Status) EXECUTOR_JAR(org.jboss.pnc.integration.setup.Deployments.EXECUTOR_JAR) HttpClient(org.jboss.pnc.buildagent.common.http.HttpClient) Assert(org.junit.Assert) BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) BuildExecutorMock(org.jboss.pnc.mock.executor.BuildExecutorMock) ArrayList(java.util.ArrayList) Request(org.jboss.pnc.api.dto.Request) TaskStatusUpdateEvent(org.jboss.pnc.buildagent.api.TaskStatusUpdateEvent) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) HttpClient(org.jboss.pnc.buildagent.common.http.HttpClient) Credentials(org.jboss.pnc.integration.setup.Credentials) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 4 with Request

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;
}
Also used : AnalyzeDeliverablesTask(org.jboss.pnc.bpm.task.AnalyzeDeliverablesTask) ArrayList(java.util.ArrayList) AnalyzeDeliverablesBpmRequest(org.jboss.pnc.bpm.model.AnalyzeDeliverablesBpmRequest) LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) Request(org.jboss.pnc.api.dto.Request) AnalyzeDeliverablesBpmRequest(org.jboss.pnc.bpm.model.AnalyzeDeliverablesBpmRequest)

Example 5 with Request

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);
}
Also used : ArrayList(java.util.ArrayList) Request(org.jboss.pnc.api.dto.Request) URI(java.net.URI)

Aggregations

Request (org.jboss.pnc.api.dto.Request)6 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 List (java.util.List)2 TimeoutException (java.util.concurrent.TimeoutException)2 Consumer (java.util.function.Consumer)2 Inject (javax.inject.Inject)2 AnalyzeDeliverablesBpmRequest (org.jboss.pnc.bpm.model.AnalyzeDeliverablesBpmRequest)2 AnalyzeDeliverablesTask (org.jboss.pnc.bpm.task.AnalyzeDeliverablesTask)2 TaskStatusUpdateEvent (org.jboss.pnc.buildagent.api.TaskStatusUpdateEvent)2 HttpClient (org.jboss.pnc.buildagent.common.http.HttpClient)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 LoggedRequest (com.github.tomakehurst.wiremock.verification.LoggedRequest)1 Headers (io.undertow.util.Headers)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Map (java.util.Map)1