forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/cstackex 36 #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+545
−96
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0244569
CSTACKEX-36 Attach Cluster and Grant Access
d57ed07
CSTACKEX-36 Added TODOs
256827c
CSTACKEX-36 Correct the logger
a3a147d
CSTACKEX-36 Fix Check Styling issue
def2cff
CSTACKEX-36 Revoke Access
da8a7f2
CSTACKEX-36 Revoke Access
4f6092f
CSTACKEX-36 Resolved Review Comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,8 +25,11 @@ | |
| import com.cloud.exception.InvalidParameterValueException; | ||
| import com.cloud.host.Host; | ||
| import com.cloud.storage.Storage; | ||
| import com.cloud.storage.StoragePool; | ||
| import com.cloud.storage.ScopeType; | ||
| import com.cloud.storage.VolumeVO; | ||
| import com.cloud.storage.Volume; | ||
| import com.cloud.storage.StoragePool; | ||
| import com.cloud.storage.dao.VolumeDao; | ||
| import com.cloud.utils.Pair; | ||
| import com.cloud.utils.exception.CloudRuntimeException; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo; | ||
|
|
@@ -45,6 +48,7 @@ | |
| import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; | ||
| import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; | ||
| import org.apache.cloudstack.storage.service.StorageStrategy; | ||
| import org.apache.cloudstack.storage.service.model.AccessGroup; | ||
| import org.apache.cloudstack.storage.service.model.CloudStackVolume; | ||
| import org.apache.cloudstack.storage.service.model.ProtocolType; | ||
| import org.apache.cloudstack.storage.utils.Constants; | ||
|
|
@@ -63,6 +67,7 @@ public class OntapPrimaryDatastoreDriver implements PrimaryDataStoreDriver { | |
| @Inject private Utility utils; | ||
| @Inject private StoragePoolDetailsDao storagePoolDetailsDao; | ||
| @Inject private PrimaryDataStoreDao storagePoolDao; | ||
| @Inject private VolumeDao volumeDao; | ||
| @Override | ||
| public Map<String, String> getCapabilities() { | ||
| s_logger.trace("OntapPrimaryDatastoreDriver: getCapabilities: Called"); | ||
|
|
@@ -99,10 +104,16 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet | |
| throw new InvalidParameterValueException("createAsync: callback should not be null"); | ||
| } | ||
| try { | ||
| s_logger.info("createAsync: Started for data store [{}] and data object [{}] of type [{}]", | ||
| dataStore, dataObject, dataObject.getType()); | ||
| s_logger.info("createAsync: Started for data store [{}] and data object [{}] of type [{}]", dataStore, dataObject, dataObject.getType()); | ||
|
|
||
| StoragePoolVO storagePool = storagePoolDao.findById(dataStore.getId()); | ||
| if(storagePool == null) { | ||
| s_logger.error("createCloudStackVolume : Storage Pool not found for id: " + dataStore.getId()); | ||
| throw new CloudRuntimeException("createCloudStackVolume : Storage Pool not found for id: " + dataStore.getId()); | ||
| } | ||
|
|
||
| if (dataObject.getType() == DataObjectType.VOLUME) { | ||
| path = createCloudStackVolumeForTypeVolume(dataStore, dataObject); | ||
| path = createCloudStackVolumeForTypeVolume(storagePool, dataObject); | ||
| createCmdResult = new CreateCmdResult(path, new Answer(null, true, null)); | ||
| } else { | ||
| errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to createAsync"; | ||
|
|
@@ -119,13 +130,8 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet | |
| } | ||
| } | ||
|
|
||
| private String createCloudStackVolumeForTypeVolume(DataStore dataStore, DataObject dataObject) { | ||
| StoragePoolVO storagePool = storagePoolDao.findById(dataStore.getId()); | ||
| if(storagePool == null) { | ||
| s_logger.error("createCloudStackVolume : Storage Pool not found for id: " + dataStore.getId()); | ||
| throw new CloudRuntimeException("createCloudStackVolume : Storage Pool not found for id: " + dataStore.getId()); | ||
| } | ||
| Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(dataStore.getId()); | ||
| private String createCloudStackVolumeForTypeVolume(StoragePoolVO storagePool, DataObject dataObject) { | ||
| Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(storagePool.getId()); | ||
| StorageStrategy storageStrategy = utils.getStrategyByStoragePoolDetails(details); | ||
| s_logger.info("createCloudStackVolumeForTypeVolume: Connection to Ontap SVM [{}] successful, preparing CloudStackVolumeRequest", details.get(Constants.SVM_NAME)); | ||
| CloudStackVolume cloudStackVolumeRequest = utils.createCloudStackVolumeRequestByProtocol(storagePool, details, dataObject); | ||
|
|
@@ -171,12 +177,151 @@ public ChapInfo getChapInfo(DataObject dataObject) { | |
|
|
||
| @Override | ||
| public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore) { | ||
| if (dataStore == null) { | ||
| throw new InvalidParameterValueException("grantAccess: dataStore should not be null"); | ||
| } | ||
| if (dataObject == null) { | ||
| throw new InvalidParameterValueException("grantAccess: dataObject should not be null"); | ||
| } | ||
| if (host == null) { | ||
| throw new InvalidParameterValueException("grantAccess: host should not be null"); | ||
| } | ||
| try { | ||
| StoragePoolVO storagePool = storagePoolDao.findById(dataStore.getId()); | ||
| if(storagePool == null) { | ||
| s_logger.error("grantAccess : Storage Pool not found for id: " + dataStore.getId()); | ||
| throw new CloudRuntimeException("grantAccess : Storage Pool not found for id: " + dataStore.getId()); | ||
| } | ||
| if (storagePool.getScope() != ScopeType.CLUSTER && storagePool.getScope() != ScopeType.ZONE) { | ||
| s_logger.error("grantAccess: Only Cluster and Zone scoped primary storage is supported for storage Pool: " + storagePool.getName()); | ||
| throw new CloudRuntimeException("grantAccess: Only Cluster and Zone scoped primary storage is supported for Storage Pool: " + storagePool.getName()); | ||
| } | ||
|
|
||
| if (dataObject.getType() == DataObjectType.VOLUME) { | ||
| VolumeVO volumeVO = volumeDao.findById(dataObject.getId()); | ||
| if(volumeVO == null) { | ||
| s_logger.error("grantAccess : Cloud Stack Volume not found for id: " + dataObject.getId()); | ||
| throw new CloudRuntimeException("grantAccess : Cloud Stack Volume not found for id: " + dataObject.getId()); | ||
| } | ||
| grantAccessForVolume(storagePool, volumeVO, host); | ||
| } else { | ||
| s_logger.error("Invalid DataObjectType (" + dataObject.getType() + ") passed to grantAccess"); | ||
| throw new CloudRuntimeException("Invalid DataObjectType (" + dataObject.getType() + ") passed to grantAccess"); | ||
| } | ||
| } catch(Exception e){ | ||
| s_logger.error("grantAccess: Failed for dataObject [{}]: {}", dataObject, e.getMessage()); | ||
| throw new CloudRuntimeException("grantAccess: Failed with error :" + e.getMessage()); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| private void grantAccessForVolume(StoragePoolVO storagePool, VolumeVO volumeVO, Host host) { | ||
| Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(storagePool.getId()); | ||
| StorageStrategy storageStrategy = utils.getStrategyByStoragePoolDetails(details); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this method has moved from utility class |
||
| String svmName = details.get(Constants.SVM_NAME); | ||
| long scopeId = (storagePool.getScope() == ScopeType.CLUSTER) ? host.getClusterId() : host.getDataCenterId(); | ||
|
|
||
| if(ProtocolType.ISCSI.name().equalsIgnoreCase(details.get(Constants.PROTOCOL))) { | ||
| String accessGroupName = utils.getIgroupName(svmName, scopeId); | ||
| CloudStackVolume cloudStackVolume = getCloudStackVolumeByName(storageStrategy, svmName, volumeVO.getPath()); | ||
| AccessGroup accessGroup = getAccessGroupByName(storageStrategy, svmName, accessGroupName); | ||
| if(accessGroup.getIgroup().getInitiators() == null || accessGroup.getIgroup().getInitiators().size() == 0 || !accessGroup.getIgroup().getInitiators().contains(host.getStorageUrl())) { | ||
| s_logger.error("grantAccess: initiator [{}] is not present in iGroup [{}]", host.getStorageUrl(), accessGroupName); | ||
| throw new CloudRuntimeException("grantAccess: initiator [" + host.getStorageUrl() + "] is not present in iGroup [" + accessGroupName); | ||
| } | ||
|
|
||
| Map<String, String> enableLogicalAccessMap = new HashMap<>(); | ||
| enableLogicalAccessMap.put(Constants.LUN_DOT_NAME, volumeVO.getPath()); | ||
| enableLogicalAccessMap.put(Constants.SVM_DOT_NAME, svmName); | ||
| enableLogicalAccessMap.put(Constants.IGROUP_DOT_NAME, accessGroupName); | ||
| storageStrategy.enableLogicalAccess(enableLogicalAccessMap); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore) { | ||
| if (dataStore == null) { | ||
| throw new InvalidParameterValueException("revokeAccess: data store should not be null"); | ||
| } | ||
| if (dataObject == null) { | ||
| throw new InvalidParameterValueException("revokeAccess: data object should not be null"); | ||
| } | ||
| if (host == null) { | ||
| throw new InvalidParameterValueException("revokeAccess: host should not be null"); | ||
| } | ||
| try { | ||
| StoragePoolVO storagePool = storagePoolDao.findById(dataStore.getId()); | ||
| if(storagePool == null) { | ||
| s_logger.error("revokeAccess : Storage Pool not found for id: " + dataStore.getId()); | ||
| throw new CloudRuntimeException("revokeAccess : Storage Pool not found for id: " + dataStore.getId()); | ||
| } | ||
| if (storagePool.getScope() != ScopeType.CLUSTER && storagePool.getScope() != ScopeType.ZONE) { | ||
| s_logger.error("revokeAccess: Only Cluster and Zone scoped primary storage is supported for storage Pool: " + storagePool.getName()); | ||
| throw new CloudRuntimeException("revokeAccess: Only Cluster and Zone scoped primary storage is supported for Storage Pool: " + storagePool.getName()); | ||
| } | ||
|
|
||
| if (dataObject.getType() == DataObjectType.VOLUME) { | ||
| VolumeVO volumeVO = volumeDao.findById(dataObject.getId()); | ||
| if(volumeVO == null) { | ||
| s_logger.error("revokeAccess : Cloud Stack Volume not found for id: " + dataObject.getId()); | ||
| throw new CloudRuntimeException("revokeAccess : Cloud Stack Volume not found for id: " + dataObject.getId()); | ||
| } | ||
| revokeAccessForVolume(storagePool, volumeVO, host); | ||
| } else { | ||
| s_logger.error("revokeAccess: Invalid DataObjectType (" + dataObject.getType() + ") passed to revokeAccess"); | ||
| throw new CloudRuntimeException("Invalid DataObjectType (" + dataObject.getType() + ") passed to revokeAccess"); | ||
| } | ||
| } catch(Exception e){ | ||
| s_logger.error("revokeAccess: Failed for dataObject [{}]: {}", dataObject, e.getMessage()); | ||
| throw new CloudRuntimeException("revokeAccess: Failed with error :" + e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private void revokeAccessForVolume(StoragePoolVO storagePool, VolumeVO volumeVO, Host host) { | ||
| Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(storagePool.getId()); | ||
| StorageStrategy storageStrategy = utils.getStrategyByStoragePoolDetails(details); | ||
| String svmName = details.get(Constants.SVM_NAME); | ||
| long scopeId = (storagePool.getScope() == ScopeType.CLUSTER) ? host.getClusterId() : host.getDataCenterId(); | ||
|
|
||
| if(ProtocolType.ISCSI.name().equalsIgnoreCase(details.get(Constants.PROTOCOL))) { | ||
| String accessGroupName = utils.getIgroupName(svmName, scopeId); | ||
| CloudStackVolume cloudStackVolume = getCloudStackVolumeByName(storageStrategy, svmName, volumeVO.getPath()); | ||
| AccessGroup accessGroup = getAccessGroupByName(storageStrategy, svmName, accessGroupName); | ||
| //TODO check if initiator does exits in igroup, will throw the error ? | ||
| if(!accessGroup.getIgroup().getInitiators().contains(host.getStorageUrl())) { | ||
| s_logger.error("grantAccess: initiator [{}] is not present in iGroup [{}]", host.getStorageUrl(), accessGroupName); | ||
| throw new CloudRuntimeException("grantAccess: initiator [" + host.getStorageUrl() + "] is not present in iGroup [" + accessGroupName); | ||
| } | ||
|
|
||
| Map<String, String> disableLogicalAccessMap = new HashMap<>(); | ||
| disableLogicalAccessMap.put(Constants.LUN_DOT_UUID, cloudStackVolume.getLun().getUuid().toString()); | ||
| disableLogicalAccessMap.put(Constants.IGROUP_DOT_UUID, accessGroup.getIgroup().getUuid()); | ||
| storageStrategy.disableLogicalAccess(disableLogicalAccessMap); | ||
| } | ||
| } | ||
|
|
||
| private CloudStackVolume getCloudStackVolumeByName(StorageStrategy storageStrategy, String svmName, String cloudStackVolumeName) { | ||
| Map<String, String> getCloudStackVolumeMap = new HashMap<>(); | ||
| getCloudStackVolumeMap.put(Constants.NAME, cloudStackVolumeName); | ||
| getCloudStackVolumeMap.put(Constants.SVM_DOT_NAME, svmName); | ||
| CloudStackVolume cloudStackVolume = storageStrategy.getCloudStackVolume(getCloudStackVolumeMap); | ||
| if(cloudStackVolume == null || cloudStackVolume.getLun() == null || cloudStackVolume.getLun().getName() == null) { | ||
| s_logger.error("getCloudStackVolumeByName: Failed to get LUN details [{}]", cloudStackVolumeName); | ||
| throw new CloudRuntimeException("getCloudStackVolumeByName: Failed to get LUN [" + cloudStackVolumeName + "]"); | ||
| } | ||
| return cloudStackVolume; | ||
| } | ||
|
|
||
| private AccessGroup getAccessGroupByName(StorageStrategy storageStrategy, String svmName, String accessGroupName) { | ||
| Map<String, String> getAccessGroupMap = new HashMap<>(); | ||
| getAccessGroupMap.put(Constants.NAME, accessGroupName); | ||
| getAccessGroupMap.put(Constants.SVM_DOT_NAME, svmName); | ||
| AccessGroup accessGroup = storageStrategy.getAccessGroup(getAccessGroupMap); | ||
| if (accessGroup == null || accessGroup.getIgroup() == null || accessGroup.getIgroup().getName() == null) { | ||
| s_logger.error("getAccessGroupByName: Failed to get iGroup details [{}]", accessGroupName); | ||
| throw new CloudRuntimeException("getAccessGroupByName: Failed to get iGroup details [" + accessGroupName + "]"); | ||
| } | ||
| return accessGroup; | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets take latest from Sandeep PR