geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jensde...@apache.org
Subject [geode] branch develop updated: GEODE-4379: Move RemoteOutputStreamServer from gfsh to the manager (#1341)
Date Fri, 26 Jan 2018 16:33:30 GMT
This is an automated email from the ASF dual-hosted git repository.

jensdeppe pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new af25a80  GEODE-4379: Move RemoteOutputStreamServer from gfsh to the manager (#1341)
af25a80 is described below

commit af25a803528aacccbe47bc4729dff17d3f82fbc4
Author: Jens Deppe <jdeppe@pivotal.io>
AuthorDate: Fri Jan 26 08:33:28 2018 -0800

    GEODE-4379: Move RemoteOutputStreamServer from gfsh to the manager (#1341)
    
    * GEODE-4379: Move RemoteOutputStreamServer from gfsh to the manager
    
    - This flips the deployment of jars from a pull (by server) to a push (from
      gfsh).
    
    * GEODE-4379: Update sanctioned-geode-core-serializables.txt for FileUploader$RemoteFile
---
 .../geode/management/internal/ManagementAgent.java |  2 +-
 .../management/internal/beans/FileUploader.java    | 86 +++++++++++++++-------
 .../internal/beans/FileUploaderMBean.java          |  5 +-
 .../internal/cli/shell/JmxOperationInvoker.java    | 23 ++++--
 .../sanctioned-geode-core-serializables.txt        |  1 +
 .../internal/beans/FileUploaderTest.java           |  4 +-
 6 files changed, 78 insertions(+), 43 deletions(-)

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 1839762..d52ee85 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
@@ -538,7 +538,7 @@ public class ManagementAgent {
 
       Set<ObjectName> names = platformMBeanServer.queryNames(mbeanON, null);
       if (names.isEmpty()) {
-        platformMBeanServer.registerMBean(new FileUploader(), mbeanON);
+        platformMBeanServer.registerMBean(new FileUploader(getRemoteStreamExporter()), mbeanON);
         logger.info("Registered FileUploaderMBean on " + mbeanON);
       }
     } catch (InstanceAlreadyExistsException | MBeanRegistrationException
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
index 929266e..bee1589 100644
--- 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
@@ -15,25 +15,26 @@
 
 package org.apache.geode.management.internal.beans;
 
+import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
+import java.io.Serializable;
 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.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
-import com.healthmarketscience.rmiio.RemoteInputStream;
-import com.healthmarketscience.rmiio.RemoteInputStreamClient;
+import com.healthmarketscience.rmiio.RemoteOutputStream;
+import com.healthmarketscience.rmiio.RemoteOutputStreamMonitor;
+import com.healthmarketscience.rmiio.RemoteOutputStreamServer;
+import com.healthmarketscience.rmiio.SimpleRemoteOutputStream;
+import com.healthmarketscience.rmiio.exporter.RemoteStreamExporter;
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
 import org.apache.logging.log4j.Logger;
 
 import org.apache.geode.internal.logging.LogService;
@@ -42,11 +43,32 @@ import org.apache.geode.security.GemFireSecurityException;
 public class FileUploader implements FileUploaderMBean {
   public static String STAGED_DIR_PREFIX = "uploaded-";
   private static Logger logger = LogService.getLogger();
+  private RemoteStreamExporter exporter;
 
-  @Override
-  public List<String> uploadFile(Map<String, RemoteInputStream> remoteFiles)
throws IOException {
-    List<String> stagedFiles = new ArrayList<>();
+  public static class RemoteFile implements Serializable {
+    private String filename;
+    private RemoteOutputStream outputStream;
+
+    public RemoteFile(String filename, RemoteOutputStream outputStream) {
+      this.filename = filename;
+      this.outputStream = outputStream;
+    }
+
+    public String getFilename() {
+      return filename;
+    }
+
+    public RemoteOutputStream getOutputStream() {
+      return outputStream;
+    }
+  }
 
+  public FileUploader(RemoteStreamExporter exporter) {
+    this.exporter = exporter;
+  }
+
+  @Override
+  public RemoteFile uploadFile(String filename) throws IOException {
     Set<PosixFilePermission> perms = new HashSet<>();
     perms.add(PosixFilePermission.OWNER_READ);
     perms.add(PosixFilePermission.OWNER_WRITE);
@@ -54,20 +76,26 @@ public class FileUploader implements FileUploaderMBean {
     Path tempDir =
         Files.createTempDirectory(STAGED_DIR_PREFIX, PosixFilePermissions.asFileAttribute(perms));
 
-    for (String filename : remoteFiles.keySet()) {
-      File stagedFile = new File(tempDir.toString(), filename);
-      FileOutputStream fos = new FileOutputStream(stagedFile);
+    File stagedFile = new File(tempDir.toString(), filename);
+    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(stagedFile));
 
-      InputStream input = RemoteInputStreamClient.wrap(remoteFiles.get(filename));
-      IOUtils.copyLarge(input, fos);
+    RemoteOutputStreamMonitor monitor = new RemoteOutputStreamMonitor() {
+      @Override
+      public void closed(RemoteOutputStreamServer stream, boolean clean) {
+        try {
+          stream.close(true);
+        } catch (IOException e) {
+          logger.error("error closing RemoteOutputStreamServer", e);
+        }
+      }
+    };
 
-      fos.close();
-      input.close();
+    RemoteOutputStreamServer server = new SimpleRemoteOutputStream(bos, monitor);
+    RemoteOutputStream remoteStream = exporter.export(server);
 
-      stagedFiles.add(stagedFile.getAbsolutePath());
-    }
+    RemoteFile remoteFile = new RemoteFile(stagedFile.getAbsolutePath(), remoteStream);
 
-    return stagedFiles;
+    return remoteFile;
   }
 
   @Override
@@ -76,15 +104,17 @@ public class FileUploader implements FileUploaderMBean {
       return;
     }
 
-    Path parent = Paths.get(files.get(0)).getParent();
-    if (!parent.getFileName().toString().startsWith(STAGED_DIR_PREFIX)) {
-      throw new GemFireSecurityException(
-          String.format("Cannot delete %s, not in the uploaded directory.", files.get(0)));
-    }
-    try {
-      FileUtils.deleteDirectory(parent.toFile());
-    } catch (IOException e) {
-      logger.error(e.getMessage(), e);
+    for (String filename : files) {
+      File file = new File(filename);
+      File parent = file.getParentFile();
+
+      if (!parent.getName().startsWith(STAGED_DIR_PREFIX)) {
+        throw new GemFireSecurityException(
+            String.format("Cannot delete %s, not in the uploaded directory.", filename));
+      }
+
+      FileUtils.deleteQuietly(file);
+      FileUtils.deleteQuietly(parent);
     }
   }
 }
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
index d504058..a213375 100644
--- 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
@@ -17,9 +17,6 @@ package org.apache.geode.management.internal.beans;
 
 import java.io.IOException;
 import java.util.List;
-import java.util.Map;
-
-import com.healthmarketscience.rmiio.RemoteInputStream;
 
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission;
@@ -28,7 +25,7 @@ import org.apache.geode.security.ResourcePermission;
     operation = ResourcePermission.Operation.MANAGE, target = ResourcePermission.Target.DEPLOY)
 public interface FileUploaderMBean {
 
-  List<String> uploadFile(Map<String, RemoteInputStream> remoteFiles) throws
IOException;
+  FileUploader.RemoteFile uploadFile(String filename) throws IOException;
 
   void deleteFiles(List<String> files);
 }
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 538019b..accd552 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
@@ -17,7 +17,9 @@ package org.apache.geode.management.internal.cli.shell;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.text.MessageFormat;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
@@ -45,7 +47,9 @@ import javax.management.remote.JMXServiceURL;
 import javax.rmi.ssl.SslRMIClientSocketFactory;
 
 import com.healthmarketscience.rmiio.RemoteInputStream;
+import com.healthmarketscience.rmiio.RemoteOutputStreamClient;
 import com.healthmarketscience.rmiio.SimpleRemoteInputStream;
+import org.apache.commons.io.IOUtils;
 
 import org.apache.geode.internal.admin.SSLConfig;
 import org.apache.geode.internal.net.SSLConfigurationFactory;
@@ -54,6 +58,7 @@ 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.FileUploader;
 import org.apache.geode.management.internal.beans.FileUploaderMBean;
 import org.apache.geode.management.internal.cli.CommandRequest;
 import org.apache.geode.management.internal.cli.LogWrapper;
@@ -269,19 +274,21 @@ public class JmxOperationInvoker implements OperationInvoker {
 
   @Override
   public Object processCommand(final CommandRequest commandRequest) {
-    // upload the files first
-
     List<String> stagedFilePaths = null;
+
     try {
       if (commandRequest.hasFileList()) {
-        Map<String, RemoteInputStream> remoteFiles = new HashMap<>();
-
+        stagedFilePaths = new ArrayList<>();
         for (File file : commandRequest.getFileList()) {
-          RemoteInputStream ris = new SimpleRemoteInputStream(new FileInputStream(file)).export();
-          remoteFiles.put(file.getName(), ris);
-        }
+          FileUploader.RemoteFile remote = fileUploadMBeanProxy.uploadFile(file.getName());
+          FileInputStream source = new FileInputStream(file);
+
+          OutputStream target = RemoteOutputStreamClient.wrap(remote.getOutputStream());
+          IOUtils.copyLarge(source, target);
+          target.close();
 
-        stagedFilePaths = fileUploadMBeanProxy.uploadFile(remoteFiles);
+          stagedFilePaths.add(remote.getFilename());
+        }
       }
     } catch (IOException e) {
       throw new JMXInvocationException("Unable to upload file", e);
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 c037b0c..e044b65 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
@@ -468,6 +468,7 @@ org/apache/geode/management/internal/JmxManagerLocator$StartJmxManagerFunction,t
 org/apache/geode/management/internal/ManagementAgent$GemFireRMIServerSocketFactory,true,-811909050641332716,bindAddr:java/net/InetAddress
 org/apache/geode/management/internal/ManagementFunction,true,1,mbeanServer:javax/management/MBeanServer,notificationHub:org/apache/geode/management/internal/NotificationHub
 org/apache/geode/management/internal/NotificationKey,false,currentTime:long,objectName:javax/management/ObjectName
+org/apache/geode/management/internal/beans/FileUploader$RemoteFile,false,filename:java/lang/String,outputStream:com/healthmarketscience/rmiio/RemoteOutputStream
 org/apache/geode/management/internal/beans/QueryDataFunction,true,1
 org/apache/geode/management/internal/beans/QueryDataFunction$LocalQueryFunction,true,1,id:java/lang/String,optimizeForWrite:boolean,regionName:java/lang/String,showMembers:boolean,this$0:org/apache/geode/management/internal/beans/QueryDataFunction
 org/apache/geode/management/internal/beans/QueryDataFunction$QueryDataFunctionResult,true,1,compressedBytes:byte[],message:java/lang/String
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/beans/FileUploaderTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/beans/FileUploaderTest.java
index 4f9e97d..a2db199 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/beans/FileUploaderTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/beans/FileUploaderTest.java
@@ -45,7 +45,7 @@ public class FileUploaderTest {
 
   @Before
   public void before() {
-    fileUploader = new FileUploader();
+    fileUploader = new FileUploader(null);
     files = new ArrayList<>();
   }
 
@@ -58,7 +58,7 @@ public class FileUploaderTest {
   }
 
   @Test
-  public void delteFileNotInTheUploadedDir() throws IOException {
+  public void deleteFileNotInTheUploadedDir() throws IOException {
     File file = temporaryFolder.newFile("a.jar");
     files.add(file.getAbsolutePath());
 

-- 
To stop receiving notification emails like this one, please contact
jensdeppe@apache.org.

Mime
View raw message