Package eu.planets_project.pp.plato.services.action

Examples of eu.planets_project.pp.plato.services.action.MigrationResult


             */
            eu.planets_project.pp.plato.services.crib_integration.remoteclient.MigrationResult migrationResult = metaconverterService.convert(representationObject, migrationPath);
            /*
             * collect migration results
             */
            MigrationResult result = new MigrationResult();
            lastResult = result;

            /*
             * if the migration was successful is indicated by two flags:
             * "process::availability" and "process::stability"
             * - which are float values (!)
             */
            Criterion[] criteria = migrationResult.getReport().getCriteria();
            double availability = Double.parseDouble(getCriterion(criteria, "process::availability"));
            double stability = Double.parseDouble(getCriterion(criteria, "process::stability"));
            result.setSuccessful((availability > 0.0) && (stability > 0.0));
           
            if (!result.isSuccessful()) {
                result.setReport(String.format("Service '%s' failed to migrate sample '%s'.", action.getShortname() ,  sampleObject.getFullname()));//+ getCriterion(criteria, "message::reason"));
                log.debug(String.format("Service '%s' failed to migrate sample '%s': %s", action.getShortname(), sampleObject.getFullname(), getCriterion(criteria, "message::reason")));
                return true;
            } else {
                result.setReport(String.format("Migrated object '%s' to format '%s'. Completed at %s.",
                        sampleObject.getFullname(), action.getTargetFormat(), migrationResult.getReport().getDatetime()));
            }
            result.getMigratedObject().getData().setData(migrationResult.getRepresentation().getFiles()[0].getBitstream().clone());
           
            /*
             * message::filename contains the name of the source-file, NOT the migrated
             */
            String filename = migrationResult.getRepresentation().getFiles()[0].getFilename();
           
            /*
             * if filename is missing, use name from the source object (without extension)
             */
            if ((filename == null) || "".equals(filename)) {
                filename = sampleObject.getFullname();
                int bodyEnd = filename.lastIndexOf(".");
                if (bodyEnd >= 0)
                    filename = filename.substring(0, bodyEnd);
            }
            result.getMigratedObject().setFullname(filename);
            int bodyEnd;

            /*
             * CRiB does not provide forther information about the format of the migrated object,
             * therfore the file extension of the migrated object is derived from the action's target formats
             */
            bodyEnd = filename.lastIndexOf(".");
            if ((bodyEnd < 0) &&
                ((result.getTargetFormat().getDefaultExtension() == null) ||
                  "".equals(result.getTargetFormat().getDefaultExtension()))) {
                FormatInfo targetFormat = new FormatInfo();
                setFormatFromCRiBID(action.getTargetFormat(), targetFormat);
                result.setTargetFormat(targetFormat);
                filename = filename + "." + result.getTargetFormat().getDefaultExtension();
                result.getMigratedObject().setFullname(filename);
            }
            lastResult = result;
            return true;
        } catch (NumberFormatException e) {
            throw new PlatoServiceException("Migration failed, CRiB returned an invalid result.", e);
View Full Code Here


            eu.planets_project.pp.plato.services.crib_integration.tu_client.MigrationResult migrationResult = migrationBroker.convert(representationObject, urlArr);
           
            /*
             * collect migration results
             */
            MigrationResult result = new MigrationResult();
            lastResult = result;

            /*
             * if the migration was successful is indicated by two flags:
             * "process::availability" and "process::stability"
             * - which are float values (!)
             */
            Criterion[] criteria = migrationResult.getReport().getCriteria();
            double availability = Double.parseDouble(getCriterion(criteria, "process::availability"));
            double stability = Double.parseDouble(getCriterion(criteria, "process::stability"));
            result.setSuccessful((availability > 0.0) && (stability > 0.0));
            if (!result.isSuccessful()) {
                result.setReport(String.format("Service '%s' failed to migrate sample '%s'.", action.getShortname() ,  sampleObject.getFullname()));//+ getCriterion(criteria, "message::reason"));
                log.debug(String.format("Service '%s' failed to migrate sample '%s': %s", action.getShortname(), sampleObject.getFullname(), getCriterion(criteria, "message::reason")));
                return true;
            } else {
                result.setReport(String.format("Migrated object '%s' to format '%s'. Completed at %s.",
                        sampleObject.getFullname(), action.getTargetFormat(), migrationResult.getReport().getDatetime()));
            }
            result.getMigratedObject().getData().setData(migrationResult.getRepresentation().getFiles()[0].getBitstream().clone());

            /*
             * message::filename contains the name of the source-file, NOT the migrated
             */
            String filename = migrationResult.getRepresentation().getFiles()[0].getFilename();
           
            /*
             * if filename is missing, use name from the source object (without extension)
             */
            if ((filename == null) || "".equals(filename)) {
                filename = sampleObject.getFullname();
                int bodyEnd = filename.lastIndexOf(".");
                if (bodyEnd >= 0)
                    filename = filename.substring(0, bodyEnd);
            }
            result.getMigratedObject().setFullname(filename);
            int bodyEnd;

            /*
             * CRiB does not provide forther information about the format of the migrated object,
             * therfore the file extension of the migrated object is derived from the action's target formats
             */
            bodyEnd = filename.lastIndexOf(".");
            if ((bodyEnd < 0) &&
                ((result.getTargetFormat().getDefaultExtension() == null) ||
                  "".equals(result.getTargetFormat().getDefaultExtension()))) {
                FormatInfo targetFormat = new FormatInfo();
                setFormatFromCRiBID(action.getTargetFormat(), targetFormat);
                result.setTargetFormat(targetFormat);
                filename = filename + "." + result.getTargetFormat().getDefaultExtension();
                result.getMigratedObject().setFullname(filename);
                result.getMigratedObject().getFormatInfo().assignValues(targetFormat);
            }
            lastResult = result;
            return true;
        } catch (NumberFormatException e) {
            throw new PlatoServiceException("Migration failed, CRiB returned an invalid result.", e);
View Full Code Here

        long start = System.nanoTime();
        String settings = "";
        if (action.isExecute()) {
            settings = action.getParamByName("settings");
        }
        MigrationResult result = service.migrate(sampleObject.getData().getData(),
                        action.getUrl(),
                        settings);
        // provide a nice name for the resulting object
        setResultName(result, sampleObject);
        long duration = (System.nanoTime()-start)/(1000000);
        service.addExperience(result.getFeedbackKey(), action.getUrl(),
                new Measurement("roundtripTimeMS",new Double(duration)));
        return result;
    }
