Search in sources :

Example 6 with VRL

use of nl.uva.vlet.vrl.VRL in project lobcder by skoulouzis.

the class Assimilator method add.

public void add(VDir dir, String base, Connection connection, long ssid, boolean addFiles) throws MalformedURLException, VlException, SQLException, NoSuchAlgorithmException {
    VFSNode[] nodes = dir.list();
    for (VFSNode f : nodes) {
        VRL currentPath = new VRL(f.getPath().replaceFirst(base, ""));
        LogicalData register = getLogicalDataByPath(Path.path(currentPath.getPath()), connection);
        LogicalData parent = getLogicalDataByPath(Path.path(currentPath.getPath()).getParent(), connection);
        Long parentRef = new Long(1);
        if (parent == null) {
            parentRef = new Long(1);
        } else {
            parentRef = parent.getUid();
        }
        if (f.isDir()) {
            if (register == null) {
                LogicalData entry = new LogicalData();
                entry.setCreateDate(f.getModificationTime());
                entry.setModifiedDate(f.getModificationTime());
                entry.setName(f.getName());
                entry.setOwner("admin");
                entry.setParentRef(parentRef);
                register = registerDirLogicalData(entry, connection);
            }
            add((VDir) f, base, connection, ssid, addFiles);
        } else if (addFiles) {
            if (register == null) {
                System.err.println(f.getVRL());
                addFile(connection, (VFile) f, parentRef, ssid);
            }
        }
    }
}
Also used : VRL(nl.uva.vlet.vrl.VRL) LogicalData(nl.uva.cs.lobcder.resources.LogicalData) VFSNode(nl.uva.vlet.vfs.VFSNode) VFile(nl.uva.vlet.vfs.VFile)

Example 7 with VRL

use of nl.uva.vlet.vrl.VRL in project lobcder by skoulouzis.

the class JDBCatalogue method setLocationPreferences.

public void setLocationPreferences(Connection connection, Long uid, List<String> locationPreferences, Boolean includePrivate) throws SQLException {
    if (locationPreferences != null && !locationPreferences.isEmpty()) {
        String storageSitesQuery = "select storageSiteId,resourceUri,private from storage_site_table " + // use =
        "WHERE resourceUri LIKE ";
        for (String site : locationPreferences) {
            try {
                new VRL(site);
                storageSitesQuery += "'" + site + "' OR resourceUri LIKE ";
            } catch (VRLSyntaxException ex) {
                Logger.getLogger(JDBCatalogue.class.getName()).log(Level.WARNING, "Wrong VRL", ex);
            }
        }
        if (storageSitesQuery.endsWith(" OR resourceUri LIKE ")) {
            storageSitesQuery = storageSitesQuery.substring(0, storageSitesQuery.lastIndexOf("OR")) + "";
        }
        storageSitesQuery += " AND isCache = false";
        List<Long> ids = new ArrayList<>();
        try (Statement s = connection.createStatement()) {
            try (ResultSet rs = s.executeQuery(storageSitesQuery)) {
                while (rs.next()) {
                    if (rs.getBoolean(3) && includePrivate) {
                        ids.add(rs.getLong(1));
                    } else if (!rs.getBoolean(3)) {
                        ids.add(rs.getLong(1));
                    }
                }
            }
            if (!ids.isEmpty()) {
                try (PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM pref_table WHERE ld_uid = ?")) {
                    preparedStatement.setLong(1, uid);
                    preparedStatement.executeUpdate();
                }
                // connection.commit();
                try (PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO pref_table (ld_uid, storageSiteRef) VALUES(?,?)")) {
                    for (Long id : ids) {
                        preparedStatement.setLong(1, uid);
                        preparedStatement.setLong(2, id);
                        preparedStatement.addBatch();
                    // preparedStatement.executeUpdate();
                    }
                    preparedStatement.executeBatch();
                }
                Collection<LogicalData> children = getChildrenByParentRef(uid);
                for (LogicalData child : children) {
                    if (!child.isFolder()) {
                        setLocationPreferences(connection, child.getUid(), locationPreferences, includePrivate);
                    }
                }
                setNeedsCheck(uid, connection);
            }
        }
    }
    connection.commit();
// return locationPreferences;//getDataLocationPreferace(connection, uid);
}
Also used : VRL(nl.uva.vlet.vrl.VRL) LogicalData(nl.uva.cs.lobcder.resources.LogicalData) VRLSyntaxException(nl.uva.vlet.exception.VRLSyntaxException)

Example 8 with VRL

use of nl.uva.vlet.vrl.VRL in project lobcder by skoulouzis.

