Search in sources :

Example 6 with Traced

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

the class OpenShiftInternalRuntime method createServices.

@Traced
// package-private so that interception is possible
@SuppressWarnings("WeakerAccess")
List<Service> createServices(OpenShiftEnvironment env, String workspaceId) throws InfrastructureException {
    TracingTags.WORKSPACE_ID.set(workspaceId);
    Collection<Service> servicesToCreate = env.getServices().values();
    List<Service> createdServices = new ArrayList<>(servicesToCreate.size());
    for (Service service : servicesToCreate) {
        createdServices.add(project.services().create(service));
    }
    return createdServices;
}
Also used : ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) Traced(org.eclipse.che.commons.annotation.Traced)

Example 7 with Traced

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

the class TracingInterceptor method getSpanName.

private String getSpanName(MethodInvocation invocation) {
    Class<?> objectType = invocation.getThis().getClass();
    Method method = invocation.getMethod();
    // we assume that there won't be more than 4 traced methods on a type. If there are, we're
    // adding a little bit of runtime overhead of enlarging the hashmap's capacity, but in the usual
    // case we're saving 12 entries in the map (16 is the default capacity).
    String ret = spanNames.computeIfAbsent(objectType, __ -> new WeakHashMap<>(4)).get(method);
    if (ret != null) {
        return ret;
    }
    Traced annotation = method.getAnnotation(Traced.class);
    if (annotation == null) {
        throw new IllegalStateException("Misconfigured Guice interception. Tracing interceptor called on method " + method + " that is not annotated with @Traced.");
    }
    String name = annotation.name();
    if (name.isEmpty()) {
        name = cleanName(objectType) + "#" + method.getName();
    }
    spanNames.get(objectType).put(method, name);
    return name;
}
Also used : Logger(org.slf4j.Logger) Tracer(io.opentracing.Tracer) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) Tags(io.opentracing.tag.Tags) Supplier(java.util.function.Supplier) Traced(org.eclipse.che.commons.annotation.Traced) Beta(com.google.common.annotations.Beta) MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Map(java.util.Map) Span(io.opentracing.Span) Scope(io.opentracing.Scope) Method(java.lang.reflect.Method) WeakHashMap(java.util.WeakHashMap) Traced(org.eclipse.che.commons.annotation.Traced) Method(java.lang.reflect.Method) WeakHashMap(java.util.WeakHashMap)

Example 8 with Traced

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

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

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

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)

Example 10 with Traced

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

the class WorkspaceManager method createWorkspace.

/**
 * Creates a workspace out of a devfile.
 *
 * <p>The devfile should have been validated using the {@link
 * DevfileIntegrityValidator#validateDevfile(Devfile)}. This method does rest of the validation
 * and actually creates the workspace.
 *
 * @param devfile the devfile describing the workspace
 * @param namespace workspace name is unique in this namespace
 * @param attributes workspace instance attributes
 * @param contentProvider the content provider to use for resolving content references in the
 *     devfile
 * @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(Devfile devfile, String namespace, Map<String, String> attributes, FileContentProvider contentProvider) throws ServerException, NotFoundException, ConflictException, ValidationException {
    requireNonNull(devfile, "Required non-null devfile");
    requireNonNull(namespace, "Required non-null namespace");
    validator.validateAttributes(attributes);
    devfile = generateNameIfNeeded(devfile);
    try {
        devfileIntegrityValidator.validateContentReferences(devfile, contentProvider);
    } catch (DevfileFormatException e) {
        throw new ValidationException(e.getMessage(), e);
    }
    WorkspaceImpl workspace = doCreateWorkspace(devfile, 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) ValidationException(org.eclipse.che.api.core.ValidationException) DevfileFormatException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException) 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