use of io.fabric8.kubernetes.client.Watch in project fabric8-maven-plugin by fabric8io.
the class DockerImageWatcher method watch.
@Override
public void watch(List<ImageConfiguration> configs, final Set<HasMetadata> resources, PlatformMode mode) {
BuildService.BuildContext buildContext = getContext().getBuildContext();
WatchService.WatchContext watchContext = getContext().getWatchContext();
// add a image customizer
watchContext = new WatchService.WatchContext.Builder(watchContext).imageCustomizer(new Task<ImageConfiguration>() {
@Override
public void execute(ImageConfiguration imageConfiguration) throws DockerAccessException, MojoExecutionException, MojoFailureException {
buildImage(imageConfiguration);
}
}).containerRestarter(new Task<WatchService.ImageWatcher>() {
@Override
public void execute(WatchService.ImageWatcher imageWatcher) throws DockerAccessException, MojoExecutionException, MojoFailureException {
restartContainer(imageWatcher, resources);
}
}).build();
ServiceHub hub = getContext().getServiceHub();
try {
hub.getWatchService().watch(watchContext, buildContext, configs);
} catch (Exception ex) {
throw new RuntimeException("Error while watching", ex);
}
}
use of io.fabric8.kubernetes.client.Watch in project fabric8-maven-plugin by fabric8io.
the class SpringBootWatcher method runRemoteSpringApplication.
private void runRemoteSpringApplication(String url) {
log.info("Running RemoteSpringApplication against endpoint: " + url);
Properties properties = SpringBootUtil.getSpringBootApplicationProperties(getContext().getProject());
String remoteSecret = properties.getProperty(DEV_TOOLS_REMOTE_SECRET, System.getProperty(DEV_TOOLS_REMOTE_SECRET));
if (Strings.isNullOrBlank(remoteSecret)) {
log.warn("There is no `%s` property defined in your src/main/resources/application.properties. Please add one!", DEV_TOOLS_REMOTE_SECRET);
throw new IllegalStateException("No " + DEV_TOOLS_REMOTE_SECRET + " property defined in application.properties or system properties");
}
ClassLoader classLoader = getClass().getClassLoader();
if (classLoader instanceof URLClassLoader) {
URLClassLoader pluginClassLoader = (URLClassLoader) classLoader;
URLClassLoader projectClassLoader = ClassUtil.createProjectClassLoader(getContext().getProject(), 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().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("fabric8:watch [spring-boot] shutdown hook") {
@Override
public void run() {
log.info("Terminating the Spring remote client...");
outputEnabled.set(false);
process.destroy();
}
});
Logger 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 (Exception e) {
throw new RuntimeException("Failed to run RemoteSpringApplication: " + e, e);
}
} else {
throw new IllegalStateException("ClassLoader must be a URLClassLoader but it is: " + classLoader.getClass().getName());
}
}
use of io.fabric8.kubernetes.client.Watch in project watchdog by isdream.
the class KubernetesListener method start.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void start(Object client, Configure config) throws Exception {
// System.out.println(config.getApiVersion());
if (ObjectUtils.isNull(client) && ObjectUtils.isNull(config)) {
throw new Exception("Invalid paremeters");
}
// it may throw Exception if wrong PROPERTY_KIND values
Object model = getModelParamtersGenerator().getKindModel(client, config.getKind());
if (model instanceof Namespaceable || model instanceof AnyNamespaceable) {
String namespace = config.getProperties().getOrDefault(PROPERTY_NAMESPACE, ALL_NAMESPACE);
if (ALL_NAMESPACE.equals(namespace)) {
model = ((AnyNamespaceable) model).inAnyNamespace();
} else {
model = ((Namespaceable) model).inNamespace(namespace);
}
}
List<String> handlers = config.getHandlers();
if (handlers.isEmpty()) {
throw new Exception("No handlers");
}
Handler handler = (Handler) Class.forName(handlers.remove(0)).newInstance();
Handler thisHandler = handler;
for (String name : handlers) {
Handler nextHandler = (Handler) Class.forName(name).newInstance();
thisHandler.setNextHandler(nextHandler);
thisHandler = nextHandler;
}
System.out.println(model.getClass());
((Watchable) model).watch(new KubernetesWatcher(handler));
}
use of io.fabric8.kubernetes.client.Watch in project fabric8 by fabric8io.
the class KubernetesConfigAdminBridgeTest method testAndOr.
@Test
public void testAndOr() {
System.setProperty("fabric8.pid.filters", "appName=A;B,database.name=my.oracle.datasource");
KubernetesMockServer plainServer = new KubernetesMockServer(false);
plainServer.expect().get().withPath("/api/v1/namespaces/test/configmaps?labelSelector=karaf.pid,appName%20in%20(A,B),database.name%20in%20(my.oracle.datasource)&watch=true").andReturnChunked(200).always();
plainServer.expect().get().withPath("/api/v1/namespaces/test/configmaps?labelSelector=karaf.pid,appName%20in%20(A,B),database.name%20in%20(my.oracle.datasource)").andReturn(200, cmEmptyList).once();
KubernetesConfigAdminBridge kcab = new KubernetesConfigAdminBridge();
kcab.bindConfigAdmin(caService);
kcab.bindKubernetesClient(plainServer.createClient());
kcab.activate();
}
use of io.fabric8.kubernetes.client.Watch in project fabric8 by fabric8io.
the class KubernetesConfigAdminBridgeTest method testAand.
@Test
public void testAand() {
System.setProperty("fabric8.pid.filters", "appName=A,database.name=my.oracle.datasource");
KubernetesMockServer plainServer = new KubernetesMockServer(false);
plainServer.expect().get().withPath("/api/v1/namespaces/test/configmaps?labelSelector=karaf.pid,appName%20in%20(A),database.name%20in%20(my.oracle.datasource)&watch=true").andReturnChunked(200).always();
plainServer.expect().get().withPath("/api/v1/namespaces/test/configmaps?labelSelector=karaf.pid,appName%20in%20(A),database.name%20in%20(my.oracle.datasource)").andReturn(200, cmEmptyList).once();
KubernetesConfigAdminBridge kcab = new KubernetesConfigAdminBridge();
kcab.bindConfigAdmin(caService);
kcab.bindKubernetesClient(plainServer.createClient());
kcab.activate();
}
Aggregations