the class VPDRI method upload.

// private void debug(String msg) {
// if (debug) {
// //            System.err.println(this.getClass().getName() + ": " + msg);
// log.debug(msg);
// }
// }
private void upload(PDRI source) throws VlException, IOException {
    VFile file = getVfsClient().createFile(vrl, true);
    try {
        if (file instanceof CloudFile) {
            CloudFile uFile = (CloudFile) file;
            VFile sourceFile = getVfsClient().openFile(new VRL(source.getURI()));
            uFile.uploadFrom(sourceFile);
        } else if (file instanceof WebdavFile) {
            WebdavFile wFile = (WebdavFile) file;
            VFile sourceFile = getVfsClient().openFile(new VRL(source.getURI()));
            wFile.uploadFrom(sourceFile);
        }
        reconnectAttemts = 0;
    } catch (Exception ex) {
        if (reconnectAttemts < Constants.RECONNECT_NTRY) {
            reconnect();
            upload(source);
        } else {
            throw ex;
        }
    } catch (Throwable ex) {
        if (reconnectAttemts < Constants.RECONNECT_NTRY) {
            reconnect();
            upload(source);
        } else {
            throw ex;
        }
    }
}
Also used : VRL(nl.uva.vlet.vrl.VRL) CloudFile(nl.uva.vlet.vfs.cloud.CloudFile) WebdavFile(nl.uva.vlet.vfs.webdavfs.WebdavFile) URISyntaxException(java.net.URISyntaxException) ResourceNotFoundException(nl.uva.vlet.exception.ResourceNotFoundException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) JAXBException(javax.xml.bind.JAXBException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) VlException(nl.uva.vlet.exception.VlException) VRLSyntaxException(nl.uva.vlet.exception.VRLSyntaxException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) CertificateException(java.security.cert.CertificateException) UnknownHostException(java.net.UnknownHostException) BadPaddingException(javax.crypto.BadPaddingException)

Example 9 with VRL

use of nl.uva.vlet.vrl.VRL in project lobcder by skoulouzis.

the class VPDRI method putData.

@Override
public void putData(InputStream in) throws IOException {
    OutputStream out = null;
    double start = System.currentTimeMillis();
    // VFile tmpFile = null;
    try {
        // upload(in);
        VRL parentVrl = vrl.getParent();
        VDir remoteDir = getVfsClient().mkdirs(parentVrl, true);
        getVfsClient().createFile(vrl, true);
        out = getVfsClient().getFile(vrl).getOutputStream();
        if (!getEncrypted()) {
            // CircularStreamBufferTransferer cBuff = new CircularStreamBufferTransferer((Constants.BUF_SIZE), in, out);
            // cBuff.startTransfer(new Long(-1));
            int read;
            byte[] copyBuffer = new byte[Constants.BUF_SIZE];
            while ((read = in.read(copyBuffer, 0, copyBuffer.length)) != -1) {
                out.write(copyBuffer, 0, read);
            }
        } else {
            DesEncrypter encrypter = new DesEncrypter(getKeyInt());
            encrypter.encrypt(in, out);
        }
        reconnectAttemts = 0;
    } catch (nl.uva.vlet.exception.VlAuthenticationException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException ex) {
        throw new IOException(ex);
    } catch (VlException ex) {
        if (ex.getMessage() != null) {
            Logger.getLogger(VPDRI.class.getName()).log(Level.FINE, "\tVlException {0}", ex.getMessage());
        }
        if (reconnectAttemts <= 2) {
            Logger.getLogger(VPDRI.class.getName()).log(Level.FINE, "\treconnectAttemts {0}", reconnectAttemts);
            reconnect();
            putData(in);
        } else {
            throw new IOException(ex);
        }
    // if (ex instanceof ResourceNotFoundException || ex.getMessage().contains("not found") || ex.getMessage().contains("Couldn open location") || ex.getMessage().contains("not found in container")) {
    // try {
    // vfsClient.mkdirs(vrl.getParent(), true);
    // vfsClient.createFile(vrl, true);
    // putData(in);
    // } catch (VlException ex1) {
    // throw new IOException(ex1);
    // }
    // }
    } finally {
        if (out != null) {
            try {
                out.flush();
                out.close();
            } catch (java.io.IOException ex) {
            }
        }
        if (in != null) {
            in.close();
        }
    }
    double elapsed = System.currentTimeMillis() - start;
    double speed = ((getLength() * 8.0) * 1000.0) / (elapsed * 1000.0);
    try {
        String msg = "File: " + this.getFileName() + " Destination: " + new URI(getURI()).getScheme() + "://" + getHost() + " Rx_Speed: " + speed + " Kbites/sec Rx_Size: " + (getLength()) + " bytes Elapsed_Time: " + elapsed + " ms";
        Logger.getLogger(VPDRI.class.getName()).log(Level.INFO, msg);
    } catch (URISyntaxException ex) {
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) java.io(java.io) VlException(nl.uva.vlet.exception.VlException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) DesEncrypter(nl.uva.cs.lobcder.util.DesEncrypter) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) URI(java.net.URI) VRL(nl.uva.vlet.vrl.VRL)

