Example usage for org.apache.zookeeper WatchedEvent getPath

List of usage examples for org.apache.zookeeper WatchedEvent getPath

Introduction

In this page you can find the example usage for org.apache.zookeeper WatchedEvent getPath.

Prototype

public String getPath() 

Source Link

Usage

From source file:org.apache.accumulo.server.security.delegation.ZooAuthenticationKeyWatcherTest.java

License:Apache License

@Test
public void testChildChanged() throws Exception {
    WatchedEvent event = new WatchedEvent(EventType.NodeCreated, null, baseNode + "/2");
    AuthenticationKey key1 = new AuthenticationKey(1, 0l, 10000l, keyGen.generateKey()),
            key2 = new AuthenticationKey(2, key1.getExpirationDate(), 20000l, keyGen.generateKey());
    secretManager.addKey(key1);//from  ww w  .  ja v  a 2 s . c  om
    assertEquals(1, secretManager.getKeys().size());
    byte[] serializedKey2 = serialize(key2);

    expect(zk.getData(event.getPath(), keyWatcher, null)).andReturn(serializedKey2);
    replay(instance, zk);

    keyWatcher.process(event);

    verify(instance, zk);
    assertEquals(2, secretManager.getKeys().size());
    assertEquals(key1, secretManager.getKeys().get(key1.getKeyId()));
    assertEquals(key2, secretManager.getKeys().get(key2.getKeyId()));
    assertEquals(key2, secretManager.getCurrentKey());
}

From source file:org.apache.accumulo.server.trace.TraceServer.java

License:Apache License

@Override
public void process(WatchedEvent event) {
    log.debug("event " + event.getPath() + " " + event.getType() + " " + event.getState());
    if (event.getState() == KeeperState.Expired) {
        log.warn("Trace server lost zookeeper registration at " + event.getPath());
        server.stop();/*w ww  .j a v  a 2 s .  c  o  m*/
    } else if (event.getType() == EventType.NodeDeleted) {
        log.warn("Trace server zookeeper entry lost " + event.getPath());
        server.stop();
    }
    if (event.getPath() != null) {
        try {
            if (ZooReaderWriter.getInstance().exists(event.getPath(), this))
                return;
        } catch (Exception ex) {
            log.error(ex, ex);
        }
        log.warn("Trace server unable to reset watch on zookeeper registration");
        server.stop();
    }
}

From source file:org.apache.accumulo.server.watcher.MonitorLog4jWatcher.java

License:Apache License

@Override
public void process(WatchedEvent event) {
    // We got an update, process the data in the node
    updateMonitorLog4jLocation();//from w  ww . j  a v a 2  s .com

    if (event.getPath() != null) {
        try {
            ZooReaderWriter.getInstance().exists(event.getPath(), this);
        } catch (Exception ex) {
            log.error("Unable to reset watch for Monitor Log4j watcher", ex);
        }
    }
}

From source file:org.apache.accumulo.server.zookeeper.DistributedWorkQueue.java

License:Apache License

public void startProcessing(final Processor processor, ThreadPoolExecutor executorService)
        throws KeeperException, InterruptedException {

    threadPool = executorService;/*w  w  w  . ja v  a  2 s . c  om*/

    zoo.mkdirs(path);
    zoo.mkdirs(path + "/" + LOCKS_NODE);

    List<String> children = zoo.getChildren(path, new Watcher() {
        @Override
        public void process(WatchedEvent event) {
            switch (event.getType()) {
            case NodeChildrenChanged:
                if (event.getPath().equals(path))
                    try {
                        lookForWork(processor, zoo.getChildren(path, this));
                    } catch (KeeperException e) {
                        log.error("Failed to look for work", e);
                    } catch (InterruptedException e) {
                        log.info("Interrupted looking for work", e);
                    }
                else
                    log.info("Unexpected path for NodeChildrenChanged event " + event.getPath());
                break;
            case NodeCreated:
            case NodeDataChanged:
            case NodeDeleted:
            case None:
                log.info("Got unexpected zookeeper event: " + event.getType() + " for " + path);
                break;

            }
        }
    });

    lookForWork(processor, children);

    // Add a little jitter to avoid all the tservers slamming zookeeper at once
    SimpleTimer.getInstance(config).schedule(new Runnable() {
        @Override
        public void run() {
            log.debug("Looking for work in " + path);
            try {
                lookForWork(processor, zoo.getChildren(path));
            } catch (KeeperException e) {
                log.error("Failed to look for work", e);
            } catch (InterruptedException e) {
                log.info("Interrupted looking for work", e);
            }
        }
    }, timerInitialDelay, timerPeriod);
}

From source file:org.apache.accumulo.tracer.TraceServer.java

License:Apache License

@Override
public void process(WatchedEvent event) {
    log.debug("event " + event.getPath() + " " + event.getType() + " " + event.getState());
    if (event.getState() == KeeperState.Expired) {
        log.warn("Trace server lost zookeeper registration at " + event.getPath());
        server.stop();//from w  w  w  .  j  a v  a2s  .  co  m
    } else if (event.getType() == EventType.NodeDeleted) {
        log.warn("Trace server zookeeper entry lost " + event.getPath());
        server.stop();
    }
    if (event.getPath() != null) {
        try {
            if (ZooReaderWriter.getInstance().exists(event.getPath(), this))
                return;
        } catch (Exception ex) {
            log.error("{}", ex.getMessage(), ex);
        }
        log.warn("Trace server unable to reset watch on zookeeper registration");
        server.stop();
    }
}

