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