use of nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper in project lobcder by skoulouzis.
the class Catalogue method getStorageSites.
private List<StorageSiteWrapper> getStorageSites(String id) throws URISyntaxException, UnknownHostException, SocketException, IOException {
if (restClient == null) {
restClient = Client.create(clientConfig);
restClient.removeAllFilters();
restClient.addFilter(new com.sun.jersey.api.client.filter.HTTPBasicAuthFilter("worker-", token));
webResource = restClient.resource(restURL);
}
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("id", id);
WebResource res = webResource.path("storage_sites").queryParams(params);
StorageSiteWrapperList storageSiteList = res.accept(MediaType.APPLICATION_XML).get(new GenericType<StorageSiteWrapperList>() {
});
List<StorageSiteWrapper> ssites = removeUnreachableStorageSites(storageSiteList);
for (StorageSiteWrapper ssw : ssites) {
storageSiteCache.put(ssw.getStorageSiteId(), ssw);
}
return ssites;
}
use of nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper in project lobcder by skoulouzis.
the class Catalogue method removeUnreachableStorageSites.
private List<StorageSiteWrapper> removeUnreachableStorageSites(StorageSiteWrapperList sites) throws URISyntaxException, UnknownHostException, SocketException, IOException {
List<StorageSiteWrapper> ssites = sites.getSites();
if (ssites != null) {
List<StorageSiteWrapper> removeIt = new ArrayList<>();
for (StorageSiteWrapper p : sites.getSites()) {
URI uri = new URI(p.getResourceURI());
String pdriHost = uri.getHost();
String pdriScheme = uri.getScheme();
if (pdriHost == null || pdriHost.equals("localhost") || pdriHost.startsWith("127.0.")) {
removeIt.add(p);
} else if (pdriScheme.equals("file") && !Catalogue.isPDRIOnWorker(new URI(p.getResourceURI()))) {
removeIt.add(p);
}
}
if (!removeIt.isEmpty()) {
ssites.removeAll(removeIt);
if (ssites.isEmpty()) {
Logger.getLogger(Catalogue.class.getName()).log(Level.SEVERE, "PDRIS from master is either empty or contains unreachable files");
throw new IOException("PDRIS from master is either empty or contains unreachable files");
}
}
}
return ssites;
}
use of nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper in project lobcder by skoulouzis.
the class Catalogue method replicate.
boolean replicate(Pair<File, String> p) throws IOException {
boolean result = true;
PDRIDescr sourceDescr = createPdriDescr(p.getLeft());
PDRI sourcePdri = PDRIFactory.getFactory().createInstance(sourceDescr);
String[] sites = p.getRight().split("-");
Long fileUID = Long.valueOf(sites[0]);
Long pdriGroupId = Long.valueOf(sites[1]);
List<PDRIDescr> destinationDescrList = new ArrayList<>();
for (int i = 2; i < sites.length; i++) {
try {
StorageSiteWrapper ss = storageSiteCache.get(Long.valueOf(sites[i]));
if (ss == null) {
getStorageSites(String.valueOf(Long.valueOf(sites[i])));
ss = storageSiteCache.get(Long.valueOf(sites[i]));
}
BigInteger pdriKey = nl.uva.cs.lobcder.util.DesEncrypter.generateKey();
PDRIDescr destinationDescr = new PDRIDescr(sourceDescr.getName(), ss.getStorageSiteId(), ss.getResourceURI(), ss.getCredential().getStorageSiteUsername(), ss.getCredential().getStorageSitePassword(), ss.isEncrypt(), pdriKey, pdriGroupId, null, ss.isCache());
PDRI destinationPdri = PDRIFactory.getFactory().createInstance(destinationDescr);
destinationPdri.replicate(sourcePdri);
result = destinationPdri.exists(destinationPdri.getFileName());
long srcLen = sourcePdri.getLength();
if (result == false || destinationPdri.getLength() != srcLen) {
result = false;
}
destinationDescrList.add(destinationDescr);
} catch (Exception e) {
result = false;
} catch (Throwable e) {
result = false;
}
}
result = updateMaster(destinationDescrList, fileUID);
return result;
}
Aggregations