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);
}
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;
}
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;
}
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);
}
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;
}
Aggregations