V4_0_3.java [src/java/m/prms/model] Revision: d0197f6caae46c208dbd83b9794c19526e453512 Date: Thu Aug 30 16:55:19 MDT 2018
package m.prms.model;
import csip.Executable;
import csip.ModelDataService;
import csip.ServiceException;
import csip.annotations.*;
import static csip.annotations.ResourceType.*;
import javax.ws.rs.Path;
import org.apache.commons.io.FileUtils;
import static m.prms.model.V4_0_3.PRMS_EXE;
/**
* PRMS Service. Execution of the original PRMS model.
*
* @author od
*/
@Name("PRMS")
@Description("Precipitation Runoff Modeling System.")
@Path("m/prms/4.0.3")
@Author(org = "USGS")
@Author(org = "CSU")
@State(State.RELEASED)
@Category("Hydrology")
@Polling(first = 5000, next = 2000)
@Resource(type = EXECUTABLE, file = "/bin/lin-amd64/prms-4.0.3", id = PRMS_EXE)
@Resource(type = OUTPUT, file = "*-stdout.txt *-stderr.txt recharge.* output/*")
public class V4_0_3 extends ModelDataService {
static final String PARM_CONTROL_FILE = "controlfile";
static final String PRMS_EXE = "prms";
@Override
protected void doProcess() throws Exception {
if (!hasParam(PARM_CONTROL_FILE)) {
throw new ServiceException("Missing parameter: " + PARM_CONTROL_FILE);
}
Executable e = getResourceExe(PRMS_EXE);
e.setArguments(getStringParam(PARM_CONTROL_FILE));
if (0 != e.exec()) {
throw new ServiceException("Error executing prms: " + FileUtils.readFileToString(e.stderr()));
}
}
}