use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project devspaces-images by redhat-developer.
the class GitConfigProvisionerTest method testShouldExpectWarningWhenUserManagerThrowsServerException.
@Test
public void testShouldExpectWarningWhenUserManagerThrowsServerException() throws Exception {
when(userManager.getById(eq("id"))).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);
}
use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project devspaces-images by redhat-developer.
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 devspaces-images by redhat-developer.
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 devspaces-images by redhat-developer.
the class KubernetesEnvironmentFactory method doCreate.
@Override
protected KubernetesEnvironment doCreate(@Nullable InternalRecipe recipe, Map<String, InternalMachineConfig> machines, List<Warning> sourceWarnings) throws InfrastructureException, ValidationException {
checkNotNull(recipe, "Null recipe is not supported by kubernetes environment factory");
List<Warning> warnings = new ArrayList<>();
if (sourceWarnings != null) {
warnings.addAll(sourceWarnings);
}
final List<HasMetadata> recipeObjects = recipeParser.parse(recipe);
Map<String, Pod> pods = new HashMap<>();
Map<String, Deployment> deployments = new HashMap<>();
Map<String, Service> services = new HashMap<>();
Map<String, ConfigMap> configMaps = new HashMap<>();
Map<String, PersistentVolumeClaim> pvcs = new HashMap<>();
Map<String, Secret> secrets = new HashMap<>();
boolean isAnyIngressPresent = false;
for (HasMetadata object : recipeObjects) {
checkNotNull(object.getKind(), "Environment contains object without specified kind field");
checkNotNull(object.getMetadata(), "%s metadata must not be null", object.getKind());
checkNotNull(object.getMetadata().getName(), "%s name must not be null", object.getKind());
if (object instanceof Pod) {
putInto(pods, object.getMetadata().getName(), (Pod) object);
} else if (object instanceof Deployment) {
putInto(deployments, object.getMetadata().getName(), (Deployment) object);
} else if (object instanceof Service) {
putInto(services, object.getMetadata().getName(), (Service) object);
} else if (object instanceof Ingress) {
isAnyIngressPresent = true;
} else if (object instanceof PersistentVolumeClaim) {
putInto(pvcs, object.getMetadata().getName(), (PersistentVolumeClaim) object);
} else if (object instanceof Secret) {
putInto(secrets, object.getMetadata().getName(), (Secret) object);
} else if (object instanceof ConfigMap) {
putInto(configMaps, object.getMetadata().getName(), (ConfigMap) object);
} else {
throw new ValidationException(format("Found unknown object type in recipe -- name: '%s', kind: '%s'", object.getMetadata().getName(), object.getKind()));
}
}
if (deployments.size() + pods.size() > 1) {
mergePods(pods, deployments, services);
}
if (isAnyIngressPresent) {
warnings.add(new WarningImpl(Warnings.INGRESSES_IGNORED_WARNING_CODE, Warnings.INGRESSES_IGNORED_WARNING_MESSAGE));
}
KubernetesEnvironment k8sEnv = KubernetesEnvironment.builder().setInternalRecipe(recipe).setMachines(machines).setWarnings(warnings).setPods(pods).setDeployments(deployments).setServices(services).setPersistentVolumeClaims(pvcs).setIngresses(new HashMap<>()).setSecrets(secrets).setConfigMaps(configMaps).build();
envValidator.validate(k8sEnv);
return k8sEnv;
}
use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project che-server by eclipse-che.
the class GitConfigProvisionerTest method testShouldExpectWarningWhenUserManagerThrowsServerException.
@Test
public void testShouldExpectWarningWhenUserManagerThrowsServerException() throws Exception {
when(userManager.getById(eq("id"))).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);
}
Aggregations