Search in sources :

Example 1 with WarningImpl

use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project che-server by eclipse-che.

the class AsyncStorageProvisioner method provision.

public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
    if (!parseBoolean(k8sEnv.getAttributes().get(ASYNC_PERSIST_ATTRIBUTE))) {
        return;
    }
    if (!COMMON_STRATEGY.equals(pvcStrategy)) {
        String message = format("Workspace configuration not valid: Asynchronous storage available only for 'common' PVC strategy, but got %s", pvcStrategy);
        LOG.warn(message);
        k8sEnv.addWarning(new WarningImpl(4200, message));
        throw new InfrastructureException(message);
    }
    if (!isEphemeral(k8sEnv.getAttributes())) {
        String message = format("Workspace configuration not valid: Asynchronous storage available only if '%s' attribute set to false", PERSIST_VOLUMES_ATTRIBUTE);
        LOG.warn(message);
        k8sEnv.addWarning(new WarningImpl(4200, message));
        throw new InfrastructureException(message);
    }
    String namespace = identity.getInfrastructureNamespace();
    String userId = identity.getOwnerId();
    KubernetesClient k8sClient = kubernetesClientFactory.create(identity.getWorkspaceId());
    String configMapName = namespace + ASYNC_STORAGE_CONFIG;
    createPvcIfNotExist(k8sClient, namespace, userId);
    createConfigMapIfNotExist(k8sClient, namespace, configMapName, userId, k8sEnv);
    createAsyncStoragePodIfNotExist(k8sClient, namespace, configMapName, userId);
    createStorageServiceIfNotExist(k8sClient, namespace, userId);
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 2 with WarningImpl

use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project che-server by eclipse-che.

the class KubernetesEnvironmentFactory method doCreate.

@Override
protected KubernetesEnvironment doCreate(@Nullable InternalRecipe recipe, Map<String, InternalMachineConfig> machines, List<Warning> sourceWarnings) throws InfrastructureException, ValidationException {
    checkNotNull(recipe, "Null recipe is not supported by kubernetes environment factory");
    List<Warning> warnings = new ArrayList<>();
    if (sourceWarnings != null) {
        warnings.addAll(sourceWarnings);
    }
    final List<HasMetadata> recipeObjects = recipeParser.parse(recipe);
    Map<String, Pod> pods = new HashMap<>();
    Map<String, Deployment> deployments = new HashMap<>();
    Map<String, Service> services = new HashMap<>();
    Map<String, ConfigMap> configMaps = new HashMap<>();
    Map<String, PersistentVolumeClaim> pvcs = new HashMap<>();
    Map<String, Secret> secrets = new HashMap<>();
    boolean isAnyIngressPresent = false;
    for (HasMetadata object : recipeObjects) {
        checkNotNull(object.getKind(), "Environment contains object without specified kind field");
        checkNotNull(object.getMetadata(), "%s metadata must not be null", object.getKind());
        checkNotNull(object.getMetadata().getName(), "%s name must not be null", object.getKind());
        if (object instanceof Pod) {
            putInto(pods, object.getMetadata().getName(), (Pod) object);
        } else if (object instanceof Deployment) {
            putInto(deployments, object.getMetadata().getName(), (Deployment) object);
        } else if (object instanceof Service) {
            putInto(services, object.getMetadata().getName(), (Service) object);
        } else if (object instanceof Ingress) {
            isAnyIngressPresent = true;
        } else if (object instanceof PersistentVolumeClaim) {
            putInto(pvcs, object.getMetadata().getName(), (PersistentVolumeClaim) object);
        } else if (object instanceof Secret) {
            putInto(secrets, object.getMetadata().getName(), (Secret) object);
        } else if (object instanceof ConfigMap) {
            putInto(configMaps, object.getMetadata().getName(), (ConfigMap) object);
        } else {
            throw new ValidationException(format("Found unknown object type in recipe -- name: '%s', kind: '%s'", object.getMetadata().getName(), object.getKind()));
        }
    }
    if (deployments.size() + pods.size() > 1) {
        mergePods(pods, deployments, services);
    }
    if (isAnyIngressPresent) {
        warnings.add(new WarningImpl(Warnings.INGRESSES_IGNORED_WARNING_CODE, Warnings.INGRESSES_IGNORED_WARNING_MESSAGE));
    }
    KubernetesEnvironment k8sEnv = KubernetesEnvironment.builder().setInternalRecipe(recipe).setMachines(machines).setWarnings(warnings).setPods(pods).setDeployments(deployments).setServices(services).setPersistentVolumeClaims(pvcs).setIngresses(new HashMap<>()).setSecrets(secrets).setConfigMaps(configMaps).build();
    envValidator.validate(k8sEnv);
    return k8sEnv;
}
Also used : Warning(org.eclipse.che.api.core.model.workspace.Warning) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ValidationException(org.eclipse.che.api.core.ValidationException) Pod(io.fabric8.kubernetes.api.model.Pod) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Secret(io.fabric8.kubernetes.api.model.Secret) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim)

