Search in sources :

Example 6 with CheServicesEnvironmentImpl

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

the class ComposeEnvironmentParser method asCheEnvironment.

private CheServicesEnvironmentImpl asCheEnvironment(ComposeEnvironment composeEnvironment) {
    Map<String, CheServiceImpl> services = Maps.newHashMapWithExpectedSize(composeEnvironment.getServices().size());
    for (Map.Entry<String, ComposeServiceImpl> composeServiceEntry : composeEnvironment.getServices().entrySet()) {
        ComposeServiceImpl service = composeServiceEntry.getValue();
        CheServiceImpl cheService = new CheServiceImpl().withCommand(service.getCommand()).withContainerName(service.getContainerName()).withDependsOn(service.getDependsOn()).withEntrypoint(service.getEntrypoint()).withEnvironment(service.getEnvironment()).withExpose(service.getExpose()).withImage(service.getImage()).withLabels(service.getLabels()).withLinks(service.getLinks()).withMemLimit(service.getMemLimit()).withNetworks(service.getNetworks()).withPorts(service.getPorts()).withVolumes(service.getVolumes()).withVolumesFrom(service.getVolumesFrom());
        if (service.getBuild() != null) {
            cheService.setBuild(new CheServiceBuildContextImpl().withContext(service.getBuild().getContext()).withDockerfilePath(service.getBuild().getDockerfile()).withArgs(service.getBuild().getArgs()));
        }
        services.put(composeServiceEntry.getKey(), cheService);
    }
    return new CheServicesEnvironmentImpl(services);
}
Also used : CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) ComposeServiceImpl(org.eclipse.che.plugin.docker.compose.ComposeServiceImpl) Map(java.util.Map)

Example 7 with CheServicesEnvironmentImpl

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

the class ComposeEnvironmentParserTest method shouldBeAbleToParseComposeEnvironmentWithApplicationByLocation.

@Test
public void shouldBeAbleToParseComposeEnvironmentWithApplicationByLocation() throws ServerException {
    // given
    when(recipe.getContentType()).thenReturn("text/yaml");
    when(recipeDownloader.getRecipe(TEXT)).thenReturn(COMPOSE_CONTENT);
    when(recipe.getLocation()).thenReturn(TEXT);
    CheServicesEnvironmentImpl expectedEnv = createTestEnv();
    //when
    CheServicesEnvironmentImpl cheServicesEnvironment = parser.parse(environment);
    //then
    assertEquals(cheServicesEnvironment, expectedEnv);
}
Also used : CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

Example 8 with CheServicesEnvironmentImpl

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

the class ComposeEnvironmentParserTest method shouldBeAbleToParseComposeEnvironmentWithTextXYamlContentType.

@Test
public void shouldBeAbleToParseComposeEnvironmentWithTextXYamlContentType() throws Exception {
    // given
    when(recipe.getContentType()).thenReturn("text/x-yaml");
    when(recipe.getContent()).thenReturn(COMPOSE_CONTENT);
    CheServicesEnvironmentImpl expectedEnv = createTestEnv();
    //when
    CheServicesEnvironmentImpl cheServicesEnvironment = parser.parse(environment);
    //then
    assertEquals(cheServicesEnvironment, expectedEnv);
}
Also used : CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

Example 9 with CheServicesEnvironmentImpl

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

the class DefaultServicesStartStrategyTest method shouldOrderServicesWithDependenciesWhereOrderIsNotStrict.

@Test
public void shouldOrderServicesWithDependenciesWhereOrderIsNotStrict() throws Exception {
    // given
    CheServicesEnvironmentImpl composeEnvironment = new CheServicesEnvironmentImpl();
    composeEnvironment.getServices().put("second", new CheServiceImpl().withDependsOn(singletonList("first")));
    composeEnvironment.getServices().put("third", new CheServiceImpl().withDependsOn(singletonList("second")));
    composeEnvironment.getServices().put("first", new CheServiceImpl().withDependsOn(emptyList()));
    composeEnvironment.getServices().put("forth", new CheServiceImpl().withDependsOn(singletonList("second")));
    composeEnvironment.getServices().put("fifth", new CheServiceImpl().withDependsOn(singletonList("second")));
    // when
    List<String> actual = strategy.order(composeEnvironment);
    // then
    assertEquals(actual.get(0), "first");
    assertEquals(actual.get(1), "second");
    assertTrue(actual.contains("third"));
    assertTrue(actual.contains("forth"));
    assertTrue(actual.contains("fifth"));
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

Example 10 with CheServicesEnvironmentImpl

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

the class DefaultServicesStartStrategyTest method shouldOrderServicesWithMixedDependenciesInDependsOnVolumesFromAndLinks.

@Test
public void shouldOrderServicesWithMixedDependenciesInDependsOnVolumesFromAndLinks() throws Exception {
    // given
    CheServicesEnvironmentImpl composeEnvironment = new CheServicesEnvironmentImpl();
    composeEnvironment.getServices().put("second", new CheServiceImpl().withDependsOn(singletonList("first")));
    composeEnvironment.getServices().put("third", new CheServiceImpl().withVolumesFrom(asList("first", "second")));
    composeEnvironment.getServices().put("first", new CheServiceImpl().withLinks(emptyList()));
    composeEnvironment.getServices().put("forth", new CheServiceImpl().withLinks(singletonList("third")));
    composeEnvironment.getServices().put("fifth", new CheServiceImpl().withDependsOn(asList("forth", "first")));
    List<String> expected = asList("first", "second", "third", "forth", "fifth");
    // when
    List<String> actual = strategy.order(composeEnvironment);
    // then
    assertEquals(actual, expected);
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

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