From 75121bd76200b2121d7ee219fc252fe4fe95eaf6 Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Wed, 16 Nov 2011 10:47:43 -0800 Subject: [PATCH] bug 11817 : NAAS external networking device support - added pluggable (service) API's for managing F5 and SRX devices --- api/src/com/cloud/api/ApiConstants.java | 1 + .../api/response/F5LoadBalancerResponse.java | 68 ++++++ .../NetscalerLoadBalancerResponse.java | 18 ++ .../api/response/SrxFirewallResponse.java | 69 ++++++ .../tomcatconf/f5bigip_commands.properties.in | 8 + .../junipersrx_commands.properties.in | 6 + .../api/commands/AddF5LoadBalancerCmd.java | 136 ++++++++++++ .../commands/AddNetscalerLoadBalancerCmd.java | 4 +- .../cloud/api/commands/AddSrxFirewallCmd.java | 135 ++++++++++++ .../commands/ConfigureF5LoadBalancerCmd.java | 114 ++++++++++ .../ConfigureNetscalerLoadBalancerCmd.java | 2 +- .../api/commands/ConfigureSrxFirewallCmd.java | 115 ++++++++++ .../api/commands/DeleteF5LoadBalancerCmd.java | 106 ++++++++++ .../api/commands/DeleteSrxFirewallCmd.java | 105 ++++++++++ .../ListF5LoadBalancerNetworksCmd.java | 100 +++++++++ .../api/commands/ListF5LoadBalancersCmd.java | 107 ++++++++++ .../ListNetscalerLoadBalancerNetworksCmd.java | 18 ++ .../commands/ListSrxFirewallNetworksCmd.java | 100 +++++++++ .../api/commands/ListSrxFirewallsCmd.java | 108 ++++++++++ .../ExternalFirewallDeviceManager.java | 2 +- .../ExternalFirewallDeviceManagerImpl.java | 24 ++- .../network/ExternalFirewallDeviceVO.java | 4 + .../ExternalNetworkDeviceManagerImpl.java | 20 +- .../F5ExternalLoadBalancerElement.java | 148 ++++++++++++- .../F5ExternalLoadBalancerElementService.java | 46 ++++ .../JuniperSRXExternalFirewallElement.java | 196 +++++++++++++++--- .../JuniperSRXFirewallElementService.java | 46 ++++ .../NetscalerExternalLoadBalancerElement.java | 4 +- .../NetscalerLoadBalancerElementService.java | 6 +- 29 files changed, 1771 insertions(+), 45 deletions(-) create mode 100644 api/src/com/cloud/api/response/F5LoadBalancerResponse.java create mode 100644 api/src/com/cloud/api/response/SrxFirewallResponse.java create mode 100644 server/src/com/cloud/api/commands/AddF5LoadBalancerCmd.java create mode 100644 server/src/com/cloud/api/commands/AddSrxFirewallCmd.java create mode 100644 server/src/com/cloud/api/commands/ConfigureF5LoadBalancerCmd.java create mode 100644 server/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java create mode 100644 server/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java create mode 100644 server/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java create mode 100644 server/src/com/cloud/api/commands/ListF5LoadBalancerNetworksCmd.java create mode 100644 server/src/com/cloud/api/commands/ListF5LoadBalancersCmd.java create mode 100644 server/src/com/cloud/api/commands/ListSrxFirewallNetworksCmd.java create mode 100644 server/src/com/cloud/api/commands/ListSrxFirewallsCmd.java diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index efb9cc6fb01..2a7895ce3e7 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -312,4 +312,5 @@ public class ApiConstants { public static final String FIREWALL_DEVICE_ID = "fwdeviceid"; public static final String FIREWALL_DEVICE_NAME = "fwdevicename"; public static final String FIREWALL_DEVICE_STATE = "fwdevicestate"; + public static final String FIREWALL_DEVICE_CAPACITY = "fwdevicecapacity"; } diff --git a/api/src/com/cloud/api/response/F5LoadBalancerResponse.java b/api/src/com/cloud/api/response/F5LoadBalancerResponse.java new file mode 100644 index 00000000000..9b8103b44fd --- /dev/null +++ b/api/src/com/cloud/api/response/F5LoadBalancerResponse.java @@ -0,0 +1,68 @@ +/** + * 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.response; + +import com.cloud.api.ApiConstants; +import com.cloud.api.IdentityProxy; +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +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"); + + @SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network to which this F5 device belongs to") + private IdentityProxy physicalNetworkId = new IdentityProxy("physical_network"); + + @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; + + @SerializedName(ApiConstants.LOAD_BALANCER_DEVICE_STATE) @Param(description="device state") + private String deviceState; + + @SerializedName(ApiConstants.LOAD_BALANCER_DEVICE_CAPACITY) @Param(description="device capacity") + private Long deviceCapacity; + + public void setId(long lbDeviceId) { + this.id.setValue(lbDeviceId); + } + + public void setPhysicalNetworkId(long physicalNetworkId) { + this.physicalNetworkId.setValue(physicalNetworkId); + } + + public void setProvider(String provider) { + this.providerName = provider; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public void setDeviceCapacity(long deviceCapacity) { + this.deviceCapacity = deviceCapacity; + } + + public void setDeviceState(String deviceState) { + this.deviceState = deviceState; + } +} diff --git a/api/src/com/cloud/api/response/NetscalerLoadBalancerResponse.java b/api/src/com/cloud/api/response/NetscalerLoadBalancerResponse.java index 50911484278..ee70a88a618 100644 --- a/api/src/com/cloud/api/response/NetscalerLoadBalancerResponse.java +++ b/api/src/com/cloud/api/response/NetscalerLoadBalancerResponse.java @@ -1,3 +1,21 @@ +/** + * 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.response; import com.cloud.api.ApiConstants; diff --git a/api/src/com/cloud/api/response/SrxFirewallResponse.java b/api/src/com/cloud/api/response/SrxFirewallResponse.java new file mode 100644 index 00000000000..63b382ccb1f --- /dev/null +++ b/api/src/com/cloud/api/response/SrxFirewallResponse.java @@ -0,0 +1,69 @@ +/** + * 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.response; + +import com.cloud.api.ApiConstants; +import com.cloud.api.IdentityProxy; +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +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"); + + @SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network to which this SRX firewall belongs to") + private IdentityProxy physicalNetworkId = new IdentityProxy("physical_network"); + + @SerializedName(ApiConstants.PROVIDER) @Param(description="name of the provider") + private String providerName; + + @SerializedName(ApiConstants.FIREWALL_DEVICE_NAME) @Param(description="device name") + private String deviceName; + + @SerializedName(ApiConstants.FIREWALL_DEVICE_STATE) @Param(description="device state") + private String deviceState; + + @SerializedName(ApiConstants.FIREWALL_DEVICE_CAPACITY) @Param(description="device capacity") + private Long deviceCapacity; + + public void setId(long lbDeviceId) { + this.id.setValue(lbDeviceId); + } + + public void setPhysicalNetworkId(long physicalNetworkId) { + this.physicalNetworkId.setValue(physicalNetworkId); + } + + public void setProvider(String provider) { + this.providerName = provider; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public void setDeviceCapacity(long deviceCapacity) { + this.deviceCapacity = deviceCapacity; + } + + public void setDeviceState(String deviceState) { + this.deviceState = deviceState; + } +} diff --git a/client/tomcatconf/f5bigip_commands.properties.in b/client/tomcatconf/f5bigip_commands.properties.in index 1370ad8bc44..c67a8f08ef6 100644 --- a/client/tomcatconf/f5bigip_commands.properties.in +++ b/client/tomcatconf/f5bigip_commands.properties.in @@ -2,6 +2,14 @@ ### Please standardize naming conventions to camel-case (even for acronyms). #### f5 big ip load balancer commands + +#Deprecated commands addExternalLoadBalancer = com.cloud.api.commands.AddExternalLoadBalancerCmd;7 deleteExternalLoadBalancer = com.cloud.api.commands.DeleteExternalLoadBalancerCmd;7 listExternalLoadBalancer = com.cloud.api.commands.ListExternalLoadBalancerCmd;7 + +addF5LoadBalancer = com.cloud.api.commands.AddF5LoadBalancerCmd;7 +configureF5LoadBalancer = com.cloud.api.commands.ConfigureF5LoadBalancerCmd;7 +deleteF5LoadBalancer = com.cloud.api.commands.DeleteF5LoadBalancerCmd;7 +listF5LoadBalancers = com.cloud.api.commands.ListF5LoadBalancersCmd;7 +listF5LoadBalancerNetworks = com.cloud.api.commands.ListF5LoadBalancerNetworksCmd;7 diff --git a/client/tomcatconf/junipersrx_commands.properties.in b/client/tomcatconf/junipersrx_commands.properties.in index 06c68cec757..a3feb28ca2b 100644 --- a/client/tomcatconf/junipersrx_commands.properties.in +++ b/client/tomcatconf/junipersrx_commands.properties.in @@ -5,3 +5,9 @@ addExternalFirewall = com.cloud.api.commands.AddExternalFirewallCmd;7 deleteExternalFirewall = com.cloud.api.commands.DeleteExternalFirewallCmd;7 listExternalFirewall = com.cloud.api.commands.ListExternalFirewallCmd;7 + +addSrxFirewall = com.cloud.api.commands.AddSrxFirewallCmd;7 +deleteSrcFirewall = com.cloud.api.commands.DeleteSrxFirewallCmd;7 +configureSrxFirewall = com.cloud.api.commands.ConfigureSrxFirewallCmd;7 +listSrxFirewalls = com.cloud.api.commands.ListSrxFirewallsCmd;7 +listSrxFirewallNetworks = com.cloud.api.commands.ListSrxFirewallNetworksCmd;7 diff --git a/server/src/com/cloud/api/commands/AddF5LoadBalancerCmd.java b/server/src/com/cloud/api/commands/AddF5LoadBalancerCmd.java new file mode 100644 index 00000000000..98e8a696ef8 --- /dev/null +++ b/server/src/com/cloud/api/commands/AddF5LoadBalancerCmd.java @@ -0,0 +1,136 @@ +/** + * 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.BaseAsyncCmd; +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.F5LoadBalancerResponse; +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.ExternalLoadBalancerDeviceVO; +import com.cloud.network.element.F5ExternalLoadBalancerElementService; +import com.cloud.user.UserContext; +import com.cloud.utils.exception.CloudRuntimeException; + +@Implementation(responseObject=F5LoadBalancerResponse.class, description="Adds a F5 BigIP load balancer device") +public class AddF5LoadBalancerCmd extends BaseAsyncCmd { + + public static final Logger s_logger = Logger.getLogger(AddF5LoadBalancerCmd.class.getName()); + private static final String s_name = "addf5bigiploadbalancerresponse"; + @PlugService F5ExternalLoadBalancerElementService _f5DeviceManagerService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="physical_network") + @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, required=true, description="the Physical Network ID") + private Long physicalNetworkId; + + @Parameter(name=ApiConstants.URL, type=CommandType.STRING, required = true, description="URL of the F5 load balancer appliance.") + private String url; + + @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Credentials to reach F5 BigIP load balancer device") + private String username; + + @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Credentials to reach F5 BigIP load balancer device") + private String password; + + @Parameter(name = ApiConstants.NETWORK_DEVICE_TYPE, type = CommandType.STRING, required = true, description = "supports only F5BigIpLoadBalancer") + private String deviceType; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getPhysicalNetworkId() { + return physicalNetworkId; + } + + public String getUrl() { + return url; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public String getDeviceType() { + return deviceType; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + try { + ExternalLoadBalancerDeviceVO lbDeviceVO = _f5DeviceManagerService.addF5LoadBalancer(this); + if (lbDeviceVO != null) { + F5LoadBalancerResponse response = _f5DeviceManagerService.createF5LoadBalancerResponse(lbDeviceVO); + response.setObjectName("f5loadbalancer"); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to add F5 Big IP load balancer due to 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 getEventDescription() { + return "Adding a F5 Big Ip load balancer device"; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_EXTERAL_LB_DEVICE_ADD; + } + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + return UserContext.current().getCaller().getId(); + } +} \ No newline at end of file diff --git a/server/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java b/server/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java index f76e145cec7..e44b6d716fb 100644 --- a/server/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java +++ b/server/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java @@ -54,7 +54,7 @@ public class AddNetscalerLoadBalancerCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, required=true, description="the Physical Network ID") private Long physicalNetworkId; - @Parameter(name=ApiConstants.URL, type=CommandType.STRING, required = true, description="URL of the external load balancer appliance.") + @Parameter(name=ApiConstants.URL, type=CommandType.STRING, required = true, description="URL of the netscaler load balancer appliance.") private String url; @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Credentials to reach netscaler load balancer device") @@ -63,7 +63,7 @@ public class AddNetscalerLoadBalancerCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Credentials to reach netscaler load balancer device") private String password; - @Parameter(name = ApiConstants.NETWORK_DEVICE_TYPE, type = CommandType.STRING, required = true, description = "Network device type, now supports ExternalDhcp, PxeServer, NetscalerMPXLoadBalancer, NetscalerVPXLoadBalancer, NetscalerSDXLoadBalancer, F5BigIpLoadBalancer, JuniperSRXFirewall") + @Parameter(name = ApiConstants.NETWORK_DEVICE_TYPE, type = CommandType.STRING, required = true, description = "Netscaler device type supports NetscalerMPXLoadBalancer, NetscalerVPXLoadBalancer, NetscalerSDXLoadBalancer") private String deviceType; ///////////////////////////////////////////////////// diff --git a/server/src/com/cloud/api/commands/AddSrxFirewallCmd.java b/server/src/com/cloud/api/commands/AddSrxFirewallCmd.java new file mode 100644 index 00000000000..0fab0f0f41f --- /dev/null +++ b/server/src/com/cloud/api/commands/AddSrxFirewallCmd.java @@ -0,0 +1,135 @@ +/** + * 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.BaseAsyncCmd; +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.SrxFirewallResponse; +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.ExternalFirewallDeviceVO; +import com.cloud.network.element.JuniperSRXFirewallElementService; +import com.cloud.user.UserContext; +import com.cloud.utils.exception.CloudRuntimeException; + +@Implementation(responseObject=SrxFirewallResponse.class, description="Adds a SRX firewall device") +public class AddSrxFirewallCmd extends BaseAsyncCmd { + public static final Logger s_logger = Logger.getLogger(AddSrxFirewallCmd.class.getName()); + private static final String s_name = "addsrxfirewallresponse"; + @PlugService JuniperSRXFirewallElementService _srxFwService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="physical_network") + @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, required=true, description="the Physical Network ID") + private Long physicalNetworkId; + + @Parameter(name=ApiConstants.URL, type=CommandType.STRING, required = true, description="URL of the SRX appliance.") + private String url; + + @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Credentials to reach SRX firewall device") + private String username; + + @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Credentials to reach SRX firewall device") + private String password; + + @Parameter(name = ApiConstants.NETWORK_DEVICE_TYPE, type = CommandType.STRING, required = true, description = "supports only JuniperSRXFirewall") + private String deviceType; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getPhysicalNetworkId() { + return physicalNetworkId; + } + + public String getUrl() { + return url; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public String getDeviceType() { + return deviceType; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + try { + ExternalFirewallDeviceVO fwDeviceVO = _srxFwService.addSrxFirewall(this); + if (fwDeviceVO != null) { + SrxFirewallResponse response = _srxFwService.createSrxFirewallResponse(fwDeviceVO); + response.setObjectName("srxfirewall"); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to add SRX firewall due to 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 getEventDescription() { + return "Adding a SRX firewall device"; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_EXTERAL_FIREWALL_DEVICE_ADD; + } + + @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/ConfigureF5LoadBalancerCmd.java b/server/src/com/cloud/api/commands/ConfigureF5LoadBalancerCmd.java new file mode 100644 index 00000000000..55b0cbc758e --- /dev/null +++ b/server/src/com/cloud/api/commands/ConfigureF5LoadBalancerCmd.java @@ -0,0 +1,114 @@ +/** + * 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.BaseAsyncCmd; +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.F5LoadBalancerResponse; +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.ExternalLoadBalancerDeviceVO; +import com.cloud.network.element.F5ExternalLoadBalancerElementService; +import com.cloud.user.UserContext; +import com.cloud.utils.exception.CloudRuntimeException; + +@Implementation(responseObject=F5LoadBalancerResponse.class, description="configures a F5 load balancer device") +public class ConfigureF5LoadBalancerCmd extends BaseAsyncCmd { + + public static final Logger s_logger = Logger.getLogger(ConfigureF5LoadBalancerCmd.class.getName()); + private static final String s_name = "configuref5Rloadbalancerresponse"; + @PlugService F5ExternalLoadBalancerElementService _f5DeviceManagerService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="external_load_balancer_devices") + @Parameter(name=ApiConstants.LOAD_BALANCER_DEVICE_ID, type=CommandType.LONG, required=true, description="F5 load balancer device ID") + private Long lbDeviceId; + + @Parameter(name=ApiConstants.LOAD_BALANCER_DEVICE_CAPACITY, type=CommandType.LONG, required=false, description="capacity of the device, Capacity will be interpreted as number of networks device can handle") + private Long capacity; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getLoadBalancerDeviceId() { + return lbDeviceId; + } + + public Long getLoadBalancerCapacity() { + return capacity; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + try { + ExternalLoadBalancerDeviceVO lbDeviceVO = _f5DeviceManagerService.configureF5LoadBalancer(this); + if (lbDeviceVO != null) { + F5LoadBalancerResponse response = _f5DeviceManagerService.createF5LoadBalancerResponse(lbDeviceVO); + response.setObjectName("f5loadbalancer"); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to configure F5 load balancer due to 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 getEventDescription() { + return "Configuring a F5 load balancer device"; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_EXTERAL_LB_DEVICE_CONFIGURE; + } + + @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/ConfigureNetscalerLoadBalancerCmd.java b/server/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java index 492562df6ba..722a10c7765 100644 --- a/server/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java +++ b/server/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java @@ -52,7 +52,7 @@ public class ConfigureNetscalerLoadBalancerCmd extends BaseAsyncCmd { ///////////////////////////////////////////////////// @IdentityMapper(entityTableName="external_load_balancer_devices") - @Parameter(name=ApiConstants.LOAD_BALANCER_DEVICE_ID, type=CommandType.LONG, required=true, description="the Physical Network ID") + @Parameter(name=ApiConstants.LOAD_BALANCER_DEVICE_ID, type=CommandType.LONG, required=true, description="Netscaler load balancer device ID") private Long lbDeviceId; @Parameter(name=ApiConstants.LOAD_BALANCER_DEVICE_CAPACITY, type=CommandType.LONG, required=false, description="capacity of the device, Capacity will be interpreted as number of networks device can handle") diff --git a/server/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java b/server/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java new file mode 100644 index 00000000000..c2d05536dca --- /dev/null +++ b/server/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java @@ -0,0 +1,115 @@ +/** + * 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.BaseAsyncCmd; +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.SrxFirewallResponse; +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.ExternalFirewallDeviceVO; +import com.cloud.network.element.JuniperSRXFirewallElementService; +import com.cloud.user.UserContext; +import com.cloud.utils.exception.CloudRuntimeException; + +@Implementation(responseObject=SrxFirewallResponse.class, description="Configures a SRX firewall device") +public class ConfigureSrxFirewallCmd extends BaseAsyncCmd { + + public static final Logger s_logger = Logger.getLogger(ConfigureSrxFirewallCmd.class.getName()); + private static final String s_name = "configuresrxfirewallresponse"; + @PlugService JuniperSRXFirewallElementService _srxFwService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="external_load_balancer_devices") + @Parameter(name=ApiConstants.FIREWALL_DEVICE_ID, type=CommandType.LONG, required=true, description="SRX firewall device ID") + private Long fwDeviceId; + + @Parameter(name=ApiConstants.FIREWALL_DEVICE_CAPACITY, type=CommandType.LONG, required=false, description="capacity of the firewall device, Capacity will be interpreted as number of networks device can handle") + private Long capacity; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getFirewallDeviceId() { + return fwDeviceId; + } + + public Long getFirewallCapacity() { + return capacity; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + try { + ExternalFirewallDeviceVO fwDeviceVO = _srxFwService.configureSrxFirewall(this); + if (fwDeviceVO != null) { + SrxFirewallResponse response = _srxFwService.createSrxFirewallResponse(fwDeviceVO); + response.setObjectName("srxfirewall"); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to configure SRX firewall device due to 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 getEventDescription() { + return "Configuring a SRX firewall device"; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_EXTERAL_FIREWALL_DEVICE_CONFIGURE; + } + + @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/DeleteF5LoadBalancerCmd.java b/server/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java new file mode 100644 index 00000000000..d5fb236b2bf --- /dev/null +++ b/server/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java @@ -0,0 +1,106 @@ +/** + * 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.BaseAsyncCmd; + +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.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.F5ExternalLoadBalancerElementService; +import com.cloud.user.UserContext; +import com.cloud.utils.exception.CloudRuntimeException; + +@Implementation(responseObject=SuccessResponse.class, description=" delete a F5 load balancer device") +public class DeleteF5LoadBalancerCmd extends BaseAsyncCmd { + public static final Logger s_logger = Logger.getLogger(DeleteF5LoadBalancerCmd.class.getName()); + private static final String s_name = "deletef5loadbalancerresponse"; + @PlugService F5ExternalLoadBalancerElementService _f5DeviceManagerService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="external_load_balancer_devices") + @Parameter(name=ApiConstants.LOAD_BALANCER_DEVICE_ID, type=CommandType.LONG, required=true, description="netscaler load balancer device ID") + private Long lbDeviceId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getLoadBalancerDeviceId() { + return lbDeviceId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + try { + boolean result = _f5DeviceManagerService.deleteF5LoadBalancer(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete F5 load balancer."); + } + } 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 getEventDescription() { + return "Deleting a F5 load balancer device"; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_LOAD_BALANCER_DELETE; + } + + @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/DeleteSrxFirewallCmd.java b/server/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java new file mode 100644 index 00000000000..499830c73c1 --- /dev/null +++ b/server/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java @@ -0,0 +1,105 @@ +/** + * 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.BaseAsyncCmd; +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.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.JuniperSRXFirewallElementService; +import com.cloud.user.UserContext; +import com.cloud.utils.exception.CloudRuntimeException; + +@Implementation(responseObject=SuccessResponse.class, description=" delete a SRX firewall device") +public class DeleteSrxFirewallCmd extends BaseAsyncCmd { + public static final Logger s_logger = Logger.getLogger(DeleteSrxFirewallCmd.class.getName()); + private static final String s_name = "deletesrxfirewallresponse"; + @PlugService JuniperSRXFirewallElementService _srxElementService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="external_firewall_devices") + @Parameter(name=ApiConstants.FIREWALL_DEVICE_ID, type=CommandType.LONG, required=true, description="srx firewall device ID") + private Long fwDeviceId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getFirewallDeviceId() { + return fwDeviceId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + try { + boolean result = _srxElementService.deleteSrxFirewall(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete SRX firewall device"); + } + } 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 getEventDescription() { + return "Deleting SRX firewall device"; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_EXTERAL_FIREWALL_DEVICE_DELETE; + } + + @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/ListF5LoadBalancerNetworksCmd.java b/server/src/com/cloud/api/commands/ListF5LoadBalancerNetworksCmd.java new file mode 100644 index 00000000000..ef3ad163413 --- /dev/null +++ b/server/src/com/cloud/api/commands/ListF5LoadBalancerNetworksCmd.java @@ -0,0 +1,100 @@ +/** + * 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 java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseCmd; +import com.cloud.api.BaseListCmd; +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.ListResponse; +import com.cloud.api.response.NetworkResponse; +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.Network; +import com.cloud.network.element.F5ExternalLoadBalancerElementService; +import com.cloud.utils.exception.CloudRuntimeException; + +@Implementation(responseObject=NetworkResponse.class, description="lists network that are using a F5 load balancer device") +public class ListF5LoadBalancerNetworksCmd extends BaseListCmd { + + public static final Logger s_logger = Logger.getLogger(ListF5LoadBalancerNetworksCmd.class.getName()); + private static final String s_name = "listf5loadbalancernetworksresponse"; + @PlugService F5ExternalLoadBalancerElementService _f5DeviceManagerService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="external_load_balancer_devices") + @Parameter(name=ApiConstants.LOAD_BALANCER_DEVICE_ID, type=CommandType.LONG, required = true, description="f5 load balancer device ID") + private Long lbDeviceId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getLoadBalancerDeviceId() { + return lbDeviceId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + try { + List networks = _f5DeviceManagerService.listNetworks(this); + ListResponse response = new ListResponse(); + List networkResponses = new ArrayList(); + + if (networks != null && !networks.isEmpty()) { + for (Network network : networks) { + NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(network); + networkResponses.add(networkResponse); + } + } + + response.setResponses(networkResponses); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } 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; + } +} diff --git a/server/src/com/cloud/api/commands/ListF5LoadBalancersCmd.java b/server/src/com/cloud/api/commands/ListF5LoadBalancersCmd.java new file mode 100644 index 00000000000..1d2ae169ecb --- /dev/null +++ b/server/src/com/cloud/api/commands/ListF5LoadBalancersCmd.java @@ -0,0 +1,107 @@ +/** + * 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 java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseCmd; +import com.cloud.api.BaseListCmd; +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.F5LoadBalancerResponse; +import com.cloud.api.response.ListResponse; +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.ExternalLoadBalancerDeviceVO; +import com.cloud.network.element.F5ExternalLoadBalancerElementService; +import com.cloud.utils.exception.CloudRuntimeException; + +@Implementation(responseObject=F5LoadBalancerResponse.class, description="lists F5 load balancer devices") +public class ListF5LoadBalancersCmd extends BaseListCmd { + public static final Logger s_logger = Logger.getLogger(ListF5LoadBalancersCmd.class.getName()); + private static final String s_name = "listf5loadbalancerresponse"; + @PlugService F5ExternalLoadBalancerElementService _f5DeviceManagerService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="physical_network") + @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="the Physical Network ID") + private Long physicalNetworkId; + + @IdentityMapper(entityTableName="external_load_balancer_devices") + @Parameter(name=ApiConstants.LOAD_BALANCER_DEVICE_ID, type=CommandType.LONG, description="f5 load balancer device ID") + private Long lbDeviceId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getLoadBalancerDeviceId() { + return lbDeviceId; + } + + public Long getPhysicalNetworkId() { + return physicalNetworkId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + try { + List lbDevices = _f5DeviceManagerService.listF5LoadBalancers(this); + ListResponse response = new ListResponse(); + List lbDevicesResponse = new ArrayList(); + + if (lbDevices != null && !lbDevices.isEmpty()) { + for (ExternalLoadBalancerDeviceVO lbDeviceVO : lbDevices) { + F5LoadBalancerResponse lbdeviceResponse = _f5DeviceManagerService.createF5LoadBalancerResponse(lbDeviceVO); + lbDevicesResponse.add(lbdeviceResponse); + } + } + + response.setResponses(lbDevicesResponse); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } 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; + } +} diff --git a/server/src/com/cloud/api/commands/ListNetscalerLoadBalancerNetworksCmd.java b/server/src/com/cloud/api/commands/ListNetscalerLoadBalancerNetworksCmd.java index d794ba6f159..3ef2ce1c44b 100644 --- a/server/src/com/cloud/api/commands/ListNetscalerLoadBalancerNetworksCmd.java +++ b/server/src/com/cloud/api/commands/ListNetscalerLoadBalancerNetworksCmd.java @@ -1,3 +1,21 @@ +/** + * 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 java.util.ArrayList; diff --git a/server/src/com/cloud/api/commands/ListSrxFirewallNetworksCmd.java b/server/src/com/cloud/api/commands/ListSrxFirewallNetworksCmd.java new file mode 100644 index 00000000000..a65089fe35b --- /dev/null +++ b/server/src/com/cloud/api/commands/ListSrxFirewallNetworksCmd.java @@ -0,0 +1,100 @@ +/** + * 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 java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseCmd; +import com.cloud.api.BaseListCmd; +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.ListResponse; +import com.cloud.api.response.NetworkResponse; +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.Network; +import com.cloud.network.element.JuniperSRXFirewallElementService; +import com.cloud.utils.exception.CloudRuntimeException; + +@Implementation(responseObject=NetworkResponse.class, description="lists network that are using SRX firewall device") +public class ListSrxFirewallNetworksCmd extends BaseListCmd { + + public static final Logger s_logger = Logger.getLogger(ListSrxFirewallNetworksCmd.class.getName()); + private static final String s_name = "listsrxfirewallnetworksresponse"; + @PlugService JuniperSRXFirewallElementService _srxFwService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="external_firewall_devices") + @Parameter(name=ApiConstants.LOAD_BALANCER_DEVICE_ID, type=CommandType.LONG, required = true, description="netscaler load balancer device ID") + private Long fwDeviceId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getFirewallDeviceId() { + return fwDeviceId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + try { + List networks = _srxFwService.listNetworks(this); + ListResponse response = new ListResponse(); + List networkResponses = new ArrayList(); + + if (networks != null && !networks.isEmpty()) { + for (Network network : networks) { + NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(network); + networkResponses.add(networkResponse); + } + } + + response.setResponses(networkResponses); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } 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; + } +} diff --git a/server/src/com/cloud/api/commands/ListSrxFirewallsCmd.java b/server/src/com/cloud/api/commands/ListSrxFirewallsCmd.java new file mode 100644 index 00000000000..73fceb38624 --- /dev/null +++ b/server/src/com/cloud/api/commands/ListSrxFirewallsCmd.java @@ -0,0 +1,108 @@ +/** + * 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 java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseCmd; +import com.cloud.api.BaseListCmd; +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.ListResponse; +import com.cloud.api.response.SrxFirewallResponse; +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.ExternalFirewallDeviceVO; +import com.cloud.network.element.JuniperSRXFirewallElementService; +import com.cloud.utils.exception.CloudRuntimeException; + +@Implementation(responseObject=SrxFirewallResponse.class, description="lists SRX firewall devices in a physical network") +public class ListSrxFirewallsCmd extends BaseListCmd { + + public static final Logger s_logger = Logger.getLogger(ListSrxFirewallsCmd.class.getName()); + private static final String s_name = "listsrxfirewallresponse"; + @PlugService JuniperSRXFirewallElementService _srxFwService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="physical_network") + @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="the Physical Network ID") + private Long physicalNetworkId; + + @IdentityMapper(entityTableName="external_firewall_devices") + @Parameter(name=ApiConstants.FIREWALL_DEVICE_ID, type=CommandType.LONG, description="SRX firewall device ID") + private Long fwDeviceId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getFirewallDeviceId() { + return fwDeviceId; + } + + public Long getPhysicalNetworkId() { + return physicalNetworkId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + try { + List fwDevices = _srxFwService.listSrxFirewalls(this); + ListResponse response = new ListResponse(); + List fwDevicesResponse = new ArrayList(); + + if (fwDevices != null && !fwDevices.isEmpty()) { + for (ExternalFirewallDeviceVO fwDeviceVO : fwDevices) { + SrxFirewallResponse lbdeviceResponse = _srxFwService.createSrxFirewallResponse(fwDeviceVO); + fwDevicesResponse.add(lbdeviceResponse); + } + } + + response.setResponses(fwDevicesResponse); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } 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; + } +} diff --git a/server/src/com/cloud/network/ExternalFirewallDeviceManager.java b/server/src/com/cloud/network/ExternalFirewallDeviceManager.java index 9f0582ba5a0..8e021052e6b 100644 --- a/server/src/com/cloud/network/ExternalFirewallDeviceManager.java +++ b/server/src/com/cloud/network/ExternalFirewallDeviceManager.java @@ -45,7 +45,7 @@ public interface ExternalFirewallDeviceManager extends Manager { * @param server resource that will handle the commands specific to this device * @return Host object for the device added */ - public Host addExternalFirewall(long physicalNetworkId, String url, String username, String password, String deviceName, ServerResource resource); + public ExternalFirewallDeviceVO addExternalFirewall(long physicalNetworkId, String url, String username, String password, String deviceName, ServerResource resource); /** * deletes load balancer device added in to a physical network diff --git a/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java index f66b51312d9..e3cbf23c0fe 100644 --- a/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java +++ b/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java @@ -1,3 +1,22 @@ +/** + * * 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.network; import java.net.URI; @@ -67,7 +86,6 @@ import com.cloud.resource.ResourceManager; import com.cloud.resource.ResourceStateAdapter; import com.cloud.resource.ServerResource; import com.cloud.resource.UnableDeleteHostException; -import com.cloud.resource.ResourceStateAdapter.DeleteHostAnswer; import com.cloud.server.api.response.ExternalFirewallResponse; import com.cloud.user.Account; import com.cloud.user.AccountManager; @@ -120,7 +138,7 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl @Override @DB - public Host addExternalFirewall(long physicalNetworkId, String url, String username, String password, String deviceName, ServerResource resource) { + public ExternalFirewallDeviceVO addExternalFirewall(long physicalNetworkId, String url, String username, String password, String deviceName, ServerResource resource) { String guid; PhysicalNetworkVO pNetwork=null; NetworkDevice ntwkDevice = NetworkDevice.getNetworkDevice(deviceName); @@ -188,7 +206,7 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl _hostDetailDao.persist(hostDetail); txn.commit(); - return externalFirewall; + return fwDevice; } else { return null; } diff --git a/server/src/com/cloud/network/ExternalFirewallDeviceVO.java b/server/src/com/cloud/network/ExternalFirewallDeviceVO.java index 803f77ddbf3..2ba07133a36 100644 --- a/server/src/com/cloud/network/ExternalFirewallDeviceVO.java +++ b/server/src/com/cloud/network/ExternalFirewallDeviceVO.java @@ -116,6 +116,10 @@ public class ExternalFirewallDeviceVO { return capacity; } + public void setCapacity(long capacity) { + this.capacity = capacity; + } + public FirewallDeviceState getState() { return state; } diff --git a/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java index 9ca1e53157d..9a1d37ab517 100644 --- a/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java +++ b/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java @@ -57,7 +57,6 @@ import com.cloud.network.dao.LoadBalancerDao; import com.cloud.network.dao.NetworkDao; import com.cloud.network.dao.NetworkExternalFirewallDao; import com.cloud.network.dao.NetworkExternalLoadBalancerDao; -import com.cloud.network.dao.NetworkServiceMapDao; import com.cloud.network.dao.PhysicalNetworkDao; import com.cloud.network.dao.PhysicalNetworkServiceProviderDao; import com.cloud.network.dao.VpnUserDao; @@ -182,7 +181,12 @@ public class ExternalNetworkDeviceManagerImpl implements ExternalNetworkDeviceMa String username = (String) params.get(ApiConstants.USERNAME); String password = (String) params.get(ApiConstants.PASSWORD); ExternalFirewallDeviceManager fwDeviceManager = (ExternalFirewallDeviceManager) _srxElementService; - return fwDeviceManager.addExternalFirewall(physicalNetworkId, url, username, password, NetworkDevice.JuniperSRXFirewall.getName(),new JuniperSrxResource()); + ExternalFirewallDeviceVO fwDeviceVO = fwDeviceManager.addExternalFirewall(physicalNetworkId, url, username, password, NetworkDevice.JuniperSRXFirewall.getName(),new JuniperSrxResource()); + if (fwDeviceVO != null) { + return _hostDao.findById(fwDeviceVO.getHostId()); + } else { + throw new CloudRuntimeException("Failed to add SRX firewall device due to internal error"); + } } else if (cmd.getDeviceType().equalsIgnoreCase(NetworkDevice.NetscalerMPXLoadBalancer.getName()) || cmd.getDeviceType().equalsIgnoreCase(NetworkDevice.NetscalerVPXLoadBalancer.getName()) || cmd.getDeviceType().equalsIgnoreCase(NetworkDevice.NetscalerSDXLoadBalancer.getName())) { @@ -193,7 +197,11 @@ public class ExternalNetworkDeviceManagerImpl implements ExternalNetworkDeviceMa ExternalLoadBalancerDeviceManager lbDeviceMgr = (ExternalLoadBalancerDeviceManager) _netsclarLbService; ExternalLoadBalancerDeviceVO lbDeviceVO = lbDeviceMgr.addExternalLoadBalancer(physicalNetworkId, url, username, password, cmd.getDeviceType(), (ServerResource) new NetscalerResource()); - return _hostDao.findById(lbDeviceVO.getHostId()); + if (lbDeviceVO != null) { + return _hostDao.findById(lbDeviceVO.getHostId()); + } else { + throw new CloudRuntimeException("Failed to add Netscaler load balancer device due to internal error"); + } } else if (cmd.getDeviceType().equalsIgnoreCase(NetworkDevice.F5BigIpLoadBalancer.getName())) { Long physicalNetworkId = (params.get(ApiConstants.PHYSICAL_NETWORK_ID)==null)?Long.parseLong((String)params.get(ApiConstants.PHYSICAL_NETWORK_ID)):null; String url = (String) params.get(ApiConstants.URL); @@ -202,7 +210,11 @@ public class ExternalNetworkDeviceManagerImpl implements ExternalNetworkDeviceMa ExternalLoadBalancerDeviceManager lbDeviceMgr = (ExternalLoadBalancerDeviceManager) _f5LbElementService; ExternalLoadBalancerDeviceVO lbDeviceVO = lbDeviceMgr.addExternalLoadBalancer(physicalNetworkId, url, username, password, cmd.getDeviceType(), (ServerResource) new F5BigIpResource()); - return _hostDao.findById(lbDeviceVO.getHostId()); + if (lbDeviceVO != null) { + return _hostDao.findById(lbDeviceVO.getHostId()); + } else { + throw new CloudRuntimeException("Failed to add Netscaler load balancer device due to internal error"); + } } else { throw new CloudRuntimeException("Unsupported network device type:" + cmd.getDeviceType()); } diff --git a/server/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java b/server/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java index b80e79a3e26..781997d399e 100644 --- a/server/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java +++ b/server/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java @@ -19,6 +19,7 @@ package com.cloud.network.element; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -28,8 +29,14 @@ import javax.ejb.Local; import org.apache.log4j.Logger; import com.cloud.api.commands.AddExternalLoadBalancerCmd; +import com.cloud.api.commands.AddF5LoadBalancerCmd; +import com.cloud.api.commands.ConfigureF5LoadBalancerCmd; import com.cloud.api.commands.DeleteExternalLoadBalancerCmd; +import com.cloud.api.commands.DeleteF5LoadBalancerCmd; import com.cloud.api.commands.ListExternalLoadBalancersCmd; +import com.cloud.api.commands.ListF5LoadBalancerNetworksCmd; +import com.cloud.api.commands.ListF5LoadBalancersCmd; +import com.cloud.api.response.F5LoadBalancerResponse; import com.cloud.configuration.ConfigurationManager; import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenterVO; @@ -46,6 +53,9 @@ import com.cloud.host.dao.HostDao; import com.cloud.network.ExternalLoadBalancerDeviceManager; import com.cloud.network.ExternalLoadBalancerDeviceManagerImpl; import com.cloud.network.ExternalLoadBalancerDeviceVO; +import com.cloud.network.NetworkExternalLoadBalancerVO; +import com.cloud.network.NetworkVO; +import com.cloud.network.ExternalLoadBalancerDeviceVO.LBDeviceState; import com.cloud.network.ExternalNetworkDeviceManager.NetworkDevice; import com.cloud.network.Network; import com.cloud.network.Network.Capability; @@ -55,6 +65,9 @@ import com.cloud.network.NetworkManager; import com.cloud.network.Networks.TrafficType; import com.cloud.network.PhysicalNetworkServiceProvider; import com.cloud.network.PhysicalNetworkVO; +import com.cloud.network.dao.ExternalLoadBalancerDeviceDao; +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkExternalLoadBalancerDao; import com.cloud.network.dao.NetworkServiceMapDao; import com.cloud.network.dao.PhysicalNetworkDao; import com.cloud.network.lb.LoadBalancingRule; @@ -63,6 +76,7 @@ import com.cloud.offering.NetworkOffering; import com.cloud.resource.ServerResource; import com.cloud.server.api.response.ExternalLoadBalancerResponse; import com.cloud.utils.component.Inject; +import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; import com.cloud.vm.VirtualMachine; @@ -80,6 +94,9 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan @Inject DataCenterDao _dcDao; @Inject PhysicalNetworkDao _physicalNetworkDao; @Inject HostDao _hostDao; + @Inject ExternalLoadBalancerDeviceDao _lbDeviceDao; + @Inject NetworkExternalLoadBalancerDao _networkLBDao; + @Inject NetworkDao _networkDao; private boolean canHandle(Network config) { DataCenter zone = _configMgr.getZone(config.getDataCenterId()); @@ -102,7 +119,7 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan try { return manageGuestNetworkWithExternalLoadBalancer(true, guestConfig); } catch (InsufficientCapacityException capacityException) { - // TODO: handle out of capacity exception + // TODO: handle out of capacity exception in graceful manner when multiple providers are avaialble for the network return false; } } @@ -179,8 +196,17 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan @Override public boolean isReady(PhysicalNetworkServiceProvider provider) { - // TODO Auto-generated method stub - return true; + List lbDevices = _lbDeviceDao.listByPhysicalNetworkAndProvider(provider.getPhysicalNetworkId(), Provider.F5BigIp.getName()); + + // true if at-least one F5 device is added in to physical network and is in configured (in enabled state) state + if (lbDevices != null && !lbDevices.isEmpty()) { + for (ExternalLoadBalancerDeviceVO lbDevice : lbDevices) { + if (lbDevice.getState() == LBDeviceState.Enabled) { + return true; + } + } + } + return false; } @Override @@ -267,4 +293,120 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan public ExternalLoadBalancerResponse createExternalLoadBalancerResponse(Host externalLb) { return super.createExternalLoadBalancerResponse(externalLb); } + + @Override + public ExternalLoadBalancerDeviceVO addF5LoadBalancer(AddF5LoadBalancerCmd cmd) { + String deviceName = cmd.getDeviceType(); + if (!deviceName.equalsIgnoreCase(NetworkDevice.F5BigIpLoadBalancer.getName())) { + throw new InvalidParameterValueException("Invalid F5 load balancer device type"); + } + + return addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceName, (ServerResource) new F5BigIpResource()); + + } + + @Override + public boolean deleteF5LoadBalancer(DeleteF5LoadBalancerCmd cmd) { + Long lbDeviceId = cmd.getLoadBalancerDeviceId(); + + ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId); + if ((lbDeviceVo == null) || !lbDeviceVo.getDeviceName().equalsIgnoreCase(NetworkDevice.F5BigIpLoadBalancer.getName())) { + throw new InvalidParameterValueException("No F5 load balancer device found with ID: " + lbDeviceId); + } + + return deleteExternalLoadBalancer(lbDeviceVo.getHostId()); + } + + @Override + public ExternalLoadBalancerDeviceVO configureF5LoadBalancer(ConfigureF5LoadBalancerCmd cmd) { + Long lbDeviceId = cmd.getLoadBalancerDeviceId(); + Long capacity = cmd.getLoadBalancerCapacity(); + + ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId); + if ((lbDeviceVo == null) || !lbDeviceVo.getDeviceName().equalsIgnoreCase(NetworkDevice.F5BigIpLoadBalancer.getName())) { + throw new InvalidParameterValueException("No F5 load balancer device found with ID: " + lbDeviceId); + } + + if (capacity != null) { + // check if any networks are using this F5 device + List networks = _networkLBDao.listByLoadBalancerDeviceId(lbDeviceId); + if ((networks != null) && !networks.isEmpty()) { + if (capacity < networks.size()) { + throw new CloudRuntimeException("There are more number of networks already using this F5 device than configured capacity"); + } + } + if (capacity != null) { + lbDeviceVo.setCapacity(capacity); + } + } + + lbDeviceVo.setState(LBDeviceState.Enabled); + _lbDeviceDao.update(lbDeviceId, lbDeviceVo); + return lbDeviceVo; + } + + @Override + public List listF5LoadBalancers(ListF5LoadBalancersCmd cmd) { + Long physcialNetworkId = cmd.getPhysicalNetworkId(); + Long lbDeviceId = cmd.getLoadBalancerDeviceId(); + PhysicalNetworkVO pNetwork = null; + List lbDevices = new ArrayList (); + + if (physcialNetworkId == null && lbDeviceId == null) { + throw new InvalidParameterValueException("Either physical network Id or load balancer device Id must be specified"); + } + + if (lbDeviceId != null) { + ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId); + if (lbDeviceVo == null || !lbDeviceVo.getDeviceName().equalsIgnoreCase(NetworkDevice.F5BigIpLoadBalancer.getName())) { + throw new InvalidParameterValueException("Could not find F5 load balancer device with ID: " + lbDeviceId); + } + lbDevices.add(lbDeviceVo); + return lbDevices; + } + + if (physcialNetworkId != null) { + pNetwork = _physicalNetworkDao.findById(physcialNetworkId); + if (pNetwork == null) { + throw new InvalidParameterValueException("Could not find phyical network with ID: " + physcialNetworkId); + } + lbDevices = _lbDeviceDao.listByPhysicalNetworkAndProvider(physcialNetworkId, Provider.F5BigIp.getName()); + return lbDevices; + } + + return null; + } + + @Override + public List listNetworks(ListF5LoadBalancerNetworksCmd cmd) { + Long lbDeviceId = cmd.getLoadBalancerDeviceId(); + List networks = new ArrayList(); + + ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId); + if (lbDeviceVo == null || !lbDeviceVo.getDeviceName().equalsIgnoreCase(NetworkDevice.F5BigIpLoadBalancer.getName())) { + throw new InvalidParameterValueException("Could not find F5 load balancer device with ID " + lbDeviceId); + } + + List networkLbMaps = _networkLBDao.listByLoadBalancerDeviceId(lbDeviceId); + if (networkLbMaps != null && !networkLbMaps.isEmpty()) { + for (NetworkExternalLoadBalancerVO networkLbMap : networkLbMaps) { + NetworkVO network = _networkDao.findById(networkLbMap.getNetworkId()); + networks.add(network); + } + } + + return networks; + } + + @Override + public F5LoadBalancerResponse createF5LoadBalancerResponse(ExternalLoadBalancerDeviceVO lbDeviceVO) { + F5LoadBalancerResponse response = new F5LoadBalancerResponse(); + response.setId(lbDeviceVO.getId()); + response.setPhysicalNetworkId(lbDeviceVO.getPhysicalNetworkId()); + response.setDeviceName(lbDeviceVO.getDeviceName()); + response.setDeviceCapacity(lbDeviceVO.getCapacity()); + response.setProvider(lbDeviceVO.getProviderName()); + response.setDeviceState(lbDeviceVO.getState().name()); + return response; + } } diff --git a/server/src/com/cloud/network/element/F5ExternalLoadBalancerElementService.java b/server/src/com/cloud/network/element/F5ExternalLoadBalancerElementService.java index b95c1e50117..89e639102d8 100644 --- a/server/src/com/cloud/network/element/F5ExternalLoadBalancerElementService.java +++ b/server/src/com/cloud/network/element/F5ExternalLoadBalancerElementService.java @@ -21,15 +21,61 @@ package com.cloud.network.element; import java.util.List; import com.cloud.api.commands.AddExternalLoadBalancerCmd; +import com.cloud.api.commands.AddF5LoadBalancerCmd; +import com.cloud.api.commands.ConfigureF5LoadBalancerCmd; import com.cloud.api.commands.DeleteExternalLoadBalancerCmd; +import com.cloud.api.commands.DeleteF5LoadBalancerCmd; import com.cloud.api.commands.ListExternalLoadBalancersCmd; +import com.cloud.api.commands.ListF5LoadBalancerNetworksCmd; +import com.cloud.api.commands.ListF5LoadBalancersCmd; +import com.cloud.api.response.F5LoadBalancerResponse; import com.cloud.host.Host; +import com.cloud.network.ExternalLoadBalancerDeviceVO; +import com.cloud.network.Network; import com.cloud.server.api.response.ExternalLoadBalancerResponse; import com.cloud.utils.component.PluggableService; @SuppressWarnings("deprecation") public interface F5ExternalLoadBalancerElementService extends PluggableService { + /** + * adds a F5 load balancer device in to a physical network + * @param AddF5LoadBalancerCmd + * @return ExternalLoadBalancerDeviceVO object for the device added + */ + public ExternalLoadBalancerDeviceVO addF5LoadBalancer(AddF5LoadBalancerCmd cmd); + + /** + * removes a F5 load balancer device from a physical network + * @param DeleteF5LoadBalancerCmd + * @return true if F5 load balancer device is successfully deleted + */ + public boolean deleteF5LoadBalancer(DeleteF5LoadBalancerCmd cmd); + + /** + * configures a F5 load balancer device added in a physical network + * @param ConfigureF5LoadBalancerCmd + * @return ExternalLoadBalancerDeviceVO for the device configured + */ + public ExternalLoadBalancerDeviceVO configureF5LoadBalancer(ConfigureF5LoadBalancerCmd cmd); + + /** + * lists all the load balancer devices added in to a physical network + * @param ListF5LoadBalancersCmd + * @return list of ExternalLoadBalancerDeviceVO for the devices in the physical network. + */ + public List listF5LoadBalancers(ListF5LoadBalancersCmd cmd); + + /** + * lists all the guest networks using a F5 load balancer device + * @param ListF5LoadBalancerNetworksCmd + * @return list of the guest networks that are using this F5 load balancer + */ + public List listNetworks(ListF5LoadBalancerNetworksCmd cmd); + + public F5LoadBalancerResponse createF5LoadBalancerResponse(ExternalLoadBalancerDeviceVO lbDeviceVO); + + /* Deprecated API helper function */ @Deprecated // API helper function supported for backward compatibility public Host addExternalLoadBalancer(AddExternalLoadBalancerCmd cmd); diff --git a/server/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java b/server/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java index d9e778c21f7..5970a85d3e5 100644 --- a/server/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java +++ b/server/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java @@ -27,8 +27,14 @@ import javax.ejb.Local; import org.apache.log4j.Logger; import com.cloud.api.commands.AddExternalFirewallCmd; +import com.cloud.api.commands.AddSrxFirewallCmd; +import com.cloud.api.commands.ConfigureSrxFirewallCmd; import com.cloud.api.commands.DeleteExternalFirewallCmd; +import com.cloud.api.commands.DeleteSrxFirewallCmd; import com.cloud.api.commands.ListExternalFirewallsCmd; +import com.cloud.api.commands.ListSrxFirewallNetworksCmd; +import com.cloud.api.commands.ListSrxFirewallsCmd; +import com.cloud.api.response.SrxFirewallResponse; import com.cloud.configuration.ConfigurationManager; import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenterVO; @@ -41,20 +47,27 @@ import com.cloud.exception.InsufficientNetworkCapacityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.host.Host; +import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.network.Network; +import com.cloud.network.ExternalFirewallDeviceVO.FirewallDeviceState; import com.cloud.network.ExternalNetworkDeviceManager.NetworkDevice; import com.cloud.network.Network.Capability; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.ExternalFirewallDeviceManagerImpl; +import com.cloud.network.ExternalFirewallDeviceVO; +import com.cloud.network.NetworkExternalFirewallVO; import com.cloud.network.NetworkManager; +import com.cloud.network.NetworkVO; import com.cloud.network.PhysicalNetworkServiceProvider; import com.cloud.network.PhysicalNetworkVO; import com.cloud.network.PublicIpAddress; import com.cloud.network.RemoteAccessVpn; import com.cloud.network.VpnUser; +import com.cloud.network.dao.ExternalFirewallDeviceDao; import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkExternalFirewallDao; import com.cloud.network.dao.PhysicalNetworkDao; import com.cloud.network.resource.JuniperSrxResource; import com.cloud.network.rules.FirewallRule; @@ -64,6 +77,7 @@ import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.resource.ServerResource; import com.cloud.server.api.response.ExternalFirewallResponse; import com.cloud.utils.component.Inject; +import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; import com.cloud.vm.VirtualMachine; @@ -84,6 +98,9 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan @Inject NetworkDao _networksDao; @Inject DataCenterDao _dcDao; @Inject PhysicalNetworkDao _physicalNetworkDao; + @Inject ExternalFirewallDeviceDao _fwDevicesDao; + @Inject NetworkExternalFirewallDao _networkFirewallDao; + @Inject NetworkDao _networkDao; private boolean canHandle(Network config) { DataCenter zone = _configMgr.getZone(config.getDataCenterId()); @@ -112,19 +129,19 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan try { return manageGuestNetworkWithExternalFirewall(true, network); } catch (InsufficientCapacityException capacityException) { - // TODO: handle out of capacity exception + // TODO: handle out of capacity exception in more gracefule manner when multiple providers are present for the network return false; } } @Override public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException { - return true; + return true; } @Override public boolean release(Network config, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) { - return true; + return true; } @Override @@ -159,7 +176,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan return false; } - return applyIps(network, ipAddresses); + return applyIps(network, ipAddresses); } @@ -168,29 +185,29 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan if (!canHandle(config)) { return false; } - - return applyFirewallRules(config, rules); - } + return applyFirewallRules(config, rules); + } + @Override public boolean startVpn(Network config, RemoteAccessVpn vpn) throws ResourceUnavailableException { - if (!canHandle(config)) { + if (!canHandle(config)) { return false; } - - return manageRemoteAccessVpn(true, config, vpn); + + return manageRemoteAccessVpn(true, config, vpn); } - + @Override public boolean stopVpn(Network config, RemoteAccessVpn vpn) throws ResourceUnavailableException { - if (!canHandle(config)) { + if (!canHandle(config)) { return false; } - - return manageRemoteAccessVpn(false, config, vpn); + + return manageRemoteAccessVpn(false, config, vpn); } - + @Override public String[] applyVpnUsers(RemoteAccessVpn vpn, List users) throws ResourceUnavailableException{ Network config = _networksDao.findById(vpn.getNetworkId()); @@ -202,22 +219,22 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan boolean result = manageRemoteAccessVpnUsers(config, vpn, users); String[] results = new String[users.size()]; for (int i = 0; i < results.length; i++) { - results[i] = String.valueOf(result); + results[i] = String.valueOf(result); } return results; } - + @Override public Provider getProvider() { return Provider.JuniperSRX; } - + @Override public Map> getCapabilities() { return capabilities; } - + private static Map> setCapabilities() { Map> capabilities = new HashMap>(); @@ -260,14 +277,23 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan if (!canHandle(network)) { return false; } - - return applyFirewallRules(network, rules); + + return applyFirewallRules(network, rules); } @Override public boolean isReady(PhysicalNetworkServiceProvider provider) { - // TODO Auto-generated method stub - return true; + + List fwDevices = _fwDevicesDao.listByPhysicalNetworkAndProvider(provider.getPhysicalNetworkId(), Provider.JuniperSRX.getName()); + // true if at-least one SRX device is added in to physical network and is in configured (in enabled state) state + if (fwDevices != null && !fwDevices.isEmpty()) { + for (ExternalFirewallDeviceVO fwDevice : fwDevices) { + if (fwDevice.getState() == FirewallDeviceState.Enabled) { + return true; + } + } + } + return false; } @Override @@ -288,6 +314,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan Long zoneId = cmd.getZoneId(); DataCenterVO zone =null; PhysicalNetworkVO pNetwork=null; + HostVO fwHost = null; zone = _dcDao.findById(zoneId); if (zone == null) { @@ -302,14 +329,19 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan pNetwork = physicalNetworks.get(0); String deviceType = NetworkDevice.JuniperSRXFirewall.getName(); - return addExternalFirewall(pNetwork.getId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceType, (ServerResource) new JuniperSrxResource()); + ExternalFirewallDeviceVO fwDeviceVO = addExternalFirewall(pNetwork.getId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceType, (ServerResource) new JuniperSrxResource()); + if (fwDeviceVO != null) { + fwHost = _hostDao.findById(fwDeviceVO.getHostId()); + } + + return fwHost; } + @Override public boolean deleteExternalFirewall(DeleteExternalFirewallCmd cmd) { return deleteExternalFirewall(cmd.getId()); } - - + @Override @Deprecated // should use more generic listNetworkDevice command public List listExternalFirewalls(ListExternalFirewallsCmd cmd) { @@ -344,4 +376,116 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan public String getPropertiesFile() { return "junipersrx_commands.properties"; } + + @Override + public ExternalFirewallDeviceVO addSrxFirewall(AddSrxFirewallCmd cmd) { + String deviceName = cmd.getDeviceType(); + if (deviceName.equalsIgnoreCase(NetworkDevice.JuniperSRXFirewall.getName())) { + throw new InvalidParameterValueException("Invalid SRX firewall device type"); + } + return addExternalFirewall(cmd.getPhysicalNetworkId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceName, + (ServerResource) new JuniperSrxResource()); + } + + @Override + public boolean deleteSrxFirewall(DeleteSrxFirewallCmd cmd) { + Long fwDeviceId = cmd.getFirewallDeviceId(); + + ExternalFirewallDeviceVO fwDeviceVO = _fwDevicesDao.findById(fwDeviceId); + if (fwDeviceVO == null || !fwDeviceVO.getDeviceName().equalsIgnoreCase(NetworkDevice.JuniperSRXFirewall.getName())) { + throw new InvalidParameterValueException("No SRX firewall device found with ID: " + fwDeviceId); + } + return deleteExternalFirewall(fwDeviceId); + } + + @Override + public ExternalFirewallDeviceVO configureSrxFirewall(ConfigureSrxFirewallCmd cmd) { + Long fwDeviceId = cmd.getFirewallDeviceId(); + Long deviceCapacity = cmd.getFirewallCapacity(); + + ExternalFirewallDeviceVO fwDeviceVO = _fwDevicesDao.findById(fwDeviceId); + if (fwDeviceVO == null || !fwDeviceVO.getDeviceName().equalsIgnoreCase(NetworkDevice.JuniperSRXFirewall.getName())) { + throw new InvalidParameterValueException("No SRX firewall device found with ID: " + fwDeviceId); + } + + if (deviceCapacity != null) { + // check if any networks are using this SRX device + List networks = _networkFirewallDao.listByFirewallDeviceId(fwDeviceId); + if ((networks != null) && !networks.isEmpty()) { + if (deviceCapacity < networks.size()) { + throw new CloudRuntimeException("There are more number of networks already using this SRX firewall device than configured capacity"); + } + } + if (deviceCapacity != null) { + fwDeviceVO.setCapacity(deviceCapacity); + } + } + + fwDeviceVO.setState(FirewallDeviceState.Enabled); + _fwDevicesDao.update(fwDeviceId, fwDeviceVO); + return fwDeviceVO; + } + + @Override + public List listSrxFirewalls(ListSrxFirewallsCmd cmd) { + Long physcialNetworkId = cmd.getPhysicalNetworkId(); + Long fwDeviceId = cmd.getFirewallDeviceId(); + PhysicalNetworkVO pNetwork = null; + List fwDevices = new ArrayList (); + + if (physcialNetworkId == null && fwDeviceId == null) { + throw new InvalidParameterValueException("Either physical network Id or load balancer device Id must be specified"); + } + + if (fwDeviceId != null) { + ExternalFirewallDeviceVO fwDeviceVo = _fwDevicesDao.findById(fwDeviceId); + if (fwDeviceVo == null || !fwDeviceVo.getDeviceName().equalsIgnoreCase(NetworkDevice.JuniperSRXFirewall.getName())) { + throw new InvalidParameterValueException("Could not find SRX firewall device with ID: " + fwDeviceId); + } + fwDevices.add(fwDeviceVo); + } + + if (physcialNetworkId != null) { + pNetwork = _physicalNetworkDao.findById(physcialNetworkId); + if (pNetwork == null) { + throw new InvalidParameterValueException("Could not find phyical network with ID: " + physcialNetworkId); + } + fwDevices = _fwDevicesDao.listByPhysicalNetworkAndProvider(physcialNetworkId, Provider.F5BigIp.getName()); + } + + return fwDevices; + } + + @Override + public List listNetworks(ListSrxFirewallNetworksCmd cmd) { + Long fwDeviceId = cmd.getFirewallDeviceId(); + List networks = new ArrayList(); + + ExternalFirewallDeviceVO fwDeviceVo = _fwDevicesDao.findById(fwDeviceId); + if (fwDeviceVo == null || !fwDeviceVo.getDeviceName().equalsIgnoreCase(NetworkDevice.JuniperSRXFirewall.getName())) { + throw new InvalidParameterValueException("Could not find SRX firewall device with ID " + fwDeviceId); + } + + List networkFirewallMaps = _networkFirewallDao.listByFirewallDeviceId(fwDeviceId); + if (networkFirewallMaps != null && !networkFirewallMaps.isEmpty()) { + for (NetworkExternalFirewallVO networkFirewallMap : networkFirewallMaps) { + NetworkVO network = _networkDao.findById(networkFirewallMap.getNetworkId()); + networks.add(network); + } + } + + return networks; + } + + @Override + public SrxFirewallResponse createSrxFirewallResponse(ExternalFirewallDeviceVO fwDeviceVO) { + SrxFirewallResponse response = new SrxFirewallResponse(); + response.setId(fwDeviceVO.getId()); + response.setPhysicalNetworkId(fwDeviceVO.getPhysicalNetworkId()); + response.setDeviceName(fwDeviceVO.getDeviceName()); + response.setDeviceCapacity(fwDeviceVO.getCapacity()); + response.setProvider(fwDeviceVO.getProviderName()); + response.setDeviceState(fwDeviceVO.getState().name()); + return response; + } } \ No newline at end of file diff --git a/server/src/com/cloud/network/element/JuniperSRXFirewallElementService.java b/server/src/com/cloud/network/element/JuniperSRXFirewallElementService.java index 11d425c4763..5358cf2076f 100644 --- a/server/src/com/cloud/network/element/JuniperSRXFirewallElementService.java +++ b/server/src/com/cloud/network/element/JuniperSRXFirewallElementService.java @@ -3,14 +3,60 @@ package com.cloud.network.element; import java.util.List; import com.cloud.api.commands.AddExternalFirewallCmd; +import com.cloud.api.commands.AddSrxFirewallCmd; +import com.cloud.api.commands.ConfigureSrxFirewallCmd; import com.cloud.api.commands.DeleteExternalFirewallCmd; +import com.cloud.api.commands.DeleteSrxFirewallCmd; import com.cloud.api.commands.ListExternalFirewallsCmd; +import com.cloud.api.commands.ListSrxFirewallNetworksCmd; +import com.cloud.api.commands.ListSrxFirewallsCmd; +import com.cloud.api.response.SrxFirewallResponse; import com.cloud.host.Host; +import com.cloud.network.ExternalFirewallDeviceVO; +import com.cloud.network.Network; import com.cloud.server.api.response.ExternalFirewallResponse; import com.cloud.utils.component.PluggableService; public interface JuniperSRXFirewallElementService extends PluggableService { + /** + * adds a SRX firewall device in to a physical network + * @param AddSrxFirewallCmd + * @return ExternalFirewallDeviceVO object for the firewall added + */ + public ExternalFirewallDeviceVO addSrxFirewall(AddSrxFirewallCmd cmd); + + /** + * removes SRX firewall device from a physical network + * @param DeleteSrxFirewallCmd + * @return true if firewall device successfully deleted + */ + public boolean deleteSrxFirewall(DeleteSrxFirewallCmd cmd); + + /** + * configures a SRX firewal device added in a physical network + * @param ConfigureSrxFirewallCmd + * @return ExternalFirewallDeviceVO for the device configured + */ + public ExternalFirewallDeviceVO configureSrxFirewall(ConfigureSrxFirewallCmd cmd); + + /** + * lists all the SRX firewall devices added in to a physical network + * @param ListSrxFirewallsCmd + * @return list of ExternalFirewallDeviceVO for the devices in the physical network. + */ + public List listSrxFirewalls(ListSrxFirewallsCmd cmd); + + /** + * lists all the guest networks using a SRX firewall device + * @param ListSrxFirewallNetworksCmd + * @return list of the guest networks that are using this F5 load balancer + */ + public List listNetworks(ListSrxFirewallNetworksCmd cmd); + + public SrxFirewallResponse createSrxFirewallResponse(ExternalFirewallDeviceVO fwDeviceVO); + + @Deprecated // API helper function supported for backward compatibility public Host addExternalFirewall(AddExternalFirewallCmd cmd); diff --git a/server/src/com/cloud/network/element/NetscalerExternalLoadBalancerElement.java b/server/src/com/cloud/network/element/NetscalerExternalLoadBalancerElement.java index 46322034fff..c47587af63d 100644 --- a/server/src/com/cloud/network/element/NetscalerExternalLoadBalancerElement.java +++ b/server/src/com/cloud/network/element/NetscalerExternalLoadBalancerElement.java @@ -264,13 +264,13 @@ public class NetscalerExternalLoadBalancerElement extends ExternalLoadBalancerDe ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId); if (lbDeviceVo == null || !isNetscalerDevice(lbDeviceVo.getDeviceName())) { - throw new InvalidParameterValueException("Could not find Netscaler load balancer device with ID: " + lbDeviceId); + throw new InvalidParameterValueException("Could not find Netscaler load balancer device with ID " + lbDeviceId); } List networkLbMaps = _networkLBDao.listByLoadBalancerDeviceId(lbDeviceId); if (networkLbMaps != null && !networkLbMaps.isEmpty()) { for (NetworkExternalLoadBalancerVO networkLbMap : networkLbMaps) { - NetworkVO network = _networkDao.findById(networkLbMap.getId()); + NetworkVO network = _networkDao.findById(networkLbMap.getNetworkId()); networks.add(network); } } diff --git a/server/src/com/cloud/network/element/NetscalerLoadBalancerElementService.java b/server/src/com/cloud/network/element/NetscalerLoadBalancerElementService.java index 437baf19172..99d9652d713 100644 --- a/server/src/com/cloud/network/element/NetscalerLoadBalancerElementService.java +++ b/server/src/com/cloud/network/element/NetscalerLoadBalancerElementService.java @@ -41,7 +41,7 @@ public interface NetscalerLoadBalancerElementService extends PluggableService { /** * removes a Netscaler load balancer device from a physical network * @param DeleteNetscalerLoadBalancerCmd - * @return ExternalLoadBalancerDeviceVO object for the device deleted + * @return true if Netscaler device is deleted successfully */ public boolean deleteNetscalerLoadBalancer(DeleteNetscalerLoadBalancerCmd cmd); @@ -54,14 +54,14 @@ public interface NetscalerLoadBalancerElementService extends PluggableService { /** * lists all the load balancer devices added in to a physical network - * @param physicalNetworkId physical Network Id + * @param ListNetscalerLoadBalancersCmd * @return list of ExternalLoadBalancerDeviceVO for the devices in the physical network. */ public List listNetscalerLoadBalancers(ListNetscalerLoadBalancersCmd cmd); /** * lists all the guest networks using a Netscaler load balancer device - * @param lbDeviceId external load balancer device Id + * @param ListNetscalerLoadBalancerNetworksCmd * @return list of the guest networks that are using this Netscaler load balancer */ public List listNetworks(ListNetscalerLoadBalancerNetworksCmd cmd);