Search in sources :

Example 11 with Traced

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

the class KubernetesInternalRuntime method doStartMachine.

/**
 * Creates Kubernetes pods and resolves servers using the specified serverResolver.
 *
 * @param serverResolver server resolver that provide servers by container
 * @throws InfrastructureException when any error occurs while creating Kubernetes pods
 */
@Traced
protected void doStartMachine(ServerResolver serverResolver) throws InfrastructureException {
    final KubernetesEnvironment environment = getContext().getEnvironment();
    final Map<String, InternalMachineConfig> machineConfigs = environment.getMachines();
    final String workspaceId = getContext().getIdentity().getWorkspaceId();
    LOG.debug("Begin pods creation for workspace '{}'", workspaceId);
    PodMerger podMerger = new PodMerger();
    Map<String, Map<String, Pod>> injectablePods = environment.getInjectablePodsCopy();
    for (Pod toCreate : environment.getPodsCopy().values()) {
        ObjectMeta toCreateMeta = toCreate.getMetadata();
        List<PodData> injectables = getAllInjectablePods(toCreate, injectablePods);
        Pod createdPod;
        if (injectables.isEmpty()) {
            createdPod = namespace.deployments().deploy(toCreate);
        } else {
            try {
                injectables.add(new PodData(toCreate));
                Deployment merged = podMerger.merge(injectables);
                merged.getMetadata().setName(toCreate.getMetadata().getName());
                createdPod = namespace.deployments().deploy(merged);
            } catch (ValidationException e) {
                throw new InfrastructureException(e);
            }
        }
        LOG.debug("Creating pod '{}' in workspace '{}'", toCreateMeta.getName(), workspaceId);
        storeStartingMachine(createdPod, createdPod.getMetadata(), machineConfigs, serverResolver);
    }
    for (Deployment toCreate : environment.getDeploymentsCopy().values()) {
        PodTemplateSpec template = toCreate.getSpec().getTemplate();
        List<PodData> injectables = getAllInjectablePods(template.getMetadata(), template.getSpec().getContainers(), injectablePods);
        Pod createdPod;
        if (injectables.isEmpty()) {
            createdPod = namespace.deployments().deploy(toCreate);
        } else {
            try {
                injectables.add(new PodData(toCreate));
                Deployment deployment = podMerger.merge(injectables);
                deployment.getMetadata().setName(toCreate.getMetadata().getName());
                putAnnotations(deployment.getMetadata(), toCreate.getMetadata().getAnnotations());
                putLabels(deployment.getMetadata(), toCreate.getMetadata().getLabels());
                createdPod = namespace.deployments().deploy(deployment);
            } catch (ValidationException e) {
                throw new InfrastructureException(e);
            }
        }
        LOG.debug("Creating deployment '{}' in workspace '{}'", createdPod.getMetadata().getName(), workspaceId);
        storeStartingMachine(createdPod, createdPod.getMetadata(), machineConfigs, serverResolver);
    }
    LOG.debug("Pods creation finished in workspace '{}'", workspaceId);
}
Also used : PodMerger(org.eclipse.che.workspace.infrastructure.kubernetes.environment.PodMerger) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ValidationException(org.eclipse.che.api.core.ValidationException) Pod(io.fabric8.kubernetes.api.model.Pod) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Collections.emptyMap(java.util.Collections.emptyMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) 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 12 with Traced

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

the class KubernetesInternalRuntime method createConfigMaps.

