Search in sources :

Example 31 with InfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.

the class WorkspaceRuntimes method recover.

@VisibleForTesting
void recover() {
    if (isStartRefused.get()) {
        LOG.warn("Recovery of the workspaces is rejected.");
        return;
    }
    Set<RuntimeIdentity> identities;
    try {
        identities = infrastructure.getIdentities();
    } catch (UnsupportedOperationException e) {
        LOG.warn("Not recoverable infrastructure: '{}'", infrastructure.getName());
        return;
    } catch (InfrastructureException e) {
        LOG.error("An error occurred while attempting to get runtime identities for infrastructure '{}'. Reason: '{}'", infrastructure.getName(), e.getMessage());
        return;
    }
    LOG.info("Infrastructure is tracking {} active runtimes", identities.size());
    if (identities.isEmpty()) {
        return;
    }
    for (RuntimeIdentity identity : identities) {
        String workspaceId = identity.getWorkspaceId();
        try (Unlocker ignored = lockService.writeLock(workspaceId)) {
            statuses.putIfAbsent(workspaceId, STARTING);
        }
    }
    sharedPool.execute(new RecoverRuntimesTask(identities));
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Unlocker(org.eclipse.che.commons.lang.concurrent.Unlocker) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 32 with InfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.

the class DefaultEditorProvisioner method provisionAsyncStoragePlugin.

/**
 * Provision the for async storage service, it will provide ability backup and restore project
 * source using special storage. Will torn on only if workspace start in Ephemeral mode and has
 * attribute 'asyncPersist = true'
 *
 * @param components The set of components currently present in the Devfile
 * @param contentProvider content provider for plugin references retrieval
 * @throws DevfileException - A DevfileException containing any caught InfrastructureException
 */
private void provisionAsyncStoragePlugin(List<ComponentImpl> components, FileContentProvider contentProvider) throws DevfileException {
    try {
        Map<String, String> missingPluginsIdToRef = Collections.singletonMap(componentFQNParser.getPluginPublisherAndName(asyncStoragePluginRef), asyncStoragePluginRef);
        addMissingPlugins(components, contentProvider, missingPluginsIdToRef);
    } catch (InfrastructureException e) {
        throw new DevfileException(e.getMessage(), e);
    }
}
Also used : DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 33 with InfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.

the class DefaultEditorProvisioner method provisionDefaultPlugins.

/**
 * Provision the default editor plugins and add them to the the Devfile's component list
 *
 * @param components The set of components currently present in the Devfile
 * @param contentProvider content provider for plugin references retrieval
 * @throws DevfileException - A DevfileException containing any caught InfrastructureException
 */
private void provisionDefaultPlugins(List<ComponentImpl> components, FileContentProvider contentProvider) throws DevfileException {
    Map<String, String> missingPluginsIdToRef = new HashMap<>(defaultPluginsToRefs);
    removeAlreadyAddedPlugins(components, contentProvider, missingPluginsIdToRef);
    try {
        addMissingPlugins(components, contentProvider, missingPluginsIdToRef);
    } catch (InfrastructureException e) {
        throw new DevfileException(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 34 with InfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.

the class WorkspaceLinksGenerator method addRuntimeLinks.

private void addRuntimeLinks(Map<String, String> links, String workspaceId, ServiceContext serviceContext) throws ServerException {
    URI uri = serviceContext.getServiceUriBuilder().build();
    links.put(LINK_REL_ENVIRONMENT_STATUS_CHANNEL, UriBuilder.fromUri(cheWebsocketEndpoint).scheme(uri.getScheme().equals("https") ? "wss" : "ws").host(uri.getHost()).port(uri.getPort()).build().toString());
    Optional<RuntimeContext> ctxOpt = workspaceRuntimes.getRuntimeContext(workspaceId);
    if (ctxOpt.isPresent()) {
        try {
            links.put(LINK_REL_ENVIRONMENT_OUTPUT_CHANNEL, ctxOpt.get().getOutputChannel().toString());
        } catch (UnsupportedOperationException e) {
        // Do not include output channel to links since it is not supported by context
        } catch (InfrastructureException x) {
            throw new ServerException(x.getMessage(), x);
        }
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) RuntimeContext(org.eclipse.che.api.workspace.server.spi.RuntimeContext) URI(java.net.URI) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 35 with InfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.

the class WorkspaceManager method stopWorkspace.

/**
 * Asynchronously stops the workspace.
 *
 * @param workspaceId the id of the workspace to stop
 * @throws ServerException when any server error occurs
 * @throws NullPointerException when {@code workspaceId} is null
 * @throws NotFoundException when workspace {@code workspaceId} doesn't have runtime
 */
public void stopWorkspace(String workspaceId, Map<String, String> options) throws ServerException, NotFoundException, ConflictException {
    requireNonNull(workspaceId, "Required non-null workspace id");
    final WorkspaceImpl workspace = normalizeState(workspaceDao.get(workspaceId), true);
    checkWorkspaceIsRunningOrStarting(workspace);
    if (!workspace.isTemporary()) {
        workspace.getAttributes().put(STOPPED_ATTRIBUTE_NAME, Long.toString(currentTimeMillis()));
        workspace.getAttributes().put(STOPPED_ABNORMALLY_ATTRIBUTE_NAME, Boolean.toString(false));
        workspaceDao.update(workspace);
    }
    String namespace = workspace.getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE);
    final String owner = workspace.getRuntime().getOwner();
    runtimes.stopAsync(workspace, options).whenComplete((aVoid, throwable) -> {
        if (workspace.isTemporary() || parseBoolean(options.get(REMOVE_WORKSPACE_AFTER_STOP))) {
            removeWorkspaceQuietly(workspace.getId());
        }
        try {
            if (runtimes.getActive(owner).isEmpty()) {
                recordLastWorkspaceStoppedTime(namespace, owner);
            }
        } catch (ServerException | InfrastructureException e) {
            LOG.error(e.getMessage(), e);
        }
    });
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ServerException(org.eclipse.che.api.core.ServerException) 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