Search in sources :

Example 1 with Namespaceable

use of io.fabric8.kubernetes.client.dsl.Namespaceable 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));
}
Also used : Watchable(io.fabric8.kubernetes.client.dsl.Watchable) Handler(com.github.isdream.cwatcher.Handler) Namespaceable(io.fabric8.kubernetes.client.dsl.Namespaceable) AnyNamespaceable(io.fabric8.kubernetes.client.dsl.AnyNamespaceable) AnyNamespaceable(io.fabric8.kubernetes.client.dsl.AnyNamespaceable) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

Handler (com.github.isdream.cwatcher.Handler)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 AnyNamespaceable (io.fabric8.kubernetes.client.dsl.AnyNamespaceable)1 Namespaceable (io.fabric8.kubernetes.client.dsl.Namespaceable)1 Watchable (io.fabric8.kubernetes.client.dsl.Watchable)1