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));
}
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);
}
}
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);
}
}
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);
}
}
}
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);
}
});
}
Aggregations