Search in sources :

Example 1 with CheServicesEnvironmentImpl

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

the class DockerfileEnvironmentParserTest method shouldBeAbleToParseDockerfileEnvironmentFromLocation.

@Test
public void shouldBeAbleToParseDockerfileEnvironmentFromLocation() throws Exception {
    // given
    String recipeLocation = "http://localhost:8080/recipe/url";
    EnvironmentImpl environment = createDockerfileEnvConfig(null, recipeLocation, DEFAULT_MACHINE_NAME);
    CheServicesEnvironmentImpl expected = new CheServicesEnvironmentImpl();
    expected.getServices().put(DEFAULT_MACHINE_NAME, new CheServiceImpl().withBuild(new CheServiceBuildContextImpl().withContext(recipeLocation)));
    // when
    CheServicesEnvironmentImpl cheServicesEnvironment = parser.parse(environment);
    // then
    Assert.assertEquals(cheServicesEnvironment, expected);
}
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) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

Example 2 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 3 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)

Example 4 with CheServicesEnvironmentImpl

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

the class ComposeEnvironmentParserTest method shouldBeAbleToParseComposeEnvironmentWithTextYamlContentType.

@Test
public void shouldBeAbleToParseComposeEnvironmentWithTextYamlContentType() throws Exception {
    // given
    when(recipe.getContentType()).thenReturn("text/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 5 with CheServicesEnvironmentImpl

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

the class ComposeEnvironmentParserTest method createTestEnv.

private CheServicesEnvironmentImpl createTestEnv() {
    CheServicesEnvironmentImpl cheServicesEnvironment = new CheServicesEnvironmentImpl();
    CheServiceImpl cheService1 = new CheServiceImpl();
    String buildContext = "http://host.com:port/location/of/dockerfile/or/git/repo/";
    cheService1.setBuild(new CheServiceBuildContextImpl().withContext(buildContext).withDockerfilePath("dockerfile/Dockerfile_alternate").withArgs(emptyMap()));
    cheService1.setCommand(asList("tail", "-f", "/dev/null"));
    cheService1.setContainerName("some_name");
    cheService1.setDependsOn(asList("machine2", "machine3"));
    cheService1.setEntrypoint(asList("/bin/bash", "-c"));
    cheService1.setEnvironment(ImmutableMap.of("env1", "123", "env2", "345"));
    cheService1.setExpose(asList("3000", "8080"));
    cheService1.setImage("codenvy/ubuntu_jdk8");
    cheService1.setLabels(ImmutableMap.of("com.example.department", "Finance", "com.example.description", "Accounting webapp", "com.example.label-with-empty-value", ""));
    cheService1.setLinks(asList("machine1", "machine2:db"));
    cheService1.setMemLimit(2147483648L);
    cheService1.setNetworks(asList("some-network", "other-network"));
    cheService1.setPorts(asList("3000", "3000-3005"));
    cheService1.setVolumes(asList("/opt/data:/var/lib/mysql", "~/configs:/etc/configs/:ro"));
    cheService1.setVolumesFrom(asList("machine2:ro", "machine3"));
    CheServiceImpl cheService2 = new CheServiceImpl();
    cheService2.setImage("codenvy/ubuntu_jdk8");
    CheServiceImpl cheService3 = new CheServiceImpl();
    cheService3.setImage("codenvy/ubuntu_jdk8");
    cheServicesEnvironment.setServices(ImmutableMap.of("machine1", cheService1, "machine2", cheService2, "machine3", cheService3));
    return cheServicesEnvironment;
}
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)

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