Search in sources :

Example 11 with StringMap

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

the class ConsistencyGroupSnapshotService method createConsistencyGroupSnapshot.

/**
 * Create consistency group snapshot
 *
 * @param openstackTenantId
 *            openstack tenant Id
 * @param param
 *            Pojo class to bind request
 * @param isV1Call
 *            cinder V1 api
 * @param header
 *            HTTP header
 * @brief Create Consistency Group Snapshot
 * @return Response
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createConsistencyGroupSnapshot(@PathParam("tenant_id") String openstackTenantId, final ConsistencyGroupSnapshotCreateRequest param, @HeaderParam("X-Cinder-V1-Call") String isV1Call, @Context HttpHeaders header) {
    // Query Consistency Group
    final String consistencyGroupId = param.cgsnapshot.consistencygroup_id;
    final BlockConsistencyGroup consistencyGroup = findConsistencyGroup(consistencyGroupId, openstackTenantId);
    if (consistencyGroup == null) {
        _log.error("Not Found : No Such Consistency Group Found {}", consistencyGroupId);
        return CinderApiUtils.createErrorResponse(404, "Not Found : No Such Consistency Group Found");
    } else if (!consistencyGroupId.equals(CinderApiUtils.splitString(consistencyGroup.getId().toString(), ":", 3))) {
        _log.error("Bad Request : Invalid Snapshot Id {} : Please enter valid or full Id", consistencyGroupId);
        return CinderApiUtils.createErrorResponse(400, "Bad Request : No such consistency id exist, Please enter valid or full Id");
    }
    if (!isSnapshotCreationpermissible(consistencyGroup)) {
        _log.error("Bad Request : vpool not being configured for the snapshots creation");
        return CinderApiUtils.createErrorResponse(400, "Bad Request : vpool not being configured for the snapshots creation");
    }
    // system types.
    if (!consistencyGroup.created()) {
        CinderApiUtils.createErrorResponse(400, "No such consistency group created");
    }
    Project project = getCinderHelper().getProject(openstackTenantId, getUserFromContext());
    URI cgStorageControllerURI = consistencyGroup.getStorageController();
    if (!NullColumnValueGetter.isNullURI(cgStorageControllerURI)) {
        // No snapshots for VPLEX consistency groups.
        StorageSystem cgStorageController = _dbClient.queryObject(StorageSystem.class, cgStorageControllerURI);
        if ((DiscoveredDataObject.Type.vplex.name().equals(cgStorageController.getSystemType())) && (!consistencyGroup.checkForType(Types.LOCAL))) {
            CinderApiUtils.createErrorResponse(400, "can't create snapshot for VPLEX");
        }
    }
    // Get the block service implementation
    BlockServiceApi blockServiceApiImpl = getBlockServiceImpl(consistencyGroup);
    // Get the volumes in the consistency group.
    List<Volume> volumeList = blockServiceApiImpl.getActiveCGVolumes(consistencyGroup);
    _log.info("Active CG volume list : " + volumeList);
    // Generate task id
    String taskId = UUID.randomUUID().toString();
    // Set snapshot type.
    String snapshotType = BlockSnapshot.TechnologyType.NATIVE.toString();
    if (consistencyGroup.checkForType(BlockConsistencyGroup.Types.RP)) {
        snapshotType = BlockSnapshot.TechnologyType.RP.toString();
    } else if ((!volumeList.isEmpty()) && (volumeList.get(0).checkForSRDF())) {
        snapshotType = BlockSnapshot.TechnologyType.SRDF.toString();
    }
    // Determine the snapshot volume for RP.
    Volume snapVolume = null;
    if (consistencyGroup.checkForType(BlockConsistencyGroup.Types.RP)) {
        for (Volume volumeToSnap : volumeList) {
            // Get the RP source volume.
            if (volumeToSnap.getPersonality() != null && volumeToSnap.getPersonality().equals(Volume.PersonalityTypes.SOURCE.toString())) {
                snapVolume = volumeToSnap;
                break;
            }
        }
    } else if (!volumeList.isEmpty()) {
        // Any volume.
        snapVolume = volumeList.get(0);
    }
    // Set the create inactive flag.
    Boolean createInactive = Boolean.FALSE;
    Boolean readOnly = Boolean.FALSE;
    // Validate the snapshot request.
    String snapshotName = param.cgsnapshot.name;
    blockServiceApiImpl.validateCreateSnapshot(snapVolume, volumeList, snapshotType, snapshotName, readOnly, getFullCopyManager());
    // Prepare and create the snapshots for the group.
    List<URI> snapIdList = new ArrayList<URI>();
    List<BlockSnapshot> snapshotList = new ArrayList<BlockSnapshot>();
    TaskList response = new TaskList();
    snapshotList.addAll(blockServiceApiImpl.prepareSnapshots(volumeList, snapshotType, snapshotName, snapIdList, taskId));
    for (BlockSnapshot snapshot : snapshotList) {
        response.getTaskList().add(toTask(snapshot, taskId));
    }
    blockServiceApiImpl.createSnapshot(snapVolume, snapIdList, snapshotType, createInactive, readOnly, taskId);
    auditBlockConsistencyGroup(OperationTypeEnum.CREATE_CONSISTENCY_GROUP_SNAPSHOT, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, param.cgsnapshot.name, consistencyGroup.getId().toString());
    ConsistencyGroupSnapshotCreateResponse cgSnapshotCreateRes = new ConsistencyGroupSnapshotCreateResponse();
    for (TaskResourceRep rep : response.getTaskList()) {
        URI snapshotUri = rep.getResource().getId();
        BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapshotUri);
        snap.setId(snapshotUri);
        snap.setConsistencyGroup(consistencyGroup.getId());
        snap.setLabel(snapshotName);
        if (snap != null) {
            StringMap extensions = snap.getExtensions();
            if (extensions == null) {
                extensions = new StringMap();
            }
            extensions.put("status", CinderConstants.ComponentStatus.CREATING.getStatus().toLowerCase());
            extensions.put("taskid", rep.getId().toString());
            snap.setExtensions(extensions);
            ScopedLabelSet tagSet = new ScopedLabelSet();
            snap.setTag(tagSet);
            tagSet.add(new ScopedLabel(project.getTenantOrg().getURI().toString(), CinderApiUtils.splitString(snapshotUri.toString(), ":", 3)));
        }
        _dbClient.updateObject(snap);
        cgSnapshotCreateRes.id = CinderApiUtils.splitString(snapshotUri.toString(), ":", 3);
        cgSnapshotCreateRes.name = param.cgsnapshot.name;
    }
    return CinderApiUtils.getCinderResponse(cgSnapshotCreateRes, header, true, CinderConstants.STATUS_OK);
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) URI(java.net.URI) BlockServiceApi(com.emc.storageos.api.service.impl.resource.BlockServiceApi) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) Project(com.emc.storageos.db.client.model.Project) Volume(com.emc.storageos.db.client.model.Volume) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) ConsistencyGroupSnapshotCreateResponse(com.emc.storageos.cinder.model.ConsistencyGroupSnapshotCreateResponse) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 12 with StringMap

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

the class DataObjectChangeAnalyzer method lookForChanges.

/**
 * Scans the methods looking for ones annotated with the Name annotation.
 * When found (if not excluded), invokes the method on each of the DataObjects
 * and then compares the results.
 *
 * @param left
 * @param right
 * @param changes
 * @param included -- If not null, only fields in included are checked.
 * @param excluded -- Fields that are excluded are not checked. Must not be null.
 * @param contained -- If not null, values for fields in contained are checked.
 */
