use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class InconsistentRuntimesDetector method getKubernetesInternalRuntime.
private KubernetesInternalRuntime getKubernetesInternalRuntime(String workspaceId) throws InfrastructureException {
InternalRuntime<?> internalRuntime;
try {
internalRuntime = workspaceRuntimes.getInternalRuntime(workspaceId);
} catch (InfrastructureException | ServerException e) {
throw new InfrastructureException(format("Failed to get internal runtime for workspace `%s` to check consistency. Cause: %s", workspaceId, e.getMessage()), e);
}
RuntimeIdentity runtimeId = internalRuntime.getContext().getIdentity();
if (!(internalRuntime instanceof KubernetesInternalRuntime)) {
// must not happen
throw new InfrastructureException(format("Fetched internal runtime '%s:%s' is not Kubernetes, it is not possible to check consistency.", runtimeId.getWorkspaceId(), runtimeId.getOwnerId()));
}
return (KubernetesInternalRuntime) internalRuntime;
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class JpaKubernetesMachineCache method doUpdateMachineStatus.
@Transactional
protected void doUpdateMachineStatus(String workspaceId, String machineName, MachineStatus status) throws InfrastructureException {
EntityManager entityManager = managerProvider.get();
KubernetesMachineImpl machine = entityManager.find(KubernetesMachineImpl.class, new MachineId(workspaceId, machineName));
if (machine == null) {
throw new InfrastructureException(format("Machine '%s:%s' was not found", workspaceId, machineName));
}
machine.setStatus(status);
entityManager.flush();
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class JpaKubernetesMachineCache method getServer.
@Transactional(rollbackOn = InfrastructureException.class)
@Override
public KubernetesServerImpl getServer(RuntimeIdentity runtimeIdentity, String machineName, String serverName) throws InfrastructureException {
try {
String workspaceId = runtimeIdentity.getWorkspaceId();
KubernetesServerImpl server = managerProvider.get().find(KubernetesServerImpl.class, new ServerId(workspaceId, machineName, serverName));
if (server == null) {
throw new InfrastructureException(format("Server with name '%s' was not found", serverName));
}
return server;
} catch (RuntimeException e) {
throw new InfrastructureException(e.getMessage(), e);
}
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class JpaKubernetesRuntimeStateCache method doUpdateStatus.
@Transactional(rollbackOn = { RuntimeException.class, InfrastructureException.class })
protected void doUpdateStatus(RuntimeIdentity id, Predicate<WorkspaceStatus> predicate, WorkspaceStatus newStatus) throws InfrastructureException {
EntityManager entityManager = managerProvider.get();
Optional<KubernetesRuntimeState> existingStateOpt = get(id);
if (!existingStateOpt.isPresent()) {
throw new InfrastructureException("Runtime state for workspace with id '" + id.getWorkspaceId() + "' was not found");
}
KubernetesRuntimeState existingState = existingStateOpt.get();
if (!predicate.test(existingState.getStatus())) {
throw new IllegalStateException("Runtime status doesn't match to the specified predicate");
}
existingState.setStatus(newStatus);
entityManager.flush();
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
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