Program: 28833
Project: 28833
Buggy source:
/** 
 * Called from ExecutionContext.execute.
 */
private void doCommand(ExecutionContext inv,AdminCommand command,final Subject subject,final Job commandInstance){
  CommandModel model;
  try {
    CommandModelProvider c=CommandModelProvider.class.cast(command);
    model=c.getModel();
  }
 catch (  ClassCastException e) {
    model=new CommandModelImpl(command.getClass());
  }
  UploadedFilesManager ufm=null;
  ActionReport report=inv.report();
  ParameterMap parameters;
  final AdminCommandContext context=new AdminCommandContextImpl(logger,report,inv.inboundPayload(),inv.outboundPayload(),commandInstance.getEventBroker());
  context.setSubject(subject);
  List<RuntimeType> runtimeTypes=new ArrayList<RuntimeType>();
  FailurePolicy fp=null;
  Set<CommandTarget> targetTypesAllowed=new HashSet<CommandTarget>();
  ActionReport.ExitCode preSupplementalReturn=ActionReport.ExitCode.SUCCESS;
  ActionReport.ExitCode postSupplementalReturn=ActionReport.ExitCode.SUCCESS;
  CommandRunnerProgressHelper progressHelper=new CommandRunnerProgressHelper(command,model.getCommandName(),commandInstance,inv.progressStatusChild);
  boolean doReplication=false;
  if ((domain.getServers().getServer().size() > 1) || (!domain.getClusters().getCluster().isEmpty())) {
    doReplication=true;
  }
 else {
    logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
  }
  try {
    Collection<SupplementalCommand> suplementalCommands=supplementalExecutor.listSuplementalCommands(model.getCommandName());
    try {
      ufm=new UploadedFilesManager(inv.report,logger,inv.inboundPayload());
      if (inv.typedParams() != null) {
        logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
        InjectionResolver<Param> injectionTarget=new DelegatedInjectionResolver(model,inv.typedParams(),ufm.optionNameToFileMap());
        if (injectParameters(model,command,injectionTarget,context).equals(ActionReport.ExitCode.SUCCESS)) {
          inv.setReport(doCommand(model,command,context,progressHelper));
        }
        return;
      }
      parameters=inv.parameters();
      if (parameters == null) {
        parameters=new ParameterMap();
      }
      if (isSet(parameters,"String_Node_Str") || isSet(parameters,"String_Node_Str")) {
        BufferedReader in=getManPage(model.getCommandName(),model);
        String manPage=encodeManPage(in);
        if (manPage != null && isSet(parameters,"String_Node_Str")) {
          inv.report().getTopMessagePart().addProperty("String_Node_Str",manPage);
        }
 else {
          report.getTopMessagePart().addProperty(AdminCommandResponse.GENERATED_HELP,"String_Node_Str");
          getHelp(command,report);
        }
        return;
      }
      try {
        if (!skipValidation(command)) {
          validateParameters(model,parameters);
        }
      }
 catch (      MultiException e) {
        Exception exception=e;
        for (        Throwable cause : e.getErrors()) {
          if (cause != null && (cause instanceof UnacceptableValueException)) {
            exception=(Exception)cause;
            break;
          }
        }
        logger.log(Level.SEVERE,KernelLoggerInfo.invocationException,exception);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(exception.getMessage());
        report.setFailureCause(exception);
        ActionReport.MessagePart childPart=report.getTopMessagePart().addChild();
        childPart.setMessage(getUsageText(command,model));
        return;
      }
      MapInjectionResolver injectionMgr=new MapInjectionResolver(model,parameters,ufm.optionNameToFileMap());
      injectionMgr.setContext(context);
      if (!injectParameters(model,command,injectionMgr,context).equals(ActionReport.ExitCode.SUCCESS)) {
        return;
      }
      CommandSupport.init(habitat,command,context,commandInstance);
      final Map<String,Object> env=buildEnvMap(parameters);
      try {
        if (!commandSecurityChecker.authorize(context.getSubject(),env,command,context)) {
          return;
        }
      }
 catch (      SecurityException ex) {
        report.setFailureCause(ex);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
        return;
      }
catch (      Exception ex) {
        report.setFailureCause(ex);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
        return;
      }
      logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
      org.glassfish.api.admin.ExecuteOn clAnnotation=model.getClusteringAttributes();
      if (clAnnotation == null) {
        runtimeTypes.add(RuntimeType.DAS);
        runtimeTypes.add(RuntimeType.INSTANCE);
        fp=FailurePolicy.Error;
      }
 else {
        if (clAnnotation.value().length == 0) {
          runtimeTypes.add(RuntimeType.DAS);
          runtimeTypes.add(RuntimeType.INSTANCE);
        }
 else {
          runtimeTypes.addAll(Arrays.asList(clAnnotation.value()));
        }
        if (clAnnotation.ifFailure() == null) {
          fp=FailurePolicy.Error;
        }
 else {
          fp=clAnnotation.ifFailure();
        }
      }
      TargetType tgtTypeAnnotation=command.getClass().getAnnotation(TargetType.class);
      if (runtimeTypes.contains(RuntimeType.SINGLE_INSTANCE)) {
        if (tgtTypeAnnotation != null) {
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str",model.getCommandName()));
          return;
        }
        doReplication=false;
      }
      String targetName=parameters.getOne("String_Node_Str");
      if (targetName == null || model.getModelFor("String_Node_Str").getParam().obsolete()) {
        if (command instanceof DeploymentTargetResolver) {
          targetName=((DeploymentTargetResolver)command).getTarget(parameters);
        }
 else {
          targetName="String_Node_Str";
        }
      }
      logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",targetName));
      if (serverEnv.isDas()) {
        if (tgtTypeAnnotation != null) {
          targetTypesAllowed.addAll(Arrays.asList(tgtTypeAnnotation.value()));
        }
        if (targetTypesAllowed.isEmpty()) {
          targetTypesAllowed.add(CommandTarget.DAS);
          targetTypesAllowed.add(CommandTarget.STANDALONE_INSTANCE);
          targetTypesAllowed.add(CommandTarget.CLUSTER);
          targetTypesAllowed.add(CommandTarget.CONFIG);
        }
        if (CommandTarget.DAS.isValid(habitat,targetName) && !runtimeTypes.contains(RuntimeType.DAS)) {
          runtimeTypes.add(RuntimeType.DAS);
        }
        logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",runtimeTypes.toString()));
        logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",targetTypesAllowed.toString()));
        if ((!CommandTarget.DOMAIN.isValid(habitat,targetName)) && (domain.getServerNamed(targetName) == null) && (domain.getClusterNamed(targetName) == null)&& (domain.getConfigNamed(targetName) == null)) {
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str",targetName));
          return;
        }
        boolean isTargetValidType=false;
        Iterator<CommandTarget> it=targetTypesAllowed.iterator();
        while (it.hasNext()) {
          if (it.next().isValid(habitat,targetName)) {
            isTargetValidType=true;
            break;
          }
        }
        if (!isTargetValidType) {
          StringBuilder validTypes=new StringBuilder();
          it=targetTypesAllowed.iterator();
          while (it.hasNext()) {
            validTypes.append(it.next().getDescription()).append("String_Node_Str");
          }
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str",targetName,model.getCommandName(),validTypes.toString()));
          return;
        }
        if ((CommandTarget.CLUSTERED_INSTANCE.isValid(habitat,targetName)) && (!targetTypesAllowed.contains(CommandTarget.CLUSTERED_INSTANCE))) {
          Cluster c=domain.getClusterForInstance(targetName);
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str",model.getCommandName(),targetName,c.getName()));
          return;
        }
        logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
      }
      Lock lock=null;
      boolean lockTimedOut=false;
      try {
        lock=adminLock.getLock(command,"String_Node_Str");
        for (        SupplementalCommand supplementalCommand : suplementalCommands) {
          progressHelper.addProgressStatusToSupplementalCommand(supplementalCommand);
        }
        if (command instanceof UndoableCommand) {
          UndoableCommand uCmd=(UndoableCommand)command;
          logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",inv.name()));
          if (!uCmd.prepare(context,parameters).equals(ActionReport.ExitCode.SUCCESS)) {
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str" + "String_Node_Str",model.getCommandName(),report.getMessage()));
            return;
          }
        }
        ClusterOperationUtil.clearInstanceList();
        logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",inv.name()));
        preSupplementalReturn=supplementalExecutor.execute(suplementalCommands,Supplemental.Timing.Before,context,parameters,ufm.optionNameToFileMap());
        if (preSupplementalReturn.equals(ActionReport.ExitCode.FAILURE)) {
          report.setActionExitCode(preSupplementalReturn);
          report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
          return;
        }
        if ((runtimeTypes.contains(RuntimeType.ALL)) || (serverEnv.isDas() && (CommandTarget.DOMAIN.isValid(habitat,targetName) || runtimeTypes.contains(RuntimeType.DAS))) || runtimeTypes.contains(RuntimeType.SINGLE_INSTANCE)|| (serverEnv.isInstance() && runtimeTypes.contains(RuntimeType.INSTANCE))) {
          logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",inv.name()));
          report=doCommand(model,command,context,progressHelper);
          inv.setReport(report);
        }
        if (!FailurePolicy.applyFailurePolicy(fp,report.getActionExitCode()).equals(ActionReport.ExitCode.FAILURE)) {
          logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",inv.name()));
          postSupplementalReturn=supplementalExecutor.execute(suplementalCommands,Supplemental.Timing.After,context,parameters,ufm.optionNameToFileMap());
          if (postSupplementalReturn.equals(ActionReport.ExitCode.FAILURE)) {
            report.setActionExitCode(postSupplementalReturn);
            report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
            return;
          }
        }
      }
 catch (      AdminCommandLockTimeoutException ex) {
        lockTimedOut=true;
        String lockTime=formatSuspendDate(ex.getTimeOfAcquisition());
        String logMsg="String_Node_Str" + model.getCommandName() + "String_Node_Str"+ "String_Node_Str"+ lockTime+ "String_Node_Str";
        String msg=adminStrings.getLocalString("String_Node_Str","String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str",lockTime);
        report.setMessage(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      }
catch (      AdminCommandLockException ex) {
        lockTimedOut=true;
        String lockTime=formatSuspendDate(ex.getTimeOfAcquisition());
        String lockMsg=ex.getMessage();
        String logMsg;
        logMsg="String_Node_Str" + model.getCommandName() + "String_Node_Str"+ "String_Node_Str"+ lockTime;
        if (lockMsg != null && !lockMsg.isEmpty()) {
          logMsg+="String_Node_Str" + lockMsg;
        }
        String msg=adminStrings.getLocalString("String_Node_Str","String_Node_Str" + "String_Node_Str",lockTime);
        if (lockMsg != null && !lockMsg.isEmpty()) {
          msg+="String_Node_Str" + adminStrings.getLocalString("String_Node_Str","String_Node_Str") + "String_Node_Str"+ lockMsg;
        }
        report.setMessage(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      }
 finally {
        if (lock != null && lockTimedOut == false) {
          lock.unlock();
        }
      }
    }
 catch (    Exception ex) {
      logger.log(Level.SEVERE,KernelLoggerInfo.invocationException,ex);
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      report.setMessage(ex.getMessage());
      report.setFailureCause(ex);
      ActionReport.MessagePart childPart=report.getTopMessagePart().addChild();
      childPart.setMessage(getUsageText(command,model));
      return;
    }
    if (processEnv.getProcessType().isEmbedded()) {
      return;
    }
    if (preSupplementalReturn == ActionReport.ExitCode.WARNING || postSupplementalReturn == ActionReport.ExitCode.WARNING) {
      report.setActionExitCode(ActionReport.ExitCode.WARNING);
    }
    if (doReplication && (!FailurePolicy.applyFailurePolicy(fp,report.getActionExitCode()).equals(ActionReport.ExitCode.FAILURE)) && (serverEnv.isDas())&& (runtimeTypes.contains(RuntimeType.INSTANCE) || runtimeTypes.contains(RuntimeType.ALL))) {
      logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
      ClusterExecutor executor=null;
      try {
        if (model.getClusteringAttributes() != null && model.getClusteringAttributes().executor() != null) {
          executor=habitat.getService(model.getClusteringAttributes().executor());
        }
 else {
          executor=habitat.getService(ClusterExecutor.class,"String_Node_Str");
        }
      }
 catch (      UnsatisfiedDependencyException usdepex) {
        logger.log(Level.WARNING,KernelLoggerInfo.cantGetClusterExecutor,usdepex);
      }
      if (executor != null) {
        report.setActionExitCode(executor.execute(model.getCommandName(),command,context,parameters));
        if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
          report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
        }
 else {
          if (!FailurePolicy.applyFailurePolicy(fp,report.getActionExitCode()).equals(ActionReport.ExitCode.FAILURE)) {
            logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",inv.name()));
            ActionReport.ExitCode afterReplicationSupplementalReturn=supplementalExecutor.execute(suplementalCommands,Supplemental.Timing.AfterReplication,context,parameters,ufm.optionNameToFileMap());
            if (afterReplicationSupplementalReturn.equals(ActionReport.ExitCode.FAILURE)) {
              report.setActionExitCode(afterReplicationSupplementalReturn);
              report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
              return;
            }
          }
        }
      }
    }
    if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
      if (command instanceof UndoableCommand) {
        UndoableCommand uCmd=(UndoableCommand)command;
        logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",inv.name()));
        uCmd.undo(context,parameters,ClusterOperationUtil.getCompletedInstances());
      }
    }
 else {
      if ("String_Node_Str".equals(model.getCommandName())) {
        state.addServerToStateService(parameters.getOne("String_Node_Str"));
      }
      if ("String_Node_Str".equals(model.getCommandName())) {
        state.removeInstanceFromStateService(parameters.getOne("String_Node_Str"));
      }
    }
  }
  finally {
    if (ufm != null) {
      ufm.close();
    }
  }
}

