1818 */
1919package org .apache .cloudstack .storage .driver ;
2020
21+ import com .cloud .agent .api .Answer ;
22+ import com .cloud .agent .api .to .DataObjectType ;
2123import com .cloud .agent .api .to .DataStoreTO ;
2224import com .cloud .agent .api .to .DataTO ;
25+ import com .cloud .exception .InvalidParameterValueException ;
2326import com .cloud .host .Host ;
2427import com .cloud .storage .Storage ;
2528import com .cloud .storage .StoragePool ;
2629import com .cloud .storage .Volume ;
2730import com .cloud .utils .Pair ;
31+ import com .cloud .utils .exception .CloudRuntimeException ;
2832import org .apache .cloudstack .engine .subsystem .api .storage .ChapInfo ;
2933import org .apache .cloudstack .engine .subsystem .api .storage .CopyCommandResult ;
3034import org .apache .cloudstack .engine .subsystem .api .storage .CreateCmdResult ;
3741import org .apache .cloudstack .engine .subsystem .api .storage .VolumeInfo ;
3842import org .apache .cloudstack .framework .async .AsyncCompletionCallback ;
3943import org .apache .cloudstack .storage .command .CommandResult ;
44+ import org .apache .cloudstack .storage .datastore .db .StoragePoolDetailsDao ;
45+ import org .apache .cloudstack .storage .feign .model .OntapStorage ;
46+ import org .apache .cloudstack .storage .provider .StorageProviderFactory ;
47+ import org .apache .cloudstack .storage .service .StorageStrategy ;
48+ import org .apache .cloudstack .storage .service .model .CloudStackVolume ;
49+ import org .apache .cloudstack .storage .service .model .ProtocolType ;
50+ import org .apache .cloudstack .storage .utils .Constants ;
51+ import org .apache .cloudstack .storage .utils .Utility ;
4052import org .apache .logging .log4j .LogManager ;
4153import org .apache .logging .log4j .Logger ;
4254
55+ import javax .inject .Inject ;
4356import java .util .HashMap ;
4457import java .util .Map ;
4558
4659public class OntapPrimaryDatastoreDriver implements PrimaryDataStoreDriver {
4760
4861 private static final Logger s_logger = (Logger )LogManager .getLogger (OntapPrimaryDatastoreDriver .class );
62+
63+ @ Inject private Utility utils ;
64+ @ Inject private StoragePoolDetailsDao storagePoolDetailsDao ;
4965 @ Override
5066 public Map <String , String > getCapabilities () {
5167 s_logger .trace ("OntapPrimaryDatastoreDriver: getCapabilities: Called" );
@@ -68,9 +84,64 @@ public DataStoreTO getStoreTO(DataStore store) {
6884 }
6985
7086 @ Override
71- public void createAsync (DataStore store , DataObject data , AsyncCompletionCallback <CreateCmdResult > callback ) {
87+ public void createAsync (DataStore dataStore , DataObject dataObject , AsyncCompletionCallback <CreateCmdResult > callback ) {
88+ CreateCmdResult createCmdResult = null ;
89+ String path = null ;
90+ String errMsg = null ;
91+ if (dataStore == null ) {
92+ throw new InvalidParameterValueException ("createAsync: dataStore should not be null" );
93+ }
94+ if (dataObject == null ) {
95+ throw new InvalidParameterValueException ("createAsync: dataObject should not be null" );
96+ }
97+ if (callback == null ) {
98+ throw new InvalidParameterValueException ("createAsync: callback should not be null" );
99+ }
100+ try {
101+ s_logger .info ("createAsync: Volume creation starting for data store [{}] and data object [{}] of type [{}]" ,
102+ dataStore , dataObject , dataObject .getType ());
103+ if (dataObject .getType () == DataObjectType .VOLUME ) {
104+ path = createCloudStackVolumeForTypeVolume (dataStore , dataObject );
105+ createCmdResult = new CreateCmdResult (path , new Answer (null , true , null ));
106+ } else {
107+ errMsg = "Invalid DataObjectType (" + dataObject .getType () + ") passed to createAsync" ;
108+ s_logger .error (errMsg );
109+ throw new CloudRuntimeException (errMsg );
110+ }
111+ } catch (Exception e ) {
112+ errMsg = e .getMessage ();
113+ s_logger .error ("createAsync: Volume creation failed for dataObject [{}]: {}" , dataObject , errMsg );
114+ createCmdResult = new CreateCmdResult (null , new Answer (null , false , errMsg ));
115+ createCmdResult .setResult (e .toString ());
116+ } finally {
117+ callback .complete (createCmdResult );
118+ }
119+ }
72120
73- s_logger .trace ("OntapPrimaryDatastoreDriver: createAsync: Store: " +store +", data: " +data );
121+ private String createCloudStackVolumeForTypeVolume (DataStore dataStore , DataObject dataObject ) {
122+ Map <String , String > details = storagePoolDetailsDao .listDetailsKeyPairs (dataStore .getId ());
123+ String protocol = details .get (Constants .PROTOCOL );
124+ OntapStorage ontapStorage = new OntapStorage (details .get (Constants .USERNAME ), details .get (Constants .PASSWORD ),
125+ details .get (Constants .MANAGEMENT_LIF ), details .get (Constants .SVM_NAME ), ProtocolType .valueOf (protocol ),
126+ Boolean .parseBoolean (details .get (Constants .IS_DISAGGREGATED )));
127+ StorageStrategy storageStrategy = StorageProviderFactory .getStrategy (ontapStorage );
128+ boolean isValid = storageStrategy .connect ();
129+ if (isValid ) {
130+ s_logger .info ("createCloudStackVolumeForTypeVolume: Connection to Ontap SVM [{}] successful, preparing CloudStackVolumeRequest" , details .get (Constants .SVM_NAME ));
131+ CloudStackVolume cloudStackVolumeRequest = utils .createCloudStackVolumeRequestByProtocol (dataStore .getId (), details , dataObject );
132+ CloudStackVolume cloudStackVolume = storageStrategy .createCloudStackVolume (cloudStackVolumeRequest );
133+ if (ProtocolType .ISCSI .name ().equalsIgnoreCase (protocol ) && cloudStackVolume .getLun () != null && cloudStackVolume .getLun ().getName () != null ) {
134+ return cloudStackVolume .getLun ().getName ();
135+ } else {
136+ String errMsg = "createCloudStackVolumeForTypeVolume: Volume creation failed. Lun or Lun Path is null for dataObject: " + dataObject ;
137+ s_logger .error (errMsg );
138+ throw new CloudRuntimeException (errMsg );
139+ }
140+ } else {
141+ String errMsg = "createCloudStackVolumeForTypeVolume: Connection to Ontap SVM [" + details .get (Constants .SVM_NAME ) + "] failed" ;
142+ s_logger .error (errMsg );
143+ throw new CloudRuntimeException (errMsg );
144+ }
74145 }
75146
76147 @ Override
0 commit comments