Search in sources :

Example 6 with MachineConfigImpl

use of org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl in project che-server by eclipse-che.

the class KubernetesComponentToWorkspaceApplier method prepareMachineConfigs.

/**
 * Creates map of machine names and corresponding {@link MachineConfigImpl} with component alias
 * attribute set.
 */
private Map<String, MachineConfigImpl> prepareMachineConfigs(List<PodData> podsData, ComponentImpl component) throws DevfileException {
    Map<String, MachineConfigImpl> machineConfigs = new HashMap<>();
    for (PodData podData : podsData) {
        List<Container> containers = new ArrayList<>();
        containers.addAll(podData.getSpec().getContainers());
        containers.addAll(podData.getSpec().getInitContainers());
        for (Container container : containers) {
            String machineName = machineName(podData, container);
            MachineConfigImpl config = new MachineConfigImpl();
            if (!isNullOrEmpty(component.getAlias())) {
                config.getAttributes().put(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE, component.getAlias());
            }
            provisionVolumes(component, container, config);
            provisionEndpoints(component, config);
            machineConfigs.put(machineName, config);
        }
    }
    return machineConfigs;
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Container(io.fabric8.kubernetes.api.model.Container) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 7 with MachineConfigImpl

use of org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl in project che-server by eclipse-che.

the class WorkspaceManagerTest method createConfig.

private static WorkspaceConfigImpl createConfig() {
    MachineConfigImpl machineConfig = new MachineConfigImpl(singletonMap("server", createServerConfig()), singletonMap("CHE_ENV", "value"), singletonMap(MEMORY_LIMIT_ATTRIBUTE, "10000"), emptyMap());
    EnvironmentImpl environment = new EnvironmentImpl(new RecipeImpl("type", "contentType", "content", null), singletonMap("dev-machine", machineConfig));
    return WorkspaceConfigImpl.builder().setName("dev-workspace").setDefaultEnv("dev-env").setEnvironments(singletonMap("dev-env", environment)).setCommands(asList(createCommand(), createCommand())).build();
}
Also used : MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)

Example 8 with MachineConfigImpl

use of org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl in project che-server by eclipse-che.

the class WorkspaceActivityDaoTest method createWorkspaceConfig.

private static WorkspaceConfigImpl createWorkspaceConfig(String name) {
    // Project Sources configuration
    final SourceStorageImpl source1 = new SourceStorageImpl();
    source1.setType("type1");
    source1.setLocation("location1");
    // Project Configuration
    final ProjectConfigImpl pCfg1 = new ProjectConfigImpl();
    pCfg1.setPath("/path1");
    pCfg1.setType("type1");
    pCfg1.setName("project1");
    pCfg1.setDescription("description1");
    pCfg1.getMixins().addAll(asList("mixin1", "mixin2"));
    pCfg1.setSource(source1);
    final List<ProjectConfigImpl> projects = new ArrayList<>(singletonList(pCfg1));
    // Commands
    final CommandImpl cmd1 = new CommandImpl("name1", "cmd1", "type1");
    final List<CommandImpl> commands = new ArrayList<>(singletonList(cmd1));
    // OldMachine configs
    final MachineConfigImpl exMachine1 = new MachineConfigImpl();
    final ServerConfigImpl serverConf1 = new ServerConfigImpl("2265", "http", "path1", singletonMap("key", "value"));
    exMachine1.setServers(ImmutableMap.of("ref1", serverConf1));
    exMachine1.setAttributes(singletonMap("att1", "val"));
    exMachine1.setEnv(ImmutableMap.of("CHE_ENV1", "value", "CHE_ENV2", "value"));
    exMachine1.setVolumes(ImmutableMap.of("vol1", new VolumeImpl().withPath("/path/1")));
    // Environments
    final RecipeImpl recipe1 = new RecipeImpl();
    recipe1.setLocation("https://eclipse.che/Dockerfile");
    recipe1.setType("dockerfile");
    recipe1.setContentType("text/x-dockerfile");
    recipe1.setContent("content");
    final EnvironmentImpl env1 = new EnvironmentImpl();
    env1.setMachines(new HashMap<>(ImmutableMap.of("machine1", exMachine1)));
    env1.setRecipe(recipe1);
    final RecipeImpl recipe2 = new RecipeImpl();
    recipe2.setLocation("https://eclipse.che/Dockerfile");
    recipe2.setType("dockerfile");
    recipe2.setContentType("text/x-dockerfile");
    recipe2.setContent("content");
    final Map<String, EnvironmentImpl> environments = ImmutableMap.of("env1", env1);
    // Workspace configuration
    final WorkspaceConfigImpl wCfg = new WorkspaceConfigImpl();
    wCfg.setDefaultEnv("env1");
    wCfg.setName(name);
    wCfg.setDescription("description");
    wCfg.setCommands(commands);
    wCfg.setProjects(projects);
    wCfg.setEnvironments(new HashMap<>(environments));
    return wCfg;
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ArrayList(java.util.ArrayList) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) SourceStorageImpl(org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.VolumeImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)

