V4_0_3.java [src/java/m/prms/model] Revision: default Date:
package m.prms.model;
import csip.api.server.Executable;
import csip.ModelDataService;
import csip.api.server.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.PRMS4_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 = PRMS4_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 PRMS4_EXE = "prms";
@Override
protected void doProcess() throws Exception {
if (!parameter().has(PARM_CONTROL_FILE)) {
throw new ServiceException("Missing parameter: " + PARM_CONTROL_FILE);
}
Executable e = resources().getExe(PRMS4_EXE);
e.setArguments(parameter().getString(PARM_CONTROL_FILE));
if (0 != e.exec()) {
throw new ServiceException("Error executing prms: " +
FileUtils.readFileToString(e.stderr(), "UTF-8"));
}
}
}