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;
}
}
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();
}
Aggregations