use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.
the class VNXUnityBlockStorageDevice method doDeleteConsistencyGroup.
@Override
public void doDeleteConsistencyGroup(StorageSystem storage, URI consistencyGroupId, String replicationGroupName, Boolean keepRGName, Boolean markInactive, TaskCompleter taskCompleter) throws DeviceControllerException {
logger.info("Deleting consistency group, array: {}", storage.getSerialNumber());
BlockConsistencyGroup consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
StringSet cgNames = new StringSet();
if (NullColumnValueGetter.isNullValue(replicationGroupName)) {
StringSetMap ssm = consistencyGroup.getSystemConsistencyGroups();
if (ssm != null) {
cgNames = ssm.get(storage.getId().toString());
if (cgNames == null || cgNames.isEmpty()) {
logger.info("There is no array consistency group to be deleted.");
// Clean up the system consistency group references
BlockConsistencyGroupUtils.cleanUpCGAndUpdate(consistencyGroup, storage.getId(), null, markInactive, dbClient);
taskCompleter.ready(dbClient);
return;
}
}
} else {
cgNames.add(replicationGroupName);
}
VNXeApiClient apiClient = getVnxUnityClient(storage);
try {
for (String cgName : cgNames) {
logger.info("Deleting the consistency group {}", cgName);
String id = apiClient.getConsistencyGroupIdByName(cgName);
if (id != null && !id.isEmpty()) {
apiClient.deleteConsistencyGroup(id, false, false);
}
if (!keepRGName) {
// Clean up the system consistency group references
BlockConsistencyGroupUtils.cleanUpCGAndUpdate(consistencyGroup, storage.getId(), cgName, markInactive, dbClient);
if (consistencyGroup.getInactive()) {
logger.info("CG is deleted");
}
}
}
taskCompleter.ready(dbClient);
} catch (Exception e) {
logger.info("Failed to delete consistency group: " + e);
// Set task to error
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("doDeleteConsistencyGroup", e.getMessage());
taskCompleter.error(dbClient, error);
}
}
use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.
the class VNXUnityBlockStorageDevice method doCreateVolumes.
@Override
public void doCreateVolumes(StorageSystem storage, StoragePool storagePool, String opId, List<Volume> volumes, VirtualPoolCapabilityValuesWrapper capabilities, TaskCompleter taskCompleter) throws DeviceControllerException {
logger.info("creating volumes, array: {}, pool : {}", storage.getSerialNumber(), storagePool.getNativeId());
VNXeApiClient apiClient = getVnxUnityClient(storage);
List<String> jobs = new ArrayList<String>();
boolean opFailed = false;
try {
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_022);
Map<String, List<Volume>> cgVolumes = new HashMap<String, List<Volume>>();
Map<String, List<URI>> jobVolumesMap = new HashMap<String, List<URI>>();
for (Volume volume : volumes) {
String tenantName = "";
try {
TenantOrg tenant = dbClient.queryObject(TenantOrg.class, volume.getTenant().getURI());
tenantName = tenant.getLabel();
} catch (DatabaseException e) {
logger.error("Error lookup TenantOrb object", e);
}
String label = nameGenerator.generate(tenantName, volume.getLabel(), volume.getId().toString(), '-', VNXeConstants.MAX_NAME_LENGTH);
String cgName = volume.getReplicationGroupInstance();
volume.setNativeGuid(label);
dbClient.updateObject(volume);
if (NullColumnValueGetter.isNullValue(cgName)) {
String autoTierPolicyName = ControllerUtils.getAutoTieringPolicyName(volume.getId(), dbClient);
if (autoTierPolicyName.equals(Constants.NONE)) {
autoTierPolicyName = null;
}
VNXeCommandJob job = apiClient.createLun(label, storagePool.getNativeId(), volume.getCapacity(), volume.getThinlyProvisioned(), autoTierPolicyName);
jobs.add(job.getId());
jobVolumesMap.put(job.getId(), Arrays.asList(volume.getId()));
} else {
logger.info(String.format("Creating the volume %s in CG %s", volume.getLabel(), cgName));
List<Volume> vols = cgVolumes.get(cgName);
if (vols == null) {
vols = new ArrayList<Volume>();
}
vols.add(volume);
cgVolumes.put(cgName, vols);
}
}
for (Map.Entry<String, List<Volume>> cgVol : cgVolumes.entrySet()) {
// Creating volumes in a CG
String cgName = cgVol.getKey();
String cgId = apiClient.getConsistencyGroupIdByName(cgName);
if (cgId == null) {
String errorMsg = String.format("The CG %s could not be found in the array", cgName);
logger.error(errorMsg);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("CreateVolumes", errorMsg);
taskCompleter.error(dbClient, error);
dbClient.markForDeletion(cgVol.getValue());
return;
}
List<Volume> vols = cgVol.getValue();
VNXeUtils.getCGLock(workflowService, storage, cgName, opId);
List<LunCreateParam> lunCreates = new ArrayList<LunCreateParam>();
StorageResource cg = apiClient.getConsistencyGroup(cgId);
List<URI> volURIs = new ArrayList<URI>();
for (Volume volToCreate : vols) {
volURIs.add(volToCreate.getId());
boolean isPolicyOn = false;
String tierPolicy = ControllerUtils.getAutoTieringPolicyName(volToCreate.getId(), dbClient);
FastVPParam fastVP = new FastVPParam();
if (!tierPolicy.equals(Constants.NONE)) {
TieringPolicyEnum tierValue = TieringPolicyEnum.valueOf(tierPolicy);
if (tierValue != null) {
fastVP.setTieringPolicy(tierValue.getValue());
isPolicyOn = true;
}
}
// Construct Unity API LunParam for each volume to be created.
LunParam lunParam = new LunParam();
lunParam.setIsThinEnabled(volToCreate.getThinlyProvisioned());
lunParam.setSize(volToCreate.getCapacity());
lunParam.setPool(new VNXeBase(storagePool.getNativeId()));
List<BlockHostAccess> hostAccesses = cg.getBlockHostAccess();
if (hostAccesses != null && !hostAccesses.isEmpty()) {
for (BlockHostAccess hostAccess : hostAccesses) {
hostAccess.setAccessMask(HostLUNAccessEnum.NOACCESS.getValue());
}
lunParam.setHostAccess(hostAccesses);
}
LunCreateParam createParam = new LunCreateParam();
createParam.setName(volToCreate.getLabel());
createParam.setLunParameters(lunParam);
if (isPolicyOn) {
lunParam.setFastVPParameters(fastVP);
}
lunCreates.add(createParam);
}
VNXeCommandJob result = apiClient.createLunsInConsistencyGroup(lunCreates, cgId);
jobs.add(result.getId());
jobVolumesMap.put(result.getId(), volURIs);
}
VNXUnityCreateVolumesJob createVolumesJob = new VNXUnityCreateVolumesJob(jobVolumesMap, jobs, storage.getId(), taskCompleter, storagePool.getId());
ControllerServiceImpl.enqueueJob(new QueueJob(createVolumesJob));
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_023);
} catch (VNXeException e) {
logger.error("Create volumes got the exception", e);
opFailed = true;
taskCompleter.error(dbClient, e);
} catch (Exception ex) {
logger.error("Create volumes got the exception", ex);
opFailed = true;
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("CreateVolumes", ex.getMessage());
taskCompleter.error(dbClient, error);
}
if (opFailed) {
for (Volume vol : volumes) {
vol.setInactive(true);
dbClient.updateObject(vol);
}
}
}
use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.
the class VNXUnityExportOperations method findHLUsForInitiators.
@Override
public Set<Integer> findHLUsForInitiators(StorageSystem storage, List<String> initiatorNames, boolean mustHaveAllPorts) {
Set<Integer> usedHLUs = new HashSet<Integer>();
try {
Set<String> vnxeHostIds = new HashSet<String>();
VNXeApiClient apiClient = getVnxeClient(storage);
for (String initiatorName : initiatorNames) {
initiatorName = Initiator.toPortNetworkId(initiatorName);
URIQueryResultList initiatorResult = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getInitiatorPortInitiatorConstraint(initiatorName), initiatorResult);
if (initiatorResult.iterator().hasNext()) {
Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorResult.iterator().next());
String initiatorId = initiator.getInitiatorPort();
if (Protocol.FC.name().equals(initiator.getProtocol())) {
initiatorId = initiator.getInitiatorNode() + ":" + initiatorId;
}
// query VNX Unity initiator
VNXeHostInitiator vnxeInitiator = apiClient.getInitiatorByWWN(initiatorId);
if (vnxeInitiator != null) {
VNXeBase parentHost = vnxeInitiator.getParentHost();
if (parentHost != null) {
vnxeHostIds.add(parentHost.getId());
}
}
}
}
if (vnxeHostIds.isEmpty()) {
log.info("No Host found on array for initiators {}", Joiner.on(',').join(initiatorNames));
} else {
log.info("Found matching hosts {} on array", vnxeHostIds);
for (String vnxeHostId : vnxeHostIds) {
// Get vnxeHost from vnxeHostId
VNXeHost vnxeHost = apiClient.getHostById(vnxeHostId);
List<VNXeBase> hostLunIds = vnxeHost.getHostLUNs();
if (hostLunIds != null && !hostLunIds.isEmpty()) {
for (VNXeBase hostLunId : hostLunIds) {
HostLun hostLun = apiClient.getHostLun(hostLunId.getId());
log.info("Looking at Host Lun {}; Lun: {}, HLU: {}", hostLunId.getId(), hostLun.getLun(), hostLun.getHlu());
usedHLUs.add(hostLun.getHlu());
}
}
}
}
log.info(String.format("HLUs found for Initiators { %s }: %s", Joiner.on(',').join(initiatorNames), usedHLUs));
} catch (Exception e) {
String errMsg = "Encountered an error when attempting to query used HLUs for initiators: " + e.getMessage();
log.error(errMsg, e);
throw VNXeException.exceptions.hluRetrievalFailed(errMsg, e);
}
return usedHLUs;
}
use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.
the class VNXUnityFileStorageDevice method doDeleteSnapshot.
@Override
public BiosCommandResult doDeleteSnapshot(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
_logger.info("Deleting file system {} snapshot {} ", args.getFsName(), args.getSnapshotLabel());
VNXeApiClient apiClient = getVnxUnityClient(storage);
VNXeCommandJob job = null;
VNXeFileTaskCompleter completer = null;
try {
job = apiClient.deleteFileSystemSnap(args.getSnapNativeId());
if (job != null) {
completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
VNXeDeleteFileSystemSnapshotJob snapJob = new VNXeDeleteFileSystemSnapshotJob(job.getId(), storage.getId(), completer);
ControllerServiceImpl.enqueueJob(new QueueJob(snapJob));
} else {
_logger.error("No job returned from deleteFileSystemSnap");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("snapshotFileSystem", "No Job returned from deleteFileSystemSnap");
return BiosCommandResult.createErrorResult(error);
}
} catch (VNXeException e) {
_logger.error("Delete file system snapshot got the exception", e);
if (completer != null) {
completer.error(dbClient, e);
}
return BiosCommandResult.createErrorResult(e);
} catch (Exception ex) {
_logger.error("Delete file system snpashot got the exception", ex);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystemSnapshot", ex.getMessage());
if (completer != null) {
completer.error(dbClient, error);
}
return BiosCommandResult.createErrorResult(error);
}
StringBuilder logMsgBuilder = new StringBuilder(String.format("Delete filesystem snapshot job submitted - Array:%s, fileSystem: %s, snapshot: %s", storage.getSerialNumber(), args.getFsName(), args.getSnapshotName()));
_logger.info(logMsgBuilder.toString());
return BiosCommandResult.createPendingResult();
}
use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.
the class VNXeExportOperations method addVolumes.
@Override
public void addVolumes(StorageSystem storage, URI exportMaskUri, VolumeURIHLU[] volumeURIHLUs, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
_logger.info("{} addVolume START...", storage.getSerialNumber());
List<URI> mappedVolumes = new ArrayList<URI>();
ExportMask exportMask = null;
try {
_logger.info("addVolumes: Export mask id: {}", exportMaskUri);
_logger.info("addVolumes: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
if (initiatorList != null) {
_logger.info("addVolumes: initiators impacted: {}", Joiner.on(',').join(initiatorList));
}
ExportOperationContext context = new VNXeExportOperationContext();
taskCompleter.updateWorkflowStepContext(context);
VNXeApiClient apiClient = getVnxeClient(storage);
exportMask = _dbClient.queryObject(ExportMask.class, exportMaskUri);
if (exportMask == null || exportMask.getInactive()) {
throw new DeviceControllerException("Invalid ExportMask URI: " + exportMaskUri);
}
List<Initiator> initiators = ExportUtils.getExportMaskInitiators(exportMask, _dbClient);
Collection<VNXeHostInitiator> vnxeInitiators = prepareInitiators(initiators).values();
VNXeBase host = apiClient.prepareHostsForExport(vnxeInitiators);
String opId = taskCompleter.getOpId();
Set<String> processedCGs = new HashSet<String>();
for (VolumeURIHLU volURIHLU : volumeURIHLUs) {
URI volUri = volURIHLU.getVolumeURI();
String hlu = volURIHLU.getHLU();
_logger.info(String.format("hlu %s", hlu));
BlockObject blockObject = BlockObject.fetch(_dbClient, volUri);
VNXeExportResult result = null;
Integer newhlu = -1;
if (hlu != null && !hlu.isEmpty() && !hlu.equals(ExportGroup.LUN_UNASSIGNED_STR)) {
newhlu = Integer.valueOf(hlu);
}
// COP-25254 this method could be called when create vplex volumes from snapshot. in this case
// the volume passed in is an internal volume, representing the snapshot. we need to find the snapshot
// with the same nativeGUID, then export the snapshot.
BlockObject snapshot = findSnapshotByInternalVolume(blockObject);
boolean isVplexVolumeFromSnap = false;
URI vplexBackendVol = null;
if (snapshot != null) {
blockObject = snapshot;
exportMask.addVolume(volUri, newhlu);
isVplexVolumeFromSnap = true;
vplexBackendVol = volUri;
volUri = blockObject.getId();
}
String cgName = VNXeUtils.getBlockObjectCGName(blockObject, _dbClient);
if (cgName != null && !processedCGs.contains(cgName)) {
processedCGs.add(cgName);
VNXeUtils.getCGLock(workflowService, storage, cgName, opId);
}
String nativeId = blockObject.getNativeId();
if (URIUtil.isType(volUri, Volume.class)) {
result = apiClient.exportLun(host, nativeId, newhlu);
exportMask.addVolume(volUri, result.getHlu());
if (result.isNewAccess()) {
mappedVolumes.add(volUri);
}
} else if (URIUtil.isType(volUri, BlockSnapshot.class)) {
result = apiClient.exportSnap(host, nativeId, newhlu);
exportMask.addVolume(volUri, result.getHlu());
if (result.isNewAccess()) {
mappedVolumes.add(volUri);
}
String snapWWN = setSnapWWN(apiClient, blockObject, nativeId);
if (isVplexVolumeFromSnap) {
Volume backendVol = _dbClient.queryObject(Volume.class, vplexBackendVol);
backendVol.setWWN(snapWWN);
_dbClient.updateObject(backendVol);
}
}
}
ExportOperationContext.insertContextOperation(taskCompleter, VNXeExportOperationContext.OPERATION_ADD_VOLUMES_TO_HOST_EXPORT, mappedVolumes);
_dbClient.updateObject(exportMask);
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_002);
taskCompleter.ready(_dbClient);
} catch (Exception e) {
_logger.error("Add volumes error: ", e);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("addVolume", e.getMessage());
taskCompleter.error(_dbClient, error);
}
_logger.info("{} addVolumes END...", storage.getSerialNumber());
}
Aggregations