use of org.eclipse.che.api.workspace.server.model.impl.VolumeImpl in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplier method provisionVolumes.
private void provisionVolumes(ComponentImpl component, Container container, MachineConfigImpl config) throws DevfileException {
for (org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl componentVolume : component.getVolumes()) {
Optional<VolumeMount> sameNameMount = container.getVolumeMounts().stream().filter(vm -> vm.getName().equals(componentVolume.getName())).findFirst();
if (sameNameMount.isPresent() && sameNameMount.get().getMountPath().equals(componentVolume.getContainerPath())) {
continue;
} else if (sameNameMount.isPresent()) {
throw new DevfileException(format("Conflicting volume with same name ('%s') but different path ('%s') found for component '%s' and its container '%s'.", componentVolume.getName(), componentVolume.getContainerPath(), getIdentifiableComponentName(component), container.getName()));
}
if (container.getVolumeMounts().stream().anyMatch(vm -> vm.getMountPath().equals(componentVolume.getContainerPath()))) {
throw new DevfileException(format("Conflicting volume with same path ('%s') but different name ('%s') found for component '%s' and its container '%s'.", componentVolume.getContainerPath(), componentVolume.getName(), getIdentifiableComponentName(component), container.getName()));
}
config.getVolumes().put(componentVolume.getName(), new VolumeImpl().withPath(componentVolume.getContainerPath()));
}
}
use of org.eclipse.che.api.workspace.server.model.impl.VolumeImpl in project che-server by eclipse-che.
the class BrokerEnvironmentFactory method createForArtifactsBroker.
/**
* Creates {@link KubernetesEnvironment} with everything needed to deploy artifacts plugin broker.
*
* @param pluginFQNs fully qualified names of plugins that needs to be resolved by the broker
* @param runtimeID ID of the runtime the broker would be started
* @param mergePlugins whether the broker should be configured to merge plugins where possible
* @return kubernetes environment (or its extension) with the Plugin broker objects
*/
public E createForArtifactsBroker(Collection<PluginFQN> pluginFQNs, RuntimeIdentity runtimeID, boolean mergePlugins) throws InfrastructureException {
BrokersConfigs brokersConfigs = getBrokersConfigs(pluginFQNs, runtimeID, artifactsBrokerImage, mergePlugins);
brokersConfigs.machines.values().forEach(m -> m.getVolumes().put(PLUGINS_VOLUME_NAME, new VolumeImpl().withPath("/plugins")));
return doCreate(brokersConfigs);
}
use of org.eclipse.che.api.workspace.server.model.impl.VolumeImpl 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.VolumeImpl in project che-server by eclipse-che.
the class PVCProvisionerTest method testMatchingUserDefinedPVCWithCheVolume.
@Test
public void testMatchingUserDefinedPVCWithCheVolume() throws Exception {
// given
k8sEnv.getPersistentVolumeClaims().put("userDataPVC", newPVC("userDataPVC"));
pod.getSpec().getVolumes().add(new VolumeBuilder().withName("userData").withPersistentVolumeClaim(new PersistentVolumeClaimVolumeSourceBuilder().withClaimName("userDataPVC").build()).build());
pod.getSpec().getContainers().get(0).getVolumeMounts().add(new VolumeMountBuilder().withName("userData").withSubPath("/home/user/data").build());
k8sEnv.getMachines().values().forEach(m -> m.getVolumes().clear());
k8sEnv.getMachines().get(MACHINE_2_NAME).getVolumes().put("userDataPVC", new VolumeImpl().withPath("/"));
// when
provisioner.convertCheVolumes(k8sEnv, WORKSPACE_ID);
// then
assertEquals(k8sEnv.getPersistentVolumeClaims().size(), 1);
PersistentVolumeClaim pvcForUserData = findPvc("userDataPVC", k8sEnv.getPersistentVolumeClaims());
assertNotNull(pvcForUserData);
assertEquals("userDataPVC", pvcForUserData.getMetadata().getName());
PodSpec podSpec = k8sEnv.getPodsData().get(POD_1_NAME).getSpec();
io.fabric8.kubernetes.api.model.Volume userPodVolume = podSpec.getVolumes().get(0);
assertEquals(userPodVolume.getPersistentVolumeClaim().getClaimName(), pvcForUserData.getMetadata().getName());
assertEquals(podSpec.getVolumes().get(0).getPersistentVolumeClaim().getClaimName(), pvcForUserData.getMetadata().getName());
// check container bound to user-defined PVC
Container container1 = podSpec.getContainers().get(0);
assertEquals(container1.getVolumeMounts().size(), 1);
VolumeMount volumeMount = container1.getVolumeMounts().get(0);
assertEquals(volumeMount.getName(), userPodVolume.getName());
// check container that is bound to Che Volume via Machine configuration
Container container2 = podSpec.getContainers().get(1);
VolumeMount cheVolumeMount2 = container2.getVolumeMounts().get(0);
assertEquals(cheVolumeMount2.getName(), userPodVolume.getName());
}
use of org.eclipse.che.api.workspace.server.model.impl.VolumeImpl in project che-server by eclipse-che.
the class WorkspaceDaoTest method createWorkspaceConfig.
public static WorkspaceConfigImpl createWorkspaceConfig(String name) {
// Project Sources configuration
final SourceStorageImpl source1 = new SourceStorageImpl();
source1.setType("type1");
source1.setLocation("location1");
source1.setParameters(new HashMap<>(ImmutableMap.of("param1", "value1", "param2", "value2", "param3", "value3")));
final SourceStorageImpl source2 = new SourceStorageImpl();
source2.setType("type2");
source2.setLocation("location2");
source2.setParameters(new HashMap<>(ImmutableMap.of("param4", "value1", "param5", "value2", "param6", "value3")));
// 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);
pCfg1.getAttributes().putAll(ImmutableMap.of("key1", asList("v1", "v2"), "key2", asList("v1", "v2")));
final ProjectConfigImpl pCfg2 = new ProjectConfigImpl();
pCfg2.setPath("/path2");
pCfg2.setType("type2");
pCfg2.setName("project2");
pCfg2.setDescription("description2");
pCfg2.getMixins().addAll(asList("mixin3", "mixin4"));
pCfg2.setSource(source2);
pCfg2.getAttributes().putAll(ImmutableMap.of("key3", asList("v1", "v2"), "key4", asList("v1", "v2")));
final List<ProjectConfigImpl> projects = new ArrayList<>(asList(pCfg1, pCfg2));
// Commands
final CommandImpl cmd1 = new CommandImpl("name1", "cmd1", "type1");
cmd1.getAttributes().putAll(ImmutableMap.of("key1", "value1", "key2", "value2", "key3", "value3"));
final CommandImpl cmd2 = new CommandImpl("name2", "cmd2", "type2");
cmd2.getAttributes().putAll(ImmutableMap.of("key4", "value4", "key5", "value5", "key6", "value6"));
final List<CommandImpl> commands = new ArrayList<>(asList(cmd1, cmd2));
// OldMachine configs
final MachineConfigImpl exMachine1 = new MachineConfigImpl();
final ServerConfigImpl serverConf1 = new ServerConfigImpl("2265", "http", "path1", singletonMap("key", "value"));
final ServerConfigImpl serverConf2 = new ServerConfigImpl("2266", "ftp", "path2", singletonMap("key", "value"));
exMachine1.setServers(ImmutableMap.of("ref1", serverConf1, "ref2", serverConf2));
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"), "vol2", new VolumeImpl().withPath("/path/2")));
final MachineConfigImpl exMachine2 = new MachineConfigImpl();
final ServerConfigImpl serverConf3 = new ServerConfigImpl("2333", "https", "path3", singletonMap("key", "value"));
final ServerConfigImpl serverConf4 = new ServerConfigImpl("2334", "wss", "path4", singletonMap("key", "value"));
exMachine2.setServers(ImmutableMap.of("ref1", serverConf3, "ref2", serverConf4));
exMachine2.setAttributes(singletonMap("att1", "val"));
exMachine2.setEnv(singletonMap("CHE_ENV2", "value"));
exMachine2.setVolumes(ImmutableMap.of("vol2", new VolumeImpl().withPath("/path/2")));
final MachineConfigImpl exMachine3 = new MachineConfigImpl();
final ServerConfigImpl serverConf5 = new ServerConfigImpl("2333", "https", "path5", singletonMap("key", "value"));
exMachine3.setServers(singletonMap("ref1", serverConf5));
exMachine3.setAttributes(singletonMap("att1", "val"));
exMachine3.setEnv(singletonMap("CHE_ENV3", "value"));
exMachine3.setVolumes(ImmutableMap.of("vol3", new VolumeImpl().withPath("/path/3")));
// 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, "machine2", exMachine2, "machine3", exMachine3)));
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 EnvironmentImpl env2 = new EnvironmentImpl();
env2.setMachines(new HashMap<>(ImmutableMap.of("machine1", new MachineConfigImpl(exMachine1), "machine3", new MachineConfigImpl(exMachine3))));
env2.setRecipe(recipe2);
final Map<String, EnvironmentImpl> environments = ImmutableMap.of("env1", env1, "env2", env2);
// 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;
}
Aggregations