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);
}
}
}
}
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);
}
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);
}
}
}
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);
}
}
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);
}
}
Aggregations