Search in sources :

Example 1 with RetainedReplica

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);
    }
}
Also used : RetainedReplica(com.emc.storageos.db.client.model.uimodels.RetainedReplica)

Example 2 with RetainedReplica

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;
}
Also used : ScheduledEvent(com.emc.storageos.db.client.model.uimodels.ScheduledEvent) ArrayList(java.util.ArrayList) OrderCreateParam(com.emc.vipr.model.catalog.OrderCreateParam) RetainedReplica(com.emc.storageos.db.client.model.uimodels.RetainedReplica) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement) IOException(java.io.IOException)

Example 3 with RetainedReplica

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);
}
Also used : ScheduledEvent(com.emc.storageos.db.client.model.uimodels.ScheduledEvent) StringSet(com.emc.storageos.db.client.model.StringSet) RetainedReplica(com.emc.storageos.db.client.model.uimodels.RetainedReplica)

Example 4 with RetainedReplica

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);
}
Also used : ScheduledEvent(com.emc.storageos.db.client.model.uimodels.ScheduledEvent) StringSet(com.emc.storageos.db.client.model.StringSet) RetainedReplica(com.emc.storageos.db.client.model.uimodels.RetainedReplica) URI(java.net.URI)

Example 5 with RetainedReplica

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);
    }
}
Also used : RetainedReplica(com.emc.storageos.db.client.model.uimodels.RetainedReplica)

Aggregations

RetainedReplica (com.emc.storageos.db.client.model.uimodels.RetainedReplica)8 ScheduledEvent (com.emc.storageos.db.client.model.uimodels.ScheduledEvent)3 StringSet (com.emc.storageos.db.client.model.StringSet)2 BlockObjectRestRep (com.emc.storageos.model.block.BlockObjectRestRep)2 URI (java.net.URI)2 DeleteSnapshotForApplication (com.emc.sa.service.vipr.application.tasks.DeleteSnapshotForApplication)1 DeleteSnapshotSessionForApplication (com.emc.sa.service.vipr.application.tasks.DeleteSnapshotSessionForApplication)1 DeactivateBlockSnapshot (com.emc.sa.service.vipr.block.tasks.DeactivateBlockSnapshot)1 DeactivateBlockSnapshotSession (com.emc.sa.service.vipr.block.tasks.DeactivateBlockSnapshotSession)1 NamedElement (com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)1 BlockSnapshotSessionRestRep (com.emc.storageos.model.block.BlockSnapshotSessionRestRep)1 OrderCreateParam (com.emc.vipr.model.catalog.OrderCreateParam)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1