use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class WorkspaceManager method doCreateWorkspace.
private WorkspaceImpl doCreateWorkspace(WorkspaceConfig config, Devfile devfile, Account account, Map<String, String> attributes, boolean isTemporary) throws ConflictException, ServerException {
WorkspaceImpl workspace = WorkspaceImpl.builder().generateId().setAccount(account).setConfig(config).setDevfile(devfile).setAttributes(attributes).setTemporary(isTemporary).setStatus(STOPPED).build();
workspace.getAttributes().put(CREATED_ATTRIBUTE_NAME, Long.toString(currentTimeMillis()));
String targetNamespace = workspace.getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE);
if (isNullOrEmpty(targetNamespace)) {
try {
targetNamespace = runtimes.evalInfrastructureNamespace(buildResolutionContext(workspace));
workspace.getAttributes().put(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, targetNamespace);
} catch (InfrastructureException e) {
throw new ServerException(e);
}
}
if (targetNamespace == null || !runtimes.isInfrastructureNamespaceValid(targetNamespace)) {
throw new ServerException(format("The workspace would be started in a namespace/project" + " '%s', which is not a valid namespace/project name.", targetNamespace));
}
workspaceDao.create(workspace);
LOG.info("Workspace '{}/{}' with id '{}' created by user '{}'", account.getName(), workspace.getName(), workspace.getId(), sessionUserNameOrUndefined());
eventService.publish(new WorkspaceCreatedEvent(workspace));
return workspace;
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class WorkspaceManager method startAsync.
/**
* Asynchronously starts given workspace.
*/
private void startAsync(WorkspaceImpl workspace, @Nullable String envName, Map<String, String> options) throws ConflictException, NotFoundException, ServerException {
try {
runtimes.validate(workspace, envName);
} catch (ValidationException e) {
throw new ConflictException(e.getMessage(), e);
}
// handle the situation where a workspace created by a previous Che version doesn't have a
// namespace stored for it. We use the legacy-aware method to figure out the namespace to
// correctly capture the workspaces which have PVCs already in a namespace defined by the legacy
// configuration variable.
String targetNamespace = workspace.getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE);
if (isNullOrEmpty(targetNamespace)) {
try {
targetNamespace = runtimes.evalInfrastructureNamespace(buildResolutionContext(workspace));
workspace.getAttributes().put(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, targetNamespace);
} catch (InfrastructureException e) {
throw new ServerException(e);
}
}
if (!runtimes.isInfrastructureNamespaceValid(targetNamespace)) {
try {
targetNamespace = runtimes.evalInfrastructureNamespace(buildResolutionContext(workspace));
if (targetNamespace == null || !runtimes.isInfrastructureNamespaceValid(targetNamespace)) {
throw new ServerException(format("The workspace would be started in a namespace/project" + " '%s', which is not a valid namespace/project name.", targetNamespace));
}
workspace.getAttributes().put(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, targetNamespace);
} catch (InfrastructureException e) {
throw new ServerException(e);
}
}
workspace.getAttributes().put(UPDATED_ATTRIBUTE_NAME, Long.toString(currentTimeMillis()));
workspaceDao.update(workspace);
runtimes.startAsync(workspace, envName, firstNonNull(options, Collections.emptyMap())).thenAccept(aVoid -> handleStartupSuccess(workspace.getId())).exceptionally(ex -> {
if (workspace.isTemporary()) {
removeWorkspaceQuietly(workspace.getId());
} else {
handleStartupError(workspace.getId(), ex.getCause());
}
return null;
});
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class WorkspaceRuntimes method stop.
void stop() {
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 that need to be stopped", identities.size());
if (identities.isEmpty()) {
return;
}
for (RuntimeIdentity identity : identities) {
try {
String workspaceId = identity.getWorkspaceId();
WorkspaceImpl workspace = workspaceDao.get(workspaceId);
try (Unlocker ignored = lockService.writeLock(workspaceId)) {
statuses.putIfAbsent(workspaceId, STARTING);
}
String namespace = workspace.getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE);
stopAsync(workspace, emptyMap()).whenComplete((aVoid, throwable) -> {
LOG.info("Workspace '{}' owned by '{}' has been stopped in namespace '{}'", workspaceId, namespace);
});
} catch (Exception e) {
LOG.error("An error occurred while attempting to stop runtime '{}' using infrastructure '{}'. Reason: '{}'", workspaceRuntimesId, infrastructure.getName(), e.getMessage(), e);
}
}
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class PluginFQNParser method evaluateFqn.
/**
* Evaluates plugin FQN from provided reference by trying to fetch and parse its meta information.
*
* @param reference plugin reference to evaluate FQN from
* @param fileContentProvider content provider instance to perform plugin meta requests
* @return plugin FQN evaluated from given reference
* @throws InfrastructureException if plugin reference is invalid or inaccessible
*/
public ExtendedPluginFQN evaluateFqn(String reference, FileContentProvider fileContentProvider) throws InfrastructureException {
JsonNode contentNode;
try {
String pluginMetaContent = fileContentProvider.fetchContent(reference);
contentNode = yamlReader.readTree(pluginMetaContent);
} catch (DevfileException | IOException e) {
throw new InfrastructureException(format("Plugin reference URL '%s' is invalid.", reference), e);
}
JsonNode publisher = contentNode.path("publisher");
if (publisher.isMissingNode()) {
throw new InfrastructureException(formatMessage(reference, "publisher"));
}
JsonNode name = contentNode.get("name");
if (name.isMissingNode()) {
throw new InfrastructureException(formatMessage(reference, "name"));
}
JsonNode version = contentNode.get("version");
if (version.isMissingNode()) {
throw new InfrastructureException(formatMessage(reference, "version"));
}
if (!version.isValueNode()) {
throw new InfrastructureException(format("Plugin specified by reference URL '%s' has version field that cannot be parsed to string", reference));
}
return new ExtendedPluginFQN(reference, publisher.textValue(), name.textValue(), version.asText());
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class PluginFQNParser method parsePluginFQN.
public ExtendedPluginFQN parsePluginFQN(String plugin) throws InfrastructureException {
String url;
String id;
String publisher;
String name;
String version;
URI registryURI = null;
Matcher matcher = PLUGIN_PATTERN.matcher(plugin);
if (matcher.matches()) {
url = matcher.group("url");
id = matcher.group("id");
publisher = matcher.group("publisher");
name = matcher.group("name");
version = matcher.group("version");
} else {
throw new InfrastructureException(format(INCORRECT_PLUGIN_FORMAT_TEMPLATE, plugin));
}
if (!isNullOrEmpty(url)) {
if (isNullOrEmpty(id)) {
// reference only
return new ExtendedPluginFQN(url);
} else {
// registry + id
try {
registryURI = new URI(url);
} catch (URISyntaxException e) {
throw new InfrastructureException(format("Plugin registry URL '%s' is invalid. Problematic plugin entry: '%s'", url, plugin));
}
}
}
return new ExtendedPluginFQN(registryURI, id, publisher, name, version);
}
Aggregations