Search in sources :

Example 26 with APIException

use of com.emc.storageos.svcs.errorhandling.resources.APIException in project coprhd-controller by CoprHD.

the class DiscoveredObjectTaskScheduler method scheduleAsyncTasks.

public TaskList scheduleAsyncTasks(List<AsyncTask> tasks) {
    TaskList list = new TaskList();
    for (AsyncTask task : tasks) {
        if (task instanceof ArrayAffinityAsyncTask) {
            List<URI> systemIds = ((ArrayAffinityAsyncTask) task).getSystemIds();
            for (URI uri : systemIds) {
                DataObject discoveredObject = (DataObject) _dbClient.queryObject(task._clazz, uri);
                Operation op = new Operation();
                op.setResourceType(_taskExecutor.getOperation());
                _dbClient.createTaskOpStatus(task._clazz, uri, task._opId, op);
                list.getTaskList().add(toTask(discoveredObject, task._opId, op));
            }
        } else {
            DataObject discoveredObject = (DataObject) _dbClient.queryObject(task._clazz, task._id);
            Operation op = new Operation();
            op.setResourceType(_taskExecutor.getOperation());
            _dbClient.createTaskOpStatus(task._clazz, task._id, task._opId, op);
            list.getTaskList().add(toTask(discoveredObject, task._opId, op));
        }
    }
    try {
        _taskExecutor.executeTasks(tasks.toArray(new AsyncTask[tasks.size()]));
    } catch (ControllerException | APIException ex) {
        for (AsyncTask task : tasks) {
            DataObject discoveredObject = (DataObject) _dbClient.queryObject(task._clazz, task._id);
            Operation op = _dbClient.error(task._clazz, task._id, task._opId, ex);
            list.getTaskList().add(toTask(discoveredObject, task._opId, op));
        }
    }
    return list;
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) ControllerException(com.emc.storageos.volumecontroller.ControllerException) TaskList(com.emc.storageos.model.TaskList) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI)

Example 27 with APIException

use of com.emc.storageos.svcs.errorhandling.resources.APIException in project coprhd-controller by CoprHD.

the class VolumeGroupService method detachVolumeGroupFullCopy.

/**
 * Detach the specified Volume group full copy.
 * - Detaches full copy for all the array replication groups within this Application.
 * - If partial flag is specified, it detaches full copy only for set of array replication groups.
 * A Full Copy from each array replication group can be provided to indicate which array replication
 * groups's full copies needs to be detached.
 *
 * @prereq Create Volume group full copy as active.
 *
 * @param volumeGroupId The URI of the Volume group.
 * @param fullCopyURI The URI of the full copy.
 *
 * @brief Detach Volume group full copy.
 *
 * @return TaskList
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/full-copies/detach")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskList detachVolumeGroupFullCopy(@PathParam("id") final URI volumeGroupId, final VolumeGroupFullCopyDetachParam param) {
    ArgValidator.checkFieldUriType(volumeGroupId, VolumeGroup.class, "id");
    // Query Volume Group
    final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
    TaskList taskList = new TaskList();
    // validate replica operation for volume group
    validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.FULL_COPY);
    // validate the requested full copies
    List<Volume> fullCopyVolumesInRequest = new ArrayList<Volume>();
    boolean partial = validateFullCopiesInRequest(fullCopyVolumesInRequest, param.getFullCopies(), param.getCopySetName(), param.getSubGroups(), volumeGroupId);
    /**
     * 1. VolumeGroupService Clone API accepts a Clone URI (to identify clone set and RG)
     * - then get All full copies belonging to same full copy set
     * - get full copy set name from the requested full copy
     * 2. If partial, there will be a List of Clone URIs (one from each RG)
     * 3. Group the full copies by Replication Group(RG)
     * 4. For each RG, invoke the ConsistencyGroup full copy API (CG uri, clone uri)
     * - a. Skip the CG/RG calls when thrown error and continue with other entries; create 'ERROR' Task for this call
     * - b. Finally return the Task List (RG tasks may finish at different times as they are different calls)
     */
    if (!partial) {
        Volume fullCopy = fullCopyVolumesInRequest.get(0);
        log.info("Full Copy operation requested for entire Application, Considering full copy {} in request.", fullCopy.getLabel());
        fullCopyVolumesInRequest.clear();
        fullCopyVolumesInRequest.addAll(getClonesBySetName(fullCopy.getFullCopySetName(), volumeGroup.getId()));
    } else {
        log.info("Full Copy operation requested for subset of array replication groups in Application.");
    }
    checkForApplicationPendingTasks(volumeGroup, _dbClient, true);
    Map<String, Volume> repGroupToFullCopyMap = groupVolumesByReplicationGroup(fullCopyVolumesInRequest);
    for (Map.Entry<String, Volume> entry : repGroupToFullCopyMap.entrySet()) {
        String replicationGroup = entry.getKey();
        Volume fullCopy = entry.getValue();
        log.info("Processing Array Replication Group {}, Full Copy {}", replicationGroup, fullCopy.getLabel());
        try {
            // get CG URI
            URI cgURI = getConsistencyGroupForFullCopy(fullCopy);
            // Detach the full copy. Note that it will take into account the
            // fact that the volume is in a ReplicationGroup
            // and all volumes in that ReplicationGroup will be detached.
            taskList.getTaskList().addAll(_blockConsistencyGroupService.detachConsistencyGroupFullCopy(cgURI, fullCopy.getId()).getTaskList());
        } catch (InternalException | APIException e) {
            String errMsg = String.format("Error detaching Array Replication Group %s, Full Copy %s", replicationGroup, fullCopy.getLabel());
            log.error(errMsg, e);
            TaskResourceRep task = BlockServiceUtils.createFailedTaskOnVolume(_dbClient, fullCopy, ResourceOperationTypeEnum.DETACH_VOLUME_FULL_COPY, e);
            taskList.addTask(task);
        }
    }
    if (!partial) {
        auditOp(OperationTypeEnum.DETACH_VOLUME_GROUP_FULL_COPY, true, AuditLogManager.AUDITOP_BEGIN, volumeGroup.getId().toString(), fullCopyVolumesInRequest.get(0).getLabel());
    }
    return taskList;
}
Also used : TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) Map(java.util.Map) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 28 with APIException

use of com.emc.storageos.svcs.errorhandling.resources.APIException in project coprhd-controller by CoprHD.

the class ScheduledEventService method createEvent.

/**
 * Create a scheduled event for one or a series of future orders.
 * Also a latest order is created and set to APPROVAL or SCHEDULED status
 * @param createParam   including schedule time info and order parameters
 * @return                ScheduledEventRestRep
 */
@POST
@Path("")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ScheduledEventRestRep createEvent(ScheduledEventCreateParam createParam) {
    StorageOSUser user = getUserFromContext();
    URI tenantId = createParam.getOrderCreateParam().getTenantId();
    if (tenantId != null) {
        verifyAuthorizedInTenantOrg(tenantId, user);
    } else {
        tenantId = uri(user.getTenantId());
    }
    ArgValidator.checkFieldNotNull(createParam.getOrderCreateParam().getCatalogService(), "catalogService");
    CatalogService catalogService = catalogServiceManager.getCatalogServiceById(createParam.getOrderCreateParam().getCatalogService());
    if (catalogService == null) {
        throw APIException.badRequests.orderServiceNotFound(asString(createParam.getOrderCreateParam().getCatalogService()));
    }
    validateParam(createParam.getScheduleInfo());
    validOrderParam(createParam.getScheduleInfo(), createParam.getOrderCreateParam().getParameters());
    validateAutomaticExpirationNumber(createParam.getOrderCreateParam().getAdditionalScheduleInfo());
    ScheduledEvent newObject = null;
    try {
        newObject = createScheduledEvent(user, tenantId, createParam, catalogService);
    } catch (APIException ex) {
        log.error(ex.getMessage(), ex);
        throw ex;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return map(newObject);
}
Also used : APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ParseException(java.text.ParseException)

Example 29 with APIException

use of com.emc.storageos.svcs.errorhandling.resources.APIException in project coprhd-controller by CoprHD.

the class DrDbHealthMonitor method checkAndRejoinSite.

private void checkAndRejoinSite(Site standbySite) {
    String siteId = standbySite.getUuid();
    int nodeCount = standbySite.getNodeCount();
    // or the data sync will fail anyways
    if (drUtil.getNumberOfLiveServices(siteId, Constants.DBSVC_NAME) == nodeCount || drUtil.getNumberOfLiveServices(siteId, Constants.GEODBSVC_NAME) == nodeCount) {
        log.info("All the dbsvc/geodbsvc instances are back. Rejoining site {}", standbySite.getUuid());
        InterProcessLock lock;
        try {
            lock = drUtil.getDROperationLock();
        } catch (APIException e) {
            log.warn("There are ongoing dr operations. Try again later.");
            return;
        }
        try {
            long vdcVersion = DrUtil.newVdcConfigVersion();
            standbySite.setState(SiteState.STANDBY_RESUMING);
            coordinatorClient.persistServiceConfiguration(standbySite.toConfiguration());
            long dataRevision = vdcVersion;
            drUtil.updateVdcTargetVersion(standbySite.getUuid(), SiteInfo.DR_OP_CHANGE_DATA_REVISION, vdcVersion, dataRevision);
            // Update version on other connected standby sites if any
            for (Site site : drUtil.listSites()) {
                if (site.equals(standbySite) || site.getUuid().equals(coordinatorClient.getSiteId())) {
                    // target site or local site
                    continue;
                }
                drUtil.updateVdcTargetVersion(site.getUuid(), SiteInfo.NONE, vdcVersion);
            }
            // Update version on active site but do nothing
            drUtil.updateVdcTargetVersion(coordinatorClient.getSiteId(), SiteInfo.NONE, vdcVersion);
        } catch (Exception e) {
            log.error("Failed to initiate rejoin standby operation. Try again later", e);
        } finally {
            try {
                lock.release();
            } catch (Exception e) {
                log.error("Failed to release the dr operation lock", e);
            }
        }
    }
}
Also used : APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) IOException(java.io.IOException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 30 with APIException

use of com.emc.storageos.svcs.errorhandling.resources.APIException in project coprhd-controller by CoprHD.

the class DrDbHealthMonitor method degradeSites.

private void degradeSites(List<Site> sitesToDegrade) {
    InterProcessLock lock;
    try {
        lock = drUtil.getDROperationLock();
    } catch (APIException e) {
        log.warn("There are ongoing dr operations. Try again later.");
        return;
    }
    try {
        long vdcVersion = DrUtil.newVdcConfigVersion();
        // Update degraded sites
        for (Site standbySite : sitesToDegrade) {
            standbySite.setState(SiteState.STANDBY_DEGRADING);
            coordinatorClient.persistServiceConfiguration(standbySite.toConfiguration());
            drUtil.updateVdcTargetVersion(standbySite.getUuid(), SiteInfo.DR_OP_DEGRADE_STANDBY, vdcVersion);
            drUtil.recordDrOperationStatus(standbySite.getUuid(), InterState.DEGRADING_STANDBY);
        }
        // Update all other connected sites
        List<Site> connectedSites = getOtherConnectedSites(sitesToDegrade);
        for (Site site : connectedSites) {
            drUtil.updateVdcTargetVersion(site.getUuid(), SiteInfo.NONE, vdcVersion);
        }
        // Update local site
        drUtil.updateVdcTargetVersion(coordinatorClient.getSiteId(), SiteInfo.DR_OP_DEGRADE_STANDBY, vdcVersion);
    } catch (Exception e) {
        log.error("Failed to initiate degrade standby operation. Try again later", e);
    } finally {
        try {
            lock.release();
        } catch (Exception e) {
            log.error("Failed to release the dr operation lock", e);
        }
    }
}
Also used : APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) IOException(java.io.IOException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Aggregations

APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)55 URI (java.net.URI)28 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)25 Produces (javax.ws.rs.Produces)22 Path (javax.ws.rs.Path)21 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)20 ArrayList (java.util.ArrayList)19 POST (javax.ws.rs.POST)19 Volume (com.emc.storageos.db.client.model.Volume)18 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)18 TaskList (com.emc.storageos.model.TaskList)17 Consumes (javax.ws.rs.Consumes)16 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)13 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)12 Operation (com.emc.storageos.db.client.model.Operation)10 DataObject (com.emc.storageos.db.client.model.DataObject)9 NamedURI (com.emc.storageos.db.client.model.NamedURI)9 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)9 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)8 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)7