Search in sources :

Example 11 with Warning

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

the class WorkspaceRuntimesTest method mockContext.

private RuntimeContext mockContext(RuntimeIdentity identity) throws ValidationException, InfrastructureException {
    RuntimeContext context = mock(RuntimeContext.class);
    InternalEnvironment internalEnvironment = mock(InternalEnvironment.class);
    lenient().doReturn(internalEnvironment).when(testEnvFactory).create(any(Environment.class));
    lenient().doReturn(context).when(infrastructure).prepare(eq(identity), eq(internalEnvironment));
    lenient().when(context.getInfrastructure()).thenReturn(infrastructure);
    lenient().when(context.getIdentity()).thenReturn(identity);
    lenient().when(context.getRuntime()).thenReturn(new TestInternalRuntime(context));
    lenient().when(context.getEnvironment()).thenReturn(internalEnvironment);
    List<Warning> warnings = new ArrayList<>();
    warnings.add(createWarning());
    lenient().when(internalEnvironment.getWarnings()).thenReturn(warnings);
    return context;
}
Also used : Warning(org.eclipse.che.api.core.model.workspace.Warning) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) ArrayList(java.util.ArrayList) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) Environment(org.eclipse.che.api.core.model.workspace.config.Environment) RuntimeContext(org.eclipse.che.api.workspace.server.spi.RuntimeContext)

Example 12 with Warning

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

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 13 with Warning

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

the class InternalEnvironmentFactory method create.

/**
 * Creates a valid instance of InternalEnvironment.
 *
 * <p>To construct a valid instance it performs the following actions:
 *
 * <ul>
 *   <li>download recipe content if it is needed;
 *   <li>retrieve the configured installers from installers registry;
 *   <li>normalize servers port by adding default protocol in port if it is absent;
 *   <li>validate the environment machines;
 *   <li>invoke implementation specific method that should validate and parse recipe;
 *   <li>ensure there are environment variables pointing to machine names;
 * </ul>
 *
 * @param sourceEnv the environment
 * @return InternalEnvironment a valid InternalEnvironment instance
 * @throws InfrastructureException if exception occurs on recipe downloading
 * @throws InfrastructureException if infrastructure specific error occurs
 * @throws ValidationException if validation fails
 */
public T create(@Nullable final Environment sourceEnv) throws InfrastructureException, ValidationException {
    Map<String, InternalMachineConfig> machines = new HashMap<>();
    List<Warning> warnings = new ArrayList<>();
    InternalRecipe recipe = null;
    if (sourceEnv != null) {
        recipe = recipeRetriever.getRecipe(sourceEnv.getRecipe());
        for (Map.Entry<String, ? extends MachineConfig> machineEntry : sourceEnv.getMachines().entrySet()) {
            MachineConfig machineConfig = machineEntry.getValue();
            machines.put(machineEntry.getKey(), new InternalMachineConfig(normalizeServers(machineConfig.getServers()), machineConfig.getEnv(), machineConfig.getAttributes(), machineConfig.getVolumes()));
        }
        machinesValidator.validate(machines);
    }
    T internalEnv = doCreate(recipe, machines, warnings);
    internalEnv.getMachines().values().forEach(m -> m.getAttributes().put(CONTAINER_SOURCE_ATTRIBUTE, RECIPE_CONTAINER_SOURCE));
    return internalEnv;
}
Also used : Warning(org.eclipse.che.api.core.model.workspace.Warning) HashMap(java.util.HashMap) MachineConfig(org.eclipse.che.api.core.model.workspace.config.MachineConfig) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with Warning

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

the class GitConfigProvisionerTest method testShouldExpectWarningWhenUserManagerThrowsServerException.

@Test
public void testShouldExpectWarningWhenUserManagerThrowsServerException() throws Exception {
    when(userManager.getById(eq("id"))).thenThrow(new ServerException("message"));
    gitConfigProvisioner.provision(k8sEnv, runtimeIdentity);
    verifyNoMoreInteractions(runtimeIdentity);
    List<Warning> warnings = k8sEnv.getWarnings();
    assertEquals(warnings.size(), 1);
    Warning actualWarning = warnings.get(0);
    String warnMsg = format(Warnings.EXCEPTION_IN_USER_MANAGEMENT_DURING_GIT_PROVISION_MESSAGE_FMT, "message");
    Warning expectedWarning = new WarningImpl(Warnings.EXCEPTION_IN_USER_MANAGEMENT_DURING_GIT_PROVISION_WARNING_CODE, warnMsg);
    assertEquals(expectedWarning, actualWarning);
}
Also used : Warning(org.eclipse.che.api.core.model.workspace.Warning) ServerException(org.eclipse.che.api.core.ServerException) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) Test(org.testng.annotations.Test)

Example 15 with Warning

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

the class InternalEnvironmentFactory method create.

/**
 * Creates a valid instance of InternalEnvironment.
 *
 * <p>To construct a valid instance it performs the following actions:
 *
 * <ul>
 *   <li>download recipe content if it is needed;
 *   <li>retrieve the configured installers from installers registry;
 *   <li>normalize servers port by adding default protocol in port if it is absent;
 *   <li>validate the environment machines;
 *   <li>invoke implementation specific method that should validate and parse recipe;
 *   <li>ensure there are environment variables pointing to machine names;
 * </ul>
 *
 * @param sourceEnv the environment
 * @return InternalEnvironment a valid InternalEnvironment instance
 * @throws InfrastructureException if exception occurs on recipe downloading
 * @throws InfrastructureException if infrastructure specific error occurs
 * @throws ValidationException if validation fails
 */
public T create(@Nullable final Environment sourceEnv) throws InfrastructureException, ValidationException {
    Map<String, InternalMachineConfig> machines = new HashMap<>();
    List<Warning> warnings = new ArrayList<>();
    InternalRecipe recipe = null;
    if (sourceEnv != null) {
        recipe = recipeRetriever.getRecipe(sourceEnv.getRecipe());
        for (Map.Entry<String, ? extends MachineConfig> machineEntry : sourceEnv.getMachines().entrySet()) {
            MachineConfig machineConfig = machineEntry.getValue();
            machines.put(machineEntry.getKey(), new InternalMachineConfig(normalizeServers(machineConfig.getServers()), machineConfig.getEnv(), machineConfig.getAttributes(), machineConfig.getVolumes()));
        }
        machinesValidator.validate(machines);
    }
    T internalEnv = doCreate(recipe, machines, warnings);
    internalEnv.getMachines().values().forEach(m -> m.getAttributes().put(CONTAINER_SOURCE_ATTRIBUTE, RECIPE_CONTAINER_SOURCE));
    return internalEnv;
}
Also used : Warning(org.eclipse.che.api.core.model.workspace.Warning) HashMap(java.util.HashMap) MachineConfig(org.eclipse.che.api.core.model.workspace.config.MachineConfig) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Warning (org.eclipse.che.api.core.model.workspace.Warning)20 Test (org.testng.annotations.Test)10 ArrayList (java.util.ArrayList)8 WarningImpl (org.eclipse.che.api.workspace.server.model.impl.WarningImpl)8 HashMap (java.util.HashMap)6 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)4 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)4 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)4 Pod (io.fabric8.kubernetes.api.model.Pod)4 Secret (io.fabric8.kubernetes.api.model.Secret)4 Service (io.fabric8.kubernetes.api.model.Service)4 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)4 ServerException (org.eclipse.che.api.core.ServerException)4 ValidationException (org.eclipse.che.api.core.ValidationException)4 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)4 ChePlugin (org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin)4 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)2 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)2 Route (io.fabric8.openshift.api.model.Route)2 Map (java.util.Map)2