geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jensde...@apache.org
Subject [31/50] [abbrv] incubator-geode git commit: Merge branch 'develop' into feature/GEODE-17
Date Thu, 25 Feb 2016 20:27:19 GMT
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5c01d5f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/WanCommands.java
----------------------------------------------------------------------
diff --cc geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/WanCommands.java
index 0000000,5630885..2892c00
mode 000000,100644..100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/WanCommands.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/WanCommands.java
@@@ -1,0 -1,1281 +1,1296 @@@
+ /*
+  * Licensed to the Apache Software Foundation (ASF) under one or more
+  * contributor license agreements.  See the NOTICE file distributed with
+  * this work for additional information regarding copyright ownership.
+  * The ASF licenses this file to You under the Apache License, Version 2.0
+  * (the "License"); you may not use this file except in compliance with
+  * the License.  You may obtain a copy of the License at
+  *
+  *      http://www.apache.org/licenses/LICENSE-2.0
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  */
+ package com.gemstone.gemfire.management.internal.cli.commands;
+ 
+ import java.util.ArrayList;
+ import java.util.HashSet;
+ import java.util.Iterator;
+ import java.util.List;
+ import java.util.Map;
+ import java.util.Set;
+ import java.util.TreeMap;
+ import java.util.concurrent.Callable;
+ import java.util.concurrent.ExecutionException;
+ import java.util.concurrent.ExecutorService;
+ import java.util.concurrent.Executors;
+ import java.util.concurrent.Future;
+ import java.util.concurrent.ThreadFactory;
+ import java.util.concurrent.atomic.AtomicInteger;
+ 
+ import javax.management.ObjectName;
+ 
+ import org.springframework.shell.core.CommandMarker;
+ import org.springframework.shell.core.annotation.CliAvailabilityIndicator;
+ import org.springframework.shell.core.annotation.CliCommand;
+ import org.springframework.shell.core.annotation.CliOption;
+ 
+ import com.gemstone.gemfire.cache.Cache;
+ import com.gemstone.gemfire.cache.CacheFactory;
+ import com.gemstone.gemfire.cache.execute.ResultCollector;
+ import com.gemstone.gemfire.distributed.DistributedMember;
+ import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
+ import com.gemstone.gemfire.management.DistributedSystemMXBean;
+ import com.gemstone.gemfire.management.GatewayReceiverMXBean;
+ import com.gemstone.gemfire.management.GatewaySenderMXBean;
+ import com.gemstone.gemfire.management.ManagementService;
+ import com.gemstone.gemfire.management.cli.CliMetaData;
+ import com.gemstone.gemfire.management.cli.ConverterHint;
+ import com.gemstone.gemfire.management.cli.Result;
+ import com.gemstone.gemfire.management.internal.MBeanJMXAdapter;
+ import com.gemstone.gemfire.management.internal.SystemManagementService;
+ import com.gemstone.gemfire.management.internal.cli.CliUtil;
+ import com.gemstone.gemfire.management.internal.cli.LogWrapper;
+ import com.gemstone.gemfire.management.internal.cli.functions.CliFunctionResult;
+ import com.gemstone.gemfire.management.internal.cli.functions.GatewayReceiverCreateFunction;
+ import com.gemstone.gemfire.management.internal.cli.functions.GatewayReceiverFunctionArgs;
+ import com.gemstone.gemfire.management.internal.cli.functions.GatewaySenderCreateFunction;
+ import com.gemstone.gemfire.management.internal.cli.functions.GatewaySenderFunctionArgs;
+ import com.gemstone.gemfire.management.internal.cli.i18n.CliStrings;
+ import com.gemstone.gemfire.management.internal.cli.result.CommandResultException;
+ import com.gemstone.gemfire.management.internal.cli.result.CompositeResultData;
+ import com.gemstone.gemfire.management.internal.cli.result.ResultBuilder;
+ import com.gemstone.gemfire.management.internal.cli.result.TabularResultData;
+ import com.gemstone.gemfire.management.internal.cli.shell.Gfsh;
+ import com.gemstone.gemfire.management.internal.configuration.SharedConfigurationWriter;
+ import com.gemstone.gemfire.management.internal.configuration.domain.XmlEntity;
++import com.gemstone.gemfire.management.internal.security.Resource;
++import com.gemstone.gemfire.management.internal.security.ResourceConstants;
++import com.gemstone.gemfire.management.internal.security.ResourceOperation;
+ 
+ public class WanCommands implements CommandMarker {
+ 
+   private Gfsh getGfsh() {
+     return Gfsh.getCurrentInstance();
+   }
+   
+   @CliCommand(value = CliStrings.CREATE_GATEWAYSENDER, help = CliStrings.CREATE_GATEWAYSENDER__HELP)
+   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEMFIRE_WAN, writesToSharedConfiguration=true)
++  @ResourceOperation( resource=Resource.DISTRIBUTED_SYSTEM, operation=ResourceConstants.CREATE_GW_SENDER)
+   public Result createGatewaySender(
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__GROUP,
+       optionContext = ConverterHint.MEMBERGROUP,
+       help = CliStrings.CREATE_GATEWAYSENDER__GROUP__HELP)
+       @CliMetaData (valueSeparator = ",") String[] onGroups,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__MEMBER, 
+       optionContext = ConverterHint.MEMBERIDNAME,
+       unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
+       help = CliStrings.CREATE_GATEWAYSENDER__MEMBER__HELP) 
+       @CliMetaData (valueSeparator = ",") String onMember,
+           
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__ID, 
+       mandatory = true, 
+       help = CliStrings.CREATE_GATEWAYSENDER__ID__HELP) String id,
+ 
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__REMOTEDISTRIBUTEDSYSTEMID, 
+       mandatory = true, 
+       help = CliStrings.CREATE_GATEWAYSENDER__REMOTEDISTRIBUTEDSYSTEMID__HELP) Integer remoteDistributedSystemId,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__PARALLEL, 
+       help = CliStrings.CREATE_GATEWAYSENDER__PARALLEL__HELP) Boolean parallel,
+ 
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__MANUALSTART, 
+       help = CliStrings.CREATE_GATEWAYSENDER__MANUALSTART__HELP) Boolean manualStart,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__SOCKETBUFFERSIZE, 
+       help = CliStrings.CREATE_GATEWAYSENDER__SOCKETBUFFERSIZE__HELP) Integer socketBufferSize,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__SOCKETREADTIMEOUT, 
+       help = CliStrings.CREATE_GATEWAYSENDER__SOCKETREADTIMEOUT__HELP) Integer socketReadTimeout,
+ 
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__ENABLEBATCHCONFLATION, 
+       help = CliStrings.CREATE_GATEWAYSENDER__ENABLEBATCHCONFLATION__HELP) Boolean enableBatchConflation,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__BATCHSIZE, 
+       help = CliStrings.CREATE_GATEWAYSENDER__BATCHSIZE__HELP) Integer batchSize,
+           
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__BATCHTIMEINTERVAL, 
+       help = CliStrings.CREATE_GATEWAYSENDER__BATCHTIMEINTERVAL__HELP) Integer batchTimeInterval,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__ENABLEPERSISTENCE, 
+       help = CliStrings.CREATE_GATEWAYSENDER__ENABLEPERSISTENCE__HELP) Boolean enablePersistence,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__DISKSTORENAME, 
+       help = CliStrings.CREATE_GATEWAYSENDER__DISKSTORENAME__HELP) String diskStoreName,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__DISKSYNCHRONOUS, 
+       help = CliStrings.CREATE_GATEWAYSENDER__DISKSYNCHRONOUS__HELP) Boolean diskSynchronous,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__MAXQUEUEMEMORY, 
+       help = CliStrings.CREATE_GATEWAYSENDER__MAXQUEUEMEMORY__HELP) Integer maxQueueMemory,
+           
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__ALERTTHRESHOLD, 
+       help = CliStrings.CREATE_GATEWAYSENDER__ALERTTHRESHOLD__HELP) Integer alertThreshold,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__DISPATCHERTHREADS, 
+       help = CliStrings.CREATE_GATEWAYSENDER__DISPATCHERTHREADS__HELP) Integer dispatcherThreads,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__ORDERPOLICY, 
+       help = CliStrings.CREATE_GATEWAYSENDER__ORDERPOLICY__HELP) String orderPolicy,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__GATEWAYEVENTFILTER, 
+       help = CliStrings.CREATE_GATEWAYSENDER__GATEWAYEVENTFILTER__HELP)
+       @CliMetaData (valueSeparator = ",") 
+       String[] gatewayEventFilters,
+           
+       @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__GATEWAYTRANSPORTFILTER, 
+       help = CliStrings.CREATE_GATEWAYSENDER__GATEWAYTRANSPORTFILTER__HELP)
+       @CliMetaData (valueSeparator = ",") 
+       String[] gatewayTransportFilter) {
+ 
+     Result result = null;
+ 
+     XmlEntity xmlEntity = null;
+     try {
+       GatewaySenderFunctionArgs gatewaySenderFunctionArgs = 
+         new GatewaySenderFunctionArgs(id,
+             remoteDistributedSystemId, parallel, manualStart, socketBufferSize, socketReadTimeout, 
+             enableBatchConflation, batchSize, batchTimeInterval, enablePersistence, diskStoreName, 
+             diskSynchronous, maxQueueMemory, alertThreshold, dispatcherThreads, orderPolicy, 
+             gatewayEventFilters, gatewayTransportFilter);
+       
+       Set<DistributedMember> membersToCreateGatewaySenderOn = CliUtil.findAllMatchingMembers(onGroups, onMember == null ? null : onMember.split(","));
+       
+       ResultCollector<?, ?> resultCollector = CliUtil.executeFunction(GatewaySenderCreateFunction.INSTANCE, gatewaySenderFunctionArgs, membersToCreateGatewaySenderOn);
+       @SuppressWarnings("unchecked")
+       List<CliFunctionResult> gatewaySenderCreateResults = (List<CliFunctionResult>) resultCollector.getResult();
+       
+       TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
+       final String errorPrefix = "ERROR: ";
+       for (CliFunctionResult gatewaySenderCreateResult : gatewaySenderCreateResults) {
+         boolean success  = gatewaySenderCreateResult.isSuccessful();
+         tabularResultData.accumulate("Member", gatewaySenderCreateResult.getMemberIdOrName());
+         tabularResultData.accumulate("Status", (success ? "" : errorPrefix) + gatewaySenderCreateResult.getMessage());
+         
+         if (success && xmlEntity == null) {
+           xmlEntity = gatewaySenderCreateResult.getXmlEntity();
+         }
+       }
+       result = ResultBuilder.buildResult(tabularResultData);
+     } catch (IllegalArgumentException e) {
+       LogWrapper.getInstance().info(e.getMessage());
+       result = ResultBuilder.createUserErrorResult(e.getMessage());
+     } catch (CommandResultException crex) {
+       result = handleCommandResultException(crex);
+     }
+     
+     if (xmlEntity != null) {
+       result.setCommandPersisted((new SharedConfigurationWriter()).addXmlEntity(xmlEntity, onGroups));
+     }
+     return result;
+   }
+ 
+   @CliCommand(value = CliStrings.START_GATEWAYSENDER, help = CliStrings.START_GATEWAYSENDER__HELP)
+   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEMFIRE_WAN)
++  @ResourceOperation( resource=Resource.GATEWAY_SENDER, operation=ResourceConstants.START_GW_SENDER)
+   public Result startGatewaySender(
+       @CliOption(key = CliStrings.START_GATEWAYSENDER__ID, 
+       mandatory = true, 
+       optionContext = ConverterHint.GATEWAY_SENDER_ID,
+       help = CliStrings.START_GATEWAYSENDER__ID__HELP) String senderId,
+       
+       @CliOption(key = CliStrings.START_GATEWAYSENDER__GROUP,
+       optionContext = ConverterHint.MEMBERGROUP,
+       help = CliStrings.START_GATEWAYSENDER__GROUP__HELP)
+       @CliMetaData (valueSeparator = ",") String onGroup,
+       
+       @CliOption(key = CliStrings.START_GATEWAYSENDER__MEMBER, 
+       optionContext = ConverterHint.MEMBERIDNAME,
+       help = CliStrings.START_GATEWAYSENDER__MEMBER__HELP) 
+       @CliMetaData (valueSeparator = ",") String onMember) {
+     
+     Result result = null;
+     final String id = senderId.trim();
+ 
+     try {
+       final Cache cache = CacheFactory.getAnyInstance();
+       final SystemManagementService service = (SystemManagementService)ManagementService
+           .getExistingManagementService(cache);
+ 
+       TabularResultData resultData = ResultBuilder.createTabularResultData();
+       Set<DistributedMember> dsMembers = CliUtil.findAllMatchingMembers(
+           onGroup, onMember);
+ 
+       ExecutorService execService = Executors
+           .newCachedThreadPool(new ThreadFactory() {
+             AtomicInteger threadNum = new AtomicInteger();
+ 
+             public Thread newThread(final Runnable r) {
+               Thread result = new Thread(r, "Start Sender Command Thread "
+                   + threadNum.incrementAndGet());
+               result.setDaemon(true);
+               return result;
+             }
+           });
+ 
+       List<Callable<List>> callables = new ArrayList<Callable<List>>();
+ 
+       for (final DistributedMember member : dsMembers) {
+         
+         callables.add(new Callable<List>() {
+           
+           public List call() throws Exception {
+             
+             GatewaySenderMXBean bean = null;
+             ArrayList<String> statusList = new ArrayList<String>();
+             if (cache.getDistributedSystem().getDistributedMember().getId()
+                 .equals(member.getId())) {
+               bean = service.getLocalGatewaySenderMXBean(id);
+             }
+             else {
+               ObjectName objectName = service.getGatewaySenderMBeanName(member,
+                   id);
+               bean = service.getMBeanProxy(objectName,
+                   GatewaySenderMXBean.class);
+             }
+             if (bean != null) {
+               if (bean.isRunning()) {
+                 statusList.add(member.getId());
+                 statusList.add(CliStrings.GATEWAY_ERROR);
+                 statusList.add(CliStrings.format(
+                     CliStrings.GATEWAY_SENDER_0_IS_ALREADY_STARTED_ON_MEMBER_1,
+                     new Object[] { id, member.getId() }));
+               }
+               else {
+                 bean.start();
+                 statusList.add(member.getId());
+                 statusList.add(CliStrings.GATEWAY_OK);
+                 statusList.add(CliStrings.format(
+                     CliStrings.GATEWAY_SENDER_0_IS_STARTED_ON_MEMBER_1,
+                     new Object[] { id, member.getId() }));
+               }
+             }
+             else {
+               statusList.add(member.getId());
+               statusList.add(CliStrings.GATEWAY_ERROR);
+               statusList.add(CliStrings.format(
+                   CliStrings.GATEWAY_SENDER_0_IS_NOT_AVAILABLE_ON_MEMBER_1,
+                   new Object[] { id, member.getId() }));
+             }
+             return statusList;
+           }
+         });
+       }
+       
+       Iterator<DistributedMember> memberIterator = dsMembers.iterator();
+       List<Future<List>> futures = null;
+       
+       try {
+         futures = execService.invokeAll(callables);
+       }
+       catch (InterruptedException ite) {
+         accumulateStartResult(resultData, null,
+             CliStrings.GATEWAY_ERROR, CliStrings.format(
+                 CliStrings.GATEWAY_SENDER_0_COULD_NOT_BE_INVOKED_DUE_TO_1,
+                 new Object[] { id, ite.getMessage() }));
+       }
+       
+       for (Future<List> future : futures) {
+         DistributedMember member = memberIterator.next();
+         List<String> memberStatus = null;
+         try {
+           memberStatus = future.get();
+           accumulateStartResult(resultData, memberStatus.get(0),
+               memberStatus.get(1), memberStatus.get(2));
+         }
+         catch (InterruptedException ite) {
+           accumulateStartResult(resultData, member.getId(),
+               CliStrings.GATEWAY_ERROR, CliStrings.format(
+                   CliStrings.GATEWAY_SENDER_0_COULD_NOT_BE_STARTED_ON_MEMBER_DUE_TO_1,
+                   new Object[] { id, ite.getMessage() }));
+           continue;
+         }
+         catch (ExecutionException ee) {
+           accumulateStartResult(resultData, member.getId(),
+               CliStrings.GATEWAY_ERROR, CliStrings.format(
+                   CliStrings.GATEWAY_SENDER_0_COULD_NOT_BE_STARTED_ON_MEMBER_DUE_TO_1,
+                   new Object[] { id, ee.getMessage() }));
+           continue;
+         }
+       }
+       execService.shutdown();
+       result = ResultBuilder.buildResult(resultData);
+     }
+     catch (CommandResultException crex) {
+       result = handleCommandResultException(crex);
+     } catch (Exception e) {
+       LogWrapper.getInstance().warning(
+           CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
+       result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR
+           + e.getMessage());
+     }
+     
+     return result;
+   }
+ 
+   @CliCommand(value = CliStrings.PAUSE_GATEWAYSENDER, help = CliStrings.PAUSE_GATEWAYSENDER__HELP)
+   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEMFIRE_WAN)
++  @ResourceOperation( resource=Resource.GATEWAY_SENDER, operation=ResourceConstants.PAUSE_GW_SENDER)
+   public Result pauseGatewaySender(
+       @CliOption(key = CliStrings.PAUSE_GATEWAYSENDER__ID, 
+       mandatory = true, 
+       optionContext = ConverterHint.GATEWAY_SENDER_ID,
+       help = CliStrings.PAUSE_GATEWAYSENDER__ID__HELP) String senderId,
+       
+       @CliOption(key = CliStrings.PAUSE_GATEWAYSENDER__GROUP,
+       optionContext = ConverterHint.MEMBERGROUP,
+       help = CliStrings.PAUSE_GATEWAYSENDER__GROUP__HELP) 
+       @CliMetaData (valueSeparator = ",")  String onGroup,
+       
+       @CliOption(key = CliStrings.PAUSE_GATEWAYSENDER__MEMBER, 
+       optionContext = ConverterHint.MEMBERIDNAME,
+       help = CliStrings.PAUSE_GATEWAYSENDER__MEMBER__HELP) 
+       @CliMetaData (valueSeparator = ",") String onMember) {
+     
+     Result result = null;
+     if (senderId != null)
+       senderId = senderId.trim();
+ //    if (memberNameOrId != null)
+ //      memberNameOrId = memberNameOrId.trim();
+ //
+ //    if (memberNameOrId != null && onGroup != null) {
+ //      return ResultBuilder
+ //          .createUserErrorResult(CliStrings.GATEWAY__MSG__OPTIONS);
+ //    }
+ 
+     try {
+       Cache cache = CacheFactory.getAnyInstance();
+       SystemManagementService service = (SystemManagementService) ManagementService
+           .getExistingManagementService(cache);
+ 
+       GatewaySenderMXBean bean = null;
+ 
+ 
+       TabularResultData resultData = ResultBuilder.createTabularResultData();
+       Set<DistributedMember> dsMembers = null;
+       
+       dsMembers = CliUtil.findAllMatchingMembers(onGroup, onMember);
+       for (DistributedMember member : dsMembers) {
+         if (cache.getDistributedSystem().getDistributedMember().getId().equals(
+             member.getId())) {
+           bean = service.getLocalGatewaySenderMXBean(senderId);
+         } else {
+           ObjectName objectName = service.getGatewaySenderMBeanName(member, senderId);
+           bean = service.getMBeanProxy(objectName, GatewaySenderMXBean.class);
+         }
+         if (bean != null) {
+           if (bean.isRunning()) {
+             if (bean.isPaused()) {
+               accumulateStartResult(
+                   resultData,
+                   member.getId(),
+                   CliStrings.GATEWAY_ERROR,
+                   CliStrings
+                       .format(
+                           CliStrings.GATEWAY_SENDER_0_IS_ALREADY_PAUSED_ON_MEMBER_1,
+                           new Object[] { senderId, member.getId() }));
+             } else {
+               bean.pause();
+               accumulateStartResult(resultData, member.getId(),
+                   CliStrings.GATEWAY_OK, CliStrings.format(
+                       CliStrings.GATEWAY_SENDER_0_IS_PAUSED_ON_MEMBER_1,
+                       new Object[] { senderId, member.getId() }));
+             }
+           } else {
+             accumulateStartResult(resultData, member.getId(),
+                 CliStrings.GATEWAY_ERROR, CliStrings.format(
+                     CliStrings.GATEWAY_SENDER_0_IS_NOT_RUNNING_ON_MEMBER_1,
+                     new Object[] { senderId, member.getId() }));
+           }
+         } else {
+           accumulateStartResult(resultData, member.getId(),
+               CliStrings.GATEWAY_ERROR, CliStrings.format(
+                   CliStrings.GATEWAY_SENDER_0_IS_NOT_AVAILABLE_ON_MEMBER_1,
+                   new Object[] { senderId, member.getId() }));
+         }
+       }
+       result = ResultBuilder.buildResult(resultData);
+     } catch (CommandResultException crex) {
+       result = handleCommandResultException(crex);
+     } catch (Exception e) {
+       LogWrapper.getInstance().warning(
+           CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
+       result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR
+           + e.getMessage());
+     }
+     return result;
+   }
+ 
+   @CliCommand(value = CliStrings.RESUME_GATEWAYSENDER, help = CliStrings.RESUME_GATEWAYSENDER__HELP)
+   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEMFIRE_WAN)
++  @ResourceOperation( resource=Resource.GATEWAY_SENDER, operation=ResourceConstants.RESUME_GW_SENDER)
+   public Result resumeGatewaySender(
+       @CliOption(key = CliStrings.RESUME_GATEWAYSENDER__ID, 
+       mandatory = true, 
+       optionContext = ConverterHint.GATEWAY_SENDER_ID,
+       help = CliStrings.RESUME_GATEWAYSENDER__ID__HELP) String senderId,
+       
+       @CliOption(key = CliStrings.RESUME_GATEWAYSENDER__GROUP,
+       optionContext = ConverterHint.MEMBERGROUP,
+       help = CliStrings.RESUME_GATEWAYSENDER__GROUP__HELP) 
+       @CliMetaData (valueSeparator = ",") String onGroup,
+       
+       @CliOption(key = CliStrings.RESUME_GATEWAYSENDER__MEMBER, 
+       optionContext = ConverterHint.MEMBERIDNAME,
+       help = CliStrings.RESUME_GATEWAYSENDER__MEMBER__HELP) 
+       @CliMetaData (valueSeparator = ",") String onMember) {
+     
+     Result result = null;
+     if (senderId != null)
+       senderId = senderId.trim();
+ //    if (memberNameOrId != null)
+ //      memberNameOrId = memberNameOrId.trim();
+ //
+ //    if (memberNameOrId != null && onGroup != null) {
+ //      return ResultBuilder
+ //          .createUserErrorResult(CliStrings.GATEWAY__MSG__OPTIONS);
+ //    }
+ 
+     try {
+       Cache cache = CacheFactory.getAnyInstance();
+       SystemManagementService service = (SystemManagementService) ManagementService
+           .getExistingManagementService(cache);
+ 
+ 
+       GatewaySenderMXBean bean = null;
+ //
+ //      if (memberNameOrId != null && memberNameOrId.length() > 0) {
+ //        InfoResultData resultData = ResultBuilder.createInfoResultData();
+ //        DistributedMember memberToBeInvoked = CliUtil
+ //            .getDistributedMemberByNameOrId(memberNameOrId);
+ //
+ //        if (memberToBeInvoked != null) {
+ //          String memberId = memberToBeInvoked.getId();
+ //          if (cache.getDistributedSystem().getDistributedMember().getId()
+ //              .equals(memberId)) {
+ //            bean = service.getLocalGatewaySenderMXBean(senderId);
+ //          } else {
+ //            ObjectName objectName = service.getGatewaySenderMBeanName(memberToBeInvoked,
+ //                senderId);
+ //            bean = service.getMBeanProxy(objectName, GatewaySenderMXBean.class);
+ //          }
+ //          if (bean != null) {
+ //            if (bean.isRunning()) {
+ //              if (bean.isPaused()) {
+ //                bean.resume();
+ //                resultData.addLine(CliStrings.format(
+ //                    CliStrings.GATEWAY_SENDER_0_IS_RESUMED_ON_MEMBER_1,
+ //                    new Object[] { senderId, memberId }));
+ //                return ResultBuilder.buildResult(resultData);
+ //              }
+ //              resultData.addLine(CliStrings.format(
+ //                  CliStrings.GATEWAY_SENDER_0_IS_NOT_PAUSED_ON_MEMBER_1,
+ //                  new Object[] { senderId, memberId }));
+ //              return ResultBuilder.buildResult(resultData);
+ //            }
+ //            resultData.addLine(CliStrings.format(
+ //                CliStrings.GATEWAY_SENDER_0_IS_NOT_RUNNING_ON_MEMBER_1,
+ //                new Object[] { senderId, memberId }));
+ //            return ResultBuilder.buildResult(resultData);
+ //          }
+ //          return ResultBuilder.createBadConfigurationErrorResult(CliStrings
+ //              .format(CliStrings.GATEWAY_SENDER_0_IS_NOT_AVAILABLE_ON_MEMBER_1,
+ //                  new Object[] { senderId, memberId }));
+ //        }
+ //        return ResultBuilder.createUserErrorResult(CliStrings.format(
+ //            CliStrings.GATEWAY_MSG_MEMBER_0_NOT_FOUND,
+ //            new Object[] { memberNameOrId }));
+ //      }
+ 
+       TabularResultData resultData = ResultBuilder.createTabularResultData();
+       Set<DistributedMember> dsMembers = null;
+ //      if (onGroup != null && onGroup.length > 0) {
+ //        dsMembers = CliUtil.getDistributedMembersByGroup(cache, onGroup);
+ //      } else {
+ //        dsMembers = CliUtil.getAllNormalMembers(cache);
+ //      }
+ //      if (dsMembers.isEmpty()) {
+ //        return ResultBuilder
+ //            .createUserErrorResult(CliStrings.GATEWAY_MSG_MEMBERS_NOT_FOUND);
+ //      }
+       dsMembers = CliUtil.findAllMatchingMembers(onGroup, onMember);
+       for (DistributedMember member : dsMembers) {
+         if (cache.getDistributedSystem().getDistributedMember().getId().equals(
+             member.getId())) {
+           bean = service.getLocalGatewaySenderMXBean(senderId);
+         } else {
+           ObjectName objectName = service.getGatewaySenderMBeanName(member, senderId);
+           bean = service.getMBeanProxy(objectName, GatewaySenderMXBean.class);
+         }
+         if (bean != null) {
+           if (bean.isRunning()) {
+             if (bean.isPaused()) {
+               bean.resume();
+               accumulateStartResult(resultData, member.getId(),
+                   CliStrings.GATEWAY_OK, CliStrings.format(
+                       CliStrings.GATEWAY_SENDER_0_IS_RESUMED_ON_MEMBER_1,
+                       new Object[] { senderId, member.getId() }));
+             } else {
+               accumulateStartResult(resultData, member.getId(),
+                   CliStrings.GATEWAY_ERROR, CliStrings.format(
+                       CliStrings.GATEWAY_SENDER_0_IS_NOT_PAUSED_ON_MEMBER_1,
+                       new Object[] { senderId, member.getId() }));
+             }
+           } else {
+             accumulateStartResult(resultData, member.getId(),
+                 CliStrings.GATEWAY_ERROR, CliStrings.format(
+                     CliStrings.GATEWAY_SENDER_0_IS_NOT_RUNNING_ON_MEMBER_1,
+                     new Object[] { senderId, member.getId() }));
+           }
+         } else {
+           accumulateStartResult(resultData, member.getId(),
+               CliStrings.GATEWAY_ERROR, CliStrings.format(
+                   CliStrings.GATEWAY_SENDER_0_IS_NOT_AVAILABLE_ON_MEMBER_1,
+                   new Object[] { senderId, member.getId() }));
+         }
+       }
+       result = ResultBuilder.buildResult(resultData);
+     } catch (CommandResultException crex) {
+       result = handleCommandResultException(crex);
+     } catch (Exception e) {
+       LogWrapper.getInstance().warning(
+           CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
+       result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR
+           + e.getMessage());
+     }
+     return result;
+   }
+ 
+   @CliCommand(value = CliStrings.STOP_GATEWAYSENDER, help = CliStrings.STOP_GATEWAYSENDER__HELP)
+   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEMFIRE_WAN)
++  @ResourceOperation( resource=Resource.GATEWAY_SENDER, operation=ResourceConstants.STOP_GW_SENDER)
+   public Result stopGatewaySender(
+       @CliOption(key = CliStrings.STOP_GATEWAYSENDER__ID, 
+       mandatory = true, 
+       optionContext = ConverterHint.GATEWAY_SENDER_ID,
+       help = CliStrings.STOP_GATEWAYSENDER__ID__HELP) String senderId,
+       
+       @CliOption(key = CliStrings.STOP_GATEWAYSENDER__GROUP,
+       optionContext = ConverterHint.MEMBERGROUP,
+       help = CliStrings.STOP_GATEWAYSENDER__GROUP__HELP)
+       @CliMetaData (valueSeparator = ",") String onGroup,
+       
+       @CliOption(key = CliStrings.STOP_GATEWAYSENDER__MEMBER, 
+       optionContext = ConverterHint.MEMBERIDNAME,
+       help = CliStrings.STOP_GATEWAYSENDER__MEMBER__HELP) 
+       @CliMetaData (valueSeparator = ",") String onMember) {
+     
+     Result result = null;
+     if (senderId != null)
+       senderId = senderId.trim();
+    
+     try {
+       Cache cache = CacheFactory.getAnyInstance();
+       SystemManagementService service = (SystemManagementService) ManagementService
+           .getExistingManagementService(cache);
+ 
+ 
+       GatewaySenderMXBean bean = null;
+ 
+ 
+       TabularResultData resultData = ResultBuilder.createTabularResultData();
+       Set<DistributedMember> dsMembers = CliUtil.findAllMatchingMembers(onGroup, onMember);
+ 
+       for (DistributedMember member : dsMembers) {
+         if (cache.getDistributedSystem().getDistributedMember().getId().equals(
+             member.getId())) {
+           bean = service.getLocalGatewaySenderMXBean(senderId);
+         } else {
+           ObjectName objectName = service.getGatewaySenderMBeanName(member, senderId);
+           bean = service.getMBeanProxy(objectName, GatewaySenderMXBean.class);
+         }
+         if (bean != null) {
+           if (bean.isRunning()) {
+             bean.stop();
+             accumulateStartResult(resultData, member.getId(),
+                 CliStrings.GATEWAY_OK, CliStrings.format(
+                     CliStrings.GATEWAY_SENDER_0_IS_STOPPED_ON_MEMBER_1,
+                     new Object[] { senderId, member.getId() }));
+ 
+           } else {
+             accumulateStartResult(resultData, member.getId(),
+                 CliStrings.GATEWAY_ERROR, CliStrings.format(
+                     CliStrings.GATEWAY_SENDER_0_IS_NOT_RUNNING_ON_MEMBER_1,
+                     new Object[] { senderId, member.getId() }));
+           }
+         } else {
+           accumulateStartResult(resultData, member.getId(),
+               CliStrings.GATEWAY_ERROR, CliStrings.format(
+                   CliStrings.GATEWAY_SENDER_0_IS_NOT_AVAILABLE_ON_MEMBER_1,
+                   new Object[] { senderId, member.getId() }));
+         }
+       }
+       result = ResultBuilder.buildResult(resultData);
+     } catch (CommandResultException crex) {
+       result = handleCommandResultException(crex);
+     } catch (Exception e) {
+       LogWrapper.getInstance().warning(
+           CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
+       result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR
+           + e.getMessage());
+     }
+     return result;
+   }
+   
+   @CliCommand(value = CliStrings.CREATE_GATEWAYRECEIVER, help = CliStrings.CREATE_GATEWAYRECEIVER__HELP)
+   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEMFIRE_WAN)
++  @ResourceOperation( resource=Resource.DISTRIBUTED_SYSTEM, operation=ResourceConstants.CREATE_GW_RECEIVER)
+   public Result createGatewayReceiver(
+       @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__GROUP,
+       optionContext = ConverterHint.MEMBERGROUP,
+       help = CliStrings.CREATE_GATEWAYRECEIVER__GROUP__HELP)
+       @CliMetaData (valueSeparator = ",") String[] onGroups,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__MEMBER, 
+       optionContext = ConverterHint.MEMBERIDNAME,
+       unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
+       help = CliStrings.CREATE_GATEWAYRECEIVER__MEMBER__HELP) 
+       @CliMetaData (valueSeparator = ",") String onMember,
+           
+       @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__MANUALSTART, 
+       help = CliStrings.CREATE_GATEWAYRECEIVER__MANUALSTART__HELP) Boolean manualStart,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__STARTPORT, 
+       help = CliStrings.CREATE_GATEWAYRECEIVER__STARTPORT__HELP) Integer startPort,
+ 
+       @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__ENDPORT, 
+       help = CliStrings.CREATE_GATEWAYRECEIVER__ENDPORT__HELP) Integer endPort,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__BINDADDRESS, 
+       help = CliStrings.CREATE_GATEWAYRECEIVER__BINDADDRESS__HELP) String bindAddress,
+ 
+       @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__MAXTIMEBETWEENPINGS, 
+       help = CliStrings.CREATE_GATEWAYRECEIVER__MAXTIMEBETWEENPINGS__HELP) Integer maximumTimeBetweenPings,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__SOCKETBUFFERSIZE, 
+       help = CliStrings.CREATE_GATEWAYRECEIVER__SOCKETBUFFERSIZE__HELP) Integer socketBufferSize,
+       
+       @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__GATEWAYTRANSPORTFILTER, 
+       help = CliStrings.CREATE_GATEWAYRECEIVER__GATEWAYTRANSPORTFILTER__HELP)
+       @CliMetaData (valueSeparator = ",") 
+       String[] gatewayTransportFilters) {
+ 
+     Result result = null;
+ 
+     XmlEntity xmlEntity = null;
+     try {
+       GatewayReceiverFunctionArgs gatewayReceiverFunctionArgs = new GatewayReceiverFunctionArgs(manualStart, startPort, endPort, bindAddress,
+           socketBufferSize, maximumTimeBetweenPings, gatewayTransportFilters);
+ 
+       Set<DistributedMember> membersToCreateGatewayReceiverOn = CliUtil.findAllMatchingMembers(onGroups, onMember == null ? null : onMember.split(","));
+ 
+       ResultCollector<?, ?> resultCollector = CliUtil.executeFunction(GatewayReceiverCreateFunction.INSTANCE,
+           gatewayReceiverFunctionArgs, membersToCreateGatewayReceiverOn);
+       @SuppressWarnings("unchecked")
+       List<CliFunctionResult> gatewayReceiverCreateResults = (List<CliFunctionResult>) resultCollector.getResult();
+ 
+       TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
+       final String errorPrefix = "ERROR: ";
+ 
+       for (CliFunctionResult gatewayReceiverCreateResult : gatewayReceiverCreateResults) {
+         boolean success = gatewayReceiverCreateResult.isSuccessful();
+         tabularResultData.accumulate("Member", gatewayReceiverCreateResult.getMemberIdOrName());
+         tabularResultData.accumulate("Status", (success ? "" : errorPrefix) + gatewayReceiverCreateResult.getMessage());
+         
+         if (success && xmlEntity == null) {
+           xmlEntity = gatewayReceiverCreateResult.getXmlEntity();
+         }
+       }
+       result = ResultBuilder.buildResult(tabularResultData);
+     } catch (IllegalArgumentException e) {
+       LogWrapper.getInstance().info(e.getMessage());
+       result = ResultBuilder.createUserErrorResult(e.getMessage());
+     }
+     catch (CommandResultException crex) {
+       result = handleCommandResultException(crex);
+     }
+     
+     if (xmlEntity != null) {
+       result.setCommandPersisted((new SharedConfigurationWriter()).addXmlEntity(xmlEntity, onGroups));
+     }
+     
+     return result;
+   }
+ 
+   @CliCommand(value = CliStrings.LOAD_BALANCE_GATEWAYSENDER, help = CliStrings.LOAD_BALANCE_GATEWAYSENDER__HELP)
+   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEMFIRE_WAN)
++  @ResourceOperation( resource=Resource.DISTRIBUTED_SYSTEM, operation=ResourceConstants.LOAD_BALANCE_GW_SENDER)
+   public Result loadBalanceGatewaySender(
+       @CliOption(key = CliStrings.LOAD_BALANCE_GATEWAYSENDER__ID, 
+       mandatory = true, 
+       optionContext = ConverterHint.GATEWAY_SENDER_ID,
+       help = CliStrings.LOAD_BALANCE_GATEWAYSENDER__ID__HELP) String senderId) {
+     
+     Result result = null;
+     if (senderId != null) {
+       senderId = senderId.trim();
+     }
+ 
+     try {
+       Cache cache = CacheFactory.getAnyInstance();
+       SystemManagementService service = (SystemManagementService) ManagementService
+           .getExistingManagementService(cache);
+       TabularResultData resultData = ResultBuilder.createTabularResultData();
+       Set<DistributedMember> dsMembers = CliUtil.getAllNormalMembers(cache);
+ 
+       if (dsMembers.isEmpty()) {
+         result = ResultBuilder.createInfoResult(CliStrings.GATEWAY_MSG_MEMBERS_NOT_FOUND);
+       } else {
+         boolean gatewaySenderExists = false;
+         for (DistributedMember member : dsMembers) {
+           GatewaySenderMXBean bean = null;
+           if (cache.getDistributedSystem().getDistributedMember().getId().equals(
+               member.getId())) {
+             bean = service.getLocalGatewaySenderMXBean(senderId);
+           } else {
+             ObjectName objectName = service.getGatewaySenderMBeanName(member, senderId);
+             bean = service.getMBeanProxy(objectName, GatewaySenderMXBean.class);
+           }
+           if (bean != null) {
+             gatewaySenderExists = true;
+             bean.rebalance();
+             accumulateStartResult(resultData, member.getId(),
+                 CliStrings.GATEWAY_OK, CliStrings.format(
+                     CliStrings.GATEWAY_SENDER_0_IS_REBALANCED_ON_MEMBER_1,
+                     new Object[] { senderId, member.getId() }));
+           } else {
+             accumulateStartResult(resultData, member.getId(),
+                 CliStrings.GATEWAY_ERROR, CliStrings.format(
+                     CliStrings.GATEWAY_SENDER_0_IS_NOT_AVAILABLE_ON_MEMBER_1,
+                     new Object[] { senderId, member.getId() }));
+           }
+         }
+         if (gatewaySenderExists) {
+           result = ResultBuilder.buildResult(resultData);
+         } else {
+           result = ResultBuilder.createInfoResult(CliStrings.format(
+               CliStrings.GATEWAY_SENDER_0_IS_NOT_FOUND_ON_ANY_MEMBER,
+               new Object[] { senderId }));
+         }
+       }
+     } catch (Exception e) {
+       LogWrapper.getInstance().warning(
+           CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
+       result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR
+           + e.getMessage());
+     }
+ 
+     return result;
+   }
+ 
+   @CliCommand(value = CliStrings.START_GATEWAYRECEIVER, help = CliStrings.START_GATEWAYRECEIVER__HELP)
+   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEMFIRE_WAN)
++  @ResourceOperation( resource=Resource.GATEWAY_RECEIVER, operation=ResourceConstants.START_GW_RECEIVER)
+   public Result startGatewayReceiver(
+       @CliOption(key = CliStrings.START_GATEWAYRECEIVER__GROUP,
+       optionContext = ConverterHint.MEMBERGROUP,
+       help = CliStrings.START_GATEWAYRECEIVER__GROUP__HELP) 
+       @CliMetaData (valueSeparator = ",")  String onGroup,
+       
+       @CliOption(key = CliStrings.START_GATEWAYRECEIVER__MEMBER, 
+       optionContext = ConverterHint.MEMBERIDNAME,
+       help = CliStrings.START_GATEWAYRECEIVER__MEMBER__HELP) 
+       @CliMetaData (valueSeparator = ",") String onMember) {
+     Result result = null;
+ 
+ 
+     try {
+       Cache cache = CacheFactory.getAnyInstance();
+       SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
+ 
+       GatewayReceiverMXBean receieverBean = null;
+ 
+       TabularResultData resultData = ResultBuilder.createTabularResultData();
+       Set<DistributedMember> dsMembers = CliUtil.findAllMatchingMembers(onGroup, onMember);
+ 
+       for (DistributedMember member : dsMembers) {
+         ObjectName gatewayReceiverObjectName = MBeanJMXAdapter.getGatewayReceiverMBeanName(member);
+ 
+         if (gatewayReceiverObjectName != null) {
+           receieverBean = service.getMBeanProxy(gatewayReceiverObjectName, GatewayReceiverMXBean.class);
+           if (receieverBean != null) {
+             if (receieverBean.isRunning()) {
+               accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(
+                   CliStrings.GATEWAY_RECEIVER_IS_ALREADY_STARTED_ON_MEMBER_0, new Object[] { member.getId() }));
+             } else {
+               receieverBean.start();
+               accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_OK, CliStrings.format(
+                   CliStrings.GATEWAY_RECEIVER_IS_STARTED_ON_MEMBER_0, new Object[] { member.getId() }));
+             }
+           } else {
+             accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(
+                 CliStrings.GATEWAY_RECEIVER_IS_NOT_AVAILABLE_ON_MEMBER_0, new Object[] { member.getId() }));
+           }
+         } else {
+           accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(
+               CliStrings.GATEWAY_RECEIVER_IS_NOT_AVAILABLE_ON_MEMBER_0, new Object[] { member.getId() }));
+         }
+       }
+       result = ResultBuilder.buildResult(resultData);
+     }
+     catch (CommandResultException crex) {
+       result = handleCommandResultException(crex);
+     }
+     catch (Exception e) {
+       LogWrapper.getInstance().warning(
+           CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
+       result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR
+           + e.getMessage());
+     }
+     return result;
+   }
+ 
+   @CliCommand(value = CliStrings.STOP_GATEWAYRECEIVER, help = CliStrings.STOP_GATEWAYRECEIVER__HELP)
+   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEMFIRE_WAN)
++  @ResourceOperation( resource=Resource.GATEWAY_RECEIVER, operation=ResourceConstants.STOP_GW_RECEIVER)
+   public Result stopGatewayReceiver(
+       
+       @CliOption(key = CliStrings.STOP_GATEWAYRECEIVER__GROUP, 
+       optionContext = ConverterHint.MEMBERGROUP,
+       help = CliStrings.STOP_GATEWAYRECEIVER__GROUP__HELP) 
+       @CliMetaData (valueSeparator = ",") String onGroup,
+       
+       @CliOption(key = CliStrings.STOP_GATEWAYRECEIVER__MEMBER, 
+       optionContext = ConverterHint.MEMBERIDNAME,
+       help = CliStrings.STOP_GATEWAYRECEIVER__MEMBER__HELP) 
+       @CliMetaData (valueSeparator = ",") String onMember) {
+     
+     Result result = null;
+ 
+     try {
+       Cache cache = CacheFactory.getAnyInstance();
+       SystemManagementService service = (SystemManagementService) ManagementService
+           .getExistingManagementService(cache);
+ 
+ 
+       GatewayReceiverMXBean receieverBean = null;
+ 
+ 
+       TabularResultData resultData = ResultBuilder.createTabularResultData();
+       Set<DistributedMember> dsMembers = CliUtil.findAllMatchingMembers(onGroup, onMember);
+ 
+       for (DistributedMember member : dsMembers) {
+         ObjectName gatewayReceiverObjectName = MBeanJMXAdapter
+             .getGatewayReceiverMBeanName(member);
+ 
+         if (gatewayReceiverObjectName != null) {
+           receieverBean = service.getMBeanProxy(gatewayReceiverObjectName,
+               GatewayReceiverMXBean.class);
+           if (receieverBean != null) {
+             if (receieverBean.isRunning()) {
+               receieverBean.stop();
+               accumulateStartResult(resultData, member.getId(),
+                   CliStrings.GATEWAY_OK, CliStrings.format(
+                       CliStrings.GATEWAY_RECEIVER_IS_STOPPED_ON_MEMBER_0,
+                       new Object[] { member.getId() }));
+             } else {
+               accumulateStartResult(resultData, member.getId(),
+                   CliStrings.GATEWAY_ERROR, CliStrings.format(
+                       CliStrings.GATEWAY_RECEIVER_IS_NOT_RUNNING_ON_MEMBER_0,
+                       new Object[] { member.getId() }));
+             }
+           } else {
+             accumulateStartResult(resultData, member.getId(),
+                 CliStrings.GATEWAY_ERROR, CliStrings.format(
+                     CliStrings.GATEWAY_RECEIVER_IS_NOT_AVAILABLE_ON_MEMBER_0,
+                     new Object[] { member.getId() }));
+           }
+         } else {
+           accumulateStartResult(resultData, member.getId(),
+               CliStrings.GATEWAY_ERROR, CliStrings.format(
+                   CliStrings.GATEWAY_RECEIVER_IS_NOT_AVAILABLE_ON_MEMBER_0,
+                   new Object[] { member.getId() }));
+         }
+       }
+       result = ResultBuilder.buildResult(resultData);
+     } catch (CommandResultException crex) {
+       result = handleCommandResultException(crex);
+     } catch (Exception e) {
+       LogWrapper.getInstance().warning(
+           CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
+       result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR
+           + e.getMessage());
+     }
+     return result;
+   }
+ 
+   @CliCommand(value = CliStrings.LIST_GATEWAY, help = CliStrings.LIST_GATEWAY__HELP)
+   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEMFIRE_WAN)
++  @ResourceOperation( resource=Resource.DISTRIBUTED_SYSTEM, operation=ResourceConstants.LIST_DS)
+   public Result listGateway(
+       @CliOption(key = CliStrings.LIST_GATEWAY__MEMBER,
+       optionContext = ConverterHint.MEMBERIDNAME,
+       help = CliStrings.LIST_GATEWAY__MEMBER__HELP)
+       @CliMetaData (valueSeparator = ",") String onMember,
+       @CliOption(key = CliStrings.LIST_GATEWAY__GROUP,
+       optionContext = ConverterHint.MEMBERGROUP,
+       help = CliStrings.LIST_GATEWAY__GROUP__HELP) 
+       @CliMetaData (valueSeparator = ",") String onGroup) {
+     
+     Result result = null;
+     Cache cache = CacheFactory.getAnyInstance();
+     try {
+       SystemManagementService service = (SystemManagementService) ManagementService
+           .getExistingManagementService(cache);
+ 
+       Set<DistributedMember> dsMembers = null;
+ //      if (onGroup != null && onGroup.length > 0) {
+ //        dsMembers = CliUtil.getDistributedMembersByGroup(cache, onGroup);
+ //      } else {
+ //        dsMembers = CliUtil.getAllNormalMembers(cache);
+ //      }
+ //      if (dsMembers.isEmpty()) {
+ //        return ResultBuilder
+ //            .createUserErrorResult(CliStrings.GATEWAY_MSG_MEMBERS_NOT_FOUND);
+ //      }
+       dsMembers = CliUtil.findAllMatchingMembers(onGroup, onMember);
+ 
+       Map<String, Map<String, GatewaySenderMXBean>> gatewaySenderBeans = new TreeMap<String, Map<String, GatewaySenderMXBean>>();
+       Map<String, GatewayReceiverMXBean> gatewayReceiverBeans = new TreeMap<String, GatewayReceiverMXBean>();
+ 
+       DistributedSystemMXBean dsMXBean = service.getDistributedSystemMXBean();
+       for (DistributedMember member : dsMembers) {
+         String memberName = member.getName();
+         String memberNameOrId = (memberName != null  && !memberName.isEmpty())? memberName : member.getId();
+         ObjectName gatewaySenderObjectNames[] = dsMXBean
+             .listGatewaySenderObjectNames(memberNameOrId);
+         // gateway senders : a member can have multiple gateway sendersdefined
+         // on it
+         if (gatewaySenderObjectNames != null) {
+           for (ObjectName name : gatewaySenderObjectNames) {
+             GatewaySenderMXBean senderBean = service.getMBeanProxy(name,
+                 GatewaySenderMXBean.class);
+             if (senderBean != null) {
+               if (gatewaySenderBeans.containsKey(senderBean.getSenderId())) {
+                 Map<String, GatewaySenderMXBean> memberToBeanMap = gatewaySenderBeans
+                     .get(senderBean.getSenderId());
+                 memberToBeanMap.put(member.getId(), senderBean);
+               } else {
+                 Map<String, GatewaySenderMXBean> memberToBeanMap = new TreeMap<String, GatewaySenderMXBean>();
+                 memberToBeanMap.put(member.getId(), senderBean);
+                 gatewaySenderBeans.put(senderBean.getSenderId(),
+                     memberToBeanMap);
+               }
+             }
+           }
+         }
+         // gateway receivers : a member can have only one gateway receiver
+         ObjectName gatewayReceiverObjectName = MBeanJMXAdapter
+             .getGatewayReceiverMBeanName(member);
+         if (gatewayReceiverObjectName != null) {
+           GatewayReceiverMXBean receieverBean = null;
+           receieverBean = service.getMBeanProxy(gatewayReceiverObjectName,
+               GatewayReceiverMXBean.class);
+           if (receieverBean != null) {
+             gatewayReceiverBeans.put(member.getId(), receieverBean);
+           }
+         }
+       }
+       if (gatewaySenderBeans.isEmpty() && gatewayReceiverBeans.isEmpty()) {
+         return ResultBuilder
+             .createUserErrorResult(CliStrings.GATEWAYS_ARE_NOT_AVAILABLE_IN_CLUSTER);
+       }
+       CompositeResultData crd = ResultBuilder.createCompositeResultData();
+       crd.setHeader(CliStrings.HEADER_GATEWAYS);
+       accumulateListGatewayResult(crd, gatewaySenderBeans, gatewayReceiverBeans);
+       result = ResultBuilder.buildResult(crd);
+     } catch (CommandResultException crex) {
+       result = handleCommandResultException(crex);
+     } catch (Exception e) {
+       LogWrapper.getInstance().warning(
+           CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
+       result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR
+           + e.getMessage());
+     }
+     return result;
+   }
+ 
+   @CliCommand(value = CliStrings.STATUS_GATEWAYSENDER, help = CliStrings.STATUS_GATEWAYSENDER__HELP)
+   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEMFIRE_WAN)
++  @ResourceOperation( resource=Resource.DISTRIBUTED_SYSTEM, operation=ResourceConstants.LIST_DS)
+   public Result statusGatewaySender(
+       @CliOption(key = CliStrings.STATUS_GATEWAYSENDER__ID, 
+       mandatory = true, 
+       optionContext = ConverterHint.GATEWAY_SENDER_ID,
+       help = CliStrings.STATUS_GATEWAYSENDER__ID__HELP) String senderId,
+       
+       @CliOption(key = CliStrings.STATUS_GATEWAYSENDER__GROUP,
+       optionContext = ConverterHint.MEMBERGROUP,
+       help = CliStrings.STATUS_GATEWAYSENDER__GROUP__HELP) 
+       @CliMetaData (valueSeparator = ",") String onGroup,
+       
+       @CliOption(key = CliStrings.STATUS_GATEWAYSENDER__MEMBER, 
+       optionContext = ConverterHint.MEMBERIDNAME,
+       help = CliStrings.STATUS_GATEWAYSENDER__MEMBER__HELP)
+       @CliMetaData (valueSeparator = ",") String onMember) {
+     
+     Result result = null;
+     if (senderId != null)
+       senderId = senderId.trim();
+     try {
+       Cache cache = CacheFactory.getAnyInstance();
+       SystemManagementService service = (SystemManagementService) ManagementService
+           .getExistingManagementService(cache);
+ 
+       GatewaySenderMXBean bean = null;
+ 
+ 
+       CompositeResultData crd = ResultBuilder.createCompositeResultData();
+       TabularResultData availableSenderData = crd.addSection(
+           CliStrings.SECTION_GATEWAY_SENDER_AVAILABLE).addTable(
+           CliStrings.TABLE_GATEWAY_SENDER);
+ 
+       TabularResultData notAvailableSenderData = crd.addSection(
+           CliStrings.SECTION_GATEWAY_SENDER_NOT_AVAILABLE).addTable(
+           CliStrings.TABLE_GATEWAY_SENDER);
+ 
+       Set<DistributedMember> dsMembers = null;
+       dsMembers = CliUtil.findAllMatchingMembers(onGroup, onMember);
+       for (DistributedMember member : dsMembers) {
+         if (cache.getDistributedSystem().getDistributedMember().getId().equals(
+             member.getId())) {
+           bean = service.getLocalGatewaySenderMXBean(senderId);
+         } else {
+           ObjectName objectName = service.getGatewaySenderMBeanName(member, senderId);
+           bean = service.getMBeanProxy(objectName, GatewaySenderMXBean.class);
+         }
+         if (bean != null) {
+           buildSenderStatus(member.getId(), bean, availableSenderData);
+         } else {
+           buildSenderStatus(member.getId(), bean, notAvailableSenderData);
+         }
+       }
+       result = ResultBuilder.buildResult(crd);
+     } catch (CommandResultException crex) {
+       result = handleCommandResultException(crex);
+     } catch (Exception e) {
+       LogWrapper.getInstance().warning(
+           CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
+       result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR
+           + e.getMessage());
+     }
+     return result;
+   }
+ 
+   @CliCommand(value = CliStrings.STATUS_GATEWAYRECEIVER, help = CliStrings.STATUS_GATEWAYRECEIVER__HELP)
+   @CliMetaData(relatedTopic = CliStrings.TOPIC_GEMFIRE_WAN)
++  @ResourceOperation( resource=Resource.DISTRIBUTED_SYSTEM, operation=ResourceConstants.LIST_DS)
+   public Result statusGatewayReceiver(
+       @CliOption(key = CliStrings.STATUS_GATEWAYRECEIVER__GROUP, 
+       optionContext = ConverterHint.MEMBERGROUP,
+       help = CliStrings.STATUS_GATEWAYRECEIVER__GROUP__HELP)
+       @CliMetaData (valueSeparator = ",")  String onGroup,
+       
+       @CliOption(key = CliStrings.STATUS_GATEWAYRECEIVER__MEMBER, 
+       optionContext = ConverterHint.MEMBERIDNAME,
+       help = CliStrings.STATUS_GATEWAYRECEIVER__MEMBER__HELP) 
+       @CliMetaData (valueSeparator = ",") String onMember) {
+     
+     Result result = null;
+ 
+     try {
+       Cache cache = CacheFactory.getAnyInstance();
+       SystemManagementService service = (SystemManagementService) ManagementService
+           .getExistingManagementService(cache);
+ 
+ 
+       CompositeResultData crd = ResultBuilder.createCompositeResultData();
+       TabularResultData availableReceiverData = crd.addSection(
+           CliStrings.SECTION_GATEWAY_RECEIVER_AVAILABLE).addTable(
+           CliStrings.TABLE_GATEWAY_RECEIVER);
+ 
+       TabularResultData notAvailableReceiverData = crd.addSection(
+           CliStrings.SECTION_GATEWAY_RECEIVER_NOT_AVAILABLE).addTable(
+           CliStrings.TABLE_GATEWAY_RECEIVER);
+ 
+       Set<DistributedMember> dsMembers = CliUtil.findAllMatchingMembers(onGroup, onMember);
+ 
+       for (DistributedMember member : dsMembers) {
+         ObjectName gatewayReceiverObjectName = MBeanJMXAdapter
+             .getGatewayReceiverMBeanName(member);
+         if (gatewayReceiverObjectName != null) {
+           GatewayReceiverMXBean receieverBean = service.getMBeanProxy(
+               gatewayReceiverObjectName, GatewayReceiverMXBean.class);
+           if (receieverBean != null) {
+             buildReceiverStatus(member.getId(), receieverBean, availableReceiverData);
+             continue;
+           }
+         }
+         buildReceiverStatus(member.getId(), null, notAvailableReceiverData);
+       }
+       result = ResultBuilder.buildResult(crd);
+     } catch (CommandResultException crex) {
+       result = handleCommandResultException(crex);
+     } catch (Exception e) {
+       LogWrapper.getInstance().warning(
+           CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
+       result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR
+           + e.getMessage());
+     }
+     return result;
+   }
+ 
+   private TabularResultData buildReceiverStatus(String memberId,
+       GatewayReceiverMXBean bean, TabularResultData resultData) {
+     resultData.accumulate(CliStrings.RESULT_HOST_MEMBER, memberId);
+     if (bean != null) {
+       resultData.accumulate(CliStrings.RESULT_PORT, bean.getPort());
+       resultData.accumulate(CliStrings.RESULT_STATUS,
+           bean.isRunning() ? CliStrings.GATEWAY_RUNNING
+               : CliStrings.GATEWAY_NOT_RUNNING);
+     } else {
+       resultData.accumulate(CliStrings.GATEWAY_ERROR,
+           CliStrings.GATEWAY_RECEIVER_IS_NOT_AVAILABLE_OR_STOPPED);
+     }
+     return resultData;
+   }
+ 
+   private TabularResultData buildSenderStatus(String memberId,
+       GatewaySenderMXBean bean, TabularResultData resultData) {
+     resultData.accumulate(CliStrings.RESULT_HOST_MEMBER, memberId);
+     if (bean != null) {
+       resultData.accumulate(CliStrings.RESULT_TYPE,
+           bean.isParallel() ? CliStrings.SENDER_PARALLEL
+               : CliStrings.SENDER_SERIAL);
+       if (!bean.isParallel()) {
+         resultData.accumulate(CliStrings.RESULT_POLICY,
+             bean.isPrimary() ? CliStrings.SENDER_PRIMARY
+                 : CliStrings.SENDER_SECONADRY);
+       }
+       if (bean.isRunning()) {
+         if (bean.isPaused()) {
+           resultData.accumulate(CliStrings.RESULT_STATUS,
+               CliStrings.SENDER_PAUSED);
+         } else {
+           resultData.accumulate(CliStrings.RESULT_STATUS,
+               CliStrings.GATEWAY_RUNNING);
+         }
+       } else {
+         resultData.accumulate(CliStrings.RESULT_STATUS,
+             CliStrings.GATEWAY_NOT_RUNNING);
+       }
+     } else {
+       resultData.accumulate(CliStrings.GATEWAY_ERROR,
+           CliStrings.GATEWAY_SENDER_IS_NOT_AVAILABLE);
+     }
+ 
+     return resultData;
+   }
+ 
+   // CliStrings.format(
+   // CliStrings.GATEWAY_SENDER_0_IS_STARTED_ON_MEMBER_1,
+   // new Object[] {senderId, memberId });
+   //  
+   // CliStrings.format(
+   // CliStrings.GATEWAY_SENDER_0_IS_ALREADY_STARTED_ON_MEMBER_1,
+   // new Object[] {senderId, memberId });
+   //  
+   // CliStrings.format(
+   // CliStrings.GATEWAY_SENDER_0_IS_NOT_AVAILABLE_ON_MEMBER_1,
+   // new Object[] {senderId, memberId });
+ 
+   private void accumulateListGatewayResult(CompositeResultData crd,
+       Map<String, Map<String, GatewaySenderMXBean>> gatewaySenderBeans,
+       Map<String, GatewayReceiverMXBean> gatewayReceiverBeans) {
+ 
+     if (!gatewaySenderBeans.isEmpty()) {
+       TabularResultData gatewaySenderData = crd.addSection(
+           CliStrings.SECTION_GATEWAY_SENDER).addTable(
+           CliStrings.TABLE_GATEWAY_SENDER).setHeader(
+           CliStrings.HEADER_GATEWAY_SENDER);
+       for (Map.Entry<String, Map<String, GatewaySenderMXBean>> entry : gatewaySenderBeans
+           .entrySet()) {
+         for (Map.Entry<String, GatewaySenderMXBean> memberToBean : entry
+             .getValue().entrySet()) {
+           gatewaySenderData.accumulate(CliStrings.RESULT_GATEWAY_SENDER_ID,
+               entry.getKey());
+           gatewaySenderData.accumulate(CliStrings.RESULT_HOST_MEMBER,
+               memberToBean.getKey());
+           gatewaySenderData.accumulate(CliStrings.RESULT_REMOTE_CLUSTER,
+               memberToBean.getValue().getRemoteDSId());
+           gatewaySenderData.accumulate(CliStrings.RESULT_TYPE, memberToBean
+               .getValue().isParallel() ? CliStrings.SENDER_PARALLEL
+               : CliStrings.SENDER_SERIAL);
+           gatewaySenderData.accumulate(CliStrings.RESULT_STATUS, memberToBean
+               .getValue().isRunning() ? CliStrings.GATEWAY_RUNNING
+               : CliStrings.GATEWAY_NOT_RUNNING);
+           gatewaySenderData.accumulate(CliStrings.RESULT_QUEUED_EVENTS,
+               memberToBean.getValue().getEventQueueSize());
+           gatewaySenderData.accumulate(CliStrings.RESULT_RECEIVER, memberToBean
+               .getValue().getGatewayReceiver());
+         }
+       }
+     }
+ 
+     if (!gatewayReceiverBeans.isEmpty()) {
+       TabularResultData gatewayReceiverData = crd.addSection(
+           CliStrings.SECTION_GATEWAY_RECEIVER).addTable(
+           CliStrings.TABLE_GATEWAY_RECEIVER).setHeader(
+           CliStrings.HEADER_GATEWAY_RECEIVER);
+       for (Map.Entry<String, GatewayReceiverMXBean> entry : gatewayReceiverBeans
+           .entrySet()) {
+         gatewayReceiverData.accumulate(CliStrings.RESULT_HOST_MEMBER, entry
+             .getKey());
+         gatewayReceiverData.accumulate(CliStrings.RESULT_PORT, entry.getValue()
+             .getPort());
+         gatewayReceiverData.accumulate(CliStrings.RESULT_SENDERS_COUNT, entry
+             .getValue().getClientConnectionCount());
+         gatewayReceiverData.accumulate(CliStrings.RESULT_SENDER_CONNECTED,
+             entry.getValue().getConnectedGatewaySenders());
+       }
+     }
+ 
+   }
+   
+   private void accumulateStartResult(TabularResultData resultData,
+       String member, String Status, String message) {
+     if (member != null) {
+       resultData.accumulate("Member", member);
+     }
+     resultData.accumulate("Result", Status);
+     resultData.accumulate("Message", message);
+   }
+ 
+   @CliAvailabilityIndicator( { CliStrings.CREATE_GATEWAYSENDER,
+       CliStrings.START_GATEWAYSENDER, CliStrings.PAUSE_GATEWAYSENDER,
+       CliStrings.RESUME_GATEWAYSENDER, CliStrings.STOP_GATEWAYSENDER,
+       CliStrings.CREATE_GATEWAYRECEIVER, CliStrings.START_GATEWAYRECEIVER,
+       CliStrings.STOP_GATEWAYRECEIVER, CliStrings.LIST_GATEWAY,
+       CliStrings.STATUS_GATEWAYSENDER, CliStrings.STATUS_GATEWAYRECEIVER,
+       CliStrings.LOAD_BALANCE_GATEWAYSENDER })
+   public boolean isWanCommandsAvailable() {
+     boolean isAvailable = true; // always available on server
+     if (CliUtil.isGfshVM()) {
+       isAvailable = getGfsh() != null && getGfsh().isConnectedAndReady();
+     }
+     return isAvailable;
+   }
+   
+   private Result handleCommandResultException(CommandResultException crex) {
+     Result result = null;
+     if (crex.getResult() != null) {
+       result = crex.getResult();
+     }
+     else {
+       LogWrapper.getInstance().warning(
+           CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(crex));
+       result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR
+           + crex.getMessage());
+     }
+     return result;
+   }
+ }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5c01d5f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/shell/JmxOperationInvoker.java
----------------------------------------------------------------------
diff --cc geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/shell/JmxOperationInvoker.java
index 0000000,c2a1b2f..fd318aa
mode 000000,100644..100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/shell/JmxOperationInvoker.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/shell/JmxOperationInvoker.java
@@@ -1,0 -1,416 +1,478 @@@
+ /*
+  * Licensed to the Apache Software Foundation (ASF) under one or more
+  * contributor license agreements.  See the NOTICE file distributed with
+  * this work for additional information regarding copyright ownership.
+  * The ASF licenses this file to You under the Apache License, Version 2.0
+  * (the "License"); you may not use this file except in compliance with
+  * the License.  You may obtain a copy of the License at
+  *
+  *      http://www.apache.org/licenses/LICENSE-2.0
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  */
+ package com.gemstone.gemfire.management.internal.cli.shell;
+ 
++import java.io.File;
+ import java.io.IOException;
++import java.io.InputStream;
+ import java.net.MalformedURLException;
++import java.net.URL;
+ import java.text.MessageFormat;
+ import java.util.Arrays;
+ import java.util.HashMap;
+ import java.util.Iterator;
+ import java.util.Map;
+ import java.util.Map.Entry;
++import java.util.Properties;
+ import java.util.Set;
+ import java.util.TreeSet;
+ import java.util.concurrent.atomic.AtomicBoolean;
++
+ import javax.management.AttributeNotFoundException;
+ import javax.management.InstanceNotFoundException;
+ import javax.management.JMX;
+ import javax.management.MBeanException;
+ import javax.management.MBeanServerConnection;
+ import javax.management.MalformedObjectNameException;
+ import javax.management.Notification;
+ import javax.management.NotificationListener;
+ import javax.management.ObjectName;
+ import javax.management.QueryExp;
+ import javax.management.ReflectionException;
+ import javax.management.remote.JMXConnectionNotification;
+ import javax.management.remote.JMXConnector;
+ import javax.management.remote.JMXConnectorFactory;
+ import javax.management.remote.JMXServiceURL;
+ import javax.rmi.ssl.SslRMIClientSocketFactory;
+ 
++import com.gemstone.gemfire.internal.lang.StringUtils;
+ import com.gemstone.gemfire.internal.util.ArrayUtils;
++import com.gemstone.gemfire.internal.util.IOUtils;
+ import com.gemstone.gemfire.management.DistributedSystemMXBean;
+ import com.gemstone.gemfire.management.MemberMXBean;
+ import com.gemstone.gemfire.management.internal.MBeanJMXAdapter;
+ import com.gemstone.gemfire.management.internal.ManagementConstants;
++import com.gemstone.gemfire.management.internal.cli.CliUtil;
+ import com.gemstone.gemfire.management.internal.cli.CommandRequest;
+ import com.gemstone.gemfire.management.internal.cli.LogWrapper;
++import com.gemstone.gemfire.management.internal.cli.commands.ShellCommands;
++import com.gemstone.gemfire.management.internal.cli.i18n.CliStrings;
+ 
+ /**
+  * OperationInvoker JMX Implementation
+  *
+  * @author Abhishek Chaudhari
+  *
+  * @since 7.0
+  */
+ public class JmxOperationInvoker implements OperationInvoker {
+ 
+   public static final String JMX_URL_FORMAT = "service:jmx:rmi://{0}/jndi/rmi://{0}:{1}/jmxrmi";
+ 
+   // an JMX object describing the client-end of a JMX connection
+   private JMXConnector connector;
+ 
+   // address of the JMX Connector Server
+   private JMXServiceURL url;
+ 
+   // an instance of an MBeanServer connection (in a connected state)
+   private MBeanServerConnection mbsc;
+ 
+   // String representation of the GemFire JMX Manager endpoint, including host and port
+   private String endpoints;
+ 
+   // the host and port of the GemFire Manager
+   private String managerHost;
+   private int managerPort;
+ 
+   // MBean Proxies
+   private DistributedSystemMXBean distributedSystemMXBeanProxy;
+   private MemberMXBean memberMXBeanProxy;
+ 
+   private ObjectName managerMemberObjectName;
+ 
+   /*package*/ final AtomicBoolean isConnected = new AtomicBoolean(false);
+   /*package*/ final AtomicBoolean isSelfDisconnect = new AtomicBoolean(false);
+ 
+   private int clusterId = CLUSTER_ID_WHEN_NOT_CONNECTED;
+ 
+   public JmxOperationInvoker(final String host,
+                              final int port,
+                              final String userName,
+                              final String password,
 -                             final Map<String, String> sslConfigProps)
++                             final Map<String, String> sslConfigProps, String gfSecurityPropertiesPath)
+     throws Exception
+   {
+     final Set<String> propsToClear = new TreeSet<String>();
+     try {
+       this.managerHost = host;
+       this.managerPort = port;
+       this.endpoints = host + "[" + port + "]"; // Use the same syntax as the "connect" command.
+ 
+       // Modify check period from default (60 sec) to 1 sec
+       final Map<String, Object> env = new HashMap<String, Object>();
+ 
+       env.put(JMXConnectionListener.CHECK_PERIOD_PROP, JMXConnectionListener.CHECK_PERIOD);
+ 
+       if (userName != null && userName.length() > 0) {
+         env.put(JMXConnector.CREDENTIALS, new String[] { userName, password });
+       }      
+       Set<Entry<String, String>> entrySet = sslConfigProps.entrySet();
+       for (Iterator<Entry<String, String>> it = entrySet.iterator(); it.hasNext();) {
+         Entry<String, String> entry = it.next();
+         String key = entry.getKey();
+         String value = entry.getValue();
+         if (key.startsWith("javax.") || key.startsWith("cluster-ssl") || key.startsWith("jmx-manager-ssl") ) {
+           key =  checkforSystemPropertyPrefix(entry.getKey());
+           if((key.equals(Gfsh.SSL_ENABLED_CIPHERS) || key.equals(Gfsh.SSL_ENABLED_PROTOCOLS)) && "any".equals(value)){
+             continue;
+           }
+           System.setProperty(key, value);
+           propsToClear.add(key);
+         }
+       }
+ 
+       if(!sslConfigProps.isEmpty()){
+         if (System.getProperty(Gfsh.SSL_KEYSTORE) != null || System.getProperty(Gfsh.SSL_TRUSTSTORE) != null) {
+           // use ssl to connect
+           env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory());
+         }
+       }
+ 
++      //Check for JMX Credentials if empty put properties instance directly so that
++      //jmx management interceptor can read it for custom security properties
++      if(!env.containsKey(JMXConnector.CREDENTIALS)) {        
++        env.put(JMXConnector.CREDENTIALS, readProperties(gfSecurityPropertiesPath));
++      }
+ 
+       this.url = new JMXServiceURL(MessageFormat.format(JMX_URL_FORMAT, checkAndConvertToCompatibleIPv6Syntax(host), String.valueOf(port)));      
+       this.connector = JMXConnectorFactory.connect(url, env);
+       this.mbsc = connector.getMBeanServerConnection();
+       this.connector.addConnectionNotificationListener(new JMXConnectionListener(this), null, null);
+       this.connector.connect(); // TODO this call to connect is not needed
+       this.distributedSystemMXBeanProxy = JMX.newMXBeanProxy(mbsc, MBeanJMXAdapter.getDistributedSystemName(), DistributedSystemMXBean.class);
+ 
+       if (this.distributedSystemMXBeanProxy == null || !JMX.isMXBeanInterface(DistributedSystemMXBean.class)) {
+         LogWrapper.getInstance().info("DistributedSystemMXBean is not present on member with endpoints : "+this.endpoints);
+         connector.close();
+         throw new JMXConnectionException(JMXConnectionException.MANAGER_NOT_FOUND_EXCEPTION);
+       }
+       else {
+         this.managerMemberObjectName = this.distributedSystemMXBeanProxy.getMemberObjectName();
+         if (this.managerMemberObjectName == null || !JMX.isMXBeanInterface(MemberMXBean.class)) {
+           LogWrapper.getInstance().info("MemberMXBean with ObjectName "+this.managerMemberObjectName+" is not present on member with endpoints : "+endpoints);
+           this.connector.close();
+           throw new JMXConnectionException(JMXConnectionException.MANAGER_NOT_FOUND_EXCEPTION);
+         }
+         else {
+           this.memberMXBeanProxy = JMX.newMXBeanProxy(mbsc, managerMemberObjectName, MemberMXBean.class);
+         }
+       }
+ 
+       this.isConnected.set(true);
+       this.clusterId = distributedSystemMXBeanProxy.getDistributedSystemId();
+     }
+     catch (NullPointerException e) {
+       throw e;
+     }
+     catch (MalformedURLException e) {
+       throw e;
+     }
+     catch (IOException e) {
+       throw e;
+     }
+     finally {
+       for (String propToClear : propsToClear) {
+         System.clearProperty(propToClear);
+       }
+     }
+   }
+ 
++  //Copied from ShellCommands.java
++  private Properties readProperties(String gfSecurityPropertiesPath) throws MalformedURLException {
++    Gfsh gfshInstance = Gfsh.getCurrentInstance();
++    // reference to hold resolved gfSecurityPropertiesPath
++    String gfSecurityPropertiesPathToUse = CliUtil.resolvePathname(gfSecurityPropertiesPath);
++    URL gfSecurityPropertiesUrl = null;
++
++    // Case 1: User has specified gfSecurity properties file
++    if (!StringUtils.isBlank(gfSecurityPropertiesPathToUse)) {
++      // User specified gfSecurity properties doesn't exist
++      if (!IOUtils.isExistingPathname(gfSecurityPropertiesPathToUse)) {
++        gfshInstance.printAsSevere(CliStrings.format(CliStrings.GEMFIRE_0_PROPERTIES_1_NOT_FOUND_MESSAGE, "Security ", gfSecurityPropertiesPathToUse));
++      } else {
++        gfSecurityPropertiesUrl = new File(gfSecurityPropertiesPathToUse).toURI().toURL();
++      }
++    } else if (gfSecurityPropertiesPath == null) {
++      // Use default "gfsecurity.properties"
++      // in current dir, user's home or classpath
++      gfSecurityPropertiesUrl = ShellCommands.getFileUrl("gfsecurity.properties");
++    }
++    // if 'gfSecurityPropertiesPath' OR gfsecurity.properties has resolvable path
++    if (gfSecurityPropertiesUrl != null) {
++      gfshInstance.logToFile("Using security properties file : "
++              + CliUtil.decodeWithDefaultCharSet(gfSecurityPropertiesUrl.getPath()), null);
++      return loadPropertiesFromURL(gfSecurityPropertiesUrl);      
++    }  
++    return null;
++  }
++  
++  static Properties loadPropertiesFromURL(URL gfSecurityPropertiesUrl) {
++    Properties props = new Properties();
++    if (gfSecurityPropertiesUrl != null) {
++      InputStream inputStream = null;
++      try {
++        
++        inputStream = gfSecurityPropertiesUrl.openStream();
++        props.load(inputStream);
++      } catch (IOException io) {
++        throw new RuntimeException(CliStrings.format(
++            CliStrings.CONNECT__MSG__COULD_NOT_READ_CONFIG_FROM_0,
++                CliUtil.decodeWithDefaultCharSet(gfSecurityPropertiesUrl.getPath())), io);
++      } finally {
++        IOUtils.close(inputStream);
++      }
++    }
++    return props;
++  }
+   
+   private String checkforSystemPropertyPrefix(String key) {
+     String returnKey = key;
+     if (key.startsWith("javax."))
+       returnKey = key;
+     if (key.startsWith("cluster-ssl") || key.startsWith("jmx-manager-ssl")) {
+       if (key.endsWith("keystore")) {
+         returnKey = Gfsh.SSL_KEYSTORE;
+       } else if (key.endsWith("keystore-password")) {
+         returnKey = Gfsh.SSL_KEYSTORE_PASSWORD;
+       } else if (key.endsWith("ciphers")) {
+         returnKey = Gfsh.SSL_ENABLED_CIPHERS;
+       } else if (key.endsWith("truststore-password")) {
+         returnKey = Gfsh.SSL_TRUSTSTORE_PASSWORD;
+       } else if (key.endsWith("truststore")) {
+         returnKey = Gfsh.SSL_TRUSTSTORE;
+       } else if (key.endsWith("protocols")) {
+         returnKey = Gfsh.SSL_ENABLED_PROTOCOLS;
+       }
+     }    
+     return returnKey;    
+   }
+ 
+   @Override
+   public Object getAttribute(String resourceName, String attributeName) throws JMXInvocationException {
+     try {
+       return mbsc.getAttribute(ObjectName.getInstance(resourceName), attributeName);
+     } catch (AttributeNotFoundException e) {
+       throw new JMXInvocationException(attributeName + " not found for " + resourceName, e);
+     } catch (InstanceNotFoundException e) {
+       throw new JMXInvocationException(resourceName + " is not registered in the MBean server.", e);
+     } catch (MalformedObjectNameException e) {
+       throw new JMXInvocationException(resourceName + " is not a valid resource name.", e);
+     } catch (MBeanException e) {
+       throw new JMXInvocationException("Exception while fetching " + attributeName + " for " + resourceName, e);
+     } catch (ReflectionException e) {
+       throw new JMXInvocationException("Couldn't find "+attributeName+" for " + resourceName, e);
+     } catch (NullPointerException e) {
+       throw new JMXInvocationException("Given resourceName is null.", e);
+     } catch (IOException e) {
+       throw new JMXInvocationException(resourceName + " is not a valid resource name.", e);
+     }
+   }
+ 
+   @Override
+   public Object invoke(String resourceName, String operationName, Object[] params, String[] signature) throws JMXInvocationException {
+     try {
+       return invoke(ObjectName.getInstance(resourceName), operationName, params, signature);
+     } catch (MalformedObjectNameException e) {
+       throw new JMXInvocationException(resourceName + " is not a valid resource name.", e);
+     } catch (NullPointerException e) {
+       throw new JMXInvocationException("Given resourceName is null.", e);
+     }
+   }
+ 
+   /**
+    * JMX Specific operation invoke caller.
+    *
+    * @param resource
+    * @param operationName
+    * @param params
+    * @param signature
+    * @return result of JMX Operation invocation
+    * @throws JMXInvocationException
+    */
+   protected Object invoke(ObjectName resource, String operationName, Object[] params, String[] signature) throws JMXInvocationException {
+     try {
+       return mbsc.invoke(resource, operationName, params, signature);
+     } catch (InstanceNotFoundException e) {
+       throw new JMXInvocationException(resource + " is not registered in the MBean server.", e);
+     } catch (MBeanException e) {
+       throw new JMXInvocationException("Exception while invoking " + operationName + " on " + resource, e);
+     } catch (ReflectionException e) {
+       throw new JMXInvocationException("Couldn't find "+operationName+" on " + resource + " with arguments "+Arrays.toString(signature), e);
+     } catch (IOException e) {
+       throw new JMXInvocationException("Couldn't communicate with remote server at " + toString(), e);
+     }
+   }
+ 
+   public Set<ObjectName> queryNames(final ObjectName objectName, final QueryExp queryExpression) {
+     try {
+       return getMBeanServerConnection().queryNames(objectName, queryExpression);
+     } catch (IOException e) {
+       throw new JMXInvocationException(String.format("Failed to communicate with the remote MBean server at (%1$s)!",
+         toString()), e);
+     }
+   }
+ 
+   @Override
+   public Object processCommand(final CommandRequest commandRequest) throws JMXInvocationException {
+     //Gfsh.getCurrentInstance().printAsSevere(String.format("Command (%1$s)%n", commandRequest.getInput()));
+     if (commandRequest.hasFileData()) {
+       return memberMXBeanProxy.processCommand(commandRequest.getInput(), commandRequest.getEnvironment(),
+         ArrayUtils.toByteArray(commandRequest.getFileData()));
+     }
+     else {
+       return memberMXBeanProxy.processCommand(commandRequest.getInput(), commandRequest.getEnvironment());
+     }
+   }
+ 
+   @Override
+   public void stop() {
+     try {
+       this.isSelfDisconnect.set(true);
+       this.connector.close();
+       this.isConnected.set(false);
+     } catch (IOException e) {
+       // ignore exceptions occurring while closing the connector
+     }
+   }
+ 
+   @Override
+   public boolean isConnected() {
+     return this.isConnected.get();
+   }
+ 
+   public DistributedSystemMXBean getDistributedSystemMXBean() {
+     if (distributedSystemMXBeanProxy == null) {
+       throw new IllegalStateException("The DistributedSystemMXBean proxy was not initialized properly!");
+     }
+     return distributedSystemMXBeanProxy;
+   }
+ 
+   public JMXServiceURL getJmxServiceUrl() {
+     return this.url;
+   }
+ 
+   public String getManagerHost() {
+     return managerHost;
+   }
+ 
+   public int getManagerPort() {
+     return managerPort;
+   }
+ 
+   public <T> T getMBeanProxy(final ObjectName objectName, final Class<T> mbeanInterface) {
+     if (DistributedSystemMXBean.class.equals(mbeanInterface)
+       && ManagementConstants.OBJECTNAME__DISTRIBUTEDSYSTEM_MXBEAN.equals(objectName.toString())) {
+       return mbeanInterface.cast(getDistributedSystemMXBean());
+     }
+     else if (JMX.isMXBeanInterface(mbeanInterface)) {
+       return JMX.newMXBeanProxy(getMBeanServerConnection(), objectName, mbeanInterface);
+     }
+     else {
+       return JMX.newMBeanProxy(getMBeanServerConnection(), objectName, mbeanInterface);
+     }
+   }
+ 
+   public MBeanServerConnection getMBeanServerConnection() {
+     if (this.mbsc == null) {
+       throw new IllegalStateException("Gfsh is not connected to the GemFire Manager.");
+     }
+     return this.mbsc;
+   }
+ 
+   public boolean isReady() {
+     try {
+       return this.mbsc.isRegistered(managerMemberObjectName);
+     } catch (IOException e) {
+       return false;
+     }
+   }
+ 
+   @Override
+   public String toString() {
+     return this.endpoints;
+   }
+ 
+   public int getClusterId() {
+     return this.clusterId;
+   }
+ 
+   /*package*/ void resetClusterId() {
+     clusterId = CLUSTER_ID_WHEN_NOT_CONNECTED;
+   }
+ 
+   /**
+    * If the given host address contains a ":", considers it as an IPv6 address &
+    * returns the host based on RFC2732 requirements i.e. surrounds the given
+    * host address string with square brackets. If ":" is not found in the given
+    * string, simply returns the same string.
+    *
+    * @param hostAddress
+    *          host address to check if it's an IPv6 address
+    * @return for an IPv6 address returns compatible host address otherwise
+    *         returns the same string
+    */
+   //TODO - Abhishek: move to utility class
+   // Taken from GFMon
+   public static String checkAndConvertToCompatibleIPv6Syntax(String hostAddress) {
+     // if host string contains ":", considering it as an IPv6 Address
+     // Conforming to RFC2732 - http://www.ietf.org/rfc/rfc2732.txt
+     if (hostAddress.indexOf(":") != -1) {
+       LogWrapper logger = LogWrapper.getInstance();
+       if (logger.fineEnabled()) {
+         logger.fine("IPv6 host address detected, using IPv6 syntax for host in JMX connection URL");
+       }
+       hostAddress = "[" + hostAddress + "]";
+       if (logger.fineEnabled()) {
+         logger.fine("Compatible host address is : " + hostAddress);
+       }
+     }
+     return hostAddress;
+   }
+ }
+ 
+ /**
+  * A Connection Notification Listener. Notifies Gfsh when a connection gets
+  * terminated abruptly.
+  *
+  * @author Abhishek Chaudhari
+  * @since 7.0
+  */
+ class JMXConnectionListener implements NotificationListener {
+   public static final String CHECK_PERIOD_PROP = "jmx.remote.x.client.connection.check.period";
+   public static final long CHECK_PERIOD        = 1000L;
+   private JmxOperationInvoker invoker;
+ 
+   JMXConnectionListener (JmxOperationInvoker invoker) {
+     this.invoker = invoker;
+   }
+   @Override
+   public void handleNotification(Notification notification, Object handback) {
+     if (JMXConnectionNotification.class.isInstance(notification)) {
+       JMXConnectionNotification connNotif = (JMXConnectionNotification)notification;
+       if (JMXConnectionNotification.CLOSED.equals(connNotif.getType()) ||
+           JMXConnectionNotification.FAILED.equals(connNotif.getType())) {
+         this.invoker.isConnected.set(false);
+         this.invoker.resetClusterId();
+         if (!this.invoker.isSelfDisconnect.get()) {
+           Gfsh.getCurrentInstance().notifyDisconnect(this.invoker.toString());
+         }
+       }
+     }
+   }
+ 
+ }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5c01d5f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/security/AccessControl.java
----------------------------------------------------------------------
diff --cc geode-core/src/main/java/com/gemstone/gemfire/management/internal/security/AccessControl.java
index 0000000,0331767..bdb6b10
mode 000000,100644..100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/security/AccessControl.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/security/AccessControl.java
@@@ -1,0 -1,51 +1,57 @@@
+ /*
+  * Licensed to the Apache Software Foundation (ASF) under one or more
+  * contributor license agreements.  See the NOTICE file distributed with
+  * this work for additional information regarding copyright ownership.
+  * The ASF licenses this file to You under the Apache License, Version 2.0
+  * (the "License"); you may not use this file except in compliance with
+  * the License.  You may obtain a copy of the License at
+  *
+  *      http://www.apache.org/licenses/LICENSE-2.0
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  */
+ package com.gemstone.gemfire.management.internal.security;
+ 
+ import java.security.AccessControlContext;
+ import java.security.AccessController;
+ import java.security.Principal;
+ import java.util.Set;
+ 
+ import javax.management.remote.JMXPrincipal;
+ import javax.security.auth.Subject;
+ 
++/**
++ * AccessControlMBean Implementation. This retrieves JMXPrincipal from AccessController
++ * and performs authorization for given role using gemfire AccessControl Plugin
++ *  
++ * @author tushark
++ * @since 9.0
++ */
+ public class AccessControl implements AccessControlMXBean {
+ 
+   private ManagementInterceptor interceptor;
+ 
+   public AccessControl(ManagementInterceptor interceptor) {
+     this.interceptor = interceptor;
+   }
+ 
+   @Override
+   public boolean authorize(String role) {
+     AccessControlContext acc = AccessController.getContext();
+     Subject subject = Subject.getSubject(acc);
 -    Set<JMXPrincipal> principals = subject.getPrincipals(JMXPrincipal.class);
 -    Set<Object> pubCredentials = subject.getPublicCredentials();
++    Set<JMXPrincipal> principals = subject.getPrincipals(JMXPrincipal.class);    
+     if (principals == null || principals.isEmpty()) {
+       throw new SecurityException("Access denied");
+     }
+     Principal principal = principals.iterator().next();
 -    com.gemstone.gemfire.security.AccessControl gemAccControl = interceptor.getAccessControl(principal);
++    com.gemstone.gemfire.security.AccessControl gemAccControl = interceptor.getAccessControl(principal, false);
+     boolean authorized = gemAccControl.authorizeOperation(null,
+         new com.gemstone.gemfire.management.internal.security.AccessControlContext(role));
+     return authorized;
+   }
+ 
+ }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5c01d5f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/security/AccessControlContext.java
----------------------------------------------------------------------
diff --cc geode-core/src/main/java/com/gemstone/gemfire/management/internal/security/AccessControlContext.java
index 0000000,225d766..8153149
mode 000000,100644..100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/security/AccessControlContext.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/security/AccessControlContext.java
@@@ -1,0 -1,37 +1,49 @@@
+ /*
+  * Licensed to the Apache Software Foundation (ASF) under one or more
+  * contributor license agreements.  See the NOTICE file distributed with
+  * this work for additional information regarding copyright ownership.
+  * The ASF licenses this file to You under the Apache License, Version 2.0
+  * (the "License"); you may not use this file except in compliance with
+  * the License.  You may obtain a copy of the License at
+  *
+  *      http://www.apache.org/licenses/LICENSE-2.0
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  */
+ package com.gemstone.gemfire.management.internal.security;
+ 
++/**
++ * 
++ * ResourceOperationContext passed to AccessControlMBean for Authorization calls made
++ * from AccessControlMBean
++ * 
++ * @author tushark
++ * @since 9.0
++ *
++ */
+ public class AccessControlContext extends ResourceOperationContext {
+   
+   private ResourceOperationCode code;
+   
+   public AccessControlContext(String code){
+     this.code = ResourceOperationCode.parse(code);
+   }
+ 
+   @Override
+   public ResourceOperationCode getResourceOperationCode() {
+     return code;
+   }
+ 
+   @Override
+   public OperationCode getOperationCode() {   
+     return OperationCode.RESOURCE;
 -  }  
++  }
++  
++  public static AccessControlContext ACCESS_GRANTED_CONTEXT = new AccessControlContext(ResourceConstants.LIST_DS);
+ 
+ }
++



Mime
View raw message