geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommands.java
@CliCommand(value = LuceneCliStrings.LUCENE_CREATE_INDEX,
      help = LuceneCliStrings.LUCENE_CREATE_INDEX__HELP)
  @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA})
  // TODO : Add optionContext for indexName
  public Result createIndex(@CliOption(key = LuceneCliStrings.LUCENE__INDEX_NAME, mandatory = true,
      help = LuceneCliStrings.LUCENE_CREATE_INDEX__NAME__HELP) final String indexName,

      @CliOption(key = LuceneCliStrings.LUCENE__REGION_PATH, mandatory = true,
          optionContext = ConverterHint.REGION_PATH,
          help = LuceneCliStrings.LUCENE_CREATE_INDEX__REGION_HELP) final String regionPath,

      @CliOption(key = LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, mandatory = true,
          help = LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD_HELP) final String[] fields,

      @CliOption(key = LuceneCliStrings.LUCENE_CREATE_INDEX__ANALYZER,
          help = LuceneCliStrings.LUCENE_CREATE_INDEX__ANALYZER_HELP) final String[] analyzers) {

    Result result;
    XmlEntity xmlEntity = null;

    // Every lucene index potentially writes to disk.
    getSecurityService().authorize(Resource.CLUSTER, Operation.MANAGE, LucenePermission.TARGET);

    try {
      final InternalCache cache = getCache();

      // trim fields for any leading trailing spaces.
      String[] trimmedFields = Arrays.stream(fields).map(String::trim).toArray(String[]::new);
      LuceneIndexInfo indexInfo =
          new LuceneIndexInfo(indexName, regionPath, trimmedFields, analyzers);

      final ResultCollector<?, ?> rc =
          this.executeFunctionOnAllMembers(createIndexFunction, indexInfo);
      final List<CliFunctionResult> funcResults = (List<CliFunctionResult>) rc.getResult();

      final TabularResultData tabularResult = ResultBuilder.createTabularResultData();
      for (final CliFunctionResult cliFunctionResult : funcResults) {
        tabularResult.accumulate("Member", cliFunctionResult.getMemberIdOrName());

        if (cliFunctionResult.isSuccessful()) {
          tabularResult.accumulate("Status", "Successfully created lucene index");
          // if (xmlEntity == null) {
          // xmlEntity = cliFunctionResult.getXmlEntity();
          // }
        } else {
          tabularResult.accumulate("Status", "Failed: " + cliFunctionResult.getMessage());
        }
      }
      result = ResultBuilder.buildResult(tabularResult);
    } catch (IllegalArgumentException iae) {
      LogWrapper.getInstance().info(iae.getMessage());
      result = ResultBuilder.createUserErrorResult(iae.getMessage());
    } catch (CommandResultException crex) {
      result = crex.getResult();
    } catch (Exception e) {
      result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    }
    // TODO - store in cluster config
    // if (xmlEntity != null) {
    // result.setCommandPersisted((new SharedConfigurationWriter()).addXmlEntity(xmlEntity,
    // groups));
    // }

    return result;
  }
/**
   * On the server, we also verify the resource operation permissions CLUSTER:WRITE:DISK
   */
On the server, we also verify the resource operation permissions CLUSTER:WRITE:DISK
On the server we also verify the resource operation permissions CLUSTER : WRITE : DISK
@CliCommand(value = LuceneCliStrings.LUCENE_CREATE_INDEX,
      help = LuceneCliStrings.LUCENE_CREATE_INDEX__HELP)
  @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA})
  public Result createIndex(@CliOption(key = LuceneCliStrings.LUCENE__INDEX_NAME, mandatory = true,
      help = LuceneCliStrings.LUCENE_CREATE_INDEX__NAME__HELP) final String indexName,
      @CliOption(key = LuceneCliStrings.LUCENE__REGION_PATH, mandatory = true,
          optionContext = ConverterHint.REGION_PATH,
          help = LuceneCliStrings.LUCENE_CREATE_INDEX__REGION_HELP) final String regionPath,
      @CliOption(key = LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, mandatory = true,
          help = LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD_HELP) final String[] fields,
      @CliOption(key = LuceneCliStrings.LUCENE_CREATE_INDEX__ANALYZER,
          help = LuceneCliStrings.LUCENE_CREATE_INDEX__ANALYZER_HELP) final String[] analyzers) {
    Result result;
    XmlEntity xmlEntity = null;
    getSecurityService().authorize(Resource.CLUSTER, Operation.MANAGE, LucenePermission.TARGET);
    try {
      final InternalCache cache = getCache();
      String[] trimmedFields = Arrays.stream(fields).map(String::trim).toArray(String[]::new);
      LuceneIndexInfo indexInfo =
          new LuceneIndexInfo(indexName, regionPath, trimmedFields, analyzers);
      final ResultCollector<?, ?> rc =
          this.executeFunctionOnAllMembers(createIndexFunction, indexInfo);
      final List<CliFunctionResult> funcResults = (List<CliFunctionResult>) rc.getResult();
      final TabularResultData tabularResult = ResultBuilder.createTabularResultData();
      for (final CliFunctionResult cliFunctionResult : funcResults) {
        tabularResult.accumulate("Member", cliFunctionResult.getMemberIdOrName());
        if (cliFunctionResult.isSuccessful()) {
          tabularResult.accumulate("Status", "Successfully created lucene index");
        } else {
          tabularResult.accumulate("Status", "Failed: " + cliFunctionResult.getMessage());
        }
      }
      result = ResultBuilder.buildResult(tabularResult);
    } catch (IllegalArgumentException iae) {
      LogWrapper.getInstance().info(iae.getMessage());
      result = ResultBuilder.createUserErrorResult(iae.getMessage());
    } catch (CommandResultException crex) {
      result = crex.getResult();
    } catch (Exception e) {
      result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    }
    return result;
  }
