@@ -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
0 commit comments