Search in sources :

Example 46 with InfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.

the class KubernetesNamespaceTest method testKubernetesNamespaceCleaningUpIfExceptionsOccurs.

@Test
public void testKubernetesNamespaceCleaningUpIfExceptionsOccurs() throws Exception {
    doThrow(new InfrastructureException("err1.")).when(services).delete();
    doThrow(new InfrastructureException("err2.")).when(deployments).delete();
    InfrastructureException error = null;
    // when
    try {
        k8sNamespace.cleanUp();
    } catch (InfrastructureException e) {
        error = e;
    }
    // then
    assertNotNull(error);
    String message = error.getMessage();
    assertEquals(message, "Error(s) occurs while cleaning up the namespace. err1. err2.");
    verify(ingresses).delete();
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) Test(org.testng.annotations.Test)

Example 47 with InfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.

the class ServersCheckerTest method awaitShouldReturnOnFirstUnavailability.

@Test(timeOut = 5000)
public void awaitShouldReturnOnFirstUnavailability() throws Exception {
    CompletableFuture<String> future1 = spy(new CompletableFuture<>());
    CompletableFuture<String> future2 = spy(new CompletableFuture<>());
    CompletableFuture<String> future3 = spy(new CompletableFuture<>());
    when(connectionChecker.getReportCompFuture()).thenReturn(future1).thenReturn(future2).thenReturn(future3);
    checker.startAsync(readinessHandler);
    future2.completeExceptionally(new InfrastructureException("error"));
    try {
        checker.await();
        fail();
    } catch (InfrastructureException ignored) {
        verify(future1, never()).complete(anyString());
        verify(future2, never()).complete(anyString());
        verify(future3, never()).complete(anyString());
        verify(future1, never()).completeExceptionally(any(Throwable.class));
        verify(future2).completeExceptionally(any(Throwable.class));
        verify(future3, never()).completeExceptionally(any(Throwable.class));
    }
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) Test(org.testng.annotations.Test)

Example 48 with InfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.

the class KubernetesInternalRuntime method markStopping.

