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"));
}
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"));
}
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;
}
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);
}
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);
}
Aggregations