2020
2121import java .util .Set ;
2222
23+ import javax .inject .Inject ;
24+
2325import org .apache .cloudstack .engine .subsystem .api .storage .CommandResult ;
2426import org .apache .cloudstack .engine .subsystem .api .storage .CopyCommandResult ;
2527import org .apache .cloudstack .engine .subsystem .api .storage .CreateCmdResult ;
2830import org .apache .cloudstack .engine .subsystem .api .storage .DataStore ;
2931import org .apache .cloudstack .engine .subsystem .api .storage .EndPoint ;
3032import org .apache .cloudstack .framework .async .AsyncCompletionCallback ;
33+ import org .apache .cloudstack .storage .command .CreateObjectAnswer ;
34+ import org .apache .cloudstack .storage .command .CreateObjectCommand ;
35+ import org .apache .cloudstack .storage .endpoint .EndPointSelector ;
3136import org .apache .cloudstack .storage .image .ImageDataStoreDriver ;
3237
3338//http-read-only based image store
3439public class DefaultImageDataStoreDriverImpl implements ImageDataStoreDriver {
35-
40+ @ Inject
41+ EndPointSelector selector ;
3642 public DefaultImageDataStoreDriverImpl () {
3743 }
3844
@@ -57,10 +63,28 @@ public Set<DataObject> listObjects(DataStore store) {
5763 public void createAsync (DataObject data ,
5864 AsyncCompletionCallback <CreateCmdResult > callback ) {
5965 //for default http data store, can create http based template/iso
60- CreateCmdResult result = new CreateCmdResult ("" );
66+ CreateCmdResult result = new CreateCmdResult ("" , null );
6167 if (!data .getUri ().startsWith ("http" )) {
6268 result .setResult ("can't register an image which is not a http link" );
6369 callback .complete (result );
70+ return ;
71+ }
72+
73+ if (data .getSize () == null && data .getType () == DataObjectType .TEMPLATE ) {
74+ //the template size is unknown during registration, need to find out the size of template
75+ EndPoint ep = selector .select (data );
76+ if (ep == null ) {
77+ result .setResult ("can't find storage client for:" + data .getId () + "," + data .getType ());
78+ callback .complete (result );
79+ return ;
80+ }
81+ CreateObjectCommand createCmd = new CreateObjectCommand (data .getUri ());
82+ CreateObjectAnswer answer = (CreateObjectAnswer )ep .sendMessage (createCmd );
83+ if (answer .getResult ()) {
84+ result = new CreateCmdResult (answer .getPath (), answer .getSize ());
85+ } else {
86+ result .setResult (answer .getDetails ());
87+ }
6488 }
6589
6690 callback .complete (result );
0 commit comments