Example 3 with WarningImpl

use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project che-server by eclipse-che.

the class KubernetesEnvironmentFactoryTest method ignoreIgressesWhenRecipeContainsThem.

@Test
public void ignoreIgressesWhenRecipeContainsThem() throws Exception {
    when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(new IngressBuilder().withNewMetadata().withName("ingress1").endMetadata().build(), new IngressBuilder().withNewMetadata().withName("ingress2").endMetadata().build()));
    final KubernetesEnvironment parsed = k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
    assertTrue(parsed.getIngresses().isEmpty());
    assertEquals(parsed.getWarnings().size(), 1);
    assertEquals(parsed.getWarnings().get(0), new WarningImpl(INGRESSES_IGNORED_WARNING_CODE, INGRESSES_IGNORED_WARNING_MESSAGE));
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) InternalRecipe(org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) Test(org.testng.annotations.Test)

Example 4 with WarningImpl

use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project che-server by eclipse-che.

the class InternalRuntime method rewriteExternalServers.

/**
 * Convenient method to rewrite incoming external servers in a loop
 *
 * @param incoming servers
 * @return rewritten Map of Servers (name -> Server)
 */
private Map<String, Server> rewriteExternalServers(String machineName, Map<String, ? extends Server> incoming) {
    Map<String, Server> outgoing = new HashMap<>();
    RuntimeIdentity identity = context.getIdentity();
    for (Map.Entry<String, ? extends Server> entry : incoming.entrySet()) {
        String name = entry.getKey();
        Server incomingServer = entry.getValue();
        if (ServerConfig.isInternal(incomingServer.getAttributes())) {
            outgoing.put(name, incomingServer);
        } else {
            try {
                ServerImpl server = new ServerImpl(incomingServer).withUrl(urlRewriter.rewriteURL(identity, machineName, name, incomingServer.getUrl()));
                outgoing.put(name, server);
            } catch (InfrastructureException e) {
                context.getEnvironment().getWarnings().add(new WarningImpl(MALFORMED_SERVER_URL_FOUND, "Malformed URL for " + name + " : " + e.getMessage()));
            }
        }
    }
    return outgoing;
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Server(org.eclipse.che.api.core.model.workspace.runtime.Server) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map)

Example 5 with WarningImpl

use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project che-server by eclipse-che.

the class GitConfigProvisionerTest method testShouldExpectWarningWhenJsonObjectInPreferencesIsNotValid.

@Test
public void testShouldExpectWarningWhenJsonObjectInPreferencesIsNotValid() throws Exception {
    Map<String, String> preferences = singletonMap("theia-user-preferences", "{#$%}");
    when(preferenceManager.find(eq("id"), eq("theia-user-preferences"))).thenReturn(preferences);
    gitConfigProvisioner.provision(k8sEnv, runtimeIdentity);
    verifyNoMoreInteractions(runtimeIdentity);
    List<Warning> warnings = k8sEnv.getWarnings();
    assertEquals(warnings.size(), 1);
    Warning actualWarning = warnings.get(0);
    String warnMsg = format(Warnings.JSON_IS_NOT_A_VALID_REPRESENTATION_FOR_AN_OBJECT_OF_TYPE_MESSAGE_FMT, "java.io.EOFException: End of input at line 1 column 6 path $.");
    Warning expectedWarning = new WarningImpl(Warnings.JSON_IS_NOT_A_VALID_REPRESENTATION_FOR_AN_OBJECT_OF_TYPE_WARNING_CODE, warnMsg);
    assertEquals(expectedWarning, actualWarning);
}
Also used : Warning(org.eclipse.che.api.core.model.workspace.Warning) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) Test(org.testng.annotations.Test)

Aggregations

WarningImpl (org.eclipse.che.api.workspace.server.model.impl.WarningImpl)36 Test (org.testng.annotations.Test)22 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 Warning (org.eclipse.che.api.core.model.workspace.Warning)8 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)6 ServerException (org.eclipse.che.api.core.ServerException)6 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)4 Pod (io.fabric8.kubernetes.api.model.Pod)4 Service (io.fabric8.kubernetes.api.model.Service)4 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)4 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)4 MachineImpl (org.eclipse.che.api.workspace.server.model.impl.MachineImpl)4 ServerImpl (org.eclipse.che.api.workspace.server.model.impl.ServerImpl)4 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)4 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)2