Search in sources :

Example 1 with Type

use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.

the class SchedulerStateRest method deleteFile.

/**
 * Deletes a file or recursively delete a directory from the given DataSpace
 *
 * @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 which must be deleted
 */
@Override
public boolean deleteFile(@HeaderParam("sessionid") String sessionId, @PathParam("spaceName") String spaceName, @PathParam("filePath") String filePath) throws IOException, NotConnectedRestException, PermissionRestException {
    checkAccess(sessionId, "deleteFile");
    Session session = dataspaceRestApi.checkSessionValidity(sessionId);
    filePath = normalizeFilePath(filePath, null);
    FileObject sourcefo = dataspaceRestApi.resolveFile(session, spaceName, filePath);
    if (!sourcefo.exists() || !sourcefo.isWriteable()) {
        RuntimeException ex = new IllegalArgumentException("File or Folder " + filePath + " does not exist or is not writable in space " + spaceName);
        logger.error(ex);
        throw ex;
    }
    if (sourcefo.getType().equals(FileType.FILE)) {
        logger.info("[deleteFile] deleting file " + sourcefo.getURL());
        sourcefo.delete();
    } else if (sourcefo.getType().equals(FileType.FOLDER)) {
        logger.info("[deleteFile] deleting folder (and all its descendants) " + sourcefo.getURL());
        sourcefo.delete(Selectors.SELECT_ALL);
    } else {
        RuntimeException ex = new IllegalArgumentException("File " + filePath + " has an unsupported type " + sourcefo.getType());
        logger.error(ex);
        throw ex;
    }
    return true;
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) HttpSession(javax.servlet.http.HttpSession) Session(org.ow2.proactive_grid_cloud_portal.common.Session)

Example 2 with Type

use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.

the class SchedulerStateRest method valueOfTaskResultByTag.

/**
 * Returns the value of the task result for a set of tasks of the job
 * <code>jobId</code> filtered by a given tag. <strong>the result is
 * deserialized before sending to the client, if the class is not found the
 * content is replaced by the string 'Unknown value type' </strong>. To get
 * the serialized form of a given result, one has to call the following
 * restful service jobs/{jobid}/tasks/tag/{tasktag}/result/serializedvalue
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskTag
 *            the tag used to filter the tasks.
 * @return the value of the task result
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result/value")
@Produces("application/json")
public Map<String, String> valueOfTaskResultByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws Throwable {
    Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/tag/" + taskTag + "/result/value");
    List<TaskResult> taskResults = s.getTaskResultsByTag(jobId, taskTag);
    Map<String, String> result = new HashMap<String, String>(taskResults.size());
    for (TaskResult currentTaskResult : taskResults) {
        result.put(currentTaskResult.getTaskId().getReadableName(), getTaskResultValueAsStringOrExceptionStackTrace(currentTaskResult));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) 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)

Example 3 with Type

use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.

the class JobComparator method isEqualParallelEnvironment.

private boolean isEqualParallelEnvironment(ParallelEnvironment e1, ParallelEnvironment e2) {
    if ((e1 == null) && (e2 == null))
        return true;
    if ((e1 == null) ^ (e2 == null)) {
        stack.push("One value out of 2 is null");
        return false;
    }
    if (e1.getNodesNumber() != e2.getNodesNumber()) {
        stack.push("nodes number");
        return false;
    }
    // check same instance of topology decsriptor
    TopologyDescriptor topologyDescriptor1 = e1.getTopologyDescriptor();
    TopologyDescriptor topologyDescriptor2 = e2.getTopologyDescriptor();
    if (topologyDescriptor1 == null && topologyDescriptor2 == null) {
        return true;
    }
    if (topologyDescriptor1 == null ^ topologyDescriptor2 == null) {
        return isEqualClass(TopologyDescriptor.ARBITRARY.getClass(), (topologyDescriptor1 == null ? topologyDescriptor2.getClass() : topologyDescriptor1.getClass()));
    }
    if (!isEqualClass(topologyDescriptor1.getClass(), topologyDescriptor2.getClass())) {
        stack.push("topology descriptor type");
        return false;
    }
    if (topologyDescriptor1 instanceof ThresholdProximityDescriptor) {
        if (!(topologyDescriptor2 instanceof ThresholdProximityDescriptor)) {
            stack.push("Only one is ThresholdProximityDescriptor type.");
            return false;
        }
        if (((ThresholdProximityDescriptor) topologyDescriptor1).getThreshold() != ((ThresholdProximityDescriptor) topologyDescriptor2).getThreshold()) {
            stack.push("ThresholdProximityDescriptor.threshold");
            return false;
        }
    }
    return true;
}
Also used : ThresholdProximityDescriptor(org.ow2.proactive.topology.descriptor.ThresholdProximityDescriptor) TopologyDescriptor(org.ow2.proactive.topology.descriptor.TopologyDescriptor)

Example 4 with Type

use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.

the class StaxJobFactory method createAndFillJob.

/**
 * Create the real job and fill it with its property. Leave the method at
 * the first tag that define the real type of job.
 *
 * @param cursorJob          the streamReader with the cursor on the job element.
 * @param replacementVariables map of variables which has precedence over those that defined
 *                           in Job descriptor
 * @throws JobCreationException if an exception occurs during job creation.
 */
