use of nl.uva.cs.lobcder.resources.PDRIDescr in project lobcder by skoulouzis.
the class StorageSitesService method updateLogicalDataAndPdri.
@PUT
@Path("update_pdri/{uid}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public void updateLogicalDataAndPdri(PDRIDescrWrapperList pdris, @PathParam("uid") Long uid) throws SQLException, IOException {
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
if (mp.isAdmin()) {
try (Connection cn = getCatalogue().getConnection()) {
for (PDRIDescr pdriDescr : pdris.getPdris()) {
LogicalData logicalData = getCatalogue().getLogicalDataByUid(uid, cn);
PDRI pdri = PDRIFactory.getFactory().createInstance(pdriDescr, false);
logicalData.setLength(pdri.getLength());
getCatalogue().updatePdri(logicalData, pdri, cn);
}
cn.commit();
cn.close();
}
}
}
use of nl.uva.cs.lobcder.resources.PDRIDescr in project lobcder by skoulouzis.
the class Catalogue method getPDRI.
public PDRI getPDRI(String fileUID) throws InterruptedException, IOException, URISyntaxException {
LogicalDataWrapped logicalData = getLogicalDataWrapped(fileUID);
// new PDRIDescr();
PDRIDescr pdriDesc = null;
pdriDesc = selectBestPDRI(logicalData.getPdriList());
Logger.getLogger(Catalogue.class.getName()).log(Level.FINE, "Selected pdri: {0}", pdriDesc.getResourceUrl());
return new VPDRI(pdriDesc.getName(), pdriDesc.getId(), pdriDesc.getResourceUrl(), pdriDesc.getUsername(), pdriDesc.getPassword(), pdriDesc.getEncrypt(), pdriDesc.getKey(), false);
}
use of nl.uva.cs.lobcder.resources.PDRIDescr in project lobcder by skoulouzis.
the class Catalogue method selectBestPDRI.
private PDRIDescr selectBestPDRI(List<PDRIDescr> pdris) throws URISyntaxException, UnknownHostException, SocketException {
if (!pdris.isEmpty()) {
Iterator<PDRIDescr> iter = pdris.iterator();
while (iter.hasNext()) {
PDRIDescr p = iter.next();
URI uri = new URI(p.getResourceUrl());
if (uri.getScheme().equals("file")) {
return p;
}
if (Catalogue.isPDRIOnWorker(uri)) {
String resURL = p.getResourceUrl().replaceFirst(uri.getScheme(), "file");
p.setResourceUrl(resURL);
return p;
}
}
}
if (weightPDRIMap.isEmpty() || weightPDRIMap.size() < pdris.size()) {
// Just return one at random;
int index = new Random().nextInt(pdris.size());
PDRIDescr[] array = pdris.toArray(new PDRIDescr[pdris.size()]);
Logger.getLogger(Catalogue.class.getName()).log(Level.FINE, "Selecting Random: {0}", array[index].getResourceUrl());
return array[index];
}
long sumOfSpeed = 0;
for (PDRIDescr p : pdris) {
URI uri = new URI(p.getResourceUrl());
String host = null;
if (uri.getScheme().equals("file") || StringUtil.isEmpty(uri.getHost()) || uri.getHost().equals("localhost") || uri.getHost().equals("127.0.0.1")) {
try {
host = InetAddress.getLocalHost().getHostName();
} catch (Exception ex) {
List<String> ips = Util.getAllIPs();
for (String ip : ips) {
if (ip.contains(".")) {
host = ip;
break;
}
}
}
} else {
host = uri.getHost();
}
Double speed = weightPDRIMap.get(host);
if (speed == null) {
speed = Double.valueOf(0);
}
Logger.getLogger(Catalogue.class.getName()).log(Level.FINE, "Speed: {0}", speed);
sumOfSpeed += speed;
}
if (sumOfSpeed <= 0) {
int index = new Random().nextInt(pdris.size());
PDRIDescr[] array = pdris.toArray(new PDRIDescr[pdris.size()]);
return array[index];
}
int itemIndex = new Random().nextInt((int) sumOfSpeed);
for (PDRIDescr p : pdris) {
Double speed = weightPDRIMap.get(new URI(p.getResourceUrl()).getHost());
if (speed == null) {
speed = Double.valueOf(0);
}
if (itemIndex < speed) {
Logger.getLogger(Catalogue.class.getName()).log(Level.FINE, "Selecting:{0} with speed: {1}", new Object[] { p.getResourceUrl(), speed });
return p;
}
itemIndex -= speed;
}
int index = new Random().nextInt(pdris.size());
PDRIDescr[] array = pdris.toArray(new PDRIDescr[pdris.size()]);
PDRIDescr res = array[index];
return res;
}
use of nl.uva.cs.lobcder.resources.PDRIDescr in project lobcder by skoulouzis.
the class Catalogue method addCacheFileToPDRIDescr.
private LogicalDataWrapped addCacheFileToPDRIDescr(LogicalDataWrapped logicalData) throws IOException, URISyntaxException {
List<PDRIDescr> pdris = logicalData.getPdriList();
cacheFile = new File(Util.getCacheDir(), pdris.get(0).getName());
if (!isFileOnWorker(logicalData) && cacheFile.exists() && !isCacheInPdriList(cacheFile, logicalData)) {
String fileName = cacheFile.getName();
long ssID = -1;
String resourceURI = "file:///" + cacheFile.getAbsoluteFile().getParentFile().getParent();
String uName = "fake";
String passwd = "fake";
boolean encrypt = false;
long key = -1;
long pdriId = -1;
Long groupId = Long.valueOf(-1);
boolean isCache = false;
pdris.add(new PDRIDescr(fileName, ssID, resourceURI, uName, passwd, encrypt, BigInteger.valueOf(key), groupId, pdriId, isCache));
switch(Util.getCacheEvictionPolicy()) {
case LRU:
case MRU:
case RR:
fileAccessMap.put(cacheFile.getAbsolutePath(), System.currentTimeMillis());
break;
case LFU:
case MFU:
Long count = fileAccessMap.get(cacheFile.getAbsolutePath());
if (count == null) {
count = Long.valueOf(0);
}
fileAccessMap.put(cacheFile.getAbsolutePath(), count++);
break;
}
logicalData.setPdriList(pdris);
}
return logicalData;
}
use of nl.uva.cs.lobcder.resources.PDRIDescr 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