Search in sources :

Example 11 with CheServiceBuildContextImpl

use of org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl 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)

Example 12 with CheServiceBuildContextImpl

use of org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl 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 13 with CheServiceBuildContextImpl

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

the class CheEnvironmentEngineTest method shouldSetDockerfileContentInsteadOfUrlIfUrlPointsToCheApiOnEnvironmentStart.

@Test
public void shouldSetDockerfileContentInsteadOfUrlIfUrlPointsToCheApiOnEnvironmentStart() throws Exception {
    // given
    EnvironmentImpl env = createEnv();
    String machineName = "machineWithDockerfileFromApi";
    String dockerfileContent = "this is dockerfile content";
    when(recipeDownloader.getRecipe(anyString())).thenReturn(dockerfileContent);
    //prepare CheServicesEnvironmentImpl which should return compose parser
    CheServicesEnvironmentImpl cheServicesEnvironment = createCheServicesEnvByName(machineName);
    cheServicesEnvironment.getServices().get(machineName).withBuild(new CheServiceBuildContextImpl().withContext(API_ENDPOINT + "/recipe/12345"));
    // when
    startEnv(env, cheServicesEnvironment);
    // then
    ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
    verify(machineProvider).startService(anyString(), anyString(), anyString(), eq(machineName), eq(false), anyString(), captor.capture(), any(LineConsumer.class));
    CheServiceImpl actualService = captor.getValue();
    assertNull(actualService.getBuild().getContext());
    assertNull(actualService.getBuild().getDockerfilePath());
    assertEquals(actualService.getBuild().getDockerfileContent(), dockerfileContent);
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) 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) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 14 with CheServiceBuildContextImpl

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

the class CheEnvironmentValidatorTest method invalidServicesEnvironmentProvider.

@DataProvider
public static Object[][] invalidServicesEnvironmentProvider() {
    // Format of result array:
    // [ [InvalidCheServicesEnvironmentObject, ExceptionMessage], ... ]
    CheServicesEnvironmentImpl env;
    Map.Entry<String, CheServiceImpl> serviceEntry;
    CheServiceImpl service;
    List<List<Object>> data = new ArrayList<>();
    env = createServicesEnv();
    env.setServices(null);
    data.add(asList(env, "Environment 'env' should contain at least 1 machine"));
    env = createServicesEnv();
    env.setServices(emptyMap());
    data.add(asList(env, "Environment 'env' should contain at least 1 machine"));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    env.getServices().put("invalid service name", serviceEntry.getValue());
    data.add(asList(env, "Name of machine 'invalid service name' in environment 'env' is invalid"));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage(null);
    service.setBuild(null);
    data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage("");
    service.setBuild(null);
    data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage(null);
    service.setBuild(new CheServiceBuildContextImpl());
    data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage("");
    service.setBuild(new CheServiceBuildContextImpl());
    data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setPorts(new ArrayList<>(singletonList("8080:8080")));
    data.add(asList(env, format("Ports binding is forbidden but found in machine '%s' of environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setVolumes(new ArrayList<>(singletonList("volume")));
    data.add(asList(env, format("Volumes binding is forbidden but found in machine '%s' of environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setNetworks(new ArrayList<>(singletonList("network1")));
    data.add(asList(env, format("Networks configuration is forbidden but found in machine '%s' of environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage(null);
    service.setBuild(new CheServiceBuildContextImpl(null, "dockerfile", null, null));
    data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage("");
    service.setBuild(new CheServiceBuildContextImpl("", "dockerfile", null, null));
    data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage("");
    service.setBuild(new CheServiceBuildContextImpl(null, null, null, null));
    data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage("");
    service.setBuild(new CheServiceBuildContextImpl("some url", null, "some content", new HashMap<String, String>() {

        {
            put("argkey", "argvalue");
        }
    }));
    data.add(asList(env, format("Machine '%s' in environment 'env' contains mutually exclusive dockerfile content and build context.", serviceEntry.getKey())));
    return data.stream().map(list -> list.toArray(new Object[list.size()])).toArray(value -> new Object[data.size()][]);
}
Also used : Listeners(org.testng.annotations.Listeners) MachineInstanceProviders(org.eclipse.che.api.machine.server.MachineInstanceProviders) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) DataProvider(org.testng.annotations.DataProvider) Mock(org.mockito.Mock) DtoConverter(org.eclipse.che.api.workspace.server.DtoConverter) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) ServerConfDto(org.eclipse.che.api.machine.shared.dto.ServerConfDto) Mockito.spy(org.mockito.Mockito.spy) ServerConf2Impl(org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) MachineConfigDto(org.eclipse.che.api.machine.shared.dto.MachineConfigDto) Collections.singleton(java.util.Collections.singleton) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) Collections.singletonMap(java.util.Collections.singletonMap) InjectMocks(org.mockito.InjectMocks) Collections.emptyMap(java.util.Collections.emptyMap) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) MachineSourceDto(org.eclipse.che.api.machine.shared.dto.MachineSourceDto) Collections.emptyList(java.util.Collections.emptyList) Assert.fail(org.testng.Assert.fail) BeforeMethod(org.testng.annotations.BeforeMethod) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) ExtendedMachineDto(org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto) Mockito.when(org.mockito.Mockito.when) String.format(java.lang.String.format) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Environment(org.eclipse.che.api.core.model.workspace.Environment) ServerException(org.eclipse.che.api.core.ServerException) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) Joiner(com.google.common.base.Joiner) CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) DataProvider(org.testng.annotations.DataProvider)

Example 15 with CheServiceBuildContextImpl

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

the class DockerfileEnvironmentParserTest method shouldBeAbleToParseDockerfileEnvironmentFromContent.

@Test
public void shouldBeAbleToParseDockerfileEnvironmentFromContent() throws ServerException {
    Environment environment = createDockerfileEnvConfig(DEFAULT_DOCKERFILE, null, DEFAULT_MACHINE_NAME);
    CheServicesEnvironmentImpl expected = new CheServicesEnvironmentImpl();
    expected.getServices().put(DEFAULT_MACHINE_NAME, new CheServiceImpl().withBuild(new CheServiceBuildContextImpl().withDockerfileContent(DEFAULT_DOCKERFILE)));
    // when
    CheServicesEnvironmentImpl cheServicesEnvironment = parser.parse(environment);
    // then
    assertEquals(cheServicesEnvironment, expected);
}
Also used : CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) Environment(org.eclipse.che.api.core.model.workspace.Environment) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

Aggregations

CheServiceBuildContextImpl (org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl)15 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)15 CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)13 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)5 Test (org.testng.annotations.Test)5 HashMap (java.util.HashMap)4 Matchers.anyString (org.mockito.Matchers.anyString)4 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ServerException (org.eclipse.che.api.core.ServerException)2 Environment (org.eclipse.che.api.core.model.workspace.Environment)2 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)2 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)2 Joiner (com.google.common.base.Joiner)1 String.format (java.lang.String.format)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singleton (java.util.Collections.singleton)1 Collections.singletonList (java.util.Collections.singletonList)1