diff --git a/client/tomcatconf/cisconexusvsm_commands.properties.in b/client/tomcatconf/cisconexusvsm_commands.properties.in index f6894600f09..8732357d294 100644 --- a/client/tomcatconf/cisconexusvsm_commands.properties.in +++ b/client/tomcatconf/cisconexusvsm_commands.properties.in @@ -5,5 +5,4 @@ deleteCiscoNexusVSM = com.cloud.api.commands.DeleteCiscoNexusVSMCmd;1 enableCiscoNexusVSM = com.cloud.api.commands.EnableCiscoNexusVSMCmd;1 disableCiscoNexusVSM = com.cloud.api.commands.DisableCiscoNexusVSMCmd;1 -getCiscoVSMByClusterId = com.cloud.api.commands.GetCiscoVSMByClusterIdCmd;1 -getCiscoVSMDetails = com.cloud.api.commands.GetCiscoVSMDetailsCmd;1 +listCiscoVSMDetails = com.cloud.api.commands.ListCiscoVSMDetailsCmd;1 diff --git a/server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java b/server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java index 886ef1b22d6..e684703feb7 100644 --- a/server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java +++ b/server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java @@ -31,12 +31,11 @@ import com.cloud.api.response.SuccessResponse; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.element.CiscoNexusVSMElementService; +import com.cloud.user.Account; import com.cloud.user.UserContext; -import com.cloud.utils.exception.CloudRuntimeException; @Implementation(responseObject=SuccessResponse.class, description=" delete a Cisco Nexus VSM device") public class DeleteCiscoNexusVSMCmd extends BaseAsyncCmd { @@ -67,19 +66,13 @@ public class DeleteCiscoNexusVSMCmd extends BaseAsyncCmd { @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - try { - boolean result = _ciscoNexusVSMService.deleteCiscoNexusVSM(this); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); - response.setResponseName(getCommandName()); - this.setResponseObject(response); - } else { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to delete Cisco Nexus VSM device"); - } - } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseAsyncCmd.PARAM_ERROR, invalidParamExcp.getMessage()); - } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + boolean result = _ciscoNexusVSMService.deleteCiscoNexusVSM(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to delete Cisco Nexus VSM device"); } } @@ -90,7 +83,7 @@ public class DeleteCiscoNexusVSMCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return Account.ACCOUNT_ID_SYSTEM; } @Override diff --git a/server/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java b/server/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java index bef7ef4391f..8700086094a 100644 --- a/server/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java +++ b/server/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java @@ -30,12 +30,11 @@ import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.element.CiscoNexusVSMElementService; +import com.cloud.user.Account; import com.cloud.user.UserContext; -import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.event.EventTypes; @Implementation(responseObject=SuccessResponse.class, description="disable a Cisco Nexus VSM device") @@ -67,19 +66,13 @@ public class DisableCiscoNexusVSMCmd extends BaseAsyncCmd { @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - try { - boolean result = _ciscoNexusVSMService.disableCiscoNexusVSM(this); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); - response.setResponseName(getCommandName()); - this.setResponseObject(response); - } else { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to disable Cisco Nexus VSM device"); - } - } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseAsyncCmd.PARAM_ERROR, invalidParamExcp.getMessage()); - } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + boolean result = _ciscoNexusVSMService.disableCiscoNexusVSM(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to disable Cisco Nexus VSM device"); } } @@ -90,7 +83,7 @@ public class DisableCiscoNexusVSMCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return Account.ACCOUNT_ID_SYSTEM; } @Override diff --git a/server/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java b/server/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java index 0f216d67af9..af85a860e5d 100644 --- a/server/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java +++ b/server/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java @@ -31,12 +31,11 @@ import com.cloud.api.response.SuccessResponse; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.element.CiscoNexusVSMElementService; +import com.cloud.user.Account; import com.cloud.user.UserContext; -import com.cloud.utils.exception.CloudRuntimeException; @Implementation(responseObject=SuccessResponse.class, description="Enable a Cisco Nexus VSM device") public class EnableCiscoNexusVSMCmd extends BaseAsyncCmd { @@ -67,19 +66,13 @@ public class EnableCiscoNexusVSMCmd extends BaseAsyncCmd { @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - try { - boolean result = _ciscoNexusVSMService.enableCiscoNexusVSM(this); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); - response.setResponseName(getCommandName()); - this.setResponseObject(response); - } else { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to enable Cisco Nexus VSM device"); - } - } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseAsyncCmd.PARAM_ERROR, invalidParamExcp.getMessage()); - } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + boolean result = _ciscoNexusVSMService.enableCiscoNexusVSM(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to enable Cisco Nexus VSM device"); } } @@ -90,7 +83,7 @@ public class EnableCiscoNexusVSMCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return Account.ACCOUNT_ID_SYSTEM; } @Override diff --git a/server/src/com/cloud/api/commands/GetCiscoVSMDetailsCmd.java b/server/src/com/cloud/api/commands/GetCiscoVSMDetailsCmd.java deleted file mode 100755 index 37a8892f994..00000000000 --- a/server/src/com/cloud/api/commands/GetCiscoVSMDetailsCmd.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved. - * - * This software is licensed under the GNU General Public License v3 or later. - * - * It is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package com.cloud.api.commands; - -import org.apache.log4j.Logger; -import com.cloud.api.ApiConstants; -import com.cloud.api.BaseCmd; -import com.cloud.api.IdentityMapper; -import com.cloud.api.Implementation; -import com.cloud.api.Parameter; -import com.cloud.api.PlugService; -import com.cloud.api.ServerApiException; -import com.cloud.api.response.CiscoNexusVSMResponse; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.InvalidParameterValueException; -import com.cloud.exception.ResourceAllocationException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.network.CiscoNexusVSMDeviceVO; -import com.cloud.network.element.CiscoNexusVSMElementService; -import com.cloud.user.UserContext; -import com.cloud.utils.exception.CloudRuntimeException; - -@Implementation(responseObject=CiscoNexusVSMResponse.class, description="Retrieves details of a Cisco Nexus 1000v Virtual Switch Manager ") -public class GetCiscoVSMDetailsCmd extends BaseCmd { - - public static final Logger s_logger = Logger.getLogger(GetCiscoVSMDetailsCmd.class.getName()); - private static final String s_name = "getciscovsmdetailscmdresponse"; - @PlugService CiscoNexusVSMElementService _ciscoNexusVSMService; - - ///////////////////////////////////////////////////// - //////////////// API parameters ///////////////////// - ///////////////////////////////////////////////////// - - @IdentityMapper(entityTableName="virtual_supervisor_module") - @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required = true, description="Id of the Cisco Nexus VSM appliance.") - private long id; - - ///////////////////////////////////////////////////// - /////////////////// Accessors /////////////////////// - ///////////////////////////////////////////////////// - - public long getVSMId() { - return id; - } - - ///////////////////////////////////////////////////// - /////////////// API Implementation/////////////////// - ///////////////////////////////////////////////////// - - @Override - public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - try { - CiscoNexusVSMDeviceVO vsmDeviceVO = _ciscoNexusVSMService.getCiscoNexusVSMDetails(this); - if (vsmDeviceVO != null) { - CiscoNexusVSMResponse response = _ciscoNexusVSMService.createCiscoNexusVSMDetailedResponse(vsmDeviceVO); - response.setObjectName("cisconexusvsm"); - response.setResponseName(getCommandName()); - this.setResponseObject(response); - } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to retrieve Cisco Nexus Virtual Switch Manager for the specified cluster due to an internal error."); - } - } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); - } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); - } - } - - @Override - public String getCommandName() { - return s_name; - } - - @Override - public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); - } -} diff --git a/server/src/com/cloud/api/commands/GetCiscoVSMByClusterIdCmd.java b/server/src/com/cloud/api/commands/ListCiscoVSMDetailsCmd.java similarity index 68% rename from server/src/com/cloud/api/commands/GetCiscoVSMByClusterIdCmd.java rename to server/src/com/cloud/api/commands/ListCiscoVSMDetailsCmd.java index e46cd7e451b..5a9c0498ac4 100755 --- a/server/src/com/cloud/api/commands/GetCiscoVSMByClusterIdCmd.java +++ b/server/src/com/cloud/api/commands/ListCiscoVSMDetailsCmd.java @@ -20,7 +20,6 @@ package com.cloud.api.commands; import org.apache.log4j.Logger; import com.cloud.api.ApiConstants; -import com.cloud.api.BaseAsyncCmd; import com.cloud.api.BaseCmd; import com.cloud.api.IdentityMapper; import com.cloud.api.Implementation; @@ -30,19 +29,18 @@ import com.cloud.api.ServerApiException; import com.cloud.api.response.CiscoNexusVSMResponse; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.CiscoNexusVSMDevice; import com.cloud.network.element.CiscoNexusVSMElementService; +import com.cloud.user.Account; import com.cloud.user.UserContext; -import com.cloud.utils.exception.CloudRuntimeException; @Implementation(responseObject=CiscoNexusVSMResponse.class, description="Retrieves a Cisco Nexus 1000v Virtual Switch Manager device associated with a Cluster") -public class GetCiscoVSMByClusterIdCmd extends BaseCmd { +public class ListCiscoVSMDetailsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(GetCiscoVSMByClusterIdCmd.class.getName()); - private static final String s_name = "getciscovsmbyclusteridcmdresponse"; + public static final Logger s_logger = Logger.getLogger(ListCiscoVSMDetailsCmd.class.getName()); + private static final String s_name = "listciscovsmdetailscmdresponse"; @PlugService CiscoNexusVSMElementService _ciscoNexusVSMService; ///////////////////////////////////////////////////// @@ -51,14 +49,14 @@ public class GetCiscoVSMByClusterIdCmd extends BaseCmd { @IdentityMapper(entityTableName="cluster") @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required = true, description="Id of the CloudStack cluster in which the Cisco Nexus 1000v VSM appliance.") - private long id; + private long clusterId; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// public long getClusterId() { - return id; + return clusterId; } ///////////////////////////////////////////////////// @@ -70,20 +68,14 @@ public class GetCiscoVSMByClusterIdCmd extends BaseCmd { // is invoked. That's the reason why we don't have any uuid-dbid translation code here. @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - try { - CiscoNexusVSMDevice vsmDevice = _ciscoNexusVSMService.getCiscoNexusVSMByClusId(this); - if (vsmDevice != null) { - CiscoNexusVSMResponse response = _ciscoNexusVSMService.createCiscoNexusVSMResponse(vsmDevice); - response.setObjectName("cisconexusvsm"); - response.setResponseName(getCommandName()); - this.setResponseObject(response); - } else { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to retrieve Cisco Nexus Virtual Switch Manager for the specified cluster due to an internal error."); - } - } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); - } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + CiscoNexusVSMDevice vsmDevice = _ciscoNexusVSMService.getCiscoNexusVSMByClusId(this); + if (vsmDevice != null) { + CiscoNexusVSMResponse response = _ciscoNexusVSMService.createCiscoNexusVSMDetailedResponse(vsmDevice); + response.setObjectName("cisconexusvsm"); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to retrieve Cisco Nexus Virtual Switch Manager for the specified cluster due to an internal error."); } } @@ -94,6 +86,6 @@ public class GetCiscoVSMByClusterIdCmd extends BaseCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return Account.ACCOUNT_ID_SYSTEM; } } diff --git a/server/src/com/cloud/network/element/CiscoNexusVSMElement.java b/server/src/com/cloud/network/element/CiscoNexusVSMElement.java index bc89cafaeed..0e60fdd9618 100644 --- a/server/src/com/cloud/network/element/CiscoNexusVSMElement.java +++ b/server/src/com/cloud/network/element/CiscoNexusVSMElement.java @@ -23,13 +23,14 @@ import com.cloud.agent.AgentManager; import com.cloud.api.commands.DeleteCiscoNexusVSMCmd; import com.cloud.api.commands.EnableCiscoNexusVSMCmd; import com.cloud.api.commands.DisableCiscoNexusVSMCmd; -import com.cloud.api.commands.GetCiscoVSMByClusterIdCmd; -import com.cloud.api.commands.GetCiscoVSMDetailsCmd; +import com.cloud.api.commands.ListCiscoVSMDetailsCmd; import com.cloud.api.response.CiscoNexusVSMResponse; import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.dao.DataCenterDao; import com.cloud.deploy.DeployDestination; +import com.cloud.event.ActionEvent; +import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; @@ -55,6 +56,7 @@ import com.cloud.vm.VirtualMachineProfile; import com.cloud.network.element.NetworkElement; import com.cloud.offering.NetworkOffering; import com.cloud.utils.component.Manager; +import com.cloud.utils.db.DB; import com.cloud.exception.ResourceInUseException; import com.cloud.utils.exception.CloudRuntimeException; @@ -159,7 +161,9 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme return true; } + @Override + @ActionEvent(eventType = EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DELETE, eventDescription = "deleting VSM", async = true) public boolean deleteCiscoNexusVSM(DeleteCiscoNexusVSMCmd cmd) { boolean result; try { @@ -185,18 +189,9 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme result = disableCiscoNexusVSM(cmd.getCiscoNexusVSMDeviceId()); return result; } - - @Override - public CiscoNexusVSMDeviceVO getCiscoNexusVSMDetails(GetCiscoVSMDetailsCmd cmd) { - CiscoNexusVSMDeviceVO result = getCiscoVSMbyVSMId(cmd.getVSMId()); - if (result == null) { - throw new CloudRuntimeException("Cisco VSM with specified Id found"); - } - return result; - } @Override - public CiscoNexusVSMDeviceVO getCiscoNexusVSMByClusId(GetCiscoVSMByClusterIdCmd cmd) { + public CiscoNexusVSMDeviceVO getCiscoNexusVSMByClusId(ListCiscoVSMDetailsCmd cmd) { CiscoNexusVSMDeviceVO result = getCiscoVSMbyClusId(cmd.getClusterId()); if (result == null) { throw new CloudRuntimeException("No Cisco VSM associated with specified Cluster Id"); diff --git a/server/src/com/cloud/network/element/CiscoNexusVSMElementService.java b/server/src/com/cloud/network/element/CiscoNexusVSMElementService.java index 45a6263af47..b806e7b0209 100644 --- a/server/src/com/cloud/network/element/CiscoNexusVSMElementService.java +++ b/server/src/com/cloud/network/element/CiscoNexusVSMElementService.java @@ -21,8 +21,7 @@ package com.cloud.network.element; import com.cloud.api.commands.DeleteCiscoNexusVSMCmd; import com.cloud.api.commands.EnableCiscoNexusVSMCmd; import com.cloud.api.commands.DisableCiscoNexusVSMCmd; -import com.cloud.api.commands.GetCiscoVSMByClusterIdCmd; -import com.cloud.api.commands.GetCiscoVSMDetailsCmd; +import com.cloud.api.commands.ListCiscoVSMDetailsCmd; import com.cloud.api.response.CiscoNexusVSMResponse; import com.cloud.network.CiscoNexusVSMDeviceVO; import com.cloud.network.CiscoNexusVSMDevice; @@ -52,14 +51,7 @@ public interface CiscoNexusVSMElementService extends PluggableService { * @param GetCiscoVSMByClusterIdCmd * @return CiscoNexusVSMDeviceVO */ - public CiscoNexusVSMDeviceVO getCiscoNexusVSMByClusId(GetCiscoVSMByClusterIdCmd cmd); - - /** - * - * @param GetCiscoVSMDetailsCmd - * @return CiscoNexusVSMDeviceVO - */ - public CiscoNexusVSMDeviceVO getCiscoNexusVSMDetails(GetCiscoVSMDetailsCmd cmd); + public CiscoNexusVSMDeviceVO getCiscoNexusVSMByClusId(ListCiscoVSMDetailsCmd cmd); /** * creates API response object for Cisco Nexus VSMs