Package net.sf.katta.protocol

Examples of net.sf.katta.protocol.InteractionProtocol


          Collection<String> liveNodes, List<MasterOperation> runningOperations) throws IndexDeployException {
    if (liveNodes.isEmpty()) {
      throw new IndexDeployException(ErrorType.NO_NODES_AVAILIBLE, "no nodes availible");
    }

    InteractionProtocol protocol = context.getProtocol();
    Set<Shard> shards = indexMD.getShards();

    // now distribute shards
    final Map<String, List<String>> currentIndexShard2NodesMap = protocol
            .getShard2NodesMap(Shard.getShardNames(shards));
    Map<String, List<String>> currentGlobalNode2ShardsMap = getCurrentNode2ShardMap(liveNodes, protocol
            .getShard2NodesMap(protocol.getShard2NodeShards()));
    addRunningDeployments(currentGlobalNode2ShardsMap, runningOperations);

    final Map<String, List<String>> newNode2ShardMap = context.getDeployPolicy().createDistributionPlan(
            currentIndexShard2NodesMap, cloneMap(currentGlobalNode2ShardsMap), new ArrayList<String>(liveNodes),
            indexMD.getReplicationLevel());

    // System.out.println(distributionMap);// node to shards
    Set<String> nodes = newNode2ShardMap.keySet();
    List<OperationId> operationIds = new ArrayList<OperationId>(nodes.size());
    One2ManyListMap<String, String> newShardsByNode = new One2ManyListMap<String, String>();
    for (String node : nodes) {
      List<String> nodeShards = newNode2ShardMap.get(node);
      List<String> listOfAdded = CollectionUtil.getListOfAdded(currentGlobalNode2ShardsMap.get(node), nodeShards);
      if (!listOfAdded.isEmpty()) {
        ShardDeployOperation deployInstruction = new ShardDeployOperation();
        for (String shard : listOfAdded) {
          deployInstruction.addShard(shard, indexMD.getShardPath(shard));
          newShardsByNode.add(node, shard);
        }
        OperationId operationId = protocol.addNodeOperation(node, deployInstruction);
        operationIds.add(operationId);
      }
      List<String> listOfRemoved = CollectionUtil.getListOfRemoved(currentGlobalNode2ShardsMap.get(node), nodeShards);
      if (!listOfRemoved.isEmpty()) {
        ShardUndeployOperation undeployInstruction = new ShardUndeployOperation(listOfRemoved);
        OperationId operationId = protocol.addNodeOperation(node, undeployInstruction);
        operationIds.add(operationId);
      }
    }
    _newShardsByNodeMap = newShardsByNode.asMap();
    return operationIds;
View Full Code Here


  }

  @SuppressWarnings("unchecked")
  private Map<String, Set<Watcher>> getExistsWatches(Client client) {
    InteractionProtocol protocol = (InteractionProtocol) ClassUtil.getPrivateFieldValue(client, "_protocol");
    ZkClient zkClient = protocol.getZkClient();
    ZkConnection zkConnection = (ZkConnection) ClassUtil.getPrivateFieldValue(zkClient, "_connection");
    ZooKeeper zookeeper = zkConnection.getZookeeper();
    Object watchManager = ClassUtil.getPrivateFieldValue(zookeeper, "watchManager");
    Map<String, Set<Watcher>> existWatches = (Map<String, Set<Watcher>>) ClassUtil.getPrivateFieldValue(watchManager,
            "existWatches");
View Full Code Here

public class MetricLoggerTest extends AbstractZkTest {

  @Test
  public void testLogMetric() throws Exception {
    InteractionProtocol protocol = _zk.createInteractionProtocol();
    MetricLogger metricLogger = new MetricLogger(OutputType.Log4J, protocol);
    protocol.setMetric("node1", new MetricsRecord("node1"));
    Thread.sleep(500);
    protocol.setMetric("node1", new MetricsRecord("node1"));
    Thread.sleep(500);
    assertEquals(2, metricLogger.getLoggedRecords());
    protocol.unregisterComponent(metricLogger);
    protocol.disconnect();
  }
View Full Code Here

    gatewayConf.setZKRootPath(_zk.getZkConf().getZkRootPath());
    gatewayConf.setZKServers("localhost:" + GATEWAY_PORT);
    Gateway gateway = new Gateway(GATEWAY_PORT, _zk.getServerPort());
    gateway.start();
    final ZkClient zkGatewayClient = ZkKattaUtil.startZkClient(gatewayConf, 30000);
    InteractionProtocol gatewayProtocol = new InteractionProtocol(zkGatewayClient, gatewayConf);
    FileUtil.deleteFolder(new NodeConfiguration().getShardFolder());
    final Node node = new Node(gatewayProtocol, new LuceneServer());
    node.start();

    // check node-master link
View Full Code Here

  @Test
  public void testGetCpu() throws Exception {
    JmxMonitor monitor = new JmxMonitor();
    String nodeId = "someId";
    InteractionProtocol protocol = mock(InteractionProtocol.class);
    monitor.startMonitoring(nodeId, protocol);
    Thread.sleep(1200);
    verify(protocol, atLeastOnce()).setMetric(eq(nodeId), (MetricsRecord) anyObject());
  }
View Full Code Here

  public void start() throws Exception {
    if (_zkServer == null) {
      _zkServer = ZkKattaUtil.startZkServer(_zkConfiguration);
    }
    _protocol = new InteractionProtocol(_zkServer.getZkClient(), _zkConfiguration);
    NodeConfiguration nodeConfiguration = new NodeConfiguration();
    nodeConfiguration.setStartPort(_nodeStartPort);
    for (int i = 0; i < _nodeCount; i++) {
      _nodes.add(new Node(_protocol, nodeConfiguration, _contentServerClass.newInstance()));
    }
View Full Code Here

    this(serverClass, policy, zkConfig, new ClientConfiguration());
  }

  public Client(Class<? extends VersionedProtocol> serverClass, final INodeSelectionPolicy policy,
          final ZkConfiguration zkConfig, ClientConfiguration clientConfiguration) {
    this(serverClass, policy, new InteractionProtocol(ZkKattaUtil.startZkClient(zkConfig, 60000), zkConfig),
            clientConfiguration);
  }
View Full Code Here

public class ClientTest extends AbstractTest {

  @Test
  public void testAddRemoveIndexForSearching() throws Exception {
    InteractionProtocol protocol = mock(InteractionProtocol.class);
    Client client = new Client(ISleepServer.class, new DefaultNodeSelectionPolicy(), protocol,
            new ClientConfiguration());
    IndexMetaData indexMD = new IndexMetaData("index1", "path", 1);
    indexMD.getShards().add(new Shard("shard1", "path"));
    indexMD.getShards().add(new Shard("shard2", "path"));
View Full Code Here

    verify(protocol, times(2)).unregisterChildListener(eq(client), eq(PathDef.SHARD_TO_NODES), anyString());
  }

  @Test
  public void testAddRemoveIndexForWatching() throws Exception {
    InteractionProtocol protocol = mock(InteractionProtocol.class);
    Client client = new Client(ISleepServer.class, new DefaultNodeSelectionPolicy(), protocol,
            new ClientConfiguration());
    IndexMetaData indexMD = new IndexMetaData("index1", "path", 1);
    indexMD.getShards().add(new Shard("shard1", "path"));
    indexMD.getShards().add(new Shard("shard2", "path"));
View Full Code Here

    verify(protocol, times(1)).unregisterDataChanges(eq(client), eq(PathDef.INDICES_METADATA), anyString());
  }

  @Test
  public void testClose() throws Exception {
    InteractionProtocol protocol = mock(InteractionProtocol.class);
    Client client = new Client(ISleepServer.class, new DefaultNodeSelectionPolicy(), protocol,
            new ClientConfiguration());
    client.close();

    verify(protocol).unregisterComponent(client);
View Full Code Here

TOP

Related Classes of net.sf.katta.protocol.InteractionProtocol

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.