Search in sources :

Example 21 with WarningImpl

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

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

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

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

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

the class WorkspaceManagerTest method mockRuntime.

private TestRuntime mockRuntime(WorkspaceImpl workspace, WorkspaceStatus status) throws Exception {
    MachineImpl machine1 = createMachine();
    MachineImpl machine2 = createMachine();
    Map<String, Machine> machines = new HashMap<>();
    machines.put("machine1", machine1);
    machines.put("machine2", machine2);
    List<WarningImpl> warnings = new ArrayList<>();
    warnings.add(new WarningImpl(103, "used default value"));
    warnings.add(new WarningImpl(105, "specified configuration parameter is ignored"));
    TestRuntime runtime = new TestRuntime(machines, workspace.getConfig().getCommands(), warnings);
    lenient().doAnswer(inv -> {
        workspace.setStatus(status);
        workspace.setRuntime(new RuntimeImpl(runtime.getActiveEnv(), runtime.getMachines(), runtime.getOwner(), runtime.getCommands(), runtime.getWarnings()));
        return null;
    }).when(runtimes).injectRuntime(workspace);
    lenient().when(runtimes.isAnyActive()).thenReturn(true);
    return runtime;
}
Also used : MachineImpl(org.eclipse.che.api.workspace.server.model.impl.MachineImpl) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Machine(org.eclipse.che.api.core.model.workspace.runtime.Machine)

Example 24 with WarningImpl

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

the class InternalRuntimeTest method shouldAddAWarningInsteadOfAServerIfURLRewritingFailed.

@Test
public void shouldAddAWarningInsteadOfAServerIfURLRewritingFailed() throws Exception {
    // given
    URLRewriter urlRewriter = spy(new URLRewriter.NoOpURLRewriter());
    setRunningRuntime(urlRewriter);
    Map<String, MachineImpl> expectedMachines = new HashMap<>();
    Map<String, MachineImpl> internalMachines = new HashMap<>();
    MachineImpl machine1 = createMachine();
    MachineImpl machine2 = createMachine();
    HashMap<String, ServerImpl> expectedServers = new HashMap<>(machine1.getServers());
    String badServerName = "badServer";
    String badServerURL = "ws://failing-rewriting:8000";
    String badServerRewritingExcMessage = "test exc";
    ServerImpl failingRewritingServer = createServer(badServerURL);
    machine1.getServers().put(badServerName, failingRewritingServer);
    internalMachines.put("m1", machine1);
    internalMachines.put("m2", machine2);
    expectedMachines.put("m1", new MachineImpl(machine1.getAttributes(), expectedServers, machine1.getStatus()));
    expectedMachines.put("m2", machine2);
    List<WarningImpl> expectedWarnings = new ArrayList<>();
    expectedWarnings.add(new WarningImpl(InternalRuntime.MALFORMED_SERVER_URL_FOUND, "Malformed URL for " + badServerName + " : " + badServerRewritingExcMessage));
    doReturn(internalMachines).when(internalRuntime).getInternalMachines();
    doThrow(new InfrastructureException(badServerRewritingExcMessage)).when(urlRewriter).rewriteURL(any(RuntimeIdentity.class), any(), anyString(), eq(badServerURL));
    // when
    Map<String, ? extends Machine> actualMachines = internalRuntime.getMachines();
    List<? extends Warning> actualWarnings = internalRuntime.getWarnings();
    // then
    assertEquals(actualMachines, expectedMachines);
    assertEquals(actualWarnings, expectedWarnings);
}
Also used : MachineImpl(org.eclipse.che.api.workspace.server.model.impl.MachineImpl) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) URLRewriter(org.eclipse.che.api.workspace.server.URLRewriter) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) Test(org.testng.annotations.Test)

Example 25 with WarningImpl

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

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