Search in sources :

Example 26 with WarningImpl

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);
}
Also used : WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl)

Example 27 with WarningImpl

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)));
        }
    }
}
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 28 with WarningImpl

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;
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Server(org.eclipse.che.api.core.model.workspace.runtime.Server) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map)

Example 29 with WarningImpl

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)));
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Pod(io.fabric8.kubernetes.api.model.Pod) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) Test(org.testng.annotations.Test)

Example 30 with WarningImpl

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));
}
Also used : IngressBuilder(io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder) InternalRecipe(org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) Test(org.testng.annotations.Test)

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