private Job createAndFillJob(XMLStreamReader cursorJob, Map<String, String> replacementVariables) throws JobCreationException {
    // create a job that will just temporary store the common properties of the job
    Job commonPropertiesHolder = new Job() {

        @Override
        public JobId getId() {
            throw new RuntimeException("Not Available!");
        }

        @Override
        public JobType getType() {
            throw new RuntimeException("Not Available!");
        }
    };
    // parse job attributes and fill the temporary one
    // all attributes in the job element are saved and will be handled after the job variables are parsed.
    // This is to allow variable replacements on these attributes
    Map<String, String> delayedJobAttributes = new HashMap<>();
    int attrLen = cursorJob.getAttributeCount();
    int i = 0;
    for (; i < attrLen; i++) {
        String attributeName = cursorJob.getAttributeLocalName(i);
        String attributeValue = cursorJob.getAttributeValue(i);
        delayedJobAttributes.put(attributeName, attributeValue);
    }
    // parse job elements and fill the temporary one
    Job job = commonPropertiesHolder;
    try {
        int eventType;
        boolean shouldContinue = true;
        while (shouldContinue && cursorJob.hasNext()) {
            eventType = cursorJob.next();
            switch(eventType) {
                case XMLEvent.START_ELEMENT:
                    String current = cursorJob.getLocalName();
                    if (XMLTags.VARIABLES.matches(current)) {
                        // create job variables using the replacement map provided at job submission
                        // the final value of the variable can either be overwritten by a value of the replacement map or
                        // use in a pattern such value
                        commonPropertiesHolder.getVariables().putAll(createJobVariables(cursorJob, replacementVariables));
                    } else if (XMLTags.COMMON_GENERIC_INFORMATION.matches(current)) {
                        commonPropertiesHolder.setGenericInformation(getGenericInformation(cursorJob, commonPropertiesHolder.getVariablesAsReplacementMap()));
                    } else if (XMLTags.JOB_CLASSPATHES.matches(current)) {
                        logger.warn("Element " + XMLTags.JOB_CLASSPATHES.getXMLName() + " is no longer supported. Please define a " + XMLTags.FORK_ENVIRONMENT.getXMLName() + " per task if needed.");
                    } else if (XMLTags.COMMON_DESCRIPTION.matches(current)) {
                        commonPropertiesHolder.setDescription(getDescription(cursorJob, commonPropertiesHolder.getVariablesAsReplacementMap()));
                    } else if (XMLTags.DS_INPUT_SPACE.matches(current)) {
                        commonPropertiesHolder.setInputSpace(getIOSpace(cursorJob, commonPropertiesHolder.getVariablesAsReplacementMap()));
                    } else if (XMLTags.DS_OUTPUT_SPACE.matches(current)) {
                        commonPropertiesHolder.setOutputSpace(getIOSpace(cursorJob, commonPropertiesHolder.getVariablesAsReplacementMap()));
                    } else if (XMLTags.DS_GLOBAL_SPACE.matches(current)) {
                        commonPropertiesHolder.setGlobalSpace(getIOSpace(cursorJob, commonPropertiesHolder.getVariablesAsReplacementMap()));
                    } else if (XMLTags.DS_USER_SPACE.matches(current)) {
                        commonPropertiesHolder.setUserSpace(getIOSpace(cursorJob, commonPropertiesHolder.getVariablesAsReplacementMap()));
                    } else if (XMLTags.TASK_FLOW.matches(current)) {
                        job = new TaskFlowJob();
                        shouldContinue = false;
                    }
                    break;
            }
        }
        handleJobAttributes(commonPropertiesHolder, delayedJobAttributes);
        // if this point is reached, fill the real job using the temporary one
        if (job != commonPropertiesHolder) {
            job.setDescription(commonPropertiesHolder.getDescription());
            job.setName(commonPropertiesHolder.getName());
            job.setPriority(commonPropertiesHolder.getPriority());
            job.setProjectName(commonPropertiesHolder.getProjectName());
            job.setOnTaskError(commonPropertiesHolder.getOnTaskErrorProperty().getValue());
            job.setRestartTaskOnError(commonPropertiesHolder.getRestartTaskOnError());
            job.setMaxNumberOfExecution(commonPropertiesHolder.getMaxNumberOfExecution());
            job.setGenericInformation(commonPropertiesHolder.getGenericInformation());
            job.setInputSpace(commonPropertiesHolder.getInputSpace());
            job.setOutputSpace(commonPropertiesHolder.getOutputSpace());
            job.setGlobalSpace(commonPropertiesHolder.getGlobalSpace());
            job.setUserSpace(commonPropertiesHolder.getUserSpace());
            job.setVariables(commonPropertiesHolder.getVariables());
        }
        return job;
    } catch (JobCreationException jce) {
        jce.pushTag(cursorJob.getLocalName());
        throw jce;
    } catch (Exception e) {
        String temporaryAttribute = null;
        if (cursorJob.isStartElement() && cursorJob.getAttributeCount() > i) {
            temporaryAttribute = cursorJob.getAttributeLocalName(i);
        }
        throw new JobCreationException(cursorJob.getLocalName(), temporaryAttribute, e);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) Job(org.ow2.proactive.scheduler.common.job.Job) 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)

