use of com.emc.storageos.db.client.model.uimodels.RetainedReplica in project coprhd-controller by CoprHD.
the class CreateFileSnapshotService method checkAndPurgeObsoleteSnapshot.
/**
* Check retention policy and delete obsolete full copies if necessary
*
* @param fileSystemId - file system id
*/
private void checkAndPurgeObsoleteSnapshot(String fileSystemId) {
if (!isRetentionRequired()) {
return;
}
List<RetainedReplica> replicas = findObsoleteReplica(fileSystemId);
for (RetainedReplica replica : replicas) {
for (String obsoleteCopyId : replica.getAssociatedReplicaIds()) {
info("Delete snapshot %s since it exceeds max number of copies allowed", obsoleteCopyId);
FileStorageUtils.deleteFileSnapshot(uri(obsoleteCopyId));
}
getModelClient().delete(replica);
}
}
use of com.emc.storageos.db.client.model.uimodels.RetainedReplica in project coprhd-controller by CoprHD.
the class ViPRService method findObsoleteReplica.
/**
* Find obsolete replicas for given resource according to defined retention policy of this order
*
* @param resourceId
* @return the replica to be removed. Otherwise null in case of no removal required
*/
protected List<RetainedReplica> findObsoleteReplica(String resourceId) {
List<RetainedReplica> obsoleteReplicas = new ArrayList<RetainedReplica>();
ScheduledEvent event = ExecutionUtils.currentContext().getScheduledEvent();
Integer maxNumOfCopies = Integer.MAX_VALUE;
try {
OrderCreateParam param = OrderCreateParam.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getOrderCreationParam().getBytes(UTF_8)));
String additionalScheduleInfo = param.getAdditionalScheduleInfo();
maxNumOfCopies = Integer.parseInt(additionalScheduleInfo);
} catch (Exception ex) {
error("Unexpected exception when checking scheduler retention", ex);
return obsoleteReplicas;
}
List<NamedElement> replicaIdList = modelClient.findBy(RetainedReplica.class, "scheduledEventId", event.getId());
List<RetainedReplica> replicas = new ArrayList<RetainedReplica>();
for (NamedElement uri : replicaIdList) {
RetainedReplica retention = modelClient.findById(RetainedReplica.class, uri.getId());
if (retention.getResourceId().toString().equals(resourceId)) {
replicas.add(retention);
}
}
if (replicas.size() >= maxNumOfCopies) {
Collections.sort(replicas, new Comparator<RetainedReplica>() {
public int compare(RetainedReplica o1, RetainedReplica o2) {
return o1.getCreationTime().compareTo(o2.getCreationTime());
}
});
// get top oldest records
int endIndex = replicas.size() - maxNumOfCopies + 1;
obsoleteReplicas.addAll(replicas.subList(0, endIndex));
}
return obsoleteReplicas;
}
use of com.emc.storageos.db.client.model.uimodels.RetainedReplica in project coprhd-controller by CoprHD.
the class ViPRService method addRetainedReplicas.
protected <T extends DataObjectRestRep> void addRetainedReplicas(URI sourceId, String replicaName) {
if (!isRetentionRequired()) {
return;
}
ScheduledEvent event = ExecutionUtils.currentContext().getScheduledEvent();
RetainedReplica retention = new RetainedReplica();
retention.setScheduledEventId(event.getId());
retention.setResourceId(sourceId);
StringSet retainedResource = new StringSet();
retention.setAssociatedReplicaIds(retainedResource);
retainedResource.add(replicaName);
modelClient.save(retention);
}
use of com.emc.storageos.db.client.model.uimodels.RetainedReplica in project coprhd-controller by CoprHD.
the class ViPRService method addRetainedReplicas.
/**
* Add newly created replica for given volume/CG to db and keep records for applying retention policy
*
* @param sourceId
* @param tasks
*/
protected <T extends DataObjectRestRep> void addRetainedReplicas(URI sourceId, List<Task<T>> tasks) {
if (!isRetentionRequired()) {
return;
}
if (tasks == null) {
return;
}
ScheduledEvent event = ExecutionUtils.currentContext().getScheduledEvent();
RetainedReplica retention = new RetainedReplica();
retention.setScheduledEventId(event.getId());
retention.setResourceId(sourceId);
StringSet retainedResource = new StringSet();
retention.setAssociatedReplicaIds(retainedResource);
for (Task<? extends DataObjectRestRep> task : tasks) {
URI resourceId = task.getResourceId();
if (resourceId != null && !sourceId.equals(resourceId)) {
info("Add %s to retained replica", resourceId.toString());
retainedResource.add(resourceId.toString());
}
if (task.getAssociatedResources() != null && !task.getAssociatedResources().isEmpty()) {
for (URI id : ResourceUtils.refIds(task.getAssociatedResources())) {
if (sourceId.equals(id)) {
continue;
}
info("Add %s to retained replica", id.toString());
retainedResource.add(id.toString());
}
}
}
modelClient.save(retention);
}
use of com.emc.storageos.db.client.model.uimodels.RetainedReplica in project coprhd-controller by CoprHD.
the class CreateCloneOfApplicationService method checkAndPurgeObsoleteClones.
/**
* Check retention policy and delete obsolete snapshots if necessary
*
* @param applicationId - application id
*/
private void checkAndPurgeObsoleteClones(URI applicationId) {
if (!isRetentionRequired()) {
return;
}
List<RetainedReplica> replicas = findObsoleteReplica(applicationId.toString());
for (RetainedReplica replica : replicas) {
for (String replicaName : replica.getAssociatedReplicaIds()) {
info("Delete clones %s since it exceeds max number of clones allowed", replicaName);
removeApplicationFullCopy(applicationId, replicaName, subGroups);
}
getModelClient().delete(replica);
}
}
Aggregations