Search in sources :

Example 11 with BuildExecutionConfiguration

use of org.jboss.pnc.spi.executor.BuildExecutionConfiguration in project pnc by project-ncl.

the class BuildTaskEndpointTest method shouldTriggerBuildExecution.

@Test
public void shouldTriggerBuildExecution() throws RemoteResourceException {
    HttpPost request = new HttpPost(url + BASE_REST_PATH + "/build-tasks/execute-build");
    request.addHeader(Credentials.USER.createAuthHeader(BasicHeader::new));
    BuildExecutionConfiguration buildExecutionConfig = BuildExecutionConfiguration.build("1", "test-content-id", "1", "mvn clean install", "12", "jboss-modules", "scm-url", "f18de64523d5054395d82e24d4e28473a05a3880", "1.0.0.redhat-1", "origin-scm-url", false, "dummy-docker-image-id", "dummy.repo.url/repo", SystemImageType.DOCKER_IMAGE, BuildType.MVN, false, null, new HashMap<>(), false, null, false, "-DdependencySource=REST -DrepoRemovalBackup=repositories-backup.xml -DversionSuffixStrip= -DreportNonAligned=true", AlignmentPreference.PREFER_PERSISTENT);
    BuildExecutionConfigurationRest buildExecutionConfigurationRest = new BuildExecutionConfigurationRest(buildExecutionConfig);
    List<NameValuePair> requestParameters = new ArrayList<>();
    requestParameters.add(new BasicNameValuePair("buildExecutionConfiguration", buildExecutionConfigurationRest.toString()));
    try {
        request.setEntity(new UrlEncodedFormEntity(requestParameters));
    } catch (UnsupportedEncodingException e) {
        log.error("Cannot prepare request.", e);
        Assert.fail("Cannot prepare request." + e.getMessage());
    }
    log.info("Executing request {} with parameters: {}", request.getRequestLine(), requestParameters);
    int statusCode = -1;
    try (CloseableHttpClient httpClient = HttpUtils.getPermissiveHttpClient()) {
        try (CloseableHttpResponse response = httpClient.execute(request)) {
            statusCode = response.getStatusLine().getStatusCode();
            Assert.assertEquals("Received error response code. Response: " + printEntity(response), 200, statusCode);
        }
    } catch (IOException e) {
        Assertions.fail("Cannot invoke remote endpoint.", 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) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) IOException(java.io.IOException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BuildExecutionConfigurationRest(org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 12 with BuildExecutionConfiguration

use of org.jboss.pnc.spi.executor.BuildExecutionConfiguration in project pnc by project-ncl.

the class BuildExecutorTriggerer method getMdcMeta.

public Optional<BuildTaskContext> getMdcMeta(String buildExecutionConfigId, String userId) {
    BuildExecutionSession runningExecution = buildExecutor.getRunningExecution(buildExecutionConfigId);
    if (runningExecution != null) {
        BuildExecutionConfiguration buildExecutionConfiguration = runningExecution.getBuildExecutionConfiguration();
        boolean temporaryBuild = buildExecutionConfiguration.isTempBuild();
        return Optional.of(new BuildTaskContext(buildExecutionConfiguration.getBuildContentId(), userId, temporaryBuild, ExpiresDate.getTemporaryBuildExpireDate(systemConfig.getTemporaryBuildsLifeSpan(), temporaryBuild)));
    } else {
        return Optional.empty();
    }
}
Also used : BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) BuildTaskContext(org.jboss.pnc.common.logging.BuildTaskContext) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration)

Example 13 with BuildExecutionConfiguration

use of org.jboss.pnc.spi.executor.BuildExecutionConfiguration in project pnc by project-ncl.

the class DatastoreAdapterTest method shouldStoreRepourResult.

@Test
public void shouldStoreRepourResult() throws DatastoreException {
    // given
    DatastoreMock datastore = new DatastoreMock();
    DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastore);
    RepourResult repourResult = RepourResultMock.mock();
    // when
    BuildConfiguration buildConfiguration = BuildConfiguration.Builder.newBuilder().name("Configuration.").build();
    BuildConfigurationAudited buildConfigurationAudited = BuildConfigurationAudited.Builder.newBuilder().buildConfiguration(buildConfiguration).build();
    BuildTask buildTask = mockBuildTask();
    BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
    BuildResult buildResult = new BuildResult(CompletionStatus.SUCCESS, Optional.empty(), "", Optional.of(buildExecutionConfiguration), Optional.of(BuildDriverResultMock.mockResult(BuildStatus.SUCCESS)), Optional.of(RepositoryManagerResultMock.mockResult()), Optional.of(EnvironmentDriverResultMock.mock()), Optional.of(repourResult));
    datastoreAdapter.storeResult(buildTask, buildResult);
    // then
    List<BuildRecord> buildRecords = datastore.getBuildRecords();
    Assert.assertEquals(1, buildRecords.size());
    BuildRecord buildRecord = buildRecords.get(0);
    Assert.assertEquals(buildRecord.getStatus(), BuildStatus.SUCCESS);
    Assert.assertEquals(repourResult.getExecutionRootName(), buildRecord.getExecutionRootName());
    Assert.assertEquals(repourResult.getExecutionRootVersion(), buildRecord.getExecutionRootVersion());
    Assert.assertEquals(repourResult.getLog(), buildRecord.getRepourLog());
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildResult(org.jboss.pnc.spi.BuildResult) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) RepourResult(org.jboss.pnc.spi.repour.RepourResult) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 14 with BuildExecutionConfiguration

