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