Search in sources :

Example 26 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl in project che by eclipse.

the class CheEnvironmentEngineTest method startEnv.

private List<Instance> startEnv() throws Exception {
    EnvironmentImpl env = createEnv();
    CheServicesEnvironmentImpl cheServicesEnv = createCheServicesEnv();
    return startEnv(env, cheServicesEnv);
}
Also used : CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)

Example 27 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldBeAbleToStartEnvironmentWhenRecoverFailed.

@Test
public void shouldBeAbleToStartEnvironmentWhenRecoverFailed() throws Exception {
    // given
    String machineImage = "che/ubuntu_jdk";
    when(snapshotDao.getSnapshot(anyString(), anyString(), anyString())).thenThrow(new NotFoundException("Snapshot not found"));
    EnvironmentImpl env = createEnv();
    String envName = "env-1";
    String workspaceId = "wsId";
    List<Instance> expectedMachines = new ArrayList<>();
    when(machineProvider.startService(anyString(), eq(workspaceId), eq(envName), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenAnswer(invocationOnMock -> {
        Object[] arguments = invocationOnMock.getArguments();
        String machineName = (String) arguments[3];
        boolean isDev = (boolean) arguments[4];
        CheServiceImpl service = (CheServiceImpl) arguments[6];
        Machine machine = createMachine(workspaceId, envName, service, machineName, isDev);
        NoOpMachineInstance instance = spy(new NoOpMachineInstance(machine));
        expectedMachines.add(instance);
        return instance;
    });
    CheServicesEnvironmentImpl servicesEnvironment = createCheServicesEnv();
    for (CheServiceImpl service : servicesEnvironment.getServices().values()) {
        service.setImage(machineImage);
    }
    when(environmentParser.parse(env)).thenReturn(servicesEnvironment);
    // when
    List<Instance> machines = engine.start(workspaceId, envName, env, true, messageConsumer);
    // then
    assertEquals(machines, expectedMachines);
    ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
    verify(machineProvider).startService(anyString(), anyString(), anyString(), anyString(), eq(false), anyString(), captor.capture(), any(LineConsumer.class));
    CheServiceImpl actualService = captor.getValue();
    assertEquals(actualService.getImage(), machineImage);
}
Also used : Instance(org.eclipse.che.api.machine.server.spi.Instance) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) ArrayList(java.util.ArrayList) NotFoundException(org.eclipse.che.api.core.NotFoundException) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Matchers.anyString(org.mockito.Matchers.anyString) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Machine(org.eclipse.che.api.core.model.machine.Machine) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) Test(org.testng.annotations.Test)

Example 28 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldApplyAgentsOnEnvironmentStart.

@Test
public void shouldApplyAgentsOnEnvironmentStart() throws Exception {
    EnvironmentImpl env = createEnv();
    String machineName = "extraMachine";
    //prepare CheServicesEnvironmentImpl which should return compose parser
    CheServicesEnvironmentImpl cheServicesEnvironment = createCheServicesEnvByName(machineName);
    cheServicesEnvironment.getServices().get(machineName).withImage("codenvy/ubuntu_jdk8");
    // when
    startEnv(env, cheServicesEnvironment);
    // then
    verify(machineProvider).startService(anyString(), anyString(), anyString(), eq(machineName), eq(false), anyString(), any(CheServiceImpl.class), any(LineConsumer.class));
    verify(infrastructureProvisioner).provision(eq(env), any(CheServicesEnvironmentImpl.class));
    verifyNoMoreInteractions(infrastructureProvisioner);
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 29 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl in project che by eclipse.

the class EnvironmentParserTest method getEntryForDockerimageEnv.

private static List<Object> getEntryForDockerimageEnv(Map<String, ServerConf2Impl> servers, List<String> expectedExpose, Map<String, String> expectedLabels) {
    EnvironmentImpl environmentConfig = createDockerimageEnvConfig();
    ExtendedMachineImpl extendedMachine = getMachine(environmentConfig);
    extendedMachine.setServers(servers);
    CheServicesEnvironmentImpl parsedCheEnv = new CheServicesEnvironmentImpl();
    parsedCheEnv.getServices().put(DEFAULT_MACHINE_NAME, new CheServiceImpl().withImage(DEFAULT_DOCKER_IMAGE));
    return asList(environmentConfig, createExpectedEnvFromImage(expectedExpose, expectedLabels), parsedCheEnv);
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)

Example 30 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl in project che by eclipse.

the class EnvironmentParserTest method getEntryForDockerfileEnv.

private static List<Object> getEntryForDockerfileEnv(Map<String, ServerConf2Impl> servers, List<String> expectedExpose, Map<String, String> expectedLabels) {
    EnvironmentImpl environmentConfig = createDockerfileEnvConfig();
    ExtendedMachineImpl extendedMachine = getMachine(environmentConfig);
    extendedMachine.setServers(servers);
    CheServicesEnvironmentImpl parsedCheEnv = new CheServicesEnvironmentImpl();
    CheServiceBuildContextImpl buildContext = new CheServiceBuildContextImpl().withDockerfileContent(DEFAULT_DOCKERFILE);
    parsedCheEnv.getServices().put(DEFAULT_MACHINE_NAME, new CheServiceImpl().withBuild(buildContext));
    return asList(environmentConfig, createExpectedEnvFromDockerfile(expectedExpose, expectedLabels), parsedCheEnv);
}
Also used : CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)

Aggregations

CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)54 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)44 Test (org.testng.annotations.Test)38 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)15 CheServiceBuildContextImpl (org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl)13 Matchers.anyString (org.mockito.Matchers.anyString)8 HashMap (java.util.HashMap)7 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)7 Environment (org.eclipse.che.api.core.model.workspace.Environment)6 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)6 Map (java.util.Map)3 EnvironmentRecipe (org.eclipse.che.api.core.model.workspace.EnvironmentRecipe)3 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)3 EnvironmentRecipeImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl)3 Joiner (com.google.common.base.Joiner)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ServerException (org.eclipse.che.api.core.ServerException)2