geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
@CliCommand(value = {CliStrings.DEPLOY}, help = CliStrings.DEPLOY__HELP)
  @CliMetaData(
      interceptor = "org.apache.geode.management.internal.cli.commands.DeployCommand$Interceptor",
      isFileUploaded = true, relatedTopic = {CliStrings.TOPIC_GEODE_CONFIG})
  @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
      operation = ResourcePermission.Operation.MANAGE, target = ResourcePermission.Target.DEPLOY)
  public Result deploy(
      @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, help = CliStrings.DEPLOY__GROUP__HELP,
          optionContext = ConverterHint.MEMBERGROUP) String[] groups,
      @CliOption(key = {CliStrings.JAR, CliStrings.JARS},
          help = CliStrings.DEPLOY__JAR__HELP) String[] jars,
      @CliOption(key = {CliStrings.DEPLOY__DIR}, help = CliStrings.DEPLOY__DIR__HELP) String dir) {

    TabularResultData tabularData = ResultBuilder.createTabularResultData();

    byte[][] shellBytesData = CommandExecutionContext.getBytesFromShell();
    String[] jarNames = CliUtil.bytesToNames(shellBytesData);
    byte[][] jarBytes = CliUtil.bytesToData(shellBytesData);

    Set<DistributedMember> targetMembers;

    targetMembers = CliUtil.findMembers(groups, null);

    if (targetMembers.size() > 0) {
      // this deploys the jars to all the matching servers
      ResultCollector<?, ?> resultCollector = CliUtil.executeFunction(this.deployFunction,
          new Object[] {jarNames, jarBytes}, targetMembers);

      List<CliFunctionResult> results =
          CliFunctionResult.cleanResults((List<?>) resultCollector.getResult());

      for (CliFunctionResult result : results) {
        if (result.getThrowable() != null) {
          tabularData.accumulate("Member", result.getMemberIdOrName());
          tabularData.accumulate("Deployed JAR", "");
          tabularData.accumulate("Deployed JAR Location",
              "ERROR: " + result.getThrowable().getClass().getName() + ": "
                  + result.getThrowable().getMessage());
          tabularData.setStatus(Result.Status.ERROR);
        } else {
          String[] strings = (String[]) result.getSerializables();
          for (int i = 0; i < strings.length; i += 2) {
            tabularData.accumulate("Member", result.getMemberIdOrName());
            tabularData.accumulate("Deployed JAR", strings[i]);
            tabularData.accumulate("Deployed JAR Location", strings[i + 1]);
          }
        }
      }
    }

    Result result = ResultBuilder.buildResult(tabularData);
    persistClusterConfiguration(result,
        () -> getSharedConfiguration().addJarsToThisLocator(jarNames, jarBytes, groups));
    return result;
  }
/**
   * Deploy one or more JAR files to members of a group or all members.
   *
   * @param groups Group(s) to deploy the JAR to or null for all members
   * @param jars JAR file to deploy
   * @param dir Directory of JAR files to deploy
   * @return The result of the attempt to deploy
   */
Deploy one or more JAR files to members of a group or all members.
@param groups Group(s) to deploy the JAR to or null for all members
@param jars JAR file to deploy
@param dir Directory of JAR files to deploy
@return The result of the attempt to deploy
Deploy one or more JAR files to members of a group or all members . @param groups Group ( s ) to deploy the JAR to or null for all members @param jars JAR file to deploy @param dir Directory of JAR files to deploy @return The result of the attempt to deploy
@CliCommand(value = {CliStrings.DEPLOY}, help = CliStrings.DEPLOY__HELP)
  @CliMetaData(
      interceptor = "org.apache.geode.management.internal.cli.commands.DeployCommand$Interceptor",
      isFileUploaded = true, relatedTopic = {CliStrings.TOPIC_GEODE_CONFIG})
  @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
      operation = ResourcePermission.Operation.MANAGE, target = ResourcePermission.Target.DEPLOY)
  public Result deploy(
      @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, help = CliStrings.DEPLOY__GROUP__HELP,
          optionContext = ConverterHint.MEMBERGROUP) String[] groups,
      @CliOption(key = {CliStrings.JAR, CliStrings.JARS},
          help = CliStrings.DEPLOY__JAR__HELP) String[] jars,
      @CliOption(key = {CliStrings.DEPLOY__DIR}, help = CliStrings.DEPLOY__DIR__HELP) String dir) {
    TabularResultData tabularData = ResultBuilder.createTabularResultData();
    byte[][] shellBytesData = CommandExecutionContext.getBytesFromShell();
    String[] jarNames = CliUtil.bytesToNames(shellBytesData);
    byte[][] jarBytes = CliUtil.bytesToData(shellBytesData);
    Set<DistributedMember> targetMembers;
    targetMembers = CliUtil.findMembers(groups, null);
    if (targetMembers.size() > 0) {
      ResultCollector<?, ?> resultCollector = CliUtil.executeFunction(this.deployFunction,
          new Object[] {jarNames, jarBytes}, targetMembers);
      List<CliFunctionResult> results =
          CliFunctionResult.cleanResults((List<?>) resultCollector.getResult());
      for (CliFunctionResult result : results) {
        if (result.getThrowable() != null) {
          tabularData.accumulate("Member", result.getMemberIdOrName());
          tabularData.accumulate("Deployed JAR", "");
          tabularData.accumulate("Deployed JAR Location",
              "ERROR: " + result.getThrowable().getClass().getName() + ": "
                  + result.getThrowable().getMessage());
          tabularData.setStatus(Result.Status.ERROR);
        } else {
          String[] strings = (String[]) result.getSerializables();
          for (int i = 0; i < strings.length; i += 2) {
            tabularData.accumulate("Member", result.getMemberIdOrName());
            tabularData.accumulate("Deployed JAR", strings[i]);
            tabularData.accumulate("Deployed JAR Location", strings[i + 1]);
          }
        }
      }
    }
    Result result = ResultBuilder.buildResult(tabularData);
    persistClusterConfiguration(result,
        () -> getSharedConfiguration().addJarsToThisLocator(jarNames, jarBytes, groups));
    return result;
  }
