use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.
the class VNXeExportOperations method addInitiators.
@Override
public void addInitiators(StorageSystem storage, URI exportMaskUri, List<URI> volumeURIs, List<Initiator> initiatorList, List<URI> targets, TaskCompleter taskCompleter) throws DeviceControllerException {
_logger.info("{} addInitiator START...", storage.getSerialNumber());
List<Initiator> createdInitiators = new ArrayList<Initiator>();
ExportMask exportMask = null;
try {
ExportOperationContext context = new VNXeExportOperationContext();
taskCompleter.updateWorkflowStepContext(context);
exportMask = _dbClient.queryObject(ExportMask.class, exportMaskUri);
if (exportMask == null || exportMask.getInactive()) {
throw new DeviceControllerException("Invalid ExportMask URI: " + exportMaskUri);
}
VNXeApiClient apiClient = getVnxeClient(storage);
List<Initiator> initiators = ExportUtils.getExportMaskInitiators(exportMask, _dbClient);
// Finding existing host from the array
Collection<VNXeHostInitiator> vnxeInitiators = prepareInitiators(initiators).values();
String hostId = null;
for (VNXeHostInitiator init : vnxeInitiators) {
VNXeHostInitiator foundInit = apiClient.getInitiatorByWWN(init.getInitiatorId());
if (foundInit != null) {
VNXeBase host = foundInit.getParentHost();
if (host != null) {
hostId = host.getId();
break;
}
}
}
if (hostId == null) {
String msg = String.format("No existing host found in the array for the existing exportMask %s", exportMask.getMaskName());
_logger.error(msg);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("addiniator", msg);
taskCompleter.error(_dbClient, error);
return;
}
validateInitiators(_dbClient, initiatorList, apiClient, hostId);
Map<Initiator, VNXeHostInitiator> initiatorMap = prepareInitiators(initiatorList);
for (Entry<Initiator, VNXeHostInitiator> entry : initiatorMap.entrySet()) {
VNXeHostInitiator newInit = entry.getValue();
VNXeHostInitiator init = apiClient.getInitiatorByWWN(newInit.getInitiatorId());
// COP-27752 - fresh deleted initiator may not be deleted completely
int retry = 0;
while (retry <= MAX_REMOVE_INITIATOR_RETRIES && init != null && init.getParentHost() == null) {
try {
Thread.sleep(WAIT_FOR_RETRY);
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
}
init = apiClient.getInitiatorByWWN(newInit.getInitiatorId());
}
if (init != null) {
// found it
VNXeBase host = init.getParentHost();
if (host != null && host.getId().equals(hostId)) {
// do nothing. it is already in the array
_logger.info("The initiator exist in the host in the array");
} else if (host == null) {
// initiator without parent host, add parent host
apiClient.setInitiatorHost(init.getId(), hostId);
} else {
String msg = String.format("Initiator %s belongs to %s, but other initiator belongs to %s. Please move initiator to the correct host", init.getInitiatorId(), host.getId(), hostId);
_logger.error(msg);
if (!createdInitiators.isEmpty()) {
for (Initiator initiator : createdInitiators) {
exportMask.getInitiators().add(initiator.getId().toString());
}
_dbClient.updateObject(exportMask);
ExportOperationContext.insertContextOperation(taskCompleter, VNXeExportOperationContext.OPERATION_ADD_INITIATORS_TO_HOST, createdInitiators);
}
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("addiniator", msg);
taskCompleter.error(_dbClient, error);
return;
}
} else {
apiClient.createInitiator(newInit, hostId);
createdInitiators.add(entry.getKey());
}
}
for (Initiator initiator : initiatorList) {
exportMask.getInitiators().add(initiator.getId().toString());
}
_dbClient.updateObject(exportMask);
ExportOperationContext.insertContextOperation(taskCompleter, VNXeExportOperationContext.OPERATION_ADD_INITIATORS_TO_HOST, createdInitiators);
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_003);
taskCompleter.ready(_dbClient);
} catch (Exception e) {
_logger.error("Add initiators error: ", e);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("addInitiator", e.getMessage());
taskCompleter.error(_dbClient, error);
}
}
use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.
the class VNXeJob method getVNXeClient.
/**
* Get VNXe API client
*
* @param jobContext
* @return
*/
public VNXeApiClient getVNXeClient(JobContext jobContext) {
VNXeApiClient vnxeApiClient = null;
StorageSystem storageSystem = jobContext.getDbClient().queryObject(StorageSystem.class, _storageSystemUri);
if (Type.unity.name().equalsIgnoreCase(storageSystem.getSystemType())) {
vnxeApiClient = jobContext.getVNXeApiClientFactory().getUnityClient(storageSystem.getIpAddress(), storageSystem.getPortNumber(), storageSystem.getUsername(), storageSystem.getPassword());
} else {
vnxeApiClient = jobContext.getVNXeApiClientFactory().getClient(storageSystem.getIpAddress(), storageSystem.getPortNumber(), storageSystem.getUsername(), storageSystem.getPassword());
}
return vnxeApiClient;
}
use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.
the class VNXUnityBlockStorageDevice method doDeleteVolumes.
@Override
public void doDeleteVolumes(StorageSystem storageSystem, String opId, List<Volume> volumes, TaskCompleter completer) throws DeviceControllerException {
logger.info("deleting volumes, array: {}", storageSystem.getSerialNumber());
VNXeApiClient apiClient = getVnxUnityClient(storageSystem);
Map<String, List<String>> cgNameMap = new HashMap<String, List<String>>();
try {
Set<URI> updateStoragePools = new HashSet<URI>();
// Invoke a test failure if testing
for (Volume volume : volumes) {
String lunId = volume.getNativeId();
if (NullColumnValueGetter.isNullValue(lunId)) {
logger.info(String.format("The volume %s does not have native id, do nothing", volume.getLabel()));
continue;
}
updateStoragePools.add(volume.getPool());
if (!apiClient.checkLunExists(lunId)) {
logger.info(String.format("The volume %s does not exist in the array, do nothing", volume.getLabel()));
continue;
}
String cgName = volume.getReplicationGroupInstance();
if (NullColumnValueGetter.isNotNullValue(cgName)) {
List<String> lunIds = cgNameMap.get(cgName);
if (lunIds == null) {
lunIds = new ArrayList<String>();
cgNameMap.put(cgName, lunIds);
}
lunIds.add(volume.getNativeId());
} else {
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_035);
apiClient.deleteLunSync(volume.getNativeId(), false);
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_036);
}
}
for (Map.Entry<String, List<String>> entry : cgNameMap.entrySet()) {
String cgName = entry.getKey();
List<String> lunIDs = entry.getValue();
String cgId = apiClient.getConsistencyGroupIdByName(cgName);
boolean isRP = false;
if (cgId != null && !cgId.isEmpty()) {
// Check if the CG has blockHostAccess to a RP host. if the CG is exported to a RP, we could not delete the lun
// directly, we have to remove the volume from the CG first, then delete it.
StorageResource cg = apiClient.getStorageResource(cgId);
List<BlockHostAccess> hosts = cg.getBlockHostAccess();
if (hosts != null && !hosts.isEmpty()) {
for (BlockHostAccess hostAccess : hosts) {
VNXeBase hostId = hostAccess.getHost();
if (hostId != null) {
VNXeHost host = apiClient.getHostById(hostId.getId());
if (host != null) {
if (host.getType() == HostTypeEnum.RPA.getValue()) {
// Remove the luns from the CG
isRP = true;
logger.info(String.format("Removing volumes from CG because the CG %sis exported to RP", cgName));
VNXeUtils.getCGLock(workflowService, storageSystem, cgName, opId);
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_034);
apiClient.removeLunsFromConsistencyGroup(cgId, lunIDs);
for (String lunId : lunIDs) {
logger.info(String.format("Deleting the volume %s", lunId));
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_035);
apiClient.deleteLunSync(lunId, false);
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_036);
}
break;
}
}
}
}
}
}
if (!isRP) {
VNXeUtils.getCGLock(workflowService, storageSystem, cgName, opId);
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_034);
apiClient.deleteLunsFromConsistencyGroup(cgId, lunIDs);
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_037);
}
}
for (URI pool : updateStoragePools) {
VNXeJob.updateStoragePoolCapacity(dbClient, apiClient, pool, null);
}
completer.ready(dbClient);
} catch (VNXeException e) {
logger.error("Delete volumes got the exception", e);
completer.error(dbClient, e);
} catch (Exception ex) {
logger.error("Delete volumes got the exception", ex);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteVolumes", ex.getMessage());
completer.error(dbClient, error);
}
}
use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.
the class VNXUnityBlockStorageDevice method doExpandVolume.
@Override
public void doExpandVolume(StorageSystem storage, StoragePool pool, Volume volume, Long size, TaskCompleter taskCompleter) throws DeviceControllerException {
logger.info(String.format("Expand Volume Start - Array: %s, Pool: %s, Volume: %s, New size: %d", storage.getSerialNumber(), pool.getNativeGuid(), volume.getLabel(), size));
String cgName = volume.getReplicationGroupInstance();
String consistencyGroupId = null;
try {
VNXeApiClient apiClient = getVnxUnityClient(storage);
if (NullColumnValueGetter.isNotNullValue(cgName)) {
consistencyGroupId = apiClient.getConsistencyGroupIdByName(cgName);
VNXeUtils.getCGLock(workflowService, storage, cgName, taskCompleter.getOpId());
}
VNXeCommandJob commandJob = apiClient.expandLun(volume.getNativeId(), size, consistencyGroupId);
VNXeExpandVolumeJob expandVolumeJob = new VNXeExpandVolumeJob(commandJob.getId(), storage.getId(), taskCompleter);
ControllerServiceImpl.enqueueJob(new QueueJob(expandVolumeJob));
} catch (VNXeException e) {
logger.error("Expand volume got the exception", e);
taskCompleter.error(dbClient, e);
} catch (Exception ex) {
logger.error("Expand volume got the exception", ex);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("ExpandVolume", ex.getMessage());
taskCompleter.error(dbClient, error);
}
}
use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.
the class VNXUnityBlockStorageDevice method doAddToConsistencyGroup.
@Override
public void doAddToConsistencyGroup(StorageSystem storage, URI consistencyGroupId, String replicationGroupName, List<URI> blockObjects, TaskCompleter taskCompleter) throws DeviceControllerException {
BlockConsistencyGroup consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
VNXeApiClient apiClient = getVnxUnityClient(storage);
try {
List<String> luns = new ArrayList<String>();
for (URI volume : blockObjects) {
BlockObject blockObject = BlockObject.fetch(dbClient, volume);
if (blockObject instanceof Volume) {
Volume lun = (Volume) blockObject;
luns.add(lun.getNativeId());
} else {
String errorStr = String.format("The blockObject %s is not a volume. it is not supported.", volume.toString());
logger.error(errorStr);
handleAddToCGError(blockObjects, taskCompleter, consistencyGroup.getLabel(), replicationGroupName, errorStr);
return;
}
}
String cgNativeId = apiClient.getConsistencyGroupIdByName(replicationGroupName);
if (cgNativeId == null || cgNativeId.isEmpty()) {
String errorStr = String.format("Could not find the consistency group %s in the error", replicationGroupName);
logger.error(errorStr);
handleAddToCGError(blockObjects, taskCompleter, consistencyGroup.getLabel(), replicationGroupName, errorStr);
return;
}
apiClient.addLunsToConsistencyGroup(cgNativeId, luns);
for (URI blockObjectURI : blockObjects) {
BlockObject blockObject = BlockObject.fetch(dbClient, blockObjectURI);
if (blockObject != null) {
blockObject.setConsistencyGroup(consistencyGroupId);
}
dbClient.updateObject(blockObject);
}
taskCompleter.ready(dbClient);
logger.info("Added volumes to the consistency group successfully");
} catch (Exception e) {
logger.error("Exception caught when adding volumes to the consistency group ", e);
handleAddToCGError(blockObjects, taskCompleter, consistencyGroup.getLabel(), replicationGroupName, e.getMessage());
}
}
Aggregations