Search in sources :

Example 1 with Env

use of org.eclipse.che.api.core.model.workspace.devfile.Env in project che-server by eclipse-che.

the class EnvVars method apply.

private void apply(List<EnvVar> targetEnv, Env env) {
    Optional<EnvVar> existingOpt = targetEnv.stream().filter(e -> e.getName().equals(env.getName())).findAny();
    if (existingOpt.isPresent()) {
        EnvVar envVar = existingOpt.get();
        envVar.setValue(env.getValue());
        envVar.setValueFrom(null);
    } else {
        targetEnv.add(new EnvVar(env.getName(), env.getValue(), null));
    }
}
Also used : EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Container(io.fabric8.kubernetes.api.model.Container) Env(org.eclipse.che.api.core.model.workspace.devfile.Env) Set(java.util.Set) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Matcher(java.util.regex.Matcher) Stream(java.util.stream.Stream) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) EnvVar(io.fabric8.kubernetes.api.model.EnvVar)

Example 2 with Env

use of org.eclipse.che.api.core.model.workspace.devfile.Env in project che-server by eclipse-che.

the class DevfileIntegrityValidator method validateComponents.

private Set<String> validateComponents(Devfile devfile) throws DevfileFormatException {
    Set<String> definedAliases = new HashSet<>();
    Component editorComponent = null;
    Map<String, Set<String>> idsPerComponentType = new HashMap<>();
    for (Component component : devfile.getComponents()) {
        if (component.getAlias() != null && !definedAliases.add(component.getAlias())) {
            throw new DevfileFormatException(format("Duplicate component alias found:'%s'", component.getAlias()));
        }
        Optional<Map.Entry<String, Long>> duplicatedEndpoint = component.getEndpoints().stream().map(Endpoint::getName).collect(Collectors.groupingBy(Function.identity(), Collectors.counting())).entrySet().stream().filter(e -> e.getValue() > 1L).findFirst();
        if (duplicatedEndpoint.isPresent()) {
            throw new DevfileFormatException(format("Duplicated endpoint name '%s' found in '%s' component", duplicatedEndpoint.get().getKey(), getIdentifiableComponentName(component)));
        }
        Set<String> tempSet = new HashSet<>();
        for (Env env : component.getEnv()) {
            if (!tempSet.add(env.getName())) {
                throw new DevfileFormatException(format("Duplicate environment variable '%s' found in component '%s'", env.getName(), getIdentifiableComponentName(component)));
            }
        }
        if (!idsPerComponentType.computeIfAbsent(component.getType(), __ -> new HashSet<>()).add(getIdentifiableComponentName(component))) {
            throw new DevfileFormatException(format("There are multiple components '%s' of type '%s' that cannot be uniquely" + " identified. Please add aliases that would distinguish the components.", getIdentifiableComponentName(component), component.getType()));
        }
        if (component.getAutomountWorkspaceSecrets() != null && component.getAlias() == null) {
            throw new DevfileFormatException(format("The 'automountWorkspaceSecrets' property cannot be used in component which doesn't have alias. " + "Please add alias to component '%s' that would allow to distinguish its containers.", getIdentifiableComponentName(component)));
        }
        switch(component.getType()) {
            case EDITOR_COMPONENT_TYPE:
                if (editorComponent != null) {
                    throw new DevfileFormatException(format("Multiple editor components found: '%s', '%s'", getIdentifiableComponentName(editorComponent), getIdentifiableComponentName(component)));
                }
                editorComponent = component;
                break;
            case PLUGIN_COMPONENT_TYPE:
            case KUBERNETES_COMPONENT_TYPE:
            case OPENSHIFT_COMPONENT_TYPE:
            case DOCKERIMAGE_COMPONENT_TYPE:
                // do nothing
                break;
            default:
                throw new DevfileFormatException(format("One of the components has unsupported component type: '%s'", component.getType()));
        }
    }
    return definedAliases;
}
Also used : KUBERNETES_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE) Env(org.eclipse.che.api.core.model.workspace.devfile.Env) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) PLUGIN_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.PLUGIN_COMPONENT_TYPE) Function(java.util.function.Function) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Map(java.util.Map) Components.getIdentifiableComponentName(org.eclipse.che.api.workspace.server.devfile.Components.getIdentifiableComponentName) EDITOR_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE) DOCKERIMAGE_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.DOCKERIMAGE_COMPONENT_TYPE) Component(org.eclipse.che.api.core.model.workspace.devfile.Component) Devfile(org.eclipse.che.api.core.model.workspace.devfile.Devfile) OPENSHIFT_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.OPENSHIFT_COMPONENT_TYPE) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) Optional(java.util.Optional) Command(org.eclipse.che.api.core.model.workspace.devfile.Command) Project(org.eclipse.che.api.core.model.workspace.devfile.Project) Pattern(java.util.regex.Pattern) Action(org.eclipse.che.api.core.model.workspace.devfile.Action) Endpoint(org.eclipse.che.api.core.model.workspace.devfile.Endpoint) DevfileFormatException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Env(org.eclipse.che.api.core.model.workspace.devfile.Env) DevfileFormatException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException) Component(org.eclipse.che.api.core.model.workspace.devfile.Component) HashSet(java.util.HashSet)

