Search in sources :

Example 21 with InfrastructureException

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

the class SidecarServicesProvisioner method provision.

/**
 * Add k8s Service objects to environment to provide service discovery in sidecar based
 * workspaces.
 */
public void provision(KubernetesEnvironment kubernetesEnvironment) throws InfrastructureException {
    for (ChePluginEndpoint endpoint : endpoints) {
        if (!isDiscoverable(endpoint)) {
            continue;
        }
        String serviceName = endpoint.getName();
        Service service = createService(serviceName, podName, endpoint.getTargetPort());
        Map<String, Service> services = kubernetesEnvironment.getServices();
        if (!services.containsKey(serviceName)) {
            services.put(serviceName, service);
        } else {
            throw new InfrastructureException(format("Applying of sidecar tooling failed. Kubernetes service with name '%s' already exists in the workspace environment.", serviceName));
        }
    }
}
Also used : ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) Service(io.fabric8.kubernetes.api.model.Service) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 22 with InfrastructureException

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

the class DeployBroker method handleUnrecoverableEvent.

private void handleUnrecoverableEvent(PodEvent podEvent) {
    String reason = podEvent.getReason();
    String message = podEvent.getMessage();
    LOG.error("Unrecoverable event occurred during plugin brokering for workspace '{}' startup: {}, {}, {}", runtimeId.getWorkspaceId(), reason, message, podEvent.getPodName());
    brokersResult.error(new InfrastructureException(format("Unrecoverable event occurred: '%s', '%s', '%s'", reason, message, podEvent.getPodName())));
}
Also used : InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 23 with InfrastructureException

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

the class DeployBroker method execute.

@Override
public List<ChePlugin> execute() throws InfrastructureException {
    LOG.debug("Starting brokers pod for workspace '{}'", runtimeId.getWorkspaceId());
    Span tracingSpan = tracer.buildSpan(DEPLOY_BROKER_PHASE).start();
    TracingTags.WORKSPACE_ID.set(tracingSpan, runtimeId.getWorkspaceId());
    KubernetesDeployments deployments = namespace.deployments();
    try {
        // broker in a workspace.
        for (ConfigMap configMap : brokerEnvironment.getConfigMaps().values()) {
            namespace.configMaps().create(configMap);
        }
        for (Secret secret : brokerEnvironment.getSecrets().values()) {
            namespace.secrets().create(secret);
        }
        Pod pluginBrokerPod = getPluginBrokerPod(brokerEnvironment.getPodsCopy());
        if (factory.isConfigured()) {
            UnrecoverablePodEventListener unrecoverableEventListener = factory.create(ImmutableSet.of(pluginBrokerPod.getMetadata().getName()), this::handleUnrecoverableEvent);
            namespace.deployments().watchEvents(unrecoverableEventListener);
        }
        namespace.deployments().watchEvents(new RuntimeLogsPublisher(runtimeEventsPublisher, runtimeId, ImmutableSet.of(pluginBrokerPod.getMetadata().getName())));
        deployments.create(pluginBrokerPod);
        watchLogsIfDebugEnabled(startOptions, pluginBrokerPod);
        LOG.debug("Brokers pod is created for workspace '{}'", runtimeId.getWorkspaceId());
        tracingSpan.finish();
        return nextPhase.execute();
    } catch (InfrastructureException e) {
        namespace.deployments().stopWatch(true);
        // Ensure span is finished with exception message
        TracingTags.setErrorStatus(tracingSpan, e);
        tracingSpan.finish();
        throw e;
    } finally {
        namespace.deployments().stopWatch();
        try {
            deployments.delete();
        } catch (InfrastructureException e) {
            LOG.error("Brokers pod removal failed. Error: " + e.getLocalizedMessage(), e);
        }
        try {
            namespace.secrets().delete();
        } catch (InfrastructureException ex) {
            LOG.error("Brokers secret removal failed. Error: " + ex.getLocalizedMessage(), ex);
        }
        try {
            namespace.configMaps().delete();
        } catch (InfrastructureException ex) {
            LOG.error("Brokers config map removal failed. Error: " + ex.getLocalizedMessage(), ex);
        }
    }
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) RuntimeLogsPublisher(org.eclipse.che.workspace.infrastructure.kubernetes.RuntimeLogsPublisher) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Pod(io.fabric8.kubernetes.api.model.Pod) UnrecoverablePodEventListener(org.eclipse.che.workspace.infrastructure.kubernetes.util.UnrecoverablePodEventListener) Span(io.opentracing.Span) KubernetesDeployments(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesDeployments) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 24 with InfrastructureException

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

the class StartSynchronizerTest method shouldReturnStartFailureWhenItIsCompletedExceptionally.

@Test
public void shouldReturnStartFailureWhenItIsCompletedExceptionally() {
    // given
    InfrastructureException toThrow = new RuntimeStartInterruptedException(runtimeId);
    startSynchronizer.completeExceptionally(toThrow);
    // when
    InfrastructureException startFailure = startSynchronizer.getStartFailureNow();
    // then
    assertTrue(startFailure instanceof RuntimeStartInterruptedException);
    assertEquals(startFailure, toThrow);
}
Also used : RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) Test(org.testng.annotations.Test)

Example 25 with InfrastructureException

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

the class InconsistentRuntimesDetectorTest method shouldMarkRuntimeAsStoppedEvenWhenExceptionOccursDuringRuntimeStoppingOnCheckingConsistency.

@Test
public void shouldMarkRuntimeAsStoppedEvenWhenExceptionOccursDuringRuntimeStoppingOnCheckingConsistency() throws Exception {
    // given
    doReturn(k8sRuntime).when(workspaceRuntimes).getInternalRuntime("workspace1");
    doReturn(false).when(k8sRuntime).isConsistent();
    doThrow(new InfrastructureException("error")).when(k8sRuntime).stop(any());
    // when
    InfrastructureException caughtException = null;
    try {
        inconsistentRuntimesDetector.checkOne("workspace1");
    } catch (InfrastructureException e) {
        caughtException = e;
    }
    // then
    assertNotNull(caughtException);
    assertEquals(caughtException.getMessage(), "Failed to stop the runtime 'workspace1:owner1' which has inconsistent state. Error: error");
    verify(k8sRuntime).stop(emptyMap());
    verify(eventPublisher).sendAbnormalStoppingEvent(runtimeId, "The runtime has inconsistent state.");
    verify(eventPublisher).sendAbnormalStoppedEvent(runtimeId, "The runtime has inconsistent state.");
}
Also used : InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) Test(org.testng.annotations.Test)

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