use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project che-server by eclipse-che.
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);
}
use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project che-server by eclipse-che.
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)));
}
}
}
use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project devspaces-images by redhat-developer.
the class InternalRuntime method rewriteExternalServers.
/**
* Convenient method to rewrite incoming external servers in a loop
*
* @param incoming servers
* @return rewritten Map of Servers (name -> Server)
*/
private Map<String, Server> rewriteExternalServers(String machineName, Map<String, ? extends Server> incoming) {
Map<String, Server> outgoing = new HashMap<>();
RuntimeIdentity identity = context.getIdentity();
for (Map.Entry<String, ? extends Server> entry : incoming.entrySet()) {
String name = entry.getKey();
Server incomingServer = entry.getValue();
if (ServerConfig.isInternal(incomingServer.getAttributes())) {
outgoing.put(name, incomingServer);
} else {
try {
ServerImpl server = new ServerImpl(incomingServer).withUrl(urlRewriter.rewriteURL(identity, machineName, name, incomingServer.getUrl()));
outgoing.put(name, server);
} catch (InfrastructureException e) {
context.getEnvironment().getWarnings().add(new WarningImpl(MALFORMED_SERVER_URL_FOUND, "Malformed URL for " + name + " : " + e.getMessage()));
}
}
}
return outgoing;
}
use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project devspaces-images by redhat-developer.
the class RestartPolicyRewriterTest method rewritesRestartPolicyWhenItsDifferentWithDefaultOne.
@Test
public void rewritesRestartPolicyWhenItsDifferentWithDefaultOne() throws Exception {
Pod pod = newPod(TEST_POD_NAME, ALWAYS_RESTART_POLICY);
PodData podData = new PodData(pod.getSpec(), pod.getMetadata());
when(k8sEnv.getPodsData()).thenReturn(singletonMap(TEST_POD_NAME, podData));
restartPolicyRewriter.provision(k8sEnv, runtimeIdentity);
assertEquals(pod.getSpec().getRestartPolicy(), DEFAULT_RESTART_POLICY);
verifyWarnings(new WarningImpl(RESTART_POLICY_SET_TO_NEVER_WARNING_CODE, format("Restart policy '%s' for pod '%s' is rewritten with %s", ALWAYS_RESTART_POLICY, TEST_POD_NAME, DEFAULT_RESTART_POLICY)));
}
use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project devspaces-images by redhat-developer.
the class KubernetesEnvironmentFactoryTest method ignoreIgressesWhenRecipeContainsThem.
@Test
public void ignoreIgressesWhenRecipeContainsThem() throws Exception {
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(new IngressBuilder().withNewMetadata().withName("ingress1").endMetadata().build(), new IngressBuilder().withNewMetadata().withName("ingress2").endMetadata().build()));
final KubernetesEnvironment parsed = k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
assertTrue(parsed.getIngresses().isEmpty());
assertEquals(parsed.getWarnings().size(), 1);
assertEquals(parsed.getWarnings().get(0), new WarningImpl(INGRESSES_IGNORED_WARNING_CODE, INGRESSES_IGNORED_WARNING_MESSAGE));
}
Aggregations