Search in sources :

Example 1 with StorageSiteBean

use of nl.uva.cs.lobcder.catalogue.beans.StorageSiteBean 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;
    }
}
Also used : StorageSiteBean(nl.uva.cs.lobcder.catalogue.beans.StorageSiteBean) PdriBean(nl.uva.cs.lobcder.catalogue.beans.PdriBean) BigInteger(java.math.BigInteger) PDRI(nl.uva.cs.lobcder.resources.PDRI) IOException(java.io.IOException)

Example 2 with StorageSiteBean

use of nl.uva.cs.lobcder.catalogue.beans.StorageSiteBean in project lobcder by skoulouzis.

the class RandomReplicationPolicyJDBC method getSitesToReplicate.

@Override
public Set<StorageSiteBean> getSitesToReplicate() throws Exception {
    try (Connection connection = getConnection()) {
        connection.setAutoCommit(true);
        try (Statement statement = connection.createStatement()) {
            ResultSet resultSet = statement.executeQuery("SELECT storageSiteId, resourceUri, encrypt, extra, username, password FROM storage_site_table JOIN credential_table ON credentialRef=credintialId WHERE private=FALSE AND removing=FALSE AND isCache=FALSE");
            ArrayList<StorageSiteBean> queryResult = new ArrayList<>(resultSet.getFetchSize());
            while (resultSet.next()) {
                queryResult.add(new StorageSiteBean(resultSet.getLong(1), resultSet.getString(2), resultSet.getBoolean(3), Boolean.FALSE, resultSet.getString(4), new CredentialBean(resultSet.getString(5), resultSet.getString(6))));
            }
            number = PropertiesHelper.getNumberOfSites();
            Collections.shuffle(queryResult);
            if (number > queryResult.size()) {
                number = queryResult.size();
            }
            return new HashSet<>(queryResult.subList(0, number));
        }
    }
}
Also used : StorageSiteBean(nl.uva.cs.lobcder.catalogue.beans.StorageSiteBean) Statement(java.sql.Statement) CredentialBean(nl.uva.cs.lobcder.catalogue.beans.CredentialBean) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 3 with StorageSiteBean

use of nl.uva.cs.lobcder.catalogue.beans.StorageSiteBean 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;
// }
// }
}
Also used : StorageSiteBean(nl.uva.cs.lobcder.catalogue.beans.StorageSiteBean) PdriBean(nl.uva.cs.lobcder.catalogue.beans.PdriBean) CredentialBean(nl.uva.cs.lobcder.catalogue.beans.CredentialBean) ArrayList(java.util.ArrayList) PdriGroupBean(nl.uva.cs.lobcder.catalogue.beans.PdriGroupBean)

Example 4 with StorageSiteBean

use of nl.uva.cs.lobcder.catalogue.beans.StorageSiteBean 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);
    }
}
Also used : StorageSiteBean(nl.uva.cs.lobcder.catalogue.beans.StorageSiteBean) ItemBean(nl.uva.cs.lobcder.catalogue.beans.ItemBean) PdriGroupBean(nl.uva.cs.lobcder.catalogue.beans.PdriGroupBean) PdriBean(nl.uva.cs.lobcder.catalogue.beans.PdriBean) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

StorageSiteBean (nl.uva.cs.lobcder.catalogue.beans.StorageSiteBean)4 PdriBean (nl.uva.cs.lobcder.catalogue.beans.PdriBean)3 IOException (java.io.IOException)2 CredentialBean (nl.uva.cs.lobcder.catalogue.beans.CredentialBean)2 PdriGroupBean (nl.uva.cs.lobcder.catalogue.beans.PdriGroupBean)2 BigInteger (java.math.BigInteger)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ItemBean (nl.uva.cs.lobcder.catalogue.beans.ItemBean)1 PDRI (nl.uva.cs.lobcder.resources.PDRI)1