Search in sources :

Example 1 with ScheduledEvent

use of com.emc.storageos.db.client.model.uimodels.ScheduledEvent 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 2 with ScheduledEvent

use of com.emc.storageos.db.client.model.uimodels.ScheduledEvent 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 3 with ScheduledEvent

use of com.emc.storageos.db.client.model.uimodels.ScheduledEvent 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 4 with ScheduledEvent

use of com.emc.storageos.db.client.model.uimodels.ScheduledEvent in project coprhd-controller by CoprHD.

the class ViPRService method isRetentionRequired.

/**
 * Check if it is a recurrent order and retention policy is defined
 *
 * @return true if retention policy defined
 */
protected boolean isRetentionRequired() {
    ScheduledEvent event = ExecutionUtils.currentContext().getScheduledEvent();
    if (event == null) {
        return false;
    }
    try {
        OrderCreateParam param = OrderCreateParam.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getOrderCreationParam().getBytes(UTF_8)));
        String additionalScheduleInfo = param.getAdditionalScheduleInfo();
        if (additionalScheduleInfo == null) {
            return false;
        }
        Integer.parseInt(additionalScheduleInfo);
    } catch (Exception ex) {
        error("Unexpected exception when checking scheduler retention", ex);
        return false;
    }
    return true;
}
Also used : ScheduledEvent(com.emc.storageos.db.client.model.uimodels.ScheduledEvent) OrderCreateParam(com.emc.vipr.model.catalog.OrderCreateParam) IOException(java.io.IOException)

Example 5 with ScheduledEvent

use of com.emc.storageos.db.client.model.uimodels.ScheduledEvent in project coprhd-controller by CoprHD.

the class OrderService method cancelOrder.

@POST
@Path("/{id}/cancel")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response cancelOrder(@PathParam("id") String id) {
    Order order = queryResource(uri(id));
    ArgValidator.checkEntity(order, uri(id), true);
    StorageOSUser user = getUserFromContext();
    verifyAuthorizedInTenantOrg(uri(order.getTenant()), user);
    if (!OrderStatus.valueOf(order.getOrderStatus()).equals(OrderStatus.SCHEDULED)) {
        throw APIException.badRequests.unexpectedValueForProperty("orderStatus", OrderStatus.SCHEDULED.toString(), order.getOrderStatus());
    }
    if (order.getScheduledEventId() != null) {
        ScheduledEvent scheduledEvent = client.scheduledEvents().findById(order.getScheduledEventId());
        if (scheduledEvent.getEventType().equals(ScheduledEventType.ONCE)) {
            scheduledEvent.setEventStatus(ScheduledEventStatus.CANCELLED);
            client.save(scheduledEvent);
        }
        order.setOrderStatus(OrderStatus.CANCELLED.name());
        client.save(order);
    } else {
        orderManager.cancelOrder(order);
    }
    return Response.ok().build();
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ScheduledEvent(com.emc.storageos.db.client.model.uimodels.ScheduledEvent) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

ScheduledEvent (com.emc.storageos.db.client.model.uimodels.ScheduledEvent)8 URI (java.net.URI)4 RetainedReplica (com.emc.storageos.db.client.model.uimodels.RetainedReplica)3 OrderCreateParam (com.emc.vipr.model.catalog.OrderCreateParam)3 NamedElement (com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)2 StringSet (com.emc.storageos.db.client.model.StringSet)2 Order (com.emc.storageos.db.client.model.uimodels.Order)2 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)2 IOException (java.io.IOException)2 TimeSeriesConstraint (com.emc.storageos.db.client.constraint.TimeSeriesConstraint)1 CatalogService (com.emc.storageos.db.client.model.uimodels.CatalogService)1 ExecutionState (com.emc.storageos.db.client.model.uimodels.ExecutionState)1 ExecutionWindow (com.emc.storageos.db.client.model.uimodels.ExecutionWindow)1 OrderParameter (com.emc.storageos.db.client.model.uimodels.OrderParameter)1 ExecutionWindowHelper (com.emc.storageos.db.client.util.ExecutionWindowHelper)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 ScheduleInfo (com.emc.vipr.model.catalog.ScheduleInfo)1 URISyntaxException (java.net.URISyntaxException)1 InvalidParameterException (java.security.InvalidParameterException)1