private ClusterHealthResponse clusterHealth(
      ClusterHealthRequest request, ClusterState clusterState) {
    if (logger.isTraceEnabled()) {
      logger.trace("Calculating health based on state version [{}]", clusterState.version());
    }
    String[] concreteIndices;
    try {
      concreteIndices =
          clusterState.metaData().concreteIndices(request.indicesOptions(), request.indices());
    } catch (IndexMissingException e) {
      // one of the specified indices is not there - treat it as RED.
      ClusterHealthResponse response =
          new ClusterHealthResponse(clusterName.value(), Strings.EMPTY_ARRAY, clusterState);
      response.status = ClusterHealthStatus.RED;
      return response;
    }

    return new ClusterHealthResponse(clusterName.value(), concreteIndices, clusterState);
  }
예제 #2
0
 protected void initialize(
     BlobStore blobStore, ClusterName clusterName, @Nullable ByteSizeValue defaultChunkSize)
     throws IOException {
   this.blobStore = blobStore;
   this.chunkSize = componentSettings.getAsBytesSize("chunk_size", defaultChunkSize);
   this.basePath = BlobPath.cleanPath().add(clusterName.value());
   this.metaDataBlobContainer = blobStore.immutableBlobContainer(basePath.add("metadata"));
   this.currentIndex = findLatestIndex();
   this.compress = componentSettings.getAsBoolean("compress", true);
   logger.debug("Latest metadata found at index [" + currentIndex + "]");
 }
  private void sendHeader(ChannelHandlerContext ctx) throws IOException {
    headerSent = true;
    logger.info(
        "Authenticating with Found Elasticsearch at [{}] on connection [{}]",
        ctx.getChannel().getRemoteAddress(),
        ctx.getChannel().getLocalAddress());
    ChannelBuffer message = new FoundTransportHeader(clusterName.value(), apiKey).getHeaderBuffer();

    ctx.sendDownstream(
        new DownstreamMessageEvent(
            ctx.getChannel(),
            Channels.succeededFuture(ctx.getChannel()),
            message,
            ctx.getChannel().getRemoteAddress()));
  }
예제 #4
0
  @Inject
  public HdfsGateway(
      Settings settings,
      ThreadPool threadPool,
      ClusterService clusterService,
      ClusterName clusterName)
      throws IOException {
    super(settings, threadPool, clusterService);

    this.closeFileSystem = componentSettings.getAsBoolean("close_fs", true);
    String uri = componentSettings.get("uri");
    if (uri == null) {
      throw new ElasticSearchIllegalArgumentException(
          "hdfs gateway requires the 'uri' setting to be set");
    }
    String path = componentSettings.get("path");
    if (path == null) {
      throw new ElasticSearchIllegalArgumentException(
          "hdfs gateway requires the 'path' path setting to be set");
    }
    Path hPath = new Path(new Path(path), clusterName.value());

    int concurrentStreams = componentSettings.getAsInt("concurrent_streams", 5);
    this.concurrentStreamPool =
        EsExecutors.newScalingExecutorService(
            1,
            concurrentStreams,
            5,
            TimeUnit.SECONDS,
            EsExecutors.daemonThreadFactory(settings, "[s3_stream]"));

    logger.debug(
        "Using uri [{}], path [{}], concurrent_streams [{}]", uri, hPath, concurrentStreams);

    Configuration conf = new Configuration();
    Settings hdfsSettings = settings.getByPrefix("hdfs.conf.");
    for (Map.Entry<String, String> entry : hdfsSettings.getAsMap().entrySet()) {
      conf.set(entry.getKey(), entry.getValue());
    }

    fileSystem = FileSystem.get(URI.create(uri), conf);

    initialize(
        new HdfsBlobStore(settings, fileSystem, concurrentStreamPool, hPath), clusterName, null);
  }
 @Inject
 public MockInternalClusterInfoService(
     Settings settings,
     ClusterSettings clusterSettings,
     TransportNodesStatsAction transportNodesStatsAction,
     TransportIndicesStatsAction transportIndicesStatsAction,
     ClusterService clusterService,
     ThreadPool threadPool) {
   super(
       settings,
       clusterSettings,
       transportNodesStatsAction,
       transportIndicesStatsAction,
       clusterService,
       threadPool);
   this.clusterName = ClusterName.clusterNameFromSettings(settings);
   stats[0] = makeStats("node_t1", new DiskUsage("node_t1", "n1", "/dev/null", 100, 100));
   stats[1] = makeStats("node_t2", new DiskUsage("node_t2", "n2", "/dev/null", 100, 100));
   stats[2] = makeStats("node_t3", new DiskUsage("node_t3", "n3", "/dev/null", 100, 100));
 }
 @Override
 public void writeTo(StreamOutput out) throws IOException {
   super.writeTo(out);
   clusterName.writeTo(out);
 }
 @Override
 public void readFrom(StreamInput in) throws IOException {
   super.readFrom(in);
   clusterName = ClusterName.readClusterName(in);
 }