@Override
protected void markStopping() throws InfrastructureException {
    RuntimeIdentity runtimeId = getContext().getIdentity();
    // Check if runtime is in STARTING phase to actualize state of startSynchronizer.
    Optional<WorkspaceStatus> statusOpt = runtimeStates.getStatus(runtimeId);
    if (statusOpt.isPresent() && statusOpt.get() == WorkspaceStatus.STARTING) {
        startSynchronizer.start();
    }
    if (!runtimeStates.updateStatus(runtimeId, s -> s == WorkspaceStatus.RUNNING || s == WorkspaceStatus.STARTING, WorkspaceStatus.STOPPING)) {
        throw new StateException("The environment must be running or starting");
    }
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) ProbeResult(org.eclipse.che.api.workspace.server.hc.probe.ProbeResult) ServerStatus(org.eclipse.che.api.core.model.workspace.runtime.ServerStatus) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Assisted(com.google.inject.assistedinject.Assisted) KubernetesObjectUtil.putLabels(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.putLabels) KubernetesRuntimeState(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState) Collectors.toMap(java.util.stream.Collectors.toMap) PodMerger(org.eclipse.che.workspace.infrastructure.kubernetes.environment.PodMerger) Map(java.util.Map) StateException(org.eclipse.che.api.workspace.server.spi.StateException) KubernetesObjectUtil.putAnnotations(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.putAnnotations) CHECK_SERVERS(org.eclipse.che.workspace.infrastructure.kubernetes.util.TracingSpanConstants.CHECK_SERVERS) Command(org.eclipse.che.api.core.model.workspace.config.Command) WorkspaceProbes(org.eclipse.che.api.workspace.server.hc.probe.WorkspaceProbes) ImmutableMap(com.google.common.collect.ImmutableMap) KubernetesServerResolverFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.KubernetesServerResolverFactory) Collection(java.util.Collection) Set(java.util.Set) KubernetesMachineCache(org.eclipse.che.workspace.infrastructure.kubernetes.cache.KubernetesMachineCache) SidecarToolingProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.SidecarToolingProvisioner) NoOpURLRewriter(org.eclipse.che.api.workspace.server.URLRewriter.NoOpURLRewriter) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) KubernetesObjectUtil.shouldCreateInCheNamespace(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.shouldCreateInCheNamespace) Objects(java.util.Objects) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) KubernetesSharedPool(org.eclipse.che.workspace.infrastructure.kubernetes.util.KubernetesSharedPool) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) List(java.util.List) WorkspaceVolumesStrategy(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.WorkspaceVolumesStrategy) CompletionStage(java.util.concurrent.CompletionStage) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) TracingTags(org.eclipse.che.commons.tracing.TracingTags) UnrecoverablePodEventListenerFactory(org.eclipse.che.workspace.infrastructure.kubernetes.util.UnrecoverablePodEventListenerFactory) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Entry(java.util.Map.Entry) Secret(io.fabric8.kubernetes.api.model.Secret) Span(io.opentracing.Span) Optional(java.util.Optional) Scope(io.opentracing.Scope) WorkspaceProbesFactory(org.eclipse.che.api.workspace.server.hc.probe.WorkspaceProbesFactory) LogWatcher(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.log.LogWatcher) WAIT_RUNNING_ASYNC(org.eclipse.che.workspace.infrastructure.kubernetes.util.TracingSpanConstants.WAIT_RUNNING_ASYNC) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MachineStatus(org.eclipse.che.api.core.model.workspace.runtime.MachineStatus) InternalEnvironmentProvisioner(org.eclipse.che.api.workspace.server.spi.provision.InternalEnvironmentProvisioner) Container(io.fabric8.kubernetes.api.model.Container) CompletableFuture(java.util.concurrent.CompletableFuture) ServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.ServerResolver) KubernetesMachineImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl) Function(java.util.function.Function) Traced(org.eclipse.che.commons.annotation.Traced) ValidationException(org.eclipse.che.api.core.ValidationException) ArrayList(java.util.ArrayList) CheNamespace(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.CheNamespace) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) ServersChecker(org.eclipse.che.api.workspace.server.hc.ServersChecker) KubernetesNamespace(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) BiConsumer(java.util.function.BiConsumer) WAIT_MACHINES_START(org.eclipse.che.workspace.infrastructure.kubernetes.util.TracingSpanConstants.WAIT_MACHINES_START) Service(io.fabric8.kubernetes.api.model.Service) Named(javax.inject.Named) RuntimeEventsPublisher(org.eclipse.che.workspace.infrastructure.kubernetes.util.RuntimeEventsPublisher) PodLogToEventPublisher(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.log.PodLogToEventPublisher) ProbeScheduler(org.eclipse.che.api.workspace.server.hc.probe.ProbeScheduler) InternalRuntime(org.eclipse.che.api.workspace.server.spi.InternalRuntime) LogWatchTimeouts(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.log.LogWatchTimeouts) Collections.emptyMap(java.util.Collections.emptyMap) Logger(org.slf4j.Logger) Tracer(io.opentracing.Tracer) Executor(java.util.concurrent.Executor) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) Pod(io.fabric8.kubernetes.api.model.Pod) SecretAsContainerResourceProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.secret.SecretAsContainerResourceProvisioner) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) KubernetesRuntimeStateCache(org.eclipse.che.workspace.infrastructure.kubernetes.cache.KubernetesRuntimeStateCache) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) PodEvent(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent) PreviewUrlCommandProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.PreviewUrlCommandProvisioner) ProbeStatus(org.eclipse.che.api.workspace.server.hc.probe.ProbeResult.ProbeStatus) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ServersCheckerFactory(org.eclipse.che.api.workspace.server.hc.ServersCheckerFactory) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) StateException(org.eclipse.che.api.workspace.server.spi.StateException)

Example 49 with InfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.

the class KubernetesInternalRuntime method doStartMachine.

/**
 * Creates Kubernetes pods and resolves servers using the specified serverResolver.
 *
 * @param serverResolver server resolver that provide servers by container
 * @throws InfrastructureException when any error occurs while creating Kubernetes pods
 */
