use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project che-server by eclipse-che.
the class KubernetesPluginsToolingApplier method apply.
@Override
public void apply(RuntimeIdentity runtimeIdentity, InternalEnvironment internalEnvironment, Collection<ChePlugin> chePlugins) throws InfrastructureException {
if (chePlugins.isEmpty()) {
return;
}
KubernetesEnvironment k8sEnv = (KubernetesEnvironment) internalEnvironment;
Map<String, PodData> pods = k8sEnv.getPodsData();
switch(pods.size()) {
case 0:
addToolingPod(k8sEnv);
pods = k8sEnv.getPodsData();
break;
case 1:
break;
default:
throw new InfrastructureException("Che plugins tooling configuration can be applied to a workspace with one pod only");
}
PodData pod = pods.values().iterator().next();
CommandsResolver commandsResolver = new CommandsResolver(k8sEnv);
for (ChePlugin chePlugin : chePlugins) {
Map<String, ComponentImpl> devfilePlugins = k8sEnv.getDevfile().getComponents().stream().filter(c -> c.getType().equals("cheEditor") || c.getType().equals("chePlugin")).collect(Collectors.toMap(ComponentImpl::getId, Function.identity()));
if (!devfilePlugins.containsKey(chePlugin.getId())) {
throw new InfrastructureException(String.format("The downloaded plugin '%s' configuration does not have the " + "corresponding component in devfile. Devfile contains the following cheEditor/chePlugins: %s", chePlugin.getId(), devfilePlugins.keySet()));
}
ComponentImpl pluginRelatedComponent = devfilePlugins.get(chePlugin.getId());
for (CheContainer container : chePlugin.getInitContainers()) {
Container k8sInitContainer = toK8sContainer(container);
envVars.apply(k8sInitContainer, pluginRelatedComponent.getEnv());
chePluginsVolumeApplier.applyVolumes(pod, k8sInitContainer, container.getVolumes(), k8sEnv);
pod.getSpec().getInitContainers().add(k8sInitContainer);
}
Collection<CommandImpl> pluginRelatedCommands = commandsResolver.resolve(chePlugin);
for (CheContainer container : chePlugin.getContainers()) {
addSidecar(pod, container, chePlugin, k8sEnv, pluginRelatedCommands, pluginRelatedComponent, runtimeIdentity);
}
}
chePlugins.forEach(chePlugin -> populateWorkspaceEnvVars(chePlugin, k8sEnv));
}
use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project che-server by eclipse-che.
the class KubernetesMachinesCacheTest method shouldUpdateMachineStatus.
@Test
public void shouldUpdateMachineStatus() throws Exception {
// given
RuntimeIdentity runtimeId = runtimeStates[0].getRuntimeId();
KubernetesMachineImpl machine = machines[0];
String machineName = machine.getName();
// when
machineCache.updateMachineStatus(runtimeId, machineName, MachineStatus.RUNNING);
// then
Optional<KubernetesMachineImpl> machineOpt = machineCache.getMachines(runtimeId).entrySet().stream().filter(e -> e.getKey().equals(machineName)).map(Map.Entry::getValue).findAny();
assertTrue(machineOpt.isPresent());
assertEquals(machineOpt.get().getStatus(), MachineStatus.RUNNING);
}
use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project che-server by eclipse-che.
the class KubernetesMachinesCacheTest method shouldGetServer.
@Test
public void shouldGetServer() throws Exception {
// given
RuntimeIdentity runtimeId = runtimeStates[0].getRuntimeId();
KubernetesMachineImpl machine = machines[0];
Entry<String, KubernetesServerImpl> serverToFetch = machine.getServers().entrySet().iterator().next();
// when
KubernetesServerImpl fetched = machineCache.getServer(runtimeId, machine.getName(), serverToFetch.getKey());
// then
assertEquals(fetched, serverToFetch.getValue());
}
use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project che-server by eclipse-che.
the class KubernetesMachinesCacheTest method shouldUpdateMachineStatusServerStatus.
@Test
public void shouldUpdateMachineStatusServerStatus() throws Exception {
// given
RuntimeIdentity runtimeId = runtimeStates[0].getRuntimeId();
// when
machineCache.updateServerStatus(runtimeId, machines[0].getName(), "server1", ServerStatus.RUNNING);
// then
KubernetesServerImpl fetchedServer = machineCache.getServer(runtimeId, "machine1", "server1");
assertEquals(fetchedServer.getStatus(), ServerStatus.RUNNING);
}
use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project che-server by eclipse-che.
the class KubernetesMachinesCacheTest method shouldUpdateServerStatus.
@Test
public void shouldUpdateServerStatus() throws Exception {
// given
RuntimeIdentity runtimeId = runtimeStates[0].getRuntimeId();
// when
machineCache.updateServerStatus(runtimeId, machines[0].getName(), "server1", ServerStatus.RUNNING);
// then
KubernetesServerImpl fetchedServer = machineCache.getServer(runtimeId, "machine1", "server1");
assertEquals(fetchedServer.getStatus(), ServerStatus.RUNNING);
}
Aggregations