use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.
the class MachineProviderImplTest method shouldAddEnvVarsFromMachineConfigToContainerOnDevInstanceCreationFromSnapshot.
@Test
public void shouldAddEnvVarsFromMachineConfigToContainerOnDevInstanceCreationFromSnapshot() throws Exception {
// given
Map<String, String> envVarsFromConfig = new HashMap<>();
envVarsFromConfig.put("ENV_VAR1", "123");
envVarsFromConfig.put("ENV_VAR2", "234");
final boolean isDev = true;
CheServiceImpl machine = createService();
machine.setEnvironment(envVarsFromConfig);
// when
createInstanceFromSnapshot(machine, isDev);
// then
ArgumentCaptor<CreateContainerParams> argumentCaptor = ArgumentCaptor.forClass(CreateContainerParams.class);
verify(dockerConnector).createContainer(argumentCaptor.capture());
assertTrue(asList(argumentCaptor.getValue().getContainerConfig().getEnv()).containsAll(envVarsFromConfig.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.toList())));
}
use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.
the class MachineProviderImplTest method shouldAddAllVolumesOnDevInstanceCreationFromSnapshot.
@Test
public void shouldAddAllVolumesOnDevInstanceCreationFromSnapshot() throws Exception {
String[] bindMountVolumesFromMachine = new String[] { "/my/bind/mount1:/from/host1", "/my/bind/mount2:/from/host2:ro", "/my/bind/mount3:/from/host3:ro,Z" };
String[] volumesFromMachine = new String[] { "/projects", "/something", "/something/else" };
String[] allMachinesSystemVolumes = new String[] { "/some/thing/else:/home/some/thing/else", "/other/path:/home/other/path", "/home/other/path2" };
String[] devMachinesSystemVolumes = new String[] { "/etc:/tmp/etc:ro", "/some/thing:/home/some/thing", "/some/thing2:/home/some/thing2:ro,z", "/home/some/thing3" };
String[] expectedBindMountVolumes = new String[] { "/my/bind/mount1:/from/host1", "/my/bind/mount2:/from/host2:ro", "/my/bind/mount3:/from/host3:ro,Z", "/some/thing/else:/home/some/thing/else", "/other/path:/home/other/path", "/etc:/tmp/etc:ro", "/some/thing:/home/some/thing", "/some/thing2:/home/some/thing2:ro,z" };
Map<String, Volume> expectedVolumes = Stream.of("/projects", "/something", "/something/else", "/home/other/path2", "/home/some/thing3").collect(toMap(Function.identity(), v -> new Volume()));
provider = new MachineProviderBuilder().setDevMachineVolumes(new HashSet<>(asList(devMachinesSystemVolumes))).setAllMachineVolumes(new HashSet<>(asList(allMachinesSystemVolumes))).build();
CheServiceImpl service = createService();
service.setVolumes(Stream.concat(Stream.of(bindMountVolumesFromMachine), Stream.of(volumesFromMachine)).collect(Collectors.toList()));
createInstanceFromSnapshot(service, true);
ArgumentCaptor<CreateContainerParams> argumentCaptor = ArgumentCaptor.forClass(CreateContainerParams.class);
verify(dockerConnector).createContainer(argumentCaptor.capture());
String[] actualBindMountVolumes = argumentCaptor.getValue().getContainerConfig().getHostConfig().getBinds();
Map<String, Volume> actualVolumes = argumentCaptor.getValue().getContainerConfig().getVolumes();
assertEquals(actualVolumes, expectedVolumes);
assertEqualsNoOrder(actualBindMountVolumes, expectedBindMountVolumes);
}
use of org.eclipse.che.api.environment.server.model.CheServiceImpl 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.CheServiceImpl 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"));
}
use of org.eclipse.che.api.environment.server.model.CheServiceImpl 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);
}
Aggregations