Search in sources :

Example 21 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 22 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)

Example 23 with CheServicesEnvironmentImpl

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

the class DefaultServicesStartStrategyTest method shouldFailIfMachineLinksByItSelf.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "A machine can not link to itself: .*")
public void shouldFailIfMachineLinksByItSelf() {
    // given
    CheServicesEnvironmentImpl composeEnvironment = new CheServicesEnvironmentImpl();
    composeEnvironment.getServices().put("first", new CheServiceImpl().withLinks(singletonList("first")));
    // when
    strategy.order(composeEnvironment);
}
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 24 with CheServicesEnvironmentImpl

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

the class DockerImageEnvironmentParser method parse.

@Override
public CheServicesEnvironmentImpl parse(Environment environment) throws IllegalArgumentException, ServerException {
    EnvironmentRecipe recipe = environment.getRecipe();
    if (!"dockerimage".equals(recipe.getType())) {
        throw new IllegalArgumentException(format("Docker image environment parser doesn't support recipe type '%s'", recipe.getType()));
    }
    CheServicesEnvironmentImpl cheServiceEnv = new CheServicesEnvironmentImpl();
    CheServiceImpl service = new CheServiceImpl();
    cheServiceEnv.getServices().put(getMachineName(environment), service);
    service.setImage(recipe.getLocation());
    return cheServiceEnv;
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) EnvironmentRecipe(org.eclipse.che.api.core.model.workspace.EnvironmentRecipe) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)

Example 25 with CheServicesEnvironmentImpl

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

the class DockerfileEnvironmentParser method parse.

@Override
public CheServicesEnvironmentImpl parse(Environment environment) throws IllegalArgumentException, ServerException {
    EnvironmentRecipe recipe = environment.getRecipe();
    if (!"dockerfile".equals(recipe.getType())) {
        throw new IllegalArgumentException(format("Dockerfile environment parser doesn't support recipe type '%s'", recipe.getType()));
    }
    if (!"text/x-dockerfile".equals(recipe.getContentType())) {
        throw new IllegalArgumentException(format("Content type '%s' of recipe of environment is unsupported." + " Supported values are: text/x-dockerfile", recipe.getContentType()));
    }
    CheServicesEnvironmentImpl cheServiceEnv = new CheServicesEnvironmentImpl();
    CheServiceImpl service = new CheServiceImpl();
    cheServiceEnv.getServices().put(getMachineName(environment), service);
    if (recipe.getLocation() != null) {
        service.setBuild(new CheServiceBuildContextImpl().withContext(recipe.getLocation()));
    } else {
        service.setBuild(new CheServiceBuildContextImpl().withDockerfileContent(recipe.getContent()));
    }
    return cheServiceEnv;
}
Also used : CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) EnvironmentRecipe(org.eclipse.che.api.core.model.workspace.EnvironmentRecipe) 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