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