Search in sources :

Example 1 with KitLogger

use of org.eclipse.jkube.kit.common.KitLogger in project jkube by eclipse.

the class PodLogService method onPod.

private void onPod(Watcher.Action action, Pod pod, KubernetesClient kubernetes, String namespace, String ctrlCMessage, boolean followLog) {
    String name = KubernetesHelper.getName(pod);
    if (action.equals(Watcher.Action.DELETED)) {
        addedPods.remove(name);
        if (Objects.equals(watchingPodName, name)) {
            watchingPodName = null;
            addedPods.remove(name);
        }
    } else {
        if (action.equals(Watcher.Action.ADDED) || action.equals(Watcher.Action.MODIFIED)) {
            addedPods.put(name, pod);
        }
    }
    Pod watchPod = KubernetesHelper.getNewestPod(addedPods.values());
    String newestPodName = KubernetesHelper.getName(watchPod);
    KitLogger statusLog = Objects.equals(name, newestPodName) ? context.getNewPodLog() : context.getOldPodLog();
    if (!action.equals(Watcher.Action.MODIFIED) || watchingPodName == null || !watchingPodName.equals(name)) {
        statusLog.info("%s status: %s%s", name, getPodStatusDescription(pod), getPodStatusMessagePostfix(action));
    }
    if (watchPod != null && KubernetesHelper.isPodRunning(watchPod)) {
        watchLogOfPodName(kubernetes, namespace, ctrlCMessage, followLog, watchPod, KubernetesHelper.getName(watchPod));
    }
}
Also used : KitLogger(org.eclipse.jkube.kit.common.KitLogger) Pod(io.fabric8.kubernetes.api.model.Pod)

Example 2 with KitLogger

use of org.eclipse.jkube.kit.common.KitLogger in project jkube by eclipse.

the class WatcherManager method watch.

public static void watch(List<ImageConfiguration> ret, String namespace, Collection<HasMetadata> resources, WatcherContext watcherCtx) throws Exception {
    final PluginServiceFactory<WatcherContext> pluginFactory = new PluginServiceFactory<>(watcherCtx);
    if (watcherCtx.isUseProjectClasspath()) {
        pluginFactory.addAdditionalClassLoader(ClassUtil.createProjectClassLoader(watcherCtx.getBuildContext().getProject().getCompileClassPathElements(), watcherCtx.getLogger()));
    }
    final boolean isOpenshift = watcherCtx.getJKubeServiceHub().getClusterAccess().isOpenShift();
    final PlatformMode mode = isOpenshift ? PlatformMode.openshift : PlatformMode.kubernetes;
    final KitLogger log = watcherCtx.getLogger();
    final List<Watcher> watchers = pluginFactory.createServiceObjects(SERVICE_PATHS);
    final List<Watcher> usableWatchers = watcherCtx.getConfig().prepareProcessors(watchers, "watcher");
    log.verbose("Watchers:");
    Watcher chosen = null;
    for (Watcher watcher : usableWatchers) {
        if (watcher.isApplicable(ret, resources, mode)) {
            if (chosen == null) {
                log.verbose(" - %s [selected]", watcher.getName());
                chosen = watcher;
            } else {
                log.verbose(" - %s", watcher.getName());
            }
        } else {
            log.verbose(" - %s [not applicable]", watcher.getName());
        }
    }
    if (chosen == null) {
        throw new IllegalStateException("No watchers can be used for the current project");
    }
    log.info("Running watcher %s", chosen.getName());
    chosen.watch(ret, namespace, resources, mode);
}
Also used : KitLogger(org.eclipse.jkube.kit.common.KitLogger) PlatformMode(org.eclipse.jkube.kit.config.resource.PlatformMode) PluginServiceFactory(org.eclipse.jkube.kit.common.util.PluginServiceFactory)

Example 3 with KitLogger

use of org.eclipse.jkube.kit.common.KitLogger in project jkube by eclipse.

the class KubernetesApplyTask method applyEntities.

private void applyEntities(String fileName, final Collection<HasMetadata> entities) throws InterruptedException {
    KitLogger serviceLogger = createLogger("[[G]][SVC][[G]] [[s]]");
    applyService.applyEntities(fileName, entities, serviceLogger, kubernetesExtension.getServiceUrlWaitTimeSecondsOrDefault());
}
Also used : KitLogger(org.eclipse.jkube.kit.common.KitLogger)

Example 4 with KitLogger

use of org.eclipse.jkube.kit.common.KitLogger in project jkube by eclipse.

the class SpringBootWatcher method runRemoteSpringApplication.

