Search in sources :

Example 46 with Traced

use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.

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)

Example 47 with Traced

use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.

the class KubernetesInternalRuntime method createServices.

@Traced
// package-private so that interception is possible
@SuppressWarnings("WeakerAccess")
List<Service> createServices(KubernetesEnvironment 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(namespace.services().create(service));
    }
    return createdServices;
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) Traced(org.eclipse.che.commons.annotation.Traced)

Example 48 with Traced

use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.

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)

Example 49 with Traced

use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.

the class UniqueNamesProvisioner method provision.

@Override
@Traced
public void provision(T k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
    final String workspaceId = identity.getWorkspaceId();
    TracingTags.WORKSPACE_ID.set(workspaceId);
    final Map<String, ConfigMap> configMaps = k8sEnv.getConfigMaps();
    Map<String, String> configMapNameTranslation = new HashMap<>();
    for (ConfigMap configMap : configMaps.values()) {
        final String originalName = configMap.getMetadata().getName();
        putLabel(configMap.getMetadata(), Constants.CHE_ORIGINAL_NAME_LABEL, originalName);
        final String uniqueName = Names.uniqueResourceName(originalName, workspaceId);
        configMap.getMetadata().setName(uniqueName);
        configMapNameTranslation.put(originalName, uniqueName);
    }
    final Collection<PodData> podData = k8sEnv.getPodsData().values();
    for (PodData pod : podData) {
        final ObjectMeta podMeta = pod.getMetadata();
        putLabel(podMeta, Constants.CHE_ORIGINAL_NAME_LABEL, podMeta.getName());
        final String podName = Names.uniqueResourceName(podMeta.getName(), workspaceId);
        podMeta.setName(podName);
        if (configMapNameTranslation.size() > 0) {
            rewriteConfigMapNames(pod, configMapNameTranslation);
        }
    }
    // We explicitly need to modify the deployments in the environment to provision unique names
    // for them.
    final Collection<Deployment> deployments = k8sEnv.getDeploymentsCopy().values();
    for (Deployment deployment : deployments) {
        final ObjectMeta deploymentMeta = deployment.getMetadata();
        final String originalName = deploymentMeta.getName();
        putLabel(deploymentMeta, Constants.CHE_ORIGINAL_NAME_LABEL, originalName);
        final String deploymentName = Names.uniqueResourceName(originalName, workspaceId);
        deploymentMeta.setName(deploymentName);
    }
    final Set<Ingress> ingresses = new HashSet<>(k8sEnv.getIngresses().values());
    k8sEnv.getIngresses().clear();
    for (Ingress ingress : ingresses) {
        final ObjectMeta ingressMeta = ingress.getMetadata();
        putLabel(ingress, Constants.CHE_ORIGINAL_NAME_LABEL, ingressMeta.getName());
        final String ingressName = Names.generateName("ingress");
        ingressMeta.setName(ingressName);
        k8sEnv.getIngresses().put(ingressName, ingress);
    }
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) HashSet(java.util.HashSet) Traced(org.eclipse.che.commons.annotation.Traced)

Example 50 with Traced

use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.

the class ImagePullSecretProvisioner method provision.

@Override
@Traced
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
    TracingTags.WORKSPACE_ID.set(identity::getWorkspaceId);
    DockerAuthConfigs credentials = credentialsProvider.getCredentials();
    if (credentials == null) {
        return;
    }
    Map<String, DockerAuthConfig> authConfigs = credentials.getConfigs();
    if (authConfigs == null || authConfigs.isEmpty()) {
        return;
    }
    String encodedConfig = Base64.getEncoder().encodeToString(generateDockerCfg(authConfigs).getBytes());
    Secret secret = new SecretBuilder().addToData(".dockercfg", encodedConfig).withType("kubernetes.io/dockercfg").withNewMetadata().withName(identity.getWorkspaceId() + SECRET_NAME_SUFFIX).endMetadata().build();
    k8sEnv.getSecrets().put(secret.getMetadata().getName(), secret);
    k8sEnv.getPodsData().values().forEach(p -> addImagePullSecret(secret.getMetadata().getName(), p.getSpec()));
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) DockerAuthConfig(org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.dto.DockerAuthConfig) DockerAuthConfigs(org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.dto.DockerAuthConfigs) 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