Example 3 with Env

use of org.eclipse.che.api.core.model.workspace.devfile.Env in project che-server by eclipse-che.

the class EnvVars method apply.

/**
 * Applies the specified env vars list to the specified containers.
 *
 * <p>If a container does not have the corresponding env - it will be provisioned, if it has - the
 * value will be overridden.
 *
 * @param container pod to supply env vars
 * @param toApply env vars to apply
 */
public void apply(Container container, List<? extends Env> toApply) {
    List<EnvVar> targetEnv = container.getEnv();
    if (targetEnv == null) {
        targetEnv = new ArrayList<>();
        container.setEnv(targetEnv);
    }
    for (Env env : toApply) {
        apply(targetEnv, env);
    }
}
Also used : EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Env(org.eclipse.che.api.core.model.workspace.devfile.Env)

Example 4 with Env

use of org.eclipse.che.api.core.model.workspace.devfile.Env in project devspaces-images by redhat-developer.

the class EnvVars method apply.

/**
 * Applies the specified env vars list to the specified containers.
 *
 * <p>If a container does not have the corresponding env - it will be provisioned, if it has - the
 * value will be overridden.
 *
 * @param container pod to supply env vars
 * @param toApply env vars to apply
 */
public void apply(Container container, List<? extends Env> toApply) {
    List<EnvVar> targetEnv = container.getEnv();
    if (targetEnv == null) {
        targetEnv = new ArrayList<>();
        container.setEnv(targetEnv);
    }
    for (Env env : toApply) {
        apply(targetEnv, env);
    }
}
Also used : EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Env(org.eclipse.che.api.core.model.workspace.devfile.Env)

Example 5 with Env

use of org.eclipse.che.api.core.model.workspace.devfile.Env in project devspaces-images by redhat-developer.

the class EnvVars method apply.

private void apply(List<EnvVar> targetEnv, Env env) {
    Optional<EnvVar> existingOpt = targetEnv.stream().filter(e -> e.getName().equals(env.getName())).findAny();
    if (existingOpt.isPresent()) {
        EnvVar envVar = existingOpt.get();
        envVar.setValue(env.getValue());
        envVar.setValueFrom(null);
    } else {
        targetEnv.add(new EnvVar(env.getName(), env.getValue(), null));
    }
}
Also used : EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Container(io.fabric8.kubernetes.api.model.Container) Env(org.eclipse.che.api.core.model.workspace.devfile.Env) Set(java.util.Set) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Matcher(java.util.regex.Matcher) Stream(java.util.stream.Stream) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) EnvVar(io.fabric8.kubernetes.api.model.EnvVar)

Aggregations

Env (org.eclipse.che.api.core.model.workspace.devfile.Env)6 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)4 HashSet (java.util.HashSet)4 Optional (java.util.Optional)4 Set (java.util.Set)4 Pattern (java.util.regex.Pattern)4 Container (io.fabric8.kubernetes.api.model.Container)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Function (java.util.function.Function)2 Matcher (java.util.regex.Matcher)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2 Action (org.eclipse.che.api.core.model.workspace.devfile.Action)2