use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.
the class StaxJobFactory method createControlFlowScript.
private FlowScript createControlFlowScript(XMLStreamReader cursorTask, Task tmpTask, Map<String, String> variables) throws JobCreationException {
String type = null;
String target = null;
String targetElse = null;
String targetJoin = null;
int event = -1;
for (int i = 0; i < cursorTask.getAttributeCount(); i++) {
String attrName = cursorTask.getAttributeLocalName(i);
if (XMLAttributes.FLOW_BLOCK.matches(attrName)) {
tmpTask.setFlowBlock(FlowBlock.parse(replace(cursorTask.getAttributeValue(i), variables)));
}
}
// <control> => <if> | <loop> | <replicate>
try {
while (cursorTask.hasNext()) {
event = cursorTask.next();
if (event == XMLEvent.START_ELEMENT) {
break;
} else if (event == XMLEvent.END_ELEMENT && XMLTags.FLOW.matches(cursorTask.getLocalName())) {
return null;
}
}
} catch (Exception e) {
throw new JobCreationException(XMLTags.FLOW.getXMLName(), null, e);
}
if (event != XMLEvent.START_ELEMENT) {
throw new JobCreationException(XMLTags.FLOW.getXMLName(), null, null);
}
String tag = null;
// REPLICATE: no attribute
if (XMLTags.FLOW_REPLICATE.matches(cursorTask.getLocalName())) {
type = FlowActionType.REPLICATE.toString();
tag = XMLTags.FLOW_REPLICATE.getXMLName();
} else // IF: attributes TARGET_IF and TARGET_ELSE and TARGET_JOIN
if (XMLTags.FLOW_IF.matches(cursorTask.getLocalName())) {
type = FlowActionType.IF.toString();
tag = XMLTags.FLOW_IF.getXMLName();
for (int i = 0; i < cursorTask.getAttributeCount(); i++) {
String attrName = cursorTask.getAttributeLocalName(i);
if (XMLAttributes.FLOW_TARGET.matches(attrName)) {
target = cursorTask.getAttributeValue(i);
} else if (XMLAttributes.FLOW_ELSE.matches(attrName)) {
targetElse = cursorTask.getAttributeValue(i);
} else if (XMLAttributes.FLOW_CONTINUATION.matches(attrName)) {
targetJoin = cursorTask.getAttributeValue(i);
}
}
} else // LOOP: attribute TARGET
if (XMLTags.FLOW_LOOP.matches(cursorTask.getLocalName())) {
type = FlowActionType.LOOP.toString();
tag = XMLTags.FLOW_LOOP.getXMLName();
for (int i = 0; i < cursorTask.getAttributeCount(); i++) {
String attrName = cursorTask.getAttributeLocalName(i);
if (XMLAttributes.FLOW_TARGET.matches(attrName)) {
target = cursorTask.getAttributeValue(i);
}
}
}
FlowScript sc = null;
Script<?> internalScript;
try {
internalScript = createScript(cursorTask, ScriptType.FLOW, variables);
switch(FlowActionType.parse(type)) {
case IF:
sc = FlowScript.createIfFlowScript(internalScript, target, targetElse, targetJoin);
break;
case REPLICATE:
sc = FlowScript.createReplicateFlowScript(internalScript);
break;
case LOOP:
sc = FlowScript.createLoopFlowScript(internalScript, target);
break;
default:
break;
}
} catch (Exception e) {
throw new JobCreationException(tag, null, e);
}
// </script> --> </if> | </replicate> | </loop>
try {
while (cursorTask.hasNext()) {
event = cursorTask.next();
if (event == XMLEvent.END_ELEMENT) {
break;
}
}
} catch (XMLStreamException e) {
throw new JobCreationException(tag, null, e);
}
if (event != XMLEvent.END_ELEMENT) {
throw new JobCreationException(tag, null, null);
}
return sc;
}
use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.
the class TestRMMonitoring method action.
@Test
public void action() throws Exception {
log("Deployment");
RMMonitorEventReceiver resourceManager = (RMMonitorEventReceiver) rmHelper.getResourceManager();
rmHelper.createNodeSource("TestRMMonitoring");
Set<String> nodesUrls = rmHelper.listAliveNodesUrls();
// we received all event as we are here
log("Test 1 - subscribing only to 'node remove' event");
resourceManager.removeRMEventListener();
resourceManager.addRMEventListener(rmHelper.getEventReceiver(), RMEventType.NODE_REMOVED);
String url = nodesUrls.iterator().next();
BooleanWrapper status = resourceManager.removeNode(url, true);
if (status.getBooleanValue()) {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_REMOVED, 10000);
log("Test 1 - success");
}
NodeSet ns = resourceManager.getAtMostNodes(5, null);
log("Got " + ns.size() + " nodes");
// must not receive "node busy" event
try {
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, 2000);
fail("Must not receive this type of event");
} catch (ProActiveTimeoutException ex) {
log("Test 2 - success");
}
resourceManager.releaseNodes(ns).getBooleanValue();
}
use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.
the class SchedulerStateRest method submit.
/**
* Submits a job to the scheduler
*
* @param sessionId
* a valid session id
* @return the <code>jobid</code> of the newly created job
* @throws IOException
* if the job was not correctly uploaded/stored
*/
@Override
@POST
@Path("{path:submit}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("application/json")
public JobIdData submit(@HeaderParam("sessionid") String sessionId, @PathParam("path") PathSegment pathSegment, MultipartFormDataInput multipart) throws JobCreationRestException, NotConnectedRestException, PermissionRestException, SubmissionClosedRestException, IOException {
try {
Scheduler scheduler = checkAccess(sessionId, "submit");
Map<String, List<InputPart>> formDataMap = multipart.getFormDataMap();
String name = formDataMap.keySet().iterator().next();
File tmpJobFile = null;
try {
// "file"
InputPart part1 = multipart.getFormDataMap().get(name).get(0);
String fileType = part1.getMediaType().toString().toLowerCase();
if (!fileType.contains(MediaType.APPLICATION_XML.toLowerCase())) {
throw new JobCreationRestException("Unknown job descriptor type: " + fileType);
}
// is the name of the browser's input field
InputStream is = part1.getBody(new GenericType<InputStream>() {
});
tmpJobFile = File.createTempFile("job", "d");
JobId jobId;
try (OutputStream outputStream = new FileOutputStream(tmpJobFile)) {
IOUtils.copy(is, outputStream);
Map<String, String> jobVariables = workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment);
WorkflowSubmitter workflowSubmitter = new WorkflowSubmitter(scheduler);
jobId = workflowSubmitter.submit(tmpJobFile, jobVariables);
}
return mapper.map(jobId, JobIdData.class);
} finally {
if (tmpJobFile != null) {
// clean the temporary file
FileUtils.deleteQuietly(tmpJobFile);
}
}
} catch (IOException e) {
throw new IOException("I/O Error: " + e.getMessage(), e);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.
the class SchedulerStateRest method pullFile.
/**
* Either Pulls a file from the given DataSpace to the local file system or
* list the content of a directory if the path refers to a directory In the
* case the path to a file is given, the content of this file will be
* returns as an input stream In the case the path to a directory is given,
* the input stream returned will be a text stream containing at each line
* the content of the directory
*
* @param sessionId
* a valid session id
* @param spaceName
* the name of the data space involved (GLOBAL or USER)
* @param filePath
* the path to the file or directory whose content must be
* received
*/
@Override
public InputStream pullFile(@HeaderParam("sessionid") String sessionId, @PathParam("spaceName") String spaceName, @PathParam("filePath") String filePath) throws IOException, NotConnectedRestException, PermissionRestException {
checkAccess(sessionId, "pullFile");
Session session = dataspaceRestApi.checkSessionValidity(sessionId);
filePath = normalizeFilePath(filePath, null);
FileObject sourcefo = dataspaceRestApi.resolveFile(session, spaceName, filePath);
if (!sourcefo.exists() || !sourcefo.isReadable()) {
RuntimeException ex = new IllegalArgumentException("File " + filePath + " does not exist or is not readable in space " + spaceName);
logger.error(ex);
throw ex;
}
if (sourcefo.getType().equals(FileType.FOLDER)) {
logger.info("[pullFile] reading directory content from " + sourcefo.getURL());
// if it's a folder we return an InputStream listing its content
StringBuilder sb = new StringBuilder();
String nl = System.lineSeparator();
for (FileObject fo : sourcefo.getChildren()) {
sb.append(fo.getName().getBaseName() + nl);
}
return IOUtils.toInputStream(sb.toString());
} else if (sourcefo.getType().equals(FileType.FILE)) {
logger.info("[pullFile] reading file content from " + sourcefo.getURL());
return sourcefo.getContent().getInputStream();
} else {
RuntimeException ex = new IllegalArgumentException("File " + filePath + " has an unsupported type " + sourcefo.getType());
logger.error(ex);
throw ex;
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.
the class SchedulerStateRest method jobResultValue.
/**
* Returns all the task results of this job as a map whose the key is the
* name of the task and its task result.<br>
* If the result cannot be instantiated, the content is replaced by the
* string 'Unknown value type'. To get the serialized form of a given
* result, one has to call the following restful service
* jobs/{jobid}/tasks/{taskname}/result/serializedvalue
*
* @param sessionId
* a valid session id
* @param jobId
* a job id
*/
@Override
@GET
@GZIP
@Path("jobs/{jobid}/result/value")
@Produces("application/json")
public Map<String, String> jobResultValue(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId) throws NotConnectedRestException, PermissionRestException, UnknownJobRestException {
try {
Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/result/value");
JobResult jobResult = PAFuture.getFutureValue(s.getJobResult(jobId));
if (jobResult == null) {
return null;
}
Map<String, TaskResult> allResults = jobResult.getAllResults();
Map<String, String> res = new HashMap<>(allResults.size());
for (final Entry<String, TaskResult> entry : allResults.entrySet()) {
TaskResult taskResult = entry.getValue();
String value = getTaskResultValueAsStringOrExceptionStackTrace(taskResult);
res.put(entry.getKey(), value);
}
return res;
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (UnknownJobException e) {
throw new UnknownJobRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
}
}
Aggregations