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;
}
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);
}
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);
}
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;
}
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();
}
Aggregations