@Traced
protected List<ConfigMap> createConfigMaps(KubernetesEnvironment env, RuntimeIdentity identity) throws InfrastructureException {
    TracingTags.WORKSPACE_ID.set(identity.getWorkspaceId());
    List<ConfigMap> createdConfigMaps = new ArrayList<>();
    List<ConfigMap> cheNamespaceConfigMaps = new ArrayList<>();
    for (ConfigMap configMap : env.getConfigMaps().values()) {
        if (shouldCreateInCheNamespace(configMap)) {
            // we collect the che namespace configmaps into separate list
            cheNamespaceConfigMaps.add(configMap);
        } else {
            createdConfigMaps.add(namespace.configMaps().create(configMap));
        }
    }
    // create che namespace configmaps in one batch, because we're doing some extra checks inside
    createdConfigMaps.addAll(cheNamespace.createConfigMaps(cheNamespaceConfigMaps, identity));
    return createdConfigMaps;
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Traced(org.eclipse.che.commons.annotation.Traced)

Example 13 with Traced

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

the class KubernetesInternalRuntime method internalStop.

@Traced
@Override
protected void internalStop(Map<String, String> stopOptions) throws InfrastructureException {
    RuntimeIdentity identity = getContext().getIdentity();
    TracingTags.WORKSPACE_ID.set(identity.getWorkspaceId());
    runtimeHangingDetector.stopTracking(getContext().getIdentity());
    if (startSynchronizer.interrupt()) {
        // runtime is STARTING. Need to wait until start will be interrupted properly
        try {
            if (!startSynchronizer.awaitInterruption(workspaceStartTimeoutMin, TimeUnit.MINUTES)) {
                // Runtime is not interrupted yet. It may occur when start was performing by another
                // Che Server that is crashed so start is hung up in STOPPING phase.
                // Need to clean up runtime resources
                probeScheduler.cancel(identity.getWorkspaceId());
                runtimeCleaner.cleanUp(namespace, identity.getWorkspaceId());
            }
        } catch (InterruptedException e) {
            throw new InfrastructureException("Interrupted while waiting for start task cancellation", e);
        }
    } else {
        // runtime is RUNNING. Clean up used resources
        // Cancels workspace servers probes if any
        probeScheduler.cancel(identity.getWorkspaceId());
        runtimeCleaner.cleanUp(namespace, identity.getWorkspaceId());
    }
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) 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 14 with Traced

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

the class ContainerResourceProvisioner method provision.

@Override
@Traced
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
    TracingTags.WORKSPACE_ID.set(identity::getWorkspaceId);
    final Map<String, InternalMachineConfig> machines = k8sEnv.getMachines();
    for (PodData pod : k8sEnv.getPodsData().values()) {
        for (Container container : pod.getSpec().getContainers()) {
            // make sure that machine configs have settings for RAM limit and request
            InternalMachineConfig machineConfig = machines.get(machineName(pod, container));
            ResourceLimitAttributesProvisioner.provisionMemory(machineConfig, Containers.getRamLimit(container), Containers.getRamRequest(container), defaultMachineMaxMemorySizeAttribute, defaultMachineRequestMemorySizeAttribute);
            // make sure that machine configs have settings for CPU limit and request
            ResourceLimitAttributesProvisioner.provisionCPU(machineConfig, Containers.getCpuLimit(container), Containers.getCpuRequest(container), defaultMachineCpuLimitAttribute, defaultMachineCpuRequestAttribute);
            // reapply memory and CPU settings to k8s container to make sure that provisioned
            // values above are set. Non-positive value means that limit is disabled, so just
            // ignoring them.
            final Map<String, String> attributes = machineConfig.getAttributes();
            long memLimit = Long.parseLong(attributes.get(MEMORY_LIMIT_ATTRIBUTE));
            if (memLimit > 0) {
                Containers.addRamLimit(container, memLimit);
            }
            long memRequest = Long.parseLong(attributes.get(MEMORY_REQUEST_ATTRIBUTE));
            if (memRequest > 0) {
                Containers.addRamRequest(container, memRequest);
            }
            float cpuLimit = Float.parseFloat(attributes.get(CPU_LIMIT_ATTRIBUTE));
            if (cpuLimit > 0) {
                Containers.addCpuLimit(container, cpuLimit);
            }
            float cpuRequest = Float.parseFloat(attributes.get(CPU_REQUEST_ATTRIBUTE));
            if (cpuRequest > 0)
                Containers.addCpuRequest(container, cpuRequest);
        }
    }
}
Also used : InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Container(io.fabric8.kubernetes.api.model.Container) Traced(org.eclipse.che.commons.annotation.Traced)

Example 15 with Traced

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

the class ServersConverter method provision.

@Override
@Traced
public void provision(T k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
    TracingTags.WORKSPACE_ID.set(identity::getWorkspaceId);
    SecureServerExposer<T> secureServerExposer = secureServerExposerFactoryProvider.get(k8sEnv).create(identity);
    for (PodData podConfig : k8sEnv.getPodsData().values()) {
        final PodSpec podSpec = podConfig.getSpec();
        for (Container containerConfig : podSpec.getContainers()) {
            String machineName = Names.machineName(podConfig, containerConfig);
            InternalMachineConfig machineConfig = k8sEnv.getMachines().get(machineName);
            if (!machineConfig.getServers().isEmpty()) {
                KubernetesServerExposer kubernetesServerExposer = new KubernetesServerExposer<>(externalServerExposer, secureServerExposer, machineName, podConfig, containerConfig, k8sEnv);
                kubernetesServerExposer.expose(machineConfig.getServers());
            }
        }
    }
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) Container(io.fabric8.kubernetes.api.model.Container) KubernetesServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) 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