Skip to content

Commit ffaa8cc

Browse files
author
Vijayendra Bhamidipati
committed
CS-9919: Support for Nexus Swiches (Cisco Vswitches)
Description: More changes incorporating Alena's review comments: 1. Changed id to clusterId for better naming. 2. Changed the name of GetCiscoVSMByClusterIdCmd to ListCiscoVSMDetailsCmd. 3. Removed the GetCiscoVSMDetailsCmd command. 4. Removed catch{} blocks in each of the Nexus related APIs since the exceptions raised in the API implementations will be caught in the command dispatcher. 5. Added ActionEvent annotation to deleteCiscoNexusVSM() function. 6. Modified each Nexus API command's getEntityOwnerId() to return Account.ACCOUNT_ID_SYSTEM.
1 parent e724684 commit ffaa8cc

8 files changed

Lines changed: 52 additions & 190 deletions

‎client/tomcatconf/cisconexusvsm_commands.properties.in‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
deleteCiscoNexusVSM = com.cloud.api.commands.DeleteCiscoNexusVSMCmd;1
66
enableCiscoNexusVSM = com.cloud.api.commands.EnableCiscoNexusVSMCmd;1
77
disableCiscoNexusVSM = com.cloud.api.commands.DisableCiscoNexusVSMCmd;1
8-
getCiscoVSMByClusterId = com.cloud.api.commands.GetCiscoVSMByClusterIdCmd;1
9-
getCiscoVSMDetails = com.cloud.api.commands.GetCiscoVSMDetailsCmd;1
8+
listCiscoVSMDetails = com.cloud.api.commands.ListCiscoVSMDetailsCmd;1

‎server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java‎

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@
3131
import com.cloud.event.EventTypes;
3232
import com.cloud.exception.ConcurrentOperationException;
3333
import com.cloud.exception.InsufficientCapacityException;
34-
import com.cloud.exception.InvalidParameterValueException;
3534
import com.cloud.exception.ResourceAllocationException;
3635
import com.cloud.exception.ResourceUnavailableException;
3736
import com.cloud.network.element.CiscoNexusVSMElementService;
37+
import com.cloud.user.Account;
3838
import com.cloud.user.UserContext;
39-
import com.cloud.utils.exception.CloudRuntimeException;
4039

