use of org.eclipse.che.api.workspace.shared.Constants.UPDATED_ATTRIBUTE_NAME 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.shared.Constants.UPDATED_ATTRIBUTE_NAME in project devspaces-images by redhat-developer.
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;
});
}
Aggregations