use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin in project che-server by eclipse-che.
the class KubernetesPluginsToolingApplierTest method addsMachinesWithVolumesToAllToolingContainer.
@Test
public void addsMachinesWithVolumesToAllToolingContainer() throws Exception {
// given
ChePlugin chePluginWithNonDefaultVolume = createChePlugin();
String anotherVolumeName = VOLUME_NAME + "1";
String anotherVolumeMountPath = VOLUME_MOUNT_PATH + "/something";
List<Volume> volumes = singletonList(new Volume().name(anotherVolumeName).mountPath(anotherVolumeMountPath));
CheContainer toolingContainer = chePluginWithNonDefaultVolume.getContainers().get(0);
toolingContainer.setVolumes(volumes);
ChePlugin chePlugin = createChePlugin();
// when
applier.apply(runtimeIdentity, internalEnvironment, asList(chePlugin, chePluginWithNonDefaultVolume));
// then
Collection<InternalMachineConfig> machineConfigs = getNonUserMachines(internalEnvironment);
assertEquals(machineConfigs.size(), 2);
verify(chePluginsVolumeApplier).applyVolumes(any(PodData.class), any(Container.class), eq(chePlugin.getContainers().get(0).getVolumes()), eq(internalEnvironment));
}
use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin in project che-server by eclipse-che.
the class BrokersResultTest method shouldReturnResultOfBroker.
@Test
public void shouldReturnResultOfBroker() throws Exception {
// given
ChePlugin chePlugin = new ChePlugin();
executeWhenResultIsStarted(() -> {
brokersResult.setResult(singletonList(chePlugin));
return null;
});
// when
List<ChePlugin> chePlugins = brokersResult.get(2, TimeUnit.SECONDS);
// then
assertEquals(chePlugins, singletonList(chePlugin));
}
use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin in project che-server by eclipse-che.
the class KubernetesPluginsToolingApplierTest method shouldAddK8sServicesForChePluginEndpoints.
@Test
public void shouldAddK8sServicesForChePluginEndpoints() throws Exception {
// given
ChePluginEndpoint endpoint1 = new ChePluginEndpoint().name(CHE_PLUGIN_ENDPOINT_NAME).targetPort(101010).setPublic(true);
ChePluginEndpoint endpoint2 = new ChePluginEndpoint().name("test-endpoint-2").targetPort(2020).setPublic(false);
CheContainerPort cheContainerPort1 = new CheContainerPort().exposedPort(101010);
CheContainerPort cheContainerPort2 = new CheContainerPort().exposedPort(2020);
ChePlugin chePlugin = createChePlugin();
chePlugin.setEndpoints(asList(endpoint1, endpoint2));
chePlugin.getContainers().get(0).setPorts(asList(cheContainerPort1, cheContainerPort2));
// when
applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
// then
verifyK8sServices(internalEnvironment, endpoint1, endpoint2);
}
use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin 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.workspace.server.wsplugins.model.ChePlugin in project che-server by eclipse-che.
the class KubernetesPluginsToolingValidator method validatePluginNames.
public void validatePluginNames(List<? extends ChePlugin> plugins) throws ValidationException {
for (ChePlugin plugin : plugins) {
if (plugin.getName() != null) {
final String formattedPluginName = plugin.getName().toLowerCase();
checkValid(formattedPluginName, "Plugin name `%s` contains unacceptable symbols and cannot be used as part of container naming.");
}
for (CheContainer container : plugin.getContainers()) {
if (container.getName() != null) {
final String formattedContainerName = container.getName().toLowerCase();
checkValid(formattedContainerName, "Container name `%s` contains unacceptable symbols and cannot be used as part of container naming.");
}
}
}
}
Aggregations