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);
}
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;
}
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());
}
}
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);
}
}
}
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());
}
}
}
}
Aggregations