Search in sources :

Example 1 with CheServiceBuildContextImpl

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

the class CheEnvironmentEngine method machineConfigToService.

private CheServiceImpl machineConfigToService(MachineConfig machineConfig) throws ServerException {
    CheServiceImpl service = new CheServiceImpl();
    service.setMemLimit(machineConfig.getLimits().getRam() * 1024L * 1024L);
    service.setEnvironment(machineConfig.getEnvVariables());
    if ("image".equals(machineConfig.getSource().getType())) {
        service.setImage(machineConfig.getSource().getLocation());
    } else {
        if (machineConfig.getSource().getContent() != null) {
            throw new ServerException("Additional machine creation from dockerfile content is not supported anymore. " + "Please use dockerfile location instead");
        } else {
            service.setBuild(new CheServiceBuildContextImpl(machineConfig.getSource().getLocation(), null, null, null));
        }
    }
    List<? extends ServerConf> servers = machineConfig.getServers();
    if (servers != null) {
        List<String> expose = new ArrayList<>();
        for (ServerConf server : servers) {
            expose.add(server.getPort());
        }
        service.setExpose(expose);
    }
    return service;
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) ServerConf(org.eclipse.che.api.core.model.machine.ServerConf) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList)

Example 2 with CheServiceBuildContextImpl

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

the class CheEnvironmentEngine method normalizeServiceSource.

private CheServiceImpl normalizeServiceSource(CheServiceImpl service, MachineSource machineSource) throws ServerException {
    CheServiceImpl serviceWithNormalizedSource = service;
    if (machineSource != null) {
        serviceWithNormalizedSource = new CheServiceImpl(service);
        if ("image".equals(machineSource.getType())) {
            serviceWithNormalizedSource.setBuild(null);
            serviceWithNormalizedSource.setImage(machineSource.getLocation());
        } else {
            // dockerfile
            serviceWithNormalizedSource.setImage(null);
            if (machineSource.getContent() != null) {
                serviceWithNormalizedSource.setBuild(new CheServiceBuildContextImpl(null, null, machineSource.getContent(), null));
            } else {
                serviceWithNormalizedSource.setBuild(new CheServiceBuildContextImpl(machineSource.getLocation(), null, null, null));
            }
        }
    }
    return serviceWithNormalizedSource;
}
Also used : CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl)

Example 3 with CheServiceBuildContextImpl

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

the class CheEnvironmentValidatorTest method createServicesEnv.

private static CheServicesEnvironmentImpl createServicesEnv() {
    CheServicesEnvironmentImpl cheServicesEnvironment = new CheServicesEnvironmentImpl();
    Map<String, CheServiceImpl> services = new HashMap<>();
    Map<String, String> buildArgs = new HashMap<String, String>() {

        {
            put("argkey", "argvalue");
        }
    };
    cheServicesEnvironment.setServices(services);
    services.put("dev-machine", createCheService("_dev", 1024L * 1024L * 1024L, singletonList("machine2"), singletonList("machine2"), singletonList("machine2")));
    CheServiceImpl service = createCheService("_machine2", 100L, null, emptyList(), null);
    service.setBuild(new CheServiceBuildContextImpl("context", "file", null, buildArgs));
    services.put("machine2", service);
    return cheServicesEnvironment;
}
Also used : CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) HashMap(java.util.HashMap) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)

Example 4 with CheServiceBuildContextImpl

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

the class EnvironmentParserTest method createExpectedEnv.

private static CheServicesEnvironmentImpl createExpectedEnv(String image, String dockerfile, List<String> expectedExpose, Map<String, String> expectedLabels) {
    CheServiceBuildContextImpl build = dockerfile != null ? new CheServiceBuildContextImpl(null, null, dockerfile, null) : null;
    CheServicesEnvironmentImpl environment = new CheServicesEnvironmentImpl();
    environment.getServices().put(DEFAULT_MACHINE_NAME, new CheServiceImpl().withImage(image).withLabels(expectedLabels).withBuild(build).withExpose(expectedExpose));
    return environment;
}
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 5 with CheServiceBuildContextImpl

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

the class CheEnvironmentEngineTest method shouldNotSetDockerfileContentInsteadOfUrlIfUrlDoesNotPointToCheApiOnEnvironmentStart.

@Test
public void shouldNotSetDockerfileContentInsteadOfUrlIfUrlDoesNotPointToCheApiOnEnvironmentStart() throws Exception {
    // given
    EnvironmentImpl env = createEnv();
    String machineName = "machineWithDockerfileNotFromApi";
    String contextUrl = "http://another-server.com/recipe/12345";
    //prepare CheServicesEnvironmentImpl which should return compose parser
    CheServicesEnvironmentImpl cheServicesEnvironment = createCheServicesEnvByName(machineName);
    cheServicesEnvironment.getServices().get(machineName).withBuild(new CheServiceBuildContextImpl().withContext(contextUrl));
    // 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().getDockerfilePath());
    assertNull(actualService.getBuild().getDockerfileContent());
    assertEquals(actualService.getBuild().getContext(), contextUrl);
}
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)

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