4140
@Implementation(responseObject=SuccessResponse.class, description=" delete a Cisco Nexus VSM device")
4241
public class DeleteCiscoNexusVSMCmd extends BaseAsyncCmd {
@@ -67,19 +66,13 @@ public Long getCiscoNexusVSMDeviceId() {
6766

6867
@Override
6968
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
70-
try {
71-
boolean result = _ciscoNexusVSMService.deleteCiscoNexusVSM(this);
72-
if (result) {
73-
SuccessResponse response = new SuccessResponse(getCommandName());
74-
response.setResponseName(getCommandName());
75-
this.setResponseObject(response);
76-
} else {
77-
throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to delete Cisco Nexus VSM device");
78-
}
79-
} catch (InvalidParameterValueException invalidParamExcp) {
80-
throw new ServerApiException(BaseAsyncCmd.PARAM_ERROR, invalidParamExcp.getMessage());
81-
} catch (CloudRuntimeException runtimeExcp) {
82-
throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
69+
boolean result = _ciscoNexusVSMService.deleteCiscoNexusVSM(this);
70+
if (result) {
71+
SuccessResponse response = new SuccessResponse(getCommandName());
72+
response.setResponseName(getCommandName());
73+
this.setResponseObject(response);
74+
} else {
75+
throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to delete Cisco Nexus VSM device");
8376
}
8477
}
8578

@@ -90,7 +83,7 @@ public String getCommandName() {
9083

9184
@Override
9285
public long getEntityOwnerId() {
93-
return UserContext.current().getCaller().getId();
86+
return Account.ACCOUNT_ID_SYSTEM;
9487
}
9588

9689
@Override

‎server/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java‎

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@
3030
import com.cloud.api.response.SuccessResponse;
3131
import com.cloud.exception.ConcurrentOperationException;
3232
import com.cloud.exception.InsufficientCapacityException;
33-
import com.cloud.exception.InvalidParameterValueException;
3433
import com.cloud.exception.ResourceAllocationException;
3534
import com.cloud.exception.ResourceUnavailableException;
3635
import com.cloud.network.element.CiscoNexusVSMElementService;
36+
import com.cloud.user.Account;
3737
import com.cloud.user.UserContext;
38-
import com.cloud.utils.exception.CloudRuntimeException;
3938
import com.cloud.event.EventTypes;
4039

4140
@Implementation(responseObject=SuccessResponse.class, description="disable a Cisco Nexus VSM device")
@@ -67,19 +66,13 @@ public Long getCiscoNexusVSMDeviceId() {
6766

6867
@Override
6968
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
70-
try {
71-
boolean result = _ciscoNexusVSMService.disableCiscoNexusVSM(this);
72-
if (result) {
73-
SuccessResponse response = new SuccessResponse(getCommandName());
74-
response.setResponseName(getCommandName());
75-
this.setResponseObject(response);
76-
} else {
77-
throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to disable Cisco Nexus VSM device");
78-
}
79-
} catch (InvalidParameterValueException invalidParamExcp) {
80-
throw new ServerApiException(BaseAsyncCmd.PARAM_ERROR, invalidParamExcp.getMessage());
81-
} catch (CloudRuntimeException runtimeExcp) {
82-
throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
69+
boolean result = _ciscoNexusVSMService.disableCiscoNexusVSM(this);
70+
if (result) {
71+
SuccessResponse response = new SuccessResponse(getCommandName());
72+
response.setResponseName(getCommandName());
73+
this.setResponseObject(response);
74+
} else {
75+
throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to disable Cisco Nexus VSM device");
8376
}
8477
}
8578

@@ -90,7 +83,7 @@ public String getCommandName() {
9083

9184
@Override
9285
public long getEntityOwnerId() {
93-
return UserContext.current().getCaller().getId();
86+
return Account.ACCOUNT_ID_SYSTEM;
9487
}
9588

9689
@Override

‎server/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java‎

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@
3131
import com.cloud.event.EventTypes;
3232
import com.cloud.exception.ConcurrentOperationException;
3333
import com.cloud.exception.InsufficientCapacityException;
34-
import com.cloud.exception.InvalidParameterValueException;
3534
import com.cloud.exception.ResourceAllocationException;
3635
import com.cloud.exception.ResourceUnavailableException;
3736
import com.cloud.network.element.CiscoNexusVSMElementService;
37+
import com.cloud.user.Account;
3838
import com.cloud.user.UserContext;
39-
import com.cloud.utils.exception.CloudRuntimeException;
4039

4140
@Implementation(responseObject=SuccessResponse.class, description="Enable a Cisco Nexus VSM device")
4241
public class EnableCiscoNexusVSMCmd extends BaseAsyncCmd {
@@ -67,19 +66,13 @@ public Long getCiscoNexusVSMDeviceId() {
6766

6867
@Override
6968
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
70-
try {
71-
boolean result = _ciscoNexusVSMService.enableCiscoNexusVSM(this);
72-
if (result) {
73-
SuccessResponse response = new SuccessResponse(getCommandName());
74-
response.setResponseName(getCommandName());
75-
this.setResponseObject(response);
76-
} else {
77-
throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to enable Cisco Nexus VSM device");
78-
}
79-
} catch (InvalidParameterValueException invalidParamExcp) {
80-
throw new ServerApiException(BaseAsyncCmd.PARAM_ERROR, invalidParamExcp.getMessage());
81-
} catch (CloudRuntimeException runtimeExcp) {
82-
throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
69+
boolean result = _ciscoNexusVSMService.enableCiscoNexusVSM(this);
70+
if (result) {
71+
SuccessResponse response = new SuccessResponse(getCommandName());
72+
response.setResponseName(getCommandName());
73+
this.setResponseObject(response);
74+
} else {
75+
throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to enable Cisco Nexus VSM device");
8376
}
8477
}
8578

@@ -90,7 +83,7 @@ public String getCommandName() {
9083

9184
@Override
9285
public long getEntityOwnerId() {
93-
return UserContext.current().getCaller().getId();
86+
return Account.ACCOUNT_ID_SYSTEM;
9487
}
9588

9689
@Override

‎server/src/com/cloud/api/commands/GetCiscoVSMDetailsCmd.java‎

Lines changed: 0 additions & 95 deletions
This file was deleted.

server/src/com/cloud/api/commands/GetCiscoVSMByClusterIdCmd.java renamed to server/src/com/cloud/api/commands/ListCiscoVSMDetailsCmd.java

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import org.apache.log4j.Logger;
2222
import com.cloud.api.ApiConstants;
23-
import com.cloud.api.BaseAsyncCmd;
2423
import com.cloud.api.BaseCmd;
2524
import com.cloud.api.IdentityMapper;
2625
import com.cloud.api.Implementation;
@@ -30,19 +29,18 @@
3029
import com.cloud.api.response.CiscoNexusVSMResponse;
3130
import com.cloud.exception.ConcurrentOperationException;
3231
import com.cloud.exception.InsufficientCapacityException;
33-
import com.cloud.exception.InvalidParameterValueException;
3432
import com.cloud.exception.ResourceAllocationException;
3533
import com.cloud.exception.ResourceUnavailableException;
3634
import com.cloud.network.CiscoNexusVSMDevice;
3735
import com.cloud.network.element.CiscoNexusVSMElementService;
36+
import com.cloud.user.Account;
3837
import com.cloud.user.UserContext;
39-
import com.cloud.utils.exception.CloudRuntimeException;
4038

4139
@Implementation(responseObject=CiscoNexusVSMResponse.class, description="Retrieves a Cisco Nexus 1000v Virtual Switch Manager device associated with a Cluster")
42-
public class GetCiscoVSMByClusterIdCmd extends BaseCmd {
40+
public class ListCiscoVSMDetailsCmd extends BaseCmd {
4341

44-
public static final Logger s_logger = Logger.getLogger(GetCiscoVSMByClusterIdCmd.class.getName());
45-
private static final String s_name = "getciscovsmbyclusteridcmdresponse";
42+
public static final Logger s_logger = Logger.getLogger(ListCiscoVSMDetailsCmd.class.getName());
43+
private static final String s_name = "listciscovsmdetailscmdresponse";
4644
@PlugService CiscoNexusVSMElementService _ciscoNexusVSMService;
4745

4846
/////////////////////////////////////////////////////
@@ -51,14 +49,14 @@ public class GetCiscoVSMByClusterIdCmd extends BaseCmd {
5149

5250
@IdentityMapper(entityTableName="cluster")
5351
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required = true, description="Id of the CloudStack cluster in which the Cisco Nexus 1000v VSM appliance.")
54-
private long id;
52+
private long clusterId;
5553

5654
/////////////////////////////////////////////////////
5755
/////////////////// Accessors ///////////////////////
5856
/////////////////////////////////////////////////////
5957

6058
public long getClusterId() {
61-
return id;
59+
return clusterId;
6260
}
6361

6462
/////////////////////////////////////////////////////
@@ -70,20 +68,14 @@ public long getClusterId() {
7068
// is invoked. That's the reason why we don't have any uuid-dbid translation code here.
7169
@Override
7270
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
73-
try {
74-
CiscoNexusVSMDevice vsmDevice = _ciscoNexusVSMService.getCiscoNexusVSMByClusId(this);
75-
if (vsmDevice != null) {
76-
CiscoNexusVSMResponse response = _ciscoNexusVSMService.createCiscoNexusVSMResponse(vsmDevice);
77-
response.setObjectName("cisconexusvsm");
78-
response.setResponseName(getCommandName());
79-
this.setResponseObject(response);
80-
} else {
81-
throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to retrieve Cisco Nexus Virtual Switch Manager for the specified cluster due to an internal error.");
82-
}
83-
} catch (InvalidParameterValueException invalidParamExcp) {
84-
throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
85-
} catch (CloudRuntimeException runtimeExcp) {
86-
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
71+
CiscoNexusVSMDevice vsmDevice = _ciscoNexusVSMService.getCiscoNexusVSMByClusId(this);
72+
if (vsmDevice != null) {
73+
CiscoNexusVSMResponse response = _ciscoNexusVSMService.createCiscoNexusVSMDetailedResponse(vsmDevice);
74+
response.setObjectName("cisconexusvsm");
75+
response.setResponseName(getCommandName());
76+
this.setResponseObject(response);
77+
} else {
78+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to retrieve Cisco Nexus Virtual Switch Manager for the specified cluster due to an internal error.");
8779
}
8880
}
8981

@@ -94,6 +86,6 @@ public String getCommandName() {
9486

9587
@Override
9688
public long getEntityOwnerId() {
97-
return UserContext.current().getCaller().getId();
89+
return Account.ACCOUNT_ID_SYSTEM;
9890
}
9991
}

‎server/src/com/cloud/network/element/CiscoNexusVSMElement.java‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
import com.cloud.api.commands.DeleteCiscoNexusVSMCmd;
2424
import com.cloud.api.commands.EnableCiscoNexusVSMCmd;
2525
import com.cloud.api.commands.DisableCiscoNexusVSMCmd;
26-
import com.cloud.api.commands.GetCiscoVSMByClusterIdCmd;
27-
import com.cloud.api.commands.GetCiscoVSMDetailsCmd;
26+
import com.cloud.api.commands.ListCiscoVSMDetailsCmd;
2827
import com.cloud.api.response.CiscoNexusVSMResponse;
2928
import com.cloud.configuration.ConfigurationManager;
3029
import com.cloud.configuration.dao.ConfigurationDao;
3130
import com.cloud.dc.dao.DataCenterDao;
3231
import com.cloud.deploy.DeployDestination;
32+
import com.cloud.event.ActionEvent;
33+
import com.cloud.event.EventTypes;
3334
import com.cloud.exception.ConcurrentOperationException;
3435
import com.cloud.exception.InsufficientCapacityException;
3536
import com.cloud.exception.ResourceUnavailableException;
@@ -55,6 +56,7 @@
5556
import com.cloud.network.element.NetworkElement;
5657
import com.cloud.offering.NetworkOffering;
5758
import com.cloud.utils.component.Manager;
59+
import com.cloud.utils.db.DB;
5860
import com.cloud.exception.ResourceInUseException;
5961
import com.cloud.utils.exception.CloudRuntimeException;
6062

@@ -159,7 +161,9 @@ public boolean verifyServicesCombination(List<String> services) {
159161
return true;
160162
}
161163

164+
162165
@Override
166+
@ActionEvent(eventType = EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DELETE, eventDescription = "deleting VSM", async = true)
163167
public boolean deleteCiscoNexusVSM(DeleteCiscoNexusVSMCmd cmd) {
164168
boolean result;
165169
try {
@@ -185,18 +189,9 @@ public boolean disableCiscoNexusVSM(DisableCiscoNexusVSMCmd cmd) {
185189
result = disableCiscoNexusVSM(cmd.getCiscoNexusVSMDeviceId());
186190
return result;
187191
}
188-
189-
@Override
190-
public CiscoNexusVSMDeviceVO getCiscoNexusVSMDetails(GetCiscoVSMDetailsCmd cmd) {
191-
CiscoNexusVSMDeviceVO result = getCiscoVSMbyVSMId(cmd.getVSMId());
192-
if (result == null) {
193-
throw new CloudRuntimeException("Cisco VSM with specified Id found");
194-
}
195-
return result;
196-
}
197192

198193
@Override
199-
public CiscoNexusVSMDeviceVO getCiscoNexusVSMByClusId(GetCiscoVSMByClusterIdCmd cmd) {
194+
public CiscoNexusVSMDeviceVO getCiscoNexusVSMByClusId(ListCiscoVSMDetailsCmd cmd) {
200195
CiscoNexusVSMDeviceVO result = getCiscoVSMbyClusId(cmd.getClusterId());
201196
if (result == null) {
202197
throw new CloudRuntimeException("No Cisco VSM associated with specified Cluster Id");

0 commit comments

Comments
 (0)