V2_0.java [src/java/m/example/externalexe] Revision: Date:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package m.example.externalexe;
import csip.ModelDataService;
import csip.api.server.Executable;
import csip.annotations.*;
import static csip.annotations.ResourceType.*;
import java.io.StringWriter;
import javax.ws.rs.Path;
/**
* External model service. Invoking the mod.exe model with arguments.
* The stdout.txt file will contain the result.
*
* @author od
*/
@Name("externalexe")
@Description("Example of an external model")
@Path("m/externalexe/2.0")
@Polling(first = 2000, next = 2000)
@Resources({
// resource definition for the mod.exe executable
@Resource(file = "${watershed.python3}", id = "py", type = ResourceType.REFERENCE), // arguments in code.
// list all the files (wildcards alowed) that should be captured as output)
@Resource(file = "*stdout.txt *stderr.txt", type = OUTPUT)
})
public class V2_0 extends ModelDataService {
@Override
protected void doProcess() throws Exception {
StringWriter w = new StringWriter();
// get the resource by its 'id'
Executable e = resources().getExe("py");
e.redirectOutput(w);
// provide arguments
e.setArguments("-c", "print('hey')");
// execute it
int ret = e.exec();
System.out.println("ret " + ret);
System.out.println("ret " + w.toString());
// return thye status. The output
}
public static void main(String[] args) throws Exception {
// Config.properties().put("watershed.python3", "python3");
V2_0 s = new V2_0();
s.doProcess();
}
}