Skip to content

Commit 04f106a

Browse files
author
Sheng Yang
committed
NaaS: Configure commands for DhcpElement, VirtualRouterElement and RedundantVirtualRouterElement
Add configure command for these virtual router based elements. The commands should be different for different elements. The context of configuration would be added later.
1 parent 5182842 commit 04f106a

15 files changed

Lines changed: 337 additions & 54 deletions

api/src/com/cloud/api/commands/ConfigureRouterCmd.java renamed to api/src/com/cloud/api/commands/ConfigureDhcpElementCmd.java

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
*
@@ -16,8 +16,8 @@
1616
*
1717
*/
1818

19-
package com.cloud.api.commands;
20-
19+
package com.cloud.api.commands;
20+
2121
import org.apache.log4j.Logger;
2222

2323
import com.cloud.api.ApiConstants;
@@ -27,32 +27,29 @@
2727
import com.cloud.api.Parameter;
2828
import com.cloud.api.PlugService;
2929
import com.cloud.api.ServerApiException;
30-
import com.cloud.api.response.DomainRouterResponse;
30+
import com.cloud.api.response.SuccessResponse;
3131
import com.cloud.async.AsyncJob;
3232
import com.cloud.event.EventTypes;
33+
import com.cloud.network.element.DhcpElementService;
3334
import com.cloud.exception.ConcurrentOperationException;
3435
import com.cloud.exception.InsufficientCapacityException;
3536
import com.cloud.exception.ResourceUnavailableException;
36-
import com.cloud.network.VirtualNetworkApplianceService;
37-
import com.cloud.network.router.VirtualRouter;
3837
import com.cloud.user.Account;
3938
import 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+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* Copyright (C) 2011 Citrix Systems, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
package com.cloud.api.commands;
20+
21+
import org.apache.log4j.Logger;
22+
23+
import com.cloud.api.ApiConstants;
24+
import com.cloud.api.BaseAsyncCmd;
25+
import com.cloud.api.BaseCmd;
26+
import com.cloud.api.Implementation;
27+
import com.cloud.api.Parameter;
28+
import com.cloud.api.PlugService;
29+
import com.cloud.api.ServerApiException;
30+
import com.cloud.api.response.SuccessResponse;
31+
import com.cloud.network.element.RedundantVirtualRouterElementService;
32+
import com.cloud.async.AsyncJob;
33+
import com.cloud.event.EventTypes;
34+
import com.cloud.exception.ConcurrentOperationException;
35+
import com.cloud.exception.InsufficientCapacityException;
36+
import com.cloud.exception.ResourceUnavailableException;
37+
import com.cloud.user.Account;
38+
import com.cloud.user.UserContext;
39+
40+
@Implementation(responseObject=SuccessResponse.class, description="Configures a redundant virtual router element.")
41+
public class ConfigureRedundantVirtualRouterElementCmd extends BaseAsyncCmd {
42+
public static final Logger s_logger = Logger.getLogger(ConfigureRedundantVirtualRouterElementCmd.class.getName());
43+
private static final String s_name = "configureredundantvirtualrouterelementresponse";
44+
45+
@PlugService
46+
private RedundantVirtualRouterElementService _service;
47+
48+
/////////////////////////////////////////////////////
49+
//////////////// API parameters /////////////////////
50+
/////////////////////////////////////////////////////
51+
52+
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the redundant virtual router element")
53+
private Long id;
54+
55+
/////////////////////////////////////////////////////
56+
/////////////////// Accessors ///////////////////////
57+
/////////////////////////////////////////////////////
58+
59+
public Long getId() {
60+
return id;
61+
}
62+
63+
/////////////////////////////////////////////////////
64+
/////////////// API Implementation///////////////////
65+
/////////////////////////////////////////////////////
66+
67+
@Override
68+
public String getCommandName() {
69+
return s_name;
70+
}
71+
72+
public static String getResultObjectName() {
73+
return "boolean";
74+
}
75+
76+
@Override
77+
public long getEntityOwnerId() {
78+
return Account.ACCOUNT_ID_SYSTEM;
79+
}
80+
81+
@Override
82+
public String getEventType() {
83+
return EventTypes.EVENT_NETWORK_ELEMENT_CONFIGURE;
84+
}
85+
86+
@Override
87+
public String getEventDescription() {
88+
return "configuring redundant virtual router element: " + getId();
89+
}
90+
91+
public AsyncJob.Type getInstanceType() {
92+
return AsyncJob.Type.None;
93+
}
94+
95+
public Long getInstanceId() {
96+
return getId();
97+
}
98+
99+
@Override
100+
public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
101+
UserContext.current().setEventDetails("Redundant virtual router 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);
108+
} else {
109+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to configure the redundant virtual router element");
110+
}
111+
}
112+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* Copyright (C) 2011 Citrix Systems, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
package com.cloud.api.commands;
20+
21+
import org.apache.log4j.Logger;
22+
23+
import com.cloud.api.ApiConstants;
24+
import com.cloud.api.BaseAsyncCmd;
25+
import com.cloud.api.BaseCmd;
26+
import com.cloud.api.Implementation;
27+
import com.cloud.api.Parameter;
28+
import com.cloud.api.PlugService;
29+
import com.cloud.api.ServerApiException;
30+
import com.cloud.api.response.SuccessResponse;
31+
import com.cloud.network.element.VirtualRouterElementService;
32+
import com.cloud.async.AsyncJob;
33+
import com.cloud.event.EventTypes;
34+
import com.cloud.exception.ConcurrentOperationException;
35+
import com.cloud.exception.InsufficientCapacityException;
36+
import com.cloud.exception.ResourceUnavailableException;
37+
import com.cloud.user.Account;
38+
import com.cloud.user.UserContext;
39+
40+
@Implementation(responseObject=SuccessResponse.class, description="Configures a virtual router element.")
41+
public class ConfigureVirtualRouterElementCmd extends BaseAsyncCmd {
42+
public static final Logger s_logger = Logger.getLogger(ConfigureVirtualRouterElementCmd.class.getName());
43+
private static final String s_name = "configurevirtualrouterelementresponse";
44+
45+
@PlugService
46+
private VirtualRouterElementService _service;
47+
48+
/////////////////////////////////////////////////////
49+
//////////////// API parameters /////////////////////
50+
/////////////////////////////////////////////////////
51+
52+
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the virtual router element")
53+
private Long id;
54+
55+
/////////////////////////////////////////////////////
56+
/////////////////// Accessors ///////////////////////
57+
/////////////////////////////////////////////////////
58+
59+
public Long getId() {
60+
return id;
61+
}
62+
63+
/////////////////////////////////////////////////////
64+
/////////////// API Implementation///////////////////
65+
/////////////////////////////////////////////////////
66+
67+
@Override
68+
public String getCommandName() {
69+
return s_name;
70+
}
71+
72+
public static String getResultObjectName() {
73+
return "boolean";
74+
}
75+
76+
@Override
77+
public long getEntityOwnerId() {
78+
return Account.ACCOUNT_ID_SYSTEM;
79+
}
80+
81+
@Override
82+
public String getEventType() {
83+
return EventTypes.EVENT_NETWORK_ELEMENT_CONFIGURE;
84+
}
85+
86+
@Override
87+
public String getEventDescription() {
88+
return "configuring virtual router element: " + getId();
89+
}
90+
91+
public AsyncJob.Type getInstanceType() {
92+
return AsyncJob.Type.None;
93+
}
94+
95+
public Long getInstanceId() {
96+
return getId();
97+
}
98+
99+
@Override
100+
public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
101+
UserContext.current().setEventDetails("Virtual router 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);
108+
} else {
109+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to configure the virtual router element");
110+
}
111+
}
112+
}

