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