Skip to content

Commit def2cff

Browse files
Gupta, SuryaGupta, Surya
authored andcommitted
CSTACKEX-36 Revoke Access
1 parent a3a147d commit def2cff

File tree

5 files changed

+105
-27
lines changed

5 files changed

+105
-27
lines changed

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java

Lines changed: 79 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -219,43 +219,100 @@ private void grantAccessForVolume(StoragePoolVO storagePool, VolumeVO volumeVO,
219219
Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(storagePool.getId());
220220
StorageStrategy storageStrategy = utils.getStrategyByStoragePoolDetails(details);
221221
String svmName = details.get(Constants.SVM_NAME);
222+
long scopeId = (storagePool.getScope() == ScopeType.CLUSTER) ? host.getClusterId() : host.getDataCenterId();
222223

223224
if(ProtocolType.ISCSI.name().equalsIgnoreCase(details.get(Constants.PROTOCOL))) {
224-
Map<String, String> getCloudStackVolumeMap = new HashMap<>();
225-
getCloudStackVolumeMap.put(Constants.NAME, volumeVO.getPath());
226-
getCloudStackVolumeMap.put(Constants.SVM_DOT_NAME, svmName);
227-
CloudStackVolume cloudStackVolume = storageStrategy.getCloudStackVolume(getCloudStackVolumeMap);
228-
if(cloudStackVolume == null ||cloudStackVolume.getLun() == null || cloudStackVolume.getLun().getName() == null) {
229-
s_logger.error("grantAccess: Failed to get LUN details [{}]", volumeVO.getName());
230-
throw new CloudRuntimeException("grantAccess: Failed to get LUN [" + volumeVO.getName() + "]");
231-
}
232-
233-
long scopeId = (storagePool.getScope() == ScopeType.CLUSTER) ? host.getClusterId() : host.getDataCenterId();
234-
String igroupName = utils.getIgroupName(svmName, scopeId);
235-
Map<String, String> getAccessGroupMap = new HashMap<>();
236-
getAccessGroupMap.put(Constants.NAME, igroupName);
237-
getAccessGroupMap.put(Constants.SVM_DOT_NAME, svmName);
238-
AccessGroup accessGroup = storageStrategy.getAccessGroup(getAccessGroupMap);
239-
if (accessGroup == null || accessGroup.getIgroup() == null || accessGroup.getIgroup().getName() == null) {
240-
s_logger.error("grantAccess: Failed to get iGroup details for host [{}]", host.getName());
241-
throw new CloudRuntimeException("grantAccess: Failed to get iGroup details for host [" + host.getName() + "]");
242-
}
225+
String accessGroupName = utils.getIgroupName(svmName, scopeId);
226+
CloudStackVolume cloudStackVolume = getCloudStackVolumeByName(storageStrategy, svmName, volumeVO.getPath());
227+
AccessGroup accessGroup = getAccessGroupByName(storageStrategy, svmName, accessGroupName);
243228
if(!accessGroup.getIgroup().getInitiators().contains(host.getStorageUrl())) {
244-
s_logger.error("grantAccess: initiator [{}] is not present in iGroup [{}]", host.getStorageUrl(), igroupName);
245-
throw new CloudRuntimeException("grantAccess: initiator [" + host.getStorageUrl() + "] is not present in iGroup [" + igroupName);
229+
s_logger.error("grantAccess: initiator [{}] is not present in iGroup [{}]", host.getStorageUrl(), accessGroupName);
230+
throw new CloudRuntimeException("grantAccess: initiator [" + host.getStorageUrl() + "] is not present in iGroup [" + accessGroupName);
246231
}
247232

248233
Map<String, String> enableLogicalAccessMap = new HashMap<>();
249234
enableLogicalAccessMap.put(Constants.LUN_DOT_NAME, volumeVO.getPath());
250235
enableLogicalAccessMap.put(Constants.SVM_DOT_NAME, svmName);
251-
enableLogicalAccessMap.put(Constants.IGROUP_DOT_NAME, igroupName);
236+
enableLogicalAccessMap.put(Constants.IGROUP_DOT_NAME, accessGroupName);
252237
storageStrategy.enableLogicalAccess(enableLogicalAccessMap);
253238
}
254239
}
255240

