use of com.emc.storageos.db.client.model.StoragePortGroup in project coprhd-controller by CoprHD.
the class AbstractDefaultMaskingOrchestrator method generateExportMaskCreateWorkflow.
/**
* Creates an ExportMask Workflow that generates a new ExportMask in an existing ExportGroup.
*
* @param workflow
* workflow to add steps to
* @param previousStep
* previous step before these steps
* @param storage
* storage system
* @param exportGroup
* export group
* @param initiatorURIs
* initiators impacted by this operation
* @param volumeMap
* volumes
* @param token
* step ID
* @return URI of the new ExportMask
* @throws Exception
*/
public GenExportMaskCreateWorkflowResult generateExportMaskCreateWorkflow(Workflow workflow, String previousStep, StorageSystem storage, ExportGroup exportGroup, List<URI> initiatorURIs, Map<URI, Integer> volumeMap, String token) throws Exception {
URI exportGroupURI = exportGroup.getId();
URI storageURI = storage.getId();
List<Initiator> initiators = null;
if (initiatorURIs != null && !initiatorURIs.isEmpty()) {
initiators = _dbClient.queryObject(Initiator.class, initiatorURIs);
} else {
_log.error("Internal Error: Need to add the initiatorURIs to the call that assembles this step.");
}
// Create and initialize the Export Mask. This involves assigning and
// allocating the Storage Ports (targets).
ExportPathParams pathParams = _blockScheduler.calculateExportPathParamForVolumes(volumeMap.keySet(), exportGroup.getNumPaths(), storage.getId(), exportGroup.getId());
if (exportGroup.getType() != null) {
pathParams.setExportGroupType(exportGroup.getType());
}
if (exportGroup.getZoneAllInitiators()) {
pathParams.setAllowFewerPorts(true);
}
URI portGroupURI = null;
if (pathParams.getPortGroup() != null) {
portGroupURI = pathParams.getPortGroup();
StoragePortGroup portGroup = _dbClient.queryObject(StoragePortGroup.class, portGroupURI);
_log.info(String.format("port group is %s", portGroup.getLabel()));
List<URI> storagePorts = StringSetUtil.stringSetToUriList(portGroup.getStoragePorts());
if (!CollectionUtils.isEmpty(storagePorts)) {
pathParams.setStoragePorts(StringSetUtil.uriListToStringSet(storagePorts));
} else {
_log.error(String.format("The port group %s does not have any port members", portGroup));
throw DeviceControllerException.exceptions.noPortMembersInPortGroupError(portGroup.getLabel());
}
}
Map<URI, List<URI>> assignments = _blockScheduler.assignStoragePorts(storage, exportGroup, initiators, null, pathParams, volumeMap.keySet(), _networkDeviceController, exportGroup.getVirtualArray(), token);
List<URI> targets = BlockStorageScheduler.getTargetURIsFromAssignments(assignments);
String maskName = useComputedMaskName() ? getComputedExportMaskName(storage, exportGroup, initiators) : null;
// can be done differently
if (exportGroup.checkInternalFlags(Flag.RECOVERPOINT_JOURNAL)) {
maskName += "_journal";
}
ExportMask exportMask = ExportMaskUtils.initializeExportMask(storage, exportGroup, initiators, volumeMap, targets, assignments, maskName, _dbClient);
if (portGroupURI != null) {
exportMask.setPortGroup(portGroupURI);
}
List<BlockObject> vols = new ArrayList<BlockObject>();
for (URI boURI : volumeMap.keySet()) {
BlockObject bo = BlockObject.fetch(_dbClient, boURI);
vols.add(bo);
}
exportMask.addToUserCreatedVolumes(vols);
_dbClient.updateObject(exportMask);
// Make a new TaskCompleter for the exportStep. It has only one subtask.
// This is due to existing requirements in the doExportGroupCreate completion
// logic.
String maskingStep = workflow.createStepId();
ExportTaskCompleter exportTaskCompleter = new ExportMaskCreateCompleter(exportGroupURI, exportMask.getId(), initiatorURIs, volumeMap, maskingStep);
Workflow.Method maskingExecuteMethod = new Workflow.Method("doExportGroupCreate", storageURI, exportGroupURI, exportMask.getId(), volumeMap, initiatorURIs, targets, exportTaskCompleter);
Workflow.Method maskingRollbackMethod = new Workflow.Method("rollbackExportGroupCreate", storageURI, exportGroupURI, exportMask.getId(), maskingStep);
maskingStep = workflow.createStep(EXPORT_GROUP_MASKING_TASK, String.format("Creating mask %s (%s)", exportMask.getMaskName(), exportMask.getId().toString()), previousStep, storageURI, storage.getSystemType(), MaskingWorkflowEntryPoints.class, maskingExecuteMethod, maskingRollbackMethod, maskingStep);
return new GenExportMaskCreateWorkflowResult(exportMask.getId(), maskingStep);
}
use of com.emc.storageos.db.client.model.StoragePortGroup in project coprhd-controller by CoprHD.
the class SmisStorageDevice method doDeleteStoragePortGroup.
@Override
public void doDeleteStoragePortGroup(StorageSystem storage, URI portGroupURI, TaskCompleter completer) throws Exception {
try {
StoragePortGroup portGroup = _dbClient.queryObject(StoragePortGroup.class, portGroupURI);
_log.info(String.format("Deleting port group %s starts", portGroup.getNativeGuid()));
String portGroupName = portGroup.getLabel();
CIMObjectPath targetPortGroupPath = _cimPath.getMaskingGroupPath(storage, portGroupName, SmisConstants.MASKING_GROUP_TYPE.SE_TargetMaskingGroup);
CIMInstance instance = _helper.checkExists(storage, targetPortGroupPath, false, false);
if (instance != null) {
// Check if there is any lun masking view associated.
if (_helper.checkPortGroupShared(storage, portGroupName, null)) {
// Could not delete the port group
String msg = String.format("The port group %s could not be deleted, because it still has associated lun masking view.", portGroup.getNativeGuid());
_log.error(msg);
completer.error(_dbClient, DeviceControllerException.errors.jobFailedOpMsg("DeleteStoragePortGroup", msg));
} else {
_helper.deleteMaskingGroup(storage, portGroupName, SmisConstants.MASKING_GROUP_TYPE.SE_TargetMaskingGroup);
completer.ready(_dbClient);
}
} else {
_log.info(String.format("The port group %s does not exist in the array", portGroupName));
}
_log.info(String.format("Deleting port group %s ends", portGroup.getNativeGuid()));
} catch (Exception e) {
_log.error("Failed deleting storage port group:", e);
completer.error(_dbClient, DeviceControllerException.errors.jobFailed(e));
}
}
use of com.emc.storageos.db.client.model.StoragePortGroup in project coprhd-controller by CoprHD.
the class VmaxPortGroupProcessor method getPortGroupInDB.
/**
* Get the port group from DB if it is discovered before.
*
* @param pgName
* - port group name
* @param storage
* - storage system
* @return - the existing or newly created port group
*/
private StoragePortGroup getPortGroupInDB(String pgName, StorageSystem storage) {
String guid = String.format("%s+%s", storage.getNativeGuid(), pgName);
URIQueryResultList result = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getPortGroupNativeGuidConstraint(guid), result);
StoragePortGroup portGroup = null;
Iterator<URI> it = result.iterator();
if (it.hasNext()) {
portGroup = dbClient.queryObject(StoragePortGroup.class, it.next());
}
return portGroup;
}
use of com.emc.storageos.db.client.model.StoragePortGroup in project coprhd-controller by CoprHD.
the class VmaxPortGroupProcessor method doBookKeeping.
/**
* Check if any port group in DB does not show up in the array anymore
*
* @param deviceURI
* - storage system URI
*/
private void doBookKeeping(URI deviceURI) {
URIQueryResultList result = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDevicePortGroupConstraint(deviceURI), result);
List<StoragePortGroup> portGroups = dbClient.queryObject(StoragePortGroup.class, result);
if (portGroups != null) {
for (StoragePortGroup portGroup : portGroups) {
String nativeGuid = portGroup.getNativeGuid();
if (nativeGuid != null && !nativeGuid.isEmpty() && !allPortGroupNativeGuids.contains(nativeGuid)) {
// the port group does not exist in the array. remove it
log.info(String.format("The port group %s does not exist in the array, remove it from DB", nativeGuid));
dbClient.removeObject(portGroup);
}
}
}
}
use of com.emc.storageos.db.client.model.StoragePortGroup in project coprhd-controller by CoprHD.
the class VmaxPortGroupProcessor method processResult.
@SuppressWarnings("unchecked")
@Override
public void processResult(Operation operation, Object resultObj, Map<String, Object> keyMap) throws BaseCollectionException {
log.info("Process port group");
try {
AccessProfile profile = (AccessProfile) keyMap.get(Constants.ACCESSPROFILE);
String serialID = (String) keyMap.get(Constants._serialID);
dbClient = (DbClient) keyMap.get(Constants.dbClient);
WBEMClient client = SMICommunicationInterface.getCIMClient(keyMap);
StorageSystem device = dbClient.queryObject(StorageSystem.class, profile.getSystemId());
boolean hasVolume = hasAnyVolume(device.getId());
final Iterator<CIMInstance> it = (Iterator<CIMInstance>) resultObj;
while (it.hasNext()) {
CIMInstance groupInstance = it.next();
CIMObjectPath groupPath = groupInstance.getObjectPath();
if (groupPath.toString().contains(serialID)) {
String portGroupName = groupInstance.getPropertyValue(Constants.ELEMENTNAME).toString();
if (StringUtils.isEmpty(portGroupName)) {
log.info(String.format("The port group %s name is null, skip", groupPath.toString()));
continue;
}
log.info(String.format("Got the port group: %s", portGroupName));
List<String> storagePorts = new ArrayList<String>();
CloseableIterator<CIMInstance> iterator = client.associatorInstances(groupPath, null, Constants.CIM_PROTOCOL_ENDPOINT, null, null, false, Constants.PS_NAME);
while (iterator.hasNext()) {
CIMInstance cimInstance = iterator.next();
String portName = CIMPropertyFactory.getPropertyValue(cimInstance, Constants._Name);
String fixedName = Initiator.toPortNetworkId(portName);
log.debug("Storage Port: {}", fixedName);
storagePorts.add(fixedName);
}
if (!storagePorts.isEmpty()) {
StoragePortGroup portGroup = getPortGroupInDB(portGroupName, device);
if (portGroup == null) {
// discovery after the upgrade.
if (hasVolume) {
List<ExportMask> masks = getExportMasksForPortGroup(client, groupPath, portGroupName, device);
boolean viprCreated = (!masks.isEmpty());
portGroup = createPortGroup(portGroupName, device, viprCreated);
for (ExportMask mask : masks) {
mask.setPortGroup(portGroup.getId());
}
dbClient.updateObject(masks);
} else {
portGroup = createPortGroup(portGroupName, device, false);
}
}
allPortGroupNativeGuids.add(portGroup.getNativeGuid());
List<URI> storagePortURIs = new ArrayList<URI>();
storagePortURIs.addAll(transform(ExportUtils.storagePortNamesToURIs(dbClient, storagePorts), CommonTransformerFunctions.FCTN_STRING_TO_URI));
portGroup.setStoragePorts(StringSetUtil.uriListToStringSet(storagePortURIs));
dbClient.updateObject(portGroup);
} else {
// no storage ports in the port group, remove it
log.info(String.format("The port group %s does not have any storage ports, ignore", portGroupName));
}
}
}
if (!allPortGroupNativeGuids.isEmpty()) {
doBookKeeping(device.getId());
} else {
log.info("Did not get any port group, skip book keeping");
}
} catch (Exception e) {
log.error("port group discovery failed ", e);
} finally {
allPortGroupNativeGuids.clear();
}
}
Aggregations