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