Search in sources :

Example 56 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class LocalPasswordHandlerTest method createLocalUsers.

private Map<String, StorageOSUser> createLocalUsers() {
    Map<String, StorageOSUser> locals = new HashMap<String, StorageOSUser>();
    locals.put(LOCAL_ROOT, new StorageOSUser(LOCAL_ROOT, ""));
    locals.put(LOCAL_SYSMON, new StorageOSUser(LOCAL_SYSMON, ""));
    locals.put(LOCAL_PROXYUSER, new StorageOSUser(LOCAL_PROXYUSER, ""));
    return locals;
}
Also used : HashMap(java.util.HashMap) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser)

Example 57 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser 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)

Example 58 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class OrderService method scheduleReoccurenceOrders.

private void scheduleReoccurenceOrders() throws Exception {
    lock = coordinatorClient.getLock(LOCK_NAME);
    try {
        lock.acquire();
        List<ScheduledEvent> scheduledEvents = dataManager.getAllReoccurrenceEvents();
        for (ScheduledEvent event : scheduledEvents) {
            if (event.getEventStatus() != ScheduledEventStatus.APPROVED) {
                log.debug("Skipping event {} which is not in APPROVED status.", event.getId());
                continue;
            }
            URI orderId = event.getLatestOrderId();
            Order order = getOrderById(orderId, false);
            if (!(OrderStatus.valueOf(order.getOrderStatus()).equals(OrderStatus.SUCCESS) || OrderStatus.valueOf(order.getOrderStatus()).equals(OrderStatus.PARTIAL_SUCCESS) || OrderStatus.valueOf(order.getOrderStatus()).equals(OrderStatus.ERROR) || OrderStatus.valueOf(order.getOrderStatus()).equals(OrderStatus.CANCELLED))) {
                log.debug("Skipping event {} whose latest order {} is not finished yet.", event.getId(), order.getId());
                continue;
            }
            log.info("Trying to schedule a new order for event {} : {}", event.getId(), ScheduleInfo.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getScheduleInfo().getBytes(UTF_8))).toString());
            StorageOSUser user = StorageOSUser.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getStorageOSUser().getBytes(UTF_8)));
            OrderCreateParam createParam = OrderCreateParam.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getOrderCreationParam().getBytes(UTF_8)));
            ScheduleInfo scheduleInfo = ScheduleInfo.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getScheduleInfo().getBytes(UTF_8)));
            Calendar nextScheduledTime = ScheduleTimeHelper.getNextScheduledTime(order.getScheduledTime(), scheduleInfo);
            int retry = 0;
            if (order.getExecutionWindowId() != null && !order.getExecutionWindowId().getURI().equals(ExecutionWindow.NEXT)) {
                ExecutionWindow window = client.executionWindows().findById(order.getExecutionWindowId().getURI());
                if (window != null) {
                    ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
                    if (nextScheduledTime != null && !helper.isActive(nextScheduledTime)) {
                        log.warn("Execution window {} might be changed after the event is scheduled.", order.getExecutionWindowId().getURI());
                        log.warn("Otherwise it is a HOURLY scheduled event");
                        do {
                            nextScheduledTime = ScheduleTimeHelper.getNextScheduledTime(nextScheduledTime, scheduleInfo);
                            retry++;
                        } while (nextScheduledTime != null && !helper.isActive(nextScheduledTime) && retry < ScheduleTimeHelper.SCHEDULE_TIME_RETRY_THRESHOLD);
                        if (retry == ScheduleTimeHelper.SCHEDULE_TIME_RETRY_THRESHOLD) {
                            log.error("Failed to find next scheduled time that match with {}", order.getExecutionWindowId().getURI());
                            nextScheduledTime = null;
                        }
                    }
                } else {
                    log.error("Execution window {} does not exist.", order.getExecutionWindowId().getURI());
                }
            }
            if (nextScheduledTime == null) {
                log.info("Scheduled event {} should be set finished.", event.getId());
                event.setEventStatus(ScheduledEventStatus.FINISHED);
            } else {
                createParam.setScheduledTime(ScheduleTimeHelper.convertCalendarToStr(nextScheduledTime));
                order = createNewOrder(user, uri(order.getTenant()), createParam);
                orderManager.processOrder(order);
                event.setLatestOrderId(order.getId());
                log.info("Scheduled an new order {} for event {} ...", order.getId(), event.getId());
            }
            client.save(event);
        }
    } catch (Exception e) {
        log.error("Failed to schedule next orders", e);
    } finally {
        try {
            lock.release();
        } catch (Exception e) {
            log.error("Error releasing order scheduler lock", e);
        }
    }
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ScheduledEvent(com.emc.storageos.db.client.model.uimodels.ScheduledEvent) ExecutionWindowHelper(com.emc.storageos.db.client.util.ExecutionWindowHelper) ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) Calendar(java.util.Calendar) OrderCreateParam(com.emc.vipr.model.catalog.OrderCreateParam) URI(java.net.URI) ScheduleInfo(com.emc.vipr.model.catalog.ScheduleInfo) TimeSeriesConstraint(com.emc.storageos.db.client.constraint.TimeSeriesConstraint) InvalidParameterException(java.security.InvalidParameterException) WebApplicationException(javax.ws.rs.WebApplicationException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 59 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class OrderService method getOrderExecutionTaskLogs.

/**
 * Gets the order execution logs
 *
 * @param orderId the URN of an order
 * @brief Get Order Execution Logs
 * @return order execution logs
 * @throws DatabaseException when a DB error occurs
 */
@GET
@Path("/{id}/execution/logs")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ExecutionLogList getOrderExecutionTaskLogs(@PathParam("id") String orderId) throws DatabaseException {
    Order order = queryResource(uri(orderId));
    StorageOSUser user = getUserFromContext();
    verifyAuthorizedInTenantOrg(uri(order.getTenant()), user);
    List<ExecutionTaskLog> executionTaskLogs = orderManager.getOrderExecutionTaskLogs(order);
    return toExecutionLogList(executionTaskLogs);
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) ExecutionTaskLog(com.emc.storageos.db.client.model.uimodels.ExecutionTaskLog) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 60 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class OrderService method getUserOrders.

/**
 * Gets the list of orders for current user
 *
 * @brief List Orders
 * @return a list of orders
 * @throws DatabaseException when a DB error occurs
 */
@GET
@Path("")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OrderList getUserOrders() throws DatabaseException {
    StorageOSUser user = getUserFromContext();
    List<Order> orders = orderManager.getUserOrders(user, 0, System.currentTimeMillis(), -1);
    return toOrderList(orders);
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)105 Produces (javax.ws.rs.Produces)59 Path (javax.ws.rs.Path)53 URI (java.net.URI)50 GET (javax.ws.rs.GET)36 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)31 Consumes (javax.ws.rs.Consumes)24 POST (javax.ws.rs.POST)15 ArrayList (java.util.ArrayList)13 Order (com.emc.storageos.db.client.model.uimodels.Order)12 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)12 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)11 NamedURI (com.emc.storageos.db.client.model.NamedURI)10 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)10 PUT (javax.ws.rs.PUT)10 Operation (com.emc.storageos.db.client.model.Operation)9 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)9 HashSet (java.util.HashSet)9 StringSet (com.emc.storageos.db.client.model.StringSet)8 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)8