You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by je...@apache.org on 2017/12/28 21:12:17 UTC
[geode] branch feature/GEODE-4131 updated (9c5de4a -> cc63152)
This is an automated email from the ASF dual-hosted git repository.
jensdeppe pushed a change to branch feature/GEODE-4131
in repository https://gitbox.apache.org/repos/asf/geode.git.
discard 9c5de4a GEODE-4131: Do not reference deployed jars as byte arrays anymore
new cc63152 GEODE-4131: Do not reference deployed jars as byte arrays anymore
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (9c5de4a)
\
N -- N -- N refs/heads/feature/GEODE-4131 (cc63152)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../java/org/apache/geode/management/internal/beans/MemberMBean.java | 1 -
1 file changed, 1 deletion(-)
--
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].
[geode] 01/01: GEODE-4131: Do not reference deployed jars as byte
arrays anymore
Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jensdeppe pushed a commit to branch feature/GEODE-4131
in repository https://gitbox.apache.org/repos/asf/geode.git
commit cc6315215b70952011375d6883d7ebb8c7393189
Author: Jens Deppe <jd...@pivotal.io>
AuthorDate: Wed Dec 27 13:45:59 2017 -0800
GEODE-4131: Do not reference deployed jars as byte arrays anymore
- All jars are streamed between locators and servers using the RMIIO library.
- Whenever an upload happens (either deploying jars or importing cluster
config) we stage the files initially and then proceed with the command.
---
geode-assembly/build.gradle | 1 +
.../src/test/resources/expected_jars.txt | 15 ++-
geode-core/build.gradle | 1 +
.../internal/ClusterConfigurationService.java | 120 +++++++++--------
.../org/apache/geode/internal/DeployedJar.java | 100 ++++++--------
.../geode/internal/InternalDataSerializer.java | 1 +
.../org/apache/geode/internal/JarDeployer.java | 148 ++++-----------------
.../internal/cache/ClusterConfigurationLoader.java | 83 ++++++++++--
.../geode/internal/cache/GemFireCacheImpl.java | 17 +--
.../org/apache/geode/management/MemberMXBean.java | 5 +-
.../geode/management/internal/ManagementAgent.java | 18 +++
.../management/internal/ManagementConstants.java | 3 +
.../management/internal/beans/FileUploader.java | 63 +++++++++
.../internal/beans/FileUploaderMBean.java | 26 ++++
.../management/internal/beans/MemberMBean.java | 7 +-
.../internal/beans/MemberMBeanBridge.java | 6 +-
.../geode/management/internal/cli/CliUtil.java | 20 ++-
.../management/internal/cli/CommandRequest.java | 20 +--
.../internal/cli/commands/DeployCommand.java | 122 +++++++++--------
.../ExportImportClusterConfigurationCommands.java | 24 ++--
.../internal/cli/functions/DeployFunction.java | 77 ++++++++++-
.../cli/remote/CommandExecutionContext.java | 13 +-
.../cli/remote/OnlineCommandProcessor.java | 9 +-
.../management/internal/cli/result/FileResult.java | 48 +++----
.../internal/cli/shell/GfshExecutionStrategy.java | 7 +-
.../internal/cli/shell/JmxOperationInvoker.java | 36 ++++-
...adJarFunction.java => DownloadJarFunction.java} | 38 +++++-
.../functions/GetClusterConfigurationFunction.java | 2 +-
.../messages/ConfigurationResponse.java | 35 ++---
.../controllers/AbstractCommandsController.java | 47 ++++---
.../web/controllers/ShellCommandsController.java | 6 +-
.../internal/web/shell/HttpOperationInvoker.java | 2 +-
.../management/internal/web/util/ConvertUtils.java | 24 ++--
.../sanctioned-geode-core-serializables.txt | 2 +-
.../internal/ClassPathLoaderIntegrationTest.java | 75 +++++++----
.../apache/geode/internal/ClassPathLoaderTest.java | 37 +++++-
.../geode/internal/DeployedJarJUnitTest.java | 13 +-
.../geode/internal/JarDeployerDeadlockTest.java | 11 +-
.../geode/internal/JarDeployerIntegrationTest.java | 22 ++-
.../backup/IncrementalBackupDistributedTest.java | 8 +-
.../commands/DeployCommandRedeployDUnitTest.java | 2 +-
.../internal/cli/commands/DeployCommandTest.java | 46 +++++++
.../cli/commands/DeployWithGroupsDUnitTest.java | 4 +-
.../internal/configuration/ClusterConfig.java | 4 +-
.../ShellCommandsControllerProcessCommandTest.java | 6 +-
.../codeAnalysis/sanctionedDataSerializables.txt | 5 +-
.../internal/web/util/ConvertUtilsJUnitTest.java | 34 -----
gradle/dependency-versions.properties | 1 +
48 files changed, 858 insertions(+), 556 deletions(-)
diff --git a/geode-assembly/build.gradle b/geode-assembly/build.gradle
index 501b279..2855632 100755
--- a/geode-assembly/build.gradle
+++ b/geode-assembly/build.gradle
@@ -193,6 +193,7 @@ def cp = {
it.contains('log4j-jcl') ||
it.contains('log4j-jul') ||
it.contains('log4j-slf4j-impl') ||
+ it.contains('rmiio') ||
it.contains('shiro') ||
it.contains('slf4j-api') ||
it.contains('spring-core') ||
diff --git a/geode-assembly/src/test/resources/expected_jars.txt b/geode-assembly/src/test/resources/expected_jars.txt
index bc49bce..51e3dd8 100644
--- a/geode-assembly/src/test/resources/expected_jars.txt
+++ b/geode-assembly/src/test/resources/expected_jars.txt
@@ -3,6 +3,7 @@ antlr
aopalliance
classmate
commons-beanutils
+commons-codec
commons-collections
commons-digester
commons-fileupload
@@ -10,7 +11,7 @@ commons-io
commons-lang
commons-logging
commons-modeler
-commons-codec
+commons-validator
fast-classpath-scanner
fastutil
findbugs-annotations
@@ -44,10 +45,11 @@ log4j-jcl
log4j-jul
log4j-slf4j-impl
lucene-analyzers-common
+lucene-analyzers-phonetic
lucene-core
lucene-queries
lucene-queryparser
-lucene-analyzers-phonetic
+mapstruct
mx4j
mx4j-remote
mx4j-tools
@@ -55,6 +57,7 @@ netty-all
paranamer
protobuf-java
ra.jar
+rmiio
scala-library
scala-reflect
shiro-core
@@ -69,6 +72,8 @@ spring-expression
spring-hateoas
spring-ldap-core
spring-oxm
+spring-plugin-core
+spring-plugin-metadata
spring-security-config
spring-security-core
spring-security-ldap
@@ -77,10 +82,6 @@ spring-shell
spring-tx
spring-web
spring-webmvc
-swagger-annotations
-mapstruct
-spring-plugin-core
-spring-plugin-metadata
springfox-core
springfox-schema
springfox-spi
@@ -88,5 +89,5 @@ springfox-spring-web
springfox-swagger
springfox-swagger-common
springfox-swagger-ui
+swagger-annotations
swagger-models
-commons-validator
diff --git a/geode-core/build.gradle b/geode-core/build.gradle
index 041e411..77c02ba 100755
--- a/geode-core/build.gradle
+++ b/geode-core/build.gradle
@@ -132,6 +132,7 @@ dependencies {
// https://mvnrepository.com/artifact/io.github.lukehutch/fast-classpath-scanner
compile 'io.github.lukehutch:fast-classpath-scanner:' + project.'fast-classpath-scanner.version'
+ compile 'com.healthmarketscience.rmiio:rmiio:' + project.'rmiio.version'
compile project(':geode-common')
compile project(':geode-json')
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/ClusterConfigurationService.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/ClusterConfigurationService.java
index beb6ae5..16921c8 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/ClusterConfigurationService.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/ClusterConfigurationService.java
@@ -21,11 +21,19 @@ import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_POST
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.nio.file.attribute.PosixFilePermission;
+import java.nio.file.attribute.PosixFilePermissions;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -45,8 +53,11 @@ import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactoryConfigurationError;
+import com.healthmarketscience.rmiio.RemoteInputStream;
+import com.healthmarketscience.rmiio.RemoteInputStreamClient;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.Logger;
@@ -78,7 +89,7 @@ import org.apache.geode.management.internal.configuration.callbacks.Configuratio
import org.apache.geode.management.internal.configuration.domain.Configuration;
import org.apache.geode.management.internal.configuration.domain.SharedConfigurationStatus;
import org.apache.geode.management.internal.configuration.domain.XmlEntity;
-import org.apache.geode.management.internal.configuration.functions.UploadJarFunction;
+import org.apache.geode.management.internal.configuration.functions.DownloadJarFunction;
import org.apache.geode.management.internal.configuration.messages.ConfigurationResponse;
import org.apache.geode.management.internal.configuration.messages.SharedConfigurationStatusResponse;
import org.apache.geode.management.internal.configuration.utils.XmlUtils;
@@ -288,7 +299,7 @@ public class ClusterConfigurationService {
*
* @return true on success
*/
- public boolean addJarsToThisLocator(String[] jarNames, byte[][] jarBytes, String[] groups) {
+ public boolean addJarsToThisLocator(List<String> jarFullPaths, String[] groups) {
lockSharedConfiguration();
boolean success = true;
try {
@@ -305,11 +316,14 @@ public class ClusterConfigurationService {
}
String groupDir = FilenameUtils.concat(this.configDirPath, group);
- for (int i = 0; i < jarNames.length; i++) {
- String filePath = FilenameUtils.concat(groupDir, jarNames[i]);
+ Set<String> jarNames = new HashSet<>();
+ for (int i = 0; i < jarFullPaths.size(); i++) {
+ File stagedJar = new File(jarFullPaths.get(i));
+ jarNames.add(stagedJar.getName());
+ String filePath = FilenameUtils.concat(groupDir, stagedJar.getName());
try {
File jarFile = new File(filePath);
- FileUtils.writeByteArrayToFile(jarFile, jarBytes[i]);
+ FileUtils.copyFile(stagedJar, jarFile);
} catch (IOException e) {
logger.info(e);
}
@@ -319,7 +333,6 @@ public class ClusterConfigurationService {
// will need the jars on file to upload to other locators. Need to update the jars
// using a new copy of the Configuration so that the change listener will pick up the jar
// name changes.
-
String memberId = cache.getMyId().getId();
Configuration configurationCopy = new Configuration(configuration);
@@ -382,23 +395,6 @@ public class ClusterConfigurationService {
return success;
}
- /**
- * read the jar bytes in the file system
- * <p>
- * used when creating cluster config response and used when uploading the jars to another locator
- */
- public byte[] getJarBytesFromThisLocator(String group, String jarName) throws IOException {
- Configuration configuration = getConfiguration(group);
-
- File jar = getPathToJarOnThisLocator(group, jarName).toFile();
-
- if (configuration == null || !configuration.getJarNames().contains(jarName) || !jar.exists()) {
- return null;
- }
-
- return FileUtils.readFileToByteArray(jar);
- }
-
// Only used when a locator is initially starting up
public void downloadJarFromOtherLocators(String groupName, String jarName)
throws IllegalStateException, IOException {
@@ -416,10 +412,7 @@ public class ClusterConfigurationService {
"Request to download jar " + jarName + " but no other locators are present");
}
- byte[] jarBytes = downloadJar(locators.get(0), groupName, jarName);
-
- File jarToWrite = getPathToJarOnThisLocator(groupName, jarName).toFile();
- FileUtils.writeByteArrayToFile(jarToWrite, jarBytes);
+ downloadJarFromLocator(groupName, jarName, locators.get(0));
}
// used in the cluster config change listener when jarnames are changed in the internal region
@@ -429,46 +422,61 @@ public class ClusterConfigurationService {
createConfigDirIfNecessary(groupName);
- byte[] jarBytes = downloadJar(sourceLocator, groupName, jarName);
-
- if (jarBytes == null) {
- throw new IllegalStateException("Could not download jar " + jarName + " in " + groupName
- + " from " + sourceLocator.getName());
- }
+ File jarFile = downloadJar(sourceLocator, groupName, jarName);
File jarToWrite = getPathToJarOnThisLocator(groupName, jarName).toFile();
- FileUtils.writeByteArrayToFile(jarToWrite, jarBytes);
+ Files.copy(jarFile.toPath(), jarToWrite.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
- private byte[] downloadJar(DistributedMember locator, String groupName, String jarName) {
- ResultCollector<byte[], List<byte[]>> rc =
- (ResultCollector<byte[], List<byte[]>>) CliUtil.executeFunction(new UploadJarFunction(),
- new Object[] {groupName, jarName}, Collections.singleton(locator));
-
- List<byte[]> result = rc.getResult();
-
- // we should only get one byte[] back in the list
- return result.get(0);
+ /**
+ * Retrieve a deployed jar from a locator. The retrieved file is staged in a temporary location.
+ *
+ * @param locator the DistributedMember
+ * @param groupName the group to use when retrieving the jar
+ * @param jarName the name of the deployed jar
+ * @return a File referencing the downloaded jar. The File is downloaded to a temporary location.
+ */
+ public File downloadJar(DistributedMember locator, String groupName, String jarName)
+ throws IOException {
+ ResultCollector<RemoteInputStream, List<RemoteInputStream>> rc =
+ (ResultCollector<RemoteInputStream, List<RemoteInputStream>>) CliUtil.executeFunction(
+ new DownloadJarFunction(), new Object[] {groupName, jarName},
+ Collections.singleton(locator));
+
+ List<RemoteInputStream> result = rc.getResult();
+ RemoteInputStream jarStream = result.get(0);
+
+ Set<PosixFilePermission> perms = new HashSet<>();
+ perms.add(PosixFilePermission.OWNER_READ);
+ perms.add(PosixFilePermission.OWNER_WRITE);
+ perms.add(PosixFilePermission.OWNER_EXECUTE);
+ Path tempDir =
+ Files.createTempDirectory("deploy-", PosixFilePermissions.asFileAttribute(perms));
+ Path tempJar = Paths.get(tempDir.toString(), jarName);
+ FileOutputStream fos = new FileOutputStream(tempJar.toString());
+ InputStream input = RemoteInputStreamClient.wrap(jarStream);
+
+ IOUtils.copy(input, fos);
+
+ fos.close();
+ input.close();
+
+ return tempJar.toFile();
}
// used when creating cluster config response
- public Map<String, byte[]> getAllJarsFromThisLocator(Set<String> groups) throws IOException {
- Map<String, byte[]> jarNamesToJarBytes = new HashMap<>();
-
+ public Set<String> getAllJarNamesFromThisLocator(Set<String> groups) {
+ Set<String> jarNames = new HashSet<>();
for (String group : groups) {
Configuration groupConfig = getConfiguration(group);
if (groupConfig == null) {
break;
}
- Set<String> jars = groupConfig.getJarNames();
- for (String jar : jars) {
- byte[] jarBytes = getJarBytesFromThisLocator(group, jar);
- jarNamesToJarBytes.put(jar, jarBytes);
- }
+ jarNames.addAll(groupConfig.getJarNames());
}
- return jarNamesToJarBytes;
+ return jarNames;
}
/**
@@ -547,13 +555,11 @@ public class ClusterConfigurationService {
for (String group : groups) {
Configuration configuration = getConfiguration(group);
configResponse.addConfiguration(configuration);
+ if (configuration != null) {
+ configResponse.addJar(group, configuration.getJarNames());
+ }
}
- Map<String, byte[]> jarNamesToJarBytes = getAllJarsFromThisLocator(groups);
- String[] jarNames = jarNamesToJarBytes.keySet().stream().toArray(String[]::new);
- byte[][] jarBytes = jarNamesToJarBytes.values().toArray(new byte[jarNames.length][]);
-
- configResponse.addJarsToBeDeployed(jarNames, jarBytes);
return configResponse;
}
} finally {
diff --git a/geode-core/src/main/java/org/apache/geode/internal/DeployedJar.java b/geode-core/src/main/java/org/apache/geode/internal/DeployedJar.java
index a341ee3..f48edc8 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/DeployedJar.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/DeployedJar.java
@@ -14,6 +14,7 @@
*/
package org.apache.geode.internal;
+import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -86,52 +87,44 @@ public class DeployedJar {
return JarDeployer.extractVersionFromFilename(this.file.getName());
}
- public DeployedJar(File versionedJarFile, String jarName) throws IOException {
- this(versionedJarFile, jarName, Files.readAllBytes(versionedJarFile.toPath()));
- }
-
/**
* Writes the given jarBytes to versionedJarFile
*/
- public DeployedJar(File versionedJarFile, final String jarName, byte[] jarBytes)
- throws FileNotFoundException {
- Assert.assertTrue(jarBytes != null, "jarBytes cannot be null");
+ public DeployedJar(File versionedJarFile, final String jarName) {
Assert.assertTrue(jarName != null, "jarName cannot be null");
Assert.assertTrue(versionedJarFile != null, "versionedJarFile cannot be null");
this.file = versionedJarFile;
this.jarName = jarName;
- final byte[] fileContent = getJarContent();
- if (!Arrays.equals(fileContent, jarBytes)) {
- throw new IllegalStateException("JAR file: " + versionedJarFile.getAbsolutePath()
- + ", does not have the expected content.");
- }
-
- if (!hasValidJarContent(fileContent)) {
+ if (!hasValidJarContent(versionedJarFile)) {
throw new IllegalArgumentException(
"File does not contain valid JAR content: " + versionedJarFile.getAbsolutePath());
}
- if (messageDigest != null) {
- this.md5hash = messageDigest.digest(jarBytes);
- } else {
- this.md5hash = null;
+ byte[] digest = null;
+ try {
+ if (messageDigest != null) {
+ digest = fileDigest(this.file);
+ }
+ } catch (IOException e) {
+ // Ignored
}
+ this.md5hash = digest;
}
/**
* Peek into the JAR data and make sure that it is valid JAR content.
*
- * @param inputStream InputStream containing data to be validated.
+ * @param jarFile Jar containing data to be validated.
* @return True if the data has JAR content, false otherwise
*/
- private static boolean hasValidJarContent(final InputStream inputStream) {
+ public static boolean hasValidJarContent(File jarFile) {
JarInputStream jarInputStream = null;
boolean valid = false;
try {
- jarInputStream = new JarInputStream(inputStream);
+ jarInputStream = new JarInputStream(new FileInputStream(jarFile));
valid = jarInputStream.getNextJarEntry() != null;
} catch (IOException ignore) {
// Ignore this exception and just return false
@@ -147,16 +140,6 @@ public class DeployedJar {
}
/**
- * Peek into the JAR data and make sure that it is valid JAR content.
- *
- * @param jarBytes Bytes of data to be validated.
- * @return True if the data has JAR content, false otherwise
- */
- static boolean hasValidJarContent(final byte[] jarBytes) {
- return hasValidJarContent(new ByteArrayInputStream(jarBytes));
- }
-
- /**
* Scan the JAR file and attempt to register any function classes found.
*/
@@ -166,13 +149,19 @@ public class DeployedJar {
logger.debug("Registering functions with DeployedJar: {}", this);
}
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(this.getJarContent());
+ BufferedInputStream bufferedInputStream;
+ try {
+ bufferedInputStream = new BufferedInputStream(new FileInputStream(this.file));
+ } catch (Exception ex) {
+ logger.error("Unable to scan jar file for functions");
+ return;
+ }
JarInputStream jarInputStream = null;
try {
Collection<String> functionClasses = findFunctionsInThisJar();
- jarInputStream = new JarInputStream(byteArrayInputStream);
+ jarInputStream = new JarInputStream(bufferedInputStream);
JarEntry jarEntry = jarInputStream.getNextJarEntry();
while (jarEntry != null) {
@@ -259,16 +248,21 @@ public class DeployedJar {
* Uses MD5 hashes to determine if the original byte content of this DeployedJar is the same as
* that past in.
*
- * @param compareToBytes Bytes to compare the original content to
+ * @param stagedFile File to compare the original content to
* @return True of the MD5 hash is the same o
*/
- boolean hasSameContentAs(final byte[] compareToBytes) {
+ boolean hasSameContentAs(final File stagedFile) {
// If the MD5 hash can't be calculated then silently return no match
if (messageDigest == null || this.md5hash == null) {
- return Arrays.equals(compareToBytes, getJarContent());
+ return false;
}
- byte[] compareToMd5 = messageDigest.digest(compareToBytes);
+ byte[] compareToMd5;
+ try {
+ compareToMd5 = fileDigest(stagedFile);
+ } catch (IOException ex) {
+ return false;
+ }
if (logger.isDebugEnabled()) {
logger.debug("For JAR file: {}, Comparing MD5 hash {} to {}", this.file.getAbsolutePath(),
new String(this.md5hash), new String(compareToMd5));
@@ -276,6 +270,18 @@ public class DeployedJar {
return Arrays.equals(this.md5hash, compareToMd5);
}
+ private byte[] fileDigest(File file) throws IOException {
+ BufferedInputStream fis = new BufferedInputStream(new FileInputStream(file));
+ byte[] data = new byte[8192];
+
+ int read;
+ while ((read = fis.read(data)) > 0) {
+ messageDigest.update(data, 0, read);
+ }
+
+ return messageDigest.digest();
+ }
+
/**
* Check to see if the class implements the Function interface. If so, it will be registered with
* FunctionService. Also, if the functions's class was originally declared in a cache.xml file
@@ -360,26 +366,6 @@ public class DeployedJar {
return null;
}
- private byte[] getJarContent() {
- try {
- InputStream channelInputStream = new FileInputStream(this.file);
-
- final ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
- final byte[] bytes = new byte[4096];
-
- int bytesRead;
- while ((bytesRead = channelInputStream.read(bytes)) != -1) {
- byteOutStream.write(bytes, 0, bytesRead);
- }
- channelInputStream.close();
- return byteOutStream.toByteArray();
- } catch (IOException e) {
- logger.error("Error when attempting to read jar contents: ", e);
- }
-
- return ZERO_BYTES;
- }
-
/**
* @return the unversioned name of this jar file, e.g. myJar.jar
*/
diff --git a/geode-core/src/main/java/org/apache/geode/internal/InternalDataSerializer.java b/geode-core/src/main/java/org/apache/geode/internal/InternalDataSerializer.java
index 5079c07..c3b890b 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/InternalDataSerializer.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/InternalDataSerializer.java
@@ -156,6 +156,7 @@ public abstract class InternalDataSerializer extends DataSerializer implements D
+ ";org.apache.shiro.*;org.apache.shiro.authz.*;org.apache.shiro.authc.*" // security
// services
+ ";org.apache.geode.modules.util.SessionCustomExpiry" // geode-modules
+ + ";com.healthmarketscience.rmiio.*;com.sun.proxy.*" // Jar deployment
+ ";";
diff --git a/geode-core/src/main/java/org/apache/geode/internal/JarDeployer.java b/geode-core/src/main/java/org/apache/geode/internal/JarDeployer.java
index 61650a7..47e11d0 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/JarDeployer.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/JarDeployer.java
@@ -18,14 +18,11 @@ import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
-import java.io.BufferedInputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
import java.io.Serializable;
import java.net.URL;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -46,6 +43,7 @@ import java.util.stream.Stream;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.Logger;
+import org.apache.geode.annotations.TestingOnly;
import org.apache.geode.internal.logging.LogService;
public class JarDeployer implements Serializable {
@@ -82,12 +80,12 @@ public class JarDeployer implements Serializable {
* @return the DeployedJar that was written from jarBytes, or null if those bytes matched the
* latest deployed version
*/
- public DeployedJar deployWithoutRegistering(final String jarName, final byte[] jarBytes)
+ public DeployedJar deployWithoutRegistering(final String jarName, final File stagedJar)
throws IOException {
lock.lock();
try {
- boolean shouldDeployNewVersion = shouldDeployNewVersion(jarName, jarBytes);
+ boolean shouldDeployNewVersion = shouldDeployNewVersion(jarName, stagedJar);
if (!shouldDeployNewVersion) {
logger.debug("No need to deploy a new version of {}", jarName);
return null;
@@ -96,9 +94,9 @@ public class JarDeployer implements Serializable {
verifyWritableDeployDirectory();
File newVersionedJarFile = getNextVersionedJarFile(jarName);
- writeJarBytesToFile(newVersionedJarFile, jarBytes);
+ Files.copy(stagedJar.toPath(), newVersionedJarFile.toPath());
- return new DeployedJar(newVersionedJarFile, jarName, jarBytes);
+ return new DeployedJar(newVersionedJarFile, jarName);
} finally {
lock.unlock();
}
@@ -152,93 +150,6 @@ public class JarDeployer implements Serializable {
}
/**
- * Attempt to write the given bytes to the given file. If this VM is able to successfully write
- * the contents to the file, or another VM writes the exact same contents, then the write is
- * considered to be successful.
- *
- * @param file File of the JAR file to deploy.
- * @param jarBytes Contents of the JAR file to deploy.
- * @return True if the file was successfully written, false otherwise
- */
- private boolean writeJarBytesToFile(final File file, final byte[] jarBytes) throws IOException {
- final boolean isDebugEnabled = logger.isDebugEnabled();
- if (file.createNewFile()) {
- if (isDebugEnabled) {
- logger.debug("Successfully created new JAR file: {}", file.getAbsolutePath());
- }
- final OutputStream outStream = new FileOutputStream(file);
- outStream.write(jarBytes);
- outStream.close();
- return true;
- }
- return doesFileMatchBytes(file, jarBytes);
- }
-
- /**
- * Determine if the contents of the file referenced is an exact match for the bytes provided. The
- * method first checks to see if the file is actively being written by checking the length over
- * time. If it appears that the file is actively being written, then it loops waiting for that to
- * complete before doing the comparison.
- *
- * @param file File to compare
- * @param bytes Bytes to compare
- * @return True if there's an exact match, false otherwise
- * @throws IOException If there's a problem reading the file
- */
- private boolean doesFileMatchBytes(final File file, final byte[] bytes) throws IOException {
- // First check to see if the file is actively being written (if it's not big enough)
- final String absolutePath = file.getAbsolutePath();
- boolean keepTrying = true;
- final boolean isDebugEnabled = logger.isDebugEnabled();
- while (file.length() < bytes.length && keepTrying) {
- if (isDebugEnabled) {
- logger.debug("Loop waiting for another to write file: {}", absolutePath);
- }
- long startingFileLength = file.length();
- try {
- Thread.sleep(500);
- } catch (InterruptedException iex) {
- // Just keep looping
- }
- if (startingFileLength == file.length()) {
- if (isDebugEnabled) {
- logger.debug("Done waiting for another to write file: {}", absolutePath);
- }
- // Assume the other process has finished writing
- keepTrying = false;
- }
- }
-
- // If they don't have the same number of bytes then nothing to do
- if (file.length() != bytes.length) {
- if (isDebugEnabled) {
- logger.debug("Unmatching file length when waiting for another to write file: {}",
- absolutePath);
- }
- return false;
- }
-
- // Open the file then loop comparing each byte
- BufferedInputStream inStream = new BufferedInputStream(new FileInputStream(file));
- int index = 0;
- try {
- for (; index < bytes.length; index++) {
- if (((byte) inStream.read()) != bytes[index]) {
- if (isDebugEnabled) {
- logger.debug("Did not find a match when waiting for another to write file: {}",
- absolutePath);
- }
- return false;
- }
- }
- } finally {
- inStream.close();
- }
-
- return true;
- }
-
- /**
* Find the version number that's embedded in the name of this file
*
* @param filename Filename to get the version number from
@@ -420,14 +331,8 @@ public class JarDeployer implements Serializable {
throws IOException {
final File[] jarFiles = findSortedOldVersionsOfJar(unversionedJarName);
- Optional<File> latestValidDeployedJarOptional =
- Arrays.stream(jarFiles).filter(Objects::nonNull).filter(jarFile -> {
- try {
- return DeployedJar.hasValidJarContent(FileUtils.readFileToByteArray(jarFile));
- } catch (IOException e) {
- return false;
- }
- }).findFirst();
+ Optional<File> latestValidDeployedJarOptional = Arrays.stream(jarFiles).filter(Objects::nonNull)
+ .filter(jarFile -> DeployedJar.hasValidJarContent(jarFile)).findFirst();
if (!latestValidDeployedJarOptional.isPresent()) {
// No valid version of this jar
@@ -482,46 +387,43 @@ public class JarDeployer implements Serializable {
/**
* Deploy the given JAR files.
*
- * @param jarNames Array of names of the JAR files to deploy.
- * @param jarBytes Array of contents of the JAR files to deploy.
+ * @param stagedJarFiles A map of Files which have been staged in another location and are ready
+ * to be deployed as a unit.
* @return An array of newly created JAR class loaders. Entries will be null for an JARs that were
* already deployed.
* @throws IOException When there's an error saving the JAR file to disk
*/
- public List<DeployedJar> deploy(final String jarNames[], final byte[][] jarBytes)
+ public List<DeployedJar> deploy(final Map<String, File> stagedJarFiles)
throws IOException, ClassNotFoundException {
- DeployedJar[] deployedJars = new DeployedJar[jarNames.length];
+ List<DeployedJar> deployedJars = new ArrayList<>(stagedJarFiles.size());
- for (int i = 0; i < jarNames.length; i++) {
- if (!DeployedJar.hasValidJarContent(jarBytes[i])) {
+ for (File jar : stagedJarFiles.values()) {
+ if (!DeployedJar.hasValidJarContent(jar)) {
throw new IllegalArgumentException(
- "File does not contain valid JAR content: " + jarNames[i]);
+ "File does not contain valid JAR content: " + jar.getName());
}
}
lock.lock();
try {
- for (int i = 0; i < jarNames.length; i++) {
- String jarName = jarNames[i];
- byte[] newJarBytes = jarBytes[i];
-
- deployedJars[i] = deployWithoutRegistering(jarName, newJarBytes);
+ for (String fileName : stagedJarFiles.keySet()) {
+ deployedJars.add(deployWithoutRegistering(fileName, stagedJarFiles.get(fileName)));
}
- return registerNewVersions(Arrays.asList(deployedJars));
+ return registerNewVersions(deployedJars);
} finally {
lock.unlock();
}
}
- private boolean shouldDeployNewVersion(String jarName, byte[] newJarBytes) throws IOException {
+ private boolean shouldDeployNewVersion(String jarName, File stagedJar) throws IOException {
DeployedJar oldDeployedJar = this.deployedJars.get(jarName);
if (oldDeployedJar == null) {
return true;
}
- if (oldDeployedJar.hasSameContentAs(newJarBytes)) {
+ if (oldDeployedJar.hasSameContentAs(stagedJar)) {
logger.warn("Jar is identical to the latest deployed version: {}",
oldDeployedJar.getFileCanonicalPath());
@@ -536,16 +438,20 @@ public class JarDeployer implements Serializable {
*
* @param jarName - the unversioned jar name, e.g. myJar.jar
*/
- public DeployedJar findDeployedJar(String jarName) {
+ public DeployedJar getDeployedJar(String jarName) {
return this.deployedJars.get(jarName);
}
- public DeployedJar deploy(final String jarName, final byte[] jarBytes)
+ @TestingOnly
+ public DeployedJar deploy(final String jarName, final File stagedJarFile)
throws IOException, ClassNotFoundException {
lock.lock();
+ Map<String, File> jarFiles = new HashMap<>();
+ jarFiles.put(jarName, stagedJarFile);
+
try {
- List<DeployedJar> deployedJars = deploy(new String[] {jarName}, new byte[][] {jarBytes});
+ List<DeployedJar> deployedJars = deploy(jarFiles);
if (deployedJars == null || deployedJars.size() == 0) {
return null;
}
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java b/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java
index cd1a85a..7716c13 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java
@@ -18,11 +18,20 @@ import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.UnknownHostException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.PosixFilePermission;
+import java.nio.file.attribute.PosixFilePermissions;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
@@ -31,9 +40,8 @@ import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
-import org.apache.commons.lang.ArrayUtils;
+import com.healthmarketscience.rmiio.RemoteInputStream;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.Logger;
@@ -41,6 +49,7 @@ import org.apache.geode.UnmodifiableException;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.execute.FunctionService;
import org.apache.geode.cache.execute.ResultCollector;
+import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
@@ -50,7 +59,9 @@ import org.apache.geode.internal.DeployedJar;
import org.apache.geode.internal.JarDeployer;
import org.apache.geode.internal.config.ClusterConfigurationNotAvailableException;
import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.management.internal.cli.CliUtil;
import org.apache.geode.management.internal.configuration.domain.Configuration;
+import org.apache.geode.management.internal.configuration.functions.DownloadJarFunction;
import org.apache.geode.management.internal.configuration.functions.GetClusterConfigurationFunction;
import org.apache.geode.management.internal.configuration.messages.ConfigurationResponse;
@@ -62,34 +73,36 @@ public class ClusterConfigurationLoader {
* Deploys the jars received from shared configuration, it undeploys any other jars that were not
* part of shared configuration
*
- * @param cache Cache of this member
* @param response {@link ConfigurationResponse} received from the locators
*/
- public void deployJarsReceivedFromClusterConfiguration(Cache cache,
- ConfigurationResponse response) throws IOException, ClassNotFoundException {
+ public void deployJarsReceivedFromClusterConfiguration(ConfigurationResponse response)
+ throws IOException, ClassNotFoundException {
logger.info("Requesting cluster configuration");
if (response == null) {
return;
}
- String[] jarFileNames = response.getJarNames();
- byte[][] jarBytes = response.getJars();
+ List<String> jarFileNames =
+ response.getJarNames().values().stream().flatMap(Set::stream).collect(Collectors.toList());
- if (jarFileNames != null && jarBytes != null) {
- logger.info("Got response with jars: {}", Stream.of(jarFileNames).collect(joining(",")));
+ if (jarFileNames != null && !jarFileNames.isEmpty()) {
+ logger.info("Got response with jars: {}", jarFileNames.stream().collect(joining(",")));
JarDeployer jarDeployer = ClassPathLoader.getLatest().getJarDeployer();
jarDeployer.suspendAll();
try {
List<String> extraJarsOnServer =
jarDeployer.findDeployedJars().stream().map(DeployedJar::getJarName)
- .filter(jarName -> !ArrayUtils.contains(jarFileNames, jarName)).collect(toList());
+ .filter(jarName -> !jarFileNames.contains(jarName)).collect(toList());
for (String extraJar : extraJarsOnServer) {
logger.info("Removing jar not present in cluster configuration: {}", extraJar);
jarDeployer.deleteAllVersionsOfJar(extraJar);
}
- List<DeployedJar> deployedJars = jarDeployer.deploy(jarFileNames, jarBytes);
+ Map<String, File> stagedJarFiles =
+ getJarsFromLocator(response.getMember(), response.getJarNames());
+
+ List<DeployedJar> deployedJars = jarDeployer.deploy(stagedJarFiles);
deployedJars.stream().filter(Objects::nonNull)
.forEach((jar) -> logger.info("Deployed: {}", jar.getFile().getAbsolutePath()));
@@ -99,6 +112,53 @@ public class ClusterConfigurationLoader {
}
}
+ private Map<String, File> getJarsFromLocator(DistributedMember locator,
+ Map<String, Set<String>> jarNames) throws IOException {
+ Map<String, File> results = new HashMap<>();
+
+ for (String group : jarNames.keySet()) {
+ for (String jar : jarNames.get(group)) {
+ results.put(jar, downloadJar(locator, group, jar));
+ }
+ }
+
+ return results;
+ }
+
+ public File downloadJar(DistributedMember locator, String groupName, String jarName)
+ throws IOException {
+ ResultCollector<RemoteInputStream, List<RemoteInputStream>> rc =
+ (ResultCollector<RemoteInputStream, List<RemoteInputStream>>) CliUtil.executeFunction(
+ new DownloadJarFunction(), new Object[] {groupName, jarName},
+ Collections.singleton(locator));
+
+ List<RemoteInputStream> result = rc.getResult();
+ RemoteInputStream jarStream = result.get(0);
+
+ Set<PosixFilePermission> perms = new HashSet<>();
+ perms.add(PosixFilePermission.OWNER_READ);
+ perms.add(PosixFilePermission.OWNER_WRITE);
+ perms.add(PosixFilePermission.OWNER_EXECUTE);
+ Path tempDir =
+ Files.createTempDirectory("deploy-", PosixFilePermissions.asFileAttribute(perms));
+ Path tempJar = Paths.get(tempDir.toString(), jarName);
+ FileOutputStream fos = new FileOutputStream(tempJar.toString());
+
+ int packetId = 0;
+ while (true) {
+ byte[] data = jarStream.readPacket(packetId);
+ if (data == null) {
+ break;
+ }
+ fos.write(data);
+ packetId++;
+ }
+ fos.close();
+ jarStream.close(true);
+
+ return tempJar.toFile();
+ }
+
/***
* Apply the cache-xml cluster configuration on this member
*/
@@ -225,6 +285,7 @@ public class ClusterConfigurationLoader {
Object result = ((ArrayList) resultCollector.getResult()).get(0);
if (result instanceof ConfigurationResponse) {
response = (ConfigurationResponse) result;
+ response.setMember(locator);
break;
} else {
logger.error("Received invalid result from {}: {}", locator.toString(), result);
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
index 76113f1..8384b27 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
@@ -1018,25 +1018,20 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has
}
// can't simply return null if server is not using shared configuration, since we need to find
- // out
- // if the locator is running in secure mode or not, if yes, then we need to throw an exception
- // if server is not using cluster config
+ // out if the locator is running in secure mode or not, if yes, then we need to throw an
+ // exception if server is not using cluster config.
- Map<InternalDistributedMember, Collection<String>> scl =
+ Map<InternalDistributedMember, Collection<String>> locatorsWithClusterConfig =
getDistributionManager().getAllHostedLocatorsWithSharedConfiguration();
// If there are no locators with Shared configuration, that means the system has been started
- // without shared configuration
- // then do not make requests to the locators
- if (scl.isEmpty()) {
+ // without shared configuration then do not make requests to the locators.
+ if (locatorsWithClusterConfig.isEmpty()) {
logger.info(LocalizedMessage
.create(LocalizedStrings.GemFireCache_NO_LOCATORS_FOUND_WITH_SHARED_CONFIGURATION));
return null;
}
- Map<InternalDistributedMember, Collection<String>> locatorsWithClusterConfig =
- getDistributionManager().getAllHostedLocatorsWithSharedConfiguration();
-
try {
ConfigurationResponse response = ccLoader.requestConfigurationFromLocators(
this.system.getConfig().getGroups(), locatorsWithClusterConfig.keySet());
@@ -1169,7 +1164,7 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has
ClassPathLoader.setLatestToDefault(this.system.getConfig().getDeployWorkingDir());
try {
- ccLoader.deployJarsReceivedFromClusterConfiguration(this, this.configurationResponse);
+ ccLoader.deployJarsReceivedFromClusterConfiguration(this.configurationResponse);
} catch (IOException | ClassNotFoundException e) {
throw new GemFireConfigException(
LocalizedStrings.GemFireCache_EXCEPTION_OCCURRED_WHILE_DEPLOYING_JARS_FROM_SHARED_CONDFIGURATION
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 9f89ce4..ea6e288 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
@@ -14,6 +14,7 @@
*/
package org.apache.geode.management;
+import java.util.List;
import java.util.Map;
import org.apache.geode.distributed.DistributedMember;
@@ -214,11 +215,11 @@ public interface MemberMXBean {
*
* @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.
+ * @param fileNames Local files (as relevant to the command). May be null.
* @return Result of the execution in JSON format.
*/
@ResourceOperation()
- String processCommand(String commandString, Map<String, String> env, Byte[][] binaryData);
+ String processCommand(String commandString, Map<String, String> env, List<String> fileNames);
/**
* Returns the name of all disk stores in use by this member.
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java b/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java
index 243458d..18e0f93 100755
--- a/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java
@@ -64,6 +64,7 @@ import org.apache.geode.internal.tcp.TCPConduit;
import org.apache.geode.management.ManagementException;
import org.apache.geode.management.ManagementService;
import org.apache.geode.management.ManagerMXBean;
+import org.apache.geode.management.internal.beans.FileUploader;
import org.apache.geode.management.internal.security.AccessControlMBean;
import org.apache.geode.management.internal.security.MBeanServerWrapper;
import org.apache.geode.management.internal.security.ResourceConstants;
@@ -490,6 +491,7 @@ public class ManagementAgent {
ReadOpFileAccessController controller = new ReadOpFileAccessController(accessFile);
controller.setMBeanServer(mbs);
}
+ registerFileUploaderMBean();
}
jmxConnectorServer.start();
@@ -521,6 +523,22 @@ public class ManagementAgent {
}
}
+ private void registerFileUploaderMBean() {
+ try {
+ ObjectName mbeanON = new ObjectName(ManagementConstants.OBJECTNAME__FILEUPLOADER_MBEAN);
+ MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
+
+ Set<ObjectName> names = platformMBeanServer.queryNames(mbeanON, null);
+ if (names.isEmpty()) {
+ platformMBeanServer.registerMBean(new FileUploader(), mbeanON);
+ logger.info("Registered FileUploaderMBean on " + mbeanON);
+ }
+ } catch (InstanceAlreadyExistsException | MBeanRegistrationException
+ | NotCompliantMBeanException | MalformedObjectNameException e) {
+ throw new GemFireConfigException("Error while configuring FileUploader MBean", e);
+ }
+ }
+
public JMXConnectorServer getJmxConnectorServer() {
return jmxConnectorServer;
}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/ManagementConstants.java b/geode-core/src/main/java/org/apache/geode/management/internal/ManagementConstants.java
index 7baa784..54a7a80 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/ManagementConstants.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/ManagementConstants.java
@@ -135,6 +135,9 @@ public interface ManagementConstants {
public static final String OBJECTNAME__CACHESERVICE_MXBEAN =
OBJECTNAME__PREFIX + "service=CacheService,name={0},type=Member,member={1}";
+ public static final String OBJECTNAME__FILEUPLOADER_MBEAN =
+ OBJECTNAME__PREFIX + "service=FileUploader,type=Distributed";
+
public static final String AGGREGATE_MBEAN_PATTERN = OBJECTNAME__PREFIX + "*,type=Distributed";
// Object Name keys
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/beans/FileUploader.java b/geode-core/src/main/java/org/apache/geode/management/internal/beans/FileUploader.java
new file mode 100644
index 0000000..7935a1b
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/beans/FileUploader.java
@@ -0,0 +1,63 @@
+/*
+ * 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.beans;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.PosixFilePermission;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.healthmarketscience.rmiio.RemoteInputStream;
+import com.healthmarketscience.rmiio.RemoteInputStreamClient;
+import org.apache.commons.io.IOUtils;
+
+public class FileUploader implements FileUploaderMBean {
+ @Override
+ public List<String> uploadFile(Map<String, RemoteInputStream> remoteFiles) throws IOException {
+ List<String> stagedFiles = new ArrayList<>();
+
+ Set<PosixFilePermission> perms = new HashSet<>();
+ perms.add(PosixFilePermission.OWNER_READ);
+ perms.add(PosixFilePermission.OWNER_WRITE);
+ perms.add(PosixFilePermission.OWNER_EXECUTE);
+ Path tempDir =
+ Files.createTempDirectory("uploaded-", PosixFilePermissions.asFileAttribute(perms));
+
+ for (String filename : remoteFiles.keySet()) {
+ File stagedFile = new File(tempDir.toString(), filename);
+ FileOutputStream fos = new FileOutputStream(stagedFile);
+
+ InputStream input = RemoteInputStreamClient.wrap(remoteFiles.get(filename));
+ IOUtils.copyLarge(input, fos);
+
+ fos.close();
+ input.close();
+
+ stagedFiles.add(stagedFile.getAbsolutePath());
+ }
+
+ return stagedFiles;
+ }
+}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/beans/FileUploaderMBean.java b/geode-core/src/main/java/org/apache/geode/management/internal/beans/FileUploaderMBean.java
new file mode 100644
index 0000000..e0d0982
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/beans/FileUploaderMBean.java
@@ -0,0 +1,26 @@
+/*
+ * 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.beans;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import com.healthmarketscience.rmiio.RemoteInputStream;
+
+public interface FileUploaderMBean {
+ List<String> uploadFile(Map<String, RemoteInputStream> remoteFiles) throws IOException;
+}
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 19a76aa..3d66b1d 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
@@ -15,11 +15,11 @@
package org.apache.geode.management.internal.beans;
import java.util.Collections;
+import java.util.List;
import java.util.Map;
import javax.management.NotificationBroadcasterSupport;
-import org.apache.geode.internal.util.ArrayUtils;
import org.apache.geode.management.GemFireProperties;
import org.apache.geode.management.JVMMetrics;
import org.apache.geode.management.MemberMXBean;
@@ -402,8 +402,9 @@ public class MemberMBean extends NotificationBroadcasterSupport implements Membe
}
@Override
- public String processCommand(String commandString, Map<String, String> env, Byte[][] binaryData) {
- return bridge.processCommand(commandString, env, ArrayUtils.toBytes(binaryData));
+ public String processCommand(String commandString, Map<String, String> env,
+ List<String> fileNames) {
+ return bridge.processCommand(commandString, env, fileNames);
}
@Override
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBeanBridge.java b/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBeanBridge.java
index 26483bb..4428969 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBeanBridge.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBeanBridge.java
@@ -1565,16 +1565,18 @@ public class MemberMBeanBridge {
*
* @param commandString command string to be processed
* @param env environment information to be used for processing the command
+ * @param fileNames list of local files to be deployed
* @return result of the processing the given command string.
*/
- public String processCommand(String commandString, Map<String, String> env, byte[][] binaryData) {
+ public String processCommand(String commandString, Map<String, String> env,
+ List<String> fileNames) {
if (commandProcessor == null) {
throw new JMRuntimeException(
"Command can not be processed as Command Service did not get initialized. Reason: "
+ commandServiceInitError);
}
- Result result = commandProcessor.executeCommand(commandString, env, binaryData);
+ Result result = commandProcessor.executeCommand(commandString, env, fileNames);
return CommandResponseBuilder.createCommandResponseJson(getMember(), (CommandResult) result);
}
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 8ad2282..0ca70b0 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
@@ -34,6 +34,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.zip.DataFormatException;
@@ -537,7 +538,7 @@ public class CliUtil {
}
/***
- * Executes a function with arguments on a set of members , ignores the departed members.
+ * Executes a function with arguments on a set of members, ignoring the departed members.
*
* @param function Function to be executed.
* @param args Arguments passed to the function, pass null if you wish to pass no arguments to the
@@ -560,6 +561,23 @@ public class CliUtil {
return execution.execute(function);
}
+ /***
+ * Executes a function with arguments on a single member, ignoring the departed members.
+ *
+ * @param function Function to be executed.
+ * @param args Arguments passed to the function, pass null if you wish to pass no arguments to the
+ * function.
+ * @param member The member on which the function is to be executed.
+ *
+ * @return ResultCollector
+ */
+ public static ResultCollector<?, ?> executeFunction(Function function, Object args,
+ DistributedMember member) {
+ Set<DistributedMember> members = new HashSet<>();
+ members.add(member);
+ return executeFunction(function, args, members);
+ }
+
/**
* Returns a Set of DistributedMember for members that have the specified <code>region</code>.
* <code>returnAll</code> indicates whether to return all members or only the first member we
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/CommandRequest.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/CommandRequest.java
index a9772e8..b80ac23 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/CommandRequest.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/CommandRequest.java
@@ -14,7 +14,9 @@
*/
package org.apache.geode.management.internal.cli;
+import java.io.File;
import java.util.Collections;
+import java.util.List;
import java.util.Map;
import org.apache.geode.annotations.TestingOnly;
@@ -30,7 +32,7 @@ import org.apache.geode.management.cli.CliMetaData;
*/
@SuppressWarnings("unused")
public class CommandRequest {
- private final byte[][] fileData;
+ private final List<File> fileList;
private final GfshParseResult parseResult;
private final Map<String, String> env;
private final boolean downloadFile;
@@ -39,24 +41,24 @@ public class CommandRequest {
@TestingOnly
public CommandRequest(final Map<String, String> env) {
this.env = env;
- this.fileData = null;
+ this.fileList = null;
this.parseResult = null;
downloadFile = false;
}
- public CommandRequest(final Map<String, String> env, final byte[][] fileData) {
+ public CommandRequest(final Map<String, String> env, final List<File> fileData) {
this.env = env;
- this.fileData = fileData;
+ this.fileList = fileData;
this.parseResult = null;
downloadFile = false;
}
public CommandRequest(final GfshParseResult parseResult, final Map<String, String> env,
- final byte[][] fileData) {
+ final List<File> fileData) {
assert parseResult != null : "The Gfsh ParseResult cannot be null!";
assert env != null : "The reference to the Gfsh CLI environment cannot be null!";
this.env = env;
- this.fileData = fileData;
+ this.fileList = fileData;
this.parseResult = parseResult;
CliMetaData metaData = parseResult.getMethod().getDeclaredAnnotation(CliMetaData.class);
@@ -73,12 +75,12 @@ public class CommandRequest {
return Collections.unmodifiableMap(env);
}
- public byte[][] getFileData() {
- return fileData;
+ public List<File> getFileList() {
+ return fileList;
}
public boolean hasFileData() {
- return (getFileData() != null);
+ return (getFileList() != null);
}
protected GfshParseResult getParseResult() {
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
index 5ee16fa..a002cdd 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
@@ -17,13 +17,18 @@ package org.apache.geode.management.internal.cli.commands;
import static org.apache.commons.io.FileUtils.ONE_MB;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.IOException;
+import java.rmi.RemoteException;
import java.text.DecimalFormat;
-import java.util.Arrays;
+import java.util.ArrayList;
import java.util.List;
import java.util.Set;
+import com.healthmarketscience.rmiio.RemoteInputStream;
+import com.healthmarketscience.rmiio.SimpleRemoteInputStream;
+import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.shell.core.annotation.CliCommand;
@@ -69,48 +74,56 @@ public class DeployCommand implements GfshCommand {
optionContext = ConverterHint.MEMBERGROUP) String[] groups,
@CliOption(key = {CliStrings.JAR, CliStrings.JARS},
help = CliStrings.DEPLOY__JAR__HELP) String[] jars,
- @CliOption(key = {CliStrings.DEPLOY__DIR}, help = CliStrings.DEPLOY__DIR__HELP) String dir) {
+ @CliOption(key = {CliStrings.DEPLOY__DIR}, help = CliStrings.DEPLOY__DIR__HELP) String dir)
+ throws FileNotFoundException, RemoteException {
TabularResultData tabularData = ResultBuilder.createTabularResultData();
- byte[][] shellBytesData = CommandExecutionContext.getBytesFromShell();
- String[] jarNames = CliUtil.bytesToNames(shellBytesData);
- byte[][] jarBytes = CliUtil.bytesToData(shellBytesData);
+ List<String> jarFullPaths = CommandExecutionContext.getFilePathFromShell();
Set<DistributedMember> targetMembers;
-
targetMembers = CliUtil.findMembers(groups, null);
- if (targetMembers.size() > 0) {
+ List results = new ArrayList();
+ for (DistributedMember member : targetMembers) {
+ List<RemoteInputStream> remoteStreams = new ArrayList<>();
+ List<String> jarNames = new ArrayList<>();
+ for (int i = 0; i < jarFullPaths.size(); i++) {
+ remoteStreams
+ .add(new SimpleRemoteInputStream(new FileInputStream(jarFullPaths.get(i))).export());
+ jarNames.add(FilenameUtils.getName(jarFullPaths.get(i)));
+ }
+
// this deploys the jars to all the matching servers
ResultCollector<?, ?> resultCollector = CliUtil.executeFunction(this.deployFunction,
- new Object[] {jarNames, jarBytes}, targetMembers);
+ new Object[] {jarNames, remoteStreams}, member);
- List<CliFunctionResult> results =
- CliFunctionResult.cleanResults((List<?>) resultCollector.getResult());
+ results.add(((List) resultCollector.getResult()).get(0));
+ }
- for (CliFunctionResult result : results) {
- if (result.getThrowable() != null) {
+ List<CliFunctionResult> cleanedResults = CliFunctionResult.cleanResults(results);
+
+ for (CliFunctionResult result : cleanedResults) {
+ if (result.getThrowable() != null) {
+ tabularData.accumulate("Member", result.getMemberIdOrName());
+ tabularData.accumulate("Deployed JAR", "");
+ tabularData.accumulate("Deployed JAR Location",
+ "ERROR: " + result.getThrowable().getClass().getName() + ": "
+ + result.getThrowable().getMessage());
+ tabularData.setStatus(Result.Status.ERROR);
+ } else {
+ String[] strings = (String[]) result.getSerializables();
+ for (int i = 0; i < strings.length; i += 2) {
tabularData.accumulate("Member", result.getMemberIdOrName());
- tabularData.accumulate("Deployed JAR", "");
- tabularData.accumulate("Deployed JAR Location",
- "ERROR: " + result.getThrowable().getClass().getName() + ": "
- + result.getThrowable().getMessage());
- tabularData.setStatus(Result.Status.ERROR);
- } else {
- String[] strings = (String[]) result.getSerializables();
- for (int i = 0; i < strings.length; i += 2) {
- tabularData.accumulate("Member", result.getMemberIdOrName());
- tabularData.accumulate("Deployed JAR", strings[i]);
- tabularData.accumulate("Deployed JAR Location", strings[i + 1]);
- }
+ tabularData.accumulate("Deployed JAR", strings[i]);
+ tabularData.accumulate("Deployed JAR Location", strings[i + 1]);
}
}
}
Result result = ResultBuilder.buildResult(tabularData);
persistClusterConfiguration(result,
- () -> getSharedConfiguration().addJarsToThisLocator(jarNames, jarBytes, groups));
+ () -> getSharedConfiguration().addJarsToThisLocator(jarFullPaths, groups));
return result;
}
@@ -122,10 +135,8 @@ public class DeployCommand implements GfshCommand {
@Override
public Result preExecution(GfshParseResult parseResult) {
- // 2nd argument is the jar
- String[] jars = (String[]) parseResult.getArguments()[1];
- // 3rd argument is the dir
- String dir = (String) parseResult.getArguments()[2];
+ String[] jars = (String[]) parseResult.getParamValue("jar");
+ String dir = (String) parseResult.getParamValue("dir");
if (ArrayUtils.isEmpty(jars) && StringUtils.isBlank(dir)) {
return ResultBuilder.createUserErrorResult(
@@ -137,34 +148,37 @@ public class DeployCommand implements GfshCommand {
.createUserErrorResult("Parameters \"jar\" and \"dir\" can not both be specified.");
}
- FileResult fileResult;
- String[] filesToUpload = jars;
- if (filesToUpload == null) {
- filesToUpload = new String[] {dir};
- }
- try {
-
- fileResult = new FileResult(filesToUpload);
- } catch (FileNotFoundException fnfex) {
- return ResultBuilder
- .createGemFireErrorResult("'" + Arrays.toString(filesToUpload) + "' not found.");
- } catch (IOException ioex) {
- return ResultBuilder.createGemFireErrorResult("I/O error when reading jar/dir: "
- + ioex.getClass().getName() + ": " + ioex.getMessage());
+ FileResult fileResult = new FileResult();
+ if (jars != null) {
+ for (String jar : jars) {
+ File jarFile = new File(jar);
+ if (!jarFile.exists()) {
+ return ResultBuilder.createUserErrorResult(jar + " not found.");
+ }
+ fileResult.addFile(jarFile);
+ }
+ } else {
+ File fileDir = new File(dir);
+ if (!fileDir.isDirectory()) {
+ return ResultBuilder.createUserErrorResult(dir + " is not a directory");
+ }
+ File[] childJarFile = fileDir.listFiles(CliUtil.JAR_FILE_FILTER);
+ for (File file : childJarFile) {
+ fileResult.addFile(file);
+ }
}
- // Only do this additional check if a dir was provided
- if (dir != null) {
- String message =
- "\nDeploying files: " + fileResult.getFormattedFileList() + "\nTotal file size is: "
- + this.numFormatter.format((double) fileResult.computeFileSizeTotal() / ONE_MB)
- + "MB\n\nContinue? ";
+ // check if user wants to upload with the computed file size
+ String message =
+ "\nDeploying files: " + fileResult.getFormattedFileList() + "\nTotal file size is: "
+ + this.numFormatter.format((double) fileResult.computeFileSizeTotal() / ONE_MB)
+ + "MB\n\nContinue? ";
- if (readYesNo(message, Response.YES) == Response.NO) {
- return ResultBuilder.createShellClientAbortOperationResult(
- "Aborted deploy of " + Arrays.toString(filesToUpload) + ".");
- }
+ if (readYesNo(message, Response.YES) == Response.NO) {
+ return ResultBuilder.createShellClientAbortOperationResult(
+ "Aborted deploy of " + fileResult.getFormattedFileList() + ".");
}
+
return fileResult;
}
}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
index e85c1ae..f250437 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
@@ -18,7 +18,6 @@ import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toSet;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -151,13 +150,11 @@ public class ExportImportClusterConfigurationCommands implements GfshCommand {
+ regionsWithData.stream().collect(joining(",")));
}
- byte[][] shellBytesData = CommandExecutionContext.getBytesFromShell();
- String zipFileName = CliUtil.bytesToNames(shellBytesData)[0];
- byte[] zipBytes = CliUtil.bytesToData(shellBytesData)[0];
+ List<String> filePathFromShell = CommandExecutionContext.getFilePathFromShell();
Result result;
InfoResultData infoData = ResultBuilder.createInfoResultData();
- File zipFile = new File(zipFileName);
+ File zipFile = new File(filePathFromShell.get(0));
try {
ClusterConfigurationService sc = locator.getSharedConfiguration();
@@ -167,8 +164,7 @@ public class ExportImportClusterConfigurationCommands implements GfshCommand {
}
sc.renameExistingSharedConfigDirectory();
- FileUtils.writeByteArrayToFile(zipFile, zipBytes);
- ZipUtils.unzip(zipFileName, sc.getSharedConfigurationDirPath());
+ ZipUtils.unzip(zipFile.getAbsolutePath(), sc.getSharedConfigurationDirPath());
// load it from the disk
sc.loadSharedConfigurationFromDisk();
@@ -270,17 +266,15 @@ public class ExportImportClusterConfigurationCommands implements GfshCommand {
CliStrings.format(CliStrings.INVALID_FILE_EXTENSION, CliStrings.ZIP_FILE_EXTENSION));
}
- FileResult fileResult;
+ FileResult fileResult = new FileResult();
- try {
- fileResult = new FileResult(new String[] {zip});
- } catch (FileNotFoundException fnfex) {
- return ResultBuilder.createUserErrorResult("'" + zip + "' not found.");
- } catch (IOException ioex) {
- return ResultBuilder
- .createGemFireErrorResult(ioex.getClass().getName() + ": " + ioex.getMessage());
+ File zipFile = new File(zip);
+ if (!zipFile.exists()) {
+ return ResultBuilder.createUserErrorResult(zip + " not found");
}
+ fileResult.addFile(zipFile);
+
return fileResult;
}
}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DeployFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DeployFunction.java
index c9ef06a..156510c 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DeployFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DeployFunction.java
@@ -14,9 +14,25 @@
*/
package org.apache.geode.management.internal.cli.functions;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.PosixFilePermission;
+import java.nio.file.attribute.PosixFilePermissions;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import com.healthmarketscience.rmiio.RemoteInputStream;
+import com.healthmarketscience.rmiio.RemoteInputStreamClient;
+import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.Logger;
import org.apache.geode.SystemFailure;
@@ -44,10 +60,10 @@ public class DeployFunction implements Function, InternalEntity {
try {
final Object[] args = (Object[]) context.getArguments();
- final String[] jarFilenames = (String[]) args[0];
- final byte[][] jarBytes = (byte[][]) args[1];
- InternalCache cache = (InternalCache) context.getCache();
+ final List<String> jarFilenames = (List<String>) args[0];
+ final List<RemoteInputStream> jarStreams = (List<RemoteInputStream>) args[1];
+ InternalCache cache = (InternalCache) context.getCache();
DistributedMember member = cache.getDistributedSystem().getDistributedMember();
memberId = member.getId();
@@ -56,11 +72,21 @@ public class DeployFunction implements Function, InternalEntity {
memberId = member.getName();
}
+ Map<String, File> stagedFiles;
+ try {
+ stagedFiles = stageJarContent(jarFilenames, jarStreams);
+ } catch (IOException ex) {
+ CliFunctionResult result =
+ new CliFunctionResult(memberId, ex, "error staging jars for deployment");
+ context.getResultSender().lastResult(result);
+ return;
+ }
+
List<String> deployedList = new ArrayList<String>();
List<DeployedJar> jarClassLoaders =
- ClassPathLoader.getLatest().getJarDeployer().deploy(jarFilenames, jarBytes);
- for (int i = 0; i < jarFilenames.length; i++) {
- deployedList.add(jarFilenames[i]);
+ ClassPathLoader.getLatest().getJarDeployer().deploy(stagedFiles);
+ for (int i = 0; i < jarFilenames.size(); i++) {
+ deployedList.add(jarFilenames.get(i));
if (jarClassLoaders.get(i) != null) {
deployedList.add(jarClassLoaders.get(i).getFileCanonicalPath());
} else {
@@ -108,4 +134,43 @@ public class DeployFunction implements Function, InternalEntity {
public boolean isHA() {
return false;
}
+
+ private Map<String, File> stageJarContent(List<String> jarNames,
+ List<RemoteInputStream> jarStreams) throws IOException {
+ Map<String, File> stagedJars = new HashMap<>();
+
+ try {
+ Set<PosixFilePermission> perms = new HashSet<>();
+ perms.add(PosixFilePermission.OWNER_READ);
+ perms.add(PosixFilePermission.OWNER_WRITE);
+ perms.add(PosixFilePermission.OWNER_EXECUTE);
+ Path tempDir =
+ Files.createTempDirectory("deploy-", PosixFilePermissions.asFileAttribute(perms));
+
+ for (int i = 0; i < jarNames.size(); i++) {
+ Path tempJar = Paths.get(tempDir.toString(), jarNames.get(i));
+ FileOutputStream fos = new FileOutputStream(tempJar.toString());
+
+ InputStream input = RemoteInputStreamClient.wrap(jarStreams.get(i));
+
+ IOUtils.copyLarge(input, fos);
+
+ fos.close();
+ input.close();
+
+ stagedJars.put(jarNames.get(i), tempJar.toFile());
+ }
+ } catch (IOException iox) {
+ for (int i = 0; i < jarStreams.size(); i++) {
+ try {
+ jarStreams.get(i).close(true);
+ } catch (IOException ex) {
+ // Ignored
+ }
+ }
+ throw iox;
+ }
+
+ return stagedJars;
+ }
}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandExecutionContext.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandExecutionContext.java
index 41456f4..7d32def 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandExecutionContext.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandExecutionContext.java
@@ -15,6 +15,7 @@
package org.apache.geode.management.internal.cli.remote;
import java.util.Collections;
+import java.util.List;
import java.util.Map;
import org.apache.geode.management.internal.cli.CommandResponseWriter;
@@ -29,7 +30,7 @@ public class CommandExecutionContext {
// ThreadLocal variables that can be uses by commands
private static final ThreadLocal<Map<String, String>> ENV = new ThreadLocal<>();
private static final ThreadLocal<Boolean> FROM_SHELL = new ThreadLocal<>();
- private static final ThreadLocal<byte[][]> SHELL_BYTES_DATA = new ThreadLocal<>();
+ private static final ThreadLocal<List<String>> SHELL_FILEPATH = new ThreadLocal<>();
private static final WrapperThreadLocal<CommandResponseWriter> WRITER_WRAPPER =
new WrapperThreadLocal<CommandResponseWriter>() {
@@ -74,12 +75,12 @@ public class CommandExecutionContext {
ENV.set(env);
}
- public static byte[][] getBytesFromShell() {
- return SHELL_BYTES_DATA.get();
+ public static List<String> getFilePathFromShell() {
+ return SHELL_FILEPATH.get();
}
- public static void setBytesFromShell(byte[][] data) {
- SHELL_BYTES_DATA.set(data);
+ public static void setFilePathToShell(List<String> data) {
+ SHELL_FILEPATH.set(data);
}
public static boolean isShellRequest() {
@@ -110,7 +111,7 @@ public class CommandExecutionContext {
ENV.set(null);
FROM_SHELL.set(false);
- SHELL_BYTES_DATA.set(null);
+ SHELL_FILEPATH.set(null);
WRITER_WRAPPER.set(null);
}
}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/OnlineCommandProcessor.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/OnlineCommandProcessor.java
index 7fa4acb..421e525 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/OnlineCommandProcessor.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/OnlineCommandProcessor.java
@@ -17,6 +17,7 @@ package org.apache.geode.management.internal.cli.remote;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Collections;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -95,7 +96,7 @@ public class OnlineCommandProcessor {
return executeCommand(command, env, null);
}
- public Result executeCommand(String command, Map<String, String> env, byte[][] binaryData) {
+ public Result executeCommand(String command, Map<String, String> env, List<String> fileNames) {
CommentSkipHelper commentSkipper = new CommentSkipHelper();
String commentLessLine = commentSkipper.skipComments(command);
if (StringUtils.isEmpty(commentLessLine)) {
@@ -103,7 +104,7 @@ public class OnlineCommandProcessor {
}
CommandExecutionContext.setShellEnv(env);
- CommandExecutionContext.setBytesFromShell(binaryData);
+ CommandExecutionContext.setFilePathToShell(fileNames);
final CommandExecutor commandExecutor = getCommandExecutor();
ParseResult parseResult = parseCommand(commentLessLine);
@@ -121,9 +122,9 @@ public class OnlineCommandProcessor {
resourceOperation.target(), ResourcePermission.ALL);
}
- // this command processor does not exeucte command that needs fileData passed from client
+ // this command processor does not execute command that needs fileData passed from client
CliMetaData metaData = method.getAnnotation(CliMetaData.class);
- if (metaData != null && metaData.isFileUploaded() && binaryData == null) {
+ if (metaData != null && metaData.isFileUploaded() && fileNames == null) {
return ResultBuilder
.createUserErrorResult(command + " can not be executed only from server side");
}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/FileResult.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/FileResult.java
index 8d3ffac..061a5ec 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/FileResult.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/FileResult.java
@@ -14,11 +14,13 @@
*/
package org.apache.geode.management.internal.cli.result;
-import java.io.FileNotFoundException;
+import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
import org.apache.geode.management.cli.Result;
-import org.apache.geode.management.internal.cli.CliUtil;
/**
*
@@ -26,21 +28,15 @@ import org.apache.geode.management.internal.cli.CliUtil;
* @since GemFire 7.0
*/
public class FileResult implements Result {
- private String[] filePaths;
- private int fileIndex;
- private Status status = Status.ERROR;
- private byte[][] localFileData = null;
- private boolean failedToPersist = false;
+ private List<File> files = new ArrayList<>();
- public FileResult(String[] filePathsToRead) throws FileNotFoundException, IOException {
- this.filePaths = filePathsToRead;
- this.localFileData = CliUtil.filesToBytes(filePathsToRead);
- this.status = Status.OK;
+ public void addFile(File file) {
+ files.add(file);
}
@Override
public Status getStatus() {
- return status;
+ return Status.OK;
}
@Override
@@ -48,16 +44,16 @@ public class FileResult implements Result {
@Override
public boolean hasNextLine() {
- return fileIndex < filePaths.length;
+ return false;
}
@Override
public String nextLine() {
- return filePaths[fileIndex++];
+ return "";
}
- public byte[][] toBytes() {
- return localFileData;
+ public List<File> getFile() {
+ return files;
}
/**
@@ -67,8 +63,8 @@ public class FileResult implements Result {
*/
public long computeFileSizeTotal() {
long byteCount = 0;
- for (int i = 1; i < this.localFileData.length; i += 2) {
- byteCount += localFileData[i].length;
+ for (File file : files) {
+ byteCount += file.length();
}
return byteCount;
}
@@ -79,14 +75,7 @@ public class FileResult implements Result {
* @return Comma separated list of files.
*/
public String getFormattedFileList() {
- StringBuffer formattedFileList = new StringBuffer();
- for (int i = 0; i < this.localFileData.length; i += 2) {
- formattedFileList.append(new String(this.localFileData[i]));
- if (i < this.localFileData.length - 2) {
- formattedFileList.append(", ");
- }
- }
- return formattedFileList.toString();
+ return files.stream().map(File::getName).collect(Collectors.joining(","));
}
@Override
@@ -97,17 +86,16 @@ public class FileResult implements Result {
@Override
public void saveIncomingFiles(String directory)
throws UnsupportedOperationException, IOException {
- // dump file data if any
- CliUtil.bytesToFiles(localFileData, directory, true);
+ throw new UnsupportedOperationException("not supported");
}
@Override
public boolean failedToPersist() {
- return this.failedToPersist;
+ return false;
}
@Override
public void setCommandPersisted(boolean commandPersisted) {
- this.failedToPersist = !commandPersisted;
+ throw new UnsupportedOperationException("not supported");
}
}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/GfshExecutionStrategy.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/GfshExecutionStrategy.java
index 592c389..e5c41c3 100755
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/GfshExecutionStrategy.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/GfshExecutionStrategy.java
@@ -14,8 +14,11 @@
*/
package org.apache.geode.management.internal.cli.shell;
+import java.io.File;
import java.lang.reflect.Method;
+import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
@@ -148,7 +151,7 @@ public class GfshExecutionStrategy implements ExecutionStrategy {
return null;
}
- byte[][] fileData = null;
+ List<File> fileData = null;
CliAroundInterceptor interceptor = null;
String interceptorClass = getInterceptor(parseResult.getMethod());
@@ -174,7 +177,7 @@ public class GfshExecutionStrategy implements ExecutionStrategy {
// when the preExecution yields a FileResult, we will get the fileData out of it
if (preExecResult instanceof FileResult) {
FileResult fileResult = (FileResult) preExecResult;
- fileData = fileResult.toBytes();
+ fileData = fileResult.getFile();
}
}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java
index 6c0b304..975f9cf 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java
@@ -14,10 +14,13 @@
*/
package org.apache.geode.management.internal.cli.shell;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@@ -41,14 +44,17 @@ import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.rmi.ssl.SslRMIClientSocketFactory;
+import com.healthmarketscience.rmiio.RemoteInputStream;
+import com.healthmarketscience.rmiio.SimpleRemoteInputStream;
+
import org.apache.geode.internal.admin.SSLConfig;
import org.apache.geode.internal.net.SSLConfigurationFactory;
import org.apache.geode.internal.security.SecurableCommunicationChannel;
-import org.apache.geode.internal.util.ArrayUtils;
import org.apache.geode.management.DistributedSystemMXBean;
import org.apache.geode.management.MemberMXBean;
import org.apache.geode.management.internal.MBeanJMXAdapter;
import org.apache.geode.management.internal.ManagementConstants;
+import org.apache.geode.management.internal.beans.FileUploaderMBean;
import org.apache.geode.management.internal.cli.CommandRequest;
import org.apache.geode.management.internal.cli.LogWrapper;
@@ -80,6 +86,7 @@ public class JmxOperationInvoker implements OperationInvoker {
// MBean Proxies
private DistributedSystemMXBean distributedSystemMXBeanProxy;
private MemberMXBean memberMXBeanProxy;
+ private FileUploaderMBean fileUploadMBeanProxy;
private ObjectName managerMemberObjectName;
@@ -159,6 +166,9 @@ public class JmxOperationInvoker implements OperationInvoker {
} else {
this.memberMXBeanProxy =
JMX.newMXBeanProxy(mbsc, managerMemberObjectName, MemberMXBean.class);
+ this.fileUploadMBeanProxy = JMX.newMBeanProxy(mbsc,
+ new ObjectName(ManagementConstants.OBJECTNAME__FILEUPLOADER_MBEAN),
+ FileUploaderMBean.class);
}
}
@@ -245,13 +255,27 @@ public class JmxOperationInvoker implements OperationInvoker {
}
@Override
- public Object processCommand(final CommandRequest commandRequest) throws JMXInvocationException {
- Byte[][] binaryData = null;
- if (commandRequest.hasFileData()) {
- binaryData = ArrayUtils.toByteArray(commandRequest.getFileData());
+ public Object processCommand(final CommandRequest commandRequest) {
+ // upload the files first
+
+ List<String> stagedFilePaths = null;
+ try {
+ if (commandRequest.hasFileData()) {
+ Map<String, RemoteInputStream> remoteFiles = new HashMap<>();
+
+ for (File file : commandRequest.getFileList()) {
+ RemoteInputStream ris = new SimpleRemoteInputStream(new FileInputStream(file)).export();
+ remoteFiles.put(file.getName(), ris);
+ }
+
+ stagedFilePaths = fileUploadMBeanProxy.uploadFile(remoteFiles);
+ }
+ } catch (IOException e) {
+ throw new JMXInvocationException("Unable to upload file", e);
}
+
return memberMXBeanProxy.processCommand(commandRequest.getUserInput(),
- commandRequest.getEnvironment(), binaryData);
+ commandRequest.getEnvironment(), stagedFilePaths);
}
@Override
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DownloadJarFunction.java
similarity index 60%
rename from geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java
rename to geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DownloadJarFunction.java
index 56225ca..fd93ecb 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DownloadJarFunction.java
@@ -15,19 +15,28 @@
*/
package org.apache.geode.management.internal.configuration.functions;
-import java.util.List;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.rmi.RemoteException;
+import com.healthmarketscience.rmiio.GZIPRemoteInputStream;
+import com.healthmarketscience.rmiio.RemoteInputStream;
+import com.healthmarketscience.rmiio.RemoteInputStreamServer;
+import com.healthmarketscience.rmiio.SimpleRemoteInputStream;
import org.apache.logging.log4j.Logger;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.cache.execute.FunctionException;
import org.apache.geode.distributed.Locator;
import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.distributed.internal.InternalLocator;
import org.apache.geode.internal.InternalEntity;
import org.apache.geode.internal.logging.LogService;
-public class UploadJarFunction implements Function<Object[]>, InternalEntity {
+public class DownloadJarFunction implements Function<Object[]>, InternalEntity {
private static final Logger logger = LogService.getLogger();
private static final long serialVersionUID = 1L;
@@ -39,24 +48,41 @@ public class UploadJarFunction implements Function<Object[]>, InternalEntity {
String group = (String) args[0];
String jarName = (String) args[1];
- byte[] jarBytes = null;
+ RemoteInputStream result = null;
if (locator != null && group != null && jarName != null) {
ClusterConfigurationService sharedConfig = locator.getSharedConfiguration();
if (sharedConfig != null) {
try {
- jarBytes = sharedConfig.getJarBytesFromThisLocator(group, jarName);
- context.getResultSender().lastResult(jarBytes);
+ File jarFile = sharedConfig.getPathToJarOnThisLocator(group, jarName).toFile();
+
+ RemoteInputStreamServer istream = null;
+ try {
+ istream =
+ new SimpleRemoteInputStream(new BufferedInputStream(new FileInputStream(jarFile)));
+ result = istream.export();
+ istream = null;
+ } catch (FileNotFoundException | RemoteException ex) {
+ throw new FunctionException(ex);
+ } finally {
+ // we will only close the stream here if the server fails before
+ // returning an exported stream
+ if (istream != null) {
+ istream.close();
+ }
+ }
} catch (Exception e) {
logger.error(e);
throw new IllegalStateException(e.getMessage());
}
}
}
+
+ context.getResultSender().lastResult(result);
}
@Override
public String getId() {
- return UploadJarFunction.class.getName();
+ return DownloadJarFunction.class.getName();
}
}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/GetClusterConfigurationFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/GetClusterConfigurationFunction.java
index bc7ab6b..c64e876 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/GetClusterConfigurationFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/GetClusterConfigurationFunction.java
@@ -55,7 +55,7 @@ public class GetClusterConfigurationFunction implements Function {
clusterConfigurationService.createConfigurationResponse(groups);
context.getResultSender().lastResult(response);
} catch (IOException e) {
- logger.error("Unable to retrieve the cluster configuraton", e);
+ logger.error("Unable to retrieve the cluster configuration", e);
context.getResultSender().lastResult(e);
}
}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/ConfigurationResponse.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/ConfigurationResponse.java
index a7188b2..bfc3c14 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/ConfigurationResponse.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/ConfigurationResponse.java
@@ -18,6 +18,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
@@ -30,8 +31,10 @@ import javax.xml.transform.TransformerFactoryConfigurationError;
import org.apache.commons.lang.StringUtils;
import org.xml.sax.SAXException;
+import org.apache.geode.DataSerializable;
import org.apache.geode.DataSerializer;
import org.apache.geode.InternalGemFireError;
+import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.internal.DataSerializableFixedID;
import org.apache.geode.internal.Version;
import org.apache.geode.management.internal.configuration.domain.Configuration;
@@ -39,11 +42,13 @@ import org.apache.geode.management.internal.configuration.utils.XmlUtils;
public class ConfigurationResponse implements DataSerializableFixedID {
- private Map<String, Configuration> requestedConfiguration = new HashMap<String, Configuration>();
- private byte[][] jarBytes;
- private String[] jarNames;
+ private Map<String, Configuration> requestedConfiguration = new HashMap<>();
+ private Map<String, Set<String>> jarNames = new HashMap<>();
private boolean failedToGetSharedConfig = false;
+ // This is set to the member from which this object was received
+ private transient DistributedMember member;
+
@Override
public int getDSFID() {
return DataSerializableFixedID.CONFIGURATION_RESPONSE;
@@ -51,17 +56,15 @@ public class ConfigurationResponse implements DataSerializableFixedID {
@Override
public void toData(DataOutput out) throws IOException {
- DataSerializer.writeHashMap((HashMap<?, ?>) requestedConfiguration, out);
- DataSerializer.writeStringArray(jarNames, out);
- DataSerializer.writeArrayOfByteArrays(jarBytes, out);
+ DataSerializer.writeHashMap(requestedConfiguration, out);
+ DataSerializer.writeHashMap(jarNames, out);
DataSerializer.writeBoolean(Boolean.valueOf(failedToGetSharedConfig), out);
}
@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
this.requestedConfiguration = DataSerializer.readHashMap(in);
- this.jarNames = DataSerializer.readStringArray(in);
- this.jarBytes = DataSerializer.readArrayOfByteArrays(in);
+ this.jarNames = DataSerializer.readHashMap(in);
this.failedToGetSharedConfig = DataSerializer.readBoolean(in);
}
@@ -126,18 +129,20 @@ public class ConfigurationResponse implements DataSerializableFixedID {
return sb.toString();
}
+ public void addJar(String group, Set<String> jarNames) {
+ this.jarNames.put(group, jarNames);
+ }
- public String[] getJarNames() {
- return this.jarNames;
+ public Map<String, Set<String>> getJarNames() {
+ return jarNames;
}
- public byte[][] getJars() {
- return this.jarBytes;
+ public DistributedMember getMember() {
+ return member;
}
- public void addJarsToBeDeployed(String[] jarNames, byte[][] jarBytes) {
- this.jarNames = jarNames;
- this.jarBytes = jarBytes;
+ public void setMember(DistributedMember member) {
+ this.member = member;
}
public Version[] getSerializationVersions() {
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/AbstractCommandsController.java b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/AbstractCommandsController.java
index 735c584..ae5ed29 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/AbstractCommandsController.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/AbstractCommandsController.java
@@ -14,11 +14,21 @@
*/
package org.apache.geode.management.internal.web.controllers;
+import java.io.File;
+import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
-import java.lang.management.ManagementFactory;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.PosixFilePermission;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.management.InstanceNotFoundException;
import javax.management.JMX;
@@ -33,14 +43,11 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.InitBinder;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.multipart.MultipartFile;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.logging.LogService;
-import org.apache.geode.internal.logging.log4j.LogMarker;
-import org.apache.geode.internal.security.SecurityService;
-import org.apache.geode.internal.util.ArrayUtils;
import org.apache.geode.management.DistributedSystemMXBean;
import org.apache.geode.management.ManagementService;
import org.apache.geode.management.MemberMXBean;
@@ -48,11 +55,9 @@ import org.apache.geode.management.internal.MBeanJMXAdapter;
import org.apache.geode.management.internal.ManagementAgent;
import org.apache.geode.management.internal.SystemManagementService;
import org.apache.geode.management.internal.cli.shell.Gfsh;
-import org.apache.geode.management.internal.security.MBeanServerWrapper;
import org.apache.geode.management.internal.web.controllers.support.LoginHandlerInterceptor;
import org.apache.geode.management.internal.web.util.UriUtils;
import org.apache.geode.security.AuthenticationFailedException;
-import org.apache.geode.security.GemFireSecurityException;
import org.apache.geode.security.NotAuthorizedException;
/**
@@ -232,18 +237,30 @@ public abstract class AbstractCommandsController {
* Gfsh, the key/value pair (APP_NAME=gfsh) is a specified mapping in the "environment.
* Note, it is common for the REST API to act as a bridge, or an adapter between Gfsh and
* the Manager, and thus need to specify this key/value pair mapping.
- * @param fileData is a two-dimensional byte array containing the pathnames and contents of file
- * data streamed to the Manager, usually for the 'deploy' Gfsh command.
+ * @param multipartFiles uploaded files
* @return a result of the command execution as a String, typically marshalled in JSON to be
* serialized back to Gfsh.
- * @see org.apache.geode.management.MemberMXBean#processCommand(String, java.util.Map, Byte[][])
*/
protected String processCommand(final String command, final Map<String, String> environment,
- final byte[][] fileData) {
- logger.debug(LogMarker.CONFIG,
- "Processing Command ({}) with Environment ({}) having File Data ({})...", command,
- environment, (fileData != null && fileData.length > 0));
+ final MultipartFile[] multipartFiles) throws IOException {
+ List<String> filePaths = null;
+ if (multipartFiles != null) {
+ Set<PosixFilePermission> perms = new HashSet<>();
+ perms.add(PosixFilePermission.OWNER_READ);
+ perms.add(PosixFilePermission.OWNER_WRITE);
+ perms.add(PosixFilePermission.OWNER_EXECUTE);
+ Path tempDir =
+ Files.createTempDirectory("uploaded-", PosixFilePermissions.asFileAttribute(perms));
+ // staging the files to local
+ filePaths = new ArrayList<>();
+ for (MultipartFile multipartFile : multipartFiles) {
+ File dest = new File(tempDir.toFile(), multipartFile.getOriginalFilename());
+ multipartFile.transferTo(dest);
+ filePaths.add(dest.getAbsolutePath());
+ }
+ }
+
MemberMXBean manager = getManagingMemberMXBean();
- return manager.processCommand(command, environment, ArrayUtils.toByteArray(fileData));
+ return manager.processCommand(command, environment, filePaths);
}
}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/ShellCommandsController.java b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/ShellCommandsController.java
index 9c65090..a3c18e0 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/ShellCommandsController.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/ShellCommandsController.java
@@ -20,7 +20,10 @@ import static org.apache.geode.management.internal.web.util.UriUtils.decode;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Set;
+import java.util.stream.Collectors;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
@@ -73,8 +76,7 @@ public class ShellCommandsController extends AbstractCommandsController {
public ResponseEntity<InputStreamResource> command(@RequestParam(value = "cmd") String command,
@RequestParam(value = "resources", required = false) MultipartFile[] fileResource)
throws IOException {
- String result =
- processCommand(decode(command), getEnvironment(), ConvertUtils.convert(fileResource));
+ String result = processCommand(decode(command), getEnvironment(), fileResource);
return getResponse(result);
}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/HttpOperationInvoker.java b/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/HttpOperationInvoker.java
index ce4aaec..0d9d8c5 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/HttpOperationInvoker.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/HttpOperationInvoker.java
@@ -420,7 +420,7 @@ public class HttpOperationInvoker implements OperationInvoker {
if (command.hasFileData()) {
MultiValueMap<String, Object> content = new LinkedMultiValueMap<String, Object>();
- Resource[] resources = ConvertUtils.convert(command.getFileData());
+ Resource[] resources = ConvertUtils.convert(command.getFileList());
for (Resource resource : resources) {
content.add(RESOURCES_REQUEST_PARAMETER, resource);
}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/util/ConvertUtils.java b/geode-core/src/main/java/org/apache/geode/management/internal/web/util/ConvertUtils.java
index b8f5c0c..2d2b991 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/util/ConvertUtils.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/web/util/ConvertUtils.java
@@ -14,12 +14,14 @@
*/
package org.apache.geode.management.internal.web.util;
+import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.springframework.core.io.ByteArrayResource;
+import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile;
@@ -44,7 +46,7 @@ public abstract class ConvertUtils {
* GemFire Manager.
* <p/>
*
- * @param fileData a 2 dimensional byte array of files names and file content.
+ * @param fileList a 2 dimensional byte array of files names and file content.
* @return an array of Spring Resource objects encapsulating the details (name and content) of
* each file being transmitted by Gfsh to the GemFire Manager.
* @see org.springframework.core.io.ByteArrayResource
@@ -52,25 +54,15 @@ public abstract class ConvertUtils {
* @see org.apache.geode.management.internal.cli.CliUtil#bytesToData(byte[][])
* @see org.apache.geode.management.internal.cli.CliUtil#bytesToNames(byte[][])
*/
- public static Resource[] convert(final byte[][] fileData) {
- if (fileData == null) {
+ public static Resource[] convert(final List<File> fileList) {
+ if (fileList == null) {
return new Resource[0];
}
- final String[] fileNames = CliUtil.bytesToNames(fileData);
- final byte[][] fileContent = CliUtil.bytesToData(fileData);
+ final List<Resource> resources = new ArrayList<Resource>();
- final List<Resource> resources = new ArrayList<Resource>(fileNames.length);
-
- for (int index = 0; index < fileNames.length; index++) {
- final String filename = fileNames[index];
- resources.add(new ByteArrayResource(fileContent[index],
- String.format("Contents of JAR file (%1$s).", filename)) {
- @Override
- public String getFilename() {
- return filename;
- }
- });
+ for (File file : fileList) {
+ resources.add(new FileSystemResource(file));
}
return resources.toArray(new Resource[resources.size()]);
diff --git a/geode-core/src/main/resources/org/apache/geode/internal/sanctioned-geode-core-serializables.txt b/geode-core/src/main/resources/org/apache/geode/internal/sanctioned-geode-core-serializables.txt
index 19fea74..84b2721 100644
--- a/geode-core/src/main/resources/org/apache/geode/internal/sanctioned-geode-core-serializables.txt
+++ b/geode-core/src/main/resources/org/apache/geode/internal/sanctioned-geode-core-serializables.txt
@@ -587,7 +587,7 @@ org/apache/geode/management/internal/configuration/domain/SharedConfigurationSta
org/apache/geode/management/internal/configuration/functions/GetClusterConfigurationFunction,false
org/apache/geode/management/internal/configuration/functions/GetRegionNamesFunction,false
org/apache/geode/management/internal/configuration/functions/RecreateCacheFunction,false
-org/apache/geode/management/internal/configuration/functions/UploadJarFunction,true,1
+org/apache/geode/management/internal/configuration/functions/DownloadJarFunction,true,1
org/apache/geode/management/internal/web/domain/QueryParameterSource,true,34131123582155,objectName:javax/management/ObjectName,queryExpression:javax/management/QueryExp
org/apache/geode/management/internal/web/shell/MBeanAccessException,true,813768898269516238
org/apache/geode/memcached/GemFireMemcachedServer$Protocol,false
diff --git a/geode-core/src/test/java/org/apache/geode/internal/ClassPathLoaderIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/internal/ClassPathLoaderIntegrationTest.java
index c442b19..a5aa996 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/ClassPathLoaderIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/ClassPathLoaderIntegrationTest.java
@@ -22,7 +22,10 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -37,6 +40,7 @@ import org.apache.bcel.Constants;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -109,10 +113,10 @@ public class ClassPathLoaderIntegrationTest {
String classAName = "integration.parent.ClassA";
- byte[] firstJarBytes = createJarWithClass("ClassA");
+ File firstJar = createJarWithClass("ClassA");
// First deploy of the JAR file
- ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, firstJarBytes).getFile();
+ ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, firstJar).getFile();
assertThatClassCanBeLoaded(classAName);
assertThatResourceCanBeLoaded(classAResource);
@@ -128,13 +132,15 @@ public class ClassPathLoaderIntegrationTest {
String classAName = "integration.parent.ClassA";
String classBName = "integration.parent.ClassB";
- byte[] firstJarBytes = createJarWithClass("ClassA");
+ File firstJar = createJarWithClass("ClassA");
+ ByteArrayOutputStream firstJarBytes = new ByteArrayOutputStream();
+ IOUtils.copy(new FileInputStream(firstJar), firstJarBytes);
// First deploy of the JAR file
File firstDeployedJarFile =
- ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, firstJarBytes).getFile();
+ ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, firstJar).getFile();
- assertThat(firstDeployedJarFile).exists().hasBinaryContent(firstJarBytes);
+ assertThat(firstDeployedJarFile).exists().hasBinaryContent(firstJarBytes.toByteArray());
assertThat(firstDeployedJarFile.getName()).contains(".v1.").doesNotContain(".v2.");
assertThatClassCanBeLoaded(classAName);
@@ -145,12 +151,14 @@ public class ClassPathLoaderIntegrationTest {
// Now deploy an updated JAR file and make sure that the next version of the JAR file
// was created and the first one is no longer used
- byte[] secondJarBytes = createJarWithClass("ClassB");
+ File secondJar = createJarWithClass("ClassB");
+ ByteArrayOutputStream secondJarBytes = new ByteArrayOutputStream();
+ IOUtils.copy(new FileInputStream(secondJar), secondJarBytes);
File secondDeployedJarFile =
- ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, secondJarBytes).getFile();
+ ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, secondJar).getFile();
- assertThat(secondDeployedJarFile).exists().hasBinaryContent(secondJarBytes);
+ assertThat(secondDeployedJarFile).exists().hasBinaryContent(secondJarBytes.toByteArray());
assertThat(secondDeployedJarFile.getName()).contains(".v2.").doesNotContain(".v1.");
assertThatClassCanBeLoaded(classBName);
@@ -174,8 +182,10 @@ public class ClassPathLoaderIntegrationTest {
// First deploy of the JAR file
byte[] jarBytes = new ClassBuilder().createJarFromName("JarDeployerDUnitDNUWNC");
+ File jarFile = temporaryFolder.newFile();
+ writeJarBytesToFile(jarFile, jarBytes);
DeployedJar jarClassLoader =
- ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, jarBytes);
+ ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, jarFile);
File deployedJar = new File(jarClassLoader.getFileCanonicalPath());
assertThat(deployedJar).exists();
@@ -183,7 +193,7 @@ public class ClassPathLoaderIntegrationTest {
// Re-deploy of the same JAR should do nothing
DeployedJar newJarClassLoader =
- ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, jarBytes);
+ ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, jarFile);
assertThat(newJarClassLoader).isNull();
assertThat(deployedJar).exists();
@@ -274,8 +284,7 @@ public class ClassPathLoaderIntegrationTest {
GemFireCacheImpl gemFireCache = GemFireCacheImpl.getInstance();
DistributedSystem distributedSystem = gemFireCache.getDistributedSystem();
- ClassPathLoader.getLatest().getJarDeployer().deploy("MyJar.jar",
- FileUtils.readFileToByteArray(jarVersion1));
+ ClassPathLoader.getLatest().getJarDeployer().deploy("MyJar.jar", jarVersion1);
assertThatClassCanBeLoaded("jddunit.function.MyFunction");
Execution execution = FunctionService.onMember(distributedSystem.getDistributedMember());
@@ -283,8 +292,7 @@ public class ClassPathLoaderIntegrationTest {
List<String> result = (List<String>) execution.execute("MyFunction").getResult();
assertThat(result.get(0)).isEqualTo("Version1");
- ClassPathLoader.getLatest().getJarDeployer().deploy("MyJar.jar",
- FileUtils.readFileToByteArray(jarVersion2));
+ ClassPathLoader.getLatest().getJarDeployer().deploy("MyJar.jar", jarVersion2);
result = (List<String>) execution.execute("MyFunction").getResult();
assertThat(result.get(0)).isEqualTo("Version2");
@@ -461,7 +469,7 @@ public class ClassPathLoaderIntegrationTest {
@Test
public void testDeclarableFunctionsWithNoCacheXml() throws Exception {
- final String jarName = "JarClassLoaderJUnitNoXml.jar";
+ final String jarFilename = "JarClassLoaderJUnitNoXml.jar";
// Add a Declarable Function without parameters for the class to the Classpath
String functionString =
@@ -478,8 +486,10 @@ public class ClassPathLoaderIntegrationTest {
byte[] jarBytes = this.classBuilder
.createJarFromClassContent("JarClassLoaderJUnitFunctionNoXml", functionString);
+ File jarFile = temporaryFolder.newFile();
+ writeJarBytesToFile(jarFile, jarBytes);
- ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, jarBytes);
+ ClassPathLoader.getLatest().getJarDeployer().deploy(jarFilename, jarFile);
ClassPathLoader.getLatest().forName("JarClassLoaderJUnitFunctionNoXml");
@@ -506,7 +516,8 @@ public class ClassPathLoaderIntegrationTest {
byte[] jarBytes = this.classBuilder.createJarFromClassContent(
"jcljunit/parent/JarClassLoaderJUnitParent", stringBuffer.toString());
writeJarBytesToFile(parentJarFile, jarBytes);
- ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitParent.jar", jarBytes);
+ ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitParent.jar",
+ parentJarFile);
stringBuffer = new StringBuffer();
stringBuffer.append("package jcljunit.uses;");
@@ -517,7 +528,7 @@ public class ClassPathLoaderIntegrationTest {
jarBytes = this.classBuilder.createJarFromClassContent("jcljunit/uses/JarClassLoaderJUnitUses",
stringBuffer.toString());
writeJarBytesToFile(usesJarFile, jarBytes);
- ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitUses.jar", jarBytes);
+ ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitUses.jar", usesJarFile);
stringBuffer = new StringBuffer();
stringBuffer.append("package jcljunit.function;");
@@ -540,9 +551,11 @@ public class ClassPathLoaderIntegrationTest {
functionClassBuilder.addToClassPath(usesJarFile.getAbsolutePath());
jarBytes = functionClassBuilder.createJarFromClassContent(
"jcljunit/function/JarClassLoaderJUnitFunction", stringBuffer.toString());
+ File jarFunction = temporaryFolder.newFile();
+ writeJarBytesToFile(jarFunction, jarBytes);
ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitFunction.jar",
- jarBytes);
+ jarFunction);
Function function = FunctionService.getFunction("JarClassLoaderJUnitFunction");
assertThat(function).isNotNull();
@@ -559,8 +572,9 @@ public class ClassPathLoaderIntegrationTest {
final String fileContent = "FILE CONTENT";
byte[] jarBytes = this.classBuilder.createJarFromFileContent(fileName, fileContent);
- ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitResource.jar",
- jarBytes);
+ File tempJar = temporaryFolder.newFile();
+ writeJarBytesToFile(tempJar, jarBytes);
+ ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitResource.jar", tempJar);
InputStream inputStream = ClassPathLoader.getLatest().getResourceAsStream(fileName);
assertThat(inputStream).isNotNull();
@@ -577,7 +591,9 @@ public class ClassPathLoaderIntegrationTest {
// First use of the JAR file
byte[] jarBytes = this.classBuilder.createJarFromClassContent("JarClassLoaderJUnitTestClass",
"public class JarClassLoaderJUnitTestClass { public Integer getValue5() { return new Integer(5); } }");
- ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitUpdate.jar", jarBytes);
+ File jarFile = temporaryFolder.newFile();
+ writeJarBytesToFile(jarFile, jarBytes);
+ ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitUpdate.jar", jarFile);
Class<?> clazz = ClassPathLoader.getLatest().forName("JarClassLoaderJUnitTestClass");
Object object = clazz.newInstance();
@@ -589,7 +605,9 @@ public class ClassPathLoaderIntegrationTest {
// class is available.
jarBytes = this.classBuilder.createJarFromClassContent("JarClassLoaderJUnitTestClass",
"public class JarClassLoaderJUnitTestClass { public Integer getValue10() { return new Integer(10); } }");
- ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitUpdate.jar", jarBytes);
+ File jarFile2 = temporaryFolder.newFile();
+ writeJarBytesToFile(jarFile2, jarBytes);
+ ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitUpdate.jar", jarFile2);
clazz = ClassPathLoader.getLatest().forName("JarClassLoaderJUnitTestClass");
object = clazz.newInstance();
@@ -678,11 +696,16 @@ public class ClassPathLoaderIntegrationTest {
}
}
- private byte[] createJarWithClass(String className) throws IOException {
+ private File createJarWithClass(String className) throws IOException {
String stringBuilder = "package integration.parent;" + "public class " + className + " {}";
- return new ClassBuilder().createJarFromClassContent("integration/parent/" + className,
- stringBuilder);
+ byte[] jarBytes = new ClassBuilder()
+ .createJarFromClassContent("integration/parent/" + className, stringBuilder);
+
+ File jarFile = temporaryFolder.newFile();
+ IOUtils.copy(new ByteArrayInputStream(jarBytes), new FileOutputStream(jarFile));
+
+ return jarFile;
}
private static class TestResultSender implements ResultSender<Object> {
diff --git a/geode-core/src/test/java/org/apache/geode/internal/ClassPathLoaderTest.java b/geode-core/src/test/java/org/apache/geode/internal/ClassPathLoaderTest.java
index 99acbc9..5525589 100755
--- a/geode-core/src/test/java/org/apache/geode/internal/ClassPathLoaderTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/ClassPathLoaderTest.java
@@ -19,24 +19,33 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Vector;
import org.apache.bcel.Constants;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.generic.ClassGen;
+import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
import org.apache.geode.test.compiler.ClassBuilder;
import org.apache.geode.test.junit.categories.UnitTest;
+import org.apache.geode.test.junit.rules.TemporaryFileRule;
/**
* Unit tests for {@link ClassPathLoader}.
@@ -51,6 +60,9 @@ public class ClassPathLoaderTest {
@Rule
public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+ @Rule
+ public TemporaryFolder tempFolder = new TemporaryFolder();
+
@Before
public void setUp() throws Exception {
System.setProperty(ClassPathLoader.EXCLUDE_TCCL_PROPERTY, "false");
@@ -68,17 +80,28 @@ public class ClassPathLoaderTest {
}
@Test
- public void testZeroLengthFile() throws IOException, ClassNotFoundException {
+ public void testZeroLengthFile() throws IOException {
+ File zeroFile = tempFolder.newFile();
+ zeroFile.createNewFile();
+
+ Map<String, File> jarFiles = new HashMap<>();
+ jarFiles.put("JarDeployerDUnitZLF.jar", zeroFile);
+
assertThatThrownBy(() -> {
- ClassPathLoader.getLatest().getJarDeployer().deploy(new String[] {"JarDeployerDUnitZLF.jar"},
- new byte[][] {new byte[0]});
+ ClassPathLoader.getLatest().getJarDeployer().deploy(jarFiles);
}).isInstanceOf(IllegalArgumentException.class);
- assertThatThrownBy(() -> {
- ClassPathLoader.getLatest().getJarDeployer().deploy(
- new String[] {"JarDeployerDUnitZLF1.jar", "JarDeployerDUnitZLF2.jar"},
- new byte[][] {new ClassBuilder().createJarFromName("JarDeployerDUnitZLF1"), new byte[0]});
+ byte[] validBytes = new ClassBuilder().createJarFromName("JarDeployerDUnitZLF1");
+ File validFile = tempFolder.newFile();
+ IOUtils.copy(new ByteArrayInputStream(validBytes), new FileOutputStream(validFile));
+
+ jarFiles.put("JarDeployerDUnitZLF1.jar", validFile);
+
+ jarFiles.put("JarDeployerDUnitZLF2.jar", zeroFile);
+
+ assertThatThrownBy(() -> {
+ ClassPathLoader.getLatest().getJarDeployer().deploy(jarFiles);
}).isInstanceOf(IllegalArgumentException.class);
}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/DeployedJarJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/DeployedJarJUnitTest.java
index abaa458..f78a6d6 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/DeployedJarJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/DeployedJarJUnitTest.java
@@ -15,7 +15,6 @@
package org.apache.geode.internal;
-import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.File;
@@ -51,22 +50,14 @@ public class DeployedJarJUnitTest {
@Test
public void validJarContentDoesNotThrow() throws Exception {
- new DeployedJar(jarFile, JAR_NAME, expectedJarBytes);
- }
-
- @Test
- public void unexpectedContentThrowsException() throws Exception {
- givenUnexpectedJarFileContents();
-
- assertThatThrownBy(() -> new DeployedJar(jarFile, JAR_NAME, expectedJarBytes))
- .isInstanceOf(IllegalStateException.class);
+ new DeployedJar(jarFile, JAR_NAME);
}
@Test
public void invalidContentThrowsException() throws Exception {
byte[] invalidJarBytes = givenInvalidJarBytes();
- assertThatThrownBy(() -> new DeployedJar(jarFile, JAR_NAME, invalidJarBytes))
+ assertThatThrownBy(() -> new DeployedJar(jarFile, JAR_NAME))
.isInstanceOf(IllegalArgumentException.class);
}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/JarDeployerDeadlockTest.java b/geode-core/src/test/java/org/apache/geode/internal/JarDeployerDeadlockTest.java
index c03b114..e20ca62 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/JarDeployerDeadlockTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/JarDeployerDeadlockTest.java
@@ -16,7 +16,9 @@ package org.apache.geode.internal;
import static org.assertj.core.api.Assertions.assertThat;
+import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.FileOutputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
@@ -25,6 +27,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
+import org.apache.commons.io.IOUtils;
import org.awaitility.Awaitility;
import org.junit.After;
import org.junit.Before;
@@ -68,11 +71,15 @@ public class JarDeployerDeadlockTest {
public void testMultiThreadingDoesNotCauseDeadlock() throws Exception {
// Add two JARs to the classpath
byte[] jarBytes = this.classBuilder.createJarFromName("JarClassLoaderJUnitA");
- ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitA.jar", jarBytes);
+ File jarFile = temporaryFolder.newFile();
+ IOUtils.copy(new ByteArrayInputStream(jarBytes), new FileOutputStream(jarFile));
+ ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitA.jar", jarFile);
jarBytes = this.classBuilder.createJarFromClassContent("com/jcljunit/JarClassLoaderJUnitB",
"package com.jcljunit; public class JarClassLoaderJUnitB {}");
- ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitB.jar", jarBytes);
+ File jarFile2 = temporaryFolder.newFile();
+ IOUtils.copy(new ByteArrayInputStream(jarBytes), new FileOutputStream(jarFile2));
+ ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitB.jar", jarFile2);
String[] classNames = new String[] {"JarClassLoaderJUnitA", "com.jcljunit.JarClassLoaderJUnitB",
"NON-EXISTENT CLASS"};
diff --git a/geode-core/src/test/java/org/apache/geode/internal/JarDeployerIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/internal/JarDeployerIntegrationTest.java
index ed7d23f..90402c1 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/JarDeployerIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/JarDeployerIntegrationTest.java
@@ -20,12 +20,15 @@ package org.apache.geode.internal;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -62,9 +65,10 @@ public class JarDeployerIntegrationTest {
String jarName = "JarDeployerIntegrationTest.jar";
byte[] firstJarBytes = createJarWithClass("ClassA");
+ File jarFile1 = writeJarBytes(firstJarBytes);
// First deploy of the JAR file
- DeployedJar firstDeployedJar = jarDeployer.deployWithoutRegistering(jarName, firstJarBytes);
+ DeployedJar firstDeployedJar = jarDeployer.deployWithoutRegistering(jarName, jarFile1);
assertThat(firstDeployedJar.getFile()).exists().hasBinaryContent(firstJarBytes);
assertThat(firstDeployedJar.getFile().getName()).contains(".v1.").doesNotContain(".v2.");
@@ -72,8 +76,9 @@ public class JarDeployerIntegrationTest {
// Now deploy an updated JAR file and make sure that the next version of the JAR file
// was created
byte[] secondJarBytes = createJarWithClass("ClassB");
+ File jarFile2 = writeJarBytes(secondJarBytes);
- DeployedJar secondDeployedJar = jarDeployer.deployWithoutRegistering(jarName, secondJarBytes);
+ DeployedJar secondDeployedJar = jarDeployer.deployWithoutRegistering(jarName, jarFile2);
File secondDeployedJarFile = new File(secondDeployedJar.getFileCanonicalPath());
assertThat(secondDeployedJarFile).exists().hasBinaryContent(secondJarBytes);
@@ -93,10 +98,11 @@ public class JarDeployerIntegrationTest {
final JarDeployer jarDeployer = new JarDeployer(alternateDir);
final byte[] jarBytes = this.classBuilder.createJarFromName("JarDeployerDUnitDTID");
+ File jarFile = writeJarBytes(jarBytes);
// Test to verify that deployment fails if the directory doesn't exist.
assertThatThrownBy(() -> {
- jarDeployer.deployWithoutRegistering("JarDeployerIntegrationTest.jar", jarBytes);
+ jarDeployer.deployWithoutRegistering("JarDeployerIntegrationTest.jar", jarFile);
}).isInstanceOf(IOException.class).hasMessageContaining("Unable to write to deploy directory:");
}
@@ -106,12 +112,13 @@ public class JarDeployerIntegrationTest {
assertThat(versionedName.getName()).isEqualTo("myJar.v1.jar");
byte[] jarBytes = this.classBuilder.createJarFromName("ClassA");
- File deployedJarFile = jarDeployer.deployWithoutRegistering("myJar.jar", jarBytes).getFile();
+ File jarFile = writeJarBytes(jarBytes);
+ File deployedJarFile = jarDeployer.deployWithoutRegistering("myJar.jar", jarFile).getFile();
assertThat(deployedJarFile.getName()).isEqualTo("myJar.v1.jar");
File secondDeployedJarFile =
- jarDeployer.deployWithoutRegistering("myJar.jar", jarBytes).getFile();
+ jarDeployer.deployWithoutRegistering("myJar.jar", deployedJarFile).getFile();
assertThat(secondDeployedJarFile.getName()).isEqualTo("myJar.v2.jar");
}
@@ -246,5 +253,10 @@ public class JarDeployerIntegrationTest {
assertThat(jarBVersion3).exists();
}
+ private File writeJarBytes(byte[] content) throws IOException {
+ File tempJar = temporaryFolder.newFile();
+ IOUtils.copy(new ByteArrayInputStream(content), new FileOutputStream(tempJar));
+ return tempJar;
+ }
}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/backup/IncrementalBackupDistributedTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/backup/IncrementalBackupDistributedTest.java
index d71bb85..6b09aed 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/backup/IncrementalBackupDistributedTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/backup/IncrementalBackupDistributedTest.java
@@ -21,8 +21,10 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileFilter;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
@@ -36,6 +38,7 @@ import java.util.Set;
import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.RegexFileFilter;
import org.apache.logging.log4j.Logger;
@@ -1002,6 +1005,9 @@ public class IncrementalBackupDistributedTest extends JUnit4CacheTestCase {
final ClassBuilder classBuilder = new ClassBuilder();
final byte[] classBytes = classBuilder.createJarFromName(jarName);
+ File jarFile = tempDir.newFile();
+ IOUtils.copyLarge(new ByteArrayInputStream(classBytes), new FileOutputStream(jarFile));
+
VM vm0 = Host.getHost(0).getVM(0);
/*
@@ -1009,7 +1015,7 @@ public class IncrementalBackupDistributedTest extends JUnit4CacheTestCase {
*/
File deployedJarFile = vm0.invoke(() -> {
DeployedJar deployedJar =
- ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, classBytes);
+ ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, jarFile);
return deployedJar.getFile();
});
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandRedeployDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandRedeployDUnitTest.java
index 45e832f..91c209d 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandRedeployDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandRedeployDUnitTest.java
@@ -209,7 +209,7 @@ public class DeployCommandRedeployDUnitTest {
private static void assertThatCanLoad(String jarName, String className)
throws ClassNotFoundException {
- assertThat(ClassPathLoader.getLatest().getJarDeployer().findDeployedJar(jarName)).isNotNull();
+ assertThat(ClassPathLoader.getLatest().getJarDeployer().getDeployedJar(jarName)).isNotNull();
assertThat(ClassPathLoader.getLatest().forName(className)).isNotNull();
}
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandTest.java
new file mode 100644
index 0000000..18d3c82
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.commands;
+
+import static org.mockito.Mockito.spy;
+
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.apache.geode.test.junit.rules.GfshParserRule;
+
+@Category(UnitTest.class)
+public class DeployCommandTest {
+
+ @ClassRule
+ public static GfshParserRule gfsh = new GfshParserRule();
+
+ private DeployCommand command;
+
+ @Before
+ public void before() {
+ command = spy(DeployCommand.class);
+ }
+
+ @Test
+ public void name() {
+ gfsh.executeAndAssertThat(command, "deploy --jar=abc.jar");
+ }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployWithGroupsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployWithGroupsDUnitTest.java
index 145bbe4..a38d142 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployWithGroupsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployWithGroupsDUnitTest.java
@@ -253,12 +253,12 @@ public class DeployWithGroupsDUnitTest implements Serializable {
}
private void assertThatCanLoad(String jarName, String className) throws ClassNotFoundException {
- assertThat(ClassPathLoader.getLatest().getJarDeployer().findDeployedJar(jarName)).isNotNull();
+ assertThat(ClassPathLoader.getLatest().getJarDeployer().getDeployedJar(jarName)).isNotNull();
assertThat(ClassPathLoader.getLatest().forName(className)).isNotNull();
}
private void assertThatCannotLoad(String jarName, String className) {
- assertThat(ClassPathLoader.getLatest().getJarDeployer().findDeployedJar(jarName)).isNull();
+ assertThat(ClassPathLoader.getLatest().getJarDeployer().getDeployedJar(jarName)).isNull();
assertThatThrownBy(() -> ClassPathLoader.getLatest().forName(className))
.isExactlyInstanceOf(ClassNotFoundException.class);
}
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfig.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfig.java
index 2a6f962..99bbafc 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfig.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfig.java
@@ -160,7 +160,7 @@ public class ClusterConfig implements Serializable {
}
for (String jar : this.getJarNames()) {
- DeployedJar deployedJar = ClassPathLoader.getLatest().getJarDeployer().findDeployedJar(jar);
+ DeployedJar deployedJar = ClassPathLoader.getLatest().getJarDeployer().getDeployedJar(jar);
assertThat(deployedJar).isNotNull();
assertThat(Class.forName(nameOfClassContainedInJar(jar), true,
new URLClassLoader(new URL[] {deployedJar.getFileURL()}))).isNotNull();
@@ -172,7 +172,7 @@ public class ClusterConfig implements Serializable {
for (String jar : undeployedJarNames) {
System.out.println("Verifying undeployed jar: " + jar);
DeployedJar undeployedJar =
- ClassPathLoader.getLatest().getJarDeployer().findDeployedJar(jar);
+ ClassPathLoader.getLatest().getJarDeployer().getDeployedJar(jar);
assertThat(undeployedJar).isNull();
}
});
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/web/controllers/ShellCommandsControllerProcessCommandTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/web/controllers/ShellCommandsControllerProcessCommandTest.java
index 3c4d8ff..f65e899 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/web/controllers/ShellCommandsControllerProcessCommandTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/web/controllers/ShellCommandsControllerProcessCommandTest.java
@@ -18,6 +18,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import org.apache.commons.io.FileUtils;
@@ -31,7 +33,9 @@ import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
+import org.springframework.web.multipart.MultipartFile;
+import org.apache.geode.management.RemoteInputStreamAttribute;
import org.apache.geode.management.internal.cli.CommandResponseBuilder;
import org.apache.geode.management.internal.cli.result.CommandResult;
import org.apache.geode.management.internal.cli.result.ErrorResultData;
@@ -53,7 +57,7 @@ public class ShellCommandsControllerProcessCommandTest {
controller = new ShellCommandsController() {
@Override
protected String processCommand(String command, final Map<String, String> environment,
- byte[][] fileData) {
+ MultipartFile[] fileData) {
return CommandResponseBuilder.createCommandResponseJson("someMember", fakeResult);
}
};
diff --git a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedDataSerializables.txt b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedDataSerializables.txt
index e9a08a5..5194f46 100644
--- a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedDataSerializables.txt
+++ b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedDataSerializables.txt
@@ -2089,8 +2089,8 @@ toData,22,2a2bb600682ab400162bb800692ab400172bb80069b1
toDataPre_GEODE_1_1_1_0,49,2ab400062bb800692ab400032bb8006a2ab400022bb800692ab4001f2bb800692ab400052bb800692ab400042bb80069b1
org/apache/geode/management/internal/configuration/messages/ConfigurationResponse,2
-fromData,36,2a2bb8000eb500042a2bb8000fb500082a2bb80010b5000a2a2bb80011b60012b50005b1
-toData,39,2ab40004c000022bb800072ab400082bb800092ab4000a2bb8000b2ab40005b8000c2bb8000db1
+fromData,28,2a2bb8000bb500042a2bb8000bb500052a2bb8000cb6000db50006b1
+toData,28,2ab400042bb800082ab400052bb800082ab40006b800092bb8000ab1
org/apache/geode/management/internal/configuration/messages/SharedConfigurationStatusRequest,2
fromData,1,b1
@@ -2135,4 +2135,3 @@ toData,9,2ab400022bb80005b1
org/apache/geode/redis/internal/DoubleWrapper,2
fromData,9,2a2bb80004b50002b1
toData,9,2ab400022bb80003b1
-
diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/web/util/ConvertUtilsJUnitTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/web/util/ConvertUtilsJUnitTest.java
index 6c09a2e..11aa070 100644
--- a/geode-web/src/test/java/org/apache/geode/management/internal/web/util/ConvertUtilsJUnitTest.java
+++ b/geode-web/src/test/java/org/apache/geode/management/internal/web/util/ConvertUtilsJUnitTest.java
@@ -84,40 +84,6 @@ public class ConvertUtilsJUnitTest {
}
@Test
- public void testConvertFileData() throws IOException {
- final String[] filenames = {"/path/to/file1.ext", "/path/to/another/file2.ext"};
- final String[] fileContent =
- {"This is the contents of file 1.", "This is the contents of file 2."};
-
- final List<byte[]> fileData = new ArrayList<byte[]>(2);
-
- for (int index = 0; index < filenames.length; index++) {
- fileData.add(filenames[index].getBytes());
- fileData.add(fileContent[index].getBytes());
- }
-
- final Resource[] resources =
- ConvertUtils.convert(fileData.toArray(new byte[fileData.size()][]));
-
- assertNotNull(resources);
- assertEquals(filenames.length, resources.length);
-
- for (int index = 0; index < resources.length; index++) {
- assertEquals(filenames[index], resources[index].getFilename());
- assertEquals(fileContent[index],
- new String(IOUtils.toByteArray(resources[index].getInputStream())));
- }
- }
-
- @Test
- public void testConvertFileDataWithNull() {
- final Resource[] resources = ConvertUtils.convert((byte[][]) null);
-
- assertNotNull(resources);
- assertEquals(0, resources.length);
- }
-
- @Test
public void testConvertMultipartFile() throws IOException {
final MultipartFile[] files = {
createMultipartFile("/path/to/multi-part/file1.txt",
diff --git a/gradle/dependency-versions.properties b/gradle/dependency-versions.properties
index 723a2e5..f5bf44a 100644
--- a/gradle/dependency-versions.properties
+++ b/gradle/dependency-versions.properties
@@ -80,6 +80,7 @@ powermock.version = 1.7.1
protobuf-gradle-plugin.version = 0.8.1
protobuf-java.version = 3.3.1
protoc.version = 3.0.0
+rmiio.version = 2.1.2
selenium.version=3.0.1
shiro.version=1.3.2
slf4j-api.version = 1.7.24
--
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <co...@geode.apache.org>.