Fixed version (ground truth):
/** 
 * Called from ExecutionContext.execute.
 */
private void doCommand(ExecutionContext inv,AdminCommand command,final Subject subject,final Job commandInstance){
  CommandModel model;
  try {
    CommandModelProvider c=CommandModelProvider.class.cast(command);
    model=c.getModel();
  }
 catch (  ClassCastException e) {
    model=new CommandModelImpl(command.getClass());
  }
  UploadedFilesManager ufm=null;
  ActionReport report=inv.report();
  ParameterMap parameters;
  final AdminCommandContext context=new AdminCommandContextImpl(logger,report,inv.inboundPayload(),inv.outboundPayload(),commandInstance.getEventBroker());
  context.setSubject(subject);
  List<RuntimeType> runtimeTypes=new ArrayList<RuntimeType>();
  FailurePolicy fp=null;
  Set<CommandTarget> targetTypesAllowed=new HashSet<CommandTarget>();
  ActionReport.ExitCode preSupplementalReturn=ActionReport.ExitCode.SUCCESS;
  ActionReport.ExitCode postSupplementalReturn=ActionReport.ExitCode.SUCCESS;
  CommandRunnerProgressHelper progressHelper=new CommandRunnerProgressHelper(command,model.getCommandName(),commandInstance,inv.progressStatusChild);
  boolean doReplication=false;
  if ((domain.getServers().getServer().size() > 1) || (!domain.getClusters().getCluster().isEmpty())) {
    doReplication=true;
  }
 else {
    logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
  }
  try {
    Collection<SupplementalCommand> suplementalCommands=supplementalExecutor.listSuplementalCommands(model.getCommandName());
    try {
      ufm=new UploadedFilesManager(inv.report,logger,inv.inboundPayload());
      if (inv.typedParams() != null) {
        logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
        InjectionResolver<Param> injectionTarget=new DelegatedInjectionResolver(model,inv.typedParams(),ufm.optionNameToFileMap());
        if (injectParameters(model,command,injectionTarget,context).equals(ActionReport.ExitCode.SUCCESS)) {
          inv.setReport(doCommand(model,command,context,progressHelper));
        }
        return;
      }
      parameters=inv.parameters();
      if (parameters == null) {
        parameters=new ParameterMap();
      }
      if (isSet(parameters,"String_Node_Str") || isSet(parameters,"String_Node_Str")) {
        BufferedReader in=getManPage(model.getCommandName(),model);
        String manPage=encodeManPage(in);
        if (manPage != null && isSet(parameters,"String_Node_Str")) {
          inv.report().getTopMessagePart().addProperty("String_Node_Str",manPage);
        }
 else {
          report.getTopMessagePart().addProperty(AdminCommandResponse.GENERATED_HELP,"String_Node_Str");
          getHelp(command,report);
        }
        return;
      }
      try {
        if (!skipValidation(command)) {
          validateParameters(model,parameters);
        }
      }
 catch (      MultiException e) {
        Exception exception=e;
        for (        Throwable cause : e.getErrors()) {
          if (cause != null && (cause instanceof UnacceptableValueException)) {
            exception=(Exception)cause;
            break;
          }
        }
        logger.log(Level.SEVERE,KernelLoggerInfo.invocationException,exception);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(exception.getMessage());
        report.setFailureCause(exception);
        ActionReport.MessagePart childPart=report.getTopMessagePart().addChild();
        childPart.setMessage(getUsageText(command,model));
        return;
      }
      MapInjectionResolver injectionMgr=new MapInjectionResolver(model,parameters,ufm.optionNameToFileMap());
      injectionMgr.setContext(context);
      if (!injectParameters(model,command,injectionMgr,context).equals(ActionReport.ExitCode.SUCCESS)) {
        return;
      }
      CommandSupport.init(habitat,command,context,commandInstance);
      final Map<String,Object> env=buildEnvMap(parameters);
      try {
        if (!commandSecurityChecker.authorize(context.getSubject(),env,command,context)) {
          return;
        }
      }
 catch (      SecurityException ex) {
        report.setFailureCause(ex);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
        return;
      }
catch (      Exception ex) {
        report.setFailureCause(ex);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
        return;
      }
      logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
      org.glassfish.api.admin.ExecuteOn clAnnotation=model.getClusteringAttributes();
      if (clAnnotation == null) {
        runtimeTypes.add(RuntimeType.DAS);
        runtimeTypes.add(RuntimeType.INSTANCE);
        fp=FailurePolicy.Error;
      }
 else {
        if (clAnnotation.value().length == 0) {
          runtimeTypes.add(RuntimeType.DAS);
          runtimeTypes.add(RuntimeType.INSTANCE);
        }
 else {
          runtimeTypes.addAll(Arrays.asList(clAnnotation.value()));
        }
        if (clAnnotation.ifFailure() == null) {
          fp=FailurePolicy.Error;
        }
 else {
          fp=clAnnotation.ifFailure();
        }
      }
      TargetType tgtTypeAnnotation=command.getClass().getAnnotation(TargetType.class);
      if (runtimeTypes.contains(RuntimeType.SINGLE_INSTANCE)) {
        if (tgtTypeAnnotation != null) {
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str",model.getCommandName()));
          return;
        }
        doReplication=false;
      }
      String targetName=parameters.getOne("String_Node_Str");
      if (targetName == null || model.getModelFor("String_Node_Str").getParam().obsolete()) {
        if (command instanceof DeploymentTargetResolver) {
          targetName=((DeploymentTargetResolver)command).getTarget(parameters);
        }
 else {
          targetName="String_Node_Str";
        }
      }
      logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",targetName));
      if (serverEnv.isDas()) {
        if (tgtTypeAnnotation != null) {
          targetTypesAllowed.addAll(Arrays.asList(tgtTypeAnnotation.value()));
        }
        if (targetTypesAllowed.isEmpty()) {
          targetTypesAllowed.add(CommandTarget.DAS);
          targetTypesAllowed.add(CommandTarget.STANDALONE_INSTANCE);
          targetTypesAllowed.add(CommandTarget.CLUSTER);
          targetTypesAllowed.add(CommandTarget.CONFIG);
        }
        if (CommandTarget.DAS.isValid(habitat,targetName) && !runtimeTypes.contains(RuntimeType.DAS)) {
          runtimeTypes.add(RuntimeType.DAS);
        }
        logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",runtimeTypes.toString()));
        logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",targetTypesAllowed.toString()));
        if ((!CommandTarget.DOMAIN.isValid(habitat,targetName)) && (domain.getServerNamed(targetName) == null) && (domain.getClusterNamed(targetName) == null)&& (domain.getConfigNamed(targetName) == null)) {
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str",targetName));
          return;
        }
        boolean isTargetValidType=false;
        Iterator<CommandTarget> it=targetTypesAllowed.iterator();
        while (it.hasNext()) {
          if (it.next().isValid(habitat,targetName)) {
            isTargetValidType=true;
            break;
          }
        }
        if (!isTargetValidType) {
          StringBuilder validTypes=new StringBuilder();
          it=targetTypesAllowed.iterator();
          while (it.hasNext()) {
            validTypes.append(it.next().getDescription()).append("String_Node_Str");
          }
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str",targetName,model.getCommandName(),validTypes.toString()));
          return;
        }
        if ((CommandTarget.CLUSTERED_INSTANCE.isValid(habitat,targetName)) && (!targetTypesAllowed.contains(CommandTarget.CLUSTERED_INSTANCE))) {
          Cluster c=domain.getClusterForInstance(targetName);
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str",model.getCommandName(),targetName,c.getName()));
          return;
        }
        logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
      }
      Lock lock=null;
      boolean lockTimedOut=false;
      try {
        lock=adminLock.getLock(command,"String_Node_Str");
        for (        SupplementalCommand supplementalCommand : suplementalCommands) {
          progressHelper.addProgressStatusToSupplementalCommand(supplementalCommand);
        }
        if (command instanceof UndoableCommand) {
          UndoableCommand uCmd=(UndoableCommand)command;
          logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",inv.name()));
          if (!uCmd.prepare(context,parameters).equals(ActionReport.ExitCode.SUCCESS)) {
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str" + "String_Node_Str",model.getCommandName(),report.getMessage()));
            return;
          }
        }
        ClusterOperationUtil.clearInstanceList();
        logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",inv.name()));
        preSupplementalReturn=supplementalExecutor.execute(suplementalCommands,Supplemental.Timing.Before,context,parameters,ufm.optionNameToFileMap());
        if (preSupplementalReturn.equals(ActionReport.ExitCode.FAILURE)) {
          report.setActionExitCode(preSupplementalReturn);
          if (!StringUtils.ok(report.getTopMessagePart().getMessage())) {
            report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
          }
          return;
        }
        if ((runtimeTypes.contains(RuntimeType.ALL)) || (serverEnv.isDas() && (CommandTarget.DOMAIN.isValid(habitat,targetName) || runtimeTypes.contains(RuntimeType.DAS))) || runtimeTypes.contains(RuntimeType.SINGLE_INSTANCE)|| (serverEnv.isInstance() && runtimeTypes.contains(RuntimeType.INSTANCE))) {
          logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",inv.name()));
          report=doCommand(model,command,context,progressHelper);
          inv.setReport(report);
        }
        if (!FailurePolicy.applyFailurePolicy(fp,report.getActionExitCode()).equals(ActionReport.ExitCode.FAILURE)) {
          logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",inv.name()));
          postSupplementalReturn=supplementalExecutor.execute(suplementalCommands,Supplemental.Timing.After,context,parameters,ufm.optionNameToFileMap());
          if (postSupplementalReturn.equals(ActionReport.ExitCode.FAILURE)) {
            report.setActionExitCode(postSupplementalReturn);
            report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
            return;
          }
        }
      }
 catch (      AdminCommandLockTimeoutException ex) {
        lockTimedOut=true;
        String lockTime=formatSuspendDate(ex.getTimeOfAcquisition());
        String logMsg="String_Node_Str" + model.getCommandName() + "String_Node_Str"+ "String_Node_Str"+ lockTime+ "String_Node_Str";
        String msg=adminStrings.getLocalString("String_Node_Str","String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str",lockTime);
        report.setMessage(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      }
catch (      AdminCommandLockException ex) {
        lockTimedOut=true;
        String lockTime=formatSuspendDate(ex.getTimeOfAcquisition());
        String lockMsg=ex.getMessage();
        String logMsg;
        logMsg="String_Node_Str" + model.getCommandName() + "String_Node_Str"+ "String_Node_Str"+ lockTime;
        if (lockMsg != null && !lockMsg.isEmpty()) {
          logMsg+="String_Node_Str" + lockMsg;
        }
        String msg=adminStrings.getLocalString("String_Node_Str","String_Node_Str" + "String_Node_Str",lockTime);
        if (lockMsg != null && !lockMsg.isEmpty()) {
          msg+="String_Node_Str" + adminStrings.getLocalString("String_Node_Str","String_Node_Str") + "String_Node_Str"+ lockMsg;
        }
        report.setMessage(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      }
 finally {
        if (lock != null && lockTimedOut == false) {
          lock.unlock();
        }
      }
    }
 catch (    Exception ex) {
      logger.log(Level.SEVERE,KernelLoggerInfo.invocationException,ex);
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      report.setMessage(ex.getMessage());
      report.setFailureCause(ex);
      ActionReport.MessagePart childPart=report.getTopMessagePart().addChild();
      childPart.setMessage(getUsageText(command,model));
      return;
    }
    if (processEnv.getProcessType().isEmbedded()) {
      return;
    }
    if (preSupplementalReturn == ActionReport.ExitCode.WARNING || postSupplementalReturn == ActionReport.ExitCode.WARNING) {
      report.setActionExitCode(ActionReport.ExitCode.WARNING);
    }
    if (doReplication && (!FailurePolicy.applyFailurePolicy(fp,report.getActionExitCode()).equals(ActionReport.ExitCode.FAILURE)) && (serverEnv.isDas())&& (runtimeTypes.contains(RuntimeType.INSTANCE) || runtimeTypes.contains(RuntimeType.ALL))) {
      logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
      ClusterExecutor executor=null;
      try {
        if (model.getClusteringAttributes() != null && model.getClusteringAttributes().executor() != null) {
          executor=habitat.getService(model.getClusteringAttributes().executor());
        }
 else {
          executor=habitat.getService(ClusterExecutor.class,"String_Node_Str");
        }
      }
 catch (      UnsatisfiedDependencyException usdepex) {
        logger.log(Level.WARNING,KernelLoggerInfo.cantGetClusterExecutor,usdepex);
      }
      if (executor != null) {
        report.setActionExitCode(executor.execute(model.getCommandName(),command,context,parameters));
        if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
          report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
        }
 else {
          if (!FailurePolicy.applyFailurePolicy(fp,report.getActionExitCode()).equals(ActionReport.ExitCode.FAILURE)) {
            logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",inv.name()));
            ActionReport.ExitCode afterReplicationSupplementalReturn=supplementalExecutor.execute(suplementalCommands,Supplemental.Timing.AfterReplication,context,parameters,ufm.optionNameToFileMap());
            if (afterReplicationSupplementalReturn.equals(ActionReport.ExitCode.FAILURE)) {
              report.setActionExitCode(afterReplicationSupplementalReturn);
              report.setMessage(adminStrings.getLocalString("String_Node_Str","String_Node_Str"));
              return;
            }
          }
        }
      }
    }
    if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
      if (command instanceof UndoableCommand) {
        UndoableCommand uCmd=(UndoableCommand)command;
        logger.fine(adminStrings.getLocalString("String_Node_Str","String_Node_Str",inv.name()));
        uCmd.undo(context,parameters,ClusterOperationUtil.getCompletedInstances());
      }
    }
 else {
      if ("String_Node_Str".equals(model.getCommandName())) {
        state.addServerToStateService(parameters.getOne("String_Node_Str"));
      }
      if ("String_Node_Str".equals(model.getCommandName())) {
        state.removeInstanceFromStateService(parameters.getOne("String_Node_Str"));
      }
    }
  }
  finally {
    if (ufm != null) {
      ufm.close();
    }
  }
}