Search in sources :

Example 26 with Traced

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();
}
Also used : ListenBrokerEvents(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.ListenBrokerEvents) WaitBrokerResult(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.WaitBrokerResult) DeployBroker(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.DeployBroker) PrepareStorage(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.PrepareStorage) KubernetesNamespace(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace) Traced(org.eclipse.che.commons.annotation.Traced) Beta(com.google.common.annotations.Beta)

Example 27 with Traced

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);
    }
}
Also used : Unlocker(org.eclipse.che.commons.lang.concurrent.Unlocker) Traced(org.eclipse.che.commons.annotation.Traced)

Example 28 with Traced

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;
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Traced(org.eclipse.che.commons.annotation.Traced)

Example 29 with Traced

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);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) ValidationException(org.eclipse.che.api.core.ValidationException) ConflictException(org.eclipse.che.api.core.ConflictException) InternalRuntime(org.eclipse.che.api.workspace.server.spi.InternalRuntime) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Unlocker(org.eclipse.che.commons.lang.concurrent.Unlocker) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) RuntimeContext(org.eclipse.che.api.workspace.server.spi.RuntimeContext) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) Traced(org.eclipse.che.commons.annotation.Traced)

Example 30 with Traced

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());
}
Also used : ConflictException(org.eclipse.che.api.core.ConflictException) NotFoundException(org.eclipse.che.api.core.NotFoundException) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) Traced(org.eclipse.che.commons.annotation.Traced)

Aggregations

Traced (org.eclipse.che.commons.annotation.Traced)54 PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)14 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)12 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)10 ArrayList (java.util.ArrayList)10 Service (io.fabric8.kubernetes.api.model.Service)8 Map (java.util.Map)8 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)8 InternalMachineConfig (org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig)8 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)8 Beta (com.google.common.annotations.Beta)6 Container (io.fabric8.kubernetes.api.model.Container)6 Route (io.fabric8.openshift.api.model.Route)6 ValidationException (org.eclipse.che.api.core.ValidationException)6 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)6 InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)5 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)4 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)4 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)4 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)4