@ CliCommand ( value = { CliStrings . DEPLOY } , help = CliStrings . DEPLOY__HELP ) @ CliMetaData ( interceptor = "org.apache.geode.management.internal.cli.commands.DeployCommand$Interceptor" , isFileUploaded = true , relatedTopic = { CliStrings . TOPIC_GEODE_CONFIG } ) @ ResourceOperation ( resource = ResourcePermission . Resource . CLUSTER , operation = ResourcePermission . Operation . MANAGE , target = ResourcePermission . Target . DEPLOY ) public Result deploy ( @ CliOption ( key = { CliStrings . GROUP , CliStrings . GROUPS } , help = CliStrings . DEPLOY__GROUP__HELP , optionContext = ConverterHint . MEMBERGROUP ) String [ ] groups , @ CliOption ( key = { CliStrings . JAR , CliStrings . JARS } , help = CliStrings . DEPLOY__JAR__HELP ) String [ ] jars , @ CliOption ( key = { CliStrings . DEPLOY__DIR } , help = CliStrings . DEPLOY__DIR__HELP ) String dir ) { TabularResultData tabularData = ResultBuilder . createTabularResultData ( ) ; byte [ ] [ ] shellBytesData = CommandExecutionContext . getBytesFromShell ( ) ; String [ ] jarNames = CliUtil . bytesToNames ( shellBytesData ) ; byte [ ] [ ] jarBytes = CliUtil . bytesToData ( shellBytesData ) ; Set < DistributedMember > targetMembers ; targetMembers = CliUtil . findMembers ( groups , null ) ; if ( targetMembers . size ( ) > 0 ) { ResultCollector < ? , ? > resultCollector = CliUtil . executeFunction ( this . deployFunction , new Object [ ] { jarNames , jarBytes } , targetMembers ) ; List < CliFunctionResult > results = CliFunctionResult . cleanResults ( ( List < ? > ) resultCollector . getResult ( ) ) ; for ( CliFunctionResult result : results ) { if ( result . getThrowable ( ) != null ) { tabularData . accumulate ( "Member" , result . getMemberIdOrName ( ) ) ; tabularData . accumulate ( "Deployed JAR" , "" ) ; tabularData . accumulate ( "Deployed JAR Location" , "ERROR: " + result . getThrowable ( ) . getClass ( ) . getName ( ) + ": " + result . getThrowable ( ) . getMessage ( ) ) ; tabularData . setStatus ( Result . Status . ERROR ) ; } else { String [ ] strings = ( String [ ] ) result . getSerializables ( ) ; for ( int i = 0 ; i < strings . length ; i += 2 ) { tabularData . accumulate ( "Member" , result . getMemberIdOrName ( ) ) ; tabularData . accumulate ( "Deployed JAR" , strings [ i ] ) ; tabularData . accumulate ( "Deployed JAR Location" , strings [ i + 1 ] ) ; } } } } Result result = ResultBuilder . buildResult ( tabularData ) ; persistClusterConfiguration ( result , ( ) -> getSharedConfiguration ( ) . addJarsToThisLocator ( jarNames , jarBytes , groups ) ) ; return result ; }
Deploy one or more JAR files to members of a group or all members.
Deploy one or more JAR files to members of a group or all members .
// this deploys the jars to all the matching servers