Example 9 with MachineConfigImpl

use of org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl in project che-server by eclipse-che.

the class DockerimageComponentToWorkspaceApplierTest method shouldProvisionMachineConfigWithoutSourcesByDefault.

@Test
public void shouldProvisionMachineConfigWithoutSourcesByDefault() throws Exception {
    // given
    ComponentImpl dockerimageComponent = new ComponentImpl();
    dockerimageComponent.setAlias("jdk");
    dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE);
    dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest");
    dockerimageComponent.setMemoryLimit("1G");
    // when
    dockerimageComponentApplier.apply(workspaceConfig, dockerimageComponent, null);
    // then
    verify(k8sEnvProvisioner).provision(eq(workspaceConfig), eq(KubernetesEnvironment.TYPE), objectsCaptor.capture(), machinesCaptor.capture());
    MachineConfigImpl machineConfig = machinesCaptor.getValue().get("jdk");
    assertNotNull(machineConfig);
    assertFalse(machineConfig.getVolumes().containsKey(PROJECTS_VOLUME_NAME));
}
Also used : MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 10 with MachineConfigImpl

use of org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl in project che-server by eclipse-che.

the class DockerimageComponentToWorkspaceApplierTest method shouldProvisionK8sEnvironmentWithMachineConfigFromSpecifiedDockerimageWithoutAlias.

@Test
public void shouldProvisionK8sEnvironmentWithMachineConfigFromSpecifiedDockerimageWithoutAlias() throws Exception {
    ComponentImpl dockerimageComponent = new ComponentImpl();
    dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE);
    dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest");
    dockerimageComponent.setMemoryLimit("1G");
    // when
    dockerimageComponentApplier.apply(workspaceConfig, dockerimageComponent, null);
    // then
    verify(k8sEnvProvisioner).provision(any(), eq(KubernetesEnvironment.TYPE), objectsCaptor.capture(), machinesCaptor.capture());
    MachineConfigImpl machineConfig = machinesCaptor.getValue().get("eclipse-ubuntu_jdk8-latest");
    assertNotNull(machineConfig);
    List<HasMetadata> objects = objectsCaptor.getValue();
    assertEquals(objects.size(), 1);
    assertTrue(objects.get(0) instanceof Deployment);
    Deployment deployment = (Deployment) objects.get(0);
    PodTemplateSpec podTemplate = deployment.getSpec().getTemplate();
    ObjectMeta podMeta = podTemplate.getMetadata();
    assertEquals(podMeta.getName(), "eclipse-ubuntu_jdk8-latest");
    Map<String, String> deploymentSelector = deployment.getSpec().getSelector().getMatchLabels();
    assertFalse(deploymentSelector.isEmpty());
    assertTrue(podMeta.getLabels().entrySet().containsAll(deploymentSelector.entrySet()));
    Container container = podTemplate.getSpec().getContainers().get(0);
    assertEquals(container.getName(), "eclipse-ubuntu_jdk8-latest");
    assertEquals(container.getImage(), "eclipse/ubuntu_jdk8:latest");
    assertEquals(Names.machineName(podTemplate.getMetadata(), container), "eclipse-ubuntu_jdk8-latest");
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Container(io.fabric8.kubernetes.api.model.Container) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Aggregations

MachineConfigImpl (org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)70 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)44 Test (org.testng.annotations.Test)44 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)26 EndpointImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl)26 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)22 Map (java.util.Map)20 ArrayList (java.util.ArrayList)18 RecipeImpl (org.eclipse.che.api.workspace.server.model.impl.RecipeImpl)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 ImmutableMap (com.google.common.collect.ImmutableMap)16 Container (io.fabric8.kubernetes.api.model.Container)16 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)16 Collections.emptyMap (java.util.Collections.emptyMap)16 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)16 Collections.singletonMap (java.util.Collections.singletonMap)14 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)12 ArgumentMatchers.anyMap (org.mockito.ArgumentMatchers.anyMap)12 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)10