use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class KubernetesNamespaceTest method testKubernetesNamespaceCleaningUpIfExceptionsOccurs.
@Test
public void testKubernetesNamespaceCleaningUpIfExceptionsOccurs() throws Exception {
doThrow(new InfrastructureException("err1.")).when(services).delete();
doThrow(new InfrastructureException("err2.")).when(deployments).delete();
InfrastructureException error = null;
// when
try {
k8sNamespace.cleanUp();
} catch (InfrastructureException e) {
error = e;
}
// then
assertNotNull(error);
String message = error.getMessage();
assertEquals(message, "Error(s) occurs while cleaning up the namespace. err1. err2.");
verify(ingresses).delete();
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class ServersCheckerTest method awaitShouldReturnOnFirstUnavailability.
@Test(timeOut = 5000)
public void awaitShouldReturnOnFirstUnavailability() throws Exception {
CompletableFuture<String> future1 = spy(new CompletableFuture<>());
CompletableFuture<String> future2 = spy(new CompletableFuture<>());
CompletableFuture<String> future3 = spy(new CompletableFuture<>());
when(connectionChecker.getReportCompFuture()).thenReturn(future1).thenReturn(future2).thenReturn(future3);
checker.startAsync(readinessHandler);
future2.completeExceptionally(new InfrastructureException("error"));
try {
checker.await();
fail();
} catch (InfrastructureException ignored) {
verify(future1, never()).complete(anyString());
verify(future2, never()).complete(anyString());
verify(future3, never()).complete(anyString());
verify(future1, never()).completeExceptionally(any(Throwable.class));
verify(future2).completeExceptionally(any(Throwable.class));
verify(future3, never()).completeExceptionally(any(Throwable.class));
}
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class KubernetesInternalRuntime method markStopping.
@Override
protected void markStopping() throws InfrastructureException {
RuntimeIdentity runtimeId = getContext().getIdentity();
// Check if runtime is in STARTING phase to actualize state of startSynchronizer.
Optional<WorkspaceStatus> statusOpt = runtimeStates.getStatus(runtimeId);
if (statusOpt.isPresent() && statusOpt.get() == WorkspaceStatus.STARTING) {
startSynchronizer.start();
}
if (!runtimeStates.updateStatus(runtimeId, s -> s == WorkspaceStatus.RUNNING || s == WorkspaceStatus.STARTING, WorkspaceStatus.STOPPING)) {
throw new StateException("The environment must be running or starting");
}
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class KubernetesInternalRuntime method doStartMachine.
/**
* Creates Kubernetes pods and resolves servers using the specified serverResolver.
*
* @param serverResolver server resolver that provide servers by container
* @throws InfrastructureException when any error occurs while creating Kubernetes pods
*/
@Traced
protected void doStartMachine(ServerResolver serverResolver) throws InfrastructureException {
final KubernetesEnvironment environment = getContext().getEnvironment();
final Map<String, InternalMachineConfig> machineConfigs = environment.getMachines();
final String workspaceId = getContext().getIdentity().getWorkspaceId();
LOG.debug("Begin pods creation for workspace '{}'", workspaceId);
PodMerger podMerger = new PodMerger();
Map<String, Map<String, Pod>> injectablePods = environment.getInjectablePodsCopy();
for (Pod toCreate : environment.getPodsCopy().values()) {
ObjectMeta toCreateMeta = toCreate.getMetadata();
List<PodData> injectables = getAllInjectablePods(toCreate, injectablePods);
Pod createdPod;
if (injectables.isEmpty()) {
createdPod = namespace.deployments().deploy(toCreate);
} else {
try {
injectables.add(new PodData(toCreate));
Deployment merged = podMerger.merge(injectables);
merged.getMetadata().setName(toCreate.getMetadata().getName());
createdPod = namespace.deployments().deploy(merged);
} catch (ValidationException e) {
throw new InfrastructureException(e);
}
}
LOG.debug("Creating pod '{}' in workspace '{}'", toCreateMeta.getName(), workspaceId);
storeStartingMachine(createdPod, createdPod.getMetadata(), machineConfigs, serverResolver);
}
for (Deployment toCreate : environment.getDeploymentsCopy().values()) {
PodTemplateSpec template = toCreate.getSpec().getTemplate();
List<PodData> injectables = getAllInjectablePods(template.getMetadata(), template.getSpec().getContainers(), injectablePods);
Pod createdPod;
if (injectables.isEmpty()) {
createdPod = namespace.deployments().deploy(toCreate);
} else {
try {
injectables.add(new PodData(toCreate));
Deployment deployment = podMerger.merge(injectables);
deployment.getMetadata().setName(toCreate.getMetadata().getName());
putAnnotations(deployment.getMetadata(), toCreate.getMetadata().getAnnotations());
putLabels(deployment.getMetadata(), toCreate.getMetadata().getLabels());
createdPod = namespace.deployments().deploy(deployment);
} catch (ValidationException e) {
throw new InfrastructureException(e);
}
}
LOG.debug("Creating deployment '{}' in workspace '{}'", createdPod.getMetadata().getName(), workspaceId);
storeStartingMachine(createdPod, createdPod.getMetadata(), machineConfigs, serverResolver);
}
LOG.debug("Pods creation finished in workspace '{}'", workspaceId);
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class KubernetesInternalRuntime method scheduleServersCheckers.
/**
* Schedules server checkers.
*
* <p>Note that if the runtime is {@link WorkspaceStatus#RUNNING} then checkers will be scheduled
* immediately. If the runtime is {@link WorkspaceStatus#STARTING} then checkers will be scheduled
* when it becomes {@link WorkspaceStatus#RUNNING}. If runtime has any another status then
* checkers won't be scheduled at all.
*
* @throws InfrastructureException when any exception occurred
*/
public void scheduleServersCheckers() throws InfrastructureException {
WorkspaceStatus status = getStatus();
if (status != WorkspaceStatus.RUNNING && status != WorkspaceStatus.STARTING) {
return;
}
ServerLivenessHandler consumer = new ServerLivenessHandler();
WorkspaceProbes probes = probesFactory.getProbes(getContext().getIdentity(), getInternalMachines());
if (status == WorkspaceStatus.RUNNING) {
probeScheduler.schedule(probes, consumer);
} else {
// Workspace is starting it is needed to start servers checkers when it becomes RUNNING
probeScheduler.schedule(probes, consumer, () -> {
try {
return getStatus();
} catch (InfrastructureException e) {
throw new RuntimeException(e.getMessage());
}
});
}
}
Aggregations