Search in sources :

Example 36 with Traced

use of org.eclipse.che.commons.annotation.Traced in project che-server by eclipse-che.

the class OpenShiftInternalRuntime method createRoutes.

@Traced
// package-private so that interception is possible
@SuppressWarnings("WeakerAccess")
List<Route> createRoutes(OpenShiftEnvironment env, String workspaceId) throws InfrastructureException {
    TracingTags.WORKSPACE_ID.set(workspaceId);
    Collection<Route> routesToCreate = env.getRoutes().values();
    List<Route> createdRoutes = new ArrayList<>(routesToCreate.size());
    for (Route route : routesToCreate) {
        createdRoutes.add(project.routes().create(route));
    }
    return createdRoutes;
}
Also used : ArrayList(java.util.ArrayList) Route(io.fabric8.openshift.api.model.Route) Traced(org.eclipse.che.commons.annotation.Traced)

Example 37 with Traced

use of org.eclipse.che.commons.annotation.Traced in project che-server by eclipse-che.

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 38 with Traced

use of org.eclipse.che.commons.annotation.Traced in project che-server by eclipse-che.

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 39 with Traced

use of org.eclipse.che.commons.annotation.Traced in project che-server by eclipse-che.

the class UniqueWorkspacePVCStrategy method prepare.

@Traced
@Override
public void prepare(KubernetesEnvironment k8sEnv, RuntimeIdentity identity, long timeoutMillis, Map<String, String> startOptions) throws InfrastructureException {
    String workspaceId = identity.getWorkspaceId();
    TracingTags.WORKSPACE_ID.set(workspaceId);
    if (EphemeralWorkspaceUtility.isEphemeral(k8sEnv.getAttributes())) {
        return;
    }
    if (k8sEnv.getPersistentVolumeClaims().isEmpty()) {
        // no PVCs to prepare
        return;
    }
    final KubernetesPersistentVolumeClaims k8sClaims = factory.getOrCreate(identity).persistentVolumeClaims();
    LOG.debug("Creating PVCs for workspace '{}'", workspaceId);
    k8sClaims.createIfNotExist(k8sEnv.getPersistentVolumeClaims().values());
    if (waitBound) {
        LOG.debug("Waiting for PVC(s) of workspace '{}' to be bound", workspaceId);
        for (PersistentVolumeClaim pvc : k8sEnv.getPersistentVolumeClaims().values()) {
            k8sClaims.waitBound(pvc.getMetadata().getName(), timeoutMillis);
        }
    }
    LOG.debug("Preparing PVCs done for workspace '{}'", workspaceId);
}
Also used : PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) KubernetesPersistentVolumeClaims(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesPersistentVolumeClaims) Traced(org.eclipse.che.commons.annotation.Traced)

Example 40 with Traced

use of org.eclipse.che.commons.annotation.Traced in project che-server by eclipse-che.

the class SshKeysProvisioner method provision.

@Override
@Traced
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
    String workspaceId = identity.getWorkspaceId();
    TracingTags.WORKSPACE_ID.set(workspaceId);
    List<SshPairImpl> vcsSshPairs = getVcsSshPairs(k8sEnv, identity);
    List<SshPairImpl> systemSshPairs = getSystemSshPairs(k8sEnv, identity);
    List<SshPairImpl> allSshPairs = new ArrayList<>(vcsSshPairs);
    allSshPairs.addAll(systemSshPairs);
    List<String> invalidSshKeyNames = allSshPairs.stream().filter(keyPair -> !isValidSshKeyPair(keyPair)).map(SshPairImpl::getName).collect(toList());
    if (!invalidSshKeyNames.isEmpty()) {
        String message = format(Warnings.SSH_KEYS_WILL_NOT_BE_MOUNTED_MESSAGE, invalidSshKeyNames.toString(), identity.getWorkspaceId());
        LOG.warn(message);
        k8sEnv.addWarning(new WarningImpl(Warnings.SSH_KEYS_WILL_NOT_BE_MOUNTED, message));
        runtimeEventsPublisher.sendRuntimeLogEvent(message, ZonedDateTime.now().toString(), identity);
    }
    doProvisionSshKeys(allSshPairs.stream().filter(this::isValidSshKeyPair).collect(toList()), k8sEnv, workspaceId);
    doProvisionVcsSshConfig(vcsSshPairs.stream().filter(this::isValidSshKeyPair).collect(toList()), k8sEnv, workspaceId);
}
Also used : SshPairImpl(org.eclipse.che.api.ssh.server.model.impl.SshPairImpl) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) ArrayList(java.util.ArrayList) 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