3939import org .apache .cloudstack .engine .subsystem .api .storage .PrimaryDataStoreParameters ;
4040import org .apache .cloudstack .engine .subsystem .api .storage .ZoneScope ;
4141import org .apache .cloudstack .storage .datastore .lifecycle .BasePrimaryDataStoreLifeCycleImpl ;
42+ import org .apache .cloudstack .storage .model .OntapStorage ;
4243import org .apache .cloudstack .storage .provider .StorageProviderManager ;
44+ import org .apache .cloudstack .storage .service .StorageStrategy ;
45+ import org .apache .cloudstack .storage .utils .Constants ;
4346import org .apache .cloudstack .storage .volume .datastore .PrimaryDataStoreHelper ;
4447import org .apache .logging .log4j .LogManager ;
4548import org .apache .logging .log4j .Logger ;
@@ -64,7 +67,10 @@ public class OntapPrimaryDatastoreLifecycle extends BasePrimaryDataStoreLifeCycl
6467 */
6568 @ Override
6669 public DataStore initialize (Map <String , Object > dsInfos ) {
67- String url = dsInfos .get ("url" ).toString ();
70+ if (dsInfos == null ) {
71+ throw new CloudRuntimeException ("Datastore info map is null, cannot create primary storage" );
72+ }
73+ String url = dsInfos .get ("url" ).toString (); // TODO: Decide on whether should the customer enter just the Management LIF IP or https://ManagementLIF
6874 Long zoneId = (Long ) dsInfos .get ("zoneId" );
6975 Long podId = (Long )dsInfos .get ("podId" );
7076 Long clusterId = (Long )dsInfos .get ("clusterId" );
@@ -74,6 +80,9 @@ public DataStore initialize(Map<String, Object> dsInfos) {
7480 Boolean isTagARule = (Boolean ) dsInfos .get ("isTagARule" );
7581 String scheme = dsInfos .get ("scheme" ).toString ();
7682
83+ s_logger .info ("Creating ONTAP primary storage pool with name: " + storagePoolName + ", provider: " + providerName +
84+ ", zoneId: " + zoneId + ", podId: " + podId + ", clusterId: " + clusterId + ", protocol: " + scheme );
85+
7786 // Additional details requested for ONTAP primary storage pool creation
7887 @ SuppressWarnings ("unchecked" )
7988 Map <String , String > details = (Map <String , String >)dsInfos .get ("details" );
@@ -94,6 +103,14 @@ public DataStore initialize(Map<String, Object> dsInfos) {
94103 }
95104 }
96105
106+ if (storagePoolName == null || storagePoolName .isEmpty ()) {
107+ throw new CloudRuntimeException ("Storage pool name is null or empty, cannot create primary storage" );
108+ }
109+
110+ if (providerName == null || providerName .isEmpty ()) {
111+ throw new CloudRuntimeException ("Provider name is null or empty, cannot create primary storage" );
112+ }
113+
97114 PrimaryDataStoreParameters parameters = new PrimaryDataStoreParameters ();
98115 if (clusterId != null ) {
99116 ClusterVO clusterVO = _clusterDao .findById (clusterId );
@@ -103,24 +120,31 @@ public DataStore initialize(Map<String, Object> dsInfos) {
103120 }
104121 parameters .setHypervisorType (clusterVO .getHypervisorType ());
105122 }
106- // Validate the ONTAP details
107- StorageProviderManager storageProviderManager = new StorageProviderManager (details , scheme );
108- boolean isValid = storageProviderManager .connect (details );
109- if (isValid ) {
110- // String volumeName = storagePoolName + "_vol"; //TODO: Figure out a better naming convention
111- storageProviderManager .createVolume (storagePoolName , Integer .parseInt ((details .get ("size" )))); // TODO: size should be in bytes, so see if conversion is needed
112- } else {
113- throw new CloudRuntimeException ("ONTAP details validation failed, cannot create primary storage" );
114- }
115123
116124 // TODO: While testing need to check what does this actually do and if the fields corresponding to each protocol should also be set
117- if (scheme .equalsIgnoreCase ("nfs" )) {
125+ // TODO: scheme could be 'custom' in our case and we might have to ask 'protocol' separately to the user
126+ if (scheme .equalsIgnoreCase (Constants .NFS )) {
118127 parameters .setType (Storage .StoragePoolType .NetworkFilesystem );
119- } else if (scheme .equalsIgnoreCase ("iscsi" )) {
128+ } else if (scheme .equalsIgnoreCase (Constants . ISCSI )) {
120129 parameters .setType (Storage .StoragePoolType .Iscsi );
121130 } else {
122131 throw new CloudRuntimeException ("Unsupported protocol: " + scheme + ", cannot create primary storage" );
123132 }
133+ details .put (Constants .MANAGEMENTLIF , url );
134+ // details.put(Constants.PROTOCOL, scheme);
135+
136+ // Validate the ONTAP details
137+ OntapStorage ontapStorage = new OntapStorage (details .get (Constants .USERNAME ), details .get (Constants .PASSWORD ),
138+ details .get (Constants .MANAGEMENTLIF ), details .get (Constants .SVMNAME ), scheme ); //TODO: Here the passing 'scheme' might need a re-look
139+ StorageProviderManager storageProviderManager = new StorageProviderManager (ontapStorage );
140+ StorageStrategy storageStrategy = storageProviderManager .getStrategy ();
141+ boolean isValid = storageStrategy .connect ();
142+ if (isValid ) {
143+ // String volumeName = storagePoolName + "_vol"; //TODO: Figure out a better naming convention
144+ storageStrategy .createVolume (storagePoolName , Long .parseLong ((details .get ("size" )))); // TODO: size should be in bytes, so see if conversion is needed
145+ } else {
146+ throw new CloudRuntimeException ("ONTAP details validation failed, cannot create primary storage" );
147+ }
124148
125149 parameters .setTags (tags );
126150 parameters .setIsTagARule (isTagARule );
@@ -138,6 +162,7 @@ public DataStore initialize(Map<String, Object> dsInfos) {
138162
139163 @ Override
140164 public boolean attachCluster (DataStore dataStore , ClusterScope scope ) {
165+ logger .debug ("In attachCluster for ONTAP primary storage" );
141166 PrimaryDataStoreInfo primarystore = (PrimaryDataStoreInfo )dataStore ;
142167 List <HostVO > hostsToConnect = _resourceMgr .getEligibleUpAndEnabledHostsInClusterForStorageConnection (primarystore );
143168
@@ -161,12 +186,8 @@ public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo exis
161186
162187 @ Override
163188 public boolean attachZone (DataStore dataStore , ZoneScope scope , Hypervisor .HypervisorType hypervisorType ) {
164- List <HostVO > hostsToConnect = new ArrayList <>();
165- Hypervisor .HypervisorType [] hypervisorTypes = {Hypervisor .HypervisorType .XenServer , Hypervisor .HypervisorType .VMware , Hypervisor .HypervisorType .KVM };
166-
167- for (Hypervisor .HypervisorType type : hypervisorTypes ) {
168- hostsToConnect .addAll (_resourceMgr .getEligibleUpAndEnabledHostsInZoneForStorageConnection (dataStore , scope .getScopeId (), type ));
169- }
189+ logger .debug ("In attachZone for ONTAP primary storage" );
190+ List <HostVO > hostsToConnect = _resourceMgr .getEligibleUpAndEnabledHostsInZoneForStorageConnection (dataStore , scope .getScopeId (), Hypervisor .HypervisorType .KVM );
170191
171192 logger .debug (String .format ("In createPool. Attaching the pool to each of the hosts in %s." , hostsToConnect ));
172193 for (HostVO host : hostsToConnect ) {
0 commit comments