@@ -5,6 +5,8 @@ |
package m.rusle2; |
|
import csip.Config; |
+import csip.Executable; |
+import csip.ServiceException; |
import java.io.File; |
import java.io.IOException; |
import java.util.logging.Logger; |
@@ -83,11 +85,51 @@ |
* @return |
* @throws IOException |
*/ |
- int executePyrome(File r2_rsh) throws IOException { |
+ int executePyrome(File r2_rsh, Executable python) throws IOException, ServiceException { |
+ LOG.info("Execute method"); |
+ //String binDir = Config.getString("m.bin.dir", "/tmp/csip/bin"); |
+ |
+ //File romeshell = Binaries.unpackResource("/bin/win-x86/RomeShell.exe", new File(binDir)); |
+ |
+ //Executable python = getResourceExe(V2_0_1.PYTHON); |
+ python.setArguments("rusle2csip.py"); |
+ LOG.info("Executing pyrome rusle2"); |
+ int ret = python.exec(); |
+ LOG.info("executed pyrome rusle2"); |
+ if (ret != 0) { |
+ throw new ServiceException("RUSLE 2 PYTHON error: error executing pyrome:" + ret); |
+ } |
+ |
+// Binaries.unpackResource("/bin/win-x86/RomeDLL.dll", new File(binDir)); |
+// Binaries.unpackResource("/bin/win-x86/pyrome.py", new File(binDir)); |
+// Binaries.unpackResource("/bin/win-x86/_pyrome.pyd", new File(binDir)); |
+// File runpyrome = new File(r2_rsh.getParent() + "/runrusle2.sh"); |
+// String runrusle2 = "winetricks vd=off ; wine /home/ubuntu/.wine/drive_c/Python34/python.exe rusle2csip.py\n"; |
+// FileUtils.writeStringToFile(runpyrome, runrusle2); |
+// runpyrome.setExecutable(true); |
+// pc.exe = "./runrusle2.sh"; |
+// pc.working_dir = r2_rsh.getParent(); |
+// pc.args = new String[]{}; |
+ stdout += "\n" + FileUtils.readFileToString(python.stdout()); |
+ stderr += "\n" + FileUtils.readFileToString(python.stderr()); |
+// LOG.info("Executing pyrome rusle2"); |
+// pc.execute(); |
+// LOG.info("executed pyrome rusle2"); |
+// stdout += "\n" + pc.stdout; |
+// stderr += "\n" + pc.stderr; |
+ LOG.info("stdout: "+ stdout); |
+ LOG.info(("stderr: "+ stderr)); |
+ //LOG.info("rusle2 model run stdout=" + stdout); |
+ LOG.info("exit val: "+ret); |
+ return ret; |
+ } |
+ |
+ int executePyromeLegacy(File r2_rsh) throws IOException, ServiceException { |
LOG.info("Execute method"); |
String binDir = Config.getString("m.bin.dir", "/tmp/csip/bin"); |
|
- //File romeshell = Binaries.unpackResource("/bin/win-x86/RomeShell.exe", new File(binDir)); |
+ File romeshell = Binaries.unpackResource("/bin/win-x86/RomeShell.exe", new File(binDir)); |
+ |
Binaries.unpackResource("/bin/win-x86/RomeDLL.dll", new File(binDir)); |
Binaries.unpackResource("/bin/win-x86/pyrome.py", new File(binDir)); |
Binaries.unpackResource("/bin/win-x86/_pyrome.pyd", new File(binDir)); |
@@ -105,7 +147,6 @@ |
stderr += "\n" + pc.stderr; |
LOG.info("stdout: "+ stdout); |
LOG.info(("stderr: "+ stderr)); |
- //LOG.info("rusle2 model run stdout=" + stdout); |
LOG.info("exit val: "+pc.exitValue); |
return pc.exitValue; |
} |
@@ -7,12 +7,11 @@ |
import c.GIS_DB; |
import c.GIS_DB_Factory; |
import csip.Config; |
+import csip.Executable; |
import csip.ServiceException; |
import java.io.File; |
import java.io.FileOutputStream; |
import java.util.*; |
-import javax.ws.rs.*; |
-import oms3.annotations.*; |
import org.apache.commons.io.FileUtils; |
import org.apache.commons.lang.StringEscapeUtils; |
import org.codehaus.jettison.json.JSONArray; |
@@ -29,13 +28,27 @@ |
import static csip.ModelDataService.REPORT_TYPE; |
import static csip.ModelDataService.REPORT_VALUE; |
import static csip.ModelDataService.VALUE; |
+import csip.annotations.Polling; |
+import csip.annotations.Resource; |
+import csip.annotations.ResourceType; |
+import static csip.annotations.ResourceType.ARCHIVE; |
+import static csip.annotations.ResourceType.FILE; |
+import static csip.annotations.ResourceType.REFERENCE; |
import static util.ErosionConst.*; |
|
import csip.utils.Binaries; |
import csip.utils.JSONUtils; |
import csip.utils.Services; |
-import csip.annotations.Polling; |
import java.util.logging.Level; |
+import javax.ws.rs.Path; |
+import static m.rusle2.V2_0_1.PYROME; |
+import static m.rusle2.V2_0_1.PYROMESRC; |
+import static m.rusle2.V2_0_1.PYTHON; |
+import static m.rusle2.V2_0_1.PYTHONZIP; |
+import static m.rusle2.V2_0_1.ROMEDLL; |
+import oms3.annotations.Description; |
+import oms3.annotations.Name; |
+import oms3.annotations.VersionInfo; |
|
/** |
* REST Web Service. Front end callable. |
@@ -47,11 +60,26 @@ |
@VersionInfo("2.0.1") |
@Path("m/rusle2/2.0.1") |
@Polling(first = 1000, next = 1000) |
+ |
+// Binaries.unpackResource("/bin/win-x86/pyrome.py", new File(binDir)); |
+// Binaries.unpackResource("/bin/win-x86/_pyrome.pyd", new File(binDir)); |
+ |
+@Resource(type = FILE, file = "/bin/win-x86/RomeDLL.dll", id = ROMEDLL) |
+@Resource(type = FILE, file = "/bin/win-x86/pyrome.py", id = PYROMESRC) |
+@Resource(type = FILE, file = "/bin/win-x86/_pyrome.pyd", id = PYROME) |
+@Resource(type = ARCHIVE, file = "/bin/win-x86/Python34.zip", id = PYTHONZIP) |
+@Resource(type = REFERENCE, file = "${csip.dir}/bin/win-x86/Python34/python.exe", wine = true, id = PYTHON) |
+ |
public class V2_0_1 extends ModelDataService { |
|
static final boolean PRODUCTION_MODE = true; |
// |
static final String R2_TMP_FILENAME = "rusle2csip"; |
+ static final String ROMEDLL = "RomeDLL.dll"; |
+ static final String PYROMESRC = "pyrome.py"; |
+ static final String PYROME = "_pyrome.pyd"; |
+ static final String PYTHONZIP = "Python34.zip"; |
+ static final String PYTHON = "python.exe"; |
static final String R2_TMP_FILEEXT = ".py"; |
static final String IO_TIMING_FILENAME = "/tmp/io-timing"; |
static final String IO_TIMING_FILEEXT = ".txt"; |
@@ -146,7 +174,8 @@ |
@Override |
protected void doProcess() throws Exception { |
try { |
- int result = r2run.executePyrome(new File(getWorkspaceDir(), R2_TMP_FILENAME + R2_TMP_FILEEXT)); |
+ Executable python = getResourceExe(V2_0_1.PYTHON); |
+ int result = r2run.executePyrome(new File(getWorkspaceDir(), R2_TMP_FILENAME + R2_TMP_FILEEXT), python); |
} |
catch (Exception e) { |
LOG.log(Level.SEVERE, "ERROR EXECUTING PYTHON-RUSLE2", e); |
@@ -156,7 +185,10 @@ |
|
@Override |
protected String process() throws Exception { |
- int result = r2run.executePyrome(new File(getWorkspaceDir(), R2_TMP_FILENAME + R2_TMP_FILEEXT)); |
+ Executable python = getResourceExe(V2_0_1.PYTHON); |
+ |
+ |
+ int result = r2run.executePyrome(new File(getWorkspaceDir(), R2_TMP_FILENAME + R2_TMP_FILEEXT), python); |
if (result != 0) { |
return EXEC_FAILED; |
} |
@@ -511,7 +543,9 @@ |
FileOutputStream fos = new FileOutputStream(file); |
|
fos.write("import sys\n".getBytes()); |
- fos.write("sys.path.append('/tmp/csip/bin/bin/win-x86/')\n".getBytes()); |
+ // could rewrite this line based on the OS, but python is interpretting it ok on windows |
+ fos.write("sys.path.append('/tmp/csip/bin/win-x86/')\n".getBytes()); |
+ //fos.write("sys.path.append('c:\\\\tmp\\\\csip\\\\bin\\\\win-x86\\\\')\n".getBytes()); |
|
fos.write("from pyrome import *\n".getBytes()); |
fos.write("from time import sleep\n".getBytes()); |
@@ -46,8 +46,7 @@ |
@Polling(first = 25000, next = 2000) |
|
// weps, weps.version is in the csip-conf.file |
-//@Resource(type = EXECUTABLE, file = "/bin/${arch}/${weps.version}/weps.exe", id = WEPS_EXE) |
-@Resource(type = EXECUTABLE, file = "/bin/${arch}/1.3.9/weps.exe", id = WEPS_EXE) |
+@Resource(type = EXECUTABLE, file = "/bin/${arch}/${weps.version}/weps.exe", id = WEPS_EXE) |
//@Resource(type = EXECUTABLE, file = "/bin/${csip.arch}/weps", id = WEPS_EXE) |
////@Resource(type = EXECUTABLE, file = "/bin/lin-amd64/weps-1.3.9", id = WEPS_EXE) |
// cligen |
@@ -81,6 +80,7 @@ |
static final String BOUNDARY_POL = "boundary.pol"; |
static final String DEFAULT_WIND_STATION_DB = "wind_gen_his_upper_US.wdb"; |
static final String STATION_PAR = "station_par"; |
+ static final String ROMEDLL = "RomeDLL.dll"; |
|
// |
// private String binDir = Config.getString("m.bin.dir", "/tmp/csip/bin"); |