1919 * under the License.
2020 */
2121
22+ import com .cloud .agent .api .Answer ;
23+ import com .cloud .agent .api .to .DataObjectType ;
2224import com .cloud .agent .api .to .DataStoreTO ;
2325import com .cloud .agent .api .to .DataTO ;
26+ import com .cloud .exception .InvalidParameterValueException ;
2427import com .cloud .host .Host ;
2528import com .cloud .storage .Storage ;
2629import com .cloud .storage .StoragePool ;
2730import com .cloud .storage .Volume ;
2831import com .cloud .utils .Pair ;
32+ import com .cloud .utils .exception .CloudRuntimeException ;
2933import org .apache .cloudstack .engine .subsystem .api .storage .ChapInfo ;
3034import org .apache .cloudstack .engine .subsystem .api .storage .CopyCommandResult ;
3135import org .apache .cloudstack .engine .subsystem .api .storage .CreateCmdResult ;
3842import org .apache .cloudstack .engine .subsystem .api .storage .VolumeInfo ;
3943import org .apache .cloudstack .framework .async .AsyncCompletionCallback ;
4044import org .apache .cloudstack .storage .command .CommandResult ;
45+ import org .apache .cloudstack .storage .datastore .db .PrimaryDataStoreDao ;
46+ import org .apache .cloudstack .storage .datastore .db .StoragePoolDetailsDao ;
47+ import org .apache .cloudstack .storage .datastore .db .StoragePoolVO ;
48+ import org .apache .cloudstack .storage .service .StorageStrategy ;
49+ import org .apache .cloudstack .storage .service .model .CloudStackVolume ;
50+ import org .apache .cloudstack .storage .service .model .ProtocolType ;
51+ import org .apache .cloudstack .storage .utils .Constants ;
52+ import org .apache .cloudstack .storage .utils .Utility ;
4153import org .apache .logging .log4j .LogManager ;
4254import org .apache .logging .log4j .Logger ;
4355
56+ import javax .inject .Inject ;
4457import java .util .HashMap ;
4558import java .util .Map ;
4659
4760public class OntapPrimaryDatastoreDriver implements PrimaryDataStoreDriver {
4861
49- private static final Logger s_logger = (Logger )LogManager .getLogger (OntapPrimaryDatastoreDriver .class );
62+ private static final Logger s_logger = LogManager .getLogger (OntapPrimaryDatastoreDriver .class );
63+
64+ @ Inject private Utility utils ;
65+ @ Inject private StoragePoolDetailsDao storagePoolDetailsDao ;
66+ @ Inject private PrimaryDataStoreDao storagePoolDao ;
5067 @ Override
5168 public Map <String , String > getCapabilities () {
5269 s_logger .trace ("OntapPrimaryDatastoreDriver: getCapabilities: Called" );
@@ -69,9 +86,58 @@ public DataStoreTO getStoreTO(DataStore store) {
6986 }
7087
7188 @ Override
72- public void createAsync (DataStore store , DataObject data , AsyncCompletionCallback <CreateCmdResult > callback ) {
89+ public void createAsync (DataStore dataStore , DataObject dataObject , AsyncCompletionCallback <CreateCmdResult > callback ) {
90+ CreateCmdResult createCmdResult = null ;
91+ String path = null ;
92+ String errMsg = null ;
93+ if (dataStore == null ) {
94+ throw new InvalidParameterValueException ("createAsync: dataStore should not be null" );
95+ }
96+ if (dataObject == null ) {
97+ throw new InvalidParameterValueException ("createAsync: dataObject should not be null" );
98+ }
99+ if (callback == null ) {
100+ throw new InvalidParameterValueException ("createAsync: callback should not be null" );
101+ }
102+ try {
103+ s_logger .info ("createAsync: Started for data store [{}] and data object [{}] of type [{}]" ,
104+ dataStore , dataObject , dataObject .getType ());
105+ if (dataObject .getType () == DataObjectType .VOLUME ) {
106+ path = createCloudStackVolumeForTypeVolume (dataStore , dataObject );
107+ createCmdResult = new CreateCmdResult (path , new Answer (null , true , null ));
108+ } else {
109+ errMsg = "Invalid DataObjectType (" + dataObject .getType () + ") passed to createAsync" ;
110+ s_logger .error (errMsg );
111+ throw new CloudRuntimeException (errMsg );
112+ }
113+ } catch (Exception e ) {
114+ errMsg = e .getMessage ();
115+ s_logger .error ("createAsync: Failed for dataObject [{}]: {}" , dataObject , errMsg );
116+ createCmdResult = new CreateCmdResult (null , new Answer (null , false , errMsg ));
117+ createCmdResult .setResult (e .toString ());
118+ } finally {
119+ callback .complete (createCmdResult );
120+ }
121+ }
73122
74- s_logger .trace ("OntapPrimaryDatastoreDriver: createAsync: Store: " +store +", data: " +data );
123+ private String createCloudStackVolumeForTypeVolume (DataStore dataStore , DataObject dataObject ) {
124+ StoragePoolVO storagePool = storagePoolDao .findById (dataStore .getId ());
125+ if (storagePool == null ) {
126+ s_logger .error ("createCloudStackVolume : Storage Pool not found for id: " + dataStore .getId ());
127+ throw new CloudRuntimeException ("createCloudStackVolume : Storage Pool not found for id: " + dataStore .getId ());
128+ }
129+ Map <String , String > details = storagePoolDetailsDao .listDetailsKeyPairs (dataStore .getId ());
130+ StorageStrategy storageStrategy = utils .getStrategyByStoragePoolDetails (details );
131+ s_logger .info ("createCloudStackVolumeForTypeVolume: Connection to Ontap SVM [{}] successful, preparing CloudStackVolumeRequest" , details .get (Constants .SVM_NAME ));
132+ CloudStackVolume cloudStackVolumeRequest = utils .createCloudStackVolumeRequestByProtocol (storagePool , details , dataObject );
133+ CloudStackVolume cloudStackVolume = storageStrategy .createCloudStackVolume (cloudStackVolumeRequest );
134+ if (ProtocolType .ISCSI .name ().equalsIgnoreCase (details .get (Constants .PROTOCOL )) && cloudStackVolume .getLun () != null && cloudStackVolume .getLun ().getName () != null ) {
135+ return cloudStackVolume .getLun ().getName ();
136+ } else {
137+ String errMsg = "createCloudStackVolumeForTypeVolume: Volume creation failed. Lun or Lun Path is null for dataObject: " + dataObject ;
138+ s_logger .error (errMsg );
139+ throw new CloudRuntimeException (errMsg );
140+ }
75141 }
76142
77143 @ Override
0 commit comments