use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.
the class PluginBrokerManager method getTooling.
/**
* Deploys Che plugin brokers in a workspace, receives result of theirs execution and returns
* resolved workspace tooling or error of plugins brokering execution.
*
* <p>This API is in <b>Beta</b> and is subject to changes or removal.
*/
@Beta
@Traced
public List<ChePlugin> getTooling(RuntimeIdentity identity, StartSynchronizer startSynchronizer, Collection<PluginFQN> pluginFQNs, boolean isEphemeral, boolean mergePlugins, Map<String, String> startOptions) throws InfrastructureException {
String workspaceId = identity.getWorkspaceId();
KubernetesNamespace kubernetesNamespace = factory.getOrCreate(identity);
BrokersResult brokersResult = new BrokersResult();
E brokerEnvironment = brokerEnvironmentFactory.createForMetadataBroker(pluginFQNs, identity, mergePlugins);
if (isEphemeral) {
EphemeralWorkspaceUtility.makeEphemeral(brokerEnvironment.getAttributes());
}
environmentProvisioner.provision(brokerEnvironment, identity);
ListenBrokerEvents listenBrokerEvents = getListenEventPhase(workspaceId, brokersResult);
PrepareStorage prepareStorage = getPrepareStoragePhase(identity, startSynchronizer, brokerEnvironment, startOptions);
WaitBrokerResult waitBrokerResult = getWaitBrokerPhase(workspaceId, brokersResult);
DeployBroker deployBroker = getDeployBrokerPhase(identity, kubernetesNamespace, brokerEnvironment, brokersResult, startOptions);
LOG.debug("Entering plugin brokers deployment chain workspace '{}'", workspaceId);
listenBrokerEvents.then(prepareStorage).then(deployBroker).then(waitBrokerResult);
return listenBrokerEvents.execute();
}
use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.
the class LimitsCheckingWorkspaceManager method createWorkspace.
@Override
@Traced
public WorkspaceImpl createWorkspace(WorkspaceConfig config, String namespace, @Nullable Map<String, String> attributes) throws ServerException, ConflictException, NotFoundException, ValidationException {
checkMaxEnvironmentRam(config);
String accountId = accountManager.getByName(namespace).getId();
try (Unlocker ignored = resourcesLocks.lock(accountId)) {
checkWorkspaceResourceAvailability(accountId);
return super.createWorkspace(config, namespace, attributes);
}
}
use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.
the class WorkspaceManager method createWorkspace.
/**
* Creates a new {@link Workspace} instance based on the given configuration and the instance
* attributes.
*
* @param config the workspace config to create the new workspace instance
* @param namespace workspace name is unique in this namespace
* @param attributes workspace instance attributes
* @return new workspace instance
* @throws NullPointerException when either {@code config} or {@code namespace} is null
* @throws NotFoundException when account with given id was not found
* @throws ConflictException when any conflict occurs (e.g Workspace with such name already exists
* for {@code owner})
* @throws ServerException when any other error occurs
* @throws ValidationException when incoming configuration or attributes are not valid
*/
@Traced
public WorkspaceImpl createWorkspace(WorkspaceConfig config, String namespace, Map<String, String> attributes) throws ServerException, NotFoundException, ConflictException, ValidationException {
requireNonNull(config, "Required non-null config");
requireNonNull(namespace, "Required non-null namespace");
validator.validateConfig(config);
validator.validateAttributes(attributes);
WorkspaceImpl workspace = doCreateWorkspace(config, accountManager.getByName(namespace), attributes, false);
TracingTags.WORKSPACE_ID.set(workspace.getId());
return workspace;
}
use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.
the class WorkspaceRuntimes method startAsync.
/**
* Starts all machines from specified workspace environment, creates workspace runtime instance
* based on that environment.
*
* <p>During the start of the workspace its runtime is visible with {@link
* WorkspaceStatus#STARTING} status.
*
* @param workspace workspace which environment should be started
* @param envName optional environment name to run
* @param options whether machines should be recovered(true) or not(false)
* @return completable future of start execution.
* @throws ConflictException when workspace is already running
* @throws ConflictException when start is interrupted
* @throws NotFoundException when any not found exception occurs during environment start
* @throws ServerException other error occurs during environment start
* @see WorkspaceStatus#STARTING
* @see WorkspaceStatus#RUNNING
*/
@Traced
public CompletableFuture<Void> startAsync(WorkspaceImpl workspace, @Nullable String envName, Map<String, String> options) throws ConflictException, NotFoundException, ServerException {
TracingTags.WORKSPACE_ID.set(workspace.getId());
final String workspaceId = workspace.getId();
if (isStartRefused.get()) {
throw new ConflictException(format("Start of the workspace '%s' is rejected by the system, " + "no more workspaces are allowed to start", workspace.getName()));
}
WorkspaceConfigImpl config = workspace.getConfig();
if (config == null) {
config = devfileConverter.convert(workspace.getDevfile());
}
if (envName == null) {
envName = config.getDefaultEnv();
}
String infraNamespace = workspace.getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE);
if (isNullOrEmpty(infraNamespace)) {
throw new ServerException(String.format("Workspace does not have infrastructure namespace " + "specified. Please set value of '%s' workspace attribute.", WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE));
}
final RuntimeIdentity runtimeId = new RuntimeIdentityImpl(workspaceId, envName, EnvironmentContext.getCurrent().getSubject().getUserId(), infraNamespace);
try {
InternalEnvironment internalEnv = createInternalEnvironment(config.getEnvironments().get(envName), config.getAttributes(), config.getCommands(), config.getDevfile());
RuntimeContext runtimeContext = infrastructure.prepare(runtimeId, internalEnv);
InternalRuntime runtime = runtimeContext.getRuntime();
try (Unlocker ignored = lockService.writeLock(workspaceId)) {
final WorkspaceStatus existingStatus = statuses.putIfAbsent(workspaceId, STARTING);
if (existingStatus != null) {
throw new ConflictException(format("Could not start workspace '%s' because its state is '%s'", workspaceId, existingStatus));
}
setRuntimesId(workspaceId);
runtimes.put(workspaceId, runtime);
}
LOG.info("Starting workspace '{}/{}' with id '{}' by user '{}'", workspace.getNamespace(), workspace.getName(), workspace.getId(), sessionUserNameOr("undefined"));
publishWorkspaceStatusEvent(workspaceId, STARTING, STOPPED, null, true, options);
return CompletableFuture.runAsync(ThreadLocalPropagateContext.wrap(new StartRuntimeTask(workspace, options, runtime)), sharedPool.getExecutor());
} catch (ValidationException e) {
LOG.error(e.getLocalizedMessage(), e);
throw new ConflictException(e.getLocalizedMessage());
} catch (InfrastructureException e) {
LOG.error(e.getLocalizedMessage(), e);
throw new ServerException(e.getLocalizedMessage(), e);
}
}
use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.
the class WorkspaceRuntimes method stopAsync.
/**
* Stops running workspace runtime asynchronously.
*
* <p>Stops environment in an implementation specific way. During the stop of the workspace its
* runtime is accessible with {@link WorkspaceStatus#STOPPING stopping} status. Workspace may be
* stopped only if its status is {@link WorkspaceStatus#RUNNING} or {@link
* WorkspaceStatus#STARTING}.
*
* @param workspace workspace which runtime should be stopped
* @throws NotFoundException when workspace with specified identifier does not have runtime
* @throws ConflictException when running workspace status is different from {@link
* WorkspaceStatus#RUNNING} or {@link WorkspaceStatus#STARTING}
* @see WorkspaceStatus#STOPPING
*/
@Traced
public CompletableFuture<Void> stopAsync(WorkspaceImpl workspace, Map<String, String> options) throws NotFoundException, ConflictException {
TracingTags.WORKSPACE_ID.set(workspace.getId());
TracingTags.STOPPED_BY.set(getStoppedBy(workspace));
String workspaceId = workspace.getId();
WorkspaceStatus status = statuses.get(workspaceId);
if (status == null) {
throw new NotFoundException("Workspace with id '" + workspaceId + "' is not running.");
}
if (status != RUNNING && status != STARTING) {
throw new ConflictException(format("Could not stop workspace '%s' because its state is '%s'", workspaceId, status));
}
if (!statuses.replace(workspaceId, status, STOPPING)) {
WorkspaceStatus newStatus = statuses.get(workspaceId);
throw new ConflictException(format("Could not stop workspace '%s' because its state is '%s'", workspaceId, newStatus == null ? STOPPED : newStatus));
}
setRuntimesId(workspaceId);
String stoppedBy = firstNonNull(sessionUserNameOr(workspace.getAttributes().get(WORKSPACE_STOPPED_BY)), "undefined");
LOG.info("Workspace '{}/{}' with id '{}' is stopping by user '{}'", workspace.getNamespace(), workspace.getName(), workspace.getId(), stoppedBy);
publishWorkspaceStatusEvent(workspaceId, STOPPING, status, options.get(WORKSPACE_STOP_REASON), true);
return CompletableFuture.runAsync(ThreadLocalPropagateContext.wrap(new StopRuntimeTask(workspace, options, stoppedBy)), sharedPool.getExecutor());
}
Aggregations