Search in sources :

Example 1 with RuntimeLogsPublisher

use of org.eclipse.che.workspace.infrastructure.kubernetes.RuntimeLogsPublisher 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 2 with RuntimeLogsPublisher

use of org.eclipse.che.workspace.infrastructure.kubernetes.RuntimeLogsPublisher 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)

Aggregations

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 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 UnrecoverablePodEventListener (org.eclipse.che.workspace.infrastructure.kubernetes.util.UnrecoverablePodEventListener)2