Search in sources :

Example 51 with DbClient

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

the class BlockObjectNormalizeWwnMigration method processType.

private <T extends BlockObject> void processType(Class<T> clazz) {
    DbClient dbClient = getDbClient();
    List<URI> blockObjectKeys = dbClient.queryByType(clazz, true);
    for (URI blockObjectKey : blockObjectKeys) {
        List<T> blockObjects = dbClient.queryObjectField(clazz, "wwn", Arrays.asList(blockObjectKey));
        for (BlockObject blockObject : blockObjects) {
            String currentWwn = blockObject.getWWN();
            if (currentWwn != null && !NumberUtils.isDigits(currentWwn)) {
                // BlockObject#setWWN has been updated to upper case the WWN
                blockObject.setWWN(currentWwn);
                log.info("Normalizing WWN of " + blockObject.getId() + " from " + currentWwn + " to " + blockObject.getWWN());
                dbClient.persistObject(blockObject);
            }
        }
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 52 with DbClient

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

the class BlockObjectSystemTypeMigration method process.

@Override
public void process() throws MigrationCallbackException {
    DbClient dbClient = getDbClient();
    Map<URI, String> storageSystemTypeMap = new HashMap<URI, String>();
    int pageSize = 100;
    int totalBlockObjectCount = 0;
    int blockObjectUpdatedCount = 0;
    List<Class<? extends BlockObject>> classesToProcess = new ArrayList<Class<? extends BlockObject>>();
    classesToProcess.add(Volume.class);
    classesToProcess.add(BlockSnapshot.class);
    classesToProcess.add(BlockMirror.class);
    for (Class<? extends BlockObject> clazz : classesToProcess) {
        URI nextId = null;
        while (true) {
            List<URI> blockObjectUris = dbClient.queryByType(clazz, true, nextId, pageSize);
            if (blockObjectUris == null || blockObjectUris.isEmpty()) {
                break;
            }
            logger.info("processing page of {} {} BlockObjects", blockObjectUris.size(), clazz.getSimpleName());
            Iterator<? extends BlockObject> pageIterator = dbClient.queryIterativeObjects(clazz, blockObjectUris, true);
            while (pageIterator.hasNext()) {
                BlockObject blockObject = pageIterator.next();
                if (blockObject != null && NullColumnValueGetter.isNullValue(blockObject.getSystemType())) {
                    logger.info("starting migration of BlockObject " + blockObject.forDisplay());
                    String deviceSystemType = getDeviceSystemType(dbClient, storageSystemTypeMap, blockObject);
                    if (deviceSystemType != null) {
                        blockObject.setSystemType(deviceSystemType);
                        dbClient.updateObject(blockObject);
                        blockObjectUpdatedCount++;
                        logger.info("set storage system type to {} for BlockObject {}", deviceSystemType, blockObject.forDisplay());
                    } else {
                        logger.warn("could not determine storage system type for BlockObject {}", blockObject.forDisplay());
                    }
                }
            }
            nextId = blockObjectUris.get(blockObjectUris.size() - 1);
            totalBlockObjectCount += blockObjectUris.size();
        }
    }
    logger.info("Updated storage system type on {} of {} BlockObjects in the system", blockObjectUpdatedCount, totalBlockObjectCount);
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 53 with DbClient

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

the class BlockSnapshotReplicationGroupInstanceMigration method initializeField.

/**
 * For all full copy volume, set replicaState as DETACHED
 */
private void initializeField() {
    log.info("Updating block snapshot replication group instance.");
    DbClient dbClient = this.getDbClient();
    List<URI> snapURIs = dbClient.queryByType(BlockSnapshot.class, false);
    Iterator<BlockSnapshot> snaps = dbClient.queryIterativeObjects(BlockSnapshot.class, snapURIs);
    while (snaps.hasNext()) {
        BlockSnapshot snapshot = snaps.next();
        log.info("Examining block snapshot (id={}) for upgrade", snapshot.getId().toString());
        String groupInstance = snapshot.getSnapshotGroupInstance();
        if (NullColumnValueGetter.isNotNullValue(groupInstance)) {
            log.info("Setting replicationGroupInstance", groupInstance);
            snapshot.setReplicationGroupInstance(groupInstance);
            dbClient.persistObject(snapshot);
        }
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI)

Example 54 with DbClient

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

the class BlockSnapshotSessionMigration method process.

/**
 * {@inheritDoc}
 */
@Override
public void process() throws MigrationCallbackException {
    s_logger.info("Executing BlockSnapshotSession migration callback.");
    try {
        DbClient dbClient = getDbClient();
        List<BlockSnapshotSession> snapshotSessions = new ArrayList<BlockSnapshotSession>();
        Map<URI, Map<String, BlockSnapshotSession>> groupSessionMap = new HashMap<>();
        List<URI> snapshotURIs = dbClient.queryByType(BlockSnapshot.class, true);
        Iterator<BlockSnapshot> snapshotsIter = dbClient.queryIterativeObjects(BlockSnapshot.class, snapshotURIs, true);
        while (snapshotsIter.hasNext()) {
            BlockSnapshot snapshot = snapshotsIter.next();
            if (isSnapshotSessionSupported(snapshot)) {
                // Check if this is a group snapshot.
                URI cgURI = snapshot.getConsistencyGroup();
                if (NullColumnValueGetter.isNullURI(cgURI)) {
                    // The storage system for the single volume snapshot supports
                    // snapshot sessions, then we need to prepare and create a
                    // snapshot session for that snapshot and add the snapshot as
                    // a linked target for the session.
                    BlockSnapshotSession snapshotSession = prepareSnapshotSession(snapshot);
                    snapshotSessions.add(snapshotSession);
                } else {
                    // Create the group session if necessary and add the snapshot as a
                    // linked target for that group session.
                    String settingsInstance = snapshot.getSettingsInstance();
                    Map<String, BlockSnapshotSession> grpSnapshotSessions = groupSessionMap.get(cgURI);
                    if (grpSnapshotSessions != null) {
                        BlockSnapshotSession snapshotSession = grpSnapshotSessions.get(settingsInstance);
                        if (snapshotSession == null) {
                            snapshotSession = prepareSnapshotSession(snapshot);
                            grpSnapshotSessions.put(settingsInstance, snapshotSession);
                            snapshotSessions.add(snapshotSession);
                        } else {
                            StringSet linkedTargets = snapshotSession.getLinkedTargets();
                            linkedTargets.add(snapshot.getId().toString());
                        }
                    } else {
                        grpSnapshotSessions = new HashMap<String, BlockSnapshotSession>();
                        groupSessionMap.put(cgURI, grpSnapshotSessions);
                        BlockSnapshotSession snapshotSession = prepareSnapshotSession(snapshot);
                        grpSnapshotSessions.put(settingsInstance, snapshotSession);
                        snapshotSessions.add(snapshotSession);
                    }
                }
            }
        }
        if (!snapshotSessions.isEmpty()) {
            dbClient.createObject(snapshotSessions);
        }
    } catch (Exception e) {
        s_logger.error("Caught exception during BlockSnapshotSession migration", e);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) Map(java.util.Map)

Example 55 with DbClient

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

the class CifsShareACLMigration method process.

@Override
public void process() throws MigrationCallbackException {
    logger.info("Migration started");
    DbClient dbClient = getDbClient();
    try {
        List<URI> fileSystemURIList = dbClient.queryByType(FileShare.class, true);
        Iterator<FileShare> fileSystemList = dbClient.queryIterativeObjects(FileShare.class, fileSystemURIList, true);
        while (fileSystemList.hasNext()) {
            FileShare fs = fileSystemList.next();
            SMBShareMap smbShareMap = fs.getSMBFileShares();
            Collection<SMBFileShare> smbShares = new ArrayList<SMBFileShare>();
            if (smbShareMap != null) {
                smbShares = smbShareMap.values();
                for (SMBFileShare smbShare : smbShares) {
                    if (smbShare.getPermissionType().equalsIgnoreCase(PERMISSION_TYPE_ALLOW)) {
                        CifsShareACL acl = new CifsShareACL();
                        acl.setId(URIUtil.createId(CifsShareACL.class));
                        acl.setShareName(smbShare.getName());
                        acl.setPermission(smbShare.getPermission());
                        acl.setUser(USER_EVERYONE);
                        acl.setFileSystemId(fs.getId());
                        logger.debug("Persisting new ACE into DB: {}", acl);
                        dbClient.createObject(acl);
                    }
                }
            }
        }
        // File snapshots
        List<URI> fileSnapshotURIList = dbClient.queryByType(Snapshot.class, true);
        Iterator<Snapshot> fileSnapshotList = dbClient.queryIterativeObjects(Snapshot.class, fileSnapshotURIList, true);
        while (fileSnapshotList.hasNext()) {
            Snapshot snapshot = fileSnapshotList.next();
            SMBShareMap smbShareMap = snapshot.getSMBFileShares();
            Collection<SMBFileShare> smbShares = new ArrayList<SMBFileShare>();
            if (smbShareMap != null) {
                smbShares = smbShareMap.values();
                for (SMBFileShare smbShare : smbShares) {
                    if (smbShare.getPermissionType().equalsIgnoreCase(PERMISSION_TYPE_ALLOW)) {
                        CifsShareACL acl = new CifsShareACL();
                        acl.setId(URIUtil.createId(CifsShareACL.class));
                        acl.setShareName(smbShare.getName());
                        acl.setPermission(getFormattedPermissionText(smbShare.getPermission()));
                        acl.setUser(USER_EVERYONE);
                        acl.setSnapshotId(snapshot.getId());
                        logger.debug("Persisting new ACE into DB: {}", acl);
                        dbClient.createObject(acl);
                    }
                }
            }
        }
        logger.info("Migration completed successfully");
    } catch (Exception e) {
        logger.error("Exception occured while migrating cifs share access control settings");
        logger.error(e.getMessage(), e);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) ArrayList(java.util.ArrayList) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) CifsShareACL(com.emc.storageos.db.client.model.CifsShareACL) Snapshot(com.emc.storageos.db.client.model.Snapshot) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare)

Aggregations

DbClient (com.emc.storageos.db.client.DbClient)253 URI (java.net.URI)155 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)73 Volume (com.emc.storageos.db.client.model.Volume)67 ArrayList (java.util.ArrayList)58 Test (org.junit.Test)42 FileShare (com.emc.storageos.db.client.model.FileShare)34 NamedURI (com.emc.storageos.db.client.model.NamedURI)31 CIMObjectPath (javax.cim.CIMObjectPath)31 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)29 WBEMClient (javax.wbem.client.WBEMClient)29 StringSet (com.emc.storageos.db.client.model.StringSet)28 CIMConnectionFactory (com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory)28 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)26 MigrationCallbackException (com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)25 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)22 InternalDbClient (com.emc.storageos.db.client.upgrade.InternalDbClient)22 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)21 CIMInstance (javax.cim.CIMInstance)21 BlockObject (com.emc.storageos.db.client.model.BlockObject)20