View Full Code Here

     * and collects their results.
     * Forwarding is done sequentially, one AFTER the other.
     */
    public MigrationResult migrate(byte[] data, String toolID, String params) {
       
        MigrationResult result = new MigrationResult();
        StringBuffer report = new StringBuffer();
       
        for (IMigrationEngine engine: engines) {
            // execute tool on all migration engines (ideally in parallel)
            report.append("migrating with engine "+engine.getName()+":\n");
            MigrationResult r = engine.migrate(data, toolID, params);
            report.append(r.getReport()).append("\n------------------- ------------\n");

            // get all performance data and put them together in the order the engines are defined
            for (MeasurableProperty p : engine.getMeasurableProperties()) {
                result.getMeasurements().put(p.getName(),r.getMeasurements().get(p.getName()));
            }
            for (Measurement m : r.getMeasurements().values()) {
                if (m.getProperty().getName().contains(":normalised")) {
                    result.getMeasurements().put(m.getProperty().getName(),m);
                }
            }// TODO define proper models and IDs for these measurements
           
           
            // Let's be nice for now - we can still get more defensive later on
            // and check consistency, i.e. identity of the produced byte arrays, etc.
            if (r.isSuccessful()) {
                result.setMigratedObject(r.getMigratedObject());
                result.setTargetFormat(r.getTargetFormat());
                result.setSuccessful(true);
            }
        }
        normaliseMeasurements(result, toolID);
        result.setReport(report.toString());
View Full Code Here

     * @see IMigrationEngine#migrate(byte[], String, String)
     * This measures <b>elapsed time</b> and relative file size only.
     */
    public MigrationResult migrate(byte[] data, String toolID, String params) {
       
        MigrationResult result = new MigrationResult();
        String key = "minimee/";
        String toolIdentifier = toolID.substring(toolID.indexOf(key)
                + key.length());
        ToolConfig config = ToolRegistry.getInstance().getToolConfig(toolIdentifier);
        migrate(data, config, params, result);
       
        normaliseMeasurements(result, toolIdentifier);
        result.getMeasurements().put("input:filesize",new Measurement("input:filesize",data.length));
        return result;
    }
View Full Code Here

                     */
                    for (MassMigrationExperiment exp : setup.getExperiments()) {
                        currentTool++;
                        setup.getStatus().setCurrentTool(currentTool);
                       
                        MigrationResult result = runExperiment(exp, file.getName(), data);
                        if ((result != null) && (result.isSuccessful())) {
                            // store migration result
                            String altPath = alternativesPaths.get(exp.getAction().getShortname());
                            if (altPath != null) {
                                File mResult = new File(altPath , file.getName() +"."+ result.getTargetFormat().getDefaultExtension());
                                OutputStream out = new BufferedOutputStream(new FileOutputStream(mResult));
                                out.write(result.getMigratedObject().getData().getData());
                                out.close();
                            }
                        }
                    }
                } catch (IOException ioe) {
View Full Code Here

        Measurement report = new Measurement();
        report.setProperty(new MeasurableProperty(new FreeStringScale(), MigrationResult.MIGRES_REPORT));
        report.setValue(report.getProperty().getScale().createValue());
       
        try {
            MigrationResult result = service.migrate(e.getAction(), r);
            if (result.isSuccessful()) {
                /* put all info to toolExperience */
                eInfo.getMeasurements().putAll(result.getMeasurements());

                ((BooleanValue)success.getValue()).setValue("true");
                ((FreeStringValue)report.getValue()).setValue(result.getReport());
            } else {
                ((BooleanValue)success.getValue()).setValue("false");
                ((FreeStringValue)report.getValue()).setValue(result.getReport());
            }
            // and return result, (including the migrated object)
            return result;
           
        } catch (Exception e1) {
View Full Code Here

        }
       
        // perform migration
        MigrateResult result = m.migrate(dob, sourceFormat, targetFormat, serviceParams);

        MigrationResult migrationResult = new MigrationResult();
        migrationResult.setSuccessful((result != null) && (result.getDigitalObject() != null));

        if (migrationResult.isSuccessful()) {
            migrationResult.setReport(String.format("Service %s successfully migrated object.", wsdlLocation));
        } else {
            migrationResult.setReport(String.format("Service %s failed migrating object. " + ((result==null)? "" : result.getReport()), wsdlLocation));
            lastResult = migrationResult;
            return true;
        }

        InputStream in = result.getDigitalObject().getContent().getInputStream();
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        byte[] b = new byte[1024];

        try {
            while ((in.read(b)) != -1) {
                out.write(b);
            }
        } catch (IOException e) {
            throw new PlatoServiceException("Unable to read result data from service response.", e);
        }

        migrationResult.getMigratedObject().getData().setData(out.toByteArray());

        String fullName = sampleObject.getFullname();

        String ext;
        try {
            ext = formatRegistry.getFirstExtension(new URI(action.getTargetFormat()));
        } catch (URISyntaxException e) {
            ext = "";
        }
       
        // if we find an extension, cut if off ...
        if (fullName.lastIndexOf('.') > 0) {
            fullName = fullName.substring(0, fullName.lastIndexOf('.'));
        }

        // ... so we can append the new one.
        if (! "".equals(ext)) {
            fullName += ("." + ext);   
        }

        migrationResult.getMigratedObject().setFullname(fullName);

        lastResult = migrationResult;

        return true;
    }
View Full Code Here

    public MigrationResult migrate(byte[] data, String toolID, String params) {
        ToolConfig config = getToolConfig(toolID);
        ToolRegistry reg = ToolRegistry.getInstance();

        IMigrationEngine engine = reg.getAllEngines().get(config.getEngine());
        MigrationResult r= engine.migrate(data, toolID, params);

        /* evaluate result */
        evaluate(config, data, r);
       
        long key = System.nanoTime();
        r.setFeedbackKey(key);
        reg.addTimePad(key);
        return r;
    }
View Full Code Here

                    try {
                        for (File f : directory.listFiles()) {
                            log.debug("testing " + config.getUrl() + " with file "
                                    + f.getName());
                            byte[] data = FileUtils.getBytesFromFile(f);
                            MigrationResult r = engine.migrate(data, "minimee/"+ config.getUrl(), "");
                            if (!r.isSuccessful()) {
                                log.warn(r.getReport());
                                initResults.put(config.getUrl(), "FAILED: "
                                        + r.getReport());
                            } else {
                                initResults.put(config.getUrl(), "SUCCESS");
                            }
                        }
                    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of eu.planets_project.pp.plato.services.action.MigrationResult

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.