예제 #8
0
 @Override
 public void writeTo(StreamOutput out) throws IOException {
   super.writeTo(out);
   clusterName.writeTo(out);
   out.writeOptionalWriteable(node);
 }
예제 #9
0
 @Override
 public String nodeDescription() {
   return clusterName.value() + "/" + localNode.id();
 }
  private ClusterHealthResponse clusterHealth(ClusterHealthRequest request) {
    ClusterState clusterState = clusterService.state();
    RoutingTableValidation validation =
        clusterState.routingTable().validate(clusterState.metaData());
    ClusterHealthResponse response =
        new ClusterHealthResponse(clusterName.value(), validation.failures());
    response.numberOfNodes = clusterState.nodes().size();
    response.numberOfDataNodes = clusterState.nodes().dataNodes().size();

    for (String index : clusterState.metaData().concreteIndices(request.indices())) {
      IndexRoutingTable indexRoutingTable = clusterState.routingTable().index(index);
      IndexMetaData indexMetaData = clusterState.metaData().index(index);
      if (indexRoutingTable == null) {
        continue;
      }
      ClusterIndexHealth indexHealth =
          new ClusterIndexHealth(
              index,
              indexMetaData.numberOfShards(),
              indexMetaData.numberOfReplicas(),
              validation.indexFailures(indexMetaData.index()));

      for (IndexShardRoutingTable shardRoutingTable : indexRoutingTable) {
        ClusterShardHealth shardHealth = new ClusterShardHealth(shardRoutingTable.shardId().id());
        for (ShardRouting shardRouting : shardRoutingTable) {
          if (shardRouting.active()) {
            shardHealth.activeShards++;
            if (shardRouting.relocating()) {
              // the shard is relocating, the one he is relocating to will be in initializing state,
              // so we don't count it
              shardHealth.relocatingShards++;
            }
            if (shardRouting.primary()) {
              shardHealth.primaryActive = true;
            }
          } else if (shardRouting.initializing()) {
            shardHealth.initializingShards++;
          } else if (shardRouting.unassigned()) {
            shardHealth.unassignedShards++;
          }
        }
        if (shardHealth.primaryActive) {
          if (shardHealth.activeShards == shardRoutingTable.size()) {
            shardHealth.status = ClusterHealthStatus.GREEN;
          } else {
            shardHealth.status = ClusterHealthStatus.YELLOW;
          }
        } else {
          shardHealth.status = ClusterHealthStatus.RED;
        }
        indexHealth.shards.put(shardHealth.id(), shardHealth);
      }

      for (ClusterShardHealth shardHealth : indexHealth) {
        if (shardHealth.primaryActive()) {
          indexHealth.activePrimaryShards++;
        }
        indexHealth.activeShards += shardHealth.activeShards;
        indexHealth.relocatingShards += shardHealth.relocatingShards;
        indexHealth.initializingShards += shardHealth.initializingShards;
        indexHealth.unassignedShards += shardHealth.unassignedShards;
      }
      // update the index status
      indexHealth.status = ClusterHealthStatus.GREEN;
      if (!indexHealth.validationFailures().isEmpty()) {
        indexHealth.status = ClusterHealthStatus.RED;
      } else if (indexHealth
          .shards()
          .isEmpty()) { // might be since none has been created yet (two phase index creation)
        indexHealth.status = ClusterHealthStatus.RED;
      } else {
        for (ClusterShardHealth shardHealth : indexHealth) {
          if (shardHealth.status() == ClusterHealthStatus.RED) {
            indexHealth.status = ClusterHealthStatus.RED;
            break;
          }
          if (shardHealth.status() == ClusterHealthStatus.YELLOW) {
            indexHealth.status = ClusterHealthStatus.YELLOW;
          }
        }
      }

      response.indices.put(indexHealth.index(), indexHealth);
    }

    for (ClusterIndexHealth indexHealth : response) {
      response.activePrimaryShards += indexHealth.activePrimaryShards;
      response.activeShards += indexHealth.activeShards;
      response.relocatingShards += indexHealth.relocatingShards;
      response.initializingShards += indexHealth.initializingShards;
      response.unassignedShards += indexHealth.unassignedShards;
    }

    response.status = ClusterHealthStatus.GREEN;
    if (!response.validationFailures().isEmpty()) {
      response.status = ClusterHealthStatus.RED;
    } else if (clusterState
        .blocks()
        .hasGlobalBlock(GatewayService.NOT_RECOVERED_FROM_GATEWAY_BLOCK)) {
      response.status = ClusterHealthStatus.RED;
    } else {
      for (ClusterIndexHealth indexHealth : response) {
        if (indexHealth.status() == ClusterHealthStatus.RED) {
          response.status = ClusterHealthStatus.RED;
          break;
        }
        if (indexHealth.status() == ClusterHealthStatus.YELLOW) {
          response.status = ClusterHealthStatus.YELLOW;
        }
      }
    }

    return response;
  }
예제 #11
0
 public static ClusterName readClusterName(StreamInput in) throws IOException {
   ClusterName clusterName = new ClusterName();
   clusterName.readFrom(in);
   return clusterName;
 }