@Traced
protected void doStartMachine(ServerResolver serverResolver) throws InfrastructureException {
    final KubernetesEnvironment environment = getContext().getEnvironment();
    final Map<String, InternalMachineConfig> machineConfigs = environment.getMachines();
    final String workspaceId = getContext().getIdentity().getWorkspaceId();
    LOG.debug("Begin pods creation for workspace '{}'", workspaceId);
    PodMerger podMerger = new PodMerger();
    Map<String, Map<String, Pod>> injectablePods = environment.getInjectablePodsCopy();
    for (Pod toCreate : environment.getPodsCopy().values()) {
        ObjectMeta toCreateMeta = toCreate.getMetadata();
        List<PodData> injectables = getAllInjectablePods(toCreate, injectablePods);
        Pod createdPod;
        if (injectables.isEmpty()) {
            createdPod = namespace.deployments().deploy(toCreate);
        } else {
            try {
                injectables.add(new PodData(toCreate));
                Deployment merged = podMerger.merge(injectables);
                merged.getMetadata().setName(toCreate.getMetadata().getName());
                createdPod = namespace.deployments().deploy(merged);
            } catch (ValidationException e) {
                throw new InfrastructureException(e);
            }
        }
        LOG.debug("Creating pod '{}' in workspace '{}'", toCreateMeta.getName(), workspaceId);
        storeStartingMachine(createdPod, createdPod.getMetadata(), machineConfigs, serverResolver);
    }
    for (Deployment toCreate : environment.getDeploymentsCopy().values()) {
        PodTemplateSpec template = toCreate.getSpec().getTemplate();
        List<PodData> injectables = getAllInjectablePods(template.getMetadata(), template.getSpec().getContainers(), injectablePods);
        Pod createdPod;
        if (injectables.isEmpty()) {
            createdPod = namespace.deployments().deploy(toCreate);
        } else {
            try {
                injectables.add(new PodData(toCreate));
                Deployment deployment = podMerger.merge(injectables);
                deployment.getMetadata().setName(toCreate.getMetadata().getName());
                putAnnotations(deployment.getMetadata(), toCreate.getMetadata().getAnnotations());
                putLabels(deployment.getMetadata(), toCreate.getMetadata().getLabels());
                createdPod = namespace.deployments().deploy(deployment);
            } catch (ValidationException e) {
                throw new InfrastructureException(e);
            }
        }
        LOG.debug("Creating deployment '{}' in workspace '{}'", createdPod.getMetadata().getName(), workspaceId);
        storeStartingMachine(createdPod, createdPod.getMetadata(), machineConfigs, serverResolver);
    }
    LOG.debug("Pods creation finished in workspace '{}'", workspaceId);
}
Also used : PodMerger(org.eclipse.che.workspace.infrastructure.kubernetes.environment.PodMerger) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ValidationException(org.eclipse.che.api.core.ValidationException) Pod(io.fabric8.kubernetes.api.model.Pod) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Collections.emptyMap(java.util.Collections.emptyMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) Traced(org.eclipse.che.commons.annotation.Traced)

Example 50 with InfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.

the class KubernetesInternalRuntime method scheduleServersCheckers.

/**
 * Schedules server checkers.
 *
 * <p>Note that if the runtime is {@link WorkspaceStatus#RUNNING} then checkers will be scheduled
 * immediately. If the runtime is {@link WorkspaceStatus#STARTING} then checkers will be scheduled
 * when it becomes {@link WorkspaceStatus#RUNNING}. If runtime has any another status then
 * checkers won't be scheduled at all.
 *
 * @throws InfrastructureException when any exception occurred
 */
public void scheduleServersCheckers() throws InfrastructureException {
    WorkspaceStatus status = getStatus();
    if (status != WorkspaceStatus.RUNNING && status != WorkspaceStatus.STARTING) {
        return;
    }
    ServerLivenessHandler consumer = new ServerLivenessHandler();
    WorkspaceProbes probes = probesFactory.getProbes(getContext().getIdentity(), getInternalMachines());
    if (status == WorkspaceStatus.RUNNING) {
        probeScheduler.schedule(probes, consumer);
    } else {
        // Workspace is starting it is needed to start servers checkers when it becomes RUNNING
        probeScheduler.schedule(probes, consumer, () -> {
            try {
                return getStatus();
            } catch (InfrastructureException e) {
                throw new RuntimeException(e.getMessage());
            }
        });
    }
}
Also used : WorkspaceProbes(org.eclipse.che.api.workspace.server.hc.probe.WorkspaceProbes) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)

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