private void runRemoteSpringApplication(String url) {
    log.info("Running RemoteSpringApplication against endpoint: " + url);
    String remoteSecret = validateSpringBootDevtoolsSettings();
    ClassLoader classLoader = getClass().getClassLoader();
    if (classLoader instanceof URLClassLoader) {
        URLClassLoader pluginClassLoader = (URLClassLoader) classLoader;
        try (URLClassLoader projectClassLoader = ClassUtil.createProjectClassLoader(getContext().getBuildContext().getProject().getCompileClassPathElements(), log)) {
            URLClassLoader[] classLoaders = { projectClassLoader, pluginClassLoader };
            StringBuilder buffer = new StringBuilder("java -cp ");
            int count = 0;
            for (URLClassLoader urlClassLoader : classLoaders) {
                URL[] urLs = urlClassLoader.getURLs();
                for (URL u : urLs) {
                    if (count++ > 0) {
                        buffer.append(File.pathSeparator);
                    }
                    try {
                        URI uri = u.toURI();
                        File file = new File(uri);
                        buffer.append(file.getCanonicalPath());
                    } catch (Exception e) {
                        throw new IllegalStateException("Failed to create classpath: " + e, e);
                    }
                }
            }
            // Add dev tools to the classpath (the main class is not read from BOOT-INF/lib)
            try {
                File devtools = getSpringBootDevToolsJar(getContext().getBuildContext().getProject());
                buffer.append(File.pathSeparator);
                buffer.append(devtools.getCanonicalPath());
            } catch (Exception e) {
                throw new IllegalStateException("Failed to include devtools in the classpath: " + e, e);
            }
            buffer.append(" -Dspring.devtools.remote.secret=");
            buffer.append(remoteSecret);
            buffer.append(" org.springframework.boot.devtools.RemoteSpringApplication ");
            buffer.append(url);
            try {
                String command = buffer.toString();
                log.debug("Running: " + command);
                final Process process = Runtime.getRuntime().exec(command);
                final AtomicBoolean outputEnabled = new AtomicBoolean(true);
                Runtime.getRuntime().addShutdownHook(new Thread("jkube:watch [spring-boot] shutdown hook") {

                    @Override
                    public void run() {
                        log.info("Terminating the Spring remote client...");
                        outputEnabled.set(false);
                        process.destroy();
                    }
                });
                KitLogger logger = new PrefixedLogger("Spring-Remote", log);
                Thread stdOutPrinter = startOutputProcessor(logger, process.getInputStream(), false, outputEnabled);
                Thread stdErrPrinter = startOutputProcessor(logger, process.getErrorStream(), true, outputEnabled);
                int status = process.waitFor();
                stdOutPrinter.join();
                stdErrPrinter.join();
                if (status != 0) {
                    log.warn("Process returned status: %s", status);
                }
            } catch (InterruptedException ex) {
                Thread.currentThread().interrupt();
            } catch (Exception e) {
                throw new RuntimeException("Failed to run RemoteSpringApplication: " + e, e);
            }
        } catch (IOException e) {
            log.warn("Instructed to use project classpath, but cannot. Continuing build if we can: ", e);
        }
    } else {
        throw new IllegalStateException("ClassLoader must be a URLClassLoader but it is: " + classLoader.getClass().getName());
    }
}
Also used : IOException(java.io.IOException) URI(java.net.URI) URL(java.net.URL) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) KitLogger(org.eclipse.jkube.kit.common.KitLogger) PrefixedLogger(org.eclipse.jkube.kit.common.PrefixedLogger) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) File(java.io.File)

Example 5 with KitLogger

use of org.eclipse.jkube.kit.common.KitLogger in project jkube by eclipse.

the class BuildServiceTest method setUp.

@Before
public void setUp() {
    mockedDockerAccess = mock(DockerAccess.class, RETURNS_DEEP_STUBS);
    ArchiveService mockedArchiveService = mock(ArchiveService.class, RETURNS_DEEP_STUBS);
    RegistryService mockedRegistryService = mock(RegistryService.class, RETURNS_DEEP_STUBS);
    KitLogger mockedLog = mock(KitLogger.SilentLogger.class, RETURNS_DEEP_STUBS);
    mockedImagePullManager = mock(ImagePullManager.class, RETURNS_DEEP_STUBS);
    mockedJKubeConfiguration = mock(JKubeConfiguration.class, RETURNS_DEEP_STUBS);
    QueryService mockedQueryService = new QueryService(mockedDockerAccess);
    buildService = new BuildService(mockedDockerAccess, mockedQueryService, mockedRegistryService, mockedArchiveService, mockedLog);
    imageConfiguration = ImageConfiguration.builder().name("image-name").build(BuildConfiguration.builder().from("from").tags(Collections.singletonList("latest")).build()).build();
}
Also used : DockerAccess(org.eclipse.jkube.kit.build.service.docker.access.DockerAccess) KitLogger(org.eclipse.jkube.kit.common.KitLogger) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) Before(org.junit.Before)

Aggregations

KitLogger (org.eclipse.jkube.kit.common.KitLogger)11 JKubeConfiguration (org.eclipse.jkube.kit.common.JKubeConfiguration)4 File (java.io.File)3 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)3 BuildServiceConfig (org.eclipse.jkube.kit.config.service.BuildServiceConfig)3 JKubeServiceHub (org.eclipse.jkube.kit.config.service.JKubeServiceHub)3 Before (org.junit.Before)3 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)1 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 Quantity (io.fabric8.kubernetes.api.model.Quantity)1 WatchEvent (io.fabric8.kubernetes.api.model.WatchEvent)1 Serialization (io.fabric8.kubernetes.client.utils.Serialization)1 Build (io.fabric8.openshift.api.model.Build)1 BuildBuilder (io.fabric8.openshift.api.model.BuildBuilder)1 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)1 BuildConfigBuilder (io.fabric8.openshift.api.model.BuildConfigBuilder)1 BuildStrategyBuilder (io.fabric8.openshift.api.model.BuildStrategyBuilder)1