use of io.fabric8.arquillian.kubernetes.log.Logger in project fabric8-maven-plugin by fabric8io.
the class ResourceMojo method getResolvedImages.
private List<ImageConfiguration> getResolvedImages(List<ImageConfiguration> images, final Logger log) throws MojoExecutionException {
List<ImageConfiguration> ret;
ret = ConfigHelper.resolveImages(log, images, new ConfigHelper.Resolver() {
@Override
public List<ImageConfiguration> resolve(ImageConfiguration image) {
return imageConfigResolver.resolve(image, project, session);
}
}, // no filter on image name yet (TODO: Maybe add this, too ?)
null, new ConfigHelper.Customizer() {
@Override
public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
try {
GeneratorContext ctx = new GeneratorContext.Builder().config(extractGeneratorConfig()).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:resource").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(useProjectClasspath).build();
return GeneratorManager.generate(configs, ctx, true);
} catch (Exception e) {
throw new IllegalArgumentException("Cannot extract generator: " + e, e);
}
}
});
Date now = getBuildReferenceDate();
storeReferenceDateInPluginContext(now);
String minimalApiVersion = ConfigHelper.initAndValidate(ret, null, /* no minimal api version */
new ImageNameFormatter(project, now), log);
return ret;
}
use of io.fabric8.arquillian.kubernetes.log.Logger 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);
}
use of io.fabric8.arquillian.kubernetes.log.Logger in project fabric8-maven-plugin by fabric8io.
the class WatchMojo method customizeConfig.
@Override
public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
try {
Fabric8ServiceHub serviceHub = getFabric8ServiceHub();
GeneratorContext ctx = new GeneratorContext.Builder().config(extractGeneratorConfig()).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:watch").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(useProjectClasspath).artifactResolver(serviceHub.getArtifactResolverService()).build();
return GeneratorManager.generate(configs, ctx, false);
} catch (MojoExecutionException e) {
throw new IllegalArgumentException("Cannot extract generator config: " + e, e);
}
}
use of io.fabric8.arquillian.kubernetes.log.Logger in project fabric8 by fabric8io.
the class Routes method createRouteForService.
public static Route createRouteForService(String routeDomainPostfix, String namespace, Service service, Logger log) {
Route route = null;
String id = KubernetesHelper.getName(service);
if (Strings.isNotBlank(id) && shouldCreateRouteForService(log, service, id)) {
route = new Route();
String routeId = id;
KubernetesHelper.setName(route, namespace, routeId);
RouteSpec routeSpec = new RouteSpec();
RouteTargetReference objectRef = new RouteTargetReferenceBuilder().withName(id).build();
// objectRef.setNamespace(namespace);
routeSpec.setTo(objectRef);
if (Strings.isNotBlank(routeDomainPostfix)) {
// Let Openshift determine the route host when the domain is not set
String host = Strings.stripSuffix(Strings.stripSuffix(id, "-service"), ".");
String namespaceSuffix = "-" + namespace;
routeSpec.setHost(host + namespaceSuffix + "." + Strings.stripPrefix(routeDomainPostfix, "."));
}
route.setSpec(routeSpec);
String json = null;
try {
json = KubernetesHelper.toJson(route);
} catch (JsonProcessingException e) {
json = e.getMessage() + ". object: " + route;
}
}
return route;
}
use of io.fabric8.arquillian.kubernetes.log.Logger in project fabric8 by fabric8io.
the class Util method waitUntilWeCanDestroyNamespace.
protected static void waitUntilWeCanDestroyNamespace(Session session) {
final Logger log = session.getLogger();
String confirmDestroy = Systems.getEnvVarOrSystemProperty(Constants.NAMESPACE_CLEANUP_CONFIRM_ENABLED, "false");
if (Objects.equal(confirmDestroy, "true")) {
showErrorsBeforePause(session);
System.out.println();
System.out.println("Waiting to destroy the namespace.");
System.out.println("Please type: [Q] to terminate the namespace.");
while (true) {
try {
int ch = System.in.read();
if (ch < 0 || ch == 'Q') {
System.out.println("\nStopping...");
break;
} else {
System.out.println("Found character: " + Character.toString((char) ch));
}
} catch (IOException e) {
log.warn("Failed to read from input. " + e);
break;
}
}
} else {
String timeoutText = Systems.getEnvVarOrSystemProperty(Constants.NAMESPACE_CLEANUP_TIMEOUT, "0");
Long timeout = null;
if (Strings.isNotBlank(timeoutText)) {
try {
timeout = Long.parseLong(timeoutText);
} catch (NumberFormatException e) {
log.warn("Failed to parse timeout value '" + timeoutText + "' for $Constants.NAMESPACE_CLEANUP_TIMEOUT. " + e);
}
}
if (timeout != null && timeout > 0L) {
showErrorsBeforePause(session);
System.out.println();
System.out.println("Sleeping for " + timeout + " seconds until destroying the namespace");
try {
Thread.sleep(timeout * 1000);
} catch (InterruptedException e) {
log.info("Interupted sleeping to GC the namespace: " + e);
}
}
}
System.out.println("Now destroying the Fabric8 Arquillian test case namespace");
}
Aggregations