use of org.jboss.pnc.spi.environment.StartedEnvironment in project pnc by project-ncl.
the class OpenshiftEnvironmentDriverRemoteTest method createAndDestroyEnvironment.
@Test
public void createAndDestroyEnvironment() throws EnvironmentDriverException, InterruptedException {
final Semaphore mutex = new Semaphore(0);
ObjectWrapper<Throwable> exceptionWrapper = new ObjectWrapper<>();
String dummyImageId = "abcd1234";
String dummyRepoUrl = "test.repo.url/repo";
// Create container
final StartedEnvironment startedEnv = environmentDriver.startEnvironment(dummyImageId, dummyRepoUrl, SystemImageType.DOCKER_IMAGE, DUMMY_REPOSITORY_CONFIGURATION, new DebugData(false), "put-access-token-here", false, Collections.emptyMap());
Consumer<RunningEnvironment> onEnvironmentStarted = (runningEnvironment) -> {
boolean containerDestroyed = false;
try {
assertThatContainerIsRunning(runningEnvironment);
// Destroy container
destroyEnvironment(runningEnvironment);
containerDestroyed = true;
assertThatContainerIsNotRunning(runningEnvironment);
mutex.release();
} catch (Throwable e) {
exceptionWrapper.set(e);
} finally {
if (!containerDestroyed) {
destroyEnvironmentWithReport(runningEnvironment);
}
}
mutex.release();
};
Consumer<Exception> onError = (e) -> {
try {
logger.info("Trying to destroy environment due to an error:", e);
startedEnv.destroyEnvironment();
mutex.release();
} catch (EnvironmentDriverException e1) {
logger.error("Environment LEAK! The running environment was not destroyed. ID: " + startedEnv.getId(), e1);
}
fail("Failed to init builder. " + e.getMessage());
};
startedEnv.monitorInitialization(onEnvironmentStarted, onError);
boolean completed = mutex.tryAcquire(TEST_EXECUTION_TIMEOUT, TimeUnit.SECONDS);
Throwable exception = exceptionWrapper.get();
if (exception != null) {
logger.error("", exception);
fail(exception.getMessage());
}
assertTrue("timeout reached, test has not complete.", completed);
}
use of org.jboss.pnc.spi.environment.StartedEnvironment 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);
}
}
Aggregations