256241
@Override
257242
public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore) {
243+
if (dataStore == null) {
244+
throw new InvalidParameterValueException("revokeAccess: data store should not be null");
245+
}
246+
if (dataObject == null) {
247+
throw new InvalidParameterValueException("revokeAccess: data object should not be null");
248+
}
249+
if (host == null) {
250+
throw new InvalidParameterValueException("revokeAccess: host should not be null");
251+
}
252+
try {
253+
StoragePoolVO storagePool = storagePoolDao.findById(dataStore.getId());
254+
if(storagePool == null) {
255+
s_logger.error("revokeAccess : Storage Pool not found for id: " + dataStore.getId());
256+
throw new CloudRuntimeException("revokeAccess : Storage Pool not found for id: " + dataStore.getId());
257+
}
258+
259+
if (dataObject.getType() == DataObjectType.VOLUME) {
260+
VolumeVO volumeVO = volumeDao.findById(dataObject.getId());
261+
if(volumeVO == null) {
262+
s_logger.error("revokeAccess : Cloud Stack Volume not found for id: " + dataObject.getId());
263+
throw new CloudRuntimeException("revokeAccess : Cloud Stack Volume not found for id: " + dataObject.getId());
264+
}
265+
revokeAccessForVolume(storagePool, volumeVO, host);
266+
} else {
267+
s_logger.error("revokeAccess: Invalid DataObjectType (" + dataObject.getType() + ") passed to grantAccess");
268+
throw new CloudRuntimeException("Invalid DataObjectType (" + dataObject.getType() + ") passed to grantAccess");
269+
}
270+
} catch(Exception e){
271+
s_logger.error("revokeAccess: Failed for dataObject [{}]: {}", dataObject, e.getMessage());
272+
throw new CloudRuntimeException("revokeAccess: Failed with error :" + e.getMessage());
273+
}
274+
}
258275

276+
private void revokeAccessForVolume(StoragePoolVO storagePool, VolumeVO volumeVO, Host host) {
277+
Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(storagePool.getId());
278+
StorageStrategy storageStrategy = utils.getStrategyByStoragePoolDetails(details);
279+
String svmName = details.get(Constants.SVM_NAME);
280+
long scopeId = (storagePool.getScope() == ScopeType.CLUSTER) ? host.getClusterId() : host.getDataCenterId();
281+
282+
if(ProtocolType.ISCSI.name().equalsIgnoreCase(details.get(Constants.PROTOCOL))) {
283+
String accessGroupName = utils.getIgroupName(svmName, scopeId);
284+
CloudStackVolume cloudStackVolume = getCloudStackVolumeByName(storageStrategy, svmName, volumeVO.getPath());
285+
AccessGroup accessGroup = getAccessGroupByName(storageStrategy, svmName, accessGroupName);
286+
287+
Map<String, String> enableLogicalAccessMap = new HashMap<>();
288+
enableLogicalAccessMap.put(Constants.LUN_DOT_UUID, cloudStackVolume.getLun().getUuid().toString());
289+
enableLogicalAccessMap.put(Constants.IGROUP_DOT_UUID, accessGroup.getIgroup().getUuid());
290+
storageStrategy.disableLogicalAccess(enableLogicalAccessMap);
291+
}
292+
}
293+
294+
private CloudStackVolume getCloudStackVolumeByName(StorageStrategy storageStrategy, String svmName, String cloudStackVolumeName) {
295+
Map<String, String> getCloudStackVolumeMap = new HashMap<>();
296+
getCloudStackVolumeMap.put(Constants.NAME, cloudStackVolumeName);
297+
getCloudStackVolumeMap.put(Constants.SVM_DOT_NAME, svmName);
298+
CloudStackVolume cloudStackVolume = storageStrategy.getCloudStackVolume(getCloudStackVolumeMap);
299+
if(cloudStackVolume == null ||cloudStackVolume.getLun() == null || cloudStackVolume.getLun().getName() == null) {
300+
s_logger.error("revokeAccessForVolume: Failed to get LUN details [{}]", cloudStackVolumeName);
301+
throw new CloudRuntimeException("revokeAccessForVolume: Failed to get LUN [" + cloudStackVolumeName + "]");
302+
}
303+
return cloudStackVolume;
304+
}
305+
306+
private AccessGroup getAccessGroupByName(StorageStrategy storageStrategy, String svmName, String accessGroupName) {
307+
Map<String, String> getAccessGroupMap = new HashMap<>();
308+
getAccessGroupMap.put(Constants.NAME, accessGroupName);
309+
getAccessGroupMap.put(Constants.SVM_DOT_NAME, svmName);
310+
AccessGroup accessGroup = storageStrategy.getAccessGroup(getAccessGroupMap);
311+
if (accessGroup == null || accessGroup.getIgroup() == null || accessGroup.getIgroup().getName() == null) {
312+
s_logger.error("revokeAccessForVolume: Failed to get iGroup details [{}]", accessGroupName);
313+
throw new CloudRuntimeException("revokeAccessForVolume: Failed to get iGroup details [" + accessGroupName + "]");
314+
}
315+
return accessGroup;
259316
}
260317

