Package net.sf.katta.protocol

Examples of net.sf.katta.protocol.InteractionProtocol


  }

  @Test
  public void testContentServer() throws Exception {
    deployTestIndices(1, getNodeCount());
    final InteractionProtocol protocol = _miniCluster.getProtocol();
    assertEquals(1, protocol.getIndices().size());

    LuceneClient luceneClient = new LuceneClient(_miniCluster.getZkConfiguration());
    final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("content: the");
    luceneClient.count(query, new String[] { INDEX_NAME });
    luceneClient.close();
View Full Code Here


    _indexName = indexName;
  }

  @Override
  public List<OperationId> execute(MasterContext context, List<MasterOperation> runningOperations) throws Exception {
    InteractionProtocol protocol = context.getProtocol();
    IndexMetaData indexMD = protocol.getIndexMD(_indexName);
    if (indexMD == null) {// could be undeployed in meantime
      LOG.info("skip balancing for index '" + _indexName + "' cause it is already undeployed");
      return null;
    }
    if (!canAndShouldRegulateReplication(protocol, indexMD)) {
      LOG.info("skip balancing for index '" + _indexName + "' cause there is no possible optimization");
      return null;
    }
    try {
      FileSystem fileSystem = context.getFileSystem(indexMD);
      Path path = new Path(indexMD.getPath());
      if (!fileSystem.exists(path)) {
        LOG.warn("skip balancing for index '" + _indexName + "' cause source '" + path + "' does not exists anymore");
        return null;
      }
    } catch (Exception e) {
      LOG.error("skip balancing of index '" + _indexName + "' cause failed to access source '" + indexMD.getPath()
              + "'", e);
      return null;
    }

    LOG.info("balancing shards for index '" + _indexName + "'");
    try {
      List<OperationId> operationIds = distributeIndexShards(context, indexMD, protocol.getLiveNodes(),
              runningOperations);
      return operationIds;
    } catch (Exception e) {
      ExceptionUtil.rethrowInterruptedException(e);
      LOG.error("failed to deploy balance " + _indexName, e);
View Full Code Here

  @Test
  public void testEqualDistributionWhenMoreNodesThenShards() throws Exception {
    int replicationCount = 1;
    _miniCluster.deployTestIndexes(_indexWithOneShard, getNodeCount(), replicationCount);

    final InteractionProtocol protocol = _miniCluster.getProtocol();
    assertEquals(getNodeCount(), protocol.getIndices().size());

    protocol.showStructure(false);
    List<Node> nodes = _miniCluster.getNodes();
    for (Node node : nodes) {
      assertEquals(1, node.getContext().getContentServer().getShards().size());
    }
View Full Code Here

  }

  @Override
  public List<OperationId> execute(MasterContext context, List<MasterOperation> runningOperations) throws Exception,
          InterruptedException {
    InteractionProtocol protocol = context.getProtocol();
    try {
      _indexMD.getShards().addAll(readShardsFromFs(_indexName, _indexPath));
      LOG.info("Found shards '" + _indexMD.getShards() + "' for index '" + _indexName + "'");
      List<OperationId> operationIds = distributeIndexShards(context, _indexMD, protocol.getLiveNodes(),
              runningOperations);
      return operationIds;
    } catch (Exception e) {
      ExceptionUtil.rethrowInterruptedException(e);
      LOG.error("failed to deploy index " + _indexName, e);
      protocol.publishIndex(_indexMD);
      handleMasterDeployException(protocol, _indexMD, e);
      return null;
    }
  }
View Full Code Here

  private static final long serialVersionUID = 1L;

  @Override
  public List<OperationId> execute(MasterContext context, List<MasterOperation> runningOperations) throws Exception {
    InteractionProtocol protocol = context.getProtocol();
    List<String> liveNodes = protocol.getLiveNodes();
    List<String> indices = protocol.getIndices();

    for (String indexName : indices) {
      IndexMetaData indexMD = protocol.getIndexMD(indexName);
      if (indexMD != null) { // can be removed already
        if ((indexMD.hasDeployError() && isRecoverable(indexMD.getDeployError(), liveNodes.size()))
                || canAndShouldRegulateReplication(protocol, indexMD)) {
          protocol.addMasterOperation(new BalanceIndexOperation(indexName));
        }
      }
    }
    return null;
  }
View Full Code Here

  public void testZkMasterReconnectDuringDeployment() throws Exception {
    deployTestIndices(1, getNodeCount());
    _miniCluster.getMaster().shutdown();

    ZkClient zkClient = new ZkClient(_miniCluster.getZkConfiguration().getZKServers());
    InteractionProtocol protocol = new InteractionProtocol(zkClient, _miniCluster.getZkConfiguration());
    Master master = new Master(protocol, false);
    master.start();
    TestUtil.waitUntilBecomeMaster(master);

    final IDeployClient deployClient = new DeployClient(_protocol);
    WatchedEvent event = new WatchedEvent(new WatcherEvent(EventType.None.getIntValue(), KeeperState.Expired
            .getIntValue(), null));
    for (int i = 0; i < 25; i++) {
      final String indexName = "index" + i;
      IIndexDeployFuture deployFuture = deployClient.addIndex(indexName, INDEX_FILE.getAbsolutePath(), 1);
      zkClient.getEventLock().lock();
      zkClient.process(event);
      zkClient.getEventLock().unlock();
      IndexState indexState = deployFuture.joinDeployment();
      assertEquals("" + deployClient.getIndexMetaData(indexName).getDeployError(), IndexState.DEPLOYED, indexState);

      if (indexState == IndexState.ERROR) {
        IndexDeployError deployError = protocol.getIndexMD(indexName).getDeployError();
        Set<Shard> shards = protocol.getIndexMD(indexName).getShards();
        for (Shard shard : shards) {
          List<Exception> shardErrors = deployError.getShardErrors(shard.getName());
          for (Exception exception : shardErrors) {
            exception.printStackTrace();
          }
View Full Code Here

    return _nodeName;
  }

  @Override
  public List<OperationId> execute(MasterContext context, List<MasterOperation> runningOperations) throws Exception {
    InteractionProtocol protocol = context.getProtocol();
    Collection<String> nodeShards = protocol.getNodeShards(_nodeName);
    List<String> obsoletShards = collectObsoleteShards(protocol, nodeShards, runningOperations);
    if (!obsoletShards.isEmpty()) {
      Log.info("found following shards obsolete on node " + _nodeName + ": " + obsoletShards);
      protocol.addNodeOperation(_nodeName, new ShardUndeployOperation(obsoletShards));
    }

    return null;
  }
View Full Code Here

    checkDeploymentForCompletion();
    if (isDone()) {
      return;
    }

    InteractionProtocol protocol = _context.getProtocol();
    protocol.registerChildListener(this, PathDef.NODES_LIVE, new IAddRemoveListener() {
      @Override
      public void removed(String name) {
        checkDeploymentForCompletion();
      }

      @Override
      public void added(String name) {
        // nothing todo
      }
    });
    IZkDataListener dataListener = new IZkDataListener() {
      @Override
      public void handleDataDeleted(String arg0) throws Exception {
        checkDeploymentForCompletion();
      }

      @Override
      public void handleDataChange(String arg0, Object arg1) throws Exception {
        // nothing todo
      }
    };
    for (OperationId operationId : _openOperationIds) {
      protocol.registerNodeOperationListener(this, operationId, dataListener);
    }
    checkDeploymentForCompletion();
  }
View Full Code Here

    _context.getProtocol().unregisterComponent(this);
    this.notifyAll();
  }

  private synchronized void finishWatchdog() {
    InteractionProtocol protocol = _context.getProtocol();
    protocol.unregisterComponent(this);
    try {
      List<OperationResult> operationResults = new ArrayList<OperationResult>(_openOperationIds.size());
      for (OperationId operationId : _operationIds) {
        OperationResult operationResult = protocol.getNodeOperationResult(operationId, true);
        if (operationResult != null && operationResult.getUnhandledException() != null) {
          // TODO jz: do we need to inform the master operation ?
          LOG.error("received unhandlde exception from node " + operationId.getNodeName(), operationResult
                  .getUnhandledException());
        }
View Full Code Here

  /**
   *@deprecated use {@link #DeployClient(InteractionProtocol)} instead
   */
  public DeployClient(ZkClient zkClient, ZkConfiguration configuration) {
    this(new InteractionProtocol(zkClient, configuration));
  }
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.