aboutsummaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantDebugger.java
blob: 12f817fc92dab34aaac8f5b820a024bd620653a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.tenant;

import com.yahoo.vespa.curator.Curator;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.TreeCache;
import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
import org.apache.curator.framework.recipes.cache.TreeCacheListener;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * For debugging tenant issues in configserver. Activate by loading component.
 *
 * @author Ulf Lilleengen
 */
public class TenantDebugger implements TreeCacheListener {

    private static final Logger log = Logger.getLogger(TenantDebugger.class.getName());

    @SuppressWarnings("deprecation") // TreeCache is deprecated, and recommended replacement is CuratorCache
    public TenantDebugger(Curator curator) throws Exception {
        TreeCache cache = new TreeCache(curator.framework(), "/config/v2/tenants");
        cache.getListenable().addListener(this);
        cache.start();
    }

    @Override
    public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception {
        switch (event.getType()) {
            case NODE_ADDED:
            case NODE_REMOVED:
            case NODE_UPDATED:
                log.log(Level.INFO, event.toString());
                break;
        }
    }

}