private static void lookForChanges(DataObject left, DataObject right, HashMap<String, Change> changes, Set<String> included, Set<String> excluded, Set<String> contained) {
    Class refClass = left.getClass();
    Method[] methods = refClass.getMethods();
    for (Method method : methods) {
        boolean contain = false;
        // We only analyze methods that have the "Name" annotation
        Name nameAnn = method.getAnnotation(Name.class);
        if (nameAnn == null) {
            continue;
        }
        String key = nameAnn.value();
        // If contained is not null and it contains the key set contain flag to true
        if (contained != null && contained.contains(key)) {
            contain = true;
        } else // If included is not null, and does not contain the name, exclude it.
        if (included != null && !included.contains(key)) {
            continue;
        }
        // Skip any excluded annotation names
        if (excluded.contains(key)) {
            continue;
        }
        Class type = method.getReturnType();
        try {
            Object obja = method.invoke(left);
            Object objb = method.invoke(right);
            if (type == StringSet.class) {
                if (contain) {
                    analyzeNewStringSetContainsOldStringSetValues((StringSet) obja, (StringSet) objb, key, changes);
                } else {
                    analyzeStringSets((StringSet) obja, (StringSet) objb, key, changes);
                }
            } else if (type == StringMap.class) {
                analyzeStringMaps((StringMap) obja, (StringMap) objb, key, changes);
            } else if (type == StringSetMap.class) {
                analyzeStringSetMaps((StringSetMap) obja, (StringSetMap) objb, key, changes);
            } else {
                if (!isEqual(obja, objb)) {
                    Change change = new Change(key, obja, objb, nameAnn.value());
                    changes.put(key, change);
                }
            }
        } catch (IllegalAccessException ex) {
            throw new ServiceCodeException(ServiceCode.UNFORSEEN_ERROR, ex, ex.getMessage(), new String[] {});
        } catch (InvocationTargetException ex) {
            throw new ServiceCodeException(ServiceCode.UNFORSEEN_ERROR, ex, ex.getMessage(), new String[] {});
        }
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) DataObject(com.emc.storageos.db.client.model.DataObject) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Name(com.emc.storageos.db.client.model.Name)

Example 13 with StringMap

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

the class RecoverPointSchedulerTest method buildProtectionSystemNoCGAvailability.

private ProtectionSystem buildProtectionSystemNoCGAvailability() {
    ProtectionSystem ps = new ProtectionSystem();
    ps.setId(URI.create("PSURI_NOCG"));
    // set the stats
    ps.setCgCapacity(312L);
    ps.setCgCount(312L);
    ps.setLabel("rp_protection_system_no_cg_capacity");
    Map<String, String> siteVolCapacity = new HashMap<String, String>();
    siteVolCapacity.put("1", "512");
    siteVolCapacity.put("2", "512");
    Map<String, String> siteVolCount = new HashMap<String, String>();
    siteVolCount.put("1", "512");
    siteVolCount.put("2", "512");
    ps.setSiteVolumeCapacity(new StringMap(siteVolCapacity));
    ps.setSiteVolumeCount(new StringMap(siteVolCount));
    return ps;
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) HashMap(java.util.HashMap) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem)

Example 14 with StringMap

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

the class RecoverPointSchedulerTest method buildProtectionSystemWithNoCapacitySite1.

private ProtectionSystem buildProtectionSystemWithNoCapacitySite1() {
    ProtectionSystem ps = new ProtectionSystem();
    ps.setId(URI.create("PSURI_NOCAPACITYSITE1"));
    // set the stats
    ps.setCgCapacity(312L);
    ps.setCgCount(12L);
    ps.setLabel("rp_protection_system_no_capacity_site1");
    Map<String, String> siteVolCapacity = new HashMap<String, String>();
    siteVolCapacity.put("1", "512");
    siteVolCapacity.put("2", "512");
    Map<String, String> siteVolCount = new HashMap<String, String>();
    siteVolCount.put("1", "512");
    siteVolCount.put("2", "100");
    ps.setSiteVolumeCapacity(new StringMap(siteVolCapacity));
    ps.setSiteVolumeCount(new StringMap(siteVolCount));
    return ps;
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) HashMap(java.util.HashMap) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem)

Example 15 with StringMap

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

the class RecoverPointSchedulerTest method buildProtectionSystemWithNoCapacity.

private ProtectionSystem buildProtectionSystemWithNoCapacity() {
    ProtectionSystem ps = new ProtectionSystem();
    ps.setId(URI.create("PSURI_NOCAPACITY"));
    // set the stats
    ps.setCgCapacity(312L);
    ps.setCgCount(12L);
    ps.setLabel("rp_protection_system_no_capacity");
    Map<String, String> siteVolCapacity = new HashMap<String, String>();
    siteVolCapacity.put("1", "512");
    siteVolCapacity.put("2", "512");
    Map<String, String> siteVolCount = new HashMap<String, String>();
    siteVolCount.put("1", "512");
    siteVolCount.put("2", "512");
    ps.setSiteVolumeCapacity(new StringMap(siteVolCapacity));
    ps.setSiteVolumeCount(new StringMap(siteVolCount));
    return ps;
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) HashMap(java.util.HashMap) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem)

Aggregations

StringMap (com.emc.storageos.db.client.model.StringMap)257 URI (java.net.URI)108 ArrayList (java.util.ArrayList)90 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)59 StringSet (com.emc.storageos.db.client.model.StringSet)57 HashMap (java.util.HashMap)57 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)48 ExportMask (com.emc.storageos.db.client.model.ExportMask)43 Volume (com.emc.storageos.db.client.model.Volume)42 NamedURI (com.emc.storageos.db.client.model.NamedURI)41 StoragePool (com.emc.storageos.db.client.model.StoragePool)39 Initiator (com.emc.storageos.db.client.model.Initiator)38 List (java.util.List)34 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)33 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)31 HashSet (java.util.HashSet)30 Project (com.emc.storageos.db.client.model.Project)24 StoragePort (com.emc.storageos.db.client.model.StoragePort)23 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)22 Network (com.emc.storageos.db.client.model.Network)21