use of com.emc.storageos.vnxe.models.VNXeBase 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.models.VNXeBase 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.models.VNXeBase in project coprhd-controller by CoprHD.
the class VNXUnityFileStorageDevice method extraExportRuleFromArray.
/**
* Get the export rule which are present in array but not in CoprHD Database.
*
* @param storage
* @param args
* @return map with security flavor and export rule
*/
private Map<String, ExportRule> extraExportRuleFromArray(StorageSystem storage, FileDeviceInputOutput args) {
// map to store the export rule grouped by sec flavor
Map<String, ExportRule> exportRuleMap = new HashMap<>();
List<VNXeNfsShare> exportsList = new ArrayList<VNXeNfsShare>();
Set<String> arrayReadOnlyHost = new HashSet<>();
Set<String> arrayReadWriteHost = new HashSet<>();
Set<String> arrayRootHost = new HashSet<>();
Set<String> dbReadOnlyHost = new HashSet<>();
Set<String> dbReadWriteHost = new HashSet<>();
Set<String> dbRootHost = new HashSet<>();
// get all export rule from CoprHD data base
List<ExportRule> existingDBExportRules = args.getExistingDBExportRules();
// get the all the export from the storage system.
VNXeApiClient apiClient = getVnxUnityClient(storage);
for (ExportRule exportRule : existingDBExportRules) {
if (exportRule.getReadOnlyHosts() != null) {
dbReadOnlyHost.addAll(exportRule.getReadOnlyHosts());
}
if (exportRule.getReadWriteHosts() != null) {
dbReadWriteHost.addAll(exportRule.getReadWriteHosts());
}
if (exportRule.getRootHosts() != null) {
dbRootHost.addAll(exportRule.getRootHosts());
}
String vnxeExportId = exportRule.getDeviceExportId();
if (vnxeExportId != null) {
List<VNXeNfsShare> vnxeExports = null;
vnxeExports = apiClient.getNfsSharesForFileSystem(args.getFs().getNativeId());
exportsList.addAll(vnxeExports);
for (VNXeNfsShare vnXeNfsShare : vnxeExports) {
List<VNXeBase> hostIdReadOnly = vnXeNfsShare.getReadOnlyHosts();
for (VNXeBase vnXeBase : hostIdReadOnly) {
VNXeHost host = apiClient.getHostById(vnXeBase.getId());
arrayReadOnlyHost.add(host.getName());
}
List<VNXeBase> hostIdReadWrite = vnXeNfsShare.getReadWriteHosts();
for (VNXeBase vnXeBase : hostIdReadWrite) {
VNXeHost host = apiClient.getHostById(vnXeBase.getId());
arrayReadWriteHost.add(host.getName());
}
List<VNXeBase> hostIdRootHost = vnXeNfsShare.getRootAccessHosts();
for (VNXeBase vnXeBase : hostIdRootHost) {
VNXeHost host = apiClient.getHostById(vnXeBase.getId());
arrayRootHost.add(host.getName());
}
}
}
// find out the change between array and CoprHD database.
Set<String> arrayExtraReadOnlyHost = Sets.difference(arrayReadOnlyHost, dbReadOnlyHost);
Set<String> arrayExtraReadWriteHost = Sets.difference(arrayReadWriteHost, dbReadWriteHost);
Set<String> arrayExtraRootHost = Sets.difference(arrayRootHost, dbRootHost);
// if change found update the exportRuleMap
if (!arrayExtraReadOnlyHost.isEmpty() || !arrayExtraReadWriteHost.isEmpty() || !arrayExtraRootHost.isEmpty()) {
ExportRule extraRuleFromArray = new ExportRule();
extraRuleFromArray.setDeviceExportId(exportRule.getDeviceExportId());
extraRuleFromArray.setAnon(exportRule.getAnon());
extraRuleFromArray.setSecFlavor(exportRule.getSecFlavor());
extraRuleFromArray.setExportPath(exportRule.getExportPath());
extraRuleFromArray.setReadOnlyHosts(arrayExtraReadOnlyHost);
extraRuleFromArray.setReadWriteHosts(arrayExtraReadWriteHost);
extraRuleFromArray.setRootHosts(arrayExtraRootHost);
exportRuleMap.put(exportRule.getSecFlavor(), extraRuleFromArray);
}
}
return exportRuleMap;
}
use of com.emc.storageos.vnxe.models.VNXeBase in project coprhd-controller by CoprHD.
the class FileSystemSnapRequestsTest method createFileSystemSnap.
// @Test
public void createFileSystemSnap() {
FileSystemSnapCreateParam parm = new FileSystemSnapCreateParam();
VNXeBase resource = new VNXeBase();
resource.setId("res_12");
parm.setStorageResource(resource);
parm.setName("test-snap");
parm.setIsReadOnly(false);
FileSystemSnapRequests req = new FileSystemSnapRequests(_client);
VNXeCommandJob response = null;
try {
response = req.createFileSystemSnap(parm);
} catch (VNXeException e) {
// TODO Auto-generated catch block
logger.error("VNXeException occured", e);
}
System.out.println(response.getId() + "state: " + response.getState());
}
use of com.emc.storageos.vnxe.models.VNXeBase in project coprhd-controller by CoprHD.
the class HostIpPortRequestsTest method createHostIpPortTest.
@Test
public void createHostIpPortTest() {
HostIpPortRequests req = new HostIpPortRequests(_client);
HostIpPortCreateParam parm = new HostIpPortCreateParam();
parm.setAddress("10.247.87.208");
VNXeBase host = new VNXeBase();
host.setId("Host_1");
parm.setHost(host);
VNXeCommandResult result = req.createHostIpPort(parm);
String id = result.getId();
System.out.println(id);
}
Aggregations