geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aba...@apache.org
Subject [5/9] incubator-geode git commit: GEODE-1984: Added a new WanCommand to destroy a gateway-sender Implemented GatewaySenderDestroyFunctionArgs and GatewaySenderDestroyFunction Started writing a test for destroy functionality. [ WIP ]
Date Fri, 25 Nov 2016 15:17:52 GMT
GEODE-1984: Added a new WanCommand to destroy a gateway-sender
Implemented GatewaySenderDestroyFunctionArgs and GatewaySenderDestroyFunction
Started writing a test for destroy functionality. [ WIP ]


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/c8228f16
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/c8228f16
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/c8228f16

Branch: refs/heads/feature/GEODE-1984
Commit: c8228f16a6c984bf8cf1e94533d9e88231311dd4
Parents: 93d4c08
Author: adongre <adongre@apache.org>
Authored: Sat Nov 19 23:10:45 2016 +0530
Committer: adongre <adongre@apache.org>
Committed: Sat Nov 19 23:10:45 2016 +0530

----------------------------------------------------------------------
 .../internal/cli/commands/WanCommands.java      |  78 ++++++--------
 .../functions/GatewaySenderDestroyFunction.java |  82 ++++++++++++++
 .../GatewaySenderDestroyFunctionArgs.java       |  32 ++++++
 ...WanCommandDestroyGatewaySenderDUnitTest.java | 107 +++++++++++++++++++
 4 files changed, 252 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c8228f16/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/WanCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/WanCommands.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/WanCommands.java
index ab5dea2..a9fd359 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/WanCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/WanCommands.java
@@ -44,11 +44,7 @@ import org.apache.geode.management.internal.MBeanJMXAdapter;
 import org.apache.geode.management.internal.SystemManagementService;
 import org.apache.geode.management.internal.cli.CliUtil;
 import org.apache.geode.management.internal.cli.LogWrapper;
-import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
-import org.apache.geode.management.internal.cli.functions.GatewayReceiverCreateFunction;
-import org.apache.geode.management.internal.cli.functions.GatewayReceiverFunctionArgs;
-import org.apache.geode.management.internal.cli.functions.GatewaySenderCreateFunction;
-import org.apache.geode.management.internal.cli.functions.GatewaySenderFunctionArgs;
+import org.apache.geode.management.internal.cli.functions.*;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.result.CommandResultException;
 import org.apache.geode.management.internal.cli.result.CompositeResultData;
@@ -205,50 +201,38 @@ public class WanCommands implements CommandMarker {
           help = CliStrings.DESTROY_GATEWAYSENDER__MEMBER__HELP) @CliMetaData(
               valueSeparator = ",") String onMember,
       @CliOption(key = CliStrings.DESTROY_GATEWAYSENDER__ID, mandatory = true,
+          optionContext = ConverterHint.GATEWAY_SENDER_ID,
           help = CliStrings.DESTROY_GATEWAYSENDER__ID__HELP) String id) {
     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));
-    // }
+    try {
+      GatewaySenderDestroyFunctionArgs gatewaySenderDestroyFunctionArgs =
+          new GatewaySenderDestroyFunctionArgs(id);
+
+      Set<DistributedMember> membersToCreateGatewaySenderOn =
+          CliUtil.findAllMatchingMembers(onGroups, onMember == null ? null : onMember.split(","));
+
+      ResultCollector<?, ?> resultCollector =
+          CliUtil.executeFunction(GatewaySenderDestroyFunction.INSTANCE,
+              gatewaySenderDestroyFunctionArgs, membersToCreateGatewaySenderOn);
+      @SuppressWarnings("unchecked")
+      List<CliFunctionResult> gatewaySenderDestroyResults =
+          (List<CliFunctionResult>) resultCollector.getResult();
+
+      TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
+      final String errorPrefix = "ERROR: ";
+      for (CliFunctionResult gatewaySenderDestroyResult : gatewaySenderDestroyResults) {
+        boolean success = gatewaySenderDestroyResult.isSuccessful();
+        tabularResultData.accumulate("Member", gatewaySenderDestroyResult.getMemberIdOrName());
+        tabularResultData.accumulate("Status",
+            (success ? "" : errorPrefix) + gatewaySenderDestroyResult.getMessage());
+      }
+      result = ResultBuilder.buildResult(tabularResultData);
+    } catch (IllegalArgumentException e) {
+      LogWrapper.getInstance().info(e.getMessage());
+      result = ResultBuilder.createUserErrorResult(e.getMessage());
+    } catch (CommandResultException crex) {
+      result = handleCommandResultException(crex);
+    }
     return result;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c8228f16/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewaySenderDestroyFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewaySenderDestroyFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewaySenderDestroyFunction.java
