From 98b022a4300dc81ad28033d2b7110a10b2df1e15 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Wed, 19 Dec 2012 13:09:02 -0800 Subject: [PATCH] Remove IdentityProxy from plugin response classes. Signed-off-by: Min Chen --- .../api/response/CiscoNexusVSMResponse.java | 41 ++++++------ .../cloud/network/CiscoNexusVSMDevice.java | 36 +++++----- .../cloud/network/CiscoNexusVSMDeviceVO.java | 10 +-- .../network/element/CiscoNexusVSMElement.java | 52 +++++++------- .../api/response/F5LoadBalancerResponse.java | 21 +++--- .../F5ExternalLoadBalancerElement.java | 11 ++- .../api/response/SrxFirewallResponse.java | 21 +++--- .../JuniperSRXExternalFirewallElement.java | 11 ++- .../NetscalerLoadBalancerResponse.java | 23 +++---- .../network/element/NetscalerElement.java | 16 +++-- .../api/response/NiciraNvpDeviceResponse.java | 37 +++++----- .../network/element/NiciraNvpElement.java | 67 ++++++++++--------- .../api/commands/GetUsageRecordsCmd.java | 26 +++++-- .../cloud/baremetal/DhcpServerResponse.java | 15 ++--- .../baremetal/ExternalDhcpManagerImpl.java | 40 +++++------ .../cloud/baremetal/PxeServerManagerImpl.java | 12 ++-- .../cloud/baremetal/PxeServerResponse.java | 15 ++--- .../ExternalNetworkDeviceManagerImpl.java | 16 ++++- .../network/NetworkUsageManagerImpl.java | 14 ++-- .../response/BaremetalTemplateResponse.java | 15 ++--- .../response/NwDevicePxeServerResponse.java | 35 +++++----- .../api/response/TrafficMonitorResponse.java | 49 +++++++------- .../api/response/UsageRecordResponse.java | 25 ++++--- 23 files changed, 322 insertions(+), 286 deletions(-) diff --git a/plugins/hypervisors/vmware/src/com/cloud/api/response/CiscoNexusVSMResponse.java b/plugins/hypervisors/vmware/src/com/cloud/api/response/CiscoNexusVSMResponse.java index 95f645461fa..79985daea85 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/api/response/CiscoNexusVSMResponse.java +++ b/plugins/hypervisors/vmware/src/com/cloud/api/response/CiscoNexusVSMResponse.java @@ -17,7 +17,6 @@ package com.cloud.api.response; import org.apache.cloudstack.api.ApiConstants; -import com.cloud.utils.IdentityProxy; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; import org.apache.cloudstack.api.BaseResponse; @@ -25,17 +24,17 @@ import org.apache.cloudstack.api.BaseResponse; public class CiscoNexusVSMResponse extends BaseResponse { @SerializedName(ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_ID) @Param(description="device id of the Cisco N1KV VSM device") - private IdentityProxy id = new IdentityProxy("virtual_supervisor_module"); - + private String id; + @SerializedName(ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_NAME) @Param(description="device name") private String deviceName; - + @SerializedName(ApiConstants.IP_ADDRESS) @Param(description="the management IP address of the external Cisco Nexus 1000v Virtual Supervisor Module") private String vsmmgmtIpAddress; - + @SerializedName(ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_STATE) @Param(description="device state") private String deviceState; - + @SerializedName(ApiConstants.VSM_MGMT_VLAN_ID) @Param(description="management vlan id of the VSM") private String vsmmgmtvlanid; @@ -47,22 +46,22 @@ public class CiscoNexusVSMResponse extends BaseResponse { @SerializedName(ApiConstants.VSM_STORAGE_VLAN_ID) @Param(description="storage vlan id of the VSM") private int vsmstoragevlanid; - + @SerializedName(ApiConstants.VSM_DOMAIN_ID) @Param(description="The VSM is a switch supervisor. This is the VSM's switch domain id") private String vsmdomainid; - + @SerializedName(ApiConstants.VSM_CONFIG_MODE) @Param(description="The mode of the VSM (standalone/HA)") private String vsmconfigmode; - + @SerializedName(ApiConstants.VSM_CONFIG_STATE) @Param(description="The Config State (Primary/Standby) of the VSM") private String vsmconfigstate; - + @SerializedName(ApiConstants.VSM_DEVICE_STATE) @Param(description="The Device State (Enabled/Disabled) of the VSM") private String vsmdevicestate; // Setter methods. - public void setId(long vsmDeviceId) { - this.id.setValue(vsmDeviceId); + public void setId(String vsmDeviceId) { + this.id = vsmDeviceId; } public void setDeviceName(String deviceName) { @@ -72,39 +71,39 @@ public class CiscoNexusVSMResponse extends BaseResponse { public void setMgmtIpAddress(String ipAddress) { this.vsmmgmtIpAddress = ipAddress; } - + public void setDeviceState(String deviceState) { this.deviceState = deviceState; } - + public void setVSMMgmtVlanId(String vlanId) { this.vsmmgmtvlanid = vlanId; } - + public void setVSMCtrlVlanId(int vlanId) { this.vsmctrlvlanid = vlanId; } - + public void setVSMPktVlanId(int vlanId) { this.vsmpktvlanid = vlanId; } - + public void setVSMStorageVlanId(int vlanId) { this.vsmstoragevlanid = vlanId; } - + public void setVSMDomainId(String domId) { this.vsmdomainid = domId; } - + public void setVSMConfigMode(String configMode) { this.vsmconfigmode = configMode; } - + public void setVSMConfigState(String configState) { this.vsmconfigstate = configState; } - + public void setVSMDeviceState(String devState) { this.vsmdevicestate = devState; } diff --git a/plugins/hypervisors/vmware/src/com/cloud/network/CiscoNexusVSMDevice.java b/plugins/hypervisors/vmware/src/com/cloud/network/CiscoNexusVSMDevice.java index c58a6a77a77..8fc68d167e5 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/network/CiscoNexusVSMDevice.java +++ b/plugins/hypervisors/vmware/src/com/cloud/network/CiscoNexusVSMDevice.java @@ -17,22 +17,22 @@ package com.cloud.network; public interface CiscoNexusVSMDevice { - + // This tells us whether the VSM is currently enabled or disabled. We may // need this if we would like to carry out any sort of maintenance on the // VSM or CS. public enum VSMDeviceState { Enabled, Disabled - } - + } + // This tells us whether the VSM is currently configured with a standby (HA) // or does not have any standby (Standalone). public enum VSMConfigMode { Standalone, HA } - + // This tells us whether the VSM is currently a primary or a standby VSM. public enum VSMConfigState { Primary, @@ -40,33 +40,35 @@ public interface CiscoNexusVSMDevice { } long getId(); - + + String getUuid(); + public String getvsmName(); - + public long getHostId(); - + public String getUserName(); - + public String getPassword(); public String getipaddr(); - + public int getManagementVlan(); - + public int getControlVlan(); - + public int getPacketVlan(); public int getStorageVlan(); - + public long getvsmDomainId(); - + public VSMConfigMode getvsmConfigMode(); - + public VSMConfigState getvsmConfigState(); - + public VSMDeviceState getvsmDeviceState(); - + public String getUuid(); - + } diff --git a/plugins/hypervisors/vmware/src/com/cloud/network/CiscoNexusVSMDeviceVO.java b/plugins/hypervisors/vmware/src/com/cloud/network/CiscoNexusVSMDeviceVO.java index 81dc277f1bf..48a388980f8 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/network/CiscoNexusVSMDeviceVO.java +++ b/plugins/hypervisors/vmware/src/com/cloud/network/CiscoNexusVSMDeviceVO.java @@ -37,7 +37,7 @@ import com.cloud.utils.db.Encrypt; @Entity @Table(name="virtual_supervisor_module") -public class CiscoNexusVSMDeviceVO implements CiscoNexusVSMDevice, Identity{ +public class CiscoNexusVSMDeviceVO implements CiscoNexusVSMDevice{ // We need to know what properties a VSM has. Put them here. @@ -133,7 +133,7 @@ public class CiscoNexusVSMDeviceVO implements CiscoNexusVSMDevice, Identity{ @Override public int getPacketVlan() { return packetVlan; - } + } @Override public int getStorageVlan() { @@ -197,7 +197,7 @@ public class CiscoNexusVSMDeviceVO implements CiscoNexusVSMDevice, Identity{ public void setPacketVlan(int vlan) { this.packetVlan = vlan; - } + } public void setStorageVlan(int vlan) { this.storageVlan = vlan; @@ -222,7 +222,7 @@ public class CiscoNexusVSMDeviceVO implements CiscoNexusVSMDevice, Identity{ // Constructors. - public CiscoNexusVSMDeviceVO(String vsmIpAddr, String username, String password) { + public CiscoNexusVSMDeviceVO(String vsmIpAddr, String username, String password) { // Set all the VSM's properties here. this.uuid = UUID.randomUUID().toString(); this.setMgmtIpAddr(vsmIpAddr); @@ -234,5 +234,5 @@ public class CiscoNexusVSMDeviceVO implements CiscoNexusVSMDevice, Identity{ public CiscoNexusVSMDeviceVO() { this.uuid = UUID.randomUUID().toString(); - } + } } diff --git a/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java b/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java index 78c704451fc..b9567dc8475 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java +++ b/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java @@ -64,18 +64,18 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme private static final Logger s_logger = Logger.getLogger(CiscoNexusVSMElement.class); @Inject - CiscoNexusVSMDeviceDao _vsmDao; + CiscoNexusVSMDeviceDao _vsmDao; @Override public Map> getCapabilities() { return null; } - + @Override public Provider getProvider() { return null; } - + @Override public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) @@ -83,7 +83,7 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme InsufficientCapacityException { return true; } - + @Override public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, @@ -92,7 +92,7 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme InsufficientCapacityException { return true; } - + @Override public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, @@ -100,7 +100,7 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme ResourceUnavailableException { return true; } - + @Override public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, @@ -113,7 +113,7 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme throws ConcurrentOperationException, ResourceUnavailableException { return true; } - + @Override public boolean isReady(PhysicalNetworkServiceProvider provider) { return true; @@ -125,19 +125,19 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme ResourceUnavailableException { return true; } - + @Override public boolean canEnableIndividualServices() { return true; } - + @Override public boolean verifyServicesCombination(Set services) { return true; } @Override - @ActionEvent(eventType = EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DELETE, eventDescription = "deleting VSM", async = true) + @ActionEvent(eventType = EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DELETE, eventDescription = "deleting VSM", async = true) public boolean deleteCiscoNexusVSM(DeleteCiscoNexusVSMCmd cmd) { boolean result; try { @@ -148,16 +148,16 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme throw new CloudRuntimeException("Failed to delete specified VSM"); } return result; - } + } @Override - @ActionEvent(eventType = EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_ENABLE, eventDescription = "deleting VSM", async = true) + @ActionEvent(eventType = EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_ENABLE, eventDescription = "deleting VSM", async = true) public CiscoNexusVSMDeviceVO enableCiscoNexusVSM(EnableCiscoNexusVSMCmd cmd) { CiscoNexusVSMDeviceVO result; result = enableCiscoNexusVSM(cmd.getCiscoNexusVSMDeviceId()); return result; } - + @Override @ActionEvent(eventType = EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DISABLE, eventDescription = "deleting VSM", async = true) public CiscoNexusVSMDeviceVO disableCiscoNexusVSM(DisableCiscoNexusVSMCmd cmd) { @@ -165,16 +165,16 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme result = disableCiscoNexusVSM(cmd.getCiscoNexusVSMDeviceId()); return result; } - + @Override public List getCiscoNexusVSMs(ListCiscoNexusVSMsCmd cmd) { // If clusterId is defined, then it takes precedence, and we will return - // the VSM associated with this cluster. + // the VSM associated with this cluster. Long clusterId = cmd.getClusterId(); Long zoneId = cmd.getZoneId(); List result = new ArrayList(); - if (clusterId != null && clusterId.longValue() != 0) { + if (clusterId != null && clusterId.longValue() != 0) { // Find the VSM associated with this clusterId and return a list. CiscoNexusVSMDeviceVO vsm = getCiscoVSMbyClusId(cmd.getClusterId()); if (vsm == null) { @@ -183,13 +183,13 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme // Else, add it to a list and return the list. result.add(vsm); return result; - } + } // Else if there is only a zoneId defined, get a list of all vmware clusters // in the zone, and then for each cluster, pull the VSM and prepare a list. if (zoneId != null && zoneId.longValue() != 0) { - ManagementService ref = cmd.getMgmtServiceRef(); + ManagementService ref = cmd.getMgmtServiceRef(); List clusterList = ref.searchForClusters(zoneId, cmd.getStartIndex(), cmd.getPageSizeVal(), "VMware"); - + if (clusterList.size() == 0) { throw new CloudRuntimeException("No VMWare clusters found in the specified zone!"); } @@ -201,27 +201,27 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme } return result; } - + // If neither is defined, we will simply return the entire list of VSMs // configured in the management server. // TODO: Is this a safe thing to do? Only ROOT admin can invoke this call. - result = _vsmDao.listAllVSMs(); + result = _vsmDao.listAllVSMs(); return result; } - + @Override public CiscoNexusVSMResponse createCiscoNexusVSMResponse(CiscoNexusVSMDevice vsmDeviceVO) { CiscoNexusVSMResponse response = new CiscoNexusVSMResponse(); - response.setId(vsmDeviceVO.getId()); + response.setId(vsmDeviceVO.getUuid()); response.setMgmtIpAddress(vsmDeviceVO.getipaddr()); return response; } - + public CiscoNexusVSMResponse createCiscoNexusVSMDetailedResponse(CiscoNexusVSMDevice vsmDeviceVO) { CiscoNexusVSMResponse response = new CiscoNexusVSMResponse(); - response.setId(vsmDeviceVO.getId()); + response.setId(vsmDeviceVO.getUuid()); response.setDeviceName(vsmDeviceVO.getvsmName()); - response.setDeviceState(vsmDeviceVO.getvsmDeviceState().toString()); + response.setDeviceState(vsmDeviceVO.getvsmDeviceState().toString()); response.setMgmtIpAddress(vsmDeviceVO.getipaddr()); // The following values can be null, so check for that. if(vsmDeviceVO.getvsmConfigMode() != null) diff --git a/plugins/network-elements/f5/src/com/cloud/api/response/F5LoadBalancerResponse.java b/plugins/network-elements/f5/src/com/cloud/api/response/F5LoadBalancerResponse.java index 07be630e783..a6d540fd67d 100644 --- a/plugins/network-elements/f5/src/com/cloud/api/response/F5LoadBalancerResponse.java +++ b/plugins/network-elements/f5/src/com/cloud/api/response/F5LoadBalancerResponse.java @@ -17,24 +17,23 @@ package com.cloud.api.response; import org.apache.cloudstack.api.ApiConstants; -import com.cloud.utils.IdentityProxy; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; import org.apache.cloudstack.api.BaseResponse; public class F5LoadBalancerResponse extends BaseResponse { @SerializedName(ApiConstants.LOAD_BALANCER_DEVICE_ID) @Param(description="device id of the F5 load balancer") - private IdentityProxy id = new IdentityProxy("external_load_balancer_devices"); + private String id; @SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network to which this F5 device belongs to") - private IdentityProxy physicalNetworkId = new IdentityProxy("physical_network"); + private String physicalNetworkId; @SerializedName(ApiConstants.PROVIDER) @Param(description="name of the provider") private String providerName; - + @SerializedName(ApiConstants.LOAD_BALANCER_DEVICE_NAME) @Param(description="device name") - private String deviceName; - + private String deviceName; + @SerializedName(ApiConstants.LOAD_BALANCER_DEVICE_STATE) @Param(description="device state") private String deviceState; @@ -49,19 +48,19 @@ public class F5LoadBalancerResponse extends BaseResponse { @SerializedName(ApiConstants.PUBLIC_INTERFACE) @Param(description="the public interface of the load balancer") private String publicInterface; - + @SerializedName(ApiConstants.PRIVATE_INTERFACE) @Param(description="the private interface of the load balancer") private String privateInterface; @SerializedName(ApiConstants.IP_ADDRESS) @Param(description="the management IP address of the external load balancer") private String ipAddress; - public void setId(long lbDeviceId) { - this.id.setValue(lbDeviceId); + public void setId(String lbDeviceId) { + this.id = lbDeviceId; } - public void setPhysicalNetworkId(long physicalNetworkId) { - this.physicalNetworkId.setValue(physicalNetworkId); + public void setPhysicalNetworkId(String physicalNetworkId) { + this.physicalNetworkId = physicalNetworkId; } public void setProvider(String provider) { diff --git a/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java b/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java index 5710e606508..dfa2c9890d6 100644 --- a/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java +++ b/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java @@ -11,7 +11,7 @@ // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the +// KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.network.element; @@ -26,6 +26,7 @@ import javax.ejb.Local; import org.apache.log4j.Logger; +import com.cloud.api.ApiDBUtils; import com.cloud.api.commands.AddExternalLoadBalancerCmd; import com.cloud.api.commands.AddF5LoadBalancerCmd; import com.cloud.api.commands.ConfigureF5LoadBalancerCmd; @@ -64,6 +65,7 @@ import com.cloud.network.NetworkExternalLoadBalancerVO; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.TrafficType; +import com.cloud.network.PhysicalNetwork; import com.cloud.network.PhysicalNetworkServiceProvider; import com.cloud.network.PhysicalNetworkVO; import com.cloud.network.PublicIpAddress; @@ -436,9 +438,12 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan Host lbHost = _hostDao.findById(lbDeviceVO.getHostId()); Map lbDetails = _detailsDao.findDetails(lbDeviceVO.getHostId()); - response.setId(lbDeviceVO.getId()); + response.setId(lbDeviceVO.getUuid()); response.setIpAddress(lbHost.getPrivateIpAddress()); - response.setPhysicalNetworkId(lbDeviceVO.getPhysicalNetworkId()); + PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(lbDeviceVO.getPhysicalNetworkId()); + if (pnw != null) { + response.setPhysicalNetworkId(pnw.getUuid()); + } response.setPublicInterface(lbDetails.get("publicInterface")); response.setPrivateInterface(lbDetails.get("privateInterface")); response.setDeviceName(lbDeviceVO.getDeviceName()); diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/response/SrxFirewallResponse.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/response/SrxFirewallResponse.java index 8ad8597cff5..8ac488f0da0 100644 --- a/plugins/network-elements/juniper-srx/src/com/cloud/api/response/SrxFirewallResponse.java +++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/response/SrxFirewallResponse.java @@ -17,7 +17,6 @@ package com.cloud.api.response; import org.apache.cloudstack.api.ApiConstants; -import com.cloud.utils.IdentityProxy; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; import org.apache.cloudstack.api.BaseResponse; @@ -26,17 +25,17 @@ import org.apache.cloudstack.api.BaseResponse; public class SrxFirewallResponse extends BaseResponse { @SerializedName(ApiConstants.FIREWALL_DEVICE_ID) @Param(description="device id of the SRX firewall") - private IdentityProxy id = new IdentityProxy("external_firewall_devices"); + private String id; @SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network to which this SRX firewall belongs to") - private IdentityProxy physicalNetworkId = new IdentityProxy("physical_network"); + private String physicalNetworkId; @SerializedName(ApiConstants.PROVIDER) @Param(description="name of the provider") private String providerName; - + @SerializedName(ApiConstants.FIREWALL_DEVICE_NAME) @Param(description="device name") - private String deviceName; - + private String deviceName; + @SerializedName(ApiConstants.FIREWALL_DEVICE_STATE) @Param(description="device state") private String deviceState; @@ -44,7 +43,7 @@ public class SrxFirewallResponse extends BaseResponse { private Long deviceCapacity; @SerializedName(ApiConstants.ZONE_ID) @Param(description="the zone ID of the external firewall") - private IdentityProxy zoneId = new IdentityProxy("data_center"); + private String zoneId; @SerializedName(ApiConstants.IP_ADDRESS) @Param(description="the management IP address of the external firewall") private String ipAddress; @@ -73,12 +72,12 @@ public class SrxFirewallResponse extends BaseResponse { @SerializedName(ApiConstants.TIMEOUT) @Param(description="the timeout (in seconds) for requests to the external firewall") private String timeout; - public void setId(long lbDeviceId) { - this.id.setValue(lbDeviceId); + public void setId(String lbDeviceId) { + this.id = lbDeviceId; } - public void setPhysicalNetworkId(long physicalNetworkId) { - this.physicalNetworkId.setValue(physicalNetworkId); + public void setPhysicalNetworkId(String physicalNetworkId) { + this.physicalNetworkId = physicalNetworkId; } public void setProvider(String provider) { diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java b/plugins/network-elements/juniper-srx/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java index d3353af449d..d9f6ce559bd 100644 --- a/plugins/network-elements/juniper-srx/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java +++ b/plugins/network-elements/juniper-srx/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java @@ -11,7 +11,7 @@ // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the +// KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.network.element; @@ -26,6 +26,7 @@ import javax.ejb.Local; import org.apache.log4j.Logger; +import com.cloud.api.ApiDBUtils; import com.cloud.api.commands.AddExternalFirewallCmd; import com.cloud.api.commands.AddSrxFirewallCmd; import com.cloud.api.commands.ConfigureSrxFirewallCmd; @@ -63,6 +64,7 @@ import com.cloud.network.Network.Service; import com.cloud.network.NetworkExternalFirewallVO; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; +import com.cloud.network.PhysicalNetwork; import com.cloud.network.PhysicalNetworkServiceProvider; import com.cloud.network.PhysicalNetworkVO; import com.cloud.network.PublicIpAddress; @@ -508,8 +510,11 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan Map fwDetails = _hostDetailDao.findDetails(fwDeviceVO.getHostId()); Host fwHost = _hostDao.findById(fwDeviceVO.getHostId()); - response.setId(fwDeviceVO.getId()); - response.setPhysicalNetworkId(fwDeviceVO.getPhysicalNetworkId()); + response.setId(fwDeviceVO.getUuid()); + PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(fwDeviceVO.getPhysicalNetworkId()); + if (pnw != null) { + response.setPhysicalNetworkId(pnw.getUuid()); + } response.setDeviceName(fwDeviceVO.getDeviceName()); if (fwDeviceVO.getCapacity() == 0) { long defaultFwCapacity = NumbersUtil.parseLong(_configDao.getValue(Config.DefaultExternalFirewallCapacity.key()), 50); diff --git a/plugins/network-elements/netscaler/src/com/cloud/api/response/NetscalerLoadBalancerResponse.java b/plugins/network-elements/netscaler/src/com/cloud/api/response/NetscalerLoadBalancerResponse.java index 290018c3c28..2983da26811 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/api/response/NetscalerLoadBalancerResponse.java +++ b/plugins/network-elements/netscaler/src/com/cloud/api/response/NetscalerLoadBalancerResponse.java @@ -19,7 +19,6 @@ package com.cloud.api.response; import java.util.List; import org.apache.cloudstack.api.ApiConstants; -import com.cloud.utils.IdentityProxy; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; import org.apache.cloudstack.api.BaseResponse; @@ -28,17 +27,17 @@ import org.apache.cloudstack.api.BaseResponse; public class NetscalerLoadBalancerResponse extends BaseResponse { @SerializedName(ApiConstants.LOAD_BALANCER_DEVICE_ID) @Param(description="device id of the netscaler load balancer") - private IdentityProxy id = new IdentityProxy("external_load_balancer_devices"); + private String id; @SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network to which this netscaler device belongs to") - private IdentityProxy physicalNetworkId = new IdentityProxy("physical_network"); + private String physicalNetworkId; @SerializedName(ApiConstants.PROVIDER) @Param(description="name of the provider") private String providerName; - + @SerializedName(ApiConstants.LOAD_BALANCER_DEVICE_NAME) @Param(description="device name") - private String deviceName; - + private String deviceName; + @SerializedName(ApiConstants.LOAD_BALANCER_DEVICE_STATE) @Param(description="device state") private String deviceState; @@ -53,7 +52,7 @@ public class NetscalerLoadBalancerResponse extends BaseResponse { @SerializedName(ApiConstants.PUBLIC_INTERFACE) @Param(description="the public interface of the load balancer") private String publicInterface; - + @SerializedName(ApiConstants.PRIVATE_INTERFACE) @Param(description="the private interface of the load balancer") private String privateInterface; @@ -64,13 +63,13 @@ public class NetscalerLoadBalancerResponse extends BaseResponse { " This parameter represents the list of pod's, for which there exists a policy based route on datacenter L3 router to " + "route pod's subnet IP to a NetScaler device.") private List podIds; - - public void setId(long lbDeviceId) { - this.id.setValue(lbDeviceId); + + public void setId(String lbDeviceId) { + this.id = lbDeviceId; } - public void setPhysicalNetworkId(long physicalNetworkId) { - this.physicalNetworkId.setValue(physicalNetworkId); + public void setPhysicalNetworkId(String physicalNetworkId) { + this.physicalNetworkId = physicalNetworkId; } public void setProvider(String provider) { diff --git a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java index 3725a246f95..4da097e3963 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java +++ b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java @@ -11,7 +11,7 @@ // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the +// KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.network.element; @@ -36,6 +36,8 @@ import com.cloud.agent.api.routing.SetStaticNatRulesCommand; import com.cloud.agent.api.to.LoadBalancerTO; import com.cloud.agent.api.to.StaticNatRuleTO; import org.apache.cloudstack.api.ApiConstants; + +import com.cloud.api.ApiDBUtils; import com.cloud.api.commands.AddNetscalerLoadBalancerCmd; import com.cloud.api.commands.ConfigureNetscalerLoadBalancerCmd; import com.cloud.api.commands.DeleteNetscalerLoadBalancerCmd; @@ -76,6 +78,7 @@ import com.cloud.network.NetworkExternalLoadBalancerVO; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.TrafficType; +import com.cloud.network.PhysicalNetwork; import com.cloud.network.PhysicalNetworkServiceProvider; import com.cloud.network.PhysicalNetworkVO; import com.cloud.network.PublicIpAddress; @@ -539,9 +542,12 @@ StaticNatServiceProvider { Host lbHost = _hostDao.findById(lbDeviceVO.getHostId()); Map lbDetails = _detailsDao.findDetails(lbDeviceVO.getHostId()); - response.setId(lbDeviceVO.getId()); + response.setId(lbDeviceVO.getUuid()); response.setIpAddress(lbHost.getPrivateIpAddress()); - response.setPhysicalNetworkId(lbDeviceVO.getPhysicalNetworkId()); + PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(lbDeviceVO.getPhysicalNetworkId()); + if (pnw != null) { + response.setPhysicalNetworkId(pnw.getUuid()); + } response.setPublicInterface(lbDetails.get("publicInterface")); response.setPrivateInterface(lbDetails.get("privateInterface")); response.setDeviceName(lbDeviceVO.getDeviceName()); @@ -619,13 +625,13 @@ StaticNatServiceProvider { // NetScaler can only act as Lb and Static Nat service provider if (services != null && !services.isEmpty() && !netscalerServices.containsAll(services)) { - s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination " + s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination " + services + " is not supported."); String servicesList = ""; for (Service service : services) { servicesList += service.getName() + " "; } - s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination " + s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination " + servicesList + " is not supported."); s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination " + services + " is not supported."); diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/api/response/NiciraNvpDeviceResponse.java b/plugins/network-elements/nicira-nvp/src/com/cloud/api/response/NiciraNvpDeviceResponse.java index 74f852b9f28..612d15b7bbe 100644 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/api/response/NiciraNvpDeviceResponse.java +++ b/plugins/network-elements/nicira-nvp/src/com/cloud/api/response/NiciraNvpDeviceResponse.java @@ -18,38 +18,37 @@ package com.cloud.api.response; import org.apache.cloudstack.api.ApiConstants; import com.cloud.serializer.Param; -import com.cloud.utils.IdentityProxy; import com.google.gson.annotations.SerializedName; import org.apache.cloudstack.api.BaseResponse; public class NiciraNvpDeviceResponse extends BaseResponse { @SerializedName(ApiConstants.NICIRA_NVP_DEVICE_ID) @Param(description="device id of the Nicire Nvp") - private IdentityProxy id = new IdentityProxy("external_nicira_nvp_devices"); - + private String id; + @SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network to which this Nirica Nvp belongs to") - private IdentityProxy physicalNetworkId = new IdentityProxy("physical_network"); - + private String physicalNetworkId; + @SerializedName(ApiConstants.PROVIDER) @Param(description="name of the provider") private String providerName; - + @SerializedName(ApiConstants.NICIRA_NVP_DEVICE_NAME) @Param(description="device name") private String deviceName; - + @SerializedName(ApiConstants.HOST_NAME) @Param(description="the controller Ip address") private String hostName; - + @SerializedName(ApiConstants.NICIRA_NVP_TRANSPORT_ZONE_UUID) @Param(description="the transport zone Uuid") private String transportZoneUuid; - + @SerializedName(ApiConstants.NICIRA_NVP_GATEWAYSERVICE_UUID) @Param(description="this L3 gateway service Uuid") private String l3GatewayServiceUuid; - - public void setId(long nvpDeviceId) { - this.id.setValue(nvpDeviceId); + + public void setId(String nvpDeviceId) { + this.id = nvpDeviceId; } - public void setPhysicalNetworkId(long physicalNetworkId) { - this.physicalNetworkId.setValue(physicalNetworkId); + public void setPhysicalNetworkId(String physicalNetworkId) { + this.physicalNetworkId = physicalNetworkId; } public void setProviderName(String providerName) { @@ -60,13 +59,7 @@ public class NiciraNvpDeviceResponse extends BaseResponse { this.deviceName = deviceName; } - public void setId(IdentityProxy id) { - this.id = id; - } - public void setPhysicalNetworkId(IdentityProxy physicalNetworkId) { - this.physicalNetworkId = physicalNetworkId; - } public void setHostName(String hostName) { this.hostName = hostName; @@ -78,6 +71,6 @@ public class NiciraNvpDeviceResponse extends BaseResponse { public void setL3GatewayServiceUuid(String l3GatewayServiceUuid) { this.l3GatewayServiceUuid = l3GatewayServiceUuid; - } - + } + } diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java index d38abcc6897..dc47a7399a2 100644 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java +++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java @@ -51,6 +51,7 @@ import com.cloud.agent.api.StartupNiciraNvpCommand; import com.cloud.agent.api.UpdateLogicalSwitchPortCommand; import com.cloud.agent.api.to.PortForwardingRuleTO; import com.cloud.agent.api.to.StaticNatRuleTO; +import com.cloud.api.ApiDBUtils; import com.cloud.api.commands.AddNiciraNvpDeviceCmd; import com.cloud.api.commands.DeleteNiciraNvpDeviceCmd; import com.cloud.api.commands.ListNiciraNvpDeviceNetworksCmd; @@ -82,6 +83,7 @@ import com.cloud.network.NetworkManager; import com.cloud.network.NiciraNvpDeviceVO; import com.cloud.network.NiciraNvpNicMappingVO; import com.cloud.network.NiciraNvpRouterMappingVO; +import com.cloud.network.PhysicalNetwork; import com.cloud.network.PhysicalNetworkServiceProvider; import com.cloud.network.PhysicalNetworkVO; import com.cloud.network.PublicIpAddress; @@ -275,9 +277,9 @@ public class NiciraNvpElement extends AdapterBase implements + network.getDisplayText()); return false; } - + // Store the uuid so we can easily find it during cleanup - NiciraNvpRouterMappingVO routermapping = + NiciraNvpRouterMappingVO routermapping = new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId()); _niciraNvpRouterMappingDao.persist(routermapping); } @@ -455,14 +457,14 @@ public class NiciraNvpElement extends AdapterBase implements } DeleteLogicalRouterCommand cmd = new DeleteLogicalRouterCommand(routermapping.getLogicalRouterUuid()); - DeleteLogicalRouterAnswer answer = + DeleteLogicalRouterAnswer answer = (DeleteLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer.getResult() == false) { s_logger.error("Failed to delete LogicalRouter for network " + network.getDisplayText()); return false; } - + _niciraNvpRouterMappingDao.remove(routermapping.getId()); } @@ -520,7 +522,7 @@ public class NiciraNvpElement extends AdapterBase implements // L3 Support : Generic? capabilities.put(Service.Gateway, null); - + // L3 Support : SourceNat Map sourceNatCapabilities = new HashMap(); sourceNatCapabilities.put(Capability.SupportedSourceNatTypes, @@ -530,10 +532,10 @@ public class NiciraNvpElement extends AdapterBase implements // L3 Support : Port Forwarding capabilities.put(Service.PortForwarding, null); - + // L3 support : StaticNat capabilities.put(Service.StaticNat, null); - + return capabilities; } @@ -591,8 +593,8 @@ public class NiciraNvpElement extends AdapterBase implements params.put("adminpass", cmd.getPassword()); params.put("transportzoneuuid", cmd.getTransportzoneUuid()); // FIXME What to do with multiple isolation types - params.put("transportzoneisotype", - physicalNetwork.getIsolationMethods().get(0).toLowerCase()); + params.put("transportzoneisotype", + physicalNetwork.getIsolationMethods().get(0).toLowerCase()); if (cmd.getL3GatewayServiceUuid() != null) { params.put("l3gatewayserviceuuid", cmd.getL3GatewayServiceUuid()); } @@ -636,11 +638,14 @@ public class NiciraNvpElement extends AdapterBase implements NiciraNvpDeviceVO niciraNvpDeviceVO) { HostVO niciraNvpHost = _hostDao.findById(niciraNvpDeviceVO.getHostId()); _hostDao.loadDetails(niciraNvpHost); - + NiciraNvpDeviceResponse response = new NiciraNvpDeviceResponse(); response.setDeviceName(niciraNvpDeviceVO.getDeviceName()); - response.setPhysicalNetworkId(niciraNvpDeviceVO.getPhysicalNetworkId()); - response.setId(niciraNvpDeviceVO.getId()); + PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(niciraNvpDeviceVO.getPhysicalNetworkId()); + if (pnw != null) { + response.setPhysicalNetworkId(pnw.getUuid()); + } + response.setId(niciraNvpDeviceVO.getUuid()); response.setProviderName(niciraNvpDeviceVO.getProviderName()); response.setHostName(niciraNvpHost.getDetail("ip")); response.setTransportZoneUuid(niciraNvpHost.getDetail("transportzoneuuid")); @@ -800,7 +805,7 @@ public class NiciraNvpElement extends AdapterBase implements /** * From interface IpDeployer - * + * * @param network * @param ipAddress * @param services @@ -824,7 +829,7 @@ public class NiciraNvpElement extends AdapterBase implements NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId()); _hostDao.loadDetails(niciraNvpHost); - + NiciraNvpRouterMappingVO routermapping = _niciraNvpRouterMappingDao .findByNetworkId(network.getId()); if (routermapping == null) { @@ -832,12 +837,12 @@ public class NiciraNvpElement extends AdapterBase implements + network.getDisplayText()); return false; } - + List cidrs = new ArrayList(); for (PublicIpAddress ip : ipAddress) { cidrs.add(ip.getAddress().addr() + "/" + NetUtils.getCidrSize(ip.getNetmask())); } - ConfigurePublicIpsOnLogicalRouterCommand cmd = new ConfigurePublicIpsOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), + ConfigurePublicIpsOnLogicalRouterCommand cmd = new ConfigurePublicIpsOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), niciraNvpHost.getDetail("l3gatewayserviceuuid"), cidrs); ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd); return answer.getResult(); @@ -845,7 +850,7 @@ public class NiciraNvpElement extends AdapterBase implements else { s_logger.debug("No need to provision ip addresses as we are not providing L3 services."); } - + return true; } @@ -869,7 +874,7 @@ public class NiciraNvpElement extends AdapterBase implements } NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId()); - + NiciraNvpRouterMappingVO routermapping = _niciraNvpRouterMappingDao .findByNetworkId(network.getId()); if (routermapping == null) { @@ -878,23 +883,23 @@ public class NiciraNvpElement extends AdapterBase implements return false; } - List staticNatRules = new ArrayList(); + List staticNatRules = new ArrayList(); for (StaticNat rule : rules) { IpAddress sourceIp = _networkManager.getIp(rule.getSourceIpAddressId()); // Force the nat rule into the StaticNatRuleTO, no use making a new TO object // we only need the source and destination ip. Unfortunately no mention if a rule // is new. - StaticNatRuleTO ruleTO = new StaticNatRuleTO(1, - sourceIp.getAddress().addr(), 0, 65535, + StaticNatRuleTO ruleTO = new StaticNatRuleTO(1, + sourceIp.getAddress().addr(), 0, 65535, rule.getDestIpAddress(), 0, 65535, "any", rule.isForRevoke(), false); staticNatRules.add(ruleTO); } - - ConfigureStaticNatRulesOnLogicalRouterCommand cmd = + + ConfigureStaticNatRulesOnLogicalRouterCommand cmd = new ConfigureStaticNatRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), staticNatRules); ConfigureStaticNatRulesOnLogicalRouterAnswer answer = (ConfigureStaticNatRulesOnLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd); - + return answer.getResult(); } @@ -907,7 +912,7 @@ public class NiciraNvpElement extends AdapterBase implements if (!canHandle(network, Service.PortForwarding)) { return false; } - + List devices = _niciraNvpDao .listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { @@ -917,7 +922,7 @@ public class NiciraNvpElement extends AdapterBase implements } NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId()); - + NiciraNvpRouterMappingVO routermapping = _niciraNvpRouterMappingDao .findByNetworkId(network.getId()); if (routermapping == null) { @@ -925,19 +930,19 @@ public class NiciraNvpElement extends AdapterBase implements + network.getDisplayText()); return false; } - - List portForwardingRules = new ArrayList(); + + List portForwardingRules = new ArrayList(); for (PortForwardingRule rule : rules) { IpAddress sourceIp = _networkManager.getIp(rule.getSourceIpAddressId()); Vlan vlan = _vlanDao.findById(sourceIp.getVlanId()); PortForwardingRuleTO ruleTO = new PortForwardingRuleTO((PortForwardingRule) rule, vlan.getVlanTag(), sourceIp.getAddress().addr()); portForwardingRules.add(ruleTO); } - - ConfigurePortForwardingRulesOnLogicalRouterCommand cmd = + + ConfigurePortForwardingRulesOnLogicalRouterCommand cmd = new ConfigurePortForwardingRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), portForwardingRules); ConfigurePortForwardingRulesOnLogicalRouterAnswer answer = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd); - + return answer.getResult(); } diff --git a/server/src/com/cloud/api/commands/GetUsageRecordsCmd.java b/server/src/com/cloud/api/commands/GetUsageRecordsCmd.java index 6d67e05043c..77fdd56eb0c 100644 --- a/server/src/com/cloud/api/commands/GetUsageRecordsCmd.java +++ b/server/src/com/cloud/api/commands/GetUsageRecordsCmd.java @@ -27,6 +27,7 @@ import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import com.cloud.api.ApiDBUtils; +import com.cloud.dc.DataCenter; import com.cloud.domain.Domain; import org.apache.cloudstack.api.BaseListCmd; @@ -37,11 +38,13 @@ import org.apache.cloudstack.api.response.ListResponse; import com.cloud.projects.Project; import com.cloud.server.ManagementServerExt; import com.cloud.server.api.response.UsageRecordResponse; +import com.cloud.storage.VMTemplateVO; import com.cloud.usage.UsageTypes; import com.cloud.usage.UsageVO; import com.cloud.user.Account; import com.cloud.uuididentity.dao.IdentityDao; import com.cloud.uuididentity.dao.IdentityDaoImpl; +import com.cloud.vm.VMInstanceVO; @Implementation(description="Lists usage records for accounts", responseObject=UsageRecordResponse.class) public class GetUsageRecordsCmd extends BaseListCmd { @@ -235,7 +238,7 @@ public class GetUsageRecordsCmd extends BaseListCmd { usageRecResponse.setProjectId(project.getUuid()); usageRecResponse.setProjectName(project.getName()); } else { - usageRecResponse.setAccountId(account.getId()); + usageRecResponse.setAccountId(account.getUuid()); usageRecResponse.setAccountName(account.getAccountName()); } @@ -244,13 +247,28 @@ public class GetUsageRecordsCmd extends BaseListCmd { usageRecResponse.setDomainId(domain.getUuid()); } - usageRecResponse.setZoneId(usageRecord.getZoneId()); + if (usageRecord.getZoneId() != null) { + DataCenter zone = ApiDBUtils.findZoneById(usageRecord.getZoneId()); + if (zone != null) { + usageRecResponse.setZoneId(zone.getUuid()); + } + } usageRecResponse.setDescription(usageRecord.getDescription()); usageRecResponse.setUsage(usageRecord.getUsageDisplay()); usageRecResponse.setUsageType(usageRecord.getUsageType()); - usageRecResponse.setVirtualMachineId(usageRecord.getVmInstanceId()); + if (usageRecord.getVmInstanceId() != null) { + VMInstanceVO vm = ApiDBUtils.findVMInstanceById(usageRecord.getVmInstanceId()); + if (vm != null) { + usageRecResponse.setVirtualMachineId(vm.getUuid()); + } + } usageRecResponse.setVmName(usageRecord.getVmName()); - usageRecResponse.setTemplateId(usageRecord.getTemplateId()); + if (usageRecord.getTemplateId() != null) { + VMTemplateVO template = ApiDBUtils.findTemplateById(usageRecord.getTemplateId()); + if (template != null) { + usageRecResponse.setTemplateId(template.getUuid()); + } + } if(usageRecord.getUsageType() == UsageTypes.RUNNING_VM || usageRecord.getUsageType() == UsageTypes.ALLOCATED_VM){ //Service Offering Id diff --git a/server/src/com/cloud/baremetal/DhcpServerResponse.java b/server/src/com/cloud/baremetal/DhcpServerResponse.java index 69b507190bf..db46ccd1a1d 100644 --- a/server/src/com/cloud/baremetal/DhcpServerResponse.java +++ b/server/src/com/cloud/baremetal/DhcpServerResponse.java @@ -17,20 +17,19 @@ package com.cloud.baremetal; import org.apache.cloudstack.api.ApiConstants; -import com.cloud.utils.IdentityProxy; import org.apache.cloudstack.api.BaseResponse; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; public class DhcpServerResponse extends BaseResponse { @SerializedName(ApiConstants.ID) @Param(description="the ID of the Dhcp server") - private IdentityProxy id = new IdentityProxy("host"); - - public Long getId() { - return id.getValue(); + private String id; + + public String getId() { + return id; } - - public void setId(Long id) { - this.id.setValue(id); + + public void setId(String id) { + this.id = id; } } diff --git a/server/src/com/cloud/baremetal/ExternalDhcpManagerImpl.java b/server/src/com/cloud/baremetal/ExternalDhcpManagerImpl.java index 0da4029784e..c1f0fff6d3c 100755 --- a/server/src/com/cloud/baremetal/ExternalDhcpManagerImpl.java +++ b/server/src/com/cloud/baremetal/ExternalDhcpManagerImpl.java @@ -71,7 +71,7 @@ public class ExternalDhcpManagerImpl implements ExternalDhcpManager, ResourceSta @Inject UserVmDao _userVmDao; @Inject ResourceManager _resourceMgr; @Inject NicDao _nicDao; - + @Override public boolean configure(String name, Map params) throws ConfigurationException { _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); @@ -97,26 +97,26 @@ public class ExternalDhcpManagerImpl implements ExternalDhcpManager, ResourceSta protected String getDhcpServerGuid(String zoneId, String name, String ip) { return zoneId + "-" + name + "-" + ip; } - - + + @Override @DB - public Host addDhcpServer(Long zoneId, Long podId, String type, String url, String username, String password) { + public Host addDhcpServer(Long zoneId, Long podId, String type, String url, String username, String password) { DataCenterVO zone = _dcDao.findById(zoneId); if (zone == null) { throw new InvalidParameterValueException("Could not find zone with ID: " + zoneId); - } - + } + HostPodVO pod = _podDao.findById(podId); if (pod == null) { throw new InvalidParameterValueException("Could not find pod with ID: " + podId); - } - + } + List dhcps = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.ExternalDhcp, null, podId, zoneId); if (dhcps.size() != 0) { throw new InvalidParameterValueException("Already had a DHCP server in Pod: " + podId + " zone: " + zoneId); } - - + + String ipAddress = url; String guid = getDhcpServerGuid(Long.toString(zoneId) + "-" + Long.toString(podId), "ExternalDhcp", ipAddress); Map params = new HashMap(); @@ -134,7 +134,7 @@ public class ExternalDhcpManagerImpl implements ExternalDhcpManager, ResourceSta dns = zone.getDns2(); } params.put("dns", dns); - + ServerResource resource = null; try { if (type.equalsIgnoreCase(DhcpServerType.Dnsmasq.getName())) { @@ -150,12 +150,12 @@ public class ExternalDhcpManagerImpl implements ExternalDhcpManager, ResourceSta s_logger.debug(e); throw new CloudRuntimeException(e.getMessage()); } - + Host dhcpServer = _resourceMgr.addHost(zoneId, resource, Host.Type.ExternalDhcp, params); if (dhcpServer == null) { throw new CloudRuntimeException("Cannot add external Dhcp server as a host"); } - + Transaction txn = Transaction.currentTxn(); txn.start(); pod.setExternalDhcp(true); @@ -163,11 +163,11 @@ public class ExternalDhcpManagerImpl implements ExternalDhcpManager, ResourceSta txn.commit(); return dhcpServer; } - + @Override public DhcpServerResponse getApiResponse(Host dhcpServer) { DhcpServerResponse response = new DhcpServerResponse(); - response.setId(dhcpServer.getId()); + response.setId(dhcpServer.getUuid()); return response; } @@ -178,7 +178,7 @@ public class ExternalDhcpManagerImpl implements ExternalDhcpManager, ResourceSta s_logger.debug("VM " + vmId + " is not baremetal machine, skip preparing baremetal DHCP entry"); return; } - + List servers = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.PxeServer, null, vm.getPodIdToDeployIn(), vm.getDataCenterIdToDeployIn()); if (servers.size() != 1) { throw new CloudRuntimeException("Wrong number of PXE server found in zone " + vm.getDataCenterIdToDeployIn() @@ -188,7 +188,7 @@ public class ExternalDhcpManagerImpl implements ExternalDhcpManager, ResourceSta cmd.setNextServer(pxeServer.getPrivateIpAddress()); s_logger.debug("Set next-server to " + pxeServer.getPrivateIpAddress() + " for VM " + vm.getId()); } - + @Override public boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException { @@ -198,11 +198,11 @@ public class ExternalDhcpManagerImpl implements ExternalDhcpManager, ResourceSta if (hosts.size() == 0) { throw new CloudRuntimeException("No external Dhcp found in zone " + zoneId + " pod " + podId); } - + if (hosts.size() > 1) { throw new CloudRuntimeException("Something wrong, more than 1 external Dhcp found in zone " + zoneId + " pod " + podId); } - + HostVO h = hosts.get(0); String dns = nic.getDns1(); if (dns == null) { @@ -240,7 +240,7 @@ public class ExternalDhcpManagerImpl implements ExternalDhcpManager, ResourceSta if (!(startup[0] instanceof StartupExternalDhcpCommand)) { return null; } - + host.setType(Host.Type.ExternalDhcp); return host; } diff --git a/server/src/com/cloud/baremetal/PxeServerManagerImpl.java b/server/src/com/cloud/baremetal/PxeServerManagerImpl.java index efbccfa2092..0db8cc9289c 100755 --- a/server/src/com/cloud/baremetal/PxeServerManagerImpl.java +++ b/server/src/com/cloud/baremetal/PxeServerManagerImpl.java @@ -57,7 +57,7 @@ public class PxeServerManagerImpl implements PxeServerManager, ResourceStateAdap @Inject ResourceManager _resourceMgr; @Inject(adapter=PxeServerService.class) protected Adapters _services; - + @Override public boolean configure(String name, Map params) throws ConfigurationException { _name = name; @@ -89,8 +89,8 @@ public class PxeServerManagerImpl implements PxeServerManager, ResourceStateAdap } return _service; } - - + + @Override public Host addPxeServer(PxeServerProfile profile) { return getServiceByType(profile.getType()).addPxeServer(profile); @@ -99,7 +99,7 @@ public class PxeServerManagerImpl implements PxeServerManager, ResourceStateAdap @Override public PxeServerResponse getApiResponse(Host pxeServer) { PxeServerResponse response = new PxeServerResponse(); - response.setId(pxeServer.getId()); + response.setId(pxeServer.getUuid()); return response; } @@ -112,7 +112,7 @@ public class PxeServerManagerImpl implements PxeServerManager, ResourceStateAdap public boolean prepareCreateTemplate(PxeServerType type, Long pxeServerId, UserVm vm, String templateUrl) { return getServiceByType(type.getName()).prepareCreateTemplate(pxeServerId, vm, templateUrl); } - + @Override public PxeServerType getPxeServerType(HostVO host) { if (host.getResource().equalsIgnoreCase(PingPxeServerResource.class.getName())) { @@ -134,7 +134,7 @@ public class PxeServerManagerImpl implements PxeServerManager, ResourceStateAdap if (!(startup[0] instanceof StartupPxeServerCommand)) { return null; } - + host.setType(Host.Type.PxeServer); return host; } diff --git a/server/src/com/cloud/baremetal/PxeServerResponse.java b/server/src/com/cloud/baremetal/PxeServerResponse.java index aa050960273..32fcc7fb5b9 100644 --- a/server/src/com/cloud/baremetal/PxeServerResponse.java +++ b/server/src/com/cloud/baremetal/PxeServerResponse.java @@ -17,20 +17,19 @@ package com.cloud.baremetal; import org.apache.cloudstack.api.ApiConstants; -import com.cloud.utils.IdentityProxy; import org.apache.cloudstack.api.BaseResponse; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; public class PxeServerResponse extends BaseResponse { @SerializedName(ApiConstants.ID) @Param(description="the ID of the PXE server") - private IdentityProxy id = new IdentityProxy("host"); - - public Long getId() { - return id.getValue(); + private String id; + + public String getId() { + return id; } - - public void setId(Long id) { - this.id.setValue(id); + + public void setId(String id) { + this.id = id; } } diff --git a/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java index 38fc6f51031..078b9e5d147 100755 --- a/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java +++ b/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java @@ -32,6 +32,8 @@ import org.apache.cloudstack.network.ExternalNetworkDeviceManager; import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; +import com.cloud.api.ApiDBUtils; + import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.IdentityService; import org.apache.cloudstack.api.command.admin.network.DeleteNetworkDeviceCmd; @@ -40,6 +42,8 @@ import com.cloud.baremetal.PxeServerManager; import com.cloud.baremetal.PxeServerProfile; import com.cloud.baremetal.PxeServerManager.PxeServerType; import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.dc.DataCenter; +import com.cloud.dc.Pod; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.VlanDao; import com.cloud.host.Host; @@ -187,8 +191,16 @@ public class ExternalNetworkDeviceManagerImpl implements ExternalNetworkDeviceMa String pxeType = host.getDetail("type"); if (pxeType.equalsIgnoreCase(PxeServerType.PING.getName())) { PxePingResponse r = new PxePingResponse(); - r.setZoneId(host.getDataCenterId()); - r.setPodId(host.getPodId()); + DataCenter zone = ApiDBUtils.findZoneById(host.getDataCenterId()); + if (zone != null) { + r.setZoneId(zone.getUuid()); + } + if (host.getPodId() != null) { + Pod pod = ApiDBUtils.findPodById(host.getPodId()); + if (pod != null) { + r.setPodId(pod.getUuid()); + } + } r.setUrl(host.getPrivateIpAddress()); r.setType(pxeType); r.setStorageServerIp(host.getDetail("storageServer")); diff --git a/server/src/com/cloud/network/NetworkUsageManagerImpl.java b/server/src/com/cloud/network/NetworkUsageManagerImpl.java index 13e5e241855..3207c6f0e37 100755 --- a/server/src/com/cloud/network/NetworkUsageManagerImpl.java +++ b/server/src/com/cloud/network/NetworkUsageManagerImpl.java @@ -202,7 +202,7 @@ public class NetworkUsageManagerImpl implements NetworkUsageManager, ResourceSta public TrafficMonitorResponse getApiResponse(Host trafficMonitor) { Map tmDetails = _detailsDao.findDetails(trafficMonitor.getId()); TrafficMonitorResponse response = new TrafficMonitorResponse(); - response.setId(trafficMonitor.getId()); + response.setId(trafficMonitor.getUuid()); response.setIpAddress(trafficMonitor.getPrivateIpAddress()); response.setNumRetries(tmDetails.get("numRetries")); response.setTimeout(tmDetails.get("timeout")); @@ -220,7 +220,7 @@ public class NetworkUsageManagerImpl implements NetworkUsageManager, ResourceSta networkJoin.and("guestType", networkJoin.entity().getGuestType(), Op.EQ); AllocatedIpSearch.join("network", networkJoin, AllocatedIpSearch.entity().getSourceNetworkId(), networkJoin.entity().getId(), JoinBuilder.JoinType.INNER); AllocatedIpSearch.done(); - + _networkStatsInterval = NumbersUtil.parseInt(_configDao.getValue(Config.DirectNetworkStatsInterval.key()), 86400); _agentMgr.registerForHostEvents(new DirectNetworkStatsListener( _networkStatsInterval), true, false, false); _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); @@ -316,8 +316,8 @@ public class NetworkUsageManagerImpl implements NetworkUsageManager, ResourceSta // This coule be made configurable rightNow.add(Calendar.HOUR_OF_DAY, -2); - Date now = rightNow.getTime(); - + Date now = rightNow.getTime(); + if(lastCollection.after(now)){ s_logger.debug("Current time is less than 2 hours after last collection time : " + lastCollection.toString() + ". Skipping direct network usage collection"); return false; @@ -369,7 +369,7 @@ public class NetworkUsageManagerImpl implements NetworkUsageManager, ResourceSta } List collectedStats = new ArrayList(); - + //Get usage for Ips which were assigned for the entire duration if(fullDurationIpUsage.size() > 0){ DirectNetworkUsageCommand cmd = new DirectNetworkUsageCommand(IpList, lastCollection, now); @@ -509,7 +509,7 @@ public class NetworkUsageManagerImpl implements NetworkUsageManager, ResourceSta protected DirectNetworkStatsListener() { } - + } @@ -525,7 +525,7 @@ public class NetworkUsageManagerImpl implements NetworkUsageManager, ResourceSta if (!(startup[0] instanceof StartupTrafficMonitorCommand)) { return null; } - + host.setType(Host.Type.TrafficMonitor); return host; } diff --git a/server/src/com/cloud/server/api/response/BaremetalTemplateResponse.java b/server/src/com/cloud/server/api/response/BaremetalTemplateResponse.java index 9718717c052..355f3646a65 100644 --- a/server/src/com/cloud/server/api/response/BaremetalTemplateResponse.java +++ b/server/src/com/cloud/server/api/response/BaremetalTemplateResponse.java @@ -16,20 +16,19 @@ // under the License. package com.cloud.server.api.response; -import com.cloud.utils.IdentityProxy; import org.apache.cloudstack.api.BaseResponse; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; public class BaremetalTemplateResponse extends BaseResponse { @SerializedName("id") @Param(description="the template ID") - private IdentityProxy id = new IdentityProxy("vm_template"); - - public Long getId() { - return id.getValue(); + private String id; + + public String getId() { + return id; } - - public void setId(Long id) { - this.id.setValue(id); + + public void setId(String id) { + this.id = id; } } diff --git a/server/src/com/cloud/server/api/response/NwDevicePxeServerResponse.java b/server/src/com/cloud/server/api/response/NwDevicePxeServerResponse.java index a59e6c2eddf..72063c39b7f 100644 --- a/server/src/com/cloud/server/api/response/NwDevicePxeServerResponse.java +++ b/server/src/com/cloud/server/api/response/NwDevicePxeServerResponse.java @@ -17,7 +17,6 @@ package com.cloud.server.api.response; import org.apache.cloudstack.api.ApiConstants; -import com.cloud.utils.IdentityProxy; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; import org.apache.cloudstack.api.response.NetworkDeviceResponse; @@ -25,38 +24,38 @@ import org.apache.cloudstack.api.response.NetworkDeviceResponse; public class NwDevicePxeServerResponse extends NetworkDeviceResponse { @SerializedName(ApiConstants.ZONE_ID) @Param(description="Zone where to add PXE server") - private IdentityProxy zoneId = new IdentityProxy("data_center"); - + private String zoneId; + @SerializedName(ApiConstants.POD_ID) @Param(description="Pod where to add PXE server") - private IdentityProxy podId = new IdentityProxy("host_pod_ref"); - + private String podId; + @SerializedName(ApiConstants.URL) @Param(description="Ip of PXE server") private String url; - + @SerializedName(ApiConstants.TYPE) @Param(description="Type of add PXE server") private String type; - - public void setZoneId(Long zoneId) { - this.zoneId.setValue(zoneId); + + public void setZoneId(String zoneId) { + this.zoneId = zoneId; } - public Long getZoneId() { - return zoneId.getValue(); + public String getZoneId() { + return zoneId; } - - public void setPodId(Long podId) { - this.podId.setValue(podId); + + public void setPodId(String podId) { + this.podId = podId; } - public Long getPodId() { - return podId.getValue(); + public String getPodId() { + return podId; } - + public void setUrl(String url) { this.url = url; } public String getUrl() { return url; } - + public void setType(String type) { this.type = type; } diff --git a/server/src/com/cloud/server/api/response/TrafficMonitorResponse.java b/server/src/com/cloud/server/api/response/TrafficMonitorResponse.java index a01e658656c..95ab4453a26 100644 --- a/server/src/com/cloud/server/api/response/TrafficMonitorResponse.java +++ b/server/src/com/cloud/server/api/response/TrafficMonitorResponse.java @@ -17,7 +17,6 @@ package com.cloud.server.api.response; import org.apache.cloudstack.api.ApiConstants; -import com.cloud.utils.IdentityProxy; import org.apache.cloudstack.api.BaseResponse; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; @@ -25,56 +24,56 @@ import com.google.gson.annotations.SerializedName; public class TrafficMonitorResponse extends BaseResponse { @SerializedName(ApiConstants.ID) @Param(description="the ID of the external firewall") - private IdentityProxy id = new IdentityProxy("host"); - + private String id; + @SerializedName(ApiConstants.ZONE_ID) @Param(description="the zone ID of the external firewall") - private IdentityProxy zoneId = new IdentityProxy("data_center"); - + private String zoneId; + @SerializedName(ApiConstants.IP_ADDRESS) @Param(description="the management IP address of the external firewall") private String ipAddress; - + @SerializedName(ApiConstants.NUM_RETRIES) @Param(description="the number of times to retry requests to the external firewall") private String numRetries; - + @SerializedName(ApiConstants.TIMEOUT) @Param(description="the timeout (in seconds) for requests to the external firewall") private String timeout; - - public Long getId() { - return id.getValue(); + + public String getId() { + return id; } - - public void setId(Long id) { - this.id.setValue(id); + + public void setId(String id) { + this.id = id; } - - public Long getZoneId() { - return zoneId.getValue(); + + public String getZoneId() { + return zoneId; } - - public void setZoneId(Long zoneId) { - this.zoneId.setValue(zoneId); + + public void setZoneId(String zoneId) { + this.zoneId = zoneId; } - + public String getIpAddress() { return ipAddress; } - + public void setIpAddress(String ipAddress) { this.ipAddress = ipAddress; } - + public String getNumRetries() { return numRetries; } - + public void setNumRetries(String numRetries) { this.numRetries = numRetries; } - + public String getTimeout() { return timeout; } - + public void setTimeout(String timeout) { this.timeout = timeout; } diff --git a/server/src/com/cloud/server/api/response/UsageRecordResponse.java b/server/src/com/cloud/server/api/response/UsageRecordResponse.java index bcfce2de19b..29c81a79dc6 100644 --- a/server/src/com/cloud/server/api/response/UsageRecordResponse.java +++ b/server/src/com/cloud/server/api/response/UsageRecordResponse.java @@ -17,7 +17,6 @@ package com.cloud.server.api.response; import org.apache.cloudstack.api.ApiConstants; -import com.cloud.utils.IdentityProxy; import org.apache.cloudstack.api.BaseResponse; import org.apache.cloudstack.api.response.ControlledEntityResponse; import com.cloud.serializer.Param; @@ -29,7 +28,7 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit private String accountName; @SerializedName(ApiConstants.ACCOUNT_ID) @Param(description="the user account Id") - private IdentityProxy accountId = new IdentityProxy("account"); + private String accountId; @SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the resource") private String projectId; @@ -44,7 +43,7 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit private String domainName; @SerializedName(ApiConstants.ZONE_ID) @Param(description="the zone ID") - private IdentityProxy zoneId = new IdentityProxy("data_center"); + private String zoneId; @SerializedName(ApiConstants.DESCRIPTION) @Param(description="description of the usage record") private String description; @@ -59,7 +58,7 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit private String rawUsage; @SerializedName(ApiConstants.VIRTUAL_MACHINE_ID) @Param(description="virtual machine ID") - private IdentityProxy virtualMachineId = new IdentityProxy("vm_instance"); + private String virtualMachineId; @SerializedName(ApiConstants.NAME) @Param(description="virtual machine name") private String vmName; @@ -68,7 +67,7 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit private String offeringId; @SerializedName(ApiConstants.TEMPLATE_ID) @Param(description="template ID") - private IdentityProxy templateId = new IdentityProxy("vm_template"); + private String templateId; @SerializedName("usageid") @Param(description="id of the resource") private String usageId; @@ -102,8 +101,8 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit this.accountName = accountName; } - public void setAccountId(Long accountId) { - this.accountId.setValue(accountId); + public void setAccountId(String accountId) { + this.accountId = accountId; } @Override @@ -111,8 +110,8 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit this.domainId = domainId; } - public void setZoneId(Long zoneId) { - this.zoneId.setValue(zoneId); + public void setZoneId(String zoneId) { + this.zoneId = zoneId; } public void setDescription(String description) { @@ -131,8 +130,8 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit this.rawUsage = rawUsage; } - public void setVirtualMachineId(Long virtualMachineId) { - this.virtualMachineId.setValue(virtualMachineId); + public void setVirtualMachineId(String virtualMachineId) { + this.virtualMachineId = virtualMachineId; } public void setVmName(String vmName) { @@ -143,8 +142,8 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit this.offeringId = offeringId; } - public void setTemplateId(Long templateId) { - this.templateId.setValue(templateId); + public void setTemplateId(String templateId) { + this.templateId = templateId; } public void setUsageId(String usageId) {