Search in sources :

Example 1 with StartedEnvironment

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);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) SystemImageType(org.jboss.pnc.enums.SystemImageType) RepositoryType(org.jboss.pnc.enums.RepositoryType) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) EnvironmentDriver(org.jboss.pnc.spi.environment.EnvironmentDriver) OpenshiftEnvironmentDriverModuleConfig(org.jboss.pnc.common.json.moduleconfig.OpenshiftEnvironmentDriverModuleConfig) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) Semaphore(java.util.concurrent.Semaphore) MethodHandles(java.lang.invoke.MethodHandles) Assert.assertTrue(org.junit.Assert.assertTrue) DebugTest(org.jboss.pnc.test.category.DebugTest) Test(org.junit.Test) IOException(java.io.IOException) Category(org.junit.experimental.categories.Category) PollingMonitor(org.jboss.pnc.common.monitor.PollingMonitor) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) RepositoryConnectionInfo(org.jboss.pnc.spi.repositorymanager.model.RepositoryConnectionInfo) Mockito(org.mockito.Mockito) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment) StartedEnvironment(org.jboss.pnc.spi.environment.StartedEnvironment) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) DebugData(org.jboss.pnc.spi.builddriver.DebugData) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) Assert.assertFalse(org.junit.Assert.assertFalse) EnvironmentDriverException(org.jboss.pnc.spi.environment.exception.EnvironmentDriverException) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) Collections(java.util.Collections) DebugData(org.jboss.pnc.spi.builddriver.DebugData) Semaphore(java.util.concurrent.Semaphore) StartedEnvironment(org.jboss.pnc.spi.environment.StartedEnvironment) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) IOException(java.io.IOException) EnvironmentDriverException(org.jboss.pnc.spi.environment.exception.EnvironmentDriverException) EnvironmentDriverException(org.jboss.pnc.spi.environment.exception.EnvironmentDriverException) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) DebugTest(org.jboss.pnc.test.category.DebugTest) Test(org.junit.Test)

Example 2 with StartedEnvironment

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

Aggregations

EnvironmentDriver (org.jboss.pnc.spi.environment.EnvironmentDriver)2 StartedEnvironment (org.jboss.pnc.spi.environment.StartedEnvironment)2 IOException (java.io.IOException)1 MethodHandles (java.lang.invoke.MethodHandles)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Semaphore (java.util.concurrent.Semaphore)1 TimeUnit (java.util.concurrent.TimeUnit)1 Consumer (java.util.function.Consumer)1 OpenshiftEnvironmentDriverModuleConfig (org.jboss.pnc.common.json.moduleconfig.OpenshiftEnvironmentDriverModuleConfig)1 SystemConfig (org.jboss.pnc.common.json.moduleconfig.SystemConfig)1 PollingMonitor (org.jboss.pnc.common.monitor.PollingMonitor)1 ObjectWrapper (org.jboss.pnc.common.util.ObjectWrapper)1 RepositoryType (org.jboss.pnc.enums.RepositoryType)1 SystemImageType (org.jboss.pnc.enums.SystemImageType)1 BuildProcessException (org.jboss.pnc.executor.exceptions.BuildProcessException)1 DebugData (org.jboss.pnc.spi.builddriver.DebugData)1 RunningEnvironment (org.jboss.pnc.spi.environment.RunningEnvironment)1