use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class K8sContainerResolver method provisionCpuRequest.
private void provisionCpuRequest(Container container, CheContainer cheContainer) throws InfrastructureException {
String cpuRequest = cheContainer.getCpuRequest();
if (isNullOrEmpty(cpuRequest)) {
return;
}
try {
KubernetesSize.toCores(cpuRequest);
} catch (IllegalArgumentException e) {
throw new InfrastructureException(format("Sidecar CPU request field contains illegal value '%s'. Error: '%s'", cpuRequest, e.getMessage()));
}
Containers.addCpuRequest(container, cpuRequest);
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class K8sContainerResolver method provisionCpuLimit.
private void provisionCpuLimit(Container container, CheContainer cheContainer) throws InfrastructureException {
String cpuLimit = cheContainer.getCpuLimit();
if (isNullOrEmpty(cpuLimit)) {
return;
}
try {
KubernetesSize.toCores(cpuLimit);
} catch (IllegalArgumentException e) {
throw new InfrastructureException(format("Sidecar CPU limit field contains illegal value '%s'. Error: '%s'", cpuLimit, e.getMessage()));
}
Containers.addCpuLimit(container, cpuLimit);
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class TraefikGatewayRouteConfigGenerator method generate.
/**
* Generates configuration for all configs added by {@link
* TraefikGatewayRouteConfigGenerator#addRouteConfig(String, ConfigMap)} so far. It does not
* change them, so this method can be used repeatedly.
*
* <p>Returned {@code Map<String, String>} has keys created from {@code name} parameter of {@link
* TraefikGatewayRouteConfigGenerator#addRouteConfig(String, ConfigMap)} + '.yml' suffix. Values
* are full configuration for single gateway route. This map is suppose to be directly used as
* {@link ConfigMap}'s data.
*
* @return map with added routes configurations
*/
@Override
public Map<String, String> generate(String namespace) throws InfrastructureException {
Map<String, String> cmData = new HashMap<>();
for (Entry<String, ConfigMap> routeConfig : routeConfigs.entrySet()) {
Map<String, ServerConfigImpl> servers = new Annotations.Deserializer(routeConfig.getValue().getMetadata().getAnnotations()).servers();
if (servers.size() != 1) {
throw new InfrastructureException("Expected exactly 1 server [" + routeConfig.getValue().toString() + "]");
}
ServerConfigImpl server = servers.get(servers.keySet().iterator().next());
String serviceName = server.getAttributes().get(SERVICE_NAME_ATTRIBUTE);
String servicePort = server.getAttributes().get(SERVICE_PORT_ATTRIBUTE);
String traefikRouteConfig = generate(routeConfig.getKey(), createServiceUrl(serviceName, servicePort, namespace), server.getEndpointOrigin());
cmData.put(routeConfig.getKey() + ".yml", traefikRouteConfig);
}
return cmData;
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class WorkspaceRuntimesTest method shouldNotInjectRuntimeIfExceptionOccurredOnRuntimeFetching.
@Test
public void shouldNotInjectRuntimeIfExceptionOccurredOnRuntimeFetching() throws Exception {
// given
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId", "infraNamespace");
mockWorkspaceWithConfig(identity);
when(statuses.get("workspace123")).thenReturn(WorkspaceStatus.STARTING);
mockContext(identity);
doThrow(new InfrastructureException("error")).when(infrastructure).prepare(eq(identity), any());
doReturn(ImmutableSet.of(identity)).when(infrastructure).getIdentities();
// when
WorkspaceImpl workspace = new WorkspaceImpl();
workspace.setId("workspace123");
runtimes.injectRuntime(workspace);
// then
verify(statuses).remove(eq(identity.getWorkspaceId()));
assertEquals(workspace.getStatus(), WorkspaceStatus.STOPPED);
assertNull(workspace.getRuntime());
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException 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));
}
Aggregations