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();
}
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);
}
}
}
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);
}
}
}
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();
}
Aggregations