new file mode 100644
index 0000000..a64df06
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewaySenderDestroyFunction.java
@@ -0,0 +1,82 @@
+/*
+ * 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 org.apache.geode.management.internal.cli.functions;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.execute.FunctionAdapter;
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.cache.execute.ResultSender;
+import org.apache.geode.cache.wan.GatewaySender;
+import org.apache.geode.internal.InternalEntity;
+import org.apache.geode.internal.cache.wan.GatewaySenderException;
+import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.management.internal.cli.CliUtil;
+import org.apache.logging.log4j.Logger;
+
+public class GatewaySenderDestroyFunction extends FunctionAdapter implements InternalEntity
{
+  private static final Logger logger = LogService.getLogger();
+  private static final String ID = GatewaySenderDestroyFunction.class.getName();
+  public static GatewaySenderDestroyFunction INSTANCE = new GatewaySenderDestroyFunction();
+
+  @Override
+  public void execute(FunctionContext context) {
+    ResultSender<Object> resultSender = context.getResultSender();
+
+    Cache cache = CacheFactory.getAnyInstance();
+    String memberNameOrId =
+        CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
+
+    GatewaySenderDestroyFunctionArgs gatewaySenderDestroyFunctionArgs =
+        (GatewaySenderDestroyFunctionArgs) context.getArguments();
+
+    try {
+      GatewaySender gatewaySender =
+          cache.getGatewaySender(gatewaySenderDestroyFunctionArgs.getId());
+      if (gatewaySender != null) {
+        gatewaySender.destroy();
+      } else {
+        throw new GatewaySenderException(
+            "GateWaySender with Id " + gatewaySenderDestroyFunctionArgs.getId() + "not found");
+      }
+    } catch (GatewaySenderException gse) {
+      resultSender.lastResult(handleException(memberNameOrId, gse.getMessage(), gse));
+    } catch (Exception e) {
+      String exceptionMsg = e.getMessage();
+      if (exceptionMsg == null) {
+        exceptionMsg = CliUtil.stackTraceAsString(e);
+      }
+      resultSender.lastResult(handleException(memberNameOrId, exceptionMsg, e));
+    }
+  }
+
+  private CliFunctionResult handleException(final String memberNameOrId, final String exceptionMsg,
+      final Exception e) {
+    if (e != null && logger.isDebugEnabled()) {
+      logger.debug(e.getMessage(), e);
+    }
+    if (exceptionMsg != null) {
+      return new CliFunctionResult(memberNameOrId, false, exceptionMsg);
+    }
+
+    return new CliFunctionResult(memberNameOrId);
+  }
+
+  @Override
+  public String getId() {
+    return ID;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c8228f16/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewaySenderDestroyFunctionArgs.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewaySenderDestroyFunctionArgs.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewaySenderDestroyFunctionArgs.java
new file mode 100644
index 0000000..361cf63
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GatewaySenderDestroyFunctionArgs.java
@@ -0,0 +1,32 @@
+/*
+ * 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 org.apache.geode.management.internal.cli.functions;
+
+import java.io.Serializable;
+
+public class GatewaySenderDestroyFunctionArgs implements Serializable {
+
+  private static final long serialVersionUID = 3848480256348119530L;
+  private String id;
+
+
+  public GatewaySenderDestroyFunctionArgs(String id) {
+    this.id = id;
+  }
+
+  public String getId() {
+    return id;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c8228f16/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/wancommand/WanCommandDestroyGatewaySenderDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/wancommand/WanCommandDestroyGatewaySenderDUnitTest.java
b/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/wancommand/WanCommandDestroyGatewaySenderDUnitTest.java
new file mode 100644
index 0000000..7e3f3dd
--- /dev/null
+++ b/geode-wan/src/test/java/org/apache/geode/internal/cache/wan/wancommand/WanCommandDestroyGatewaySenderDUnitTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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 org.apache.geode.internal.cache.wan.wancommand;
+
+import org.apache.geode.management.cli.Result;
+import org.apache.geode.management.internal.cli.i18n.CliStrings;
+import org.apache.geode.management.internal.cli.result.CommandResult;
+import org.apache.geode.management.internal.cli.result.TabularResultData;
+import org.apache.geode.test.dunit.IgnoredException;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.List;
+import java.util.Properties;
+
+import static org.apache.geode.distributed.ConfigurationProperties.DISTRIBUTED_SYSTEM_ID;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+@Category(DistributedTest.class)
+public class WanCommandDestroyGatewaySenderDUnitTest extends WANCommandTestBase {
+  private static final long serialVersionUID = 1L;
+
+  private CommandResult executeCommandWithIgnoredExceptions(String command) {
+    final IgnoredException exln = IgnoredException.addIgnoredException("Could not connect");
+    try {
+      CommandResult commandResult = executeCommand(command);
+      return commandResult;
+    } finally {
+      exln.remove();
+    }
+  }
+
+  @Test
+  public void testDestroyGatewaySenderWithDefault() {
+    createGatewaySenderWithDefault();
+
+    String command =
+        CliStrings.DESTROY_GATEWAYSENDER + " --" + CliStrings.DESTROY_GATEWAYSENDER__ID +
"=ln";
+    CommandResult cmdResult = executeCommandWithIgnoredExceptions(command);
+    if (cmdResult != null) {
+      String strCmdResult = commandResultToString(cmdResult);
+      getLogWriter().info("testCreateGatewaySender stringResult : " + strCmdResult + ">>>>");
+      assertEquals(Result.Status.OK, cmdResult.getStatus());
+    } else {
+      fail("testDestroyGatewaySenderWithDefault failed as did not get CommandResult");
+    }
+  }
+
+  private void createGatewaySenderWithDefault() {
+    Integer punePort = (Integer) vm1.invoke(() -> createFirstLocatorWithDSId(1));
+
+    Properties props = getDistributedSystemProperties();
+    props.setProperty(MCAST_PORT, "0");
+    props.setProperty(DISTRIBUTED_SYSTEM_ID, "1");
+    props.setProperty(LOCATORS, "localhost[" + punePort + "]");
+    setUpJmxManagerOnVm0ThenConnect(props);
+
+    Integer nyPort = (Integer) vm2.invoke(() -> createFirstRemoteLocator(2, punePort));
+
+    vm3.invoke(() -> createCache(punePort));
+    vm4.invoke(() -> createCache(punePort));
+    vm5.invoke(() -> createCache(punePort));
+
+    String command = CliStrings.CREATE_GATEWAYSENDER + " --" + CliStrings.CREATE_GATEWAYSENDER__ID
+        + "=ln" + " --" + CliStrings.CREATE_GATEWAYSENDER__REMOTEDISTRIBUTEDSYSTEMID + "=2";
+    CommandResult cmdResult = executeCommandWithIgnoredExceptions(command);
+    if (cmdResult != null) {
+      String strCmdResult = commandResultToString(cmdResult);
+      getLogWriter().info("testCreateGatewaySender stringResult : " + strCmdResult + ">>>>");
+      assertEquals(Result.Status.OK, cmdResult.getStatus());
+
+      TabularResultData resultData = (TabularResultData) cmdResult.getResultData();
+      List<String> status = resultData.retrieveAllValues("Status");
+      assertEquals(5, status.size());
+      for (int i = 0; i < status.size(); i++) {
+        assertTrue("GatewaySender creation failed with: " + status.get(i),
+            status.get(i).indexOf("ERROR:") == -1);
+      }
+    } else {
+      fail("testCreateGatewaySender failed as did not get CommandResult");
+    }
+
+    vm3.invoke(() -> verifySenderState("ln", true, false));
+    vm4.invoke(() -> verifySenderState("ln", true, false));
+    vm5.invoke(() -> verifySenderState("ln", true, false));
+
+  }
+
+}


Mime
View raw message