@ CliCommand ( value = LuceneCliStrings . LUCENE_CREATE_INDEX , help = LuceneCliStrings . LUCENE_CREATE_INDEX__HELP ) @ CliMetaData ( relatedTopic = { CliStrings . TOPIC_GEODE_REGION , CliStrings . TOPIC_GEODE_DATA } ) public Result createIndex ( @ CliOption ( key = LuceneCliStrings . LUCENE__INDEX_NAME , mandatory = true , help = LuceneCliStrings . LUCENE_CREATE_INDEX__NAME__HELP ) final String indexName , @ CliOption ( key = LuceneCliStrings . LUCENE__REGION_PATH , mandatory = true , optionContext = ConverterHint . REGION_PATH , help = LuceneCliStrings . LUCENE_CREATE_INDEX__REGION_HELP ) final String regionPath , @ CliOption ( key = LuceneCliStrings . LUCENE_CREATE_INDEX__FIELD , mandatory = true , help = LuceneCliStrings . LUCENE_CREATE_INDEX__FIELD_HELP ) final String [ ] fields , @ CliOption ( key = LuceneCliStrings . LUCENE_CREATE_INDEX__ANALYZER , help = LuceneCliStrings . LUCENE_CREATE_INDEX__ANALYZER_HELP ) final String [ ] analyzers ) { Result result ; XmlEntity xmlEntity = null ; getSecurityService ( ) . authorize ( Resource . CLUSTER , Operation . MANAGE , LucenePermission . TARGET ) ; try { final InternalCache cache = getCache ( ) ; String [ ] trimmedFields = Arrays . stream ( fields ) . map ( String :: trim ) . toArray ( String [ ] :: new ) ; LuceneIndexInfo indexInfo = new LuceneIndexInfo ( indexName , regionPath , trimmedFields , analyzers ) ; final ResultCollector < ? , ? > rc = this . executeFunctionOnAllMembers ( createIndexFunction , indexInfo ) ; final List < CliFunctionResult > funcResults = ( List < CliFunctionResult > ) rc . getResult ( ) ; final TabularResultData tabularResult = ResultBuilder . createTabularResultData ( ) ; for ( final CliFunctionResult cliFunctionResult : funcResults ) { tabularResult . accumulate ( "Member" , cliFunctionResult . getMemberIdOrName ( ) ) ; if ( cliFunctionResult . isSuccessful ( ) ) { tabularResult . accumulate ( "Status" , "Successfully created lucene index" ) ; } else { tabularResult . accumulate ( "Status" , "Failed: " + cliFunctionResult . getMessage ( ) ) ; } } result = ResultBuilder . buildResult ( tabularResult ) ; } catch ( IllegalArgumentException iae ) { LogWrapper . getInstance ( ) . info ( iae . getMessage ( ) ) ; result = ResultBuilder . createUserErrorResult ( iae . getMessage ( ) ) ; } catch ( CommandResultException crex ) { result = crex . getResult ( ) ; } catch ( Exception e ) { result = ResultBuilder . createGemFireErrorResult ( e . getMessage ( ) ) ; } return result ; }
On the server, we also verify the resource operation permissions CLUSTER:WRITE:DISK
On the server we also verify the resource operation permissions CLUSTER : WRITE : DISK
// TODO : Add optionContext for indexName // Every lucene index potentially writes to disk. // trim fields for any leading trailing spaces. // if (xmlEntity == null) { // xmlEntity = cliFunctionResult.getXmlEntity(); // } // TODO - store in cluster config // if (xmlEntity != null) { // result.setCommandPersisted((new SharedConfigurationWriter()).addXmlEntity(xmlEntity, // groups)); // }