From source file:org.apache.airavata.gfac.core.cpi.BetterGfacImpl.java

License:Apache License

public void process(WatchedEvent watchedEvent) {
    if (Event.EventType.NodeDataChanged.equals(watchedEvent.getType())) {
        // node data is changed, this means node is cancelled.
        log.info("Experiment is cancelled with this path:" + watchedEvent.getPath());
        this.cancelled = true;
    }/* www .  java  2 s .c  om*/
}

From source file:org.apache.airavata.gfac.impl.GfacInternalStatusUpdator.java

License:Apache License

public void process(WatchedEvent watchedEvent) {
    logger.info(watchedEvent.getPath());
    synchronized (mutex) {
        Event.KeeperState state = watchedEvent.getState();
        if (state == Event.KeeperState.SyncConnected) {
            mutex.notify();//from  w  ww. jav  a2 s.  c om
        }
    }
}

From source file:org.apache.airavata.gfac.impl.watcher.CancelRequestWatcherImpl.java

License:Apache License

@Override
public void process(WatchedEvent watchedEvent) throws Exception {
    // this watcher change data in cancel listener node in the experiment node
    String path = watchedEvent.getPath();
    Watcher.Event.EventType type = watchedEvent.getType();
    CuratorFramework curatorClient = Factory.getCuratorClient();
    log.info("cancel watcher triggered process id {}.", processId);
    switch (type) {
    case NodeDataChanged:
        byte[] bytes = curatorClient.getData().forPath(path);
        String action = new String(bytes);
        if (action.equalsIgnoreCase(ZkConstants.ZOOKEEPER_CANCEL_REQEUST)) {
            cancelProcess(0);/*from   w  w w . j a v  a  2s .co  m*/
        } else {
            curatorClient.getData().usingWatcher(this).forPath(path);
        }
        break;
    case NodeDeleted:
        //end of experiment execution, ignore this event
        log.info("expId: {}, cancel watcher trigger for process {} with event type {}", experimentId, processId,
                type.name());
        break;
    case NodeCreated:
    case NodeChildrenChanged:
    case None:
        log.info("expId: {}, Cancel watcher trigger for process {} with event type {}", experimentId, processId,
                type.name());
        if (path != null) {
            curatorClient.getData().usingWatcher(this).forPath(path);
        }
        break;
    default:
        log.info("expId: {}, Cancel watcher trigger for process {} with event type {}", experimentId, processId,
                type.name());
        if (path != null) {
            curatorClient.getData().usingWatcher(this).forPath(path);
        }
        break;
    }
}

From source file:org.apache.airavata.gfac.impl.watcher.RedeliveryRequestWatcherImpl.java

License:Apache License

@Override
public void process(WatchedEvent watchedEvent) throws Exception {
    String path = watchedEvent.getPath();
    Watcher.Event.EventType eventType = watchedEvent.getType();
    log.info("Redelivery request came for zk path {} event type {} ", path, eventType.name());
    CuratorFramework curatorClient = Factory.getCuratorClient();
    switch (eventType) {
    case NodeDataChanged:
        byte[] bytes = curatorClient.getData().forPath(path);
        String serverName = new String(bytes);
        if (ServerSettings.getGFacServerName().trim().equals(serverName)) {
            curatorClient.getData().usingWatcher(this).forPath(path);
            log.info("processId: {},event type {}, change data with same server name : {}", processId,
                    eventType, serverName);
        } else {/*from   w  w  w  . java 2  s  .co m*/
            ProcessContext processContext = Factory.getGfacContext().getProcess(processId);
            if (processContext != null) {
                processContext.setHandOver(true);
                log.info("processId : {}, event type {}, handing over to new server instance : {}", processId,
                        eventType, serverName);
            } else {
                log.info("Redelivery request came for processId {}, with event type {}, but couldn't find "
                        + "process context", processId, eventType.name());
            }
        }
        break;
    case NodeDeleted:
        //end of experiment execution, ignore this event
        log.info("Redelivery watcher trigger for process {} with event type {}", processId, eventType.name());
        break;
    case NodeCreated:
    case NodeChildrenChanged:
    case None:
        if (path != null) {
            curatorClient.getData().usingWatcher(this).forPath(path);
            log.info("Redelivery watcher trigger for process {} with event type {}", processId,
                    eventType.name());
        }
        break;
    // not yet implemented
    default:
        if (path != null) {
            curatorClient.getData().usingWatcher(this).forPath(path);
            log.info("Redelivery watcher trigger for process {} with event type {}", processId,
                    eventType.name());
        }
        break;
    }
}

From source file:org.apache.airavata.gfac.monitor.handlers.GridPullMonitorHandler.java

License:Apache License

public void process(WatchedEvent watchedEvent) {
    if (Event.EventType.NodeDataChanged.equals(watchedEvent.getType())) {
        // node data is changed, this means node is cancelled.
        logger.info("Experiment is cancelled with this path:" + watchedEvent.getPath());

        String[] split = watchedEvent.getPath().split("/");
        for (String element : split) {
            if (element.contains("+")) {
                logger.info("Adding experimentID+TaskID to be removed from monitoring:" + element);
                hpcPullMonitor.getCancelJobList().add(element);
            }//w  ww . jav a  2  s. c o  m
        }
    }
}