use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project devspaces-images by redhat-developer.
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.core.model.workspace.runtime.RuntimeIdentity 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.core.model.workspace.runtime.RuntimeIdentity 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.core.model.workspace.runtime.RuntimeIdentity 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");
}
}
use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project devspaces-images by redhat-developer.
the class InconsistentRuntimesDetector method checkOne.
@VisibleForTesting
void checkOne(String workspaceId) throws InfrastructureException {
LOG.debug("Checking consistency of runtime for workspace `{}`", workspaceId);
KubernetesInternalRuntime k8sRuntime = getKubernetesInternalRuntime(workspaceId);
RuntimeIdentity runtimeId = k8sRuntime.getContext().getIdentity();
try {
if (k8sRuntime.isConsistent()) {
return;
}
} catch (InfrastructureException e) {
throw new InfrastructureException(format("Error occurred during runtime '%s:%s' consistency checking. Cause: %s", runtimeId.getWorkspaceId(), runtimeId.getOwnerId(), e.getMessage()), e);
}
// not to initialize abnormal stop for a runtime that is not RUNNING anymore
if (!isRunning(k8sRuntime)) {
return;
}
LOG.warn("Found runtime `{}:{}` with inconsistent state. It's going to be stopped automatically", runtimeId.getWorkspaceId(), runtimeId.getOwnerId());
stopAbnormally(k8sRuntime);
LOG.debug("Checking consistency of runtime for workspace `{}` is finished", workspaceId);
}
Aggregations