You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2018/01/05 19:22:33 UTC
[geode] branch release/1.4.0 updated: GEODE-4131: add the
deprecated API in MemberMXBean (#1231)
This is an automated email from the ASF dual-hosted git repository.
jinmeiliao pushed a commit to branch release/1.4.0
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/release/1.4.0 by this push:
new 21d243d GEODE-4131: add the deprecated API in MemberMXBean (#1231)
21d243d is described below
commit 21d243d950270bb9f265f3a47c4d2ddd8be15cec
Author: jinmeiliao <ji...@pivotal.io>
AuthorDate: Fri Jan 5 10:59:52 2018 -0800
GEODE-4131: add the deprecated API in MemberMXBean (#1231)
(cherry picked from commit 78438f8)
---
.../org/apache/geode/management/MemberMXBean.java | 16 ++++++
.../management/internal/beans/MemberMBean.java | 30 +++++++++++-
.../geode/management/internal/cli/CliUtil.java | 57 ++++++++++------------
.../geode/management/internal/cli/CliUtilTest.java | 30 ++++++++++++
4 files changed, 100 insertions(+), 33 deletions(-)
diff --git a/geode-core/src/main/java/org/apache/geode/management/MemberMXBean.java b/geode-core/src/main/java/org/apache/geode/management/MemberMXBean.java
index 68eb105..15a309c 100644
--- a/geode-core/src/main/java/org/apache/geode/management/MemberMXBean.java
+++ b/geode-core/src/main/java/org/apache/geode/management/MemberMXBean.java
@@ -223,6 +223,22 @@ public interface MemberMXBean {
List<String> stagedFilePaths);
/**
+ * Executes a command on the member. this is the method that's used by the HttpOperationInvoker
+ * and JmxOperationInvoker
+ *
+ * @param commandString Command to be execute.
+ * @param env Environmental properties to use during command execution.
+ * @param binaryData Binary data specific to the command being executed.
+ * @return Result of the execution in JSON format.
+ *
+ * @deprecated since 1.4 use processCommand(String commandString, Map<String, String> env,
+ * List<String> stagedFilePaths) instead
+ */
+ @Deprecated
+ @ResourceOperation()
+ String processCommand(String commandString, Map<String, String> env, Byte[][] binaryData);
+
+ /**
* Returns the name of all disk stores in use by this member.
*
* @param includeRegionOwned Whether to include disk stores owned by a region.
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBean.java b/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBean.java
index c541051..b05258f 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBean.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBean.java
@@ -14,16 +14,21 @@
*/
package org.apache.geode.management.internal.beans;
+import java.io.File;
+import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.management.NotificationBroadcasterSupport;
+import org.apache.commons.io.FileUtils;
+
import org.apache.geode.management.GemFireProperties;
import org.apache.geode.management.JVMMetrics;
import org.apache.geode.management.MemberMXBean;
import org.apache.geode.management.OSMetrics;
+import org.apache.geode.management.internal.cli.CliUtil;
/**
* This MBean is a gateway to cache and a member
@@ -398,7 +403,7 @@ public class MemberMBean extends NotificationBroadcasterSupport implements Membe
@Override
public String processCommand(String commandString, Map<String, String> env) {
- return processCommand(commandString, env, null);
+ return processCommand(commandString, env, (List<String>) null);
}
@Override
@@ -408,6 +413,29 @@ public class MemberMBean extends NotificationBroadcasterSupport implements Membe
}
@Override
+ /**
+ * We don't expect any callers to call this code, but just in case, implementation is provided for
+ * backward compatibility
+ *
+ * @deprecated since 1.4 use processCommand(String commandString, Map<String, String> env,
+ * List<String> stagedFilePaths)
+ */
+ public String processCommand(String commandString, Map<String, String> env, Byte[][] binaryData) {
+ // save the binaryData into stagedFile first, and then call the new api
+ File tempDir = FileUtils.getTempDirectory();
+ List<String> filePaths = null;
+ try {
+ filePaths = CliUtil.bytesToFiles(binaryData, tempDir.getAbsolutePath());
+ return bridge.processCommand(commandString, env, filePaths);
+ } catch (IOException e) {
+ throw new RuntimeException(e.getMessage(), e);
+ } finally {
+ // delete the staged files
+ FileUtils.deleteQuietly(tempDir);
+ }
+ }
+
+ @Override
public String[] listDiskStores(boolean includeRegionOwned) {
return bridge.listDiskStores(includeRegionOwned);
}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/CliUtil.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/CliUtil.java
index 6718fe0..ed6ee28 100755
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/CliUtil.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/CliUtil.java
@@ -40,6 +40,7 @@ import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
+import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.geode.cache.CacheClosedException;
@@ -127,7 +128,14 @@ public class CliUtil {
return cache;
}
- public static byte[][] filesToBytes(String[] fileNames) throws IOException {
+ /**
+ * Even thought this is only used in a test, caller of MemberMXBean.processCommand(String, Map,
+ * Byte[][]) will need to use this method to convert a fileList to Byte[][] to call that
+ * deprecated API.
+ *
+ * Once that deprecated API is removed, we can delete this method and the tests.
+ */
+ public static Byte[][] filesToBytes(List<String> fileNames) throws IOException {
List<byte[]> filesDataList = new ArrayList<>();
for (String fileName : fileNames) {
@@ -151,11 +159,10 @@ public class CliUtil {
}
}
- byte[][] filesData = new byte[filesDataList.size()][];
-
- filesData = filesDataList.toArray(filesData);
+ List<Byte[]> convertedList =
+ filesDataList.stream().map(ArrayUtils::toObject).collect(Collectors.toList());
- return filesData;
+ return convertedList.toArray(new Byte[convertedList.size()][]);
}
public static byte[] toByteArray(InputStream input) throws IOException {
@@ -169,46 +176,32 @@ public class CliUtil {
return output.toByteArray();
}
- public static String[] bytesToNames(byte[][] fileData) {
- String[] names = new String[fileData.length / 2];
- for (int i = 0; i < fileData.length; i += 2) {
- names[i / 2] = new String(fileData[i]);
- }
-
- return names;
- }
-
- public static byte[][] bytesToData(byte[][] fileData) {
- byte[][] data = new byte[fileData.length / 2][];
- for (int i = 1; i < fileData.length; i += 2) {
- data[i / 2] = fileData[i];
- }
-
- return data;
- }
-
- public static void bytesToFiles(byte[][] fileData, String parentDirPath, boolean mkRequireddirs)
+ public static List<String> bytesToFiles(Byte[][] fileData, String parentDirPath)
throws IOException, UnsupportedOperationException {
+ List<String> filesPaths = new ArrayList<>();
FileOutputStream fos = null;
+ File file = null;
File parentDir = new File(parentDirPath);
- if (mkRequireddirs && !parentDir.exists()) {
- if (!parentDir.mkdirs()) {
- throw new UnsupportedOperationException(
- "Couldn't create required directory structure for " + parentDirPath);
- }
+ if (!parentDir.exists() && !parentDir.mkdirs()) {
+ throw new UnsupportedOperationException(
+ "Couldn't create required directory structure for " + parentDirPath);
}
for (int i = 0; i < fileData.length; i++) {
+ byte[] bytes = ArrayUtils.toPrimitive(fileData[i]);
if (i % 2 == 0) {
// Expect file name as bytes at even index
- String fileName = new String(fileData[i]);
- fos = new FileOutputStream(new File(parentDir, fileName));
+ String fileName = new String(bytes);
+ file = new File(parentDir, fileName);
+ fos = new FileOutputStream(file);
} else {
// Expect file contents as bytes at odd index
- fos.write(fileData[i]);
+ fos.write(bytes);
fos.close();
+ filesPaths.add(file.getAbsolutePath());
}
}
+ return filesPaths;
}
private static InternalCache getInternalCache() {
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/CliUtilTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/CliUtilTest.java
index 9f049c2..d181054 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/CliUtilTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/CliUtilTest.java
@@ -17,8 +17,16 @@ package org.apache.geode.management.internal.cli;
import static org.assertj.core.api.Assertions.assertThat;
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
import org.apache.geode.test.junit.categories.UnitTest;
@@ -26,6 +34,9 @@ import org.apache.geode.test.junit.categories.UnitTest;
@Category(UnitTest.class)
public class CliUtilTest {
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
@Test
public void arrayToString() throws Exception {
assertThat(CliUtil.arrayToString(null)).isEqualTo("null");
@@ -36,4 +47,23 @@ public class CliUtilTest {
String[] array3 = {null};
assertThat(CliUtil.arrayToString(array3)).isEqualTo("null");
}
+
+ @Test
+ public void filesToBytesAndThenBytesToFiles() throws IOException {
+ File file1 = new File(temporaryFolder.getRoot(), "file1.txt");
+ File file2 = new File(temporaryFolder.getRoot(), "file2.txt");
+
+ FileUtils.write(file1, "file1-content", "UTF-8");
+ FileUtils.write(file2, "file2-content", "UTF-8");
+
+ List<String> fileNames = Arrays.asList(file1.getAbsolutePath(), file2.getAbsolutePath());
+ Byte[][] bytes = CliUtil.filesToBytes(fileNames);
+
+ File dir = temporaryFolder.newFolder("temp");
+ List<String> filePaths = CliUtil.bytesToFiles(bytes, dir.getAbsolutePath());
+
+ assertThat(filePaths).hasSize(2);
+ assertThat(new File(filePaths.get(0))).hasContent("file1-content");
+ assertThat(new File(filePaths.get(1))).hasContent("file2-content");
+ }
}
--
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].