use of org.jboss.pnc.spi.executor.BuildExecutionConfiguration in project pnc by project-ncl.

the class DefaultBuildExecutor method setUpEnvironment.

private CompletableFuture<Void> setUpEnvironment(DefaultBuildExecutionSession buildExecutionSession, RepositorySession repositorySession, DebugData debugData) {
    if (buildExecutionSession.isCanceled()) {
        return null;
    }
    ProcessStageUtils.logProcessStageBegin(BuildExecutionStatus.BUILD_ENV_SETTING_UP.toString(), "Setting up build environment ...");
    buildExecutionSession.setStatus(BuildExecutionStatus.BUILD_ENV_SETTING_UP);
    BuildExecutionConfiguration buildExecutionConfiguration = buildExecutionSession.getBuildExecutionConfiguration();
    try {
        EnvironmentDriver envDriver = environmentDriverFactory.getDriver(buildExecutionConfiguration.getSystemImageType());
        StartedEnvironment startedEnv = envDriver.startEnvironment(buildExecutionConfiguration.getSystemImageId(), buildExecutionConfiguration.getSystemImageRepositoryUrl(), buildExecutionConfiguration.getSystemImageType(), repositorySession, debugData, buildExecutionSession.getAccessToken(), buildExecutionConfiguration.isTempBuild(), buildExecutionConfiguration.getGenericParameters());
        buildExecutionSession.setCancelHook(startedEnv::cancel);
        return waitForEnvironmentInitialization(buildExecutionSession, startedEnv);
    } catch (Throwable e) {
        throw new BuildProcessException(e);
    }
}
Also used : BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) EnvironmentDriver(org.jboss.pnc.spi.environment.EnvironmentDriver) StartedEnvironment(org.jboss.pnc.spi.environment.StartedEnvironment) BuildProcessException(org.jboss.pnc.executor.exceptions.BuildProcessException)

Example 15 with BuildExecutionConfiguration

use of org.jboss.pnc.spi.executor.BuildExecutionConfiguration in project pnc by project-ncl.

the class BuildResultMock method mock.

public static BuildResult mock(BuildStatus status) {
    BuildExecutionConfiguration buildExecutionConfig = BuildExecutionConfigurationMock.mockConfig();
    BuildDriverResult buildDriverResult = BuildDriverResultMock.mockResult(status);
    RepositoryManagerResult repositoryManagerResult = RepositoryManagerResultMock.mockResult();
    ExecutorException exception = buildException();
    CompletionStatus completionStatus;
    if (status.completedSuccessfully()) {
        completionStatus = CompletionStatus.SUCCESS;
    } else {
        completionStatus = CompletionStatus.FAILED;
    }
    return new BuildResult(completionStatus, Optional.of(new ProcessException("Test Exception.")), "", Optional.ofNullable(buildExecutionConfig), Optional.ofNullable(buildDriverResult), Optional.ofNullable(repositoryManagerResult), Optional.of(EnvironmentDriverResultMock.mock()), Optional.of(RepourResultMock.mock()));
}
Also used : BuildResult(org.jboss.pnc.spi.BuildResult) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus)

Aggregations

BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)24 Consumer (java.util.function.Consumer)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Test (org.junit.Test)10 BuildExecutionSession (org.jboss.pnc.spi.executor.BuildExecutionSession)9 SystemConfig (org.jboss.pnc.common.json.moduleconfig.SystemConfig)7 BuildResult (org.jboss.pnc.spi.BuildResult)7 ExecutorException (org.jboss.pnc.spi.executor.exceptions.ExecutorException)7 RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)7 ConfigurationParseException (org.jboss.pnc.common.json.ConfigurationParseException)6 BuildDriverResult (org.jboss.pnc.spi.builddriver.BuildDriverResult)6 CompletedBuild (org.jboss.pnc.spi.builddriver.CompletedBuild)6 RunningBuild (org.jboss.pnc.spi.builddriver.RunningBuild)6 RunningEnvironment (org.jboss.pnc.spi.environment.RunningEnvironment)6 IOException (java.io.IOException)5 BuildExecutionStatusChangedEvent (org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)5 Inject (javax.inject.Inject)4 TaskStatusUpdateEvent (org.jboss.pnc.buildagent.api.TaskStatusUpdateEvent)4 BuildExecutionStatus (org.jboss.pnc.enums.BuildExecutionStatus)4