11/**
2- * Copyright (C) 2010 Cloud.com , Inc. All rights reserved.
2+ * Copyright (C) 2011 Citrix Systems , Inc. All rights reserved.
33 *
44 * This software is licensed under the GNU General Public License v3 or later.
55 *
1616 *
1717 */
1818
19- package com .cloud .api .commands ;
20-
19+ package com .cloud .api .commands ;
20+
2121import org .apache .log4j .Logger ;
2222
2323import com .cloud .api .ApiConstants ;
2727import com .cloud .api .Parameter ;
2828import com .cloud .api .PlugService ;
2929import com .cloud .api .ServerApiException ;
30- import com .cloud .api .response .DomainRouterResponse ;
30+ import com .cloud .api .response .SuccessResponse ;
3131import com .cloud .async .AsyncJob ;
3232import com .cloud .event .EventTypes ;
33+ import com .cloud .network .element .DhcpElementService ;
3334import com .cloud .exception .ConcurrentOperationException ;
3435import com .cloud .exception .InsufficientCapacityException ;
3536import com .cloud .exception .ResourceUnavailableException ;
36- import com .cloud .network .VirtualNetworkApplianceService ;
37- import com .cloud .network .router .VirtualRouter ;
3837import com .cloud .user .Account ;
3938import com .cloud .user .UserContext ;
4039
41-
42-
43- @ Implementation (responseObject =DomainRouterResponse .class , description ="Configures a router." )
44- public class ConfigureRouterCmd extends BaseAsyncCmd {
45- public static final Logger s_logger = Logger .getLogger (ConfigureRouterCmd .class .getName ());
46- private static final String s_name = "configurerouterresponse" ;
40+ @ Implementation (responseObject =SuccessResponse .class , description ="Configures a dhcp element." )
41+ public class ConfigureDhcpElementCmd extends BaseAsyncCmd {
42+ public static final Logger s_logger = Logger .getLogger (ConfigureDhcpElementCmd .class .getName ());
43+ private static final String s_name = "configuredhcpelementresponse" ;
4744
48- @ PlugService
49- private static VirtualNetworkApplianceService _myrouterService ;
50-
45+ @ PlugService
46+ private DhcpElementService _service ;
47+
5148 /////////////////////////////////////////////////////
5249 //////////////// API parameters /////////////////////
5350 /////////////////////////////////////////////////////
5451
55- @ Parameter (name =ApiConstants .ID , type =CommandType .LONG , required =true , description ="the ID of the router " )
52+ @ Parameter (name =ApiConstants .ID , type =CommandType .LONG , required =true , description ="the ID of the dhcp element " )
5653 private Long id ;
5754
5855 /////////////////////////////////////////////////////
@@ -68,36 +65,31 @@ public Long getId() {
6865 /////////////////////////////////////////////////////
6966
7067 @ Override
71- public String getCommandName () {
72- return s_name ;
73- }
74-
75- public static String getResultObjectName () {
76- return "router" ;
68+ public String getCommandName () {
69+ return s_name ;
70+ }
71+
72+ public static String getResultObjectName () {
73+ return "boolean" ;
7774 }
7875
7976 @ Override
8077 public long getEntityOwnerId () {
81- VirtualRouter router = _entityMgr .findById (VirtualRouter .class , getId ());
82- if (router != null ) {
83- return router .getAccountId ();
84- }
85-
86- return Account .ACCOUNT_ID_SYSTEM ; // no account info given, parent this command to SYSTEM so ERROR events are tracked
78+ return Account .ACCOUNT_ID_SYSTEM ;
8779 }
8880
8981 @ Override
9082 public String getEventType () {
91- return EventTypes .EVENT_ROUTER_START ;
83+ return EventTypes .EVENT_NETWORK_ELEMENT_CONFIGURE ;
9284 }
9385
9486 @ Override
9587 public String getEventDescription () {
96- return "configuring router : " + getId ();
88+ return "configuring dhcp element : " + getId ();
9789 }
9890
9991 public AsyncJob .Type getInstanceType () {
100- return AsyncJob .Type .DomainRouter ;
92+ return AsyncJob .Type .None ;
10193 }
10294
10395 public Long getInstanceId () {
@@ -106,15 +98,15 @@ public Long getInstanceId() {
10698
10799 @ Override
108100 public void execute () throws ConcurrentOperationException , ResourceUnavailableException , InsufficientCapacityException {
109- UserContext .current ().setEventDetails ("Router Id: " + getId ());
110- //This should call the configure API. Calling startRouter for now.
111- VirtualRouter result = _myrouterService . startRouter ( id );
112- if ( result != null ){
113- DomainRouterResponse routerResponse = _responseGenerator . createDomainRouterResponse ( result );
114- routerResponse . setResponseName ( getCommandName () );
115- this .setResponseObject (routerResponse );
101+ UserContext .current ().setEventDetails ("Dhcp element Id: " + getId ());
102+ Boolean result = _service . configure ();
103+ if ( result ){
104+ SuccessResponse response = new SuccessResponse ();
105+ response . setResponseName ( getCommandName () );
106+ response . setSuccess ( result );
107+ this .setResponseObject (response );
116108 } else {
117- throw new ServerApiException (BaseCmd .INTERNAL_ERROR , "Failed to start router " );
109+ throw new ServerApiException (BaseCmd .INTERNAL_ERROR , "Failed to configure the dhcp element " );
118110 }
119- }
120- }
111+ }
112+ }
0 commit comments