Example 10 with VRL

use of nl.uva.vlet.vrl.VRL in project lobcder by skoulouzis.

the class Assimilator method assimilate.

private void assimilate(List<StorageSite> sites) throws SQLException, MalformedURLException, VlException, NoSuchAlgorithmException, Exception {
    Connection c = getConnection();
    StorageSiteClient ssClient;
    for (StorageSite site : sites) {
        String username = site.getCredential().getStorageSiteUsername();
        String password = site.getCredential().getStorageSitePassword();
        String ssURI = site.getResourceURI();
        long ssID = getStorageSiteID(c, ssURI);
        if (ssID == -1) {
            long credentialsID = addCredentials(c, username, password);
            ssID = addStorageSite(c, site, credentialsID, false);
        }
        URI importedURI = new URI(site.getResourceURI());
        String importedFolderName = "ImportedFrom-" + importedURI.getScheme() + "-" + importedURI.getHost();
        // Add imported folder
        LogicalData imported = getLogicalDataByPath(Path.path(importedFolderName), c);
        Long importedUid;
        if (imported == null) {
            importedUid = addRegisteredFolder(importedFolderName, c);
        } else {
            importedUid = imported.getUid();
        }
        // 
        ssClient = new StorageSiteClient(username, password, ssURI);
        VNode dir = ssClient.getStorageSiteClient().getNode(new VRL(ssURI));
        // VFSClient client = (VFSClient) ssClient.getStorageSiteClient();
        // VDir dir = client.openDir(new VRL(ssURI));
        // build folders first
        nl.uva.vlet.vdriver.vrs.http.HTTPNode k = (nl.uva.vlet.vdriver.vrs.http.HTTPNode) dir;
        // k.getInputStream()
        add((VComposite) dir, dir.getPath(), c, ssID, false);
        VNode[] nodes = ((VComposite) dir).getNodes();
        for (VNode n : nodes) {
            if (!n.isComposite()) {
                VFile f = (VFile) n;
                String fileName = n.getName();
                VRL currentPath = new VRL(f.getPath().replaceFirst(dir.getPath(), ""));
                LogicalData parent = getLogicalDataByPath(Path.path(currentPath.getPath()), c);
                Long parentRef;
                if (parent != null) {
                    parentRef = parent.getUid();
                } else {
                    parentRef = importedUid;
                }
                LogicalData registered = getLogicalDataByParentRefAndName(parentRef, fileName, c);
                System.err.println(currentPath);
                if (registered == null) {
                    addFile(c, f, parentRef, ssID);
                }
            }
        }
    }
    c.commit();
    c.close();
}
Also used : URI(java.net.URI) VFile(nl.uva.vlet.vfs.VFile) LogicalData(nl.uva.cs.lobcder.resources.LogicalData) VRL(nl.uva.vlet.vrl.VRL) StorageSite(nl.uva.cs.lobcder.resources.StorageSite) VNode(nl.uva.vlet.vrs.VNode) VComposite(nl.uva.vlet.vrs.VComposite)

Aggregations

VRL (nl.uva.vlet.vrl.VRL)11 LogicalData (nl.uva.cs.lobcder.resources.LogicalData)4 VlException (nl.uva.vlet.exception.VlException)4 VFSClient (nl.uva.vlet.vfs.VFSClient)4 GridProxy (nl.uva.vlet.util.cog.GridProxy)3 VFile (nl.uva.vlet.vfs.VFile)3 ServerInfo (nl.uva.vlet.vrs.ServerInfo)3 VRSContext (nl.uva.vlet.vrs.VRSContext)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)2 JAXBException (javax.xml.bind.JAXBException)2 VRLSyntaxException (nl.uva.vlet.exception.VRLSyntaxException)2 VNode (nl.uva.vlet.vrs.VNode)2 java.io (java.io)1 UnknownHostException (java.net.UnknownHostException)1 CertificateException (java.security.cert.CertificateException)1