Search in sources :

Example 6 with WarningImpl

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

the class GitConfigProvisionerTest method testShouldExpectWarningWhenPreferenceManagerThrowsServerException.

@Test
public void testShouldExpectWarningWhenPreferenceManagerThrowsServerException() throws Exception {
    when(preferenceManager.find(eq("id"), eq("theia-user-preferences"))).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 7 with WarningImpl

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

the class RestartPolicyRewriterTest method rewritesRestartPolicyWhenItsDifferentWithDefaultOne.

@Test
public void rewritesRestartPolicyWhenItsDifferentWithDefaultOne() throws Exception {
    Pod pod = newPod(TEST_POD_NAME, ALWAYS_RESTART_POLICY);
    PodData podData = new PodData(pod.getSpec(), pod.getMetadata());
    when(k8sEnv.getPodsData()).thenReturn(singletonMap(TEST_POD_NAME, podData));
    restartPolicyRewriter.provision(k8sEnv, runtimeIdentity);
    assertEquals(pod.getSpec().getRestartPolicy(), DEFAULT_RESTART_POLICY);
    verifyWarnings(new WarningImpl(RESTART_POLICY_SET_TO_NEVER_WARNING_CODE, format("Restart policy '%s' for pod '%s' is rewritten with %s", ALWAYS_RESTART_POLICY, TEST_POD_NAME, DEFAULT_RESTART_POLICY)));
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Pod(io.fabric8.kubernetes.api.model.Pod) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) Test(org.testng.annotations.Test)

Example 8 with WarningImpl

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

the class SecureServerExposerFactoryProviderTest method shouldAddWarningIfSecureServerConfiguredInEnvironmentWasNotFound.

@Test
public void shouldAddWarningIfSecureServerConfiguredInEnvironmentWasNotFound() {
    // given
    SecureServerExposerFactoryProvider<KubernetesEnvironment> factoryProvider = new SecureServerExposerFactoryProvider<>(EXPOSER1, factories);
    kubernetesEnvironment.setAttributes(ImmutableMap.of(SECURE_EXPOSER_IMPL_PROPERTY, NON_EXISTING_EXPOSER));
    WarningImpl expectedWarning = new WarningImpl(UNKNOWN_SECURE_SERVER_EXPOSER_CONFIGURED_IN_WS_WARNING_CODE, format(UNKNOWN_EXPOSER_ERROR_TEMPLATE, NON_EXISTING_EXPOSER, String.join(", ", factories.keySet())));
    SecureServerExposerFactory<KubernetesEnvironment> factory = factoryProvider.get(kubernetesEnvironment);
    // then
    assertSame(factory, secureServerExposer1);
    assertEquals(kubernetesEnvironment.getWarnings().size(), 1);
    assertEquals(kubernetesEnvironment.getWarnings().get(0), expectedWarning);
}
Also used : WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Test(org.testng.annotations.Test)

Example 9 with WarningImpl

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

the class DeploymentMetadataProvisionerTest method shouldAddWarningIfLabelAttributeInInvalidFormat.

@Test
public void shouldAddWarningIfLabelAttributeInInvalidFormat() throws NotFoundException, ServerException, InfrastructureException {
    // given
    when(workspace.getAttributes()).thenReturn(ImmutableMap.of(WS_DEPLOYMENT_LABELS_ATTR_NAME, "L1~V1"));
    when(workspaceManager.getWorkspace(eq(WS_ID))).thenReturn(workspace);
    Deployment deployment = newDeployment();
    doReturn(ImmutableMap.of(DEPLOYMENT_NAME, deployment)).when(k8sEnv).getDeploymentsCopy();
    // when
    provisioner.provision(k8sEnv, identity);
    // then
    ArgumentCaptor<WarningImpl> argumentCaptor = ArgumentCaptor.forClass(WarningImpl.class);
    verify(k8sEnv).addWarning(argumentCaptor.capture());
    assertEquals(argumentCaptor.getAllValues().size(), 1);
    assertEquals(argumentCaptor.getValue(), new WarningImpl(NOT_ABLE_TO_PROVISION_WORKSPACE_DEPLOYMENT_LABELS_OR_ANNOTATIONS, "Not able to provision workspace " + WS_ID + " deployment labels or annotations because of invalid configuration. Reason: 'Chunk [L1~V1] is not a valid entry'"));
}
Also used : WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Test(org.testng.annotations.Test)

Example 10 with WarningImpl

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

the class DeploymentMetadataProvisionerTest method shouldAddWarningIfAnnotationAttributeInInvalidFormat.

@Test
public void shouldAddWarningIfAnnotationAttributeInInvalidFormat() throws NotFoundException, ServerException, InfrastructureException {
    // given
    when(workspace.getAttributes()).thenReturn(ImmutableMap.of(WS_DEPLOYMENT_ANNOTATIONS_ATTR_NAME, "A1~V1"));
    when(workspaceManager.getWorkspace(eq(WS_ID))).thenReturn(workspace);
    Deployment deployment = newDeployment();
    doReturn(ImmutableMap.of(DEPLOYMENT_NAME, deployment)).when(k8sEnv).getDeploymentsCopy();
    // when
    provisioner.provision(k8sEnv, identity);
    // then
    ArgumentCaptor<WarningImpl> argumentCaptor = ArgumentCaptor.forClass(WarningImpl.class);
    verify(k8sEnv).addWarning(argumentCaptor.capture());
    assertEquals(argumentCaptor.getAllValues().size(), 1);
    assertEquals(argumentCaptor.getValue(), new WarningImpl(NOT_ABLE_TO_PROVISION_WORKSPACE_DEPLOYMENT_LABELS_OR_ANNOTATIONS, "Not able to provision workspace " + WS_ID + " deployment labels or annotations because of invalid configuration. Reason: 'Chunk [A1~V1] is not a valid entry'"));
}
Also used : WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) 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