Example 5 with Type

use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.

the class StaxJobFactory method setNativeExecutable.

/**
 * Add the Native Executable to this native Task.
 * The cursor is currently at the beginning of the 'ELEMENT_NATIVE_EXECUTABLE' tag.
 *
 * @param nativeTask the task in which to add the Native Executable.
 * @param cursorExec the streamReader with the cursor on the 'ELEMENT_NATIVE_EXECUTABLE' tag.
 */
private void setNativeExecutable(NativeTask nativeTask, XMLStreamReader cursorExec) throws JobCreationException {
    int i = 0;
    String current = null;
    try {
        // one step ahead to go to the command (static or dynamic)
        while (cursorExec.next() != XMLEvent.START_ELEMENT) ;
        current = cursorExec.getLocalName();
        ArrayList<String> command = new ArrayList<>(0);
        if (XMLTags.NATIVE_TASK_STATIC_COMMAND.matches(cursorExec.getLocalName())) {
            String attr_ = null;
            String current_ = null;
            try {
                for (i = 0; i < cursorExec.getAttributeCount(); i++) {
                    String attrName = cursorExec.getAttributeLocalName(i);
                    attr_ = attrName;
                    if (XMLAttributes.TASK_COMMAND_VALUE.matches(attrName)) {
                        command.add((cursorExec.getAttributeValue(i)));
                    }
                    if (XMLAttributes.TASK_WORKDING_DIR.matches(attrName)) {
                        logger.warn(XMLAttributes.TASK_WORKDING_DIR.getXMLName() + " attribute no longer supported. Please use a forkEnvironment for defining a working directory.");
                    }
                }
                int eventType;
                while (cursorExec.hasNext()) {
                    eventType = cursorExec.next();
                    switch(eventType) {
                        case XMLEvent.START_ELEMENT:
                            current_ = cursorExec.getLocalName();
                            if (XMLTags.SCRIPT_ARGUMENT.matches(cursorExec.getLocalName())) {
                                command.add((cursorExec.getAttributeValue(0)));
                            }
                            break;
                        case XMLEvent.END_ELEMENT:
                            if (XMLTags.NATIVE_EXECUTABLE.matches(cursorExec.getLocalName())) {
                                nativeTask.setCommandLine(command.toArray(new String[command.size()]));
                                return;
                            }
                            break;
                    }
                }
            } catch (Exception e) {
                throw new JobCreationException(current_, attr_, e);
            }
        } else {
            throw new RuntimeException("Unknown command type: " + cursorExec.getLocalName());
        }
    } catch (JobCreationException jce) {
        jce.pushTag(current);
        throw jce;
    } catch (Exception e) {
        String temporaryAttribute = null;
        if (cursorExec.isStartElement() && cursorExec.getAttributeCount() > 0) {
            temporaryAttribute = cursorExec.getAttributeLocalName(i);
        }
        throw new JobCreationException(current, temporaryAttribute, e);
    }
}
Also used : ArrayList(java.util.ArrayList) 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)

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