Search in sources :

Example 56 with InfrastructureException

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;
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) ServerException(org.eclipse.che.api.core.ServerException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 57 with InfrastructureException

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();
}
Also used : MachineId(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl.MachineId) EntityManager(javax.persistence.EntityManager) KubernetesMachineImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) Transactional(com.google.inject.persist.Transactional)

Example 58 with InfrastructureException

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);
    }
}
Also used : KubernetesServerImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesServerImpl) ServerId(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesServerImpl.ServerId) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) Transactional(com.google.inject.persist.Transactional)

Example 59 with InfrastructureException

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();
}
Also used : EntityManager(javax.persistence.EntityManager) KubernetesRuntimeState(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) Transactional(com.google.inject.persist.Transactional)

Example 60 with InfrastructureException

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");
    }
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Aggregations

InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)242 InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)64 Test (org.testng.annotations.Test)56 KubernetesInfrastructureException (org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException)44 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)42 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)38 CompletableFuture (java.util.concurrent.CompletableFuture)36 ExecutionException (java.util.concurrent.ExecutionException)36 TimeoutException (java.util.concurrent.TimeoutException)32 ServerException (org.eclipse.che.api.core.ServerException)32 Pod (io.fabric8.kubernetes.api.model.Pod)30 Map (java.util.Map)26 ValidationException (org.eclipse.che.api.core.ValidationException)22 Traced (org.eclipse.che.commons.annotation.Traced)20 Container (io.fabric8.kubernetes.api.model.Container)18 List (java.util.List)18 Set (java.util.Set)18 Inject (javax.inject.Inject)18 RuntimeStartInterruptedException (org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException)18 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)18