Search in sources :

Example 16 with InfrastructureException

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);
}
Also used : InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 17 with InfrastructureException

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);
}
Also used : InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 18 with InfrastructureException

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;
}
Also used : Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 19 with InfrastructureException

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());
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) Test(org.testng.annotations.Test)

Example 20 with InfrastructureException

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));
}
Also used : PLUGIN_MACHINE_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.PLUGIN_MACHINE_ATTRIBUTE) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Container(io.fabric8.kubernetes.api.model.Container) ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) EnvVars(org.eclipse.che.workspace.infrastructure.kubernetes.util.EnvVars) Singleton(javax.inject.Singleton) CONTAINER_SOURCE_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.CONTAINER_SOURCE_ATTRIBUTE) Function(java.util.function.Function) WORKING_DIRECTORY_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.WORKING_DIRECTORY_ATTRIBUTE) Inject(javax.inject.Inject) Names(org.eclipse.che.workspace.infrastructure.kubernetes.Names) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) Map(java.util.Map) MACHINE_NAME_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE) Service(io.fabric8.kubernetes.api.model.Service) Named(javax.inject.Named) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) Command(org.eclipse.che.api.workspace.server.wsplugins.model.Command) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) ChePluginsApplier(org.eclipse.che.api.workspace.server.wsplugins.ChePluginsApplier) TOOL_CONTAINER_SOURCE(org.eclipse.che.api.workspace.shared.Constants.TOOL_CONTAINER_SOURCE) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) Component(org.eclipse.che.api.core.model.workspace.devfile.Component) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Pod(io.fabric8.kubernetes.api.model.Pod) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) Beta(com.google.common.annotations.Beta) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) List(java.util.List) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Warnings(org.eclipse.che.workspace.infrastructure.kubernetes.Warnings) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) ProjectsRootEnvVariableProvider(org.eclipse.che.api.workspace.server.spi.provision.env.ProjectsRootEnvVariableProvider) KubernetesSize(org.eclipse.che.workspace.infrastructure.kubernetes.util.KubernetesSize) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) Container(io.fabric8.kubernetes.api.model.Container) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Aggregations

InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)242 InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)64 Test (org.testng.annotations.Test)56 KubernetesInfrastructureException (org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException)44 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)42 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)38 CompletableFuture (java.util.concurrent.CompletableFuture)36 ExecutionException (java.util.concurrent.ExecutionException)36 TimeoutException (java.util.concurrent.TimeoutException)32 ServerException (org.eclipse.che.api.core.ServerException)32 Pod (io.fabric8.kubernetes.api.model.Pod)30 Map (java.util.Map)26 ValidationException (org.eclipse.che.api.core.ValidationException)22 Traced (org.eclipse.che.commons.annotation.Traced)20 Container (io.fabric8.kubernetes.api.model.Container)18 List (java.util.List)18 Set (java.util.Set)18 Inject (javax.inject.Inject)18 RuntimeStartInterruptedException (org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException)18 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)18