Search in sources :

Example 11 with StorageSite

use of nl.uva.cs.lobcder.resources.StorageSite in project lobcder by skoulouzis.

the class FastestSiteReplicationPolicy method getStorageSites.

private Map<String, StorageSite> getStorageSites(Connection connection) throws SQLException {
    try (Statement s = connection.createStatement()) {
        ResultSet rs = s.executeQuery("SELECT storageSiteId, resourceURI, " + "currentNum, currentSize, quotaNum, quotaSize, username, " + "password, encrypt FROM storage_site_table JOIN credential_table ON " + "credentialRef = credintialId " + "WHERE private=FALSE AND removing=FALSE AND isCache=FALSE AND readOnly = FALSE");
        Map<String, StorageSite> res = new HashMap<>();
        while (rs.next()) {
            Credential c = new Credential();
            c.setStorageSiteUsername(rs.getString(7));
            c.setStorageSitePassword(rs.getString(8));
            StorageSite ss = new StorageSite();
            ss.setStorageSiteId(rs.getLong(1));
            ss.setCredential(c);
            String uri = rs.getString(2);
            ss.setResourceURI(uri);
            ss.setCurrentNum(rs.getLong(3));
            ss.setCurrentSize(rs.getLong(4));
            ss.setQuotaNum(rs.getLong(5));
            ss.setQuotaSize(rs.getLong(6));
            ss.setEncrypt(rs.getBoolean(9));
            res.put(uri, ss);
        }
        return res;
    }
}
Also used : Credential(nl.uva.cs.lobcder.resources.Credential) HashMap(java.util.HashMap) Statement(java.sql.Statement) StorageSite(nl.uva.cs.lobcder.resources.StorageSite) ResultSet(java.sql.ResultSet)

Example 12 with StorageSite

use of nl.uva.cs.lobcder.resources.StorageSite 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

StorageSite (nl.uva.cs.lobcder.resources.StorageSite)12 ArrayList (java.util.ArrayList)6 Credential (nl.uva.cs.lobcder.resources.Credential)6 HashMap (java.util.HashMap)3 StorageSiteWrapper (nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper)3 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 CredentialWrapped (nl.uva.cs.lobcder.rest.wrappers.CredentialWrapped)2 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Connection (java.sql.Connection)1 LinkedList (java.util.LinkedList)1 Random (java.util.Random)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 MyPrincipal (nl.uva.cs.lobcder.auth.MyPrincipal)1 LogicalData (nl.uva.cs.lobcder.resources.LogicalData)1 StorageSiteWrapperList (nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapperList)1