Search in sources :

Example 26 with ProtectionSystem

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

the class ProtectionSystemService method queryResource.

/**
 * Gets the protection system with the passed id from the database.
 *
 * @param id the URN of a ViPR protection system
 *
 * @return A reference to the registered ProtectionSystem.
 *
 * @throws BadRequestException When the protection system is not
 *             registered.
 */
@Override
protected ProtectionSystem queryResource(URI id) {
    ArgValidator.checkUri(id);
    ProtectionSystem system = _dbClient.queryObject(ProtectionSystem.class, id);
    ArgValidator.checkEntityNotNull(system, id, isIdEmbeddedInURL(id));
    if (!RegistrationStatus.REGISTERED.toString().equalsIgnoreCase(system.getRegistrationStatus())) {
        throw APIException.badRequests.resourceAlreadyRegistered(ProtectionSystem.class.getSimpleName(), id);
    }
    return system;
}
Also used : MapProtectionSystem(com.emc.storageos.api.mapper.functions.MapProtectionSystem) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem)

Example 27 with ProtectionSystem

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

the class ProtectionSystemService method updateProtectionSystem.

/**
 * Allows the user to update credentials for a manually created protection systems.
 *
 * @param id the URN of a ViPR protection system
 * @param param The protection system details to update.
 *
 * @brief Update protection system credentials
 * @return A ProtectionSystemRestRep reference specifying the protection system
 *         data.
 *
 * @throws InternalException When an error occurs discovering the protection
 *             system.
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep updateProtectionSystem(@PathParam("id") URI id, ProtectionSystemUpdateRequestParam param) throws InternalException {
    ProtectionSystem system = _dbClient.queryObject(ProtectionSystem.class, id);
    ArgValidator.checkEntityNotNull(system, id, isIdEmbeddedInURL(id));
    // and Compatibility Status.
    if (!system.getIpAddress().equals(param.getIpAddress())) {
        system.setMajorVersion("");
        system.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.UNKNOWN.toString());
    }
    // Update the IP, port, username, and password with the new incoming values
    system.setIpAddress(param.getIpAddress());
    system.setPortNumber(param.getPortNumber());
    system.setUsername(param.getUserName());
    system.setPassword(param.getPassword());
    // Must force a discover during an update.
    system.setLastDiscoveryRunTime(new Long(0));
    // Make necessary changes to the protection system's cluster->varray assignments
    modifyClusterVarrayAssignments(system, param.getVarrayChanges());
    // Persist the object changes
    _dbClient.persistObject(system);
    auditOp(OperationTypeEnum.UPDATE_PROTECTION_SYSTEM, true, null, system.getId().toString(), param.getIpAddress(), param.getPortNumber(), param.getUserName());
    startProtectionSystem(system);
    // execute discovery
    ProtectionController controller = getController(RPController.class, system.getSystemType());
    ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
    String taskId = UUID.randomUUID().toString();
    tasks.add(new AsyncTask(ProtectionSystem.class, system.getId(), taskId));
    TaskList taskList = discoverProtectionSystems(tasks, controller);
    return taskList.getTaskList().iterator().next();
}
Also used : TaskList(com.emc.storageos.model.TaskList) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayList(java.util.ArrayList) MapProtectionSystem(com.emc.storageos.api.mapper.functions.MapProtectionSystem) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) ProtectionController(com.emc.storageos.protectioncontroller.ProtectionController) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 28 with ProtectionSystem

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

the class RPBlockServiceApiImpl method updateVolumesInVolumeGroup.

/**
 * {@inheritDoc}
 */
