Search in sources :

Example 6 with Warning

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

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)

Example 7 with Warning

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

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

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

the class RestartPolicyRewriterTest method verifyWarnings.

private void verifyWarnings(Warning... expectedWarnings) {
    final Iterator<Warning> actualWarnings = captureWarnings().iterator();
    for (Warning expected : expectedWarnings) {
        if (!actualWarnings.hasNext()) {
            fail("It is expected to receive environment warning");
        }
        final Warning actual = actualWarnings.next();
        assertEquals(actual, expected);
    }
    if (actualWarnings.hasNext()) {
        fail("No more warnings expected");
    }
}
Also used : Warning(org.eclipse.che.api.core.model.workspace.Warning)

Example 9 with Warning

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

the class KubernetesPluginsToolingApplierTest method shouldFillInWarningIfChePluginDoesNotHaveAnyContainersButThereAreRelatedCommands.

@Test
public void shouldFillInWarningIfChePluginDoesNotHaveAnyContainersButThereAreRelatedCommands() throws Exception {
    // given
    ChePlugin chePlugin = createChePlugin("somePublisher/custom-name/0.0.3");
    String pluginRef = chePlugin.getId();
    CommandImpl pluginCommand = new CommandImpl("test-command", "echo Hello World!", "custom");
    pluginCommand.getAttributes().put("plugin", pluginRef);
    internalEnvironment.getCommands().add(pluginCommand);
    // when
    applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
    // then
    List<Warning> envWarnings = internalEnvironment.getWarnings();
    assertEquals(envWarnings.size(), 1);
    Warning warning = envWarnings.get(0);
    assertEquals(warning.getCode(), Warnings.COMMAND_IS_CONFIGURED_IN_PLUGIN_WITHOUT_CONTAINERS_WARNING_CODE);
    assertEquals(warning.getMessage(), "There are configured commands for plugin 'somePublisher/custom-name/0.0.3' that doesn't have any containers");
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) Warning(org.eclipse.che.api.core.model.workspace.Warning) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) Test(org.testng.annotations.Test)

Example 10 with Warning

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

the class OpenShiftEnvironmentFactory method doCreate.

@Override
protected OpenShiftEnvironment doCreate(@Nullable InternalRecipe recipe, Map<String, InternalMachineConfig> machines, List<Warning> sourceWarnings) throws InfrastructureException, ValidationException {
    checkNotNull(recipe, "Null recipe is not supported by openshift environment factory");
    List<Warning> warnings = new ArrayList<>();
    if (sourceWarnings != null) {
        warnings.addAll(sourceWarnings);
    }
    final List<HasMetadata> list = k8sObjectsParser.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, Route> routes = new HashMap<>();
    Map<String, Secret> secrets = new HashMap<>();
    for (HasMetadata object : list) {
        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 DeploymentConfig) {
            throw new ValidationException("Supporting of deployment configs is not implemented yet.");
        } else 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 Route) {
            putInto(routes, object.getMetadata().getName(), (Route) object);
        } 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);
    }
    OpenShiftEnvironment osEnv = OpenShiftEnvironment.builder().setInternalRecipe(recipe).setMachines(machines).setWarnings(warnings).setPods(pods).setDeployments(deployments).setServices(services).setPersistentVolumeClaims(pvcs).setSecrets(secrets).setConfigMaps(configMaps).setRoutes(routes).build();
    envValidator.validate(osEnv);
    return osEnv;
}
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) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Service(io.fabric8.kubernetes.api.model.Service) Secret(io.fabric8.kubernetes.api.model.Secret) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Route(io.fabric8.openshift.api.model.Route)

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