Search in sources :

Example 21 with Type

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;
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) XMLStreamException(javax.xml.stream.XMLStreamException) JobValidationException(org.ow2.proactive.scheduler.common.exception.JobValidationException) FileNotFoundException(java.io.FileNotFoundException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) VerifierConfigurationException(org.iso_relax.verifier.VerifierConfigurationException) FlowScript(org.ow2.proactive.scheduler.common.task.flow.FlowScript)

Example 22 with Type

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();
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) ProActiveTimeoutException(org.objectweb.proactive.core.ProActiveTimeoutException) BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMFunctionalTest(functionaltests.utils.RMFunctionalTest) Test(org.junit.Test)

Example 23 with Type

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);
    }
}
Also used : Scheduler(org.ow2.proactive.scheduler.common.Scheduler) BufferedInputStream(java.io.BufferedInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) JobCreationRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.JobCreationRestException) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 24 with Type

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;
    }
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) HttpSession(javax.servlet.http.HttpSession) Session(org.ow2.proactive_grid_cloud_portal.common.Session)

Example 25 with Type

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);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) HashMap(java.util.HashMap) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)7 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)7 File (java.io.File)6 XMLStreamException (javax.xml.stream.XMLStreamException)6 VerifierConfigurationException (org.iso_relax.verifier.VerifierConfigurationException)6 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)6 HashMap (java.util.HashMap)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 GET (javax.ws.rs.GET)3 FileObject (org.apache.commons.vfs2.FileObject)3 GZIP (org.jboss.resteasy.annotations.GZIP)3 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)3 SchedulerEventListener (org.ow2.proactive.scheduler.common.SchedulerEventListener)3 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)3 KeyException (java.security.KeyException)2