‎api/src/com/cloud/event/EventTypes.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,7 @@ public class EventTypes {
211211
public static final String EVENT_PROJECT_SUSPEND = "PROJECT.SUSPEND";
212212
public static final String EVENT_PROJECT_ACCOUNT_ADD = "PROJECT.ACCOUNT.ADD";
213213
public static final String EVENT_PROJECT_ACCOUNT_REMOVE = "PROJECT.ACCOUNT.REMOVE";
214+
215+
//Network as a Service
216+
public static final String EVENT_NETWORK_ELEMENT_CONFIGURE = "NETWORK.ELEMENT.CONFIGURE";
214217
}

‎api/src/com/cloud/network/VirtualNetworkApplianceService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.cloud.network.router.VirtualRouter;
2525
import com.cloud.utils.component.PluggableService;
2626

27-
public interface VirtualNetworkApplianceService extends PluggableService{
27+
public interface VirtualNetworkApplianceService {
2828
/**
2929
* Starts domain router
3030
* @param cmd the command specifying router's id
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.cloud.network.element;
2+
3+
import com.cloud.utils.component.PluggableService;
4+
5+
public interface DhcpElementService extends PluggableService{
6+
boolean configure();
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.cloud.network.element;
2+
3+
import com.cloud.utils.component.PluggableService;
4+
5+
public interface RedundantVirtualRouterElementService extends PluggableService{
6+
boolean configure();
7+
}

0 commit comments

Comments
 (0)