@Override
public void updateVolumesInVolumeGroup(VolumeGroupVolumeList addVolumes, List<Volume> removeVolumes, URI applicationId, String taskId) {
    VolumeGroup volumeGroup = _dbClient.queryObject(VolumeGroup.class, applicationId);
    ApplicationAddVolumeList addVolumeList = null;
    List<URI> removeVolumesURI = null;
    RPController controller = null;
    URI protSystemUri = null;
    Volume firstVolume = null;
    if (addVolumes != null && addVolumes.getVolumes() != null && !addVolumes.getVolumes().isEmpty()) {
        addVolumeList = addVolumesToApplication(addVolumes, volumeGroup);
        List<URI> vols = addVolumeList.getVolumes();
        if (vols != null && !vols.isEmpty()) {
            firstVolume = _dbClient.queryObject(Volume.class, vols.get(0));
        }
    }
    if (removeVolumes != null && !removeVolumes.isEmpty()) {
        removeVolumesURI = getValidVolumesToRemoveFromCG(removeVolumes);
        if (firstVolume == null) {
            firstVolume = removeVolumes.get(0);
        }
    }
    if ((addVolumeList != null && !addVolumeList.getVolumes().isEmpty()) || (removeVolumesURI != null && !removeVolumesURI.isEmpty())) {
        protSystemUri = firstVolume.getProtectionController();
        ProtectionSystem system = _dbClient.queryObject(ProtectionSystem.class, protSystemUri);
        controller = getController(RPController.class, system.getSystemType());
        controller.updateApplication(protSystemUri, addVolumeList, removeVolumesURI, volumeGroup.getId(), taskId);
    } else {
        // No need to call to controller. update the application task
        Operation op = volumeGroup.getOpStatus().get(taskId);
        op.ready();
        volumeGroup.getOpStatus().updateTaskStatus(taskId, op);
        _dbClient.updateObject(volumeGroup);
    }
}
Also used : ApplicationAddVolumeList(com.emc.storageos.volumecontroller.ApplicationAddVolumeList) RPController(com.emc.storageos.protectioncontroller.RPController) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem)

Example 29 with ProtectionSystem

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

the class RPBlockServiceApiImpl method getConnectedVarrays.

@Override
protected Set<URI> getConnectedVarrays(URI varrayUID) {
    Set<URI> varrays = new HashSet<URI>();
    List<ProtectionSystem> protectionSystems = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, ProtectionSystem.class, AlternateIdConstraint.Factory.getConstraint(ProtectionSystem.class, VIRTUAL_ARRAYS_CONSTRAINT, varrayUID.toString()));
    // Create and return the result.
    for (ProtectionSystem protectionSystem : protectionSystems) {
        if (protectionSystem.getVirtualArrays() != null) {
            for (String varrayURIStr : protectionSystem.getVirtualArrays()) {
                varrays.add(URI.create(varrayURIStr));
            }
        }
    }
    return varrays;
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) HashSet(java.util.HashSet)

Example 30 with ProtectionSystem

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

the class BlockConsistencyGroupService method performProtectionAction.

/**
 * Since all of the protection operations are very similar, this method does all of the work.
 * We keep the actual REST methods separate mostly for the purpose of documentation generators.
 *
 * @param consistencyGroupId the URI of the BlockConsistencyGroup to perform the protection action against.
 * @param targetVarrayId the target virtual array.
 * @param pointInTime any point in time, specified in UTC.
 *            Allowed values: "yyyy-MM-dd_HH:mm:ss" formatted date or datetime in milliseconds.
 * @param op operation to perform (pause, stop, failover, etc)
 * @return task resource rep
 * @throws InternalException
 */
private TaskResourceRep performProtectionAction(URI consistencyGroupId, Copy copy, String op) throws InternalException {
    ArgValidator.checkFieldUriType(consistencyGroupId, BlockConsistencyGroup.class, "id");
    ArgValidator.checkFieldUriType(copy.getCopyID(), VirtualArray.class, "copyId");
    // Get the BlockConsistencyGroup and target VirtualArray associated with the request.
    final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(consistencyGroupId);
    final VirtualArray targetVirtualArray = _permissionsHelper.getObjectById(copy.getCopyID(), VirtualArray.class);
    ArgValidator.checkEntity(consistencyGroup, consistencyGroupId, true);
    ArgValidator.checkEntity(targetVirtualArray, copy.getCopyID(), true);
    // The consistency group needs to be associated with RecoverPoint in order to perform the operation.
    if (!consistencyGroup.checkForType(Types.RP)) {
        // Attempt to do protection link management on unprotected CG
        throw APIException.badRequests.consistencyGroupMustBeRPProtected(consistencyGroupId);
    }
    if (op.equalsIgnoreCase(ProtectionOp.SWAP.getRestOp()) && !NullColumnValueGetter.isNullURI(consistencyGroupId)) {
        ExportUtils.validateConsistencyGroupBookmarksExported(_dbClient, consistencyGroupId);
    }
    // Catch any attempts to use an invalid access mode
    if (op.equalsIgnoreCase(ProtectionOp.CHANGE_ACCESS_MODE.getRestOp()) && !Copy.ImageAccessMode.DIRECT_ACCESS.name().equalsIgnoreCase(copy.getAccessMode())) {
        throw APIException.badRequests.unsupportedAccessMode(copy.getAccessMode());
    }
    // Verify that the supplied target Virtual Array is being referenced by at least one target volume in the CG.
    List<Volume> targetVolumes = getTargetVolumes(consistencyGroup, copy.getCopyID());
    if (targetVolumes == null || targetVolumes.isEmpty()) {
        // The supplied target varray is not referenced by any target volumes in the CG.
        throw APIException.badRequests.targetVirtualArrayDoesNotMatch(consistencyGroupId, copy.getCopyID());
    }
    // Get the first target volume
    Volume targetVolume = targetVolumes.get(0);
    String task = UUID.randomUUID().toString();
    Operation status = new Operation();
    status.setResourceType(ProtectionOp.getResourceOperationTypeEnum(op));
    _dbClient.createTaskOpStatus(BlockConsistencyGroup.class, consistencyGroupId, task, status);
    ProtectionSystem system = _dbClient.queryObject(ProtectionSystem.class, targetVolume.getProtectionController());
    String deviceType = system.getSystemType();
    if (!deviceType.equals(DiscoveredDataObject.Type.rp.name())) {
        throw APIException.badRequests.protectionForRpClusters();
    }
    RPController controller = getController(RPController.class, system.getSystemType());
    controller.performProtectionOperation(system.getId(), consistencyGroupId, targetVolume.getId(), copy.getPointInTime(), copy.getAccessMode(), op, task);
    /*
         * auditOp(OperationTypeEnum.PERFORM_PROTECTION_ACTION, true, AuditLogManager.AUDITOP_BEGIN,
         * op, copyID.toString(), id.toString(), system.getId().toString());
         */
    return toTask(consistencyGroup, task, status);
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) Volume(com.emc.storageos.db.client.model.Volume) RPController(com.emc.storageos.protectioncontroller.RPController) Operation(com.emc.storageos.db.client.model.Operation) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) MapBlockConsistencyGroup(com.emc.storageos.api.mapper.functions.MapBlockConsistencyGroup) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Aggregations

ProtectionSystem (com.emc.storageos.db.client.model.ProtectionSystem)120 URI (java.net.URI)57 ArrayList (java.util.ArrayList)52 NamedURI (com.emc.storageos.db.client.model.NamedURI)44 Volume (com.emc.storageos.db.client.model.Volume)44 HashMap (java.util.HashMap)32 StringSet (com.emc.storageos.db.client.model.StringSet)30 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)28 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)25 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)25 ControllerException (com.emc.storageos.volumecontroller.ControllerException)25 RPProtectionRecommendation (com.emc.storageos.volumecontroller.RPProtectionRecommendation)25 URISyntaxException (java.net.URISyntaxException)25 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)24 RecoverPointException (com.emc.storageos.recoverpoint.exceptions.RecoverPointException)24 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)24 WorkflowException (com.emc.storageos.workflow.WorkflowException)24 Test (org.junit.Test)24 FunctionalAPIActionFailedException_Exception (com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception)23 FunctionalAPIInternalError_Exception (com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception)23