Package eu.scape_project.planning.services.taverna.executor

Examples of eu.scape_project.planning.services.taverna.executor.SSHTavernaExecutor$ByteArraySourceFile


    @Override
    public MigrationResult migrate(Alternative alternative, DigitalObject digitalObject) throws PlatoException {
        PreservationActionDefinition action = alternative.getAction();

        SSHTavernaExecutor tavernaExecutor = new SSHTavernaExecutor();
        tavernaExecutor.init();

        MigrationResult result = new MigrationResult();

        HashMap<String, Object> inputData = new HashMap<String, Object>();

        WorkflowDescription workflowDescription = MyExperimentRESTClient.getWorkflow(action.getDescriptor());
        workflowDescription.readMetadata();
        if (!workflowDescription.getProfile().equals("http://purl.org/DP/components#MigrationAction")) {
            result.setSuccessful(false);
            result.setReport("The workflow " + action.getUrl() + " is no MigrationAction.");
            return result;
        }

        List<Port> inputPorts = workflowDescription.getInputPorts();

        for (Port p : inputPorts) {
            if (ComponentConstants.VALUE_SOURCE_OBJECT.equals(p.getValue())) {
                inputData.put(p.getName(),
                    tavernaExecutor.new ByteArraySourceFile(FileUtils.makeFilename(digitalObject.getFullname()),
                        digitalObject.getData().getData()));
            } else if (ComponentConstants.VALUE_PARAMETER.equals(p.getValue()) || p.getValue() == null) {
                String value = action.getParamByName(p.getName());
                if (value == null) {
                    value = "";
                }
                inputData.put(p.getName(), value);
            } else {
                result.setSuccessful(false);
                result.setReport("The workflow " + action.getUrl() + " has unsupported port " + p.getName()
                    + " that accepts " + p.getValue());
                return result;
            }
        }
        tavernaExecutor.setInputData(inputData);

        // Workflow
        tavernaExecutor.setWorkflow(action.getUrl());

        // Output ports to receive
        List<Port> outputPorts = workflowDescription.getOutputPorts();
        Set<String> outputPortNames = new HashSet<String>(outputPorts.size());
        String targetPathPort = null;
        for (Port p : outputPorts) {
            outputPortNames.add(p.getName());

            if (ComponentConstants.VALUE_TARGET_OBJECT.equals(p.getValue())) {
                targetPathPort = p.getName();
            }
        }
        tavernaExecutor.setOutputPorts(outputPortNames);

        // Output files
        if (targetPathPort == null) {
            result.setSuccessful(false);
            result.setReport("The workflow " + action.getUrl() + " has not target port.");
            return result;
        }
        HashMap<String, SSHInMemoryTempFile> requestedFiles = new HashMap<String, SSHInMemoryTempFile>(1);
        SSHInMemoryTempFile tempFile = new SSHInMemoryTempFile();
        requestedFiles.put(targetPathPort, tempFile);
        tavernaExecutor.setOutputFiles(requestedFiles);

        // Execute
        try {
            tavernaExecutor.execute();
        } catch (IOException e) {
            result.setSuccessful(false);
            result.setReport("Error connecting to execution server");
            log.error("Error connecting to execution server", e);
            return result;
        } catch (TavernaExecutorException e) {
            result.setSuccessful(false);
            result.setReport("Error executing taverna workflow");
            log.error("Error executing taverna workflow", e);
            return result;
        }

        result.setSuccessful(true);
        result.setReport(tavernaExecutor.getOutputDoc());

        Map<String, ?> outputFiles = tavernaExecutor.getOutputFiles();

        DigitalObject u = new DigitalObject();
        for (Entry<String, ?> entry : outputFiles.entrySet()) {
            SSHInMemoryTempFile resultFile = (SSHInMemoryTempFile) entry.getValue();
            u.getData().setData(resultFile.getData());
View Full Code Here


        MigrationResult result = new MigrationResult();
        result.setSourceFormat(digitalObject.getFormatInfo());
        result.setSuccessful(false);

        // Prepare executor
        SSHTavernaExecutor tavernaExecutor = new SSHTavernaExecutor();
        tavernaExecutor.init();
        SSHTavernaExecutor.ByteArraySourceFile workflowFile = tavernaExecutor.new ByteArraySourceFile(
            FileUtils.makeFilename(workflow.getFullname()), workflow.getData().getData());
        tavernaExecutor.setWorkflow(workflowFile);

        // Input
        HashMap<String, Object> inputData = new HashMap<String, Object>();
        SSHTavernaExecutor.ByteArraySourceFile sourceFile = tavernaExecutor.new ByteArraySourceFile(
            FileUtils.makeFilename(digitalObject.getFullname()), digitalObject.getData().getData());
        inputData.put("source", sourceFile);
        tavernaExecutor.setInputData(inputData);

        // Outputs
        tavernaExecutor.setOutputPorts(null);
        HashMap<String, SSHInMemoryTempFile> requestedFiles = new HashMap<String, SSHInMemoryTempFile>(1);
        SSHInMemoryTempFile tempFile = new SSHInMemoryTempFile();
        requestedFiles.put("target", tempFile);
        tavernaExecutor.setOutputFiles(requestedFiles);

        // Execute
        try {
            tavernaExecutor.execute();
            result.setReport(tavernaExecutor.getOutputDoc());

            // Migrated file
            Map<String, ?> outputFiles = tavernaExecutor.getOutputFiles();

            DigitalObject migrated = new DigitalObject();
            for (Entry<String, ?> entry : outputFiles.entrySet()) {
                SSHInMemoryTempFile resultFile = (SSHInMemoryTempFile) entry.getValue();
                migrated.getData().setData(resultFile.getData());
                migrated.setFullname(alternative.getAction().getShortname() + " - " + digitalObject.getFullname());
            }
            result.setMigratedObject(migrated);
            result.setTargetFormat(migrated.getFormatInfo());
            result.setSuccessful(migrated.isDataExistent());

            // Measures
            Map<String, ?> outputData = tavernaExecutor.getOutputData();
            Map<String, Measurement> measurements = new HashMap<String, Measurement>();
            for (Entry<String, ?> outputEntry : outputData.entrySet()) {
                Measurement measurement = createMeasurement(outputEntry.getKey(), outputEntry.getValue());
                if (measurement != null) {
                    measurements.put(measurement.getMeasureId(), measurement);
View Full Code Here

     *             if an error occurred during evaluation
     */
    private HashMap<String, Value> evaluate(DigitalObject sample, DigitalObject result, WorkflowInfo service,
        List<String> measureUris, IStatusListener listener) throws EvaluatorException {

        SSHTavernaExecutor tavernaExecutor = new SSHTavernaExecutor();
        tavernaExecutor.init();

        HashMap<String, Value> results = new HashMap<String, Value>();

        // Get description
        WorkflowDescription workflowDescription = MyExperimentRESTClient.getWorkflow(service.getDescriptor());
        workflowDescription.readMetadata();

        if (!workflowDescription.getProfile().equals("http://purl.org/DP/components#Characterisation")
            && !workflowDescription.getProfile().equals("http://purl.org/DP/components#QAObjectComparison")) {
            LOG.warn("The workflow {} is no CC or QA component.", service.getDescriptor());
            throw new EvaluatorException("The workflow " + service.getDescriptor() + " is no CC or QA component.");
        }

        // Input
        if (workflowDescription.getProfile().equals("http://purl.org/DP/components#Characterisation")) {
            setCCInputData(workflowDescription, result, tavernaExecutor);
        } else {
            setQAInputData(workflowDescription, sample, result, tavernaExecutor);
        }

        // Workflow
        tavernaExecutor.setWorkflow(service.getContentUri());

        // Output ports to receive
        List<Port> outputPorts = workflowDescription.getOutputPorts();
        Set<String> outputPortNames = new HashSet<String>(outputPorts.size());
        for (Port p : outputPorts) {
            outputPortNames.add(p.getName());
        }
        tavernaExecutor.setOutputPorts(outputPortNames);

        // Execute
        try {
            tavernaExecutor.execute();
        } catch (IOException e) {
            LOG.error("Error connecting to execution server", e);
            throw new EvaluatorException("Error connecting to execution server", e);
        } catch (TavernaExecutorException e) {
            LOG.error("Error executing taverna workflow", e);
            throw new EvaluatorException("Error executing taverna workflow", e);
        }

        Map<String, ?> outputData = tavernaExecutor.getOutputData();
        for (Port p : outputPorts) {
            String measure = p.getValue();
            // Ignore non-measures, measures for sample object
            if (measure != null && !measure.isEmpty() && measureUris.contains(measure)) {
                Object value = outputData.get(p.getName());
View Full Code Here

TOP

Related Classes of eu.scape_project.planning.services.taverna.executor.SSHTavernaExecutor$ByteArraySourceFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.