261318
@Override

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/StorageStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,6 @@ public Volume getStorageVolume(Volume volume)
322322
* //TODO for Nvme/TCP and Nvme/FC protocols
323323
* @param values
324324
*/
325-
abstract void disableLogicalAccess(Map<String,String> values);
325+
abstract public void disableLogicalAccess(Map<String,String> values);
326326

327327
}

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedNASStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void enableLogicalAccess(Map<String, String> values) {
8282
}
8383

8484
@Override
85-
void disableLogicalAccess(Map<String, String> values) {
85+
public void disableLogicalAccess(Map<String, String> values) {
8686

8787
}
8888

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,24 @@ public void enableLogicalAccess(Map<String, String> values) {
226226
}
227227

228228
@Override
229-
void disableLogicalAccess(Map<String, String> values) {
230-
229+
public void disableLogicalAccess(Map<String, String> values) {
230+
s_logger.info("disableLogicalAccess : Deleting LunMap with values {} ", values);
231+
String lunUUID = values.get(Constants.LUN_DOT_UUID);
232+
String igroupUUID = values.get(Constants.IGROUP_DOT_UUID);
233+
if(lunUUID == null || igroupUUID == null || lunUUID.isEmpty() || igroupUUID.isEmpty()) {
234+
s_logger.error("disableLogicalAccess: LunMap deletion failed. Invalid request values: {}", values);
235+
throw new CloudRuntimeException("disableLogicalAccess : Failed to delete LunMap, invalid request");
236+
}
237+
try {
238+
// Get AuthHeader
239+
String authHeader = utils.generateAuthHeader(storage.getUsername(), storage.getPassword());
240+
// URI for Igroup delete
241+
URI url = utils.generateURI(Constants.CREATE_LUNMAP);
242+
sanFeignClient.deleteLunMap(url, authHeader, lunUUID, igroupUUID);
243+
s_logger.info("disableLogicalAccess: LunMap deleted successfully.");
244+
} catch (Exception e) {
245+
s_logger.error("Exception occurred while deleting LunMap: {}. Exception: {}", e.getMessage());
246+
throw new CloudRuntimeException("Failed to delete LunMap: " + e.getMessage());
247+
}
231248
}
232249
}

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/Constants.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ public class Constants {
3333

3434
public static final String SVM_DOT_NAME = "svm.name";
3535
public static final String LUN_DOT_NAME = "lun.name";
36+
37+
public static final String LUN_DOT_UUID = "lun.uuid";
3638
public static final String IGROUP_DOT_NAME = "igroup.name";
39+
40+
public static final String IGROUP_DOT_UUID = "igroup.uuid";
3741
public static final String NAME = "name";
3842

3943
public static final String JOB_RUNNING = "running";
@@ -45,7 +49,7 @@ public class Constants {
4549
public static final int JOB_MAX_RETRIES = 100;
4650
public static final int CREATE_VOLUME_CHECK_SLEEP_TIME = 2000;
4751

48-
public static final String PATH_SEPARATOR = "/";
52+
public static final String SLASH = "/";
4953
public static final String UNDERSCORE = "_";
5054
public static final String CS = "cs";
5155

0 commit comments

Comments
 (0)