3939import org .apache .cloudstack .api .response .TemplateResponse ;
4040import org .apache .cloudstack .api .response .UserVmResponse ;
4141import org .apache .cloudstack .context .CallContext ;
42- import org .apache .cloudstack .ingestion .VmIngestionService ;
42+ import org .apache .cloudstack .ingestion .VmImportService ;
4343import org .apache .log4j .Logger ;
4444
4545import com .cloud .event .EventTypes ;
5656import com .cloud .user .Account ;
5757
5858@ APICommand (name = ImportUnmanageInstanceCmd .API_NAME ,
59- description = "Import unmanaged virtual machine from a given cluster/host ." ,
59+ description = "Import unmanaged virtual machine from a given cluster." ,
6060 responseObject = UserVmResponse .class ,
6161 responseView = ResponseObject .ResponseView .Full ,
6262 requestHasSensitiveInfo = false ,
6363 responseHasSensitiveInfo = true )
6464public class ImportUnmanageInstanceCmd extends BaseAsyncCmd {
65- public static final Logger s_logger = Logger .getLogger (ImportUnmanageInstanceCmd .class . getName () );
65+ public static final Logger s_logger = Logger .getLogger (ImportUnmanageInstanceCmd .class );
6666 public static final String API_NAME = "importUnmanagedInstance" ;
6767
6868 @ Inject
69- public VmIngestionService vmIngestionService ;
69+ public VmImportService vmImportService ;
70+
71+ /////////////////////////////////////////////////////
72+ //////////////// API parameters /////////////////////
73+ /////////////////////////////////////////////////////
7074
7175 @ Parameter (name = ApiConstants .CLUSTER_ID ,
7276 type = CommandType .UUID ,
@@ -145,7 +149,11 @@ public class ImportUnmanageInstanceCmd extends BaseAsyncCmd {
145149 @ Parameter (name = ApiConstants .DETAILS ,
146150 type = CommandType .MAP ,
147151 description = "used to specify the custom parameters." )
148- private Map details ;
152+ private Map <String , String > details ;
153+
154+ /////////////////////////////////////////////////////
155+ /////////////////// Accessors ///////////////////////
156+ /////////////////////////////////////////////////////
149157
150158 public Long getClusterId () {
151159 return clusterId ;
@@ -225,7 +233,7 @@ public Map<String, Long> getDataDiskToDiskOfferingList() {
225233 return dataDiskToDiskOfferingMap ;
226234 }
227235
228- public Map getDetails () {
236+ public Map < String , String > getDetails () {
229237 Map <String , String > customParameterMap = new HashMap <String , String >();
230238 if (details != null && details .size () != 0 ) {
231239 Collection parameterCollection = details .values ();
@@ -242,18 +250,31 @@ public Map getDetails() {
242250
243251 @ Override
244252 public String getEventType () {
245- return EventTypes .EVENT_VM_INGEST ;
253+ return EventTypes .EVENT_VM_IMPORT ;
246254 }
247255
248256 @ Override
249257 public String getEventDescription () {
250258 return "Importing unmanaged VM" ;
251259 }
252260
261+ /////////////////////////////////////////////////////
262+ /////////////// API Implementation///////////////////
263+ /////////////////////////////////////////////////////
264+
265+ private void validateInput () {
266+ if (_entityMgr .findById (Cluster .class , clusterId ) == null ) {
267+ throw new InvalidParameterValueException (String .format ("Unable to find cluster with ID: %d" , clusterId ));
268+ }
269+ if (_entityMgr .findById (ServiceOffering .class , serviceOfferingId ) == null ) {
270+ throw new InvalidParameterValueException (String .format ("Unable to find service offering with ID: %d" , serviceOfferingId ));
271+ }
272+ }
273+
253274 @ Override
254275 public void execute () throws ResourceUnavailableException , InsufficientCapacityException , ServerApiException , ConcurrentOperationException , ResourceAllocationException , NetworkRuleConflictException {
255276 validateInput ();
256- UserVmResponse response = vmIngestionService .importUnmanagedInstance (this );
277+ UserVmResponse response = vmImportService .importUnmanagedInstance (this );
257278 response .setResponseName (getCommandName ());
258279 setResponseObject (response );
259280 }
@@ -276,13 +297,4 @@ public long getEntityOwnerId() {
276297 }
277298 return accountId ;
278299 }
279-
280- private void validateInput () {
281- if (_entityMgr .findById (Cluster .class , clusterId ) == null ) {
282- throw new InvalidParameterValueException (String .format ("Unable to find cluster with ID: %d" , clusterId ));
283- }
284- if (_entityMgr .findById (ServiceOffering .class , serviceOfferingId ) == null ) {
285- throw new InvalidParameterValueException (String .format ("Unable to find service offering with ID: %d" , serviceOfferingId ));
286- }
287- }
288300}
0 commit comments