Package eu.scape_project.planning.model

Examples of eu.scape_project.planning.model.PreservationActionDefinition


*/
public class MiniMeeMigrationService implements IMigrationAction {

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

        MigrationService service = new MigrationService();
        long start = System.nanoTime();
        String settings = "";
        if (action.isExecute()) {
            settings = action.getParamByName("settings");
        }
        MigrationResult result = service.migrate(digitalObject.getData().getData(), action.getUrl(), settings);
        setResultName(result, digitalObject);

        long duration = (System.nanoTime() - start) / (1000000);
        service.addExperience(result.getFeedbackKey(), action.getUrl(), new Measurement("roundtripTimeMS", new Double(
            duration)));
        return result;
    }
View Full Code Here


            facesMessages.addError("Could not retrieve workflow description from myExeriment.");
            return;
        }

        try {
            PreservationActionDefinition actionDefinition = new PreservationActionDefinition();
            actionDefinition.setActionIdentifier(serviceInfo.getServiceIdentifier());
            actionDefinition.setShortname(serviceInfo.getShortname());
            actionDefinition.setDescriptor(serviceInfo.getDescriptor());
            actionDefinition.setUrl(serviceInfo.getUrl());
            actionDefinition.setInfo(serviceInfo.getInfo());

            for (Port p : wf.getInputPorts()) {
                if (p.isParameterPort()) {
                    actionDefinition.getParams().add(new Parameter(p.getName(), ""));
                }
            }

            String uniqueName = plan.getAlternativesDefinition().createUniqueName(actionDefinition.getShortname());
            Alternative a = Alternative.createAlternative(uniqueName, actionDefinition);
            defineAlternatives.addAlternative(a);
        } catch (PlanningException e) {
            facesMessages.addError("Could not create an alternative from the service you selected.");
        }
View Full Code Here

        return result.isSuccessful();
    }

    @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());
            u.setFullname(action.getShortname() + " - " + digitalObject.getFullname());
        }
        FormatInfo tFormat = new FormatInfo();
        result.setTargetFormat(tFormat);
        result.setMigratedObject(u);
View Full Code Here

        // Add ports
        generator.addSourcePort();
        generator.addTargetPort();

        // Migration action
        PreservationActionDefinition action = alternative.getAction();
        if (action != null) {
            try {
                WorkflowDescription wf = MyExperimentRESTClient.getWorkflow(action.getDescriptor());
                HashMap<String, String> parameters = new HashMap<String, String>();
                for (Parameter p : action.getParams()) {
                    parameters.put(p.getName(), p.getValue());
                }
                wf.readMetadata();
                String workflowContent = MyExperimentRESTClient.getWorkflowContent(wf);
                generator.setMigrationComponent(wf, workflowContent, parameters);
View Full Code Here

        alternatives = plan.getAlternativesDefinition().getConsideredAlternatives();

        targetMimetypes = new HashMap<Alternative, String>(alternatives.size());
        actionInfos = new HashMap<Alternative, ActionInfo>(alternatives.size());
        for (Alternative a : alternatives) {
            PreservationActionDefinition pad = a.getAction();
            if (pad != null) {
                targetMimetypes.put(a, "");
                ActionInfo actionInfo = ActionInfoFactory.createActionInfo(pad);
                actionInfos.put(a, actionInfo);
                myExperimentServices.load(actionInfo);
View Full Code Here

     * @return the new alternative
     * @throws PlanningException
     *             if the alternative could not be added
     */
    public Alternative addAlternative(IServiceInfo actionInfo) throws PlanningException {
        PreservationActionDefinition actionDefinition = new PreservationActionDefinition();
        actionDefinition.setActionIdentifier(actionInfo.getServiceIdentifier());
        actionDefinition.setShortname(actionInfo.getShortname());
        actionDefinition.setDescriptor(actionInfo.getDescriptor());
        actionDefinition.setUrl(actionInfo.getUrl());
        actionDefinition.setInfo(actionInfo.getInfo());

        String uniqueName = plan.getAlternativesDefinition().createUniqueName(actionDefinition.getShortname());
        Alternative a = Alternative.createAlternative(uniqueName, actionDefinition);
        plan.getAlternativesDefinition().addAlternative(a);
        return a;
    }
View Full Code Here

     * @return the new alternative
     * @throws PlanningException
     *             if the alternative could not be added
     */
    public Alternative addAlternative(ActionInfo actionInfo) throws PlanningException {
        PreservationActionDefinition actionDefinition = new PreservationActionDefinition();
        actionDefinition.setShortname(actionInfo.getShortname());
        actionDefinition.setDescriptor(actionInfo.getDescriptor());
        actionDefinition.setInfo(actionInfo.getInfo());
        actionDefinition.setActionIdentifier(actionInfo.getActionIdentifier());
        actionDefinition.setParams(actionInfo.getParams());
        actionDefinition.setParameterInfo(actionInfo.getParameterInfo());
        actionDefinition.setUrl(actionInfo.getUrl());
        actionDefinition.setTargetFormatInfo(actionInfo.getTargetFormatInfo());
        actionDefinition.setTargetFormat(actionInfo.getTargetFormat());
        actionDefinition.setEmulated(actionInfo.isEmulated());
        actionDefinition.setExecutable(actionInfo.isExecutable());

        String uniqueName = plan.getAlternativesDefinition().createUniqueName(actionDefinition.getShortname());
        Alternative a = Alternative.createAlternative(uniqueName, actionDefinition);
        plan.getAlternativesDefinition().addAlternative(a);
        return a;
    }
View Full Code Here

TOP

Related Classes of eu.scape_project.planning.model.PreservationActionDefinition

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.