Search in sources :

Example 31 with WarningImpl

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

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

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

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)

Example 33 with WarningImpl

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

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

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

the class PreviewUrlCommandProvisioner method injectsPreviewUrlToCommands.

/**
 * Go through all commands, find matching service and exposed host. Then construct full preview
 * url from this data and set it as Command's parameter under `previewUrl` key.
 *
 * @param env environment to get commands
 * @param namespace current kubernetes namespace where we're looking for services and ingresses
 */
private void injectsPreviewUrlToCommands(E env, KubernetesNamespace namespace) throws InfrastructureException {
    if (env.getCommands() == null) {
        return;
    }
    List<T> exposureObjects = loadExposureObjects(namespace);
    List<Service> services = namespace.services().get();
    for (CommandImpl command : env.getCommands().stream().filter(c -> c.getPreviewUrl() != null).collect(Collectors.toList())) {
        Optional<Service> foundService = Services.findServiceWithPort(services, command.getPreviewUrl().getPort());
        if (!foundService.isPresent()) {
            String message = String.format("unable to find service for port '%s' for command '%s'", command.getPreviewUrl().getPort(), command.getName());
            LOG.warn(message);
            env.addWarning(new WarningImpl(NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL, String.format(NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL_MESSAGE, message)));
            continue;
        }
        Optional<String> foundHost = findHostForServicePort(exposureObjects, foundService.get(), command.getPreviewUrl().getPort());
        if (foundHost.isPresent()) {
            command.getAttributes().put(PREVIEW_URL_ATTRIBUTE, foundHost.get());
        } else {
            String message = String.format("unable to find ingress for service '%s' and port '%s'", foundService.get(), command.getPreviewUrl().getPort());
            LOG.warn(message);
            env.addWarning(new WarningImpl(NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL, String.format(NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL_MESSAGE, message)));
        }
    }
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL(org.eclipse.che.workspace.infrastructure.kubernetes.Warnings.NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL) Logger(org.slf4j.Logger) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) LoggerFactory(org.slf4j.LoggerFactory) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) KubernetesNamespace(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) List(java.util.List) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) Services(org.eclipse.che.workspace.infrastructure.kubernetes.util.Services) NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL_MESSAGE(org.eclipse.che.workspace.infrastructure.kubernetes.Warnings.NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL_MESSAGE) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Optional(java.util.Optional) Service(io.fabric8.kubernetes.api.model.Service) PREVIEW_URL_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.PREVIEW_URL_ATTRIBUTE) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) Service(io.fabric8.kubernetes.api.model.Service)

Example 35 with WarningImpl

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

the class SshKeysProvisioner method provision.

@Override
@Traced
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
    String workspaceId = identity.getWorkspaceId();
    TracingTags.WORKSPACE_ID.set(workspaceId);
    List<SshPairImpl> vcsSshPairs = getVcsSshPairs(k8sEnv, identity);
    List<SshPairImpl> systemSshPairs = getSystemSshPairs(k8sEnv, identity);
    List<SshPairImpl> allSshPairs = new ArrayList<>(vcsSshPairs);
    allSshPairs.addAll(systemSshPairs);
    List<String> invalidSshKeyNames = allSshPairs.stream().filter(keyPair -> !isValidSshKeyPair(keyPair)).map(SshPairImpl::getName).collect(toList());
    if (!invalidSshKeyNames.isEmpty()) {
        String message = format(Warnings.SSH_KEYS_WILL_NOT_BE_MOUNTED_MESSAGE, invalidSshKeyNames.toString(), identity.getWorkspaceId());
        LOG.warn(message);
        k8sEnv.addWarning(new WarningImpl(Warnings.SSH_KEYS_WILL_NOT_BE_MOUNTED, message));
        runtimeEventsPublisher.sendRuntimeLogEvent(message, ZonedDateTime.now().toString(), identity);
    }
    doProvisionSshKeys(allSshPairs.stream().filter(this::isValidSshKeyPair).collect(toList()), k8sEnv, workspaceId);
    doProvisionVcsSshConfig(vcsSshPairs.stream().filter(this::isValidSshKeyPair).collect(toList()), k8sEnv, workspaceId);
}
Also used : SshPairImpl(org.eclipse.che.api.ssh.server.model.impl.SshPairImpl) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) ArrayList(java.util.ArrayList) Traced(org.eclipse.che.commons.annotation.Traced)

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