use of nl.uva.cs.lobcder.catalogue.beans.PdriBean in project lobcder by skoulouzis.
the class ReplicateSweep method removePdris.
private void removePdris(Set<PdriBean> removePdriBeans) throws Exception {
for (PdriBean pdriBean : removePdriBeans) {
DeleteHelper.delete(pdriBean);
connector.reportDeletedPdri(pdriBean);
}
}
use of nl.uva.cs.lobcder.catalogue.beans.PdriBean in project lobcder by skoulouzis.
the class ReplicateSweep method replicate.
private void replicate(PdriGroupBean source, Set<StorageSiteBean> toReplicate) throws Exception {
PDRI destinationPdri = null;
PdriBean sourcePdriBean = getSourcePdriForGroup(source);
PDRI sourcePdri = PDRIFactory.getFactory().createInstance(sourcePdriBean);
try {
for (StorageSiteBean storageSiteBean : toReplicate) {
BigInteger pdriKey = DesEncrypter.generateKey();
PdriBean destinationPdriBean = new PdriBean(null, generateFileName(sourcePdriBean), pdriKey, storageSiteBean);
destinationPdri = PDRIFactory.getFactory().createInstance(destinationPdriBean);
if (!destinationPdri.exists(destinationPdri.getFileName())) {
destinationPdri.replicate(sourcePdri);
}
connector.reportNewReplica(destinationPdriBean, source);
destinationPdri = null;
}
} catch (Exception e) {
Logger.getLogger(ReplicateSweep.class.getName()).log(Level.WARNING, null, e);
if (destinationPdri != null) {
destinationPdri.delete();
}
throw e;
}
}
use of nl.uva.cs.lobcder.catalogue.beans.PdriBean in project lobcder by skoulouzis.
the class ConnectorJDBC method getPdriGroupsToProcess.
@Override
public Collection<PdriGroupBean> getPdriGroupsToProcess() throws Exception {
try (Connection connection = datasource.getConnection()) {
connection.setAutoCommit(true);
ArrayList<Long> pdriGroups = new ArrayList<>();
try (CallableStatement s1 = connection.prepareCall("call GET_PDRI_GROUPS_FOR_DELETE(?)")) {
s1.setInt(1, limit);
ResultSet rs = s1.executeQuery();
while (rs.next()) {
pdriGroups.add(rs.getLong(1));
}
}
ArrayList<PdriGroupBean> result = new ArrayList<>(pdriGroups.size());
try (PreparedStatement ps = connection.prepareStatement("SELECT pdriId, fileName, storageSiteRef, resourceUri, username, password " + "FROM pdri_table " + "JOIN storage_site_table ON storage_site_table.storageSiteId = pdri_table.storageSiteRef " + "JOIN credential_table ON storage_site_table.credentialRef = credintialId " + "WHERE pdriGroupRef = ?")) {
for (Long pdrigrId : pdriGroups) {
ps.setLong(1, pdrigrId);
ResultSet rs = ps.executeQuery();
PdriGroupBean pdriGroupBean = new PdriGroupBean();
pdriGroupBean.setId(pdrigrId);
if (rs.next()) {
ArrayList<PdriBean> pdriBeans = new ArrayList<>();
do {
pdriBeans.add(new PdriBean(rs.getLong(1), rs.getString(2), null, new StorageSiteBean(rs.getLong(3), rs.getString(4), null, null, null, new CredentialBean(rs.getString(5), rs.getString(6)))));
} while (rs.next());
pdriGroupBean.setPdri(pdriBeans);
}
result.add(pdriGroupBean);
}
}
return result;
}
// catch (Exception ex) {
// reconnectAttemts++;
// if (reconnectAttemts < Constants.RECONNECT_NTRY) {
// sleeTime = sleeTime * 2;
// Thread.sleep(sleeTime);
// return getPdriGroupsToProcess();
// } else {
// reconnectAttemts = 0;
// sleeTime = 100;
// throw ex;
// }
// }
}
use of nl.uva.cs.lobcder.catalogue.beans.PdriBean in project lobcder by skoulouzis.
the class ReplicateSweep method getSourcePdriForGroup.
private PdriBean getSourcePdriForGroup(PdriGroupBean source) {
Set<PdriBean> noCache = new HashSet<>();
for (PdriBean pdriBean : source.getPdri()) {
if (isLocalCachePdri(pdriBean))
return pdriBean;
if (!pdriBean.getStorage().getCache())
noCache.add(pdriBean);
}
PdriBean[] arr = noCache.toArray(new PdriBean[noCache.size()]);
return arr[new Random().nextInt(arr.length)];
}
use of nl.uva.cs.lobcder.catalogue.beans.PdriBean in project lobcder by skoulouzis.
the class ReplicateSweep method run.
@Override
public void run() {
try {
Collection<PdriGroupBean> pdriGroupBeanCollection = connector.selectPdriGroupsToRelocate(localCacheId);
if (pdriGroupBeanCollection != null) {
for (PdriGroupBean pdriGroupBean : pdriGroupBeanCollection) {
try {
Set<StorageSiteBean> preferences = new HashSet<>();
if (pdriGroupBean.getItem() != null) {
for (ItemBean itemBean : pdriGroupBean.getItem()) {
Collection<StorageSiteBean> itemPreferences = itemBean.getPreference();
if (itemPreferences != null)
preferences.addAll(itemPreferences);
}
}
Set<StorageSiteBean> toReplicate = new HashSet<>(preferences);
Set<PdriBean> wantRemove = new HashSet<>();
Set<StorageSiteBean> removingStorage = connector.getRemovingStorage();
Set<PdriBean> noCache = new HashSet<>();
Set<PdriBean> remoteCache = new HashSet<>();
if (pdriGroupBean.getPdri() != null) {
for (PdriBean pdriBean : pdriGroupBean.getPdri()) {
if (isLocalCachePdri(pdriBean)) {
wantRemove.add(pdriBean);
} else {
if (pdriBean.getStorage().getCache()) {
remoteCache.add(pdriBean);
} else {
if (preferences.isEmpty()) {
if (removingStorage.contains(pdriBean.getStorage())) {
wantRemove.add(pdriBean);
} else {
noCache.add(pdriBean);
}
} else {
if (preferences.contains(pdriBean.getStorage())) {
toReplicate.remove(pdriBean.getStorage());
} else {
wantRemove.add(pdriBean);
}
}
}
}
}
}
if (preferences.isEmpty()) {
if (noCache.isEmpty()) {
replicate(pdriGroupBean, replicationPolicy.getSitesToReplicate());
}
} else {
replicate(pdriGroupBean, toReplicate);
}
removePdris(wantRemove);
if (remoteCache.isEmpty()) {
connector.reportPdriGroupDone(pdriGroupBean);
} else {
connector.reportPdriGroupRelease(pdriGroupBean);
}
} catch (Exception e) {
Logger.getLogger(ReplicateSweep.class.getName()).log(Level.SEVERE, null, e);
connector.reportPdriGroupRelease(pdriGroupBean);
}
}
}
} catch (Exception e) {
Logger.getLogger(ReplicateSweep.class.getName()).log(Level.SEVERE, null, e);
}
}
Aggregations