use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class SmisStorageDevice method doRemoveFromConsistencyGroup.
@Override
public void doRemoveFromConsistencyGroup(StorageSystem storage, final URI consistencyGroupId, final List<URI> blockObjects, final TaskCompleter taskCompleter) throws DeviceControllerException {
Set<String> groupNames = new HashSet<String>();
String grpName = null;
try {
// get the group name from one of the block objects; we expect all of them to be the same group
Iterator<URI> itr = blockObjects.iterator();
while (itr.hasNext()) {
BlockObject blockObject = BlockObject.fetch(_dbClient, itr.next());
if (blockObject != null && !blockObject.getInactive() && !NullColumnValueGetter.isNullValue(blockObject.getReplicationGroupInstance())) {
groupNames.add(blockObject.getReplicationGroupInstance());
}
}
// Check if the replication group exists
for (String groupName : groupNames) {
grpName = groupName;
storage = findProviderFactory.withGroup(storage, groupName).find();
if (storage == null) {
ServiceError error = DeviceControllerErrors.smis.noConsistencyGroupWithGivenName();
taskCompleter.error(_dbClient, error);
return;
}
String[] blockObjectNames = _helper.getBlockObjectAlternateNames(blockObjects);
CIMObjectPath[] members = _cimPath.getVolumePaths(storage, blockObjectNames);
CIMArgument[] output = new CIMArgument[5];
BlockConsistencyGroup consistencyGroup = _dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
if (!storage.deviceIsType(Type.vnxblock) && ControllerUtils.checkCGHasGroupRelationship(storage, consistencyGroupId, _dbClient)) {
// remove from DeviceMaskingGroup
CIMObjectPath maskingGroupPath = _cimPath.getMaskingGroupPath(storage, groupName, SmisConstants.MASKING_GROUP_TYPE.SE_DeviceMaskingGroup);
_log.info("Removing volumes {} from device masking group {}", blockObjectNames, maskingGroupPath.toString());
CIMArgument[] inArgs = _helper.getRemoveAndUnmapMaskingGroupMembersInputArguments(maskingGroupPath, members, storage, true);
_helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), SmisConstants.REMOVE_MEMBERS, inArgs, output, null);
} else {
CIMObjectPath cgPath = _cimPath.getReplicationGroupPath(storage, groupName);
CIMInstance cgPathInstance = _helper.checkExists(storage, cgPath, false, false);
// If there is no replication group with the given name, return success
if (cgPathInstance == null) {
_log.info(String.format("no replication group with name %s exists on storage system %s", groupName, storage.getLabel()));
} else {
CIMObjectPath replicationSvc = _cimPath.getControllerReplicationSvcPath(storage);
CIMArgument[] removeMembersInput = _helper.getRemoveMembersInputArguments(cgPath, members);
_helper.invokeMethod(storage, replicationSvc, SmisConstants.REMOVE_MEMBERS, removeMembersInput, output);
}
}
}
taskCompleter.ready(_dbClient);
} catch (Exception e) {
BlockConsistencyGroup consistencyGroup = _dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
_log.error("Problem while removing volume from CG :{}", consistencyGroupId, e);
taskCompleter.error(_dbClient, DeviceControllerException.exceptions.failedToRemoveMembersToConsistencyGroup((consistencyGroup == null ? "unknown cg" : consistencyGroup.getLabel()), (grpName == null ? "unknown replication group" : grpName), e.getMessage()));
}
}
use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class SmisStorageDevice method getSRDFSourceProvider.
/**
* Gets the SRDF source provider, given target CG.
*/
private StorageSystem getSRDFSourceProvider(BlockConsistencyGroup consistencyGroup) {
StorageSystem sourceProvider = null;
List<BlockConsistencyGroup> groups = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, BlockConsistencyGroup.class, PrefixConstraint.Factory.getFullMatchConstraint(BlockConsistencyGroup.class, "label", consistencyGroup.getAlternateLabel()));
BlockConsistencyGroup sourceCG = groups.iterator().next();
URI sourceSystemURI = sourceCG.getStorageController();
if (!NullColumnValueGetter.isNullURI(sourceSystemURI)) {
sourceProvider = _dbClient.queryObject(StorageSystem.class, sourceSystemURI);
}
return sourceProvider;
}
use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class SmisStorageDevice method doAddToConsistencyGroup.
@Override
public void doAddToConsistencyGroup(StorageSystem storage, final URI consistencyGroupId, String replicationGroupName, final List<URI> blockObjectURIs, final TaskCompleter taskCompleter) throws DeviceControllerException {
BlockConsistencyGroup consistencyGroup = _dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
Map<URI, BlockObject> uriToBlockObjectMap = new HashMap<URI, BlockObject>();
List<URI> replicas = new ArrayList<URI>();
List<URI> volumes = new ArrayList<URI>();
try {
List<BlockObject> blockObjects = new ArrayList<BlockObject>();
for (URI blockObjectURI : blockObjectURIs) {
// FIXME Performance improvement here
BlockObject blockObject = BlockObject.fetch(_dbClient, blockObjectURI);
if (blockObject != null) {
blockObjects.add(blockObject);
uriToBlockObjectMap.put(blockObjectURI, blockObject);
}
}
/**
* Request: Volume CG with volume objects OR
* Volume CG with replica objects(snap/clone/mirror)
*
* make sure that the blockObjects are of same type (Volume/Snap/Clone/Mirror)
* If Volume:
* add them to group
* If Replica (supported only for 8.0):
* If existing replicas do not have replicationGroupInstance set:
* create new RG on array with random name,
* add replicas to that RG,
* set RG name in replicationGroupInstance field for new replicas.
* Else:
* Get RG name from existing replica,
* Add new replicas to DMG with same name as RG name,
* set RG name in replicationGroupInstance field for new replicas.
*
* For all objects except Clone, set CG URI.
*/
for (BlockObject blockObject : blockObjects) {
boolean isFullCopy = false;
if (blockObject instanceof Volume) {
isFullCopy = ControllerUtils.isVolumeFullCopy((Volume) blockObject, _dbClient);
}
if (blockObject instanceof BlockSnapshot || isFullCopy || blockObject instanceof BlockMirror) {
replicas.add(blockObject.getId());
} else {
volumes.add(blockObject.getId());
}
}
// adding replicas to ReplicationGroup is supported only for 8.0
if (!storage.getUsingSmis80() && !replicas.isEmpty()) {
String errMsg = "Adding replicas to Consistency Group is not supported on 4.6.x Provider";
_log.warn(errMsg);
taskCompleter.error(_dbClient, DeviceControllerException.exceptions.failedToAddMembersToConsistencyGroup(consistencyGroup.getLabel(), consistencyGroup.fetchArrayCgName(storage.getId()), errMsg));
return;
}
if (!volumes.isEmpty() && !replicas.isEmpty()) {
String errMsg = "Mix of Volumes and Replica types is not supported";
_log.warn(errMsg);
taskCompleter.error(_dbClient, DeviceControllerException.exceptions.failedToAddMembersToConsistencyGroup(consistencyGroup.getLabel(), consistencyGroup.getCgNameOnStorageSystem(storage.getId()), errMsg));
return;
}
if (!replicas.isEmpty()) {
addReplicasToConsistencyGroup(storage, consistencyGroup, replicas, uriToBlockObjectMap);
} else if (!volumes.isEmpty()) {
// get source provider for SRDF target volumes
// target CG is created using source system provider
StorageSystem forProvider = storage;
boolean isSrdfTarget = false;
Volume vol = (Volume) uriToBlockObjectMap.get(volumes.iterator().next());
if (vol.checkForSRDF() && !NullColumnValueGetter.isNullNamedURI(vol.getSrdfParent())) {
Volume srcVolume = _dbClient.queryObject(Volume.class, vol.getSrdfParent().getURI());
forProvider = _dbClient.queryObject(StorageSystem.class, srcVolume.getStorageController());
isSrdfTarget = true;
}
// Check if the consistency group exists
boolean createCG = false;
CIMObjectPath cgPath = null;
CIMInstance cgPathInstance = null;
boolean isVPlexOrRP = consistencyGroup.checkForType(Types.VPLEX) || consistencyGroup.checkForType(Types.RP);
String groupName = ControllerUtils.generateReplicationGroupName(storage, consistencyGroup, replicationGroupName, _dbClient);
// If this is for VPlex or RP, we would create backend consistency group if it does not exist yet.
if (!consistencyGroup.created(storage.getId(), groupName)) {
if (isVPlexOrRP) {
createCG = true;
_log.info(String.format("No consistency group exists for the storage: %s", storage.getId()));
} else {
ServiceError error = DeviceControllerErrors.smis.noConsistencyGroupWithGivenName();
taskCompleter.error(_dbClient, error);
return;
}
} else {
if (!isSrdfTarget) {
StorageSystem storageSystem = findProviderFactory.withGroup(storage, groupName).find();
if (storageSystem == null) {
if (isVPlexOrRP) {
_log.info(String.format("Could not find consistency group with the name: %s", groupName));
createCG = true;
} else {
ServiceError error = DeviceControllerErrors.smis.noConsistencyGroupWithGivenName();
taskCompleter.error(_dbClient, error);
return;
}
} else {
forProvider = storageSystem;
}
}
if (!createCG && !(storage.deviceIsType(Type.vnxblock) && !consistencyGroup.getArrayConsistency())) {
cgPath = _cimPath.getReplicationGroupPath(forProvider, storage.getSerialNumber(), groupName);
cgPathInstance = _helper.checkExists(forProvider, cgPath, false, false);
// operation to error
if (cgPathInstance == null) {
taskCompleter.error(_dbClient, DeviceControllerException.exceptions.consistencyGroupNotFound(consistencyGroup.getLabel(), consistencyGroup.getCgNameOnStorageSystem(storage.getId())));
return;
}
}
}
if (createCG) {
doCreateConsistencyGroup(storage, consistencyGroupId, groupName, null);
consistencyGroup = _dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
cgPath = _cimPath.getReplicationGroupPath(storage, groupName);
}
if (storage.deviceIsType(Type.vnxblock) && !consistencyGroup.getArrayConsistency()) {
// nothing need to be done on array side
_log.info("No array operation needed for VNX replication group {}", groupName);
} else {
CIMObjectPath replicationSvc = _cimPath.getControllerReplicationSvcPath(storage);
String[] blockObjectNames = _helper.getBlockObjectAlternateNames(volumes);
// Smis call to add volumes that are already available in Group, will result in error.
// Refresh first for confidence and avoid false positives.
ReplicationUtils.callEMCRefresh(_helper, storage, true);
Set<String> blockObjectsToAdd = _helper.filterVolumesAlreadyPartOfReplicationGroup(storage, cgPath, blockObjectNames);
if (!blockObjectsToAdd.isEmpty()) {
CIMArgument[] output = new CIMArgument[5];
CIMObjectPath[] members = _cimPath.getVolumePaths(storage, blockObjectsToAdd.toArray(new String[blockObjectsToAdd.size()]));
boolean cgHasGroupRelationship = ControllerUtils.checkCGHasGroupRelationship(storage, consistencyGroup.getId(), _dbClient);
if (!cgHasGroupRelationship) {
CIMArgument[] addMembersInput = _helper.getAddMembersInputArguments(cgPath, members);
_helper.invokeMethod(storage, replicationSvc, SmisConstants.ADD_MEMBERS, addMembersInput, output);
} else {
final CIMObjectPath maskingGroupPath = _cimPath.getMaskingGroupPath(storage, groupName, SmisConstants.MASKING_GROUP_TYPE.SE_DeviceMaskingGroup);
_log.info("Adding volumes {} to device masking group {}", StringUtils.join(blockObjectsToAdd, ", "), maskingGroupPath.toString());
final CIMArgument[] inArgs = _helper.getAddOrRemoveMaskingGroupMembersInputArguments(maskingGroupPath, members, true);
_helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), SmisConstants.ADD_MEMBERS, inArgs, output, null);
}
} else {
_log.info("Requested volumes {} are already part of the Replication Group {}, hence skipping AddMembers call..", Joiner.on(", ").join(blockObjectNames), groupName);
}
}
// refresh target provider to update its view on target CG
if (isSrdfTarget) {
refreshStorageSystem(storage.getId(), null);
}
}
taskCompleter.ready(_dbClient);
} catch (Exception e) {
_log.error("Problem in adding volumes to Consistency Group {}", consistencyGroupId, e);
// Remove any references to the consistency group
for (URI volume : volumes) {
BlockObject volumeObject = uriToBlockObjectMap.get(volume);
volumeObject.setConsistencyGroup(NullColumnValueGetter.getNullURI());
volumeObject.setReplicationGroupInstance(NullColumnValueGetter.getNullStr());
_dbClient.updateObject(volumeObject);
}
// Remove replication group instance
for (URI replica : replicas) {
BlockObject replicaObject = uriToBlockObjectMap.get(replica);
replicaObject.setReplicationGroupInstance(NullColumnValueGetter.getNullStr());
if (!(replicaObject instanceof Volume && ControllerUtils.isVolumeFullCopy((Volume) replicaObject, _dbClient))) {
replicaObject.setConsistencyGroup(NullColumnValueGetter.getNullURI());
replicaObject.setReplicationGroupInstance(NullColumnValueGetter.getNullStr());
}
_dbClient.updateObject(replicaObject);
}
taskCompleter.error(_dbClient, DeviceControllerException.exceptions.failedToAddMembersToConsistencyGroup(consistencyGroup.getLabel(), consistencyGroup.getCgNameOnStorageSystem(storage.getId()), e.getMessage()));
}
}
use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class SmisStorageDevice method doCreateConsistencyGroup.
@Override
public void doCreateConsistencyGroup(final StorageSystem storage, final URI consistencyGroupId, String groupName, final TaskCompleter taskCompleter) throws DeviceControllerException {
BlockConsistencyGroup consistencyGroup = _dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
try {
CIMArgument[] inArgs;
CIMArgument[] outArgs = new CIMArgument[5];
boolean srdfCG = false;
String deviceName = groupName;
// create target CG on source provider
StorageSystem forProvider = storage;
if (consistencyGroup.getRequestedTypes().contains(Types.SRDF.name())) {
srdfCG = true;
if (NullColumnValueGetter.isNotNullValue(consistencyGroup.getAlternateLabel())) {
forProvider = getSRDFSourceProvider(consistencyGroup);
_log.debug("Creating target Consistency Group on source provider");
}
}
if (forProvider.deviceIsType(Type.vnxblock) && !consistencyGroup.getArrayConsistency()) {
// nothing need to be done on array side
_log.info("No array operation needed for VNX replication group {}", groupName);
} else {
inArgs = _helper.getCreateReplicationGroupInputArguments(groupName);
CIMObjectPath replicationSvc = _cimPath.getControllerReplicationSvcPath(storage);
_helper.invokeMethod(forProvider, replicationSvc, SmisConstants.CREATE_GROUP, inArgs, outArgs);
// Grab the generated name from the instance ID and store it in the db
final String instanceID = (String) _cimPath.getCimObjectPathFromOutputArgs(outArgs, CP_REPLICATION_GROUP).getKey(CP_INSTANCE_ID).getValue();
// VMAX instanceID, e.g., 000196700567+EMC_SMI_RG1414546375042 (8.0.2 provider)
deviceName = instanceID.split(Constants.PATH_DELIMITER_REGEX)[storage.getUsingSmis80() ? 1 : 0];
}
consistencyGroup.addSystemConsistencyGroup(storage.getId().toString(), deviceName);
if (srdfCG) {
consistencyGroup.addConsistencyGroupTypes(Types.SRDF.name());
} else {
consistencyGroup.addConsistencyGroupTypes(Types.LOCAL.name());
}
if (!consistencyGroup.isProtectedCG() && NullColumnValueGetter.isNullURI(consistencyGroup.getStorageController())) {
consistencyGroup.setStorageController(storage.getId());
}
_dbClient.updateObject(consistencyGroup);
// This function could be called from doAddToConsistencyGroup() with a null taskCompleter.
if (taskCompleter != null) {
// Set task to ready.
taskCompleter.ready(_dbClient);
}
} catch (Exception e) {
_log.error("Failed to create consistency group: ", e);
ServiceError error = DeviceControllerErrors.smis.methodFailed("doCreateConsistencyGroup", e.getMessage());
// Set task to error
if (taskCompleter != null) {
taskCompleter.error(_dbClient, error);
}
}
}
use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class XIVSmisStorageDevice method doRemoveFromConsistencyGroup.
@Override
public void doRemoveFromConsistencyGroup(final StorageSystem storage, final URI consistencyGroupId, final List<URI> blockObjects, final TaskCompleter taskCompleter) throws DeviceControllerException {
BlockConsistencyGroup consistencyGroup = _dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
try {
// check if the consistency group already exists
String groupName = _helper.getConsistencyGroupName(consistencyGroup, storage);
CIMObjectPath cgPath = _cimPath.getConsistencyGroupPath(storage, groupName);
CIMInstance cgPathInstance = _helper.checkExists(storage, cgPath, false, false);
if (cgPathInstance != null) {
String[] blockObjectIds = _helper.getBlockObjectNativeIds(blockObjects);
removeVolumesFromCG(storage, consistencyGroup, cgPath, blockObjectIds);
}
// remove any references to the consistency group
List<BlockObject> objectsToSave = new ArrayList<BlockObject>();
for (URI blockObjectURI : blockObjects) {
BlockObject blockObject = BlockObject.fetch(_dbClient, blockObjectURI);
if (blockObject != null) {
if (blockObject.getConsistencyGroup() != null) {
blockObject.setConsistencyGroup(NullColumnValueGetter.getNullURI());
}
}
objectsToSave.add(blockObject);
}
_dbClient.persistObject(objectsToSave);
taskCompleter.ready(_dbClient);
} catch (DeviceControllerException e) {
taskCompleter.error(_dbClient, e);
} catch (Exception e) {
taskCompleter.error(_dbClient, DeviceControllerException.exceptions.failedToRemoveMembersToConsistencyGroup(consistencyGroup.getLabel(), consistencyGroup.getCgNameOnStorageSystem(storage.getId()), e.getMessage()));
}
}
Aggregations