Search in sources :

Example 1 with WatcherContext

use of io.fabric8.maven.watcher.api.WatcherContext in project fabric8-maven-plugin by fabric8io.

the class WatcherManager method watch.

public static void watch(List<ImageConfiguration> ret, Set<HasMetadata> resources, WatcherContext watcherCtx) throws Exception {
    PluginServiceFactory<WatcherContext> pluginFactory = watcherCtx.isUseProjectClasspath() ? new PluginServiceFactory<>(watcherCtx, ClassUtil.createProjectClassLoader(watcherCtx.getProject(), watcherCtx.getLogger())) : new PluginServiceFactory<>(watcherCtx);
    boolean isOpenshift = KubernetesHelper.isOpenShift(watcherCtx.getKubernetesClient());
    PlatformMode mode = isOpenshift ? PlatformMode.openshift : PlatformMode.kubernetes;
    List<Watcher> watchers = pluginFactory.createServiceObjects("META-INF/fabric8/watcher-default", "META-INF/fabric8/fabric8-watcher-default", "META-INF/fabric8/watcher", "META-INF/fabric8-watcher");
    ProcessorConfig config = watcherCtx.getConfig();
    Logger log = watcherCtx.getLogger();
    List<Watcher> usableWatchers = config.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, resources, mode);
}
Also used : WatcherContext(io.fabric8.maven.watcher.api.WatcherContext) Watcher(io.fabric8.maven.watcher.api.Watcher) PlatformMode(io.fabric8.maven.core.config.PlatformMode) Logger(io.fabric8.maven.docker.util.Logger) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig)

Example 2 with WatcherContext

use of io.fabric8.maven.watcher.api.WatcherContext in project fabric8-maven-plugin by fabric8io.

the class WatchMojo method executeInternal.

@Override
protected synchronized void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException {
    this.hub = hub;
    URL masterUrl = kubernetes.getMasterUrl();
    KubernetesResourceUtil.validateKubernetesMasterUrl(masterUrl);
    File manifest;
    boolean isOpenshift = KubernetesHelper.isOpenShift(kubernetes);
    if (isOpenshift) {
        manifest = openshiftManifest;
    } else {
        manifest = kubernetesManifest;
    }
    try {
        Set<HasMetadata> resources = KubernetesResourceUtil.loadResources(manifest);
        WatcherContext context = getWatcherContext();
        WatcherManager.watch(getResolvedImages(), resources, context);
    } catch (KubernetesClientException ex) {
        KubernetesResourceUtil.handleKubernetesClientException(ex, this.log);
    } catch (Exception ex) {
        throw new MojoExecutionException("An error has occurred while while trying to watch the resources", ex);
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) WatcherContext(io.fabric8.maven.watcher.api.WatcherContext) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File) URL(java.net.URL) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

WatcherContext (io.fabric8.maven.watcher.api.WatcherContext)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 PlatformMode (io.fabric8.maven.core.config.PlatformMode)1 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)1 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)1 Logger (io.fabric8.maven.docker.util.Logger)1 Watcher (io.fabric8.maven.watcher.api.Watcher)1 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1