コード例 #1
0
 @Override
 protected ClusterBlockException checkBlock(DeleteWarmerRequest request, ClusterState state) {
   return state
       .blocks()
       .indicesBlockedException(
           ClusterBlockLevel.METADATA,
           clusterService
               .state()
               .metaData()
               .concreteIndices(request.indicesOptions(), request.indices()));
 }
コード例 #2
0
  @Override
  protected void masterOperation(
      final DeleteWarmerRequest request,
      final ClusterState state,
      final ActionListener<DeleteWarmerResponse> listener)
      throws ElasticsearchException {
    final String[] concreteIndices =
        clusterService
            .state()
            .metaData()
            .concreteIndices(request.indicesOptions(), request.indices());
    clusterService.submitStateUpdateTask(
        "delete_warmer [" + Arrays.toString(request.names()) + "]",
        new AckedClusterStateUpdateTask<DeleteWarmerResponse>(request, listener) {

          @Override
          protected DeleteWarmerResponse newResponse(boolean acknowledged) {
            return new DeleteWarmerResponse(acknowledged);
          }

          @Override
          public void onFailure(String source, Throwable t) {
            logger.debug(
                "failed to delete warmer [{}] on indices [{}]",
                t,
                Arrays.toString(request.names()),
                concreteIndices);
            super.onFailure(source, t);
          }

          @Override
          public ClusterState execute(ClusterState currentState) {
            MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());

            boolean globalFoundAtLeastOne = false;
            for (String index : concreteIndices) {
              IndexMetaData indexMetaData = currentState.metaData().index(index);
              if (indexMetaData == null) {
                throw new IndexMissingException(new Index(index));
              }
              IndexWarmersMetaData warmers = indexMetaData.custom(IndexWarmersMetaData.TYPE);
              if (warmers != null) {
                List<IndexWarmersMetaData.Entry> entries = Lists.newArrayList();
                for (IndexWarmersMetaData.Entry entry : warmers.entries()) {
                  boolean keepWarmer = true;
                  for (String warmer : request.names()) {
                    if (Regex.simpleMatch(warmer, entry.name()) || warmer.equals("_all")) {
                      globalFoundAtLeastOne = true;
                      keepWarmer = false;
                      // don't add it...
                      break;
                    }
                  }
                  if (keepWarmer) {
                    entries.add(entry);
                  }
                }
                // a change, update it...
                if (entries.size() != warmers.entries().size()) {
                  warmers =
                      new IndexWarmersMetaData(
                          entries.toArray(new IndexWarmersMetaData.Entry[entries.size()]));
                  IndexMetaData.Builder indexBuilder =
                      IndexMetaData.builder(indexMetaData)
                          .putCustom(IndexWarmersMetaData.TYPE, warmers);
                  mdBuilder.put(indexBuilder);
                }
              }
            }

            if (!globalFoundAtLeastOne) {
              throw new IndexWarmerMissingException(request.names());
            }

            if (logger.isInfoEnabled()) {
              for (String index : concreteIndices) {
                IndexMetaData indexMetaData = currentState.metaData().index(index);
                if (indexMetaData == null) {
                  throw new IndexMissingException(new Index(index));
                }
                IndexWarmersMetaData warmers = indexMetaData.custom(IndexWarmersMetaData.TYPE);
                if (warmers != null) {
                  for (IndexWarmersMetaData.Entry entry : warmers.entries()) {
                    for (String warmer : request.names()) {
                      if (Regex.simpleMatch(warmer, entry.name()) || warmer.equals("_all")) {
                        logger.info("[{}] delete warmer [{}]", index, entry.name());
                      }
                    }
                  }
                }
              }
            }

            return ClusterState.builder(currentState).metaData(mdBuilder).build();
          }
        });
  }