use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project devspaces-images by redhat-developer.
the class KubernetesInternalRuntime method internalStop.
@Traced
@Override
protected void internalStop(Map<String, String> stopOptions) throws InfrastructureException {
RuntimeIdentity identity = getContext().getIdentity();
TracingTags.WORKSPACE_ID.set(identity.getWorkspaceId());
runtimeHangingDetector.stopTracking(getContext().getIdentity());
if (startSynchronizer.interrupt()) {
// runtime is STARTING. Need to wait until start will be interrupted properly
try {
if (!startSynchronizer.awaitInterruption(workspaceStartTimeoutMin, TimeUnit.MINUTES)) {
// Runtime is not interrupted yet. It may occur when start was performing by another
// Che Server that is crashed so start is hung up in STOPPING phase.
// Need to clean up runtime resources
probeScheduler.cancel(identity.getWorkspaceId());
runtimeCleaner.cleanUp(namespace, identity.getWorkspaceId());
}
} catch (InterruptedException e) {
throw new InfrastructureException("Interrupted while waiting for start task cancellation", e);
}
} else {
// runtime is RUNNING. Clean up used resources
// Cancels workspace servers probes if any
probeScheduler.cancel(identity.getWorkspaceId());
runtimeCleaner.cleanUp(namespace, identity.getWorkspaceId());
}
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project devspaces-images by redhat-developer.
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 devspaces-images by redhat-developer.
the class KubernetesInternalRuntime method internalStart.
@Override
protected void internalStart(Map<String, String> startOptions) throws InfrastructureException {
KubernetesRuntimeContext<E> context = getContext();
String workspaceId = context.getIdentity().getWorkspaceId();
try {
startSynchronizer.setStartThread();
startSynchronizer.start();
runtimeCleaner.cleanUp(namespace, workspaceId);
provisionWorkspace(startOptions, context, workspaceId);
volumesStrategy.prepare(context.getEnvironment(), context.getIdentity(), startSynchronizer.getStartTimeoutMillis(), startOptions);
startSynchronizer.checkFailure();
startMachines();
watchLogsIfDebugEnabled(startOptions);
previewUrlCommandProvisioner.provision(context.getEnvironment(), namespace);
runtimeStates.updateCommands(context.getIdentity(), context.getEnvironment().getCommands());
startSynchronizer.checkFailure();
final Map<String, CompletableFuture<Void>> machinesFutures = new LinkedHashMap<>();
// futures that must be cancelled explicitly
final List<CompletableFuture<?>> toCancelFutures = new CopyOnWriteArrayList<>();
final EnvironmentContext currentContext = EnvironmentContext.getCurrent();
CompletableFuture<Void> startFailure = startSynchronizer.getStartFailure();
Span waitRunningAsyncSpan = tracer.buildSpan(WAIT_MACHINES_START).start();
try (Scope waitRunningAsyncScope = tracer.scopeManager().activate(waitRunningAsyncSpan)) {
TracingTags.WORKSPACE_ID.set(waitRunningAsyncSpan, workspaceId);
for (KubernetesMachineImpl machine : machines.getMachines(context.getIdentity()).values()) {
String machineName = machine.getName();
final CompletableFuture<Void> machineBootChain = waitRunningAsync(toCancelFutures, machine).thenComposeAsync(checkFailure(startFailure), executor).thenRun(publishRunningStatus(machineName)).thenCompose(checkFailure(startFailure)).thenCompose(setContext(currentContext, checkServers(toCancelFutures, machine))).exceptionally(publishFailedStatus(startFailure, machineName));
machinesFutures.put(machineName, machineBootChain);
}
waitMachines(machinesFutures, toCancelFutures, startFailure);
} finally {
waitRunningAsyncSpan.finish();
}
startSynchronizer.complete();
} catch (InfrastructureException | RuntimeException e) {
Exception startFailureCause = startSynchronizer.getStartFailureNow();
if (startFailureCause == null) {
startFailureCause = e;
}
startSynchronizer.completeExceptionally(startFailureCause);
LOG.warn("Failed to start Kubernetes runtime of workspace {}.", workspaceId, startFailureCause);
boolean interrupted = Thread.interrupted() || startFailureCause instanceof RuntimeStartInterruptedException;
// Cancels workspace servers probes if any
probeScheduler.cancel(workspaceId);
// stop watching before namespace cleaning up
namespace.deployments().stopWatch(true);
try {
runtimeCleaner.cleanUp(namespace, workspaceId);
} catch (InfrastructureException cleanUppingEx) {
LOG.warn("Failed to clean up namespace after workspace '{}' start failing.", context.getIdentity().getWorkspaceId(), cleanUppingEx);
}
if (interrupted) {
throw new RuntimeStartInterruptedException(getContext().getIdentity());
}
wrapAndRethrow(startFailureCause);
} finally {
namespace.deployments().stopWatch();
}
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project devspaces-images by redhat-developer.
the class RuntimeHangingDetector method handleHangingStoppingRuntime.
private void handleHangingStoppingRuntime(KubernetesInternalRuntime runtime) {
RuntimeIdentity runtimeId = runtime.getContext().getIdentity();
eventPublisher.sendAbnormalStoppingEvent(runtimeId, "Workspace is not stopped in time. Trying to stop it forcibly");
try {
LOG.info("Runtime '{}:{}:{}' is not stopped in time. Stopped it forcibly", runtimeId.getWorkspaceId(), runtimeId.getEnvName(), runtimeId.getOwnerId());
runtime.internalStop(emptyMap());
} catch (InfrastructureException e) {
LOG.error("Error occurred during forcibly stopping of hanging runtime '{}:{}:{}'. Error: {}", runtimeId.getWorkspaceId(), runtimeId.getEnvName(), runtimeId.getOwnerId(), e.getMessage(), e);
} finally {
try {
runtime.markStopped();
} catch (InfrastructureException e) {
LOG.error("Error occurred during marking hanging runtime as stopped '{}:{}:{}'. Error: {}", runtimeId.getWorkspaceId(), runtimeId.getEnvName(), runtimeId.getOwnerId(), e.getMessage(), e);
}
eventPublisher.sendAbnormalStoppedEvent(runtimeId, "Workspace stop reached timeout");
}
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project devspaces-images by redhat-developer.
the class RuntimeHangingDetector method handleHangingStartingRuntime.
private void handleHangingStartingRuntime(KubernetesInternalRuntime runtime) {
RuntimeIdentity runtimeId = runtime.getContext().getIdentity();
eventPublisher.sendAbnormalStoppingEvent(runtimeId, "Workspace is not started in time. Trying interrupt runtime start");
try {
runtime.stop(emptyMap());
LOG.info("Start of hanging runtime '{}:{}:{}' is interrupted", runtimeId.getWorkspaceId(), runtimeId.getEnvName(), runtimeId.getOwnerId());
} catch (InfrastructureException e) {
LOG.error("Error occurred during start interruption of hanging runtime '{}:{}:{}'. Error: {}", runtimeId.getWorkspaceId(), runtimeId.getEnvName(), runtimeId.getOwnerId(), e.getMessage(), e);
} finally {
eventPublisher.sendAbnormalStoppedEvent(runtimeId, "Workspace start reached timeout");
}
}
Aggregations