Search in sources :

Example 11 with WarningImpl

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

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 12 with WarningImpl

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

the class RestartPolicyRewriter method rewriteRestartPolicy.

private void rewriteRestartPolicy(PodSpec podSpec, String podName, KubernetesEnvironment env) {
    final String restartPolicy = podSpec.getRestartPolicy();
    if (restartPolicy != null && !DEFAULT_RESTART_POLICY.equalsIgnoreCase(restartPolicy)) {
        final String warnMsg = format(Warnings.RESTART_POLICY_SET_TO_NEVER_WARNING_MESSAGE_FMT, restartPolicy, podName, DEFAULT_RESTART_POLICY);
        env.addWarning(new WarningImpl(Warnings.RESTART_POLICY_SET_TO_NEVER_WARNING_CODE, warnMsg));
    }
    podSpec.setRestartPolicy(DEFAULT_RESTART_POLICY);
}
Also used : WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl)

Example 13 with WarningImpl

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

the class DeploymentMetadataProvisionerTest method shouldAddWarningIfNotAbleToGetWorkspaceAttributes.

@Test
public void shouldAddWarningIfNotAbleToGetWorkspaceAttributes() throws NotFoundException, ServerException, InfrastructureException {
    // given
    doThrow(new NotFoundException("Element not found")).when(workspaceManager).getWorkspace(eq(WS_ID));
    // 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(4200, "Not able to find workspace attributes for " + WS_ID + ". Reason Element not found"));
}
Also used : WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Test(org.testng.annotations.Test)

Example 14 with WarningImpl

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

the class DeploymentMetadataProvisionerTest method shouldAddWarningIfNotAbleToGetWorkspaceAttributesServerException.

@Test
public void shouldAddWarningIfNotAbleToGetWorkspaceAttributesServerException() throws NotFoundException, ServerException, InfrastructureException {
    // given
    doThrow(new ServerException("Connection problem")).when(workspaceManager).getWorkspace(eq(WS_ID));
    // 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, "Not able to find workspace attributes for " + WS_ID + ". Reason Connection problem"));
}
Also used : 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 WarningImpl

use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl 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)

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