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 .PrimaryDataStoreDao ;
45+ import org .apache .cloudstack .storage .datastore .db .StoragePoolDetailsDao ;
46+ import org .apache .cloudstack .storage .datastore .db .StoragePoolVO ;
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
48- private static final Logger s_logger = (Logger )LogManager .getLogger (OntapPrimaryDatastoreDriver .class );
61+ private static final Logger s_logger = LogManager .getLogger (OntapPrimaryDatastoreDriver .class );
62+
63+ @ Inject private Utility utils ;
64+ @ Inject private StoragePoolDetailsDao storagePoolDetailsDao ;
65+ @ Inject private PrimaryDataStoreDao storagePoolDao ;
4966 @ Override
5067 public Map <String , String > getCapabilities () {
5168 s_logger .trace ("OntapPrimaryDatastoreDriver: getCapabilities: Called" );
@@ -68,9 +85,58 @@ public DataStoreTO getStoreTO(DataStore store) {
6885 }
6986
7087 @ Override
71- public void createAsync (DataStore store , DataObject data , AsyncCompletionCallback <CreateCmdResult > callback ) {
88+ public void createAsync (DataStore dataStore , DataObject dataObject , AsyncCompletionCallback <CreateCmdResult > callback ) {
89+ CreateCmdResult createCmdResult = null ;
90+ String path = null ;
91+ String errMsg = null ;
92+ if (dataStore == null ) {
93+ throw new InvalidParameterValueException ("createAsync: dataStore should not be null" );
94+ }
95+ if (dataObject == null ) {
96+ throw new InvalidParameterValueException ("createAsync: dataObject should not be null" );
97+ }
98+ if (callback == null ) {
99+ throw new InvalidParameterValueException ("createAsync: callback should not be null" );
100+ }
101+ try {
102+ s_logger .info ("createAsync: Started for data store [{}] and data object [{}] of type [{}]" ,
103+ dataStore , dataObject , dataObject .getType ());
104+ if (dataObject .getType () == DataObjectType .VOLUME ) {
105+ path = createCloudStackVolumeForTypeVolume (dataStore , dataObject );
106+ createCmdResult = new CreateCmdResult (path , new Answer (null , true , null ));
107+ } else {
108+ errMsg = "Invalid DataObjectType (" + dataObject .getType () + ") passed to createAsync" ;
109+ s_logger .error (errMsg );
110+ throw new CloudRuntimeException (errMsg );
111+ }
112+ } catch (Exception e ) {
113+ errMsg = e .getMessage ();
114+ s_logger .error ("createAsync: Failed for dataObject [{}]: {}" , dataObject , errMsg );
115+ createCmdResult = new CreateCmdResult (null , new Answer (null , false , errMsg ));
116+ createCmdResult .setResult (e .toString ());
117+ } finally {
118+ callback .complete (createCmdResult );
119+ }
120+ }
72121
73- s_logger .trace ("OntapPrimaryDatastoreDriver: createAsync: Store: " +store +", data: " +data );
122+ private String createCloudStackVolumeForTypeVolume (DataStore dataStore , DataObject dataObject ) {
123+ StoragePoolVO storagePool = storagePoolDao .findById (dataStore .getId ());
124+ if (storagePool == null ) {
125+ s_logger .error ("createCloudStackVolume : Storage Pool not found for id: " + dataStore .getId ());
126+ throw new CloudRuntimeException ("createCloudStackVolume : Storage Pool not found for id: " + dataStore .getId ());
127+ }
128+ Map <String , String > details = storagePoolDetailsDao .listDetailsKeyPairs (dataStore .getId ());
129+ StorageStrategy storageStrategy = utils .getStrategyByStoragePoolDetails (details );
130+ s_logger .info ("createCloudStackVolumeForTypeVolume: Connection to Ontap SVM [{}] successful, preparing CloudStackVolumeRequest" , details .get (Constants .SVM_NAME ));
131+ CloudStackVolume cloudStackVolumeRequest = utils .createCloudStackVolumeRequestByProtocol (storagePool , details , dataObject );
132+ CloudStackVolume cloudStackVolume = storageStrategy .createCloudStackVolume (cloudStackVolumeRequest );
133+ if (ProtocolType .ISCSI .name ().equalsIgnoreCase (details .get (Constants .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+ }
74140 }
75141
76142 @ Override
0 commit comments