Search in sources :

Example 1 with UnrecoverablePodEventListener

use of org.eclipse.che.workspace.infrastructure.kubernetes.util.UnrecoverablePodEventListener in project che-server by eclipse-che.

the class DeployBrokerTest method shouldListenToUnrecoverableEventsIfFactoryIsConfigured.

@Test
public void shouldListenToUnrecoverableEventsIfFactoryIsConfigured() throws Exception {
    // given
    when(unrecoverableEventListenerFactory.isConfigured()).thenReturn(true);
    UnrecoverablePodEventListener listener = mock(UnrecoverablePodEventListener.class);
    when(unrecoverableEventListenerFactory.create(any(Set.class), any())).thenReturn(listener);
    // when
    deployBrokerPhase.execute();
    // then
    verify(unrecoverableEventListenerFactory).isConfigured();
    verify(unrecoverableEventListenerFactory).create(eq(ImmutableSet.of(PLUGIN_BROKER_POD_NAME)), any());
    verify(k8sDeployments).watchEvents(listener);
    verify(k8sDeployments).stopWatch();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) UnrecoverablePodEventListener(org.eclipse.che.workspace.infrastructure.kubernetes.util.UnrecoverablePodEventListener) Test(org.testng.annotations.Test)

Example 2 with UnrecoverablePodEventListener

use of org.eclipse.che.workspace.infrastructure.kubernetes.util.UnrecoverablePodEventListener 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 3 with UnrecoverablePodEventListener

use of org.eclipse.che.workspace.infrastructure.kubernetes.util.UnrecoverablePodEventListener in project devspaces-images by redhat-developer.

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 4 with UnrecoverablePodEventListener

use of org.eclipse.che.workspace.infrastructure.kubernetes.util.UnrecoverablePodEventListener in project devspaces-images by redhat-developer.

the class DeployBrokerTest method shouldListenToUnrecoverableEventsIfFactoryIsConfigured.

@Test
public void shouldListenToUnrecoverableEventsIfFactoryIsConfigured() throws Exception {
    // given
    when(unrecoverableEventListenerFactory.isConfigured()).thenReturn(true);
    UnrecoverablePodEventListener listener = mock(UnrecoverablePodEventListener.class);
    when(unrecoverableEventListenerFactory.create(any(Set.class), any())).thenReturn(listener);
    // when
    deployBrokerPhase.execute();
    // then
    verify(unrecoverableEventListenerFactory).isConfigured();
    verify(unrecoverableEventListenerFactory).create(eq(ImmutableSet.of(PLUGIN_BROKER_POD_NAME)), any());
    verify(k8sDeployments).watchEvents(listener);
    verify(k8sDeployments).stopWatch();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) UnrecoverablePodEventListener(org.eclipse.che.workspace.infrastructure.kubernetes.util.UnrecoverablePodEventListener) Test(org.testng.annotations.Test)

Aggregations

UnrecoverablePodEventListener (org.eclipse.che.workspace.infrastructure.kubernetes.util.UnrecoverablePodEventListener)4 ImmutableSet (com.google.common.collect.ImmutableSet)2 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 Secret (io.fabric8.kubernetes.api.model.Secret)2 Span (io.opentracing.Span)2 Set (java.util.Set)2 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)2 InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)2 RuntimeLogsPublisher (org.eclipse.che.workspace.infrastructure.kubernetes.RuntimeLogsPublisher)2 KubernetesDeployments (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesDeployments)2 Test (org.testng.annotations.Test)2