|
41 | 41 | import java.util.Set;
|
42 | 42 | import java.util.logging.Logger;
|
43 | 43 |
|
| 44 | +import edu.harvard.iq.dataverse.settings.JvmSettings; |
44 | 45 | import org.apache.commons.io.IOUtils;
|
45 | 46 |
|
46 | 47 | import org.apache.commons.lang3.RandomStringUtils;
|
@@ -72,57 +73,33 @@ public class RemoteDataFrameService {
|
72 | 73 |
|
73 | 74 | private static String TMP_TABDATA_FILE_EXT = ".tab";
|
74 | 75 | private static String TMP_RDATA_FILE_EXT = ".RData";
|
75 |
| - |
76 |
| - private static String RSERVE_HOST = null; |
77 |
| - private static String RSERVE_USER = null; |
78 |
| - private static String RSERVE_PWD = null; |
79 |
| - private static int RSERVE_PORT = -1; |
| 76 | + |
| 77 | + // These settings have sane defaults in resources/META-INF/microprofile-config.properties, |
| 78 | + // ready to be overridden by a sysadmin |
| 79 | + private final String RSERVE_HOST; |
| 80 | + private final String RSERVE_USER; |
| 81 | + private final String RSERVE_PWD; |
| 82 | + private final int RSERVE_PORT; |
| 83 | + private final String RSERVE_TMP_DIR; |
80 | 84 |
|
81 | 85 | private static String DATAVERSE_R_FUNCTIONS = "scripts/dataverse_r_functions.R";
|
82 | 86 | private static String DATAVERSE_R_PREPROCESSING = "scripts/preprocess.R";
|
83 |
| - |
84 |
| - public static String LOCAL_TEMP_DIR = System.getProperty("java.io.tmpdir"); |
85 |
| - public static String RSERVE_TMP_DIR=null; |
86 | 87 |
|
87 | 88 | public String PID = null;
|
88 | 89 | public String tempFileNameIn = null;
|
89 | 90 | public String tempFileNameOut = null;
|
90 |
| - |
91 |
| - static { |
92 |
| - |
93 |
| - RSERVE_TMP_DIR = System.getProperty("dataverse.rserve.tempdir"); |
94 |
| - |
95 |
| - if (RSERVE_TMP_DIR == null){ |
96 |
| - RSERVE_TMP_DIR = "/tmp/"; |
97 |
| - } |
98 |
| - |
99 |
| - RSERVE_HOST = System.getProperty("dataverse.rserve.host"); |
100 |
| - if (RSERVE_HOST == null){ |
101 |
| - RSERVE_HOST= "localhost"; |
102 |
| - } |
103 |
| - |
104 |
| - RSERVE_USER = System.getProperty("dataverse.rserve.user"); |
105 |
| - if (RSERVE_USER == null){ |
106 |
| - RSERVE_USER= "rserve"; |
107 |
| - } |
108 |
| - |
109 |
| - RSERVE_PWD = System.getProperty("dataverse.rserve.password"); |
110 |
| - if (RSERVE_PWD == null){ |
111 |
| - RSERVE_PWD= "rserve"; |
112 |
| - } |
113 |
| - |
114 |
| - |
115 |
| - if (System.getProperty("dataverse.rserve.port") == null ){ |
116 |
| - RSERVE_PORT= 6311; |
117 |
| - } else { |
118 |
| - RSERVE_PORT = Integer.parseInt(System.getProperty("dataverse.rserve.port")); |
119 |
| - } |
120 |
| - |
121 |
| - } |
122 |
| - |
123 |
| - |
124 | 91 |
|
125 | 92 | public RemoteDataFrameService() {
|
| 93 | + // These settings have sane defaults in resources/META-INF/microprofile-config.properties, |
| 94 | + // ready to be overridden by a sysadmin. Config sources have their own caches, so adding |
| 95 | + // these here means the setting can be changed dynamically without too much overhead. |
| 96 | + this.RSERVE_HOST = JvmSettings.RSERVE_HOST.lookup(); |
| 97 | + this.RSERVE_USER = JvmSettings.RSERVE_USER.lookup(); |
| 98 | + this.RSERVE_PWD = JvmSettings.RSERVE_PASSWORD.lookup(); |
| 99 | + this.RSERVE_PORT = JvmSettings.RSERVE_PORT.lookup(Integer.class); |
| 100 | + this.RSERVE_TMP_DIR = JvmSettings.RSERVE_TEMPDIR.lookup(); |
| 101 | + |
| 102 | + |
126 | 103 | // initialization
|
127 | 104 | PID = RandomStringUtils.randomNumeric(6);
|
128 | 105 |
|
@@ -703,15 +680,12 @@ public Map<String, String> runDataFrameRequest(RJobRequest jobRequest, RConnecti
|
703 | 680 | public File transferRemoteFile(RConnection connection, String targetFilename,
|
704 | 681 | String tmpFilePrefix, String tmpFileExt, int fileSize) {
|
705 | 682 |
|
706 |
| - // set up a local temp file: |
707 |
| - |
| 683 | + // set up a local temp file: |
708 | 684 | File tmpResultFile = null;
|
709 |
| - String resultFile = tmpFilePrefix + PID + "." + tmpFileExt; |
710 |
| - |
711 | 685 | RFileInputStream rInStream = null;
|
712 | 686 | OutputStream outbr = null;
|
713 | 687 | try {
|
714 |
| - tmpResultFile = new File(LOCAL_TEMP_DIR, resultFile); |
| 688 | + tmpResultFile = File.createTempFile(tmpFilePrefix + PID, "."+tmpFileExt); |
715 | 689 | outbr = new BufferedOutputStream(new FileOutputStream(tmpResultFile));
|
716 | 690 | // open the input stream
|
717 | 691 | rInStream = connection.openFile(targetFilename);
|
|
0 commit comments