Search in sources :

Example 36 with CheServicesEnvironmentImpl

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

the class CheEnvironmentValidatorTest method shouldNotFailIfExtraMachineDoesNotHaveExtendedMachineEntry.

@Test
public void shouldNotFailIfExtraMachineDoesNotHaveExtendedMachineEntry() throws Exception {
    // given
    CheServicesEnvironmentImpl cheServicesEnv = createServicesEnv();
    cheServicesEnv.getServices().put("extra", createCheService("_extra", 1000000L, null, null, null));
    when(environmentParser.parse(any(Environment.class))).thenReturn(cheServicesEnv);
    // when
    environmentValidator.validate("env", environment);
}
Also used : CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Environment(org.eclipse.che.api.core.model.workspace.Environment) Test(org.testng.annotations.Test)

Example 37 with CheServicesEnvironmentImpl

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

the class EnvironmentParserTest method createCheServicesEnv.

private static CheServicesEnvironmentImpl createCheServicesEnv(Map<String, String> labels, List<String> expose) {
    CheServiceImpl cheService = new CheServiceImpl().withLabels(labels).withExpose(expose).withImage(DEFAULT_DOCKER_IMAGE);
    Map<String, CheServiceImpl> cheComposeEnvs = new HashMap<>();
    cheComposeEnvs.put(DEFAULT_MACHINE_NAME, cheService);
    return new CheServicesEnvironmentImpl().withServices(cheComposeEnvs);
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) HashMap(java.util.HashMap) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)

Example 38 with CheServicesEnvironmentImpl

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

the class EnvironmentParserTest method shouldAddPortsAndLabelsFromExtendedMachineServers.

@Test(dataProvider = "environmentWithServersProvider")
public void shouldAddPortsAndLabelsFromExtendedMachineServers(EnvironmentImpl environment, CheServicesEnvironmentImpl expectedEnv, CheServicesEnvironmentImpl parsedCheEnv) throws Exception {
    when(envParser.parse(any(Environment.class))).thenReturn(parsedCheEnv);
    // when
    CheServicesEnvironmentImpl cheServicesEnvironment = parser.parse(environment);
    // then
    // prevent failures because of reordered entries of expose field
    assertEquals(cheServicesEnvironment.getServices().size(), expectedEnv.getServices().size());
    cheServicesEnvironment.getServices().entrySet().forEach(entry -> {
        CheServiceImpl actual = entry.getValue();
        CheServiceImpl expected = expectedEnv.getServices().get(entry.getKey());
        assertNotNull(expected);
        assertEqualsNoOrder(actual.getExpose().toArray(), expected.getExpose().toArray(), format("Expose fields differ. Actual:%s. Expected:%s", actual.getExpose(), expected.getExpose()));
        expected.setExpose(null);
        actual.setExpose(null);
    });
    assertEquals(cheServicesEnvironment, expectedEnv);
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) Environment(org.eclipse.che.api.core.model.workspace.Environment) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

Example 39 with CheServicesEnvironmentImpl

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

the class EnvironmentParserTest method shouldOverrideMemoryLimitFromExtendedMachineInComposeEnv.

@Test
public void shouldOverrideMemoryLimitFromExtendedMachineInComposeEnv() throws Exception {
    // given
    HashMap<String, ExtendedMachineImpl> machines = new HashMap<>();
    machines.put("machine1", new ExtendedMachineImpl(emptyList(), emptyMap(), singletonMap("memoryLimitBytes", "101010")));
    machines.put("machine2", new ExtendedMachineImpl(emptyList(), emptyMap(), emptyMap()));
    EnvironmentImpl environment = new EnvironmentImpl(new EnvironmentRecipeImpl("compose", "application/x-yaml", "content", null), machines);
    CheServicesEnvironmentImpl cheEnv = new CheServicesEnvironmentImpl();
    cheEnv.getServices().put("machine1", new CheServiceImpl());
    cheEnv.getServices().put("machine2", new CheServiceImpl());
    when(envParser.parse(environment)).thenReturn(cheEnv);
    // when
    CheServicesEnvironmentImpl cheServicesEnvironment = parser.parse(environment);
    // then
    assertEquals(cheServicesEnvironment, cheEnv);
    assertEquals(cheServicesEnvironment.getServices().get("machine1").getMemLimit().longValue(), 101010L);
    assertEquals(cheServicesEnvironment.getServices().get("machine2").getMemLimit(), null);
}
Also used : HashMap(java.util.HashMap) 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) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) Test(org.testng.annotations.Test)

Example 40 with CheServicesEnvironmentImpl

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

the class EnvironmentParserTest method getEntryForComposeEnv.

private static List<Object> getEntryForComposeEnv(Map<String, ServerConf2Impl> servers, List<String> composeExpose, Map<String, String> composeLabels, List<String> expectedExpose, Map<String, String> expectedLabels) {
    CheServicesEnvironmentImpl cheComposeEnv = createCheServicesEnv(new HashMap<>(composeLabels), new ArrayList<>(composeExpose));
    CheServicesEnvironmentImpl expectedEnv = createCheServicesEnv(expectedLabels, expectedExpose);
    EnvironmentImpl environmentConfig = createCompose1MachineEnvConfig();
    ExtendedMachineImpl extendedMachine = getMachine(environmentConfig);
    extendedMachine.setServers(new HashMap<>(servers));
    return asList(environmentConfig, expectedEnv, cheComposeEnv);
}
Also used : 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