use of nl.uva.cs.lobcder.catalogue.beans.PdriGroupBean 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.PdriGroupBean 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