Search in sources :

Example 1 with ItemBean

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

IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 ItemBean (nl.uva.cs.lobcder.catalogue.beans.ItemBean)1 PdriBean (nl.uva.cs.lobcder.catalogue.beans.PdriBean)1 PdriGroupBean (nl.uva.cs.lobcder.catalogue.beans.PdriGroupBean)1 StorageSiteBean (nl.uva.cs.lobcder.catalogue.beans.StorageSiteBean)1