From 435e74e9148b4e23f139b4b79de1f648a6707930 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 26 Aug 2013 14:02:34 -0700 Subject: [PATCH] Commit to try something on removing getZone --- api/src/com/cloud/network/NetworkModel.java | 7 - .../cloud/network/router/VirtualRouter.java | 2 +- .../com/cloud/network/rules/RulesService.java | 6 - api/src/com/cloud/network/vpc/VpcService.java | 71 +- .../network/vpn/RemoteAccessVpnService.java | 1 + .../admin/vpc/CreatePrivateGatewayCmd.java | 11 +- .../user/address/AssociateIPAddrCmd.java | 2 +- .../firewall/DeletePortForwardingRuleCmd.java | 8 +- .../user/nat/DeleteIpForwardingRuleCmd.java | 8 +- .../user/network/CreateNetworkACLListCmd.java | 17 +- .../user/vpc/CreateStaticRouteCmd.java | 11 +- .../api/command/user/vpc/CreateVPCCmd.java | 14 +- .../user/vpn/CreateVpnConnectionCmd.java | 13 +- .../command/user/vpn/CreateVpnGatewayCmd.java | 7 +- engine/api/pom.xml | 5 + .../service/NetworkOrchestrationService.java | 43 +- engine/components-api/pom.xml | 5 + .../src/com/cloud/agent/AgentManager.java | 21 +- .../src/com/cloud/agent/Listener.java | 0 .../src/com/cloud/alert/AlertManager.java | 15 +- .../com/cloud/capacity/CapacityManager.java | 14 +- .../configuration/ConfigurationManager.java | 0 .../com/cloud/ha/HighAvailabilityManager.java | 0 .../hypervisor/HypervisorGuruManager.java | 0 .../com/cloud/network/IpAddressManager.java | 8 +- .../cloud/network/rules/FirewallManager.java | 2 +- .../com/cloud/network/rules/RulesManager.java | 2 +- .../cloud/network/vpc/NetworkACLManager.java | 0 .../src/com/cloud/network/vpc/VpcManager.java | 13 +- .../src/com/cloud/resource/Discoverer.java | 0 .../com/cloud/resource/ResourceManager.java | 0 .../cloud/resource/ResourceStateAdapter.java | 0 .../com/cloud/template/TemplateManager.java | 4 + .../cloud/vm/snapshot/VMSnapshotManager.java | 0 engine/orchestration/pom.xml | 2 + .../com/cloud/agent/manager/AgentAttache.java | 0 .../cloud/agent/manager/AgentManagerImpl.java | 15 +- .../agent/manager/ClusteredAgentAttache.java | 0 .../manager/ClusteredAgentManagerImpl.java | 14 +- .../manager/ClusteredDirectAgentAttache.java | 0 .../agent/manager/ConnectedAgentAttache.java | 0 .../agent/manager/DirectAgentAttache.java | 0 .../com/cloud/agent/manager/DummyAttache.java | 0 .../src/com/cloud/agent/manager/Routable.java | 0 .../agent/manager/SynchronousListener.java | 0 .../ClusteredAgentRebalanceService.java | 0 .../agentlb/AgentLoadBalancerPlanner.java | 0 .../ClusterBasedAgentLoadBalancerPlanner.java | 0 .../cloud/network/NetworkStateListener.java | 30 +- .../network/rules/StaticNatRuleImpl.java | 0 .../cloud/vm/VirtualMachineManagerImpl.java | 473 +++++------ .../orchestration/NetworkOrchestrator.java | 751 +++++++++--------- .../vm/VirtualMachineManagerImplTest.java | 36 +- engine/schema/pom.xml | 5 + .../com/cloud/dc/ClusterDetailsDaoImpl.java | 19 +- .../com/cloud/dc/dao/DcDetailsDaoImpl.java | 21 +- .../cloud/network/vpc/NetworkACLItemDao.java | 0 .../cloud/network/vpc/NetworkACLItemVO.java | 0 .../com/cloud/network/vpc/NetworkACLVO.java | 0 .../cloud/network/vpc/dao/NetworkACLDao.java | 0 .../network/vpc/dao/NetworkACLDaoImpl.java | 0 .../vpc/dao/NetworkACLItemDaoImpl.java | 0 .../dao/StoragePoolDetailsDaoImpl.java | 19 +- .../src/com/cloud/user/AccountDetailsDao.java | 3 +- .../com/cloud/user/AccountDetailsDaoImpl.java | 104 +-- .../cloudstack/region/PortableIpDao.java | 0 .../cloudstack/region/PortableIpDaoImpl.java | 0 .../cloudstack/region/PortableIpRangeDao.java | 0 .../region/PortableIpRangeDaoImpl.java | 0 .../cloudstack/region/PortableIpRangeVO.java | 0 .../cloudstack/region/PortableIpVO.java | 0 .../framework/config/ConfigDepot.java | 13 +- .../framework/config/ConfigDepotImpl.java | 66 +- .../framework/config/ConfigKey.java | 52 +- .../framework/config/ConfigValue.java | 72 +- .../framework/config/ConfigurationVO.java | 2 +- .../framework/config/ScopedConfigValue.java | 43 - .../jobs/impl/AsyncJobManagerImpl.java | 13 +- .../guru/BigSwitchVnsGuestNetworkGuru.java | 24 +- .../lb/InternalLoadBalancerVMManager.java | 9 +- .../lb/InternalLoadBalancerVMManagerImpl.java | 39 +- .../network/guru/OvsGuestNetworkGuru.java | 14 +- .../agent/manager/AgentMonitorService.java | 26 - .../src/com/cloud/alert/AlertManagerImpl.java | 151 ++-- server/src/com/cloud/api/ApiDBUtils.java | 3 +- .../src/com/cloud/api/ApiResponseHelper.java | 1 - .../cloud/capacity/CapacityManagerImpl.java | 27 +- .../src/com/cloud/configuration/Config.java | 73 +- .../ConfigurationManagerImpl.java | 44 +- .../cloud/hypervisor/HypervisorGuruBase.java | 10 +- .../cloud/network/IpAddressManagerImpl.java | 27 +- .../com/cloud/network/NetworkModelImpl.java | 12 - .../com/cloud/network/NetworkServiceImpl.java | 4 +- .../element/VpcVirtualRouterElement.java | 51 +- .../guru/ExternalGuestNetworkGuru.java | 4 +- .../cloud/network/guru/GuestNetworkGuru.java | 31 +- .../VirtualNetworkApplianceManager.java | 50 +- .../VirtualNetworkApplianceManagerImpl.java | 42 +- ...VpcVirtualNetworkApplianceManagerImpl.java | 6 +- .../cloud/network/rules/RulesManagerImpl.java | 5 +- .../network/vpc/NetworkACLManagerImpl.java | 6 +- .../network/vpc/NetworkACLServiceImpl.java | 53 +- .../com/cloud/network/vpc/VpcManagerImpl.java | 34 +- .../vpn/RemoteAccessVpnManagerImpl.java | 72 +- .../cloud/resource/ResourceManagerImpl.java | 16 +- .../com/cloud/server/ConfigurationServer.java | 1 - .../cloud/server/ConfigurationServerImpl.java | 80 +- .../cloud/server/ManagementServerImpl.java | 22 +- .../com/cloud/storage/StorageManagerImpl.java | 13 +- .../cloud/template/TemplateAdapterBase.java | 21 +- .../cloud/template/TemplateManagerImpl.java | 25 +- server/src/com/cloud/vm/UserVmManager.java | 6 + .../src/com/cloud/vm/UserVmManagerImpl.java | 56 +- .../cloud/network/MockNetworkModelImpl.java | 18 +- .../cloud/network/MockRulesManagerImpl.java | 258 ------ .../com/cloud/vpc/MockNetworkManagerImpl.java | 13 - .../com/cloud/vpc/MockNetworkModelImpl.java | 19 +- .../com/cloud/vpc/MockVpcManagerImpl.java | 386 --------- .../com/cloud/vpc/NetworkACLServiceTest.java | 15 +- server/test/com/cloud/vpc/VpcApiUnitTest.java | 20 +- server/test/com/cloud/vpc/VpcTest.java | 4 +- .../component/ComponentLifecycleBase.java | 14 + 122 files changed, 1615 insertions(+), 2253 deletions(-) rename {server => engine/components-api}/src/com/cloud/agent/AgentManager.java (89%) rename {core => engine/components-api}/src/com/cloud/agent/Listener.java (100%) rename {server => engine/components-api}/src/com/cloud/alert/AlertManager.java (70%) rename {server => engine/components-api}/src/com/cloud/capacity/CapacityManager.java (73%) rename {server => engine/components-api}/src/com/cloud/configuration/ConfigurationManager.java (100%) rename {server => engine/components-api}/src/com/cloud/ha/HighAvailabilityManager.java (100%) rename {server => engine/components-api}/src/com/cloud/hypervisor/HypervisorGuruManager.java (100%) rename {server => engine/components-api}/src/com/cloud/network/rules/FirewallManager.java (99%) rename {server => engine/components-api}/src/com/cloud/network/rules/RulesManager.java (98%) rename {server => engine/components-api}/src/com/cloud/network/vpc/NetworkACLManager.java (100%) rename {server => engine/components-api}/src/com/cloud/network/vpc/VpcManager.java (94%) rename {server => engine/components-api}/src/com/cloud/resource/Discoverer.java (100%) rename {server => engine/components-api}/src/com/cloud/resource/ResourceManager.java (100%) rename {server => engine/components-api}/src/com/cloud/resource/ResourceStateAdapter.java (100%) rename {server => engine/components-api}/src/com/cloud/vm/snapshot/VMSnapshotManager.java (100%) rename {server => engine/orchestration}/src/com/cloud/agent/manager/AgentAttache.java (100%) rename {server => engine/orchestration}/src/com/cloud/agent/manager/AgentManagerImpl.java (98%) rename {server => engine/orchestration}/src/com/cloud/agent/manager/ClusteredAgentAttache.java (100%) rename {server => engine/orchestration}/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java (99%) rename {server => engine/orchestration}/src/com/cloud/agent/manager/ClusteredDirectAgentAttache.java (100%) rename {server => engine/orchestration}/src/com/cloud/agent/manager/ConnectedAgentAttache.java (100%) rename {server => engine/orchestration}/src/com/cloud/agent/manager/DirectAgentAttache.java (100%) rename {server => engine/orchestration}/src/com/cloud/agent/manager/DummyAttache.java (100%) rename {server => engine/orchestration}/src/com/cloud/agent/manager/Routable.java (100%) rename {server => engine/orchestration}/src/com/cloud/agent/manager/SynchronousListener.java (100%) rename {server => engine/orchestration}/src/com/cloud/cluster/ClusteredAgentRebalanceService.java (100%) rename {server => engine/orchestration}/src/com/cloud/cluster/agentlb/AgentLoadBalancerPlanner.java (100%) rename {server => engine/orchestration}/src/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java (100%) rename {server => engine/orchestration}/src/com/cloud/network/NetworkStateListener.java (96%) rename {server => engine/orchestration}/src/com/cloud/network/rules/StaticNatRuleImpl.java (100%) rename {server => engine/schema}/src/com/cloud/network/vpc/NetworkACLItemDao.java (100%) rename {server => engine/schema}/src/com/cloud/network/vpc/NetworkACLItemVO.java (100%) rename {server => engine/schema}/src/com/cloud/network/vpc/NetworkACLVO.java (100%) rename {server => engine/schema}/src/com/cloud/network/vpc/dao/NetworkACLDao.java (100%) rename {server => engine/schema}/src/com/cloud/network/vpc/dao/NetworkACLDaoImpl.java (100%) rename {server => engine/schema}/src/com/cloud/network/vpc/dao/NetworkACLItemDaoImpl.java (100%) rename {server => engine/schema}/src/org/apache/cloudstack/region/PortableIpDao.java (100%) rename {server => engine/schema}/src/org/apache/cloudstack/region/PortableIpDaoImpl.java (100%) rename {server => engine/schema}/src/org/apache/cloudstack/region/PortableIpRangeDao.java (100%) rename {server => engine/schema}/src/org/apache/cloudstack/region/PortableIpRangeDaoImpl.java (100%) rename {server => engine/schema}/src/org/apache/cloudstack/region/PortableIpRangeVO.java (100%) rename {server => engine/schema}/src/org/apache/cloudstack/region/PortableIpVO.java (100%) delete mode 100644 framework/config/src/org/apache/cloudstack/framework/config/ScopedConfigValue.java delete mode 100644 server/src/com/cloud/agent/manager/AgentMonitorService.java delete mode 100644 server/test/com/cloud/network/MockRulesManagerImpl.java delete mode 100644 server/test/com/cloud/vpc/MockVpcManagerImpl.java diff --git a/api/src/com/cloud/network/NetworkModel.java b/api/src/com/cloud/network/NetworkModel.java index 01c0e2195d4..f067787b9d6 100644 --- a/api/src/com/cloud/network/NetworkModel.java +++ b/api/src/com/cloud/network/NetworkModel.java @@ -97,8 +97,6 @@ public interface NetworkModel { List listAllNetworksInAllZonesByType(Network.GuestType type); - String getGlobalGuestDomainSuffix(); - String getStartIpAddress(long networkId); String getIpInNetwork(long vmId, long networkId); @@ -179,11 +177,6 @@ public interface NetworkModel { */ String getAccountNetworkDomain(long accountId, long zoneId); - /** - * @return - */ - String getDefaultNetworkDomain(long zoneId); - /** * @param ntwkOffId * @return diff --git a/api/src/com/cloud/network/router/VirtualRouter.java b/api/src/com/cloud/network/router/VirtualRouter.java index 2311f489918..9e90e8e262f 100755 --- a/api/src/com/cloud/network/router/VirtualRouter.java +++ b/api/src/com/cloud/network/router/VirtualRouter.java @@ -22,7 +22,7 @@ import com.cloud.vm.VirtualMachine; * bridge internal and external traffic. */ public interface VirtualRouter extends VirtualMachine { - public enum Role { + public enum Role { VIRTUAL_ROUTER, LB, INTERNAL_LB_VM } Role getRole(); diff --git a/api/src/com/cloud/network/rules/RulesService.java b/api/src/com/cloud/network/rules/RulesService.java index 45abd84a9ec..2a2074b37d8 100644 --- a/api/src/com/cloud/network/rules/RulesService.java +++ b/api/src/com/cloud/network/rules/RulesService.java @@ -69,10 +69,6 @@ public interface RulesService { boolean enableStaticNat(long ipAddressId, long vmId, long networkId, String vmGuestIp) throws NetworkRuleConflictException, ResourceUnavailableException; - PortForwardingRule getPortForwardigRule(long ruleId); - - FirewallRule getFirewallRule(long ruleId); - StaticNatRule createStaticNatRule(StaticNatRule rule, boolean openFirewall) throws NetworkRuleConflictException; boolean revokeStaticNatRule(long ruleId, boolean apply); @@ -81,8 +77,6 @@ public interface RulesService { StaticNatRule buildStaticNatRule(FirewallRule rule, boolean forRevoke); - List getSourceCidrs(long ruleId); - boolean disableStaticNat(long ipId) throws ResourceUnavailableException, NetworkRuleConflictException, InsufficientAddressCapacityException; } diff --git a/api/src/com/cloud/network/vpc/VpcService.java b/api/src/com/cloud/network/vpc/VpcService.java index 7a444c07b85..f772879712d 100644 --- a/api/src/com/cloud/network/vpc/VpcService.java +++ b/api/src/com/cloud/network/vpc/VpcService.java @@ -29,27 +29,10 @@ import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.IpAddress; -import com.cloud.network.Network; import com.cloud.utils.Pair; public interface VpcService { - /**Returns existing VPC found by id - * - * @param vpcId - * @return - */ - public Vpc getVpc(long vpcId); - - - /** - * Returns all the Guest networks that are part of VPC - * - * @param vpcId - * @return - */ - public List getVpcNetworks(long vpcId); - /** * Persists VPC record in the database * @@ -63,10 +46,9 @@ public interface VpcService { * @return * @throws ResourceAllocationException TODO */ - public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr, - String networkDomain) throws ResourceAllocationException; + public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr, String networkDomain) throws ResourceAllocationException; + - /** * Deletes a VPC * @@ -78,7 +60,7 @@ public interface VpcService { */ public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException; - + /** * Updates VPC with new name/displayText * @@ -89,7 +71,7 @@ public interface VpcService { */ public Vpc updateVpc(long vpcId, String vpcName, String displayText); - + /** * Lists VPC(s) based on the parameters passed to the method call * @@ -113,10 +95,9 @@ public interface VpcService { * @param vpc * @return */ - public List listVpcs(Long id, String vpcName, String displayText, - List supportedServicesStr, String cidr, Long vpcOffId, String state, String accountName, Long domainId, - String keyword, Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll, - Boolean restartRequired, Map tags, Long projectId); + public List listVpcs(Long id, String vpcName, String displayText, List supportedServicesStr, String cidr, Long vpcOffId, String state, + String accountName, Long domainId, String keyword, Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll, Boolean restartRequired, + Map tags, Long projectId); /** * Starts VPC which includes starting VPC provider and applying all the neworking rules on the backend @@ -128,8 +109,7 @@ public interface VpcService { * @throws ResourceUnavailableException * @throws ConcurrentOperationException */ - boolean startVpc(long vpcId, boolean destroyOnFailure) throws ConcurrentOperationException, - ResourceUnavailableException, InsufficientCapacityException; + boolean startVpc(long vpcId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; /** * Shuts down the VPC which includes shutting down all VPC provider and rules cleanup on the backend @@ -141,7 +121,7 @@ public interface VpcService { */ boolean shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException; - + /** * Restarts the VPC. VPC gets shutdown and started as a part of it * @@ -159,7 +139,6 @@ public interface VpcService { */ PrivateGateway getVpcPrivateGateway(long id); - /** * Persists VPC private gateway in the Database. * @@ -178,9 +157,8 @@ public interface VpcService { * @throws ConcurrentOperationException * @throws ResourceAllocationException */ - public PrivateGateway createVpcPrivateGateway(long vpcId, Long physicalNetworkId, String vlan, String ipAddress, - String gateway, String netmask, long gatewayOwnerId, Boolean isSoruceNat, Long aclId) throws ResourceAllocationException, - ConcurrentOperationException, InsufficientCapacityException; + public PrivateGateway createVpcPrivateGateway(long vpcId, Long physicalNetworkId, String vlan, String ipAddress, String gateway, String netmask, long gatewayOwnerId, + Boolean isSoruceNat, Long aclId) throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException; /** * Applies VPC private gateway on the backend, so it becomes functional @@ -193,7 +171,7 @@ public interface VpcService { */ public PrivateGateway applyVpcPrivateGateway(long gatewayId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException; - + /** * Deletes VPC private gateway * @@ -204,7 +182,7 @@ public interface VpcService { */ boolean deleteVpcPrivateGateway(long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException; - + /** * Returns the list of Private gateways existing in the VPC * @@ -213,7 +191,7 @@ public interface VpcService { */ public Pair, Integer> listPrivateGateway(ListPrivateGatewaysCmd listPrivateGatewaysCmd); - + /** * Returns Static Route found by Id * @@ -222,7 +200,7 @@ public interface VpcService { */ StaticRoute getStaticRoute(long routeId); - + /** * Applies existing Static Routes to the VPC elements * @@ -232,7 +210,7 @@ public interface VpcService { */ public boolean applyStaticRoutes(long vpcId) throws ResourceUnavailableException; - + /** * Deletes static route from the backend and the database * @@ -242,7 +220,7 @@ public interface VpcService { */ public boolean revokeStaticRoute(long routeId) throws ResourceUnavailableException; - + /** * Persists static route entry in the Database * @@ -252,7 +230,7 @@ public interface VpcService { */ public StaticRoute createStaticRoute(long gatewayId, String cidr) throws NetworkRuleConflictException; - + /** * Lists static routes based on parameters passed to the call * @@ -261,16 +239,7 @@ public interface VpcService { */ public Pair, Integer> listStaticRoutes(ListStaticRoutesCmd cmd); - - /** - * Returns gateway (VPN or Public) existign in the VPC - * - * @param id - * @return - */ - VpcGateway getVpcGateway(long id); - /** * Associates IP address from the Public network, to the VPC * @@ -282,7 +251,7 @@ public interface VpcService { * @throws InsufficientAddressCapacityException * @throws ConcurrentOperationException */ - IpAddress associateIPToVpc(long ipId, long vpcId) throws ResourceAllocationException, ResourceUnavailableException, - InsufficientAddressCapacityException, ConcurrentOperationException; + IpAddress associateIPToVpc(long ipId, long vpcId) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, + ConcurrentOperationException; } diff --git a/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java b/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java index b554719f188..285e714122a 100644 --- a/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java +++ b/api/src/com/cloud/network/vpn/RemoteAccessVpnService.java @@ -29,6 +29,7 @@ import com.cloud.user.Account; import com.cloud.utils.Pair; public interface RemoteAccessVpnService { + static final String RemoteAccessVpnClientIpRangeCK = "remote.access.vpn.client.iprange"; RemoteAccessVpn createRemoteAccessVpn(long vpnServerAddressId, String ipRange, boolean openFirewall, long networkId) throws NetworkRuleConflictException; diff --git a/api/src/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayCmd.java index 0bc905c49d5..be7e7847241 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayCmd.java @@ -16,6 +16,8 @@ // under the License. package org.apache.cloudstack.api.command.admin.vpc; +import org.apache.log4j.Logger; + import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandJobType; import org.apache.cloudstack.api.ApiConstants; @@ -28,7 +30,6 @@ import org.apache.cloudstack.api.response.NetworkACLResponse; import org.apache.cloudstack.api.response.PhysicalNetworkResponse; import org.apache.cloudstack.api.response.PrivateGatewayResponse; import org.apache.cloudstack.api.response.VpcResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -145,8 +146,8 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd { } if (result != null) { - this.setEntityId(result.getId()); - this.setEntityUuid(result.getUuid()); + setEntityId(result.getId()); + setEntityUuid(result.getUuid()); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create private gateway"); } @@ -159,7 +160,7 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd { if (result != null) { PrivateGatewayResponse response = _responseGenerator.createPrivateGatewayResponse(result); response.setResponseName(getCommandName()); - this.setResponseObject(response); + setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create private gateway"); } @@ -189,7 +190,7 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd { @Override public Long getSyncObjId() { - Vpc vpc = _vpcService.getVpc(vpcId); + Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); if (vpc == null) { throw new InvalidParameterValueException("Invalid id is specified for the vpc"); } diff --git a/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java b/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java index 91d09741f3d..48ffd12cafb 100644 --- a/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java @@ -228,7 +228,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd { return network.getAccountId(); } else if (vpcId != null) { - Vpc vpc = _vpcService.getVpc(getVpcId()); + Vpc vpc = _entityMgr.findById(Vpc.class, getVpcId()); if (vpc == null) { throw new InvalidParameterValueException("Can't find Enabled vpc by id specified"); } diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java index 47c9ee039d9..cbdd429b9c5 100644 --- a/api/src/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java @@ -16,6 +16,8 @@ // under the License. package org.apache.cloudstack.api.command.user.firewall; +import org.apache.log4j.Logger; + import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandJobType; import org.apache.cloudstack.api.ApiConstants; @@ -28,8 +30,6 @@ import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; - import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.rules.PortForwardingRule; @@ -100,7 +100,7 @@ public class DeletePortForwardingRuleCmd extends BaseAsyncCmd { if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); - this.setResponseObject(response); + setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete port forwarding rule"); } @@ -114,7 +114,7 @@ public class DeletePortForwardingRuleCmd extends BaseAsyncCmd { @Override public Long getSyncObjId() { - return _rulesService.getPortForwardigRule(id).getNetworkId(); + return _entityMgr.findById(PortForwardingRule.class, id).getNetworkId(); } @Override diff --git a/api/src/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java index fe41028c4fb..e0a82bbcc07 100644 --- a/api/src/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java @@ -16,6 +16,8 @@ // under the License. package org.apache.cloudstack.api.command.user.nat; +import org.apache.log4j.Logger; + import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandJobType; import org.apache.cloudstack.api.ApiConstants; @@ -28,8 +30,6 @@ import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; - import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.rules.FirewallRule; @@ -77,7 +77,7 @@ public class DeleteIpForwardingRuleCmd extends BaseAsyncCmd { if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); - this.setResponseObject(response); + setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete ip forwarding rule"); } @@ -113,7 +113,7 @@ public class DeleteIpForwardingRuleCmd extends BaseAsyncCmd { @Override public Long getSyncObjId() { - return _rulesService.getFirewallRule(id).getNetworkId(); + return _entityMgr.findById(FirewallRule.class, id).getNetworkId(); } @Override diff --git a/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkACLListCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkACLListCmd.java index d587fe557e3..52a4281333a 100644 --- a/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkACLListCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkACLListCmd.java @@ -16,12 +16,7 @@ // under the License. package org.apache.cloudstack.api.command.user.network; -import com.cloud.event.EventTypes; -import com.cloud.exception.InvalidParameterValueException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.network.vpc.NetworkACL; -import com.cloud.network.vpc.Vpc; -import com.cloud.user.Account; +import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -31,9 +26,13 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.NetworkACLResponse; import org.apache.cloudstack.api.response.VpcResponse; -import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.vpc.NetworkACL; +import com.cloud.network.vpc.Vpc; +import com.cloud.user.Account; @APICommand(name = "createNetworkACLList", description = "Creates a Network ACL for the given VPC", responseObject = NetworkACLResponse.class) @@ -101,7 +100,7 @@ public class CreateNetworkACLListCmd extends BaseAsyncCreateCmd { @Override public long getEntityOwnerId() { - Vpc vpc = _vpcService.getVpc(getVpcId()); + Vpc vpc = _entityMgr.findById(Vpc.class, getVpcId()); if (vpc == null) { throw new InvalidParameterValueException("Invalid vpcId is given"); } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java index 91aecef210d..bc59bbdc632 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java @@ -16,6 +16,8 @@ // under the License. package org.apache.cloudstack.api.command.user.vpc; +import org.apache.log4j.Logger; + import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandJobType; import org.apache.cloudstack.api.ApiConstants; @@ -28,14 +30,13 @@ import org.apache.cloudstack.api.response.PrivateGatewayResponse; import org.apache.cloudstack.api.response.StaticRouteResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; - import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.vpc.StaticRoute; +import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.VpcGateway; @APICommand(name = "createStaticRoute", description="Creates a static route", responseObject=StaticRouteResponse.class) @@ -119,11 +120,11 @@ public class CreateStaticRouteCmd extends BaseAsyncCreateCmd{ @Override public long getEntityOwnerId() { - VpcGateway gateway = _vpcService.getVpcGateway(gatewayId); + VpcGateway gateway = _entityMgr.findById(VpcGateway.class, gatewayId); if (gateway == null) { throw new InvalidParameterValueException("Invalid gateway id is specified"); } - return _vpcService.getVpc(gateway.getVpcId()).getAccountId(); + return _entityMgr.findById(Vpc.class, gateway.getVpcId()).getAccountId(); } @Override @@ -133,7 +134,7 @@ public class CreateStaticRouteCmd extends BaseAsyncCreateCmd{ @Override public Long getSyncObjId() { - VpcGateway gateway = _vpcService.getVpcGateway(gatewayId); + VpcGateway gateway = _entityMgr.findById(VpcGateway.class, gatewayId); if (gateway == null) { throw new InvalidParameterValueException("Invalid id is specified for the gateway"); } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java index 78e4363d7d3..6e86ba086d6 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java @@ -16,6 +16,8 @@ // under the License. package org.apache.cloudstack.api.command.user.vpc; +import org.apache.log4j.Logger; + import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; @@ -29,8 +31,6 @@ import org.apache.cloudstack.api.response.VpcResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; - import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -124,8 +124,8 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{ Vpc vpc = _vpcService.createVpc(getZoneId(), getVpcOffering(), getEntityOwnerId(), getVpcName(), getDisplayText(), getCidr(), getNetworkDomain()); if (vpc != null) { - this.setEntityId(vpc.getId()); - this.setEntityUuid(vpc.getUuid()); + setEntityId(vpc.getId()); + setEntityUuid(vpc.getUuid()); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a VPC"); } @@ -135,8 +135,8 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{ public void execute() { Vpc vpc = null; try { - if (_vpcService.startVpc(this.getEntityId(), true)) { - vpc = _vpcService.getVpc(getEntityId()); + if (_vpcService.startVpc(getEntityId(), true)) { + vpc = _entityMgr.findById(Vpc.class, getEntityId()); } } catch (ResourceUnavailableException ex) { s_logger.warn("Exception: ", ex); @@ -153,7 +153,7 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{ if (vpc != null) { VpcResponse response = _responseGenerator.createVpcResponse(vpc); response.setResponseName(getCommandName()); - this.setResponseObject(response); + setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPC"); } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java index fee0325e908..a8c6dc2f0be 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java @@ -16,6 +16,8 @@ // under the License. package org.apache.cloudstack.api.command.user.vpn; +import org.apache.log4j.Logger; + import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; @@ -26,7 +28,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.Site2SiteCustomerGatewayResponse; import org.apache.cloudstack.api.response.Site2SiteVpnConnectionResponse; import org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.NetworkRuleConflictException; @@ -77,7 +78,7 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { @Override public long getEntityOwnerId() { - Vpc vpc = _vpcService.getVpc(getVpnGateway().getVpcId()); + Vpc vpc = _entityMgr.findById(Vpc.class, getVpnGateway().getVpcId()); return vpc.getAccountId(); } @@ -96,8 +97,8 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { try { Site2SiteVpnConnection conn = _s2sVpnService.createVpnConnection(this); if (conn != null) { - this.setEntityId(conn.getId()); - this.setEntityUuid(conn.getUuid()); + setEntityId(conn.getId()); + setEntityUuid(conn.getUuid()); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create site to site vpn connection"); } @@ -111,11 +112,11 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { @Override public void execute(){ try { - Site2SiteVpnConnection result = _s2sVpnService.startVpnConnection(this.getEntityId()); + Site2SiteVpnConnection result = _s2sVpnService.startVpnConnection(getEntityId()); if (result != null) { Site2SiteVpnConnectionResponse response = _responseGenerator.createSite2SiteVpnConnectionResponse(result); response.setResponseName(getCommandName()); - this.setResponseObject(response); + setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create site to site vpn connection"); } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java index 4cc650f704d..e8db1abcf77 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java @@ -16,6 +16,8 @@ // under the License. package org.apache.cloudstack.api.command.user.vpn; +import org.apache.log4j.Logger; + import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; @@ -24,7 +26,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse; import org.apache.cloudstack.api.response.VpcResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.network.Site2SiteVpnGateway; @@ -63,7 +64,7 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Vpc vpc = _vpcService.getVpc(vpcId); + Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); return vpc.getAccountId(); } @@ -84,7 +85,7 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd { if (result != null) { Site2SiteVpnGatewayResponse response = _responseGenerator.createSite2SiteVpnGatewayResponse(result); response.setResponseName(getCommandName()); - this.setResponseObject(response); + setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPN gateway"); } diff --git a/engine/api/pom.xml b/engine/api/pom.xml index f7f67c4ab50..5f170d131b0 100644 --- a/engine/api/pom.xml +++ b/engine/api/pom.xml @@ -60,5 +60,10 @@ cloud-framework-ipc ${project.version} + + org.apache.cloudstack + cloud-framework-config + ${project.version} + diff --git a/engine/api/src/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java b/engine/api/src/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java index 5d971c8ade1..173feef51d7 100755 --- a/engine/api/src/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java +++ b/engine/api/src/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import org.apache.cloudstack.acl.ControlledEntity.ACLType; +import org.apache.cloudstack.framework.config.ConfigKey; import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; @@ -32,10 +33,10 @@ import com.cloud.exception.InsufficientVirtualNetworkCapcityException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network; -import com.cloud.network.NetworkProfile; -import com.cloud.network.PhysicalNetwork; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; +import com.cloud.network.NetworkProfile; +import com.cloud.network.PhysicalNetwork; import com.cloud.network.element.DhcpServiceProvider; import com.cloud.network.element.LoadBalancingServiceProvider; import com.cloud.network.element.StaticNatServiceProvider; @@ -58,6 +59,16 @@ import com.cloud.vm.VirtualMachineProfile; * */ public interface NetworkOrchestrationService { + static final String NetworkLockTimeoutCK = "network.lock.timeout"; + static final String GuestDomainSuffixCK = "guest.domain.suffix"; + static final String NetworkThrottlingRateCK = "network.throttling.rate"; + + static final ConfigKey NetworkLockTimeout = new ConfigKey(Integer.class, NetworkLockTimeoutCK, "Network", "600", + "Lock wait timeout (seconds) while implementing network", true); + static final ConfigKey GuestDomainSuffix = new ConfigKey(String.class, GuestDomainSuffixCK, "Network", "cloud.internal", + "Default domain name for vms inside virtualized networks fronted by router", true, ConfigKey.Scope.Zone, null); + static final ConfigKey NetworkThrottlingRate = new ConfigKey("Network", Integer.class, NetworkThrottlingRateCK, "200", + "Default data transfer rate in megabits per second allowed in network.", true, ConfigKey.Scope.Zone); List setupNetwork(Account owner, NetworkOffering offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) throws ConcurrentOperationException; @@ -158,10 +169,6 @@ public interface NetworkOrchestrationService { throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; - /** - * @param vm - * @param nic TODO - */ void removeNic(VirtualMachineProfile vm, Nic nic); /** @@ -171,38 +178,14 @@ public interface NetworkOrchestrationService { */ boolean setupDns(Network network, Provider provider); - /** - * @param vmProfile - * @param nic TODO - * @throws ConcurrentOperationException - * @throws ResourceUnavailableException - */ void releaseNic(VirtualMachineProfile vmProfile, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException; - /** - * @param network - * @param requested - * @param context - * @param vmProfile - * @param prepare TODO - * @return - * @throws InsufficientVirtualNetworkCapcityException - * @throws InsufficientAddressCapacityException - * @throws ConcurrentOperationException - * @throws InsufficientCapacityException - * @throws ResourceUnavailableException - */ NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context, VirtualMachineProfile vmProfile, boolean prepare) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; NetworkProfile convertNetworkToNetworkProfile(long networkId); - /** - * @return - */ - int getNetworkLockTimeout(); - boolean restartNetwork(Long networkId, Account callerAccount, User callerUser, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; diff --git a/engine/components-api/pom.xml b/engine/components-api/pom.xml index 55af5eebb3b..5b82b2966b6 100644 --- a/engine/components-api/pom.xml +++ b/engine/components-api/pom.xml @@ -38,6 +38,11 @@ cloud-engine-schema ${project.version} + + org.apache.cloudstack + cloud-core + ${project.version} + org.apache.cloudstack cloud-framework-ipc diff --git a/server/src/com/cloud/agent/AgentManager.java b/engine/components-api/src/com/cloud/agent/AgentManager.java similarity index 89% rename from server/src/com/cloud/agent/AgentManager.java rename to engine/components-api/src/com/cloud/agent/AgentManager.java index 43b42b9cb9e..a10db291358 100755 --- a/server/src/com/cloud/agent/AgentManager.java +++ b/engine/components-api/src/com/cloud/agent/AgentManager.java @@ -18,26 +18,21 @@ package com.cloud.agent; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; -import com.cloud.agent.api.StartupCommand; -import com.cloud.agent.manager.AgentAttache; import com.cloud.agent.manager.Commands; import com.cloud.exception.AgentUnavailableException; -import com.cloud.exception.ConnectionException; import com.cloud.exception.OperationTimedoutException; import com.cloud.host.HostVO; import com.cloud.host.Status; import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.resource.ServerResource; -import com.cloud.utils.component.Manager; /** * AgentManager manages hosts. It directly coordinates between the DAOs and the connections it manages. */ -public interface AgentManager extends Manager { +public interface AgentManager { + final static String WaitCK = "wait"; + public enum TapAgentsAction { - Add, - Del, - Contains, + Add, Del, Contains, } /** @@ -109,14 +104,13 @@ public interface AgentManager extends Manager { */ int registerForHostEvents(Listener listener, boolean connections, boolean commands, boolean priority); - /** * Register to listen for initial agent connections. * @param creator * @param priority in listening for events. * @return id to unregister if needed. */ - int registerForInitialConnects(StartupCommandProcessor creator, boolean priority); + int registerForInitialConnects(StartupCommandProcessor creator, boolean priority); /** * Unregister for listening to host events. @@ -128,11 +122,10 @@ public interface AgentManager extends Manager { Answer sendTo(Long dcId, HypervisorType type, Command cmd); - /* working as a lock while agent is being loaded */ public boolean tapLoadingAgents(Long hostId, TapAgentsAction action); - public AgentAttache handleDirectConnectAgent(HostVO host, StartupCommand[] cmds, ServerResource resource, boolean forRebalance) throws ConnectionException; +// public AgentAttache handleDirectConnectAgent(HostVO host, StartupCommand[] cmds, ServerResource resource, boolean forRebalance) throws ConnectionException; public boolean agentStatusTransitTo(HostVO host, Status.Event e, long msId); @@ -144,5 +137,5 @@ public interface AgentManager extends Manager { public void pullAgentOutMaintenance(long hostId); - boolean reconnect(long hostId); + boolean reconnect(long hostId); } diff --git a/core/src/com/cloud/agent/Listener.java b/engine/components-api/src/com/cloud/agent/Listener.java similarity index 100% rename from core/src/com/cloud/agent/Listener.java rename to engine/components-api/src/com/cloud/agent/Listener.java diff --git a/server/src/com/cloud/alert/AlertManager.java b/engine/components-api/src/com/cloud/alert/AlertManager.java similarity index 70% rename from server/src/com/cloud/alert/AlertManager.java rename to engine/components-api/src/com/cloud/alert/AlertManager.java index b6d005a5f21..1ae6b1b7216 100755 --- a/server/src/com/cloud/alert/AlertManager.java +++ b/engine/components-api/src/com/cloud/alert/AlertManager.java @@ -16,6 +16,8 @@ // under the License. package com.cloud.alert; +import org.apache.cloudstack.framework.config.ConfigKey; + import com.cloud.capacity.CapacityVO; import com.cloud.utils.component.Manager; @@ -48,8 +50,17 @@ public interface AlertManager extends Manager { public static final short ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP = 24; public static final short ALERT_TYPE_LOCAL_STORAGE = 25; public static final short ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED = 26; // Generated when the resource limit exceeds the limit. Currently used for recurring snapshots only - - + + static final ConfigKey StorageCapacityThreshold = new ConfigKey(Double.class, "cluster.storage.capacity.notificationthreshold", "Alert", "0.75", + "Percentage (as a value between 0 and 1) of storage utilization above which alerts will be sent about low storage available.", true, ConfigKey.Scope.Cluster, null); + static final ConfigKey CPUCapacityThreshold = new ConfigKey(Double.class, "cluster.cpu.allocated.capacity.notificationthreshold", "Alert", "0.75", + "Percentage (as a value between 0 and 1) of cpu utilization above which alerts will be sent about low cpu available.", true, ConfigKey.Scope.Cluster, null); + static final ConfigKey MemoryCapacityThreshold = new ConfigKey(Double.class, "cluster.memory.allocated.capacity.notificationthreshold", "Alert", "0.75", + "Percentage (as a value between 0 and 1) of memory utilization above which alerts will be sent about low memory available.", true, ConfigKey.Scope.Cluster, null); + static final ConfigKey StorageAllocatedCapacityThreshold = new ConfigKey(Double.class, "cluster.storage.allocated.capacity.notificationthreshold", "Alert", + "0.75", "Percentage (as a value between 0 and 1) of allocated storage utilization above which alerts will be sent about low storage available.", true, + ConfigKey.Scope.Cluster, null); + void clearAlert(short alertType, long dataCenterId, long podId); void sendAlert(short alertType, long dataCenterId, Long podId, String subject, String body); diff --git a/server/src/com/cloud/capacity/CapacityManager.java b/engine/components-api/src/com/cloud/capacity/CapacityManager.java similarity index 73% rename from server/src/com/cloud/capacity/CapacityManager.java rename to engine/components-api/src/com/cloud/capacity/CapacityManager.java index ded1f806b4a..17641827648 100755 --- a/server/src/com/cloud/capacity/CapacityManager.java +++ b/engine/components-api/src/com/cloud/capacity/CapacityManager.java @@ -16,11 +16,11 @@ // under the License. package com.cloud.capacity; +import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import com.cloud.host.Host; import com.cloud.storage.VMTemplateVO; -import com.cloud.utils.component.Manager; import com.cloud.vm.VirtualMachine; /** @@ -28,7 +28,17 @@ import com.cloud.vm.VirtualMachine; * available within the Cloud Stack. * */ -public interface CapacityManager extends Manager { +public interface CapacityManager { + + static final String CpuOverprovisioningFactorCK = "cpu.overprovisioning.factor"; + static final String MemOverprovisioningFactorCK = "mem.overprovisioning.factor"; + + static final ConfigKey CpuOverprovisioningFactor = new ConfigKey(Float.class, CpuOverprovisioningFactorCK, "Advanced", "1.0", + "Used for CPU overprovisioning calculation; available CPU will be (actualCpuCapacity * cpu.overprovisioning.factor)", true, ConfigKey.Scope.Cluster, null); + static final ConfigKey MemOverprovisioningFactor = new ConfigKey(Float.class, MemOverprovisioningFactorCK, "Advanced", "1.0", + "Used for memory overprovisioning calculation", true, ConfigKey.Scope.Cluster, null); + + public boolean releaseVmCapacity(VirtualMachine vm, boolean moveFromReserved, boolean moveToReservered, Long hostId); void allocateVmCapacity(VirtualMachine vm, boolean fromLastHost); diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/engine/components-api/src/com/cloud/configuration/ConfigurationManager.java similarity index 100% rename from server/src/com/cloud/configuration/ConfigurationManager.java rename to engine/components-api/src/com/cloud/configuration/ConfigurationManager.java diff --git a/server/src/com/cloud/ha/HighAvailabilityManager.java b/engine/components-api/src/com/cloud/ha/HighAvailabilityManager.java similarity index 100% rename from server/src/com/cloud/ha/HighAvailabilityManager.java rename to engine/components-api/src/com/cloud/ha/HighAvailabilityManager.java diff --git a/server/src/com/cloud/hypervisor/HypervisorGuruManager.java b/engine/components-api/src/com/cloud/hypervisor/HypervisorGuruManager.java similarity index 100% rename from server/src/com/cloud/hypervisor/HypervisorGuruManager.java rename to engine/components-api/src/com/cloud/hypervisor/HypervisorGuruManager.java diff --git a/engine/components-api/src/com/cloud/network/IpAddressManager.java b/engine/components-api/src/com/cloud/network/IpAddressManager.java index 0394ebb5060..512c50b5485 100644 --- a/engine/components-api/src/com/cloud/network/IpAddressManager.java +++ b/engine/components-api/src/com/cloud/network/IpAddressManager.java @@ -18,6 +18,8 @@ package com.cloud.network; import java.util.List; +import org.apache.cloudstack.framework.config.ConfigKey; + import com.cloud.dc.DataCenter; import com.cloud.dc.Pod; import com.cloud.dc.Vlan.VlanType; @@ -36,6 +38,11 @@ import com.cloud.vm.NicProfile; import com.cloud.vm.VirtualMachineProfile; public interface IpAddressManager { + static final String UseSystemPublicIpsCK = "use.system.public.ips"; + static final ConfigKey UseSystemPublicIps = new ConfigKey("Advanced", Boolean.class, UseSystemPublicIpsCK, "true", + "If true, when account has dedicated public ip range(s), once the ips dedicated to the account have been consumed ips will be acquired from the system pool", true, + ConfigKey.Scope.Account); + /** * Assigns a new public ip address. * @@ -52,7 +59,6 @@ public interface IpAddressManager { * @return * @throws InsufficientAddressCapacityException */ - PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException; diff --git a/server/src/com/cloud/network/rules/FirewallManager.java b/engine/components-api/src/com/cloud/network/rules/FirewallManager.java similarity index 99% rename from server/src/com/cloud/network/rules/FirewallManager.java rename to engine/components-api/src/com/cloud/network/rules/FirewallManager.java index 6d36ed3462e..fa12cd804a6 100644 --- a/server/src/com/cloud/network/rules/FirewallManager.java +++ b/engine/components-api/src/com/cloud/network/rules/FirewallManager.java @@ -5,7 +5,7 @@ // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, diff --git a/server/src/com/cloud/network/rules/RulesManager.java b/engine/components-api/src/com/cloud/network/rules/RulesManager.java similarity index 98% rename from server/src/com/cloud/network/rules/RulesManager.java rename to engine/components-api/src/com/cloud/network/rules/RulesManager.java index 201d79db9c6..2bdf356460b 100644 --- a/server/src/com/cloud/network/rules/RulesManager.java +++ b/engine/components-api/src/com/cloud/network/rules/RulesManager.java @@ -30,7 +30,7 @@ import com.cloud.vm.VirtualMachine; /** * Rules Manager manages the network rules created for different networks. */ -public interface RulesManager extends RulesService { +public interface RulesManager { boolean applyPortForwardingRulesForNetwork(long networkId, boolean continueOnError, Account caller); diff --git a/server/src/com/cloud/network/vpc/NetworkACLManager.java b/engine/components-api/src/com/cloud/network/vpc/NetworkACLManager.java similarity index 100% rename from server/src/com/cloud/network/vpc/NetworkACLManager.java rename to engine/components-api/src/com/cloud/network/vpc/NetworkACLManager.java diff --git a/server/src/com/cloud/network/vpc/VpcManager.java b/engine/components-api/src/com/cloud/network/vpc/VpcManager.java similarity index 94% rename from server/src/com/cloud/network/vpc/VpcManager.java rename to engine/components-api/src/com/cloud/network/vpc/VpcManager.java index e01413f78f3..ce2185f5916 100644 --- a/server/src/com/cloud/network/vpc/VpcManager.java +++ b/engine/components-api/src/com/cloud/network/vpc/VpcManager.java @@ -38,7 +38,14 @@ import com.cloud.offering.NetworkOffering; import com.cloud.user.Account; -public interface VpcManager extends VpcService{ +public interface VpcManager { + /** + * Returns all the Guest networks that are part of VPC + * + * @param vpcId + * @return + */ + public List getVpcNetworks(long vpcId); /** * Returns all existing VPCs for a given account @@ -141,7 +148,7 @@ public interface VpcManager extends VpcService{ /** * Lists all the services and providers that the current VPC suppots * @param vpcOffId - * @return map of Service to Provider(s) map + * @return map of Service to Provider(s) map */ Map> getVpcOffSvcProvidersMap(long vpcOffId); @@ -155,7 +162,7 @@ public interface VpcManager extends VpcService{ /** - * Performs network offering validation to determine if it can be used for network upgrade inside the VPC + * Performs network offering validation to determine if it can be used for network upgrade inside the VPC * @param networkId * @param newNtwkOffId * @param newCidr diff --git a/server/src/com/cloud/resource/Discoverer.java b/engine/components-api/src/com/cloud/resource/Discoverer.java similarity index 100% rename from server/src/com/cloud/resource/Discoverer.java rename to engine/components-api/src/com/cloud/resource/Discoverer.java diff --git a/server/src/com/cloud/resource/ResourceManager.java b/engine/components-api/src/com/cloud/resource/ResourceManager.java similarity index 100% rename from server/src/com/cloud/resource/ResourceManager.java rename to engine/components-api/src/com/cloud/resource/ResourceManager.java diff --git a/server/src/com/cloud/resource/ResourceStateAdapter.java b/engine/components-api/src/com/cloud/resource/ResourceStateAdapter.java similarity index 100% rename from server/src/com/cloud/resource/ResourceStateAdapter.java rename to engine/components-api/src/com/cloud/resource/ResourceStateAdapter.java diff --git a/engine/components-api/src/com/cloud/template/TemplateManager.java b/engine/components-api/src/com/cloud/template/TemplateManager.java index 4c42ab74c4b..1372a1433aa 100755 --- a/engine/components-api/src/com/cloud/template/TemplateManager.java +++ b/engine/components-api/src/com/cloud/template/TemplateManager.java @@ -20,6 +20,7 @@ import java.util.List; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; +import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import com.cloud.dc.DataCenterVO; @@ -36,6 +37,9 @@ import com.cloud.utils.Pair; * TemplateManager manages the templates stored on secondary storage. It is responsible for creating private/public templates. */ public interface TemplateManager { + static final String AllowPublicUserTemplatesCK = "allow.public.user.templates"; + static final ConfigKey AllowPublicUserTemplates = new ConfigKey("Advanced", Boolean.class, AllowPublicUserTemplatesCK, "true", + "If false, users will not be able to create public templates.", true, ConfigKey.Scope.Account); /** * Prepares a template for vm creation for a certain storage pool. diff --git a/server/src/com/cloud/vm/snapshot/VMSnapshotManager.java b/engine/components-api/src/com/cloud/vm/snapshot/VMSnapshotManager.java similarity index 100% rename from server/src/com/cloud/vm/snapshot/VMSnapshotManager.java rename to engine/components-api/src/com/cloud/vm/snapshot/VMSnapshotManager.java diff --git a/engine/orchestration/pom.xml b/engine/orchestration/pom.xml index 290a4d42ddd..37fba37844f 100755 --- a/engine/orchestration/pom.xml +++ b/engine/orchestration/pom.xml @@ -58,11 +58,13 @@ cloud-utils ${project.version} + diff --git a/server/src/com/cloud/agent/manager/AgentAttache.java b/engine/orchestration/src/com/cloud/agent/manager/AgentAttache.java similarity index 100% rename from server/src/com/cloud/agent/manager/AgentAttache.java rename to engine/orchestration/src/com/cloud/agent/manager/AgentAttache.java diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java similarity index 98% rename from server/src/com/cloud/agent/manager/AgentManagerImpl.java rename to engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java index 7b74b3902d3..a70f4032101 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -72,7 +72,6 @@ import com.cloud.agent.api.UnsupportedAnswer; import com.cloud.agent.transport.Request; import com.cloud.agent.transport.Response; import com.cloud.alert.AlertManager; -import com.cloud.configuration.Config; import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; @@ -91,12 +90,10 @@ import com.cloud.host.Status.Event; import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.HypervisorGuruManager; -import com.cloud.hypervisor.kvm.discoverer.KvmDummyResourceBase; import com.cloud.resource.Discoverer; import com.cloud.resource.ResourceManager; import com.cloud.resource.ResourceState; import com.cloud.resource.ServerResource; -import com.cloud.storage.resource.DummySecondaryStorageResource; import com.cloud.utils.Pair; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.concurrency.NamedThreadFactory; @@ -185,14 +182,13 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl "Interval to send application level pings to make sure the connection is still working", false); protected final ConfigKey PingTimeout = new ConfigKey(Float.class, "ping.timeout", "Advance", "2.5", "Multiplier to ping.interval before announcing an agent has timed out", true); - protected final ConfigKey Wait = new ConfigKey(Integer.class, "wait", "Advance", "1800", - "Time in seconds to wait for control commands to return", true); protected final ConfigKey AlertWait = new ConfigKey(Integer.class, "alert.wait", "Advance", "1800", "Seconds to wait before alerting on a disconnected agent", true); protected final ConfigKey DirectAgentLoadSize = new ConfigKey(Integer.class, "direct.agent.load.size", "Advance", "16", "The number of direct agents to load each time", false); protected final ConfigKey DirectAgentPoolSize = new ConfigKey(Integer.class, "direct.agent.pool.size", "Advance", "500", "Default size for DirectAgentPool", false); + static final ConfigKey Wait = new ConfigKey("Advanced", Integer.class, WaitCK, "1800", "Time in seconds to wait for control commands to return", true); protected ConfigValue _port; @@ -642,8 +638,6 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl params.put("ipaddress", host.getPrivateIpAddress()); params.put("secondary.storage.vm", "false"); - params.put("max.template.iso.size", _configDao.getValue(Config.MaxTemplateAndIsoSize.toString())); - params.put("migratewait", _configDao.getValue(Config.MigrateWait.toString())); try { resource.configure(host.getName(), params); @@ -699,9 +693,9 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl protected AgentAttache createAttacheForDirectConnect(HostVO host, ServerResource resource) throws ConnectionException { - if (resource instanceof DummySecondaryStorageResource || resource instanceof KvmDummyResourceBase) { - return new DummyAttache(this, host.getId(), false); - } +// if (resource instanceof DummySecondaryStorageResource || resource instanceof KvmDummyResourceBase) { +// return new DummyAttache(this, host.getId(), false); +// } s_logger.debug("create DirectAgentAttache for " + host.getId()); DirectAgentAttache attache = new DirectAgentAttache(this, host.getId(), resource, host.isInMaintenanceStates(), this); @@ -1401,7 +1395,6 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl disconnectInternal(hostId, event, false); } - @Override public AgentAttache handleDirectConnectAgent(HostVO host, StartupCommand[] cmds, ServerResource resource, boolean forRebalance) throws ConnectionException { AgentAttache attache; diff --git a/server/src/com/cloud/agent/manager/ClusteredAgentAttache.java b/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentAttache.java similarity index 100% rename from server/src/com/cloud/agent/manager/ClusteredAgentAttache.java rename to engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentAttache.java diff --git a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java b/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java similarity index 99% rename from server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java rename to engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java index bacd4d96e17..3b24e94ece4 100755 --- a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java +++ b/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java @@ -66,7 +66,6 @@ import com.cloud.agent.api.TransferAgentCommand; import com.cloud.agent.transport.Request; import com.cloud.agent.transport.Request.Version; import com.cloud.agent.transport.Response; -import com.cloud.api.ApiDBUtils; import com.cloud.cluster.ClusterManager; import com.cloud.cluster.ClusterManagerListener; import com.cloud.cluster.ClusterServicePdu; @@ -86,7 +85,6 @@ import com.cloud.host.Status; import com.cloud.host.Status.Event; import com.cloud.resource.ServerResource; import com.cloud.serializer.GsonHelper; -import com.cloud.storage.resource.DummySecondaryStorageResource; import com.cloud.utils.DateUtil; import com.cloud.utils.Profiler; import com.cloud.utils.concurrency.NamedThreadFactory; @@ -141,7 +139,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust protected final ConfigKey LoadSize = new ConfigKey(Integer.class, "direct.agent.load.size", "Advanced", "16", "How many agents to connect to in each round", true); protected final ConfigKey ScanInterval = new ConfigKey(Integer.class, "direct.agent.scan.interval", "Advanced", "90", - "Interval between scans to load agents", false); + "Interval between scans to load agents", false, ConfigKey.Scope.Global, 1000); protected ConfigValue _agentLBEnabled; @@ -158,7 +156,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust s_logger.info("Configuring ClusterAgentManagerImpl. management server node id(msid): " + _nodeId); _loadSize = _configDepot.get(LoadSize); - _directAgentScanInterval = _configDepot.get(ScanInterval).setMultiplier(1000); + _directAgentScanInterval = _configDepot.get(ScanInterval); _agentLBEnabled = _configDepot.get(EnableLB); _connectedAgentsThreshold = _configDepot.get(ConnectedAgentThreshold); @@ -293,9 +291,9 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust @Override protected AgentAttache createAttacheForDirectConnect(HostVO host, ServerResource resource) { - if (resource instanceof DummySecondaryStorageResource) { - return new DummyAttache(this, host.getId(), false); - } +// if (resource instanceof DummySecondaryStorageResource) { +// return new DummyAttache(this, host.getId(), false); +// } s_logger.debug("create ClusteredDirectAgentAttache for " + host.getId()); final DirectAgentAttache attache = new ClusteredDirectAgentAttache(this, host.getId(), _nodeId, resource, host.isInMaintenanceStates(), this); AgentAttache old = null; @@ -565,7 +563,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } if (agent == null) { AgentUnavailableException ex = new AgentUnavailableException("Host with specified id is not in the right state: " + host.getStatus(), hostId); - ex.addProxyObject(ApiDBUtils.findHostById(hostId).getUuid()); + ex.addProxyObject(_entityMgr.findById(Host.class, hostId).getUuid()); throw ex; } diff --git a/server/src/com/cloud/agent/manager/ClusteredDirectAgentAttache.java b/engine/orchestration/src/com/cloud/agent/manager/ClusteredDirectAgentAttache.java similarity index 100% rename from server/src/com/cloud/agent/manager/ClusteredDirectAgentAttache.java rename to engine/orchestration/src/com/cloud/agent/manager/ClusteredDirectAgentAttache.java diff --git a/server/src/com/cloud/agent/manager/ConnectedAgentAttache.java b/engine/orchestration/src/com/cloud/agent/manager/ConnectedAgentAttache.java similarity index 100% rename from server/src/com/cloud/agent/manager/ConnectedAgentAttache.java rename to engine/orchestration/src/com/cloud/agent/manager/ConnectedAgentAttache.java diff --git a/server/src/com/cloud/agent/manager/DirectAgentAttache.java b/engine/orchestration/src/com/cloud/agent/manager/DirectAgentAttache.java similarity index 100% rename from server/src/com/cloud/agent/manager/DirectAgentAttache.java rename to engine/orchestration/src/com/cloud/agent/manager/DirectAgentAttache.java diff --git a/server/src/com/cloud/agent/manager/DummyAttache.java b/engine/orchestration/src/com/cloud/agent/manager/DummyAttache.java similarity index 100% rename from server/src/com/cloud/agent/manager/DummyAttache.java rename to engine/orchestration/src/com/cloud/agent/manager/DummyAttache.java diff --git a/server/src/com/cloud/agent/manager/Routable.java b/engine/orchestration/src/com/cloud/agent/manager/Routable.java similarity index 100% rename from server/src/com/cloud/agent/manager/Routable.java rename to engine/orchestration/src/com/cloud/agent/manager/Routable.java diff --git a/server/src/com/cloud/agent/manager/SynchronousListener.java b/engine/orchestration/src/com/cloud/agent/manager/SynchronousListener.java similarity index 100% rename from server/src/com/cloud/agent/manager/SynchronousListener.java rename to engine/orchestration/src/com/cloud/agent/manager/SynchronousListener.java diff --git a/server/src/com/cloud/cluster/ClusteredAgentRebalanceService.java b/engine/orchestration/src/com/cloud/cluster/ClusteredAgentRebalanceService.java similarity index 100% rename from server/src/com/cloud/cluster/ClusteredAgentRebalanceService.java rename to engine/orchestration/src/com/cloud/cluster/ClusteredAgentRebalanceService.java diff --git a/server/src/com/cloud/cluster/agentlb/AgentLoadBalancerPlanner.java b/engine/orchestration/src/com/cloud/cluster/agentlb/AgentLoadBalancerPlanner.java similarity index 100% rename from server/src/com/cloud/cluster/agentlb/AgentLoadBalancerPlanner.java rename to engine/orchestration/src/com/cloud/cluster/agentlb/AgentLoadBalancerPlanner.java diff --git a/server/src/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java b/engine/orchestration/src/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java similarity index 100% rename from server/src/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java rename to engine/orchestration/src/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java diff --git a/server/src/com/cloud/network/NetworkStateListener.java b/engine/orchestration/src/com/cloud/network/NetworkStateListener.java similarity index 96% rename from server/src/com/cloud/network/NetworkStateListener.java rename to engine/orchestration/src/com/cloud/network/NetworkStateListener.java index 520244c12e0..5a3ba2b7057 100644 --- a/server/src/com/cloud/network/NetworkStateListener.java +++ b/engine/orchestration/src/com/cloud/network/NetworkStateListener.java @@ -17,24 +17,26 @@ package com.cloud.network; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import javax.inject.Inject; + +import org.apache.log4j.Logger; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; + +import org.apache.cloudstack.framework.events.EventBus; +import org.apache.cloudstack.framework.events.EventBusException; + import com.cloud.event.EventCategory; import com.cloud.event.dao.UsageEventDao; import com.cloud.network.Network.Event; import com.cloud.network.Network.State; import com.cloud.network.dao.NetworkDao; -import com.cloud.server.ManagementServer; import com.cloud.utils.component.ComponentContext; import com.cloud.utils.fsm.StateListener; -import org.apache.cloudstack.framework.events.EventBus; -import org.apache.cloudstack.framework.events.EventBusException; -import org.apache.log4j.Logger; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; - -import javax.inject.Inject; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; public class NetworkStateListener implements StateListener { @@ -46,8 +48,8 @@ public class NetworkStateListener implements StateListener _hostAllocators; @@ -286,9 +265,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @Inject protected ResourceManager _resourceMgr; - @Inject - protected SnapshotManager _snapshotMgr; - @Inject protected VMSnapshotManager _vmSnapshotMgr = null; @Inject @@ -307,17 +283,46 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac Map _vmGurus = new HashMap(); protected StateMachine2 _stateMachine; - ScheduledExecutorService _executor = null; - protected int _operationTimeout; + static final ConfigKey StartRetry = new ConfigKey(Integer.class, "start.retry", "Advanced", "10", "Number of times to retry create and start commands", true); + static final ConfigKey VmOpWaitInterval = new ConfigKey("Advanced", Integer.class, "vm.op.wait.interval", "120", + "Time (in seconds) to wait before checking if a previous operation has succeeded", true); - protected int _retry; + static final ConfigKey VmOpLockStateRetry = new ConfigKey("Advanced", Integer.class, "vm.op.lock.state.retry", "5", + "Times to retry locking the state of a VM for operations, -1 means forever", true); + static final ConfigKey VmOpCleanupInterval = new ConfigKey("Advanced", Long.class, "vm.op.cleanup.interval", "86400", + "Interval to run the thread that cleans up the vm operations (in seconds)", false); + static final ConfigKey VmOpCleanupWait = new ConfigKey("Advanced", Long.class, "vm.op.cleanup.wait", "3600", + "Time (in seconds) to wait before cleanuping up any vm work items", true); + static final ConfigKey VmOpCancelInterval = new ConfigKey("Advanced", Long.class, "vm.op.cancel.interval", "3600", + "Time (in seconds) to wait before cancelling a operation", false); + static final ConfigKey VmDestroyForcestop = new ConfigKey("Advanced", Boolean.class, "vm.destroy.forcestop", "false", + "On destroy, force-stop takes this value ", true); + static final ConfigKey ClusterDeltaSyncInterval = new ConfigKey("Advanced", Integer.class, "sync.interval", "60", "Cluster Delta sync interval in seconds", + false); + + ScheduledExecutorService _executor = null; + + @InjectConfig(key = AgentManager.WaitCK) + protected ConfigValue _operationTimeout; + + @InjectConfig(key = "start.retry") + protected ConfigValue _retry; protected long _nodeId; - protected long _cleanupWait; - protected long _cleanupInterval; - protected long _cancelWait; - protected long _opWaitInterval; - protected int _lockStateRetry; - protected boolean _forceStop; + + @InjectConfig(key = "vm.op.cleanup.wait") + protected ConfigValue _cleanupWait; + @InjectConfig(key = "vm.op.cleanup.interval") + protected ConfigValue _cleanupInterval; + @InjectConfig(key = "vm.op.cancel.interval") + protected ConfigValue _cancelWait; + @InjectConfig(key = "vm.op.wait.interval") + protected ConfigValue _opWaitInterval; + @InjectConfig(key = "vm.op.lock.state.retry") + protected ConfigValue _lockStateRetry; + @InjectConfig(key = "vm.destroy.forcestop") + protected ConfigValue _forceStop; + @InjectConfig(key = "sync.interval") + protected ConfigValue _syncInterval; @Override public void registerGuru(VirtualMachine.Type type, VirtualMachineGuru guru) { @@ -328,13 +333,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @Override @DB - public void allocate(String vmInstanceName, - VirtualMachineTemplate template, - ServiceOffering serviceOffering, - Pair rootDiskOffering, - LinkedHashMap dataDiskOfferings, - LinkedHashMap auxiliaryNetworks, - DeploymentPlan plan, + public void allocate(String vmInstanceName, VirtualMachineTemplate template, ServiceOffering serviceOffering, Pair rootDiskOffering, + LinkedHashMap dataDiskOfferings, LinkedHashMap auxiliaryNetworks, DeploymentPlan plan, HypervisorType hyperType) throws InsufficientCapacityException { VMInstanceVO vm = _vmDao.findVMByInstanceName(vmInstanceName); @@ -393,12 +393,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } @Override - public void allocate(String vmInstanceName, - VirtualMachineTemplate template, - ServiceOffering serviceOffering, - LinkedHashMap networks, - DeploymentPlan plan, - HypervisorType hyperType) throws InsufficientCapacityException { + public void allocate(String vmInstanceName, VirtualMachineTemplate template, ServiceOffering serviceOffering, LinkedHashMap networks, + DeploymentPlan plan, HypervisorType hyperType) throws InsufficientCapacityException { allocate(vmInstanceName, template, serviceOffering, new Pair(serviceOffering, null), null, networks, plan, hyperType); } @@ -498,7 +494,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @Override public boolean start() { - _executor.scheduleAtFixedRate(new CleanupTask(), _cleanupInterval, _cleanupInterval, TimeUnit.SECONDS); + _executor.scheduleAtFixedRate(new CleanupTask(), _cleanupInterval.value(), _cleanupInterval.value(), TimeUnit.SECONDS); cancelWorkItems(_nodeId); return true; } @@ -510,21 +506,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @Override public boolean configure(String name, Map xmlParams) throws ConfigurationException { - Map params = _configDao.getConfiguration(xmlParams); - - _retry = NumbersUtil.parseInt(params.get(Config.StartRetry.key()), 10); - ReservationContextImpl.init(_entityMgr); VirtualMachineProfileImpl.init(_entityMgr); - _cancelWait = NumbersUtil.parseLong(params.get(Config.VmOpCancelInterval.key()), 3600); - _cleanupWait = NumbersUtil.parseLong(params.get(Config.VmOpCleanupWait.key()), 3600); - _cleanupInterval = NumbersUtil.parseLong(params.get(Config.VmOpCleanupInterval.key()), 86400) * 1000; - _opWaitInterval = NumbersUtil.parseLong(params.get(Config.VmOpWaitInterval.key()), 120) * 1000; - _lockStateRetry = NumbersUtil.parseInt(params.get(Config.VmOpLockStateRetry.key()), 5); - _operationTimeout = NumbersUtil.parseInt(params.get(Config.Wait.key()), 1800) * 2; - _forceStop = Boolean.parseBoolean(params.get(Config.VmDestroyForcestop.key())); - _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Vm-Operations-Cleanup")); _nodeId = ManagementServerNode.getManagementServerId(); @@ -572,13 +556,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return true; } - if (vo.getSecondsTaskIsInactive() > _cancelWait) { + if (vo.getSecondsTaskIsInactive() > _cancelWait.value()) { s_logger.warn("The task item for vm " + vm + " has been inactive for " + vo.getSecondsTaskIsInactive()); return false; } try { - Thread.sleep(_opWaitInterval); + Thread.sleep(_opWaitInterval.value()); } catch (InterruptedException e) { s_logger.info("Waiting for " + vm + " but is interrupted"); throw new ConcurrentOperationException("Waiting for " + vm + " but is interrupted"); @@ -590,11 +574,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @DB protected Ternary changeToStartState(VirtualMachineGuru vmGuru, VMInstanceVO vm, User caller, Account account) - throws ConcurrentOperationException { + throws ConcurrentOperationException { long vmId = vm.getId(); ItWorkVO work = new ItWorkVO(UUID.randomUUID().toString(), _nodeId, State.Starting, vm.getType(), vm.getId()); - int retry = _lockStateRetry; + int retry = _lockStateRetry.value(); while (retry-- != 0) { Transaction txn = Transaction.currentTxn(); Ternary result = null; @@ -682,14 +666,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } @Override - public void advanceStart(String vmUuid, Map params) - throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { + public void advanceStart(String vmUuid, Map params) throws InsufficientCapacityException, ConcurrentOperationException, + ResourceUnavailableException { advanceStart(vmUuid, params, null); } @Override - public void advanceStart(String vmUuid, Map params, DeploymentPlan planToDeploy) - throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { + public void advanceStart(String vmUuid, Map params, DeploymentPlan planToDeploy) throws InsufficientCapacityException, + ConcurrentOperationException, ResourceUnavailableException { CallContext cctxt = CallContext.current(); Account account = cctxt.getCallingAccount(); User caller = cctxt.getCallingUser(); @@ -709,7 +693,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac VMInstanceVO startedVm = null; ServiceOfferingVO offering = _offeringDao.findById(vm.getServiceOfferingId()); - VMTemplateVO template = _templateDao.findById(vm.getTemplateId()); + VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, vm.getTemplateId()); if (s_logger.isDebugEnabled()) { s_logger.debug("Trying to deploy VM, vm has dcId: " + vm.getDataCenterId() + " and podId: " + vm.getPodIdToDeployIn()); @@ -717,11 +701,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodIdToDeployIn(), null, null, null, null, ctx); if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) { if (s_logger.isDebugEnabled()) { - s_logger.debug("advanceStart: DeploymentPlan is provided, using dcId:" + planToDeploy.getDataCenterId() + ", podId: " + planToDeploy.getPodId() + ", clusterId: " - + planToDeploy.getClusterId() + ", hostId: " + planToDeploy.getHostId() + ", poolId: " + planToDeploy.getPoolId()); + s_logger.debug("advanceStart: DeploymentPlan is provided, using dcId:" + planToDeploy.getDataCenterId() + ", podId: " + planToDeploy.getPodId() + ", clusterId: " + + planToDeploy.getClusterId() + ", hostId: " + planToDeploy.getHostId() + ", poolId: " + planToDeploy.getPoolId()); } plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), - planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId(), ctx); + planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId(), ctx); } HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType()); @@ -745,7 +729,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac boolean reuseVolume = true; DataCenterDeployment originalPlan = plan; - int retry = _retry; + int retry = _retry.value(); while (retry-- != 0) { // It's != so that it can match -1. if (reuseVolume) { @@ -778,22 +762,21 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac // cannot satisfy the plan passed in to the // planner if (s_logger.isDebugEnabled()) { - s_logger.debug("Cannot satisfy the deployment plan passed in since the ready Root volume is in different cluster. volume's cluster: " - + rootVolClusterId - + ", cluster specified: " + clusterIdSpecified); + s_logger.debug("Cannot satisfy the deployment plan passed in since the ready Root volume is in different cluster. volume's cluster: " + + rootVolClusterId + ", cluster specified: " + clusterIdSpecified); } throw new ResourceUnavailableException( - "Root volume is ready in different cluster, Deployment plan provided cannot be satisfied, unable to create a deployment for " - + vm, Cluster.class, clusterIdSpecified); + "Root volume is ready in different cluster, Deployment plan provided cannot be satisfied, unable to create a deployment for " + vm, + Cluster.class, clusterIdSpecified); } } plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), - vol.getPoolId(), null, ctx); + vol.getPoolId(), null, ctx); } else { plan = new DataCenterDeployment(rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null, ctx); if (s_logger.isDebugEnabled()) { - s_logger.debug(vol + " is READY, changing deployment plan to use this pool's dcId: " + rootVolDcId + " , podId: " + rootVolPodId - + " , and clusterId: " + rootVolClusterId); + s_logger.debug(vol + " is READY, changing deployment plan to use this pool's dcId: " + rootVolDcId + " , podId: " + rootVolPodId + + " , and clusterId: " + rootVolClusterId); } planChangedByVolume = true; } @@ -807,8 +790,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac dest = _dpMgr.planDeployment(vmProfile, plan, avoids); } catch (AffinityConflictException e2) { s_logger.warn("Unable to create deployment, affinity rules associted to the VM conflict", e2); - throw new CloudRuntimeException( - "Unable to create deployment, affinity rules associted to the VM conflict"); + throw new CloudRuntimeException("Unable to create deployment, affinity rules associted to the VM conflict"); } @@ -820,8 +802,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac reuseVolume = false; continue; } - throw new InsufficientServerCapacityException("Unable to create a deployment for " + vmProfile, - DataCenter.class, plan.getDataCenterId(), areAffinityGroupsAssociated(vmProfile)); + throw new InsufficientServerCapacityException("Unable to create a deployment for " + vmProfile, DataCenter.class, plan.getDataCenterId(), + areAffinityGroupsAssociated(vmProfile)); } if (dest != null) { @@ -832,16 +814,16 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac long destHostId = dest.getHost().getId(); vm.setPodId(dest.getPod().getId()); Long cluster_id = dest.getCluster().getId(); - ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao.findDetail(cluster_id,"cpuOvercommitRatio"); - ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao.findDetail(cluster_id,"memoryOvercommitRatio"); + ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao.findDetail(cluster_id, "cpuOvercommitRatio"); + ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao.findDetail(cluster_id, "memoryOvercommitRatio"); //storing the value of overcommit in the vm_details table for doing a capacity check in case the cluster overcommit ratio is changed. - if (_uservmDetailsDao.findDetail(vm.getId(),"cpuOvercommitRatio") == null && ((Float.parseFloat(cluster_detail_cpu.getValue()) > 1f || Float.parseFloat(cluster_detail_ram.getValue()) > 1f)) ){ + if (_uservmDetailsDao.findDetail(vm.getId(), "cpuOvercommitRatio") == null && + ((Float.parseFloat(cluster_detail_cpu.getValue()) > 1f || Float.parseFloat(cluster_detail_ram.getValue()) > 1f))) { UserVmDetailVO vmDetail_cpu = new UserVmDetailVO(vm.getId(), "cpuOvercommitRatio", cluster_detail_cpu.getValue()); UserVmDetailVO vmDetail_ram = new UserVmDetailVO(vm.getId(), "memoryOvercommitRatio", cluster_detail_ram.getValue()); _uservmDetailsDao.persist(vmDetail_cpu); _uservmDetailsDao.persist(vmDetail_ram); - } - else if (_uservmDetailsDao.findDetail(vm.getId(),"cpuOvercommitRatio") != null) { + } else if (_uservmDetailsDao.findDetail(vm.getId(), "cpuOvercommitRatio") != null) { UserVmDetailVO vmDetail_cpu = _uservmDetailsDao.findDetail(vm.getId(), "cpuOvercommitRatio"); vmDetail_cpu.setValue(cluster_detail_cpu.getValue()); UserVmDetailVO vmDetail_ram = _uservmDetailsDao.findDetail(vm.getId(), "memoryOvercommitRatio"); @@ -880,7 +862,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac VirtualMachineTO vmTO = hvGuru.implement(vmProfile); cmds = new Commands(Command.OnError.Stop); - cmds.addCommand(new StartCommand(vmTO, dest.getHost(), _mgmtServer.getExecuteInSequence())); + cmds.addCommand(new StartCommand(vmTO, dest.getHost(), getExecuteInSequence())); vmGuru.finalizeDeployment(cmds, vmProfile, dest, ctx); @@ -922,7 +904,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac s_logger.info("The guru did not like the answers so stopping " + vm); } - StopCommand cmd = new StopCommand(vm, _mgmtServer.getExecuteInSequence()); + StopCommand cmd = new StopCommand(vm, getExecuteInSequence()); StopAnswer answer = (StopAnswer)_agentMgr.easySend(destHostId, cmd); if (answer == null || !answer.getResult()) { s_logger.warn("Unable to stop " + vm + " due to " + (answer != null ? answer.getDetails() : "no answers")); @@ -994,8 +976,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } if (startedVm == null) { - throw new CloudRuntimeException("Unable to start instance '" + vm.getHostName() - + "' (" + vm.getUuid() + "), see management server log for details"); + throw new CloudRuntimeException("Unable to start instance '" + vm.getHostName() + "' (" + vm.getUuid() + "), see management server log for details"); } } @@ -1022,9 +1003,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } + protected boolean getExecuteInSequence() { + return false; + } + protected boolean sendStop(VirtualMachineGuru guru, VirtualMachineProfile profile, boolean force) { VirtualMachine vm = profile.getVirtualMachine(); - StopCommand stop = new StopCommand(vm, _mgmtServer.getExecuteInSequence()); + StopCommand stop = new StopCommand(vm, getExecuteInSequence()); try { Answer answer = _agentMgr.send(vm.getHostId(), stop); if (!answer.getResult()) { @@ -1217,7 +1202,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } vmGuru.prepareStop(profile); - StopCommand stop = new StopCommand(vm, _mgmtServer.getExecuteInSequence()); + StopCommand stop = new StopCommand(vm, getExecuteInSequence()); boolean stopped = false; StopAnswer answer = null; try { @@ -1344,7 +1329,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac s_logger.debug("Destroying vm " + vm); } - advanceStop(vm, _forceStop); + advanceStop(vm, _forceStop.value()); if (!_vmSnapshotMgr.deleteAllVMSnapshots(vm.getId(), null)) { s_logger.debug("Unable to delete all snapshots for " + vm); @@ -1566,9 +1551,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac s_logger.info("Migration was unsuccessful. Cleaning up: " + vm); _networkMgr.rollbackNicForMigration(vmSrc, profile); - _alertMgr.sendAlert(alertType, fromHost.getDataCenterId(), fromHost.getPodId(), "Unable to migrate vm " + vm.getInstanceName() + " from host " + fromHost.getName() - + " in zone " - + dest.getDataCenter().getName() + " and pod " + dest.getPod().getName(), "Migrate Command failed. Please check logs."); + _alertMgr.sendAlert(alertType, fromHost.getDataCenterId(), fromHost.getPodId(), "Unable to migrate vm " + vm.getInstanceName() + " from host " + + fromHost.getName() + " in zone " + dest.getDataCenter().getName() + " and pod " + + dest.getPod().getName(), "Migrate Command failed. Please check logs."); try { _agentMgr.send(dstHostId, new Commands(cleanup(vm)), null); } catch (AgentUnavailableException ae) { @@ -1598,13 +1583,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (pool != null) { // Check if pool is accessible from the destination host and disk offering with which the volume was // created is compliant with the pool type. - if (_poolHostDao.findByPoolHost(pool.getId(), host.getId()) == null || - pool.isLocal() != diskOffering.getUseLocalStorage()) { + if (_poolHostDao.findByPoolHost(pool.getId(), host.getId()) == null || pool.isLocal() != diskOffering.getUseLocalStorage()) { // Cannot find a pool for the volume. Throw an exception. - throw new CloudRuntimeException("Cannot migrate volume " + volume + " to storage pool " + pool + - " while migrating vm to host " + host + ". Either the pool is not accessible from the " + - "host or because of the offering with which the volume is created it cannot be placed on " + - "the given pool."); + throw new CloudRuntimeException("Cannot migrate volume " + volume + " to storage pool " + pool + " while migrating vm to host " + host + + ". Either the pool is not accessible from the " + + "host or because of the offering with which the volume is created it cannot be placed on " + "the given pool."); } else if (pool.getId() == currentPool.getId()) { // If the pool to migrate too is the same as current pool, remove the volume from the list of // volumes to be migrated. @@ -1613,14 +1596,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } else { // Find a suitable pool for the volume. Call the storage pool allocator to find the list of pools. DiskProfile diskProfile = new DiskProfile(volume, diskOffering, profile.getHypervisorType()); - DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), - host.getClusterId(), host.getId(), null, null); + DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), null, null); ExcludeList avoid = new ExcludeList(); boolean currentPoolAvailable = false; for (StoragePoolAllocator allocator : _storagePoolAllocators) { - List poolList = allocator.allocateToPool(diskProfile, profile, plan, avoid, - StoragePoolAllocator.RETURN_UPTO_ALL); + List poolList = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL); if (poolList != null && !poolList.isEmpty()) { // Volume needs to be migrated. Pick the first pool from the list. Add a mapping to migrate the // volume to a pool only if it is required; that is the current pool on which the volume resides @@ -1637,9 +1618,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (!currentPoolAvailable && !volumeToPool.containsKey(volume)) { // Cannot find a pool for the volume. Throw an exception. - throw new CloudRuntimeException("Cannot find a storage pool which is available for volume " + - volume + " while migrating virtual machine " + profile.getVirtualMachine() + " to host " + - host); + throw new CloudRuntimeException("Cannot find a storage pool which is available for volume " + volume + " while migrating virtual machine " + + profile.getVirtualMachine() + " to host " + host); } } } @@ -1647,8 +1627,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return volumeToPool; } - private void moveVmToMigratingState(T vm, Long hostId, ItWorkVO work) - throws ConcurrentOperationException { + private void moveVmToMigratingState(T vm, Long hostId, ItWorkVO work) throws ConcurrentOperationException { // Put the vm in migrating state. try { if (!changeState(vm, Event.MigrationRequested, hostId, work, Step.Migrating)) { @@ -1661,8 +1640,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } - private void moveVmOutofMigratingStateOnSuccess(T vm, Long hostId, ItWorkVO work) - throws ConcurrentOperationException { + private void moveVmOutofMigratingStateOnSuccess(T vm, Long hostId, ItWorkVO work) throws ConcurrentOperationException { // Put the vm in running state. try { if (!changeState(vm, Event.OperationSucceeded, hostId, work, Step.Started)) { @@ -1677,7 +1655,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @Override public void migrateWithStorage(String vmUuid, long srcHostId, long destHostId, Map volumeToPool) throws ResourceUnavailableException, - ConcurrentOperationException { + ConcurrentOperationException { VMInstanceVO vm = _vmDao.findByUuid(vmUuid); HostVO srcHost = _hostDao.findById(srcHostId); @@ -1696,8 +1674,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac // If none of the volumes have to be migrated, fail the call. Administrator needs to make a call for migrating // a vm and not migrating a vm with storage. if (volumeToPool.isEmpty()) { - throw new InvalidParameterValueException("Migration of the vm " + vm + "from host " + srcHost + - " to destination host " + destHost + " doesn't involve migrating the volumes."); + throw new InvalidParameterValueException("Migration of the vm " + vm + "from host " + srcHost + " to destination host " + destHost + + " doesn't involve migrating the volumes."); } short alertType = AlertManager.ALERT_TYPE_USERVM_MIGRATE; @@ -1749,9 +1727,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } finally { if (!migrated) { s_logger.info("Migration was unsuccessful. Cleaning up: " + vm); - _alertMgr.sendAlert(alertType, srcHost.getDataCenterId(), srcHost.getPodId(), "Unable to migrate vm " + - vm.getInstanceName() + " from host " + srcHost.getName() + " in zone " + dc.getName() + - " and pod " + dc.getName(), "Migrate Command failed. Please check logs."); + _alertMgr.sendAlert(alertType, srcHost.getDataCenterId(), srcHost.getPodId(), "Unable to migrate vm " + vm.getInstanceName() + " from host " + srcHost.getName() + + " in zone " + dc.getName() + " and pod " + dc.getName(), + "Migrate Command failed. Please check logs."); try { _agentMgr.send(destHostId, new Commands(cleanup(vm.getInstanceName())), null); stateTransitTo(vm, Event.OperationFailed, srcHostId); @@ -1842,8 +1820,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac dest = _dpMgr.planDeployment(profile, plan, excludes); } catch (AffinityConflictException e2) { s_logger.warn("Unable to create deployment, affinity rules associted to the VM conflict", e2); - throw new CloudRuntimeException( - "Unable to create deployment, affinity rules associted to the VM conflict"); + throw new CloudRuntimeException("Unable to create deployment, affinity rules associted to the VM conflict"); } if (dest != null) { @@ -1888,7 +1865,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac public void run() { s_logger.trace("VM Operation Thread Running"); try { - _workDao.cleanup(_cleanupWait); + _workDao.cleanup(_cleanupWait.value()); } catch (Exception e) { s_logger.error("VM Operations failed due to ", e); } @@ -1920,7 +1897,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @Override public void advanceReboot(String vmUuid, Map params) throws InsufficientCapacityException, ConcurrentOperationException, - ResourceUnavailableException { + ResourceUnavailableException { VMInstanceVO vm = _vmDao.findByUuid(vmUuid); DataCenter dc = _entityMgr.findById(DataCenter.class, vm.getDataCenterId()); @@ -1950,11 +1927,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } public Command cleanup(VirtualMachine vm) { - return new StopCommand(vm, _mgmtServer.getExecuteInSequence()); + return new StopCommand(vm, getExecuteInSequence()); } public Command cleanup(String vmName) { - return new StopCommand(vmName, _mgmtServer.getExecuteInSequence()); + return new StopCommand(vmName, getExecuteInSequence()); } public Commands fullHostSync(final long hostId, StartupRoutingCommand startup) { @@ -1969,7 +1946,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac // sync VM Snapshots related transient states List vmSnapshotsInTrasientStates = _vmSnapshotDao.listByInstanceId(vm.getId(), VMSnapshot.State.Expunging, VMSnapshot.State.Reverting, - VMSnapshot.State.Creating); + VMSnapshot.State.Creating); if (vmSnapshotsInTrasientStates.size() > 1) { s_logger.info("Found vm " + vm.getInstanceName() + " with VM snapshots in transient states, needs to sync VM snapshot state"); if (!_vmSnapshotMgr.syncVMSnapshot(vm, hostId)) { @@ -2092,7 +2069,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac // sync VM Snapshots related transient states List vmSnapshotsInExpungingStates = _vmSnapshotDao.listByInstanceId(vm.getId(), VMSnapshot.State.Expunging, VMSnapshot.State.Creating, - VMSnapshot.State.Reverting); + VMSnapshot.State.Reverting); if (vmSnapshotsInExpungingStates.size() > 0) { s_logger.info("Found vm " + vm.getInstanceName() + " in state. " + vm.getState() + ", needs to sync VM snapshot state"); Long hostId = null; @@ -2109,11 +2086,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } - if ((info == null && (vm.getState() == State.Running || vm.getState() == State.Starting)) - || (info != null && (info.state == State.Running && vm.getState() == State.Starting))) - { - s_logger.info("Found vm " + vm.getInstanceName() + " in inconsistent state. " + vm.getState() + " on CS while " + (info == null ? "Stopped" : "Running") - + " on agent"); + if ((info == null && (vm.getState() == State.Running || vm.getState() == State.Starting)) || + (info != null && (info.state == State.Running && vm.getState() == State.Starting))) { + s_logger.info("Found vm " + vm.getInstanceName() + " in inconsistent state. " + vm.getState() + " on CS while " + (info == null ? "Stopped" : "Running") + + " on agent"); info = new AgentVmInfo(vm.getInstanceName(), vm, State.Stopped); // Bug 13850- grab outstanding work item if any for this VM state so that we mark it as DONE after we change VM state, else it will remain pending @@ -2149,9 +2125,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac s_logger.warn("Unable to update state of the VM due to exception " + e.getMessage()); e.printStackTrace(); } - } - else if (info != null && (vm.getState() == State.Stopped || vm.getState() == State.Stopping - || vm.isRemoved() || vm.getState() == State.Destroyed || vm.getState() == State.Expunging)) { + } else if (info != null && + (vm.getState() == State.Stopped || vm.getState() == State.Stopping || vm.isRemoved() || vm.getState() == State.Destroyed || vm.getState() == State.Expunging)) { Host host = _hostDao.findByGuid(info.getHostUuid()); if (host != null) { s_logger.warn("Stopping a VM which is stopped/stopping/destroyed/expunging " + info.name); @@ -2169,8 +2144,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac s_logger.warn("Unable to stop a VM due to " + e.getMessage()); } } - } - else + } else // host id can change if (info != null && vm.getState() == State.Running) { // check for host id changes @@ -2306,18 +2280,16 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac HostVO hostVO = _hostDao.findById(vm.getHostId()); String hostDesc = "name: " + hostVO.getName() + " (id:" + hostVO.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName(); - _alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodIdToDeployIn(), "VM (name: " + vm.getInstanceName() + ", id: " + vm.getId() + ") stopped on host " - + hostDesc - + " due to storage failure", "Virtual Machine " + vm.getInstanceName() + " (id: " + vm.getId() + ") running on host [" + vm.getHostId() - + "] stopped due to storage failure."); + _alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodIdToDeployIn(), "VM (name: " + vm.getInstanceName() + ", id: " + vm.getId() + ") stopped on host " + + hostDesc + " due to storage failure", + "Virtual Machine " + vm.getInstanceName() + " (id: " + vm.getId() + ") running on host [" + vm.getHostId() + "] stopped due to storage failure."); } if (trackExternalChange) { if (serverState == State.Starting) { if (vm.getHostId() != null && vm.getHostId() != hostId) { - s_logger.info("CloudStack is starting VM on host " + vm.getHostId() + ", but status report comes from a different host " + hostId - + ", skip status sync for vm: " - + vm.getInstanceName()); + s_logger.info("CloudStack is starting VM on host " + vm.getHostId() + ", but status report comes from a different host " + hostId + + ", skip status sync for vm: " + vm.getInstanceName()); return null; } } @@ -2341,9 +2313,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (trackExternalChange) { if (serverState == State.Starting) { if (vm.getHostId() != null && vm.getHostId() != hostId) { - s_logger.info("CloudStack is starting VM on host " + vm.getHostId() + ", but status report comes from a different host " + hostId - + ", skip status sync for vm: " - + vm.getInstanceName()); + s_logger.info("CloudStack is starting VM on host " + vm.getHostId() + ", but status report comes from a different host " + hostId + + ", skip status sync for vm: " + vm.getInstanceName()); return null; } } @@ -2358,8 +2329,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac // if (vm.getHostId() == null || hostId != vm.getHostId()) { if (s_logger.isDebugEnabled()) { - s_logger.debug("detected host change when VM " + vm + " is at running state, VM could be live-migrated externally from host " + vm.getHostId() - + " to host " + hostId); + s_logger.debug("detected host change when VM " + vm + " is at running state, VM could be live-migrated externally from host " + vm.getHostId() + + " to host " + hostId); } stateTransitTo(vm, VirtualMachine.Event.AgentReportMigrated, hostId); @@ -2457,7 +2428,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } private void ensureVmRunningContext(long hostId, VMInstanceVO vm, Event cause) throws OperationTimedoutException, ResourceUnavailableException, NoTransitionException, - InsufficientAddressCapacityException { + InsufficientAddressCapacityException { VirtualMachineGuru vmGuru = getVmGuru(vm); s_logger.debug("VM state is starting on full sync so updating it to running"); @@ -2485,8 +2456,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac List nics = _nicsDao.listByVmId(profile.getId()); for (NicVO nic : nics) { Network network = _networkModel.getNetwork(nic.getNetworkId()); - NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, - _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(profile.getHypervisorType(), network)); + NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel.isSecurityGroupSupportedInNetwork(network), + _networkModel.getNetworkTag(profile.getHypervisorType(), network)); profile.addNic(nicProfile); } @@ -2604,15 +2575,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } // initiate the cron job - ClusterSyncCommand syncCmd = new ClusterSyncCommand(Integer.parseInt(Config.ClusterDeltaSyncInterval.getDefaultValue()), clusterId); + ClusterSyncCommand syncCmd = new ClusterSyncCommand(_syncInterval.value(), clusterId); try { long seq_no = _agentMgr.send(agentId, new Commands(syncCmd), this); s_logger.debug("Cluster VM sync started with jobid " + seq_no); } catch (AgentUnavailableException e) { s_logger.fatal("The Cluster VM sync process failed for cluster id " + clusterId + " with ", e); } - } - else { // for others KVM and VMWare + } else { // for others KVM and VMWare StartupRoutingCommand startup = (StartupRoutingCommand)cmd; Commands commands = fullHostSync(agentId, startup); @@ -2658,7 +2628,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } try { lock.addRef(); - List instances = _vmDao.findVMInTransition(new Date(new Date().getTime() - (_operationTimeout * 1000)), State.Starting, State.Stopping); + List instances = _vmDao.findVMInTransition(new Date(new Date().getTime() - (_operationTimeout.value() * 1000)), State.Starting, State.Stopping); for (VMInstanceVO instance : instances) { State state = instance.getState(); if (state == State.Stopping) { @@ -2712,19 +2682,18 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac // Check that the VM is stopped / running if (!(vmInstance.getState().equals(State.Stopped) || vmInstance.getState().equals(State.Running))) { s_logger.warn("Unable to upgrade virtual machine " + vmInstance.toString() + " in state " + vmInstance.getState()); - throw new InvalidParameterValueException("Unable to upgrade virtual machine " + vmInstance.toString() + " " + " in state " + vmInstance.getState() - + "; make sure the virtual machine is stopped/running"); + throw new InvalidParameterValueException("Unable to upgrade virtual machine " + vmInstance.toString() + " " + " in state " + vmInstance.getState() + + "; make sure the virtual machine is stopped/running"); } // Check if the service offering being upgraded to is what the VM is already running with if (vmInstance.getServiceOfferingId() == newServiceOffering.getId()) { if (s_logger.isInfoEnabled()) { - s_logger.info("Not upgrading vm " + vmInstance.toString() + " since it already has the requested " + - "service offering (" + newServiceOffering.getName() + ")"); + s_logger.info("Not upgrading vm " + vmInstance.toString() + " since it already has the requested " + "service offering (" + newServiceOffering.getName() + ")"); } - throw new InvalidParameterValueException("Not upgrading vm " + vmInstance.toString() + " since it already " + - "has the requested service offering (" + newServiceOffering.getName() + ")"); + throw new InvalidParameterValueException("Not upgrading vm " + vmInstance.toString() + " since it already " + "has the requested service offering (" + + newServiceOffering.getName() + ")"); } ServiceOfferingVO currentServiceOffering = _offeringDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId()); @@ -2741,10 +2710,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac // Check that the service offering being upgraded to has the same storage pool preference as the VM's current service // offering if (currentServiceOffering.getUseLocalStorage() != newServiceOffering.getUseLocalStorage()) { - throw new InvalidParameterValueException("Unable to upgrade virtual machine " + vmInstance.toString() - + ", cannot switch between local storage and shared storage service offerings. Current offering " + - "useLocalStorage=" + currentServiceOffering.getUseLocalStorage() - + ", target offering useLocalStorage=" + newServiceOffering.getUseLocalStorage()); + throw new InvalidParameterValueException("Unable to upgrade virtual machine " + vmInstance.toString() + + ", cannot switch between local storage and shared storage service offerings. Current offering " + "useLocalStorage=" + + currentServiceOffering.getUseLocalStorage() + ", target offering useLocalStorage=" + newServiceOffering.getUseLocalStorage()); } // if vm is a system vm, check if it is a system service offering, if yes return with error as it cannot be used for user vms @@ -2754,19 +2722,17 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac // Check that there are enough resources to upgrade the service offering if (!isVirtualMachineUpgradable(vmInstance, newServiceOffering)) { - throw new InvalidParameterValueException("Unable to upgrade virtual machine, not enough resources available " + - "for an offering of " + newServiceOffering.getCpu() + " cpu(s) at " - + newServiceOffering.getSpeed() + " Mhz, and " + newServiceOffering.getRamSize() + " MB of memory"); + throw new InvalidParameterValueException("Unable to upgrade virtual machine, not enough resources available " + "for an offering of " + newServiceOffering.getCpu() + + " cpu(s) at " + newServiceOffering.getSpeed() + " Mhz, and " + newServiceOffering.getRamSize() + " MB of memory"); } // Check that the service offering being upgraded to has all the tags of the current service offering List currentTags = StringUtils.csvTagsToList(currentServiceOffering.getTags()); List newTags = StringUtils.csvTagsToList(newServiceOffering.getTags()); if (!newTags.containsAll(currentTags)) { - throw new InvalidParameterValueException("Unable to upgrade virtual machine; the new service offering " + - "does not have all the tags of the " - + "current service offering. Current service offering tags: " + currentTags + "; " + "new service " + - "offering tags: " + newTags); + throw new InvalidParameterValueException("Unable to upgrade virtual machine; the new service offering " + "does not have all the tags of the " + + "current service offering. Current service offering tags: " + currentTags + "; " + "new service " + "offering tags: " + + newTags); } } @@ -2782,13 +2748,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } @Override - public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException, - ResourceUnavailableException, InsufficientCapacityException { + public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + CallContext cctx = CallContext.current(); s_logger.debug("Adding vm " + vm + " to network " + network + "; requested nic profile " + requested); VMInstanceVO vmVO = _vmDao.findById(vm.getId()); - ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), - _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM)); + ReservationContext context = new ReservationContextImpl(null, null, cctx.getCallingUser(), cctx.getCallingAccount()); VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, null, null, null); @@ -2818,18 +2784,16 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac s_logger.debug("Nic is plugged successfully for vm " + vm + " in network " + network + ". Vm is a part of network now"); long isDefault = (nic.isDefaultNic()) ? 1 : 0; // insert nic's Id into DB as resource_name - UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmVO.getAccountId(), - vmVO.getDataCenterId(), vmVO.getId(), Long.toString(nic.getId()), network.getNetworkOfferingId(), - null, isDefault, VirtualMachine.class.getName(), vmVO.getUuid()); + UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmVO.getAccountId(), vmVO.getDataCenterId(), vmVO.getId(), + Long.toString(nic.getId()), network.getNetworkOfferingId(), null, isDefault, VirtualMachine.class.getName(), vmVO.getUuid()); return nic; } else { s_logger.warn("Failed to plug nic to the vm " + vm + " in network " + network); return null; } } finally { - if (!result){ - s_logger.debug("Removing nic " + nic + " from vm " + vmProfile.getVirtualMachine() - + " as nic plug failed on the backend"); + if (!result) { + s_logger.debug("Removing nic " + nic + " from vm " + vmProfile.getVirtualMachine() + " as nic plug failed on the backend"); _networkMgr.removeNic(vmProfile, _nicsDao.findById(nic.getId())); } } @@ -2838,8 +2802,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return _networkMgr.createNicForVm(network, requested, context, vmProfile, false); } else { s_logger.warn("Unable to add vm " + vm + " to network " + network); - throw new ResourceUnavailableException("Unable to add vm " + vm + " to network, is not in the right state", - DataCenter.class, vm.getDataCenterId()); + throw new ResourceUnavailableException("Unable to add vm " + vm + " to network, is not in the right state", DataCenter.class, vm.getDataCenterId()); } } @@ -2853,13 +2816,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @Override public boolean removeNicFromVm(VirtualMachine vm, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException { + CallContext cctx = CallContext.current(); VMInstanceVO vmVO = _vmDao.findById(vm.getId()); NetworkVO network = _networkDao.findById(nic.getNetworkId()); - ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), - _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM)); + ReservationContext context = new ReservationContextImpl(null, null, cctx.getCallingUser(), cctx.getCallingAccount()); - VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, - null, null, null); + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, null, null, null); DataCenter dc = _entityMgr.findById(DataCenter.class, network.getDataCenterId()); Host host = _hostDao.findById(vm.getHostId()); @@ -2875,14 +2837,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac // if specified nic is associated with PF/LB/Static NAT if (rulesMgr.listAssociatedRulesForGuestNic(nic).size() > 0) { - throw new CloudRuntimeException("Failed to remove nic from " + vm + " in " + network - + ", nic has associated Port forwarding or Load balancer or Static NAT rules."); + throw new CloudRuntimeException("Failed to remove nic from " + vm + " in " + network + ", nic has associated Port forwarding or Load balancer or Static NAT rules."); } - NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), - _networkModel.getNetworkRate(network.getId(), vm.getId()), - _networkModel.isSecurityGroupSupportedInNetwork(network), - _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network)); + NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(network.getId(), vm.getId()), + _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network)); //1) Unplug the nic if (vm.getState() == State.Running) { @@ -2892,17 +2851,15 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (result) { s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network); long isDefault = (nic.isDefaultNic()) ? 1 : 0; - UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(), - vm.getId(), Long.toString(nic.getId()), network.getNetworkOfferingId(), null, - isDefault, VirtualMachine.class.getName(), vm.getUuid()); + UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), Long.toString(nic.getId()), + network.getNetworkOfferingId(), null, isDefault, VirtualMachine.class.getName(), vm.getUuid()); } else { s_logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network); return false; } } else if (vm.getState() != State.Stopped) { s_logger.warn("Unable to remove vm " + vm + " from network " + network); - throw new ResourceUnavailableException("Unable to remove vm " + vm + " from network, is not in the right state", - DataCenter.class, vm.getDataCenterId()); + throw new ResourceUnavailableException("Unable to remove vm " + vm + " from network, is not in the right state", DataCenter.class, vm.getDataCenterId()); } //2) Release the nic @@ -2918,12 +2875,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @Override @DB public boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException { + CallContext cctx = CallContext.current(); VMInstanceVO vmVO = _vmDao.findById(vm.getId()); - ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), - _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM)); + ReservationContext context = new ReservationContextImpl(null, null, cctx.getCallingUser(), cctx.getCallingAccount()); - VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, - null, null, null); + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, null, null, null); DataCenter dc = _entityMgr.findById(DataCenter.class, network.getDataCenterId()); Host host = _hostDao.findById(vm.getHostId()); @@ -2937,12 +2893,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } else { nic = _networkModel.getNicInNetwork(vm.getId(), network.getId()); } - - if (nic == null){ + + if (nic == null) { s_logger.warn("Could not get a nic with " + network); return false; } - + // don't delete default NIC on a user VM if (nic.isDefaultNic() && vm.getType() == VirtualMachine.Type.User) { s_logger.warn("Failed to remove nic from " + vm + " in " + network + ", nic is default."); @@ -2961,16 +2917,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } throw new ConcurrentOperationException("Unable to lock nic " + nic.getId()); } - + if (s_logger.isDebugEnabled()) { s_logger.debug("Lock is acquired for nic id " + lock.getId() + " as a part of remove vm " + vm + " from network " + network); } - + try { - NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), - _networkModel.getNetworkRate(network.getId(), vm.getId()), - _networkModel.isSecurityGroupSupportedInNetwork(network), - _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network)); + NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(network.getId(), vm.getId()), + _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network)); //1) Unplug the nic if (vm.getState() == State.Running) { @@ -2978,20 +2932,19 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac s_logger.debug("Un-plugging nic for vm " + vm + " from network " + network); boolean result = unplugNic(network, nicTO, vmTO, context, dest); if (result) { - s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network ); + s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network); } else { s_logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network); return false; } } else if (vm.getState() != State.Stopped) { s_logger.warn("Unable to remove vm " + vm + " from network " + network); - throw new ResourceUnavailableException("Unable to remove vm " + vm + " from network, is not in the right state", - DataCenter.class, vm.getDataCenterId()); + throw new ResourceUnavailableException("Unable to remove vm " + vm + " from network, is not in the right state", DataCenter.class, vm.getDataCenterId()); } //2) Release the nic _networkMgr.releaseNic(vmProfile, nic); - s_logger.debug("Successfully released nic " + nic + "for vm " + vm); + s_logger.debug("Successfully released nic " + nic + "for vm " + vm); //3) Remove the nic _networkMgr.removeNic(vmProfile, nic); @@ -3008,7 +2961,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @Override public void findHostAndMigrate(String vmUuid, Long newSvcOfferingId, ExcludeList excludes) throws InsufficientCapacityException, ConcurrentOperationException, - ResourceUnavailableException { + ResourceUnavailableException { VMInstanceVO vm = _vmDao.findByUuid(vmUuid); if (vm == null) { @@ -3033,8 +2986,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac dest = _dpMgr.planDeployment(profile, plan, excludes); } catch (AffinityConflictException e2) { s_logger.warn("Unable to create deployment, affinity rules associted to the VM conflict", e2); - throw new CloudRuntimeException( - "Unable to create deployment, affinity rules associted to the VM conflict"); + throw new CloudRuntimeException("Unable to create deployment, affinity rules associted to the VM conflict"); } if (dest != null) { @@ -3193,9 +3145,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (!migrated) { s_logger.info("Migration was unsuccessful. Cleaning up: " + vm); - _alertMgr.sendAlert(alertType, fromHost.getDataCenterId(), fromHost.getPodId(), "Unable to migrate vm " + vm.getInstanceName() + " from host " + fromHost.getName() - + " in zone " - + dest.getDataCenter().getName() + " and pod " + dest.getPod().getName(), "Migrate Command failed. Please check logs."); + _alertMgr.sendAlert(alertType, fromHost.getDataCenterId(), fromHost.getPodId(), "Unable to migrate vm " + vm.getInstanceName() + " from host " + + fromHost.getName() + " in zone " + dest.getDataCenter().getName() + " and pod " + + dest.getPod().getName(), "Migrate Command failed. Please check logs."); try { _agentMgr.send(dstHostId, new Commands(cleanup(vm.getInstanceName())), null); } catch (AgentUnavailableException ae) { @@ -3215,8 +3167,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm, ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, - ResourceUnavailableException, - InsufficientCapacityException { + ResourceUnavailableException, InsufficientCapacityException { boolean result = true; VMInstanceVO router = _vmDao.findById(vm.getId()); @@ -3233,21 +3184,20 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac result = false; } } catch (OperationTimedoutException e) { - throw new AgentUnavailableException("Unable to plug nic for router " + vm.getName() + " in network " + network, - dest.getHost().getId(), e); + throw new AgentUnavailableException("Unable to plug nic for router " + vm.getName() + " in network " + network, dest.getHost().getId(), e); } } else { s_logger.warn("Unable to apply PlugNic, vm " + router + " is not in the right state " + router.getState()); - throw new ResourceUnavailableException("Unable to apply PlugNic on the backend," + - " vm " + vm + " is not in the right state", DataCenter.class, router.getDataCenterId()); + throw new ResourceUnavailableException("Unable to apply PlugNic on the backend," + " vm " + vm + " is not in the right state", DataCenter.class, + router.getDataCenterId()); } return result; } - public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, - ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException { + public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, + ResourceUnavailableException { boolean result = true; VMInstanceVO router = _vmDao.findById(vm.getId()); @@ -3265,39 +3215,39 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac result = false; } } catch (OperationTimedoutException e) { - throw new AgentUnavailableException("Unable to unplug nic from rotuer " + router + " from network " + network, - dest.getHost().getId(), e); + throw new AgentUnavailableException("Unable to unplug nic from rotuer " + router + " from network " + network, dest.getHost().getId(), e); } } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) { - s_logger.debug("Vm " + router.getInstanceName() + " is in " + router.getState() + - ", so not sending unplug nic command to the backend"); + s_logger.debug("Vm " + router.getInstanceName() + " is in " + router.getState() + ", so not sending unplug nic command to the backend"); } else { s_logger.warn("Unable to apply unplug nic, Vm " + router + " is not in the right state " + router.getState()); - throw new ResourceUnavailableException("Unable to apply unplug nic on the backend," + - " vm " + router + " is not in the right state", DataCenter.class, router.getDataCenterId()); + throw new ResourceUnavailableException("Unable to apply unplug nic on the backend," + " vm " + router + " is not in the right state", DataCenter.class, + router.getDataCenterId()); } return result; } + @InjectConfig(key = CapacityManager.CpuOverprovisioningFactorCK) + ConfigValue _cpuOverprovisioningFactor; + @InjectConfig(key = CapacityManager.MemOverprovisioningFactorCK) + ConfigValue _memOverprovisioningFactor; + @Override public VMInstanceVO reConfigureVm(String vmUuid, ServiceOffering oldServiceOffering, boolean reconfiguringOnExistingHost) throws ResourceUnavailableException, - ConcurrentOperationException { + ConcurrentOperationException { VMInstanceVO vm = _vmDao.findByUuid(vmUuid); long newServiceofferingId = vm.getServiceOfferingId(); ServiceOffering newServiceOffering = _entityMgr.findById(ServiceOffering.class, newServiceofferingId); HostVO hostVo = _hostDao.findById(vm.getHostId()); - Float memoryOvercommitRatio = Float.parseFloat(_configServer.getConfigValue(Config.MemOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), - hostVo.getClusterId())); - Float cpuOvercommitRatio = Float.parseFloat(_configServer.getConfigValue(Config.CPUOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), - hostVo.getClusterId())); + Float memoryOvercommitRatio = _memOverprovisioningFactor.valueIn(hostVo.getClusterId()); + Float cpuOvercommitRatio = _cpuOverprovisioningFactor.valueIn(hostVo.getClusterId()); long minMemory = (long)(newServiceOffering.getRamSize() / memoryOvercommitRatio); - ScaleVmCommand reconfigureCmd = new ScaleVmCommand(vm.getInstanceName(), newServiceOffering.getCpu(), - (int)(newServiceOffering.getSpeed() / cpuOvercommitRatio), newServiceOffering.getSpeed(), minMemory * 1024L * 1024L, - newServiceOffering.getRamSize() * 1024L * 1024L, newServiceOffering.getLimitCpuUse()); + ScaleVmCommand reconfigureCmd = new ScaleVmCommand(vm.getInstanceName(), newServiceOffering.getCpu(), (int)(newServiceOffering.getSpeed() / cpuOvercommitRatio), + newServiceOffering.getSpeed(), minMemory * 1024L * 1024L, newServiceOffering.getRamSize() * 1024L * 1024L, newServiceOffering.getLimitCpuUse()); Long dstHostId = vm.getHostId(); ItWorkVO work = new ItWorkVO(UUID.randomUUID().toString(), _nodeId, State.Running, vm.getType(), vm.getId()); @@ -3339,4 +3289,15 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } + @Override + public String getConfigComponentName() { + return VirtualMachineManager.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[] {ClusterDeltaSyncInterval, StartRetry, VmDestroyForcestop, VmOpCancelInterval, VmOpCleanupInterval, VmOpCleanupWait, VmOpLockStateRetry, + VmOpWaitInterval}; + } + } diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java index 19145211197..d78e6ee3062 100755 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java @@ -43,6 +43,10 @@ import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.context.ServerContexts; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; +import org.apache.cloudstack.framework.config.ConfigDepot; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.ConfigValue; +import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import com.cloud.agent.api.Answer; @@ -90,6 +94,7 @@ import com.cloud.network.Network.Service; import com.cloud.network.NetworkMigrationResponder; import com.cloud.network.NetworkModel; import com.cloud.network.NetworkProfile; +import com.cloud.network.NetworkStateListener; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.TrafficType; import com.cloud.network.PhysicalNetwork; @@ -101,7 +106,6 @@ import com.cloud.network.dao.AccountGuestVlanMapVO; import com.cloud.network.dao.FirewallRulesDao; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.IPAddressVO; -import com.cloud.network.dao.LoadBalancerDao; import com.cloud.network.dao.NetworkAccountDao; import com.cloud.network.dao.NetworkAccountVO; import com.cloud.network.dao.NetworkDao; @@ -115,7 +119,6 @@ import com.cloud.network.dao.PhysicalNetworkServiceProviderDao; import com.cloud.network.dao.PhysicalNetworkTrafficTypeDao; import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO; import com.cloud.network.dao.PhysicalNetworkVO; -import com.cloud.network.dao.UserIpv6AddressDao; import com.cloud.network.element.DhcpServiceProvider; import com.cloud.network.element.IpDeployer; import com.cloud.network.element.LoadBalancingServiceProvider; @@ -144,7 +147,6 @@ import com.cloud.user.Account; import com.cloud.user.ResourceLimitService; import com.cloud.user.User; import com.cloud.user.dao.AccountDao; -import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; import com.cloud.utils.component.AdapterBase; import com.cloud.utils.component.ManagerBase; @@ -183,8 +185,8 @@ import com.cloud.vm.dao.VMInstanceDao; /** * NetworkManagerImpl implements NetworkManager. */ -@Local(value = { NetworkOrchestrationService.class}) -public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestrationService, Listener { +@Local(value = {NetworkOrchestrationService.class}) +public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestrationService, Listener, Configurable { static final Logger s_logger = Logger.getLogger(NetworkOrchestrator.class); @Inject @@ -204,8 +206,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra @Inject AlertManager _alertMgr; @Inject - AccountManager _accountMgr; - @Inject ConfigurationManager _configMgr; @Inject NetworkOfferingDao _networkOfferingDao = null; @@ -224,8 +224,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra @Inject NetworkOfferingDetailsDao _ntwkOffDetailsDao; @Inject - ConfigurationServer _configServer; - @Inject AccountGuestVlanMapDao _accountGuestVlanMapDao; @Inject DataCenterVnetDao _datacenterVnetDao; @@ -239,40 +237,50 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra protected IpAddressManager _ipAddrMgr; List _networkGurus; + public List getNetworkGurus() { - return _networkGurus; - } - public void setNetworkGurus(List _networkGurus) { - this._networkGurus = _networkGurus; - } + return _networkGurus; + } + + public void setNetworkGurus(List _networkGurus) { + this._networkGurus = _networkGurus; + } + + List _networkElements; - List _networkElements; public List getNetworkElements() { - return _networkElements; - } - public void setNetworkElements(List _networkElements) { - this._networkElements = _networkElements; - } + return _networkElements; + } - @Inject NetworkDomainDao _networkDomainDao; + public void setNetworkElements(List _networkElements) { + this._networkElements = _networkElements; + } + + @Inject + NetworkDomainDao _networkDomainDao; + + List _ipDeployers; - List _ipDeployers; public List getIpDeployers() { - return _ipDeployers; - } - public void setIpDeployers(List _ipDeployers) { - this._ipDeployers = _ipDeployers; - } + return _ipDeployers; + } + + public void setIpDeployers(List _ipDeployers) { + this._ipDeployers = _ipDeployers; + } + + List _dhcpProviders; - List _dhcpProviders; public List getDhcpProviders() { - return _dhcpProviders; - } - public void setDhcpProviders(List _dhcpProviders) { - this._dhcpProviders = _dhcpProviders; - } + return _dhcpProviders; + } - @Inject + public void setDhcpProviders(List _dhcpProviders) { + this._dhcpProviders = _dhcpProviders; + } + + + @Inject VMInstanceDao _vmDao; @Inject FirewallManager _firewallMgr; @@ -280,7 +288,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra FirewallRulesDao _firewallDao; @Inject ResourceLimitService _resourceLimitMgr; - + @Inject NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao; @Inject @@ -290,8 +298,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra @Inject PortForwardingRulesDao _portForwardingRulesDao; @Inject - LoadBalancerDao _lbDao; - @Inject PhysicalNetworkTrafficTypeDao _pNTrafficTypeDao; @Inject AgentManager _agentMgr; @@ -309,14 +315,12 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra UsageEventDao _usageEventDao; @Inject NetworkModel _networkModel; - @Inject + @Inject NicSecondaryIpDao _nicSecondaryIpDao; @Inject - UserIpv6AddressDao _ipv6Dao; - @Inject - Ipv6AddressManager _ipv6Mgr; - @Inject PortableIpDao _portableIpDao; + @Inject + ConfigDepot _configDepot; protected StateMachine2 _stateMachine; ScheduledExecutorService _executor; @@ -324,27 +328,19 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra SearchBuilder AssignIpAddressSearch; SearchBuilder AssignIpAddressFromPodVlanSearch; - int _networkGcWait; - int _networkGcInterval; - int _networkLockTimeout; - - private Map _configs; + ConfigValue _networkGcWait; + ConfigValue _networkGcInterval; + ConfigValue _networkLockTimeout; + ConfigValue _domainSuffix; HashMap _lastNetworkIdsToFree = new HashMap(); - - - @Override @DB public boolean configure(final String name, final Map params) throws ConfigurationException { - _configs = _configDao.getConfiguration("AgentManager", params); - _networkGcWait = NumbersUtil.parseInt(_configs.get(Config.NetworkGcWait.key()), 600); - _networkGcInterval = NumbersUtil.parseInt(_configs.get(Config.NetworkGcInterval.key()), 600); - - _configs = _configDao.getConfiguration("Network", params); - - _networkLockTimeout = NumbersUtil.parseInt(_configs.get(Config.NetworkLockTimeout.key()), 600); + _networkGcWait = _configDepot.get(NetworkGcWait); + _networkGcInterval = _configDepot.get(NetworkGcInterval); + _networkLockTimeout = _configDepot.get(NetworkLockTimeout); // populate providers Map> defaultSharedNetworkOfferingProviders = new HashMap>(); @@ -374,8 +370,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra sgProviders.add(Provider.SecurityGroupProvider); defaultSharedSGEnabledNetworkOfferingProviders.put(Service.SecurityGroup, sgProviders); - Map> defaultIsolatedSourceNatEnabledNetworkOfferingProviders = - new HashMap>(); + Map> defaultIsolatedSourceNatEnabledNetworkOfferingProviders = new HashMap>(); defaultProviders.clear(); defaultProviders.add(Network.Provider.VirtualRouter); defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Dhcp, defaultProviders); @@ -389,9 +384,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.PortForwarding, defaultProviders); defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Vpn, defaultProviders); - - Map> defaultVPCOffProviders = - new HashMap>(); + Map> defaultVPCOffProviders = new HashMap>(); defaultProviders.clear(); defaultProviders.add(Network.Provider.VirtualRouter); defaultVPCOffProviders.put(Service.Dhcp, defaultProviders); @@ -411,41 +404,35 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra NetworkOfferingVO offering = null; //#1 - quick cloud network offering if (_networkOfferingDao.findByUniqueName(NetworkOffering.QuickCloudNoServices) == null) { - offering = - _configMgr.createNetworkOffering(NetworkOffering.QuickCloudNoServices, - "Offering for QuickCloud with no services", TrafficType.Guest, null, true, - Availability.Optional, null, new HashMap>(), true, - Network.GuestType.Shared, false, null, true, null, true, false, null, false, null); + offering = _configMgr.createNetworkOffering(NetworkOffering.QuickCloudNoServices, "Offering for QuickCloud with no services", TrafficType.Guest, null, true, + Availability.Optional, null, new HashMap>(), true, Network.GuestType.Shared, false, null, true, null, true, false, null, + false, null); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } - + //#2 - SG enabled network offering if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOfferingWithSGService) == null) { - offering = - _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOfferingWithSGService, - "Offering for Shared Security group enabled networks", TrafficType.Guest, null, true, - Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, - Network.GuestType.Shared, false, null, true, null, true, false, null, false, null); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks", + TrafficType.Guest, null, true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true, + false, null, false, null); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } //#3 - shared network offering with no SG service if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOffering) == null) { - offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, null, true, Availability.Optional, null, - defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true, false, null, false, null); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, null, true, + Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true, false, null, false, null); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } - //#4 - default isolated offering with Source nat service if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService, - "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, - null, false, Availability.Required, null, defaultIsolatedSourceNatEnabledNetworkOfferingProviders, - true, Network.GuestType.Isolated, false, null, true, null, false, false, null, false, null); + "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, null, false, Availability.Required, null, + defaultIsolatedSourceNatEnabledNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, false, false, null, false, null); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); @@ -454,9 +441,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra //#5 - default vpc offering with LB service if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks, - "Offering for Isolated VPC networks with Source Nat service enabled", TrafficType.Guest, - null, false, Availability.Optional, null, defaultVPCOffProviders, - true, Network.GuestType.Isolated, false, null, false, null, false, false, null,false, null); + "Offering for Isolated VPC networks with Source Nat service enabled", TrafficType.Guest, null, false, Availability.Optional, null, defaultVPCOffProviders, true, + Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } @@ -466,29 +452,26 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra //remove LB service defaultVPCOffProviders.remove(Service.Lb); offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB, - "Offering for Isolated VPC networks with Source Nat service enabled and LB service disabled", TrafficType.Guest, - null, false, Availability.Optional, null, defaultVPCOffProviders, - true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null); + "Offering for Isolated VPC networks with Source Nat service enabled and LB service disabled", TrafficType.Guest, null, false, Availability.Optional, null, + defaultVPCOffProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } //#7 - isolated offering with source nat disabled if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOffering) == null) { - offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering, - "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, null, true, - Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, - false, null, true, null, true, false, null, false, null); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", + TrafficType.Guest, null, true, Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, + true, false, null, false, null); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } - + //#8 - network offering with internal lb service - Map> internalLbOffProviders = - new HashMap>(); + Map> internalLbOffProviders = new HashMap>(); Set defaultVpcProvider = new HashSet(); defaultVpcProvider.add(Network.Provider.VPCVirtualRouter); - + Set defaultInternalLbProvider = new HashSet(); defaultInternalLbProvider.add(Network.Provider.InternalLbVm); @@ -499,12 +482,11 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra internalLbOffProviders.put(Service.Gateway, defaultVpcProvider); internalLbOffProviders.put(Service.Lb, defaultInternalLbProvider); internalLbOffProviders.put(Service.SourceNat, defaultVpcProvider); - + if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB, - "Offering for Isolated VPC networks with Internal Lb support", TrafficType.Guest, - null, false, Availability.Optional, null, internalLbOffProviders, - true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null); + "Offering for Isolated VPC networks with Internal Lb support", TrafficType.Guest, null, false, Availability.Optional, null, internalLbOffProviders, true, + Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null); offering.setState(NetworkOffering.State.Enabled); offering.setInternalLb(true); offering.setPublicLb(false); @@ -534,8 +516,9 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra serviceCapabilityMap.put(Service.StaticNat, eip); if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedEIPandELBNetworkOffering) == null) { - offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedEIPandELBNetworkOffering, "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, null, true, - Availability.Optional, null, netscalerServiceProviders, true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true, false, null, false, null); + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedEIPandELBNetworkOffering, + "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, null, true, Availability.Optional, null, netscalerServiceProviders, + true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true, false, null, false, null); offering.setState(NetworkOffering.State.Enabled); offering.setDedicatedLB(false); _networkOfferingDao.update(offering.getId(), offering); @@ -543,7 +526,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra txn.commit(); - AssignIpAddressSearch = _ipAddressDao.createSearchBuilder(); AssignIpAddressSearch.and("dc", AssignIpAddressSearch.entity().getDataCenterId(), Op.EQ); AssignIpAddressSearch.and("allocated", AssignIpAddressSearch.entity().getAllocatedTime(), Op.NULL); @@ -564,7 +546,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra podVlanSearch.and("networkId", podVlanSearch.entity().getNetworkId(), Op.EQ); SearchBuilder podVlanMapSB = _podVlanMapDao.createSearchBuilder(); podVlanMapSB.and("podId", podVlanMapSB.entity().getPodId(), Op.EQ); - AssignIpAddressFromPodVlanSearch.join("podVlanMapSB", podVlanMapSB, podVlanMapSB.entity().getVlanDbId(), AssignIpAddressFromPodVlanSearch.entity().getVlanId(), JoinType.INNER); + AssignIpAddressFromPodVlanSearch.join("podVlanMapSB", podVlanMapSB, podVlanMapSB.entity().getVlanDbId(), AssignIpAddressFromPodVlanSearch.entity().getVlanId(), + JoinType.INNER); AssignIpAddressFromPodVlanSearch.join("vlan", podVlanSearch, podVlanSearch.entity().getId(), AssignIpAddressFromPodVlanSearch.entity().getVlanId(), JoinType.INNER); @@ -583,7 +566,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra @Override public boolean start() { - _executor.scheduleWithFixedDelay(new NetworkGarbageCollector(), _networkGcInterval, _networkGcInterval, TimeUnit.SECONDS); + _executor.scheduleWithFixedDelay(new NetworkGarbageCollector(), _networkGcInterval.value(), _networkGcInterval.value(), TimeUnit.SECONDS); return true; } @@ -597,17 +580,15 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } @Override - public List setupNetwork(Account owner, NetworkOffering offering, DeploymentPlan plan, String name, - String displayText, boolean isDefault) - throws ConcurrentOperationException { + public List setupNetwork(Account owner, NetworkOffering offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) + throws ConcurrentOperationException { return setupNetwork(owner, offering, null, plan, name, displayText, false, null, null, null, null, true); } @Override @DB - public List setupNetwork(Account owner, NetworkOffering offering, Network predefined, DeploymentPlan - plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId, - ACLType aclType, Boolean subdomainAccess, Long vpcId, Boolean isDisplayNetworkEnabled) throws ConcurrentOperationException { + public List setupNetwork(Account owner, NetworkOffering offering, Network predefined, DeploymentPlan plan, String name, String displayText, + boolean errorIfAlreadySetup, Long domainId, ACLType aclType, Boolean subdomainAccess, Long vpcId, Boolean isDisplayNetworkEnabled) throws ConcurrentOperationException { Account locked = _accountDao.acquireInLockTable(owner.getId()); if (locked == null) { @@ -615,9 +596,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } try { - if (predefined == null - || (offering.getTrafficType() != TrafficType.Guest && predefined.getCidr() == null && predefined.getBroadcastUri() == null && - !(predefined.getBroadcastDomainType() == BroadcastDomainType.Vlan || predefined.getBroadcastDomainType() == BroadcastDomainType.Lswitch))) { + if (predefined == null || + (offering.getTrafficType() != TrafficType.Guest && predefined.getCidr() == null && predefined.getBroadcastUri() == null && !(predefined.getBroadcastDomainType() == BroadcastDomainType.Vlan || predefined.getBroadcastDomainType() == BroadcastDomainType.Lswitch))) { List configs = _networksDao.listBy(owner.getId(), offering.getId(), plan.getDataCenterId()); if (configs.size() > 0) { if (s_logger.isDebugEnabled()) { @@ -647,7 +627,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (network.getId() != -1) { if (network instanceof NetworkVO) { - networks.add((NetworkVO) network); + networks.add((NetworkVO)network); } else { networks.add(_networksDao.findById(network.getId())); } @@ -662,17 +642,30 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra Transaction txn = Transaction.currentTxn(); txn.start(); - NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), - related, name, displayText, predefined.getNetworkDomain(), offering.getGuestType(), - plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.getSpecifyIpRanges(), vpcId); + NetworkVO vo = new NetworkVO(id, + network, + offering.getId(), + guru.getName(), + owner.getDomainId(), + owner.getId(), + related, + name, + displayText, + predefined.getNetworkDomain(), + offering.getGuestType(), + plan.getDataCenterId(), + plan.getPhysicalNetworkId(), + aclType, + offering.getSpecifyIpRanges(), + vpcId); vo.setDisplayNetwork(isDisplayNetworkEnabled == null ? true : isDisplayNetworkEnabled); networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated, - finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId()))); + finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId()))); if (domainId != null && aclType == ACLType.Domain) { - if (subdomainAccess == null ) { + if (subdomainAccess == null) { subdomainAccess = true; - } + } _networksDao.addDomainToNetwork(id, domainId, subdomainAccess); } @@ -693,12 +686,10 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } } - - @Override @DB - public void allocate(VirtualMachineProfile vm, LinkedHashMap networks) - throws InsufficientCapacityException, ConcurrentOperationException { + public void allocate(VirtualMachineProfile vm, LinkedHashMap networks) throws InsufficientCapacityException, + ConcurrentOperationException { Transaction txn = Transaction.currentTxn(); txn.start(); @@ -723,8 +714,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra deviceId++; } - Pair vmNicPair = allocateNic(requested, config, isDefaultNic, - deviceId, vm); + Pair vmNicPair = allocateNic(requested, config, isDefaultNic, deviceId, vm); NicProfile vmNic = vmNicPair.first(); if (vmNic == null) { @@ -745,8 +735,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (vmNic.isDefaultNic()) { if (defaultNic != null) { - throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " + - defaultNic + "; nic 2 = " + vmNic); + throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " + defaultNic + "; nic 2 = " + vmNic); } defaultNic = vmNic; } @@ -768,12 +757,10 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra txn.commit(); } - @DB @Override - public Pair allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, - int deviceId, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, - InsufficientAddressCapacityException, ConcurrentOperationException{ + public Pair allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, int deviceId, VirtualMachineProfile vm) + throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { NetworkVO ntwkVO = _networksDao.findById(network.getId()); s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network + " with requested profile " + requested); @@ -802,13 +789,17 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra deviceId = applyProfileToNic(vo, profile, deviceId); vo = _nicDao.persist(vo); - - Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); - NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, - _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), - network)); - return new Pair(vmNic, Integer.valueOf(deviceId)); + Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); + NicProfile vmNic = new NicProfile(vo, + network, + vo.getBroadcastUri(), + vo.getIsolationUri(), + networkRate, + _networkModel.isSecurityGroupSupportedInNetwork(network), + _networkModel.getNetworkTag(vm.getHypervisorType(), network)); + + return new Pair(vmNic, Integer.valueOf(deviceId)); } protected Integer applyProfileToNic(NicVO vo, NicProfile profile, Integer deviceId) { @@ -844,11 +835,11 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } vo.setState(Nic.State.Allocated); - + vo.setIp6Address(profile.getIp6Address()); vo.setIp6Gateway(profile.getIp6Gateway()); vo.setIp6Cidr(profile.getIp6Cidr()); - + return deviceId; } @@ -919,9 +910,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra @Override @DB - public Pair implementNetwork(long networkId, DeployDestination dest, ReservationContext context) - throws ConcurrentOperationException, ResourceUnavailableException, - InsufficientCapacityException { + public Pair implementNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException { Transaction.currentTxn(); Pair implemented = new Pair(null, null); @@ -934,11 +924,11 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } // Acquire lock only when network needs to be implemented - network = _networksDao.acquireInLockTable(networkId, _networkLockTimeout); + network = _networksDao.acquireInLockTable(networkId, _networkLockTimeout.value()); if (network == null) { // see NetworkVO.java ConcurrentOperationException ex = new ConcurrentOperationException("Unable to acquire network configuration"); - ex.addProxyObject(ApiDBUtils.findNetworkById(networkId).getUuid()); + ex.addProxyObject(_entityMgr.findById(Network.class, networkId).getUuid()); throw ex; } @@ -980,7 +970,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (isSharedNetworkWithServices(network)) { network.setState(Network.State.Implemented); } else { - stateTransitTo(network,Event.OperationSucceeded); + stateTransitTo(network, Event.OperationSucceeded); } network.setRestartRequired(false); @@ -998,7 +988,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra network.setState(Network.State.Shutdown); _networksDao.update(networkId, network); } else { - stateTransitTo(network,Event.OperationFailed); + stateTransitTo(network, Event.OperationFailed); } } catch (NoTransitionException e) { s_logger.error(e.getMessage()); @@ -1020,9 +1010,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } @Override - public void implementNetworkElementsAndResources(DeployDestination dest, ReservationContext context, - Network network, NetworkOffering offering) - throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException { + public void implementNetworkElementsAndResources(DeployDestination dest, ReservationContext context, Network network, NetworkOffering offering) + throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException { // Associate a source NAT IP (if one isn't already associated with the network) if this is a // 1) 'Isolated' or 'Shared' guest virtual network in the advance zone @@ -1032,9 +1021,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra boolean sharedSourceNat = offering.getSharedSourceNat(); DataCenter zone = _dcDao.findById(network.getDataCenterId()); - if (!sharedSourceNat && _networkModel.areServicesSupportedInNetwork(network.getId(), Service.SourceNat) - && (network.getGuestType() == Network.GuestType.Isolated || - (network.getGuestType() == Network.GuestType.Shared && zone.getNetworkType() == NetworkType.Advanced))) { + if (!sharedSourceNat && _networkModel.areServicesSupportedInNetwork(network.getId(), Service.SourceNat) && + (network.getGuestType() == Network.GuestType.Isolated || (network.getGuestType() == Network.GuestType.Shared && zone.getNetworkType() == NetworkType.Advanced))) { List ips = null; if (network.getVpcId() != null) { @@ -1048,7 +1036,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (ips.isEmpty()) { s_logger.debug("Creating a source nat ip for network " + network); - Account owner = _accountMgr.getAccount(network.getAccountId()); + Account owner = _entityMgr.findById(Account.class, network.getAccountId()); _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network); } } @@ -1062,8 +1050,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra // because the serializer would look up the NetworkVO class's table and retrieve the // network id instead of the physical network id. // So just throw this exception as is. We may need to TBD by changing the serializer. - throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + - " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId()); + throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + + network.getPhysicalNetworkId()); } if (s_logger.isDebugEnabled()) { @@ -1083,8 +1071,10 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (!reprogramNetworkRules(network.getId(), CallContext.current().getCallingAccount(), network)) { s_logger.warn("Failed to re-program the network as a part of network " + network + " implement"); // see DataCenterVO.java - ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId()); - ex.addProxyObject(ApiDBUtils.findZoneById(network.getDataCenterId()).getUuid()); + ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", + DataCenter.class, + network.getDataCenterId()); + ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid()); throw ex; } } @@ -1173,17 +1163,14 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return success; } - protected boolean prepareElement(NetworkElement element, Network network, - NicProfile profile, VirtualMachineProfile vmProfile, - DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, - ConcurrentOperationException, ResourceUnavailableException { + protected boolean prepareElement(NetworkElement element, Network network, NicProfile profile, VirtualMachineProfile vmProfile, DeployDestination dest, + ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { element.prepare(network, profile, vmProfile, dest, context); if (vmProfile.getType() == Type.User && element.getProvider() != null) { if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp) && - _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, element.getProvider()) && - element instanceof DhcpServiceProvider ) { - DhcpServiceProvider sp = (DhcpServiceProvider) element; - Map dhcpCapabilities = element.getCapabilities().get(Service.Dhcp); + _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, element.getProvider()) && element instanceof DhcpServiceProvider) { + DhcpServiceProvider sp = (DhcpServiceProvider)element; + Map dhcpCapabilities = element.getCapabilities().get(Service.Dhcp); String supportsMultipleSubnets = dhcpCapabilities.get(Capability.DhcpAccrossMultipleSubnets); if ((supportsMultipleSubnets != null && Boolean.valueOf(supportsMultipleSubnets)) && profile.getIp6Address() == null) { if (!sp.configDhcpSupportForSubnet(network, profile, vmProfile, dest, context)) { @@ -1193,9 +1180,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra sp.addDhcpEntry(network, profile, vmProfile, dest, context); } if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.UserData) && - _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.UserData, element.getProvider()) && - element instanceof UserDataServiceProvider) { - UserDataServiceProvider sp = (UserDataServiceProvider) element; + _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.UserData, element.getProvider()) && element instanceof UserDataServiceProvider) { + UserDataServiceProvider sp = (UserDataServiceProvider)element; sp.addPasswordAndUserdata(network, profile, vmProfile, dest, context); } } @@ -1213,7 +1199,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra _networksDao.changeActiveNicsBy(networkId, count); } - if (nic.getVmType() == VirtualMachine.Type.User || (nic.getVmType() == VirtualMachine.Type.DomainRouter && _networksDao.findById(networkId).getTrafficType() == TrafficType.Guest)) { + if (nic.getVmType() == VirtualMachine.Type.User || + (nic.getVmType() == VirtualMachine.Type.DomainRouter && _networksDao.findById(networkId).getTrafficType() == TrafficType.Guest)) { _networksDao.setCheckForGc(networkId); } @@ -1221,8 +1208,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } @Override - public void prepare(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, - ConcurrentOperationException, ResourceUnavailableException { + public void prepare(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, + ResourceUnavailableException { List nics = _nicDao.listByVmId(vmProfile.getId()); // we have to implement default nics first - to ensure that default network elements start up first in multiple @@ -1243,7 +1230,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra Pair implemented = implementNetwork(nic.getNetworkId(), dest, context); if (implemented.first() == null) { s_logger.warn("Failed to implement network id=" + nic.getNetworkId() + " as a part of preparing nic id=" + nic.getId()); - throw new CloudRuntimeException("Failed to implement network id=" + nic.getNetworkId() + " as a part preparing nic id=" +nic.getId()); + throw new CloudRuntimeException("Failed to implement network id=" + nic.getNetworkId() + " as a part preparing nic id=" + nic.getId()); } NetworkVO network = implemented.second(); @@ -1253,11 +1240,10 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } @Override - public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination - dest, ReservationContext context, long nicId, Network network) - throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, - ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { - + public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context, long nicId, Network network) + throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, + ResourceUnavailableException { + Integer networkRate = _networkModel.getNetworkRate(network.getId(), vmProfile.getId()); NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName()); NicVO nic = _nicDao.findById(nicId); @@ -1295,8 +1281,13 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra updateNic(nic, network.getId(), 1); } else { - profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), - networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network)); + profile = new NicProfile(nic, + network, + nic.getBroadcastUri(), + nic.getIsolationUri(), + networkRate, + _networkModel.isSecurityGroupSupportedInNetwork(network), + _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network)); guru.updateNicProfile(profile, network); nic.setState(Nic.State.Reserved); updateNic(nic, network.getId(), 1); @@ -1331,11 +1322,16 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName()); - NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, - _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network)); - if(guru instanceof NetworkMigrationResponder){ - if(!((NetworkMigrationResponder) guru).prepareMigration(profile, network, vm, dest, context)){ - s_logger.error("NetworkGuru "+guru+" prepareForMigration failed."); // XXX: Transaction error + NicProfile profile = new NicProfile(nic, + network, + nic.getBroadcastUri(), + nic.getIsolationUri(), + networkRate, + _networkModel.isSecurityGroupSupportedInNetwork(network), + _networkModel.getNetworkTag(vm.getHypervisorType(), network)); + if (guru instanceof NetworkMigrationResponder) { + if (!((NetworkMigrationResponder)guru).prepareMigration(profile, network, vm, dest, context)) { + s_logger.error("NetworkGuru " + guru + " prepareForMigration failed."); // XXX: Transaction error } } List providersToImplement = getNetworkProviders(network.getId()); @@ -1356,9 +1352,9 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } } - private NicProfile findNicProfileById(VirtualMachineProfile vm, long id){ - for(NicProfile nic: vm.getNics()){ - if(nic.getId() == id){ + private NicProfile findNicProfileById(VirtualMachineProfile vm, long id) { + for (NicProfile nic : vm.getNics()) { + if (nic.getId() == id) { return nic; } } @@ -1366,18 +1362,16 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } @Override - public void commitNicForMigration( - VirtualMachineProfile src, - VirtualMachineProfile dst) { - for(NicProfile nicSrc: src.getNics()){ + public void commitNicForMigration(VirtualMachineProfile src, VirtualMachineProfile dst) { + for (NicProfile nicSrc : src.getNics()) { NetworkVO network = _networksDao.findById(nicSrc.getNetworkId()); NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName()); NicProfile nicDst = findNicProfileById(dst, nicSrc.getId()); ReservationContext src_context = new ReservationContextImpl(nicSrc.getReservationId(), null, null); ReservationContext dst_context = new ReservationContextImpl(nicDst.getReservationId(), null, null); - if(guru instanceof NetworkMigrationResponder){ - ((NetworkMigrationResponder) guru).commitMigration(nicSrc, network, src, src_context, dst_context); + if (guru instanceof NetworkMigrationResponder) { + ((NetworkMigrationResponder)guru).commitMigration(nicSrc, network, src, src_context, dst_context); } List providersToImplement = getNetworkProviders(network.getId()); for (NetworkElement element : _networkElements) { @@ -1398,18 +1392,16 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } @Override - public void rollbackNicForMigration( - VirtualMachineProfile src, - VirtualMachineProfile dst) { - for(NicProfile nicDst: dst.getNics()){ + public void rollbackNicForMigration(VirtualMachineProfile src, VirtualMachineProfile dst) { + for (NicProfile nicDst : dst.getNics()) { NetworkVO network = _networksDao.findById(nicDst.getNetworkId()); NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName()); NicProfile nicSrc = findNicProfileById(src, nicDst.getId()); ReservationContext src_context = new ReservationContextImpl(nicSrc.getReservationId(), null, null); ReservationContext dst_context = new ReservationContextImpl(nicDst.getReservationId(), null, null); - if(guru instanceof NetworkMigrationResponder){ - ((NetworkMigrationResponder) guru).rollbackMigration(nicDst, network, dst, src_context, dst_context); + if (guru instanceof NetworkMigrationResponder) { + ((NetworkMigrationResponder)guru).rollbackMigration(nicDst, network, dst, src_context, dst_context); } List providersToImplement = getNetworkProviders(network.getId()); for (NetworkElement element : _networkElements) { @@ -1427,25 +1419,21 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra @Override @DB - public void release(VirtualMachineProfile vmProfile, boolean forced) throws - ConcurrentOperationException, ResourceUnavailableException { + public void release(VirtualMachineProfile vmProfile, boolean forced) throws ConcurrentOperationException, ResourceUnavailableException { List nics = _nicDao.listByVmId(vmProfile.getId()); for (NicVO nic : nics) { releaseNic(vmProfile, nic.getId()); } } - @Override @DB - public void releaseNic(VirtualMachineProfile vmProfile, Nic nic) - throws ConcurrentOperationException, ResourceUnavailableException { + public void releaseNic(VirtualMachineProfile vmProfile, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException { releaseNic(vmProfile, nic.getId()); } @DB - protected void releaseNic(VirtualMachineProfile vmProfile, long nicId) - throws ConcurrentOperationException, ResourceUnavailableException { + protected void releaseNic(VirtualMachineProfile vmProfile, long nicId) throws ConcurrentOperationException, ResourceUnavailableException { //lock the nic Transaction txn = Transaction.currentTxn(); txn.start(); @@ -1463,8 +1451,13 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName()); nic.setState(Nic.State.Releasing); _nicDao.update(nic.getId(), nic); - NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, - _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network)); + NicProfile profile = new NicProfile(nic, + network, + nic.getBroadcastUri(), + nic.getIsolationUri(), + null, + _networkModel.isSecurityGroupSupportedInNetwork(network), + _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network)); if (guru.release(profile, vmProfile, nic.getReservationId())) { applyProfileToNicForRelease(nic, profile); nic.setState(Nic.State.Allocated); @@ -1513,19 +1506,17 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } } - @Override public void removeNic(VirtualMachineProfile vm, Nic nic) { removeNic(vm, _nicDao.findById(nic.getId())); } - protected void removeNic(VirtualMachineProfile vm, NicVO nic) { nic.setState(Nic.State.Deallocating); _nicDao.update(nic.getId(), nic); NetworkVO network = _networksDao.findById(nic.getNetworkId()); - NicProfile profile = new NicProfile(nic, network, null, null, null, - _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network)); + NicProfile profile = new NicProfile(nic, network, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag( + vm.getHypervisorType(), network)); /* * We need to release the nics with a Create ReservationStrategy here @@ -1553,8 +1544,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } // remove the dhcpservice ip if this is the last nic in subnet. - if (vm.getType() == Type.User && isDhcpAccrossMultipleSubnetsSupported(network) && isLastNicInSubnet(nic) && - network.getTrafficType() == TrafficType.Guest && network.getGuestType() == GuestType.Shared) { + if (vm.getType() == Type.User && isDhcpAccrossMultipleSubnetsSupported(network) && isLastNicInSubnet(nic) && network.getTrafficType() == TrafficType.Guest && + network.getGuestType() == GuestType.Shared) { removeDhcpServiceInSubnet(nic); } NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName()); @@ -1569,7 +1560,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra public boolean isDhcpAccrossMultipleSubnetsSupported(Network network) { DhcpServiceProvider dhcpServiceProvider = getDhcpServiceProvider(network); - Map capabilities = dhcpServiceProvider.getCapabilities().get(Network.Service.Dhcp); + Map capabilities = dhcpServiceProvider.getCapabilities().get(Network.Service.Dhcp); String supportsMultipleSubnets = capabilities.get(Network.Capability.DhcpAccrossMultipleSubnets); if (supportsMultipleSubnets != null && Boolean.valueOf(supportsMultipleSubnets)) { return true; @@ -1579,7 +1570,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra private boolean isLastNicInSubnet(NicVO nic) { if (_nicDao.listByNetworkIdTypeAndGatewayAndBroadcastUri(nic.getNetworkId(), VirtualMachine.Type.User, nic.getGateway(), nic.getBroadcastUri()).size() > 1) { - return false; + return false; } return true; } @@ -1595,7 +1586,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra ipAlias.setState(NicIpAlias.state.revoked); Transaction txn = Transaction.currentTxn(); txn.start(); - _nicIpAliasDao.update(ipAlias.getId(),ipAlias); + _nicIpAliasDao.update(ipAlias.getId(), ipAlias); IPAddressVO aliasIpaddressVo = _publicIpAddressDao.findByIpAndSourceNetworkId(ipAlias.getNetworkId(), ipAlias.getIp4Address()); _publicIpAddressDao.unassignIpAddress(aliasIpaddressVo.getId()); txn.commit(); @@ -1603,16 +1594,13 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra s_logger.warn("Failed to remove the ip alias on the router, marking it as removed in db and freed the allocated ip " + ipAlias.getIp4Address()); } } - } - catch (ResourceUnavailableException e) { + } catch (ResourceUnavailableException e) { //failed to remove the dhcpconfig on the router. - s_logger.info ("Unable to delete the ip alias due to unable to contact the virtualrouter."); + s_logger.info("Unable to delete the ip alias due to unable to contact the virtualrouter."); } } - - @Override public void expungeNics(VirtualMachineProfile vm) { List nics = _nicDao.listByVmIdIncludingRemoved(vm.getId()); @@ -1621,15 +1609,11 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } } - - @Override @DB - public Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, - String cidr, String vlanId, String networkDomain, Account owner, Long domainId, - PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId, String ip6Gateway, String ip6Cidr, - Boolean isDisplayNetworkEnabled, String isolatedPvlan) - throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { + public Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr, String vlanId, String networkDomain, Account owner, + Long domainId, PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId, String ip6Gateway, String ip6Cidr, + Boolean isDisplayNetworkEnabled, String isolatedPvlan) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(networkOfferingId); // this method supports only guest network creation @@ -1655,24 +1639,23 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra // Validate physical network if (pNtwk.getState() != PhysicalNetwork.State.Enabled) { // see PhysicalNetworkVO.java - InvalidParameterValueException ex = new InvalidParameterValueException("Specified physical network id is" + - " in incorrect state:" + pNtwk.getState()); + InvalidParameterValueException ex = new InvalidParameterValueException("Specified physical network id is" + " in incorrect state:" + pNtwk.getState()); ex.addProxyObject(pNtwk.getUuid(), "physicalNetworkId"); throw ex; } boolean ipv6 = false; - + if (ip6Gateway != null && ip6Cidr != null) { - ipv6 = true; + ipv6 = true; } // Validate zone DataCenterVO zone = _dcDao.findById(zoneId); if (zone.getNetworkType() == NetworkType.Basic) { - if (ipv6) { + if (ipv6) { throw new InvalidParameterValueException("IPv6 is not supported in Basic zone"); - } - + } + // In Basic zone the network should have aclType=Domain, domainId=1, subdomainAccess=true if (aclType == null || aclType != ACLType.Domain) { throw new InvalidParameterValueException("Only AclType=Domain can be specified for network creation in Basic zone"); @@ -1681,16 +1664,13 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra // Only one guest network is supported in Basic zone List guestNetworks = _networksDao.listByZoneAndTrafficType(zone.getId(), TrafficType.Guest); if (!guestNetworks.isEmpty()) { - throw new InvalidParameterValueException("Can't have more than one Guest network in zone with network type " - + NetworkType.Basic); + throw new InvalidParameterValueException("Can't have more than one Guest network in zone with network type " + NetworkType.Basic); } // if zone is basic, only Shared network offerings w/o source nat service are allowed - if (!(ntwkOff.getGuestType() == GuestType.Shared && - !_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))) { - throw new InvalidParameterValueException("For zone of type " + NetworkType.Basic + " only offerings of " + - "guestType " + GuestType.Shared + " with disabled " + Service.SourceNat.getName() - + " service are allowed"); + if (!(ntwkOff.getGuestType() == GuestType.Shared && !_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))) { + throw new InvalidParameterValueException("For zone of type " + NetworkType.Basic + " only offerings of " + "guestType " + GuestType.Shared + " with disabled " + + Service.SourceNat.getName() + " service are allowed"); } if (domainId == null || domainId != Domain.ROOT_DOMAIN) { @@ -1700,36 +1680,34 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (subdomainAccess == null) { subdomainAccess = true; } else if (!subdomainAccess) { - throw new InvalidParameterValueException("Subdomain access should be set to true for the" + - " guest network in the Basic zone"); + throw new InvalidParameterValueException("Subdomain access should be set to true for the" + " guest network in the Basic zone"); } if (vlanId == null) { vlanId = Vlan.UNTAGGED; } else { if (!vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) { - throw new InvalidParameterValueException("Only vlan " + Vlan.UNTAGGED + " can be created in " + - "the zone of type " + NetworkType.Basic); + throw new InvalidParameterValueException("Only vlan " + Vlan.UNTAGGED + " can be created in " + "the zone of type " + NetworkType.Basic); } } } else if (zone.getNetworkType() == NetworkType.Advanced) { if (zone.isSecurityGroupEnabled()) { - if (ipv6) { - throw new InvalidParameterValueException("IPv6 is not supported with security group!"); - } - if (isolatedPvlan != null) { - throw new InvalidParameterValueException("Isolated Private VLAN is not supported with security group!"); - } + if (ipv6) { + throw new InvalidParameterValueException("IPv6 is not supported with security group!"); + } + if (isolatedPvlan != null) { + throw new InvalidParameterValueException("Isolated Private VLAN is not supported with security group!"); + } // Only Account specific Isolated network with sourceNat service disabled are allowed in security group // enabled zone - if ( ntwkOff.getGuestType() != GuestType.Shared ){ + if (ntwkOff.getGuestType() != GuestType.Shared) { throw new InvalidParameterValueException("Only shared guest network can be created in security group enabled zone"); } - if ( _networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)) { + if (_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)) { throw new InvalidParameterValueException("Service SourceNat is not allowed in security group enabled zone"); } - if (!( _networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SecurityGroup))) { + if (!(_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SecurityGroup))) { throw new InvalidParameterValueException("network must have SecurityGroup provider in security group enabled zone"); } } @@ -1753,10 +1731,9 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (vlanSpecified) { //don't allow to specify vlan tag used by physical network for dynamic vlan allocation if (_dcDao.findVnet(zoneId, pNtwk.getId(), vlanId).size() > 0) { - throw new InvalidParameterValueException("The VLAN tag " + vlanId - + " is already being used for dynamic vlan allocation for the guest network in zone " + zone.getName()); + throw new InvalidParameterValueException("The VLAN tag " + vlanId + " is already being used for dynamic vlan allocation for the guest network in zone " + + zone.getName()); } - String uri = BroadcastDomainType.fromString(vlanId).toString(); // For Isolated networks, don't allow to create network with vlan that already exists in the zone if (ntwkOff.getGuestType() == GuestType.Isolated) { @@ -1775,15 +1752,15 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (map.getAccountId() != owner.getAccountId()) { throw new InvalidParameterValueException("Vlan " + vlanId + " is dedicated to a different account"); } - // Fail network creation if owner has a dedicated range of vlans but the specified vlan belongs to the system pool + // Fail network creation if owner has a dedicated range of vlans but the specified vlan belongs to the system pool } else { List maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(owner.getAccountId()); if (maps != null && !maps.isEmpty()) { int vnetsAllocatedToAccount = _datacenterVnetDao.countVnetsAllocatedToAccount(zoneId, owner.getAccountId()); int vnetsDedicatedToAccount = _datacenterVnetDao.countVnetsDedicatedToAccount(zoneId, owner.getAccountId()); if (vnetsAllocatedToAccount < vnetsDedicatedToAccount) { - throw new InvalidParameterValueException("Specified vlan " + vlanId + " doesn't belong" + - " to the vlan range dedicated to the owner "+ owner.getAccountName()); + throw new InvalidParameterValueException("Specified vlan " + vlanId + " doesn't belong" + " to the vlan range dedicated to the owner " + + owner.getAccountName()); } } } @@ -1792,27 +1769,21 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } else { // don't allow to creating shared network with given Vlan ID, if there already exists a isolated network or // shared network with same Vlan ID in the zone - if (_networksDao.countByZoneUriAndGuestType(zoneId, uri, GuestType.Isolated) > 0 || - _networksDao.countByZoneUriAndGuestType(zoneId, uri, GuestType.Shared) > 0) { - throw new InvalidParameterValueException("There is a isolated/shared network with vlan id: " + - vlanId + " already exists " + "in zone " + zoneId); + if (_networksDao.countByZoneUriAndGuestType(zoneId, uri, GuestType.Isolated) > 0 || _networksDao.countByZoneUriAndGuestType(zoneId, uri, GuestType.Shared) > 0) { + throw new InvalidParameterValueException("There is a isolated/shared network with vlan id: " + vlanId + " already exists " + "in zone " + zoneId); } } - - } // If networkDomain is not specified, take it from the global configuration if (_networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.Dns)) { - Map dnsCapabilities = _networkModel.getNetworkOfferingServiceCapabilities - (_entityMgr.findById(NetworkOffering.class, networkOfferingId), Service.Dns); + Map dnsCapabilities = _networkModel.getNetworkOfferingServiceCapabilities(_entityMgr.findById(NetworkOffering.class, networkOfferingId), Service.Dns); String isUpdateDnsSupported = dnsCapabilities.get(Capability.AllowDnsSuffixModification); if (isUpdateDnsSupported == null || !Boolean.valueOf(isUpdateDnsSupported)) { if (networkDomain != null) { // TBD: NetworkOfferingId and zoneId. Send uuids instead. - throw new InvalidParameterValueException("Domain name change is not supported by network offering id=" - + networkOfferingId + " in zone id=" + zoneId); + throw new InvalidParameterValueException("Domain name change is not supported by network offering id=" + networkOfferingId + " in zone id=" + zoneId); } } else { if (networkDomain == null) { @@ -1825,31 +1796,30 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra // 2) If null, generate networkDomain using domain suffix from the global config variables if (networkDomain == null) { - networkDomain = "cs" + Long.toHexString(owner.getId()) + _configServer.getConfigValue(Config.GuestDomainSuffix.key(), Config.ConfigurationParameterScope.zone.toString(), zoneId); + networkDomain = "cs" + Long.toHexString(owner.getId()) + _domainSuffix.valueIn(zoneId); } } else { // validate network domain if (!NetUtils.verifyDomainName(networkDomain)) { - throw new InvalidParameterValueException( - "Invalid network domain. Total length shouldn't exceed 190 chars. Each domain " + - "label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', " - + "and the hyphen ('-'); can't start or end with \"-\""); + throw new InvalidParameterValueException("Invalid network domain. Total length shouldn't exceed 190 chars. Each domain " + + "label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', " + + "and the hyphen ('-'); can't start or end with \"-\""); } } } } - + // In Advance zone Cidr for Shared networks and Isolated networks w/o source nat service can't be NULL - 2.2.x // limitation, remove after we introduce support for multiple ip ranges // with different Cidrs for the same Shared network - boolean cidrRequired = zone.getNetworkType() == NetworkType.Advanced && ntwkOff.getTrafficType() == TrafficType.Guest - && (ntwkOff.getGuestType() == GuestType.Shared || (ntwkOff.getGuestType() == GuestType.Isolated - && !_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))); - if (cidr == null && ip6Cidr == null && cidrRequired) { - throw new InvalidParameterValueException("StartIp/endIp/gateway/netmask are required when create network of" + - " type " + Network.GuestType.Shared + " and network of type " + GuestType.Isolated + " with service " - + Service.SourceNat.getName() + " disabled"); + boolean cidrRequired = zone.getNetworkType() == NetworkType.Advanced && + ntwkOff.getTrafficType() == TrafficType.Guest && + (ntwkOff.getGuestType() == GuestType.Shared || (ntwkOff.getGuestType() == GuestType.Isolated && !_networkModel.areServicesSupportedByNetworkOffering( + ntwkOff.getId(), Service.SourceNat))); + if (cidr == null && ip6Cidr == null && cidrRequired) { + throw new InvalidParameterValueException("StartIp/endIp/gateway/netmask are required when create network of" + " type " + Network.GuestType.Shared + + " and network of type " + GuestType.Isolated + " with service " + Service.SourceNat.getName() + " disabled"); } // No cidr can be specified in Basic zone @@ -1859,9 +1829,9 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra // Check if cidr is RFC1918 compliant if the network is Guest Isolated for IPv4 if (cidr != null && ntwkOff.getGuestType() == Network.GuestType.Isolated && ntwkOff.getTrafficType() == TrafficType.Guest) { - if (!NetUtils.validateGuestCidr(cidr)) { - throw new InvalidParameterValueException("Virtual Guest Cidr " + cidr + " is not RFC1918 compliant"); - } + if (!NetUtils.validateGuestCidr(cidr)) { + throw new InvalidParameterValueException("Virtual Guest Cidr " + cidr + " is not RFC1918 compliant"); + } } Transaction txn = Transaction.currentTxn(); @@ -1879,12 +1849,12 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra userNetwork.setCidr(cidr); userNetwork.setGateway(gateway); } - + if (ip6Cidr != null && ip6Gateway != null) { userNetwork.setIp6Cidr(ip6Cidr); userNetwork.setIp6Gateway(ip6Gateway); } - + if (vlanId != null) { if (isolatedPvlan == null) { URI uri = BroadcastDomainType.fromString(vlanId); @@ -1910,8 +1880,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (networks == null || networks.isEmpty()) { throw new CloudRuntimeException("Fail to create a network"); } else { - if (networks.size() > 0 && networks.get(0).getGuestType() == Network.GuestType.Isolated && - networks.get(0).getTrafficType() == TrafficType.Guest) { + if (networks.size() > 0 && networks.get(0).getGuestType() == Network.GuestType.Isolated && networks.get(0).getTrafficType() == TrafficType.Guest) { Network defaultGuestNetwork = networks.get(0); for (Network nw : networks) { if (nw.getCidr() != null && nw.getCidr().equals(zone.getGuestNetworkCidr())) { @@ -1951,7 +1920,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra try { //do global lock for the network - network = _networksDao.acquireInLockTable(networkId, getNetworkLockTimeout()); + network = _networksDao.acquireInLockTable(networkId, _networkLockTimeout.value()); if (network == null) { s_logger.warn("Unable to acquire lock for the network " + network + " as a part of network shutdown"); return false; @@ -2054,8 +2023,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (providersToShutdown.contains(element.getProvider())) { try { if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) { - s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName() + " either doesn't exist or not enabled in the physical network " - + _networkModel.getPhysicalNetworkId(network)); + s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName() + + " either doesn't exist or not enabled in the physical network " + _networkModel.getPhysicalNetworkId(network)); success = false; } if (s_logger.isDebugEnabled()) { @@ -2113,8 +2082,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra //In Basic zone, make sure that there are no non-removed console proxies and SSVMs using the network DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId()); if (zone.getNetworkType() == NetworkType.Basic) { - List systemVms = _vmDao.listNonRemovedVmsByTypeAndNetwork(network.getId(), - Type.ConsoleProxy, Type.SecondaryStorageVm); + List systemVms = _vmDao.listNonRemovedVmsByTypeAndNetwork(network.getId(), Type.ConsoleProxy, Type.SecondaryStorageVm); if (systemVms != null && !systemVms.isEmpty()) { s_logger.warn("Can't delete the network, not all consoleProxy/secondaryStorage vms are expunged"); return false; @@ -2143,8 +2111,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (providersToDestroy.contains(element.getProvider())) { try { if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) { - s_logger.warn("Unable to complete destroy of the network elements due to element: " + element.getName() + " either doesn't exist or not enabled in the physical network " - + _networkModel.getPhysicalNetworkId(network)); + s_logger.warn("Unable to complete destroy of the network elements due to element: " + element.getName() + + " either doesn't exist or not enabled in the physical network " + _networkModel.getPhysicalNetworkId(network)); success = false; } @@ -2186,9 +2154,9 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra // commit transaction only when ips and vlans for the network are released successfully try { stateTransitTo(network, Event.DestroyNetwork); - } catch (NoTransitionException e) { - s_logger.debug(e.getMessage()); - } + } catch (NoTransitionException e) { + s_logger.debug(e.getMessage()); + } if (_networksDao.remove(network.getId())) { NetworkDomainVO networkDomain = _networkDomainDao.getDomainNetworkMapByNetworkId(network.getId()); if (networkDomain != null) @@ -2213,8 +2181,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra private boolean resourceCountNeedsUpdate(NetworkOffering ntwkOff, ACLType aclType) { //Update resource count only for Isolated account specific non-system networks - boolean updateResourceCount = (ntwkOff.getGuestType() == GuestType.Isolated && - !ntwkOff.isSystemOnly() && aclType == ACLType.Account); + boolean updateResourceCount = (ntwkOff.getGuestType() == GuestType.Isolated && !ntwkOff.isSystemOnly() && aclType == ACLType.Account); return updateResourceCount; } @@ -2224,7 +2191,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra List publicVlans = _vlanDao.listVlansByNetworkId(networkId); boolean result = true; for (VlanVO vlan : publicVlans) { - if (!_configMgr.deleteVlanAndPublicIpRange(_accountMgr.getSystemUser().getId(), vlan.getId(), callerAccount)) { + if (!_configMgr.deleteVlanAndPublicIpRange(userId, vlan.getId(), callerAccount)) { s_logger.warn("Failed to delete vlan " + vlan.getId() + ");"); result = false; } @@ -2248,7 +2215,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra ServerContexts.registerSystemContext(); GlobalLock gcLock = GlobalLock.getInternLock("Network.GC.Lock"); try { - if(gcLock.lock(3)) { + if (gcLock.lock(3)) { try { reallyRun(); } finally { @@ -2260,11 +2227,11 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra ServerContexts.unregisterSystemContext(); } } - + public void reallyRun() { try { List shutdownList = new ArrayList(); - long currentTime = System.currentTimeMillis() / 1000 ; + long currentTime = System.currentTimeMillis() / 1000; HashMap stillFree = new HashMap(); List networkIds = _networksDao.findNetworksToGarbageCollect(); @@ -2280,7 +2247,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra s_logger.debug("We found network " + networkId + " to be free for the first time. Adding it to the list: " + currentTime); } stillFree.put(networkId, currentTime); - } else if (time > (currentTime - _networkGcWait)) { + } else if (time > (currentTime - _networkGcWait.value())) { if (s_logger.isDebugEnabled()) { s_logger.debug("Network " + networkId + " is still free but it's not time to shutdown yet: " + time); } @@ -2320,10 +2287,9 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } } - - @Override - public boolean startNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + public boolean startNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { // Check if network exists NetworkVO network = _networksDao.findById(networkId); @@ -2345,7 +2311,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } @Override - public boolean restartNetwork(Long networkId, Account callerAccount, User callerUser, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + public boolean restartNetwork(Long networkId, Account callerAccount, User callerUser, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { NetworkVO network = _networksDao.findById(networkId); @@ -2393,7 +2360,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return _networksDao.getActiveNicsIn(networkId); } - @Override public NetworkProfile convertNetworkToNetworkProfile(long networkId) { NetworkVO network = _networksDao.findById(networkId); @@ -2412,7 +2378,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra s_logger.debug("Network " + network + " doesn't support service " + Service.UserData.getName()); return null; } - + return (UserDataServiceProvider)_networkModel.getElementImplementingProvider(passwordProvider); } @@ -2441,7 +2407,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } - protected boolean isSharedNetworkWithServices(Network network) { assert(network != null); DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId()); @@ -2455,18 +2420,17 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra protected boolean isSharedNetworkOfferingWithServices(long networkOfferingId) { NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId); - if ( (networkOffering.getGuestType() == Network.GuestType.Shared) && ( - _networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.SourceNat) || - _networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.StaticNat) || - _networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.Firewall) || - _networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.PortForwarding) || - _networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.Lb))) { + if ((networkOffering.getGuestType() == Network.GuestType.Shared) && + (_networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.SourceNat) || + _networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.StaticNat) || + _networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.Firewall) || + _networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.PortForwarding) || _networkModel.areServicesSupportedByNetworkOffering( + networkOfferingId, Service.Lb))) { return true; } return false; } - @Override public List listVmNics(Long vmId, Long nicId) { List result = null; @@ -2478,9 +2442,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return result; } - - - @DB @Override public boolean reallocate(VirtualMachineProfile vm, DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException { @@ -2556,8 +2517,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } } catch (ResourceUnavailableException ex) { success = false; - s_logger.warn("Failed to cleanup Network ACLs as a part of network id=" + networkId + - " cleanup due to resourceUnavailable ", ex); + s_logger.warn("Failed to cleanup Network ACLs as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex); } //release all ip addresses @@ -2566,8 +2526,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (ipToRelease.getVpcId() == null) { if (!ipToRelease.isPortable()) { IPAddressVO ip = _ipAddrMgr.markIpAsUnavailable(ipToRelease.getId()); - assert (ip != null) : "Unable to mark the ip address id=" + ipToRelease.getId() + " as unavailable."; - } else { + assert (ip != null) : "Unable to mark the ip address id=" + ipToRelease.getId() + " as unavailable."; + } else { // portable IP address are associated with owner, until explicitly requested to be disassociated // so as part of network clean up just break IP association with guest network ipToRelease.setAssociatedWithNetworkId(null); @@ -2657,7 +2617,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra s_logger.warn("Failed to cleanup public lb rules as a part of shutdownNetworkRules due to ", ex); success = false; } - + try { if (!_lbMgr.revokeLoadBalancersForNetwork(networkId, Scheme.Internal)) { s_logger.warn("Failed to cleanup internal lb rules as a part of shutdownNetworkRules"); @@ -2709,10 +2669,9 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra success = false; } - if(network.getVpcId() != null){ + if (network.getVpcId() != null) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing Network ACL Items for network id=" + networkId + - " as a part of shutdownNetworkRules"); + s_logger.debug("Releasing Network ACL Items for network id=" + networkId + " as a part of shutdownNetworkRules"); } try { @@ -2728,7 +2687,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } - //release all static nats for the network if (!_rulesMgr.applyStaticNatForNetwork(networkId, false, caller, true)) { s_logger.warn("Failed to disable static nats as part of shutdownNetworkRules for network id " + networkId); @@ -2779,7 +2737,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return; } long hostId = host.getId(); - StartupRoutingCommand startup = (StartupRoutingCommand) cmd; + StartupRoutingCommand startup = (StartupRoutingCommand)cmd; String dataCenter = startup.getDataCenter(); @@ -2832,7 +2790,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } CheckNetworkCommand nwCmd = new CheckNetworkCommand(networkInfoList); - CheckNetworkAnswer answer = (CheckNetworkAnswer) _agentMgr.easySend(hostId, nwCmd); + CheckNetworkAnswer answer = (CheckNetworkAnswer)_agentMgr.easySend(hostId, nwCmd); if (answer == null) { s_logger.warn("Unable to get an answer to the CheckNetworkCommand from agent:" + host.getId()); @@ -2876,7 +2834,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } @Override - public Map finalizeServicesAndProvidersForNetwork(NetworkOffering offering, Long physicalNetworkId) { + public Map finalizeServicesAndProvidersForNetwork(NetworkOffering offering, Long physicalNetworkId) { Map svcProviders = new HashMap(); Map> providerSvcs = new HashMap>(); List servicesMap = _ntwkOfferingSrvcDao.listByNetworkOfferingId(offering.getId()); @@ -2900,8 +2858,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra // check that provider is supported if (checkPhysicalNetwork) { if (!_pNSPDao.isServiceProviderEnabled(physicalNetworkId, provider, service)) { - throw new UnsupportedServiceException("Provider " + provider + " is either not enabled or doesn't " + - "support service " + service + " in physical network id=" + physicalNetworkId); + throw new UnsupportedServiceException("Provider " + provider + " is either not enabled or doesn't " + "support service " + service + + " in physical network id=" + physicalNetworkId); } } @@ -2926,17 +2884,15 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return providers; } - @Override + @Override public boolean setupDns(Network network, Provider provider) { - boolean dnsProvided = _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dns, provider ); - boolean dhcpProvided =_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, - provider); + boolean dnsProvided = _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dns, provider); + boolean dhcpProvided = _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, provider); boolean setupDns = dnsProvided || dhcpProvided; return setupDns; } - - + protected NicProfile getNicProfileForVm(Network network, NicProfile requested, VirtualMachine vm) { NicProfile nic = null; if (requested != null && requested.getBroadCastUri() != null) { @@ -2956,7 +2912,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } return nic; } - + @Override public NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context, VirtualMachineProfile vmProfile, boolean prepare) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, @@ -2993,20 +2949,37 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return nic; } + s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network); + } + + //2) prepare nic + if (prepare) { + Pair implemented = implementNetwork(nic.getNetworkId(), dest, context); + nic = prepareNic(vmProfile, dest, context, nic.getId(), implemented.second()); + s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network); + } + + return nic; + } @Override public List getNicProfiles(VirtualMachine vm) { List nics = _nicDao.listByVmId(vm.getId()); List profiles = new ArrayList(); - + if (nics != null) { for (Nic nic : nics) { NetworkVO network = _networksDao.findById(nic.getNetworkId()); Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); - + NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName()); - NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), - networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network)); + NicProfile profile = new NicProfile(nic, + network, + nic.getBroadcastUri(), + nic.getIsolationUri(), + networkRate, + _networkModel.isSecurityGroupSupportedInNetwork(network), + _networkModel.getNetworkTag(vm.getHypervisorType(), network)); guru.updateNicProfile(profile, network); profiles.add(profile); } @@ -3014,13 +2987,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return profiles; } - - @Override - public int getNetworkLockTimeout() { - return _networkLockTimeout; - } - - protected boolean stateTransitTo(NetworkVO network, Network.Event e) throws NoTransitionException { return _stateMachine.transitTo(network, e, null, _networksDao); } @@ -3043,7 +3009,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return map; } - @Override public List getProvidersForServiceInNetwork(Network network, Service service) { Map> service2ProviderMap = getServiceProvidersMap(network.getId()); @@ -3054,12 +3019,11 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return null; } - protected List getElementForServiceInNetwork(Network network, Service service) { List elements = new ArrayList(); List providers = getProvidersForServiceInNetwork(network, service); //Only support one provider now - if (providers == null) { + if (providers == null) { s_logger.error("Cannot find " + service.getName() + " provider for network " + network.getId()); return null; } @@ -3068,7 +3032,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra s_logger.error("Found " + providers.size() + " " + service.getName() + " providers for network!" + network.getId()); return null; } - + for (Provider provider : providers) { NetworkElement element = _networkModel.getElementImplementingProvider(provider.getName()); s_logger.info("Let " + element.getName() + " handle " + service.getName() + " in network " + network.getId()); @@ -3076,7 +3040,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } return elements; } - @Override public StaticNatServiceProvider getStaticNatProviderForNetwork(Network network) { @@ -3086,7 +3049,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return (StaticNatServiceProvider)element; } - @Override public LoadBalancingServiceProvider getLoadBalancingProviderForNetwork(Network network, Scheme lbScheme) { List lbElements = getElementForServiceInNetwork(network, Service.Lb); @@ -3103,16 +3065,15 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (providerName == null) { throw new InvalidParameterValueException("Can't find Lb provider supporting scheme " + lbScheme.toString() + " in network " + network); } - lbElement = _networkModel.getElementImplementingProvider(providerName); - } else if (lbElements.size() == 1){ + lbElement = _networkModel.getElementImplementingProvider(providerName); + } else if (lbElements.size() == 1) { lbElement = lbElements.get(0); } - + assert lbElement != null; assert lbElement instanceof LoadBalancingServiceProvider; return (LoadBalancingServiceProvider)lbElement; } - @Override public boolean isNetworkInlineMode(Network network) { @@ -3120,36 +3081,56 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return offering.isInline(); } - @Override + @Override public boolean isSecondaryIpSetForNic(long nicId) { NicVO nic = _nicDao.findById(nicId); return nic.getSecondaryIp(); } - private boolean removeVmSecondaryIpsOfNic(long nicId) { - Transaction txn = Transaction.currentTxn(); - txn.start(); - List ipList = _nicSecondaryIpDao.listByNicId(nicId); - if (ipList != null) { - for (NicSecondaryIpVO ip: ipList) { - _nicSecondaryIpDao.remove(ip.getId()); - } - s_logger.debug("Revoving nic secondary ip entry ..."); - } - txn.commit(); - return true; + Transaction txn = Transaction.currentTxn(); + txn.start(); + List ipList = _nicSecondaryIpDao.listByNicId(nicId); + if (ipList != null) { + for (NicSecondaryIpVO ip : ipList) { + _nicSecondaryIpDao.remove(ip.getId()); + } + s_logger.debug("Revoving nic secondary ip entry ..."); } + txn.commit(); + return true; + } - - @Override + @Override public NicVO savePlaceholderNic(Network network, String ip4Address, String ip6Address, Type vmType) { - NicVO nic = new NicVO(null, null, network.getId(), null); - nic.setIp4Address(ip4Address); + NicVO nic = new NicVO(null, null, network.getId(), null); + nic.setIp4Address(ip4Address); nic.setIp6Address(ip6Address); nic.setReservationStrategy(ReservationStrategy.PlaceHolder); nic.setState(Nic.State.Reserved); nic.setVmType(vmType); return _nicDao.persist(nic); } - } + + @Override + public String getConfigComponentName() { + return NetworkOrchestrationService.class.getSimpleName(); + } + + public static final ConfigKey NetworkGcWait = new ConfigKey(Integer.class, + "network.gc.wait", + "Advanced", + "600", + "Time (in seconds) to wait before shutting down a network that's not in used", + false); + public static final ConfigKey NetworkGcInterval = new ConfigKey(Integer.class, + "network.gc.interval", + "Advanced", + "600", + "Seconds to wait before checking for networks to shutdown", + true); + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[] {NetworkGcWait, NetworkGcInterval, NetworkLockTimeout, GuestDomainSuffix, NetworkThrottlingRate}; + } +} diff --git a/engine/orchestration/test/com/cloud/vm/VirtualMachineManagerImplTest.java b/engine/orchestration/test/com/cloud/vm/VirtualMachineManagerImplTest.java index f124093e23d..beeff404c1e 100644 --- a/engine/orchestration/test/com/cloud/vm/VirtualMachineManagerImplTest.java +++ b/engine/orchestration/test/com/cloud/vm/VirtualMachineManagerImplTest.java @@ -45,7 +45,23 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; +import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; +import com.cloud.agent.api.CheckVirtualMachineAnswer; +import com.cloud.agent.api.CheckVirtualMachineCommand; +import com.cloud.agent.api.MigrateWithStorageAnswer; +import com.cloud.agent.api.MigrateWithStorageCommand; +import com.cloud.agent.api.MigrateWithStorageCompleteAnswer; +import com.cloud.agent.api.MigrateWithStorageCompleteCommand; +import com.cloud.agent.api.MigrateWithStorageReceiveAnswer; +import com.cloud.agent.api.MigrateWithStorageReceiveCommand; +import com.cloud.agent.api.MigrateWithStorageSendAnswer; +import com.cloud.agent.api.MigrateWithStorageSendCommand; +import com.cloud.agent.api.PrepareForMigrationAnswer; +import com.cloud.agent.api.PrepareForMigrationCommand; +import com.cloud.agent.api.ScaleVmAnswer; +import com.cloud.agent.api.ScaleVmCommand; +import com.cloud.capacity.CapacityManager; import com.cloud.dc.dao.ClusterDao; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.HostPodDao; @@ -60,6 +76,7 @@ import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.HypervisorGuru; +import com.cloud.hypervisor.HypervisorGuruManager; import com.cloud.offering.ServiceOffering; import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.DiskOfferingVO; @@ -85,6 +102,7 @@ import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.UserVmDetailsDao; import com.cloud.vm.dao.VMInstanceDao; +import com.cloud.vm.snapshot.VMSnapshotManager; public class VirtualMachineManagerImplTest { @@ -95,8 +113,6 @@ public class VirtualMachineManagerImplTest { @Mock Account _account; @Mock - AccountManager _accountMgr; - @Mock ConfigurationManager _configMgr; @Mock CapacityManager _capacityMgr; @@ -141,8 +157,6 @@ public class VirtualMachineManagerImplTest { @Mock ItWorkVO _work; @Mock - ConfigurationServer _configServer; - @Mock HostVO hostVO; @Mock UserVmDetailVO _vmDetailVO; @@ -191,9 +205,6 @@ public class VirtualMachineManagerImplTest { _vmMgr._templateDao = _templateDao; _vmMgr._volsDao = _volsDao; _vmMgr.volumeMgr = _storageMgr; - _vmMgr._accountDao = _accountDao; - _vmMgr._accountMgr = _accountMgr; - _vmMgr._configMgr = _configMgr; _vmMgr._capacityMgr = _capacityMgr; _vmMgr._hostDao = _hostDao; _vmMgr._nodeId = 1L; @@ -209,7 +220,6 @@ public class VirtualMachineManagerImplTest { _vmMgr._hvGuruMgr = _hvGuruMgr; _vmMgr._vmSnapshotMgr = _vmSnapshotMgr; _vmMgr._vmDao = _vmInstanceDao; - _vmMgr._configServer = _configServer; _vmMgr._uservmDetailsDao = _vmDetailsDao; _vmMgr._entityMgr = _entityMgr; @@ -256,9 +266,9 @@ public class VirtualMachineManagerImplTest { doReturn(hostVO).when(_hostDao).findById(1L); doReturn(1L).when(_vmInstance).getDataCenterId(); doReturn(1L).when(hostVO).getClusterId(); - when(_configServer.getConfigValue(Config.EnableDynamicallyScaleVm.key(), Config.ConfigurationParameterScope.zone.toString(), 1L)).thenReturn("true"); - when(_configServer.getConfigValue(Config.MemOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), 1L)).thenReturn("1.0"); - when(_configServer.getConfigValue(Config.CPUOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), 1L)).thenReturn("1.0"); + when(_configMgr.getConfigValue(Config.EnableDynamicallyScaleVm.key(), Config.Scope.zone.toString(), 1L)).thenReturn("true"); + when(_configMgr.getConfigValue(Config.MemOverprovisioningFactor.key(), Config.Scope.cluster.toString(), 1L)).thenReturn("1.0"); + when(_configMgr.getConfigValue(Config.CPUOverprovisioningFactor.key(), Config.Scope.cluster.toString(), 1L)).thenReturn("1.0"); ScaleVmCommand reconfigureCmd = new ScaleVmCommand("myVmName", newServiceOffering.getCpu(), newServiceOffering.getSpeed(), newServiceOffering.getSpeed(), newServiceOffering.getRamSize(), newServiceOffering.getRamSize(), newServiceOffering.getLimitCpuUse()); @@ -334,8 +344,8 @@ public class VirtualMachineManagerImplTest { // Mock the vm guru and the user vm object that gets returned. _vmMgr._vmGurus = new HashMap(); - UserVmManagerImpl userVmManager = mock(UserVmManagerImpl.class); - _vmMgr.registerGuru(VirtualMachine.Type.User, userVmManager); +// UserVmManagerImpl userVmManager = mock(UserVmManagerImpl.class); +// _vmMgr.registerGuru(VirtualMachine.Type.User, userVmManager); // Mock the iteration over all the volumes of an instance. Iterator volumeIterator = mock(Iterator.class); diff --git a/engine/schema/pom.xml b/engine/schema/pom.xml index a62cb90f65b..8860b9b7920 100644 --- a/engine/schema/pom.xml +++ b/engine/schema/pom.xml @@ -38,6 +38,11 @@ cloud-framework-ipc ${project.version} + + org.apache.cloudstack + cloud-framework-config + ${project.version} + org.apache.cloudstack cloud-framework-db diff --git a/engine/schema/src/com/cloud/dc/ClusterDetailsDaoImpl.java b/engine/schema/src/com/cloud/dc/ClusterDetailsDaoImpl.java index d14e0e42af2..f7f0f11ba07 100755 --- a/engine/schema/src/com/cloud/dc/ClusterDetailsDaoImpl.java +++ b/engine/schema/src/com/cloud/dc/ClusterDetailsDaoImpl.java @@ -22,7 +22,9 @@ import java.util.Map; import javax.ejb.Local; -import org.springframework.stereotype.Component; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.ConfigKey.Scope; +import org.apache.cloudstack.framework.config.ScopedConfigStorage; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.db.GenericDaoBase; @@ -30,9 +32,8 @@ import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; -@Component @Local(value=ClusterDetailsDao.class) -public class ClusterDetailsDaoImpl extends GenericDaoBase implements ClusterDetailsDao { +public class ClusterDetailsDaoImpl extends GenericDaoBase implements ClusterDetailsDao, ScopedConfigStorage { protected final SearchBuilder ClusterSearch; protected final SearchBuilder DetailSearch; @@ -88,7 +89,7 @@ public class ClusterDetailsDaoImpl extends GenericDaoBase sc = ClusterSearch.create(); sc.setParameters("clusterId", clusterId); List results = search(sc, null); @@ -130,4 +131,14 @@ public class ClusterDetailsDaoImpl extends GenericDaoBase key) { + ClusterDetailsVO vo = findDetail(id, key.key()); + return vo == null ? null : vo.getValue(); + } } diff --git a/engine/schema/src/com/cloud/dc/dao/DcDetailsDaoImpl.java b/engine/schema/src/com/cloud/dc/dao/DcDetailsDaoImpl.java index 278fdb49079..7f5723f2b8b 100644 --- a/engine/schema/src/com/cloud/dc/dao/DcDetailsDaoImpl.java +++ b/engine/schema/src/com/cloud/dc/dao/DcDetailsDaoImpl.java @@ -22,7 +22,9 @@ import java.util.Map; import javax.ejb.Local; -import org.springframework.stereotype.Component; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.ConfigKey.Scope; +import org.apache.cloudstack.framework.config.ScopedConfigStorage; import com.cloud.dc.DcDetailVO; import com.cloud.utils.db.GenericDaoBase; @@ -30,9 +32,8 @@ import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; -@Component @Local(value=DcDetailsDao.class) -public class DcDetailsDaoImpl extends GenericDaoBase implements DcDetailsDao { +public class DcDetailsDaoImpl extends GenericDaoBase implements DcDetailsDao, ScopedConfigStorage { protected final SearchBuilder DcSearch; protected final SearchBuilder DetailSearch; @@ -71,7 +72,7 @@ public class DcDetailsDaoImpl extends GenericDaoBase implement @Override public void deleteDetails(long dcId) { - SearchCriteria sc = DcSearch.create(); + SearchCriteria sc = DcSearch.create(); sc.setParameters("dcId", dcId); List results = search(sc, null); @@ -94,4 +95,16 @@ public class DcDetailsDaoImpl extends GenericDaoBase implement } txn.commit(); } + + @Override + public Scope getScope() { + return ConfigKey.Scope.Zone; + } + + @Override + public String getConfigValue(long id, ConfigKey key) { + DcDetailVO vo = findDetail(id, key.key()); + return vo == null ? null : vo.getValue(); + } + } diff --git a/server/src/com/cloud/network/vpc/NetworkACLItemDao.java b/engine/schema/src/com/cloud/network/vpc/NetworkACLItemDao.java similarity index 100% rename from server/src/com/cloud/network/vpc/NetworkACLItemDao.java rename to engine/schema/src/com/cloud/network/vpc/NetworkACLItemDao.java diff --git a/server/src/com/cloud/network/vpc/NetworkACLItemVO.java b/engine/schema/src/com/cloud/network/vpc/NetworkACLItemVO.java similarity index 100% rename from server/src/com/cloud/network/vpc/NetworkACLItemVO.java rename to engine/schema/src/com/cloud/network/vpc/NetworkACLItemVO.java diff --git a/server/src/com/cloud/network/vpc/NetworkACLVO.java b/engine/schema/src/com/cloud/network/vpc/NetworkACLVO.java similarity index 100% rename from server/src/com/cloud/network/vpc/NetworkACLVO.java rename to engine/schema/src/com/cloud/network/vpc/NetworkACLVO.java diff --git a/server/src/com/cloud/network/vpc/dao/NetworkACLDao.java b/engine/schema/src/com/cloud/network/vpc/dao/NetworkACLDao.java similarity index 100% rename from server/src/com/cloud/network/vpc/dao/NetworkACLDao.java rename to engine/schema/src/com/cloud/network/vpc/dao/NetworkACLDao.java diff --git a/server/src/com/cloud/network/vpc/dao/NetworkACLDaoImpl.java b/engine/schema/src/com/cloud/network/vpc/dao/NetworkACLDaoImpl.java similarity index 100% rename from server/src/com/cloud/network/vpc/dao/NetworkACLDaoImpl.java rename to engine/schema/src/com/cloud/network/vpc/dao/NetworkACLDaoImpl.java diff --git a/server/src/com/cloud/network/vpc/dao/NetworkACLItemDaoImpl.java b/engine/schema/src/com/cloud/network/vpc/dao/NetworkACLItemDaoImpl.java similarity index 100% rename from server/src/com/cloud/network/vpc/dao/NetworkACLItemDaoImpl.java rename to engine/schema/src/com/cloud/network/vpc/dao/NetworkACLItemDaoImpl.java diff --git a/engine/schema/src/com/cloud/storage/dao/StoragePoolDetailsDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/StoragePoolDetailsDaoImpl.java index 8952e6cb154..f60ea176f52 100644 --- a/engine/schema/src/com/cloud/storage/dao/StoragePoolDetailsDaoImpl.java +++ b/engine/schema/src/com/cloud/storage/dao/StoragePoolDetailsDaoImpl.java @@ -22,19 +22,19 @@ import java.util.Map; import javax.ejb.Local; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.ConfigKey.Scope; +import org.apache.cloudstack.framework.config.ScopedConfigStorage; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; -import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; -@Component @Local(value = StoragePoolDetailsDao.class) -public class StoragePoolDetailsDaoImpl extends GenericDaoBase implements - StoragePoolDetailsDao { +public class StoragePoolDetailsDaoImpl extends GenericDaoBase implements StoragePoolDetailsDao, ScopedConfigStorage { protected final SearchBuilder PoolSearch; @@ -83,4 +83,15 @@ public class StoragePoolDetailsDaoImpl extends GenericDaoBase key) { + StoragePoolDetailVO vo = findDetail(id, key.key()); + return vo == null ? null : vo.getValue(); + } } diff --git a/engine/schema/src/com/cloud/user/AccountDetailsDao.java b/engine/schema/src/com/cloud/user/AccountDetailsDao.java index f2a1f0e2884..036e7a20637 100755 --- a/engine/schema/src/com/cloud/user/AccountDetailsDao.java +++ b/engine/schema/src/com/cloud/user/AccountDetailsDao.java @@ -17,6 +17,7 @@ package com.cloud.user; import java.util.Map; + import com.cloud.utils.db.GenericDao; @@ -31,7 +32,7 @@ public interface AccountDetailsDao extends GenericDao { /* * For these existing entries, they will get updated. For these new entries, - * they will get created + * they will get created */ void update(long accountId, Map details); } diff --git a/engine/schema/src/com/cloud/user/AccountDetailsDaoImpl.java b/engine/schema/src/com/cloud/user/AccountDetailsDaoImpl.java index c123f548dbe..36fd5b4e605 100755 --- a/engine/schema/src/com/cloud/user/AccountDetailsDaoImpl.java +++ b/engine/schema/src/com/cloud/user/AccountDetailsDaoImpl.java @@ -22,75 +22,87 @@ import java.util.Map; import javax.ejb.Local; -import org.springframework.stereotype.Component; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.ConfigKey.Scope; +import org.apache.cloudstack.framework.config.ScopedConfigStorage; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.SearchCriteria2; -import com.cloud.utils.db.Transaction; import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.utils.db.SearchCriteria2; import com.cloud.utils.db.SearchCriteriaService; +import com.cloud.utils.db.Transaction; -@Component -@Local(value={AccountDetailsDao.class}) -public class AccountDetailsDaoImpl extends GenericDaoBase implements AccountDetailsDao { - protected final SearchBuilder accountSearch; - - protected AccountDetailsDaoImpl() { - accountSearch = createSearchBuilder(); - accountSearch.and("accountId", accountSearch.entity().getAccountId(), Op.EQ); - accountSearch.done(); - } - - @Override - public Map findDetails(long accountId) { - SearchCriteriaService sc = SearchCriteria2.create(AccountDetailVO.class); - sc.addAnd(sc.getEntity().getAccountId(), Op.EQ, accountId); - List results = sc.list(); - Map details = new HashMap(results.size()); - for (AccountDetailVO r : results) { - details.put(r.getName(), r.getValue()); - } - return details; - } +@Local(value = {AccountDetailsDao.class}) +public class AccountDetailsDaoImpl extends GenericDaoBase implements AccountDetailsDao, ScopedConfigStorage { + protected final SearchBuilder accountSearch; - @Override - public void persist(long accountId, Map details) { + protected AccountDetailsDaoImpl() { + accountSearch = createSearchBuilder(); + accountSearch.and("accountId", accountSearch.entity().getAccountId(), Op.EQ); + accountSearch.done(); + } + + @Override + public Map findDetails(long accountId) { + SearchCriteriaService sc = SearchCriteria2.create(AccountDetailVO.class); + sc.addAnd(sc.getEntity().getAccountId(), Op.EQ, accountId); + List results = sc.list(); + Map details = new HashMap(results.size()); + for (AccountDetailVO r : results) { + details.put(r.getName(), r.getValue()); + } + return details; + } + + @Override + public void persist(long accountId, Map details) { Transaction txn = Transaction.currentTxn(); txn.start(); SearchCriteria sc = accountSearch.create(); sc.setParameters("accountId", accountId); expunge(sc); for (Map.Entry detail : details.entrySet()) { - AccountDetailVO vo = new AccountDetailVO(accountId, detail.getKey(), detail.getValue()); - persist(vo); + AccountDetailVO vo = new AccountDetailVO(accountId, detail.getKey(), detail.getValue()); + persist(vo); } txn.commit(); - } + } - @Override - public AccountDetailVO findDetail(long accountId, String name) { - SearchCriteriaService sc = SearchCriteria2.create(AccountDetailVO.class); - sc.addAnd(sc.getEntity().getAccountId(), Op.EQ, accountId); - sc.addAnd(sc.getEntity().getName(), Op.EQ, name); - return sc.find(); - } + @Override + public AccountDetailVO findDetail(long accountId, String name) { + SearchCriteriaService sc = SearchCriteria2.create(AccountDetailVO.class); + sc.addAnd(sc.getEntity().getAccountId(), Op.EQ, accountId); + sc.addAnd(sc.getEntity().getName(), Op.EQ, name); + return sc.find(); + } - @Override - public void deleteDetails(long accountId) { - SearchCriteria sc = accountSearch.create(); + @Override + public void deleteDetails(long accountId) { + SearchCriteria sc = accountSearch.create(); sc.setParameters("accountId", accountId); List results = search(sc, null); for (AccountDetailVO result : results) { - remove(result.getId()); + remove(result.getId()); } - } + } - @Override + @Override public void update(long accountId, Map details) { - Map oldDetails = findDetails(accountId); - oldDetails.putAll(details); - persist(accountId, oldDetails); + Map oldDetails = findDetails(accountId); + oldDetails.putAll(details); + persist(accountId, oldDetails); + } + + @Override + public Scope getScope() { + return ConfigKey.Scope.Account; + } + + @Override + public String getConfigValue(long id, ConfigKey key) { + AccountDetailVO vo = findDetail(id, key.key()); + return vo == null ? null : vo.getValue(); } } diff --git a/server/src/org/apache/cloudstack/region/PortableIpDao.java b/engine/schema/src/org/apache/cloudstack/region/PortableIpDao.java similarity index 100% rename from server/src/org/apache/cloudstack/region/PortableIpDao.java rename to engine/schema/src/org/apache/cloudstack/region/PortableIpDao.java diff --git a/server/src/org/apache/cloudstack/region/PortableIpDaoImpl.java b/engine/schema/src/org/apache/cloudstack/region/PortableIpDaoImpl.java similarity index 100% rename from server/src/org/apache/cloudstack/region/PortableIpDaoImpl.java rename to engine/schema/src/org/apache/cloudstack/region/PortableIpDaoImpl.java diff --git a/server/src/org/apache/cloudstack/region/PortableIpRangeDao.java b/engine/schema/src/org/apache/cloudstack/region/PortableIpRangeDao.java similarity index 100% rename from server/src/org/apache/cloudstack/region/PortableIpRangeDao.java rename to engine/schema/src/org/apache/cloudstack/region/PortableIpRangeDao.java diff --git a/server/src/org/apache/cloudstack/region/PortableIpRangeDaoImpl.java b/engine/schema/src/org/apache/cloudstack/region/PortableIpRangeDaoImpl.java similarity index 100% rename from server/src/org/apache/cloudstack/region/PortableIpRangeDaoImpl.java rename to engine/schema/src/org/apache/cloudstack/region/PortableIpRangeDaoImpl.java diff --git a/server/src/org/apache/cloudstack/region/PortableIpRangeVO.java b/engine/schema/src/org/apache/cloudstack/region/PortableIpRangeVO.java similarity index 100% rename from server/src/org/apache/cloudstack/region/PortableIpRangeVO.java rename to engine/schema/src/org/apache/cloudstack/region/PortableIpRangeVO.java diff --git a/server/src/org/apache/cloudstack/region/PortableIpVO.java b/engine/schema/src/org/apache/cloudstack/region/PortableIpVO.java similarity index 100% rename from server/src/org/apache/cloudstack/region/PortableIpVO.java rename to engine/schema/src/org/apache/cloudstack/region/PortableIpVO.java diff --git a/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepot.java b/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepot.java index 98363f30c9d..544f188373c 100644 --- a/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepot.java +++ b/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepot.java @@ -21,7 +21,18 @@ package org.apache.cloudstack.framework.config; * */ public interface ConfigDepot { + /** + * Retrieves the global configuration value for key. + * @param key name of the key to retrieve. + * @return global configuration value even if the key is scoped + */ ConfigValue get(ConfigKey key); - ScopedConfigValue getScopedValue(ConfigKey key); + /** + * Retrieves a ConfigValue by its name + * @param name name of the config + * @return ConfigValue + */ + ConfigValue get(String name); + } diff --git a/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepotImpl.java b/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepotImpl.java index b2be0f2f298..241dcfe2f8e 100644 --- a/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepotImpl.java +++ b/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepotImpl.java @@ -16,15 +16,21 @@ // under the License. package org.apache.cloudstack.framework.config; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; import javax.inject.Inject; +import org.apache.cloudstack.framework.config.ConfigKey.Scope; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; +import com.cloud.utils.component.ConfigInjector; +import com.cloud.utils.component.SystemIntegrityChecker; import com.cloud.utils.db.EntityManager; +import com.cloud.utils.exception.CloudRuntimeException; /** * ConfigDepotImpl implements the ConfigDepot and ConfigDepotAdmin interface. @@ -39,8 +45,6 @@ import com.cloud.utils.db.EntityManager; * * TODO: * - Move the rest of the changes to the config table to here. - * - Implement ScopedConfigValue - * - Move the code to set scoped configuration values to here. * - Add the code to mark the rows in configuration table without * the corresponding keys to be null. * - Move all of the configurations to using ConfigDepot @@ -48,28 +52,33 @@ import com.cloud.utils.db.EntityManager; * - Figure out the correct categories. * */ -class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin { +class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemIntegrityChecker, ConfigInjector { @Inject EntityManager _entityMgr; - @Inject ConfigurationDao _configDao; - @Inject List _configurables; + @Inject + List _scopedStorage; + + HashMap> _allKeys = new HashMap>(1007); public ConfigDepotImpl() { } @Override public ConfigValue get(ConfigKey config) { - return new ConfigValue(_entityMgr, config); - } - - @Override - public ScopedConfigValue getScopedValue(ConfigKey config) { - assert (config.scope() != null) : "Did you notice the configuration you're trying to retrieve is not scoped?"; - return new ScopedConfigValue(_entityMgr, config); + if (config.scope() == Scope.Global) { + return new ConfigValue(_entityMgr, config); + } else { + for (ScopedConfigStorage storage : _scopedStorage) { + if (storage.getScope() == config.scope()) { + return new ConfigValue(_entityMgr, config, storage); + } + } + throw new CloudRuntimeException("Unable to find config storage for this scope: " + config.scope()); + } } @Override @@ -103,4 +112,37 @@ class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin { public List getComponentsInDepot() { return new ArrayList(); } + + @Override + public void check() { + for (Configurable configurable : _configurables) { + for (ConfigKey key : configurable.getConfigKeys()) { + if (_allKeys.containsKey(key.key())) { + throw new CloudRuntimeException("Configurable " + configurable.getConfigComponentName() + " is adding a key that has been added before: " + key.toString()); + } + _allKeys.put(key.key(), key); + } + } + } + + @Override + public void inject(Field field, Object obj, String key) { + ConfigKey configKey = _allKeys.get(key); + try { + field.set(obj, get(configKey)); + } catch (IllegalArgumentException e) { + throw new CloudRuntimeException("Unable to inject configuration due to ", e); + } catch (IllegalAccessException e) { + throw new CloudRuntimeException("Unable to inject configuration due to ", e); + } + } + + @Override + public ConfigValue get(String name) { + ConfigKey configKey = _allKeys.get(name); + if (configKey == null) { + throw new CloudRuntimeException("Unable to find a registered config key for " + name); + } + return get(configKey); + } } diff --git a/framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java b/framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java index cef226c74b6..3d0884f5e54 100644 --- a/framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java +++ b/framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java @@ -16,7 +16,8 @@ // under the License. package org.apache.cloudstack.framework.config; -import com.cloud.org.Grouping; +import com.cloud.utils.exception.CloudRuntimeException; + /** * ConfigKey supplants the original Config.java. It is just a class @@ -24,7 +25,11 @@ import com.cloud.org.Grouping; * */ public class ConfigKey { - + + public static enum Scope { + Global, Zone, Cluster, StoragePool, Account + } + private final String _category; public String category() { @@ -35,7 +40,7 @@ public class ConfigKey { return _type; } - public String key() { + public final String key() { return _name; } @@ -47,7 +52,7 @@ public class ConfigKey { return _description; } - public Class scope() { + public Scope scope() { return _scope; } @@ -64,11 +69,19 @@ public class ConfigKey { private final String _name; private final String _defaultValue; private final String _description; - private final Class _scope; // Parameter can be at different levels (Zone/cluster/pool/account), by default every parameter is at global + private final Scope _scope; // Parameter can be at different levels (Zone/cluster/pool/account), by default every parameter is at global private final boolean _isDynamic; + private final T _multiplier; - public ConfigKey(Class type, String name, String category, String defaultValue, String description, boolean isDynamic, - Class scope) { + public ConfigKey(String category, Class type, String name, String defaultValue, String description, boolean isDynamic, Scope scope) { + this(type, name, category, defaultValue, description, isDynamic, scope, null); + } + + public ConfigKey(String category, Class type, String name, String defaultValue, String description, boolean isDynamic) { + this(type, name, category, defaultValue, description, isDynamic, Scope.Global, null); + } + + public ConfigKey(Class type, String name, String category, String defaultValue, String description, boolean isDynamic, Scope scope, T multiplier) { _category = category; _type = type; _name = name; @@ -76,9 +89,32 @@ public class ConfigKey { _description = description; _scope = scope; _isDynamic = isDynamic; + _multiplier = multiplier; } public ConfigKey(Class type, String name, String category, String defaultValue, String description, boolean isDynamic) { - this(type, name, category, defaultValue, description, isDynamic, null); + this(type, name, category, defaultValue, description, isDynamic, Scope.Global, null); + } + + public T multiplier() { + return _multiplier; + } + + @Override + public int hashCode() { + return _name.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof ConfigKey) { + ConfigKey that = (ConfigKey)obj; + return this._name.equals(that._name); + } else if (obj instanceof String) { + String key = (String)obj; + return key.equals(_name); + } + + throw new CloudRuntimeException("Comparing ConfigKey to " + obj.toString()); } } diff --git a/framework/config/src/org/apache/cloudstack/framework/config/ConfigValue.java b/framework/config/src/org/apache/cloudstack/framework/config/ConfigValue.java index 0cfc61a3554..c6b99db100d 100644 --- a/framework/config/src/org/apache/cloudstack/framework/config/ConfigValue.java +++ b/framework/config/src/org/apache/cloudstack/framework/config/ConfigValue.java @@ -16,6 +16,8 @@ // under the License. package org.apache.cloudstack.framework.config; +import java.sql.Date; + import org.apache.cloudstack.config.Configuration; import com.cloud.utils.db.EntityManager; @@ -31,48 +33,66 @@ public class ConfigValue { ConfigKey _config; EntityManager _entityMgr; - Number _multiplier; T _value; + ScopedConfigStorage _storage; public ConfigValue(EntityManager entityMgr, ConfigKey config) { _entityMgr = entityMgr; _config = config; - _multiplier = 1; + } + + protected ConfigValue(EntityManager entityMgr, ConfigKey key, ScopedConfigStorage storage) { + this(entityMgr, key); + _storage = storage; } public ConfigKey getConfigKey() { return _config; } - public ConfigValue setMultiplier(Number multiplier) { // Convience method - _multiplier = multiplier; - return this; - } - - @SuppressWarnings("unchecked") public T value() { if (_value == null || _config.isDynamic()) { Configuration vo = _entityMgr.findById(Configuration.class, _config.key()); - String value = vo != null ? vo.getValue() : _config.defaultValue(); - - Class type = _config.type(); - if (type.isAssignableFrom(Boolean.class)) { - _value = (T)Boolean.valueOf(value); - } else if (type.isAssignableFrom(Integer.class)) { - _value = (T)new Integer((Integer.parseInt(value) * _multiplier.intValue())); - } else if (type.isAssignableFrom(Long.class)) { - _value = (T)new Long(Long.parseLong(value) * _multiplier.longValue()); - } else if (type.isAssignableFrom(Short.class)) { - _value = (T)new Short(Short.parseShort(value)); - } else if (type.isAssignableFrom(String.class)) { - _value = (T)value; - } else if (type.isAssignableFrom(Float.class)) { - _value = (T)new Float(Float.parseFloat(value) * _multiplier.floatValue()); - } else { - throw new CloudRuntimeException("Unsupported data type for config values: " + type); - } + _value = valueOf(vo != null ? vo.getValue() : _config.defaultValue()); } return _value; } + + public T valueIn(long id) { + String value = _storage.getConfigValue(id, _config); + if (value == null) { + return value(); + } else { + return valueOf(value); + } + } + + @SuppressWarnings("unchecked") + protected T valueOf(String value) { + Class type = _config.type(); + if (type.isAssignableFrom(Boolean.class)) { + return (T)Boolean.valueOf(value); + } else if (type.isAssignableFrom(Integer.class)) { + return (T)new Integer((Integer.parseInt(value) * ((Number)_config.multiplier()).intValue())); + } else if (type.isAssignableFrom(Long.class)) { + return (T)new Long(Long.parseLong(value) * ((Number)_config.multiplier()).longValue()); + } else if (type.isAssignableFrom(Short.class)) { + return (T)new Short(Short.parseShort(value)); + } else if (type.isAssignableFrom(String.class)) { + return (T)value; + } else if (type.isAssignableFrom(Float.class)) { + return (T)new Float(Float.parseFloat(value) * ((Number)_config.multiplier()).floatValue()); + } else if (type.isAssignableFrom(Double.class)) { + return (T)new Double(Double.parseDouble(value)); + } else if (type.isAssignableFrom(String.class)) { + return (T)value; + } else if (type.isAssignableFrom(Date.class)) { + return (T)Date.valueOf(value); + } else if (type.isAssignableFrom(Character.class)) { + return (T)new Character(value.charAt(0)); + } else { + throw new CloudRuntimeException("Unsupported data type for config values: " + type); + } + } } diff --git a/framework/config/src/org/apache/cloudstack/framework/config/ConfigurationVO.java b/framework/config/src/org/apache/cloudstack/framework/config/ConfigurationVO.java index 0cc10190efd..2953fcf5767 100644 --- a/framework/config/src/org/apache/cloudstack/framework/config/ConfigurationVO.java +++ b/framework/config/src/org/apache/cloudstack/framework/config/ConfigurationVO.java @@ -80,7 +80,7 @@ public class ConfigurationVO implements Configuration { this(key.category(), "DEFAULT", component, key.key(), key.defaultValue(), key.description()); defaultValue = key.defaultValue(); dynamic = key.isDynamic(); - scope = key.scope() != null ? key.scope().getName() : null; + scope = key.scope() != null ? key.scope().toString() : null; } @Override diff --git a/framework/config/src/org/apache/cloudstack/framework/config/ScopedConfigValue.java b/framework/config/src/org/apache/cloudstack/framework/config/ScopedConfigValue.java deleted file mode 100644 index 4631521b386..00000000000 --- a/framework/config/src/org/apache/cloudstack/framework/config/ScopedConfigValue.java +++ /dev/null @@ -1,43 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package org.apache.cloudstack.framework.config; - -import com.cloud.dc.DataCenter; -import com.cloud.dc.Pod; -import com.cloud.org.Cluster; -import com.cloud.org.Grouping; -import com.cloud.utils.db.EntityManager; - -public class ScopedConfigValue extends ConfigValue { - public T getValueForScope(long scopeId) { - // TODO: In order to complete this the details for zone, pod, cluster - // needs to have interfaces. Then you can use the EntityManager to - // retrieve those information. - Class scope = _config.scope(); - if (scope == DataCenter.class) { - } else if (scope == Pod.class) { - - } else if (scope == Cluster.class) { - - } - return null; - } - - protected ScopedConfigValue(EntityManager entityMgr, ConfigKey key) { - super(entityMgr, key); - } -} diff --git a/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java b/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java index 38377ee9202..8188640bdd2 100644 --- a/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java +++ b/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java @@ -62,6 +62,7 @@ import com.cloud.cluster.ManagementServerHost; import com.cloud.utils.DateUtil; import com.cloud.utils.Predicate; import com.cloud.utils.PropertiesUtil; +import com.cloud.utils.component.InjectConfig; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.DB; @@ -80,9 +81,9 @@ import com.cloud.utils.mgmt.JmxUtil; public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, ClusterManagerListener, Configurable { // Advanced private static final ConfigKey JobExpireMinutes = new ConfigKey(Long.class, "job.expire.minutes", "Advanced", "1440", - "Time (in minutes) for async-jobs to be kept in system", true, null); - private static final ConfigKey JobCancelThresholdMinutes = new ConfigKey(Long.class, "job.cancel.threshold.minutes", "Advanced", - "60", "Time (in minutes) for async-jobs to be forcely cancelled if it has been in process for long", true, null); + "Time (in minutes) for async-jobs to be kept in system", true, ConfigKey.Scope.Global, 60l); + private static final ConfigKey JobCancelThresholdMinutes = new ConfigKey(Long.class, "job.cancel.threshold.minutes", "Advanced", "60", + "Time (in minutes) for async-jobs to be forcely cancelled if it has been in process for long", true, ConfigKey.Scope.Global, 60l); private static final Logger s_logger = Logger.getLogger(AsyncJobManagerImpl.class); @@ -105,7 +106,9 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, @Inject private ConfigDepot _configDepot; + @InjectConfig(key = "job.expire.minutes") private ConfigValue _jobExpireSeconds; // 1 day + @InjectConfig(key = "job.cancel.threshold.minutes") private ConfigValue _jobCancelThresholdSeconds; // 1 hour (for cancelling the jobs blocking other jobs) private volatile long _executionRunNumber = 1; @@ -878,8 +881,8 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, @Override public boolean configure(String name, Map params) throws ConfigurationException { - _jobExpireSeconds = _configDepot.get(JobExpireMinutes).setMultiplier(60); - _jobCancelThresholdSeconds = _configDepot.get(JobCancelThresholdMinutes).setMultiplier(60); + _jobExpireSeconds = _configDepot.get(JobExpireMinutes); + _jobCancelThresholdSeconds = _configDepot.get(JobCancelThresholdMinutes); try { final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties"); diff --git a/plugins/network-elements/bigswitch-vns/src/com/cloud/network/guru/BigSwitchVnsGuestNetworkGuru.java b/plugins/network-elements/bigswitch-vns/src/com/cloud/network/guru/BigSwitchVnsGuestNetworkGuru.java index 4396d47534b..3d3196e0b1a 100644 --- a/plugins/network-elements/bigswitch-vns/src/com/cloud/network/guru/BigSwitchVnsGuestNetworkGuru.java +++ b/plugins/network-elements/bigswitch-vns/src/com/cloud/network/guru/BigSwitchVnsGuestNetworkGuru.java @@ -19,6 +19,15 @@ package com.cloud.network.guru; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; + +import javax.ejb.Local; +import javax.inject.Inject; + +import org.apache.log4j.Logger; + import com.cloud.agent.AgentManager; import com.cloud.agent.api.CreateVnsNetworkAnswer; import com.cloud.agent.api.CreateVnsNetworkCommand; @@ -35,9 +44,9 @@ import com.cloud.host.dao.HostDao; import com.cloud.host.dao.HostDetailsDao; import com.cloud.network.BigSwitchVnsDeviceVO; import com.cloud.network.Network; -import com.cloud.network.NetworkProfile; import com.cloud.network.Network.GuestType; import com.cloud.network.Network.State; +import com.cloud.network.NetworkProfile; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.PhysicalNetwork; import com.cloud.network.PhysicalNetwork.IsolationMethod; @@ -51,18 +60,8 @@ import com.cloud.user.Account; import com.cloud.user.dao.AccountDao; import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.List; - -import org.apache.log4j.Logger; - -import javax.ejb.Local; -import javax.inject.Inject; - @Local(value = NetworkGuru.class) public class BigSwitchVnsGuestNetworkGuru extends GuestNetworkGuru { @@ -161,8 +160,7 @@ public class BigSwitchVnsGuestNetworkGuru extends GuestNetworkGuru { implemented.setCidr(network.getCidr()); } - String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, - network.getAccountId(), context.getReservationId(), canUseSystemGuestVlan(network.getAccountId())); + String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), context.getReservationId(), _useSystemGuestVlans.valueIn(network.getAccountId())); if (vnet == null) { throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a " + "part of network " + network + " implement ", DataCenter.class, dcId); diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManager.java b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManager.java index 9faca562bfb..efd5bf5f6c2 100644 --- a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManager.java +++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManager.java @@ -5,7 +5,7 @@ // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, @@ -27,11 +27,10 @@ import com.cloud.network.Network; import com.cloud.network.lb.LoadBalancingRule; import com.cloud.network.router.VirtualRouter; import com.cloud.user.Account; -import com.cloud.utils.component.Manager; import com.cloud.utils.net.Ip; import com.cloud.vm.VirtualMachineProfile.Param; -public interface InternalLoadBalancerVMManager extends Manager, InternalLoadBalancerVMService{ +public interface InternalLoadBalancerVMManager { //RAM/CPU for the system offering used by Internal LB VMs public static final int DEFAULT_INTERNALLB_VM_RAMSIZE = 128; // 128 MB public static final int DEFAULT_INTERNALLB_VM_CPU_MHZ = 256; // 256 MHz @@ -41,11 +40,11 @@ public interface InternalLoadBalancerVMManager extends Manager, InternalLoadBala * @param vmId * @param caller * @param callerUserId - * @return + * @return * @throws ResourceUnavailableException * @throws ConcurrentOperationException */ - boolean destroyInternalLbVm(long vmId, Account caller, Long callerUserId) + boolean destroyInternalLbVm(long vmId, Account caller, Long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException; diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java index ff69577616b..e9fa8427cf3 100644 --- a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java +++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java @@ -27,9 +27,10 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; +import org.apache.cloudstack.framework.config.ConfigDepot; +import org.apache.cloudstack.framework.config.ConfigValue; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO; import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao; @@ -79,6 +80,7 @@ import com.cloud.network.lb.LoadBalancingRule.LbDestination; import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy; import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy; import com.cloud.network.lb.LoadBalancingRulesManager; +import com.cloud.network.router.VirtualNetworkApplianceManager; import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VirtualRouter.RedundantState; import com.cloud.network.router.VirtualRouter.Role; @@ -117,12 +119,9 @@ import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.NicDao; -@Component @Local(value = { InternalLoadBalancerVMManager.class, InternalLoadBalancerVMService.class}) -public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements - InternalLoadBalancerVMManager, VirtualMachineGuru { - private static final Logger s_logger = Logger - .getLogger(InternalLoadBalancerVMManagerImpl.class); +public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements InternalLoadBalancerVMManager, InternalLoadBalancerVMService, VirtualMachineGuru { + private static final Logger s_logger = Logger.getLogger(InternalLoadBalancerVMManagerImpl.class); static final private String _internalLbVmNamePrefix = "b"; private String _instance; @@ -151,6 +150,8 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements @Inject VMTemplateDao _templateDao; @Inject ResourceManager _resourceMgr; @Inject ConfigurationServer _configServer; + @Inject + ConfigDepot _configDepot; @Override public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, @@ -343,6 +344,13 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements public void prepareStop(VirtualMachineProfile profile) { } + static ConfigValue _networkLockTimeout; + static ConfigValue _routerTemplateXen; + static ConfigValue _routerTemplateKvm; + static ConfigValue _routerTemplateVmware; + static ConfigValue _routerTemplateHyperV; + static ConfigValue _routerTemplateLxc; + @Override public boolean configure(String name, Map params) throws ConfigurationException { final Map configs = _configDao.getConfiguration("AgentManager", params); @@ -351,6 +359,13 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements _instance = "DEFAULT"; } + _networkLockTimeout = _configDepot.get(NetworkOrchestrationService.NetworkLockTimeout); + _routerTemplateXen = _configDepot.get(VirtualNetworkApplianceManager.RouterTemplateXen); + _routerTemplateKvm = _configDepot.get(VirtualNetworkApplianceManager.RouterTemplateKvm); + _routerTemplateVmware = _configDepot.get(VirtualNetworkApplianceManager.RouterTemplateVmware); + _routerTemplateHyperV = _configDepot.get(VirtualNetworkApplianceManager.RouterTemplateHyperV); + _routerTemplateLxc = _configDepot.get(VirtualNetworkApplianceManager.RouterTemplateLxc); + _mgmtHost = configs.get("host"); _mgmtCidr = _configDao.getValue(Config.ManagementNetwork.key()); @@ -587,7 +602,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements InsufficientCapacityException, ResourceUnavailableException { List internalLbVms = new ArrayList(); - Network lock = _networkDao.acquireInLockTable(guestNetwork.getId(), _ntwkMgr.getNetworkLockTimeout()); + Network lock = _networkDao.acquireInLockTable(guestNetwork.getId(), _networkLockTimeout.value()); if (lock == null) { throw new ConcurrentOperationException("Unable to lock network " + guestNetwork.getId()); } @@ -740,19 +755,19 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements } String templateName = null; switch (hType) { case XenServer: - templateName = _configServer.getConfigValue(Config.RouterTemplateXen.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); + templateName = _routerTemplateXen.valueIn(dest.getDataCenter().getId()); break; case KVM: - templateName = _configServer.getConfigValue(Config.RouterTemplateKVM.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); + templateName = _routerTemplateKvm.valueIn(dest.getDataCenter().getId()); break; case VMware: - templateName = _configServer.getConfigValue(Config.RouterTemplateVmware.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); + templateName = _routerTemplateVmware.valueIn(dest.getDataCenter().getId()); break; case Hyperv: - templateName = _configServer.getConfigValue(Config.RouterTemplateHyperv.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); + templateName = _routerTemplateHyperV.valueIn(dest.getDataCenter().getId()); break; case LXC: - templateName = _configServer.getConfigValue(Config.RouterTemplateLXC.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); + templateName = _routerTemplateLxc.valueIn(dest.getDataCenter().getId()); break; default: break; } diff --git a/plugins/network-elements/ovs/src/com/cloud/network/guru/OvsGuestNetworkGuru.java b/plugins/network-elements/ovs/src/com/cloud/network/guru/OvsGuestNetworkGuru.java index 34246ddefc4..61ab27234ce 100644 --- a/plugins/network-elements/ovs/src/com/cloud/network/guru/OvsGuestNetworkGuru.java +++ b/plugins/network-elements/ovs/src/com/cloud/network/guru/OvsGuestNetworkGuru.java @@ -19,10 +19,7 @@ package com.cloud.network.guru; import javax.ejb.Local; import javax.inject.Inject; -import com.cloud.event.ActionEventUtils; - import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; import org.apache.cloudstack.context.CallContext; @@ -30,6 +27,7 @@ import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter.NetworkType; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; +import com.cloud.event.ActionEventUtils; import com.cloud.event.EventTypes; import com.cloud.event.EventVO; import com.cloud.exception.InsufficientVirtualNetworkCapcityException; @@ -45,7 +43,6 @@ import com.cloud.offering.NetworkOffering; import com.cloud.user.Account; import com.cloud.vm.ReservationContext; -@Component @Local(value=NetworkGuru.class) public class OvsGuestNetworkGuru extends GuestNetworkGuru { private static final Logger s_logger = Logger.getLogger(OvsGuestNetworkGuru.class); @@ -73,7 +70,7 @@ public class OvsGuestNetworkGuru extends GuestNetworkGuru { + NetworkType.Advanced); return false; } - } + } @Override public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) { @@ -82,7 +79,7 @@ public class OvsGuestNetworkGuru extends GuestNetworkGuru { return null; } - NetworkVO config = (NetworkVO) super.design(offering, plan, userSpecified, owner); + NetworkVO config = (NetworkVO) super.design(offering, plan, userSpecified, owner); if (config == null) { return null; } @@ -96,8 +93,7 @@ public class OvsGuestNetworkGuru extends GuestNetworkGuru { protected void allocateVnet(Network network, NetworkVO implemented, long dcId, long physicalNetworkId, String reservationId) throws InsufficientVirtualNetworkCapcityException { if (network.getBroadcastUri() == null) { - String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId, - canUseSystemGuestVlan(network.getAccountId())); + String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId, _useSystemGuestVlans.valueIn(network.getAccountId())); if (vnet == null) { throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a part of network " + network + " implement ", DataCenter.class, dcId); } @@ -114,7 +110,7 @@ public class OvsGuestNetworkGuru extends GuestNetworkGuru { if (!_ovsTunnelMgr.isOvsTunnelEnabled()) { return null; } - NetworkVO implemented = (NetworkVO)super.implement(config, offering, dest, context); + NetworkVO implemented = (NetworkVO)super.implement(config, offering, dest, context); return implemented; } diff --git a/server/src/com/cloud/agent/manager/AgentMonitorService.java b/server/src/com/cloud/agent/manager/AgentMonitorService.java deleted file mode 100644 index 4dd2c1ef28e..00000000000 --- a/server/src/com/cloud/agent/manager/AgentMonitorService.java +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.agent.manager; - -import com.cloud.agent.Listener; - -public interface AgentMonitorService extends Listener { - - public Long getAgentPingTime(long agentId); - public void pingBy(long agentId); - public void signalStop(); -} diff --git a/server/src/com/cloud/alert/AlertManagerImpl.java b/server/src/com/cloud/alert/AlertManagerImpl.java index 944b250fbee..5494ec1face 100755 --- a/server/src/com/cloud/alert/AlertManagerImpl.java +++ b/server/src/com/cloud/alert/AlertManagerImpl.java @@ -38,13 +38,20 @@ import javax.mail.URLName; import javax.mail.internet.InternetAddress; import javax.naming.ConfigurationException; +import org.apache.log4j.Logger; + +import com.sun.mail.smtp.SMTPMessage; +import com.sun.mail.smtp.SMTPSSLTransport; +import com.sun.mail.smtp.SMTPTransport; + +import org.apache.cloudstack.framework.config.ConfigDepot; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.ConfigValue; +import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - import com.cloud.alert.dao.AlertDao; import com.cloud.api.ApiDBUtils; import com.cloud.capacity.Capacity; @@ -67,25 +74,17 @@ import com.cloud.dc.dao.HostPodDao; import com.cloud.event.AlertGenerator; import com.cloud.host.Host; import com.cloud.host.HostVO; -import com.cloud.host.dao.HostDao; import com.cloud.network.dao.IPAddressDao; import com.cloud.org.Grouping.AllocationState; import com.cloud.resource.ResourceManager; -import com.cloud.server.ConfigurationServer; import com.cloud.storage.StorageManager; -import com.cloud.storage.dao.VolumeDao; import com.cloud.utils.NumbersUtil; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.db.DB; import com.cloud.utils.db.SearchCriteria; -import com.sun.mail.smtp.SMTPMessage; -import com.sun.mail.smtp.SMTPSSLTransport; -import com.sun.mail.smtp.SMTPTransport; - -@Component @Local(value={AlertManager.class}) -public class AlertManagerImpl extends ManagerBase implements AlertManager { +public class AlertManagerImpl extends ManagerBase implements AlertManager, Configurable { private static final Logger s_logger = Logger.getLogger(AlertManagerImpl.class.getName()); private static final Logger s_alertsLogger = Logger.getLogger("org.apache.cloudstack.alerts"); @@ -96,31 +95,30 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { private EmailAlert _emailAlert; @Inject private AlertDao _alertDao; - @Inject private HostDao _hostDao; @Inject protected StorageManager _storageMgr; @Inject protected CapacityManager _capacityMgr; @Inject private CapacityDao _capacityDao; @Inject private DataCenterDao _dcDao; @Inject private HostPodDao _podDao; @Inject private ClusterDao _clusterDao; - @Inject private VolumeDao _volumeDao; @Inject private IPAddressDao _publicIPAddressDao; @Inject private DataCenterIpAddressDao _privateIPAddressDao; @Inject private PrimaryDataStoreDao _storagePoolDao; @Inject private ConfigurationDao _configDao; @Inject private ResourceManager _resourceMgr; @Inject private ConfigurationManager _configMgr; - @Inject ConfigurationServer _configServer; + @Inject + protected ConfigDepot _configDepot; + private Timer _timer = null; - private float _cpuOverProvisioningFactor = 1; private long _capacityCheckPeriod = 60L * 60L * 1000L; // one hour by default - private double _memoryCapacityThreshold = 0.75; - private double _cpuCapacityThreshold = 0.75; - private double _storageCapacityThreshold = 0.75; - private double _storageAllocCapacityThreshold = 0.75; + private ConfigValue _memoryCapacityThreshold; + private ConfigValue _cpuCapacityThreshold; + private ConfigValue _storageCapacityThreshold; + private ConfigValue _storageAllocCapacityThreshold; private double _publicIPCapacityThreshold = 0.75; private double _privateIPCapacityThreshold = 0.75; - private double _secondaryStorageCapacityThreshold = 0.75; + private double _secondaryStorageCapacityThreshold = 0.75; private double _vlanCapacityThreshold = 0.75; private double _directNetworkPublicIpCapacityThreshold = 0.75; private double _localStorageCapacityThreshold = 0.75; @@ -152,11 +150,6 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { _emailAlert = new EmailAlert(emailAddresses, smtpHost, smtpPort, useAuth, smtpUsername, smtpPassword, emailSender, smtpDebug); - - String storageCapacityThreshold = _configDao.getValue(Config.StorageCapacityThreshold.key()); - String cpuCapacityThreshold = _configDao.getValue(Config.CPUCapacityThreshold.key()); - String memoryCapacityThreshold = _configDao.getValue(Config.MemoryCapacityThreshold.key()); - String storageAllocCapacityThreshold = _configDao.getValue(Config.StorageAllocatedCapacityThreshold.key()); String publicIPCapacityThreshold = _configDao.getValue(Config.PublicIpCapacityThreshold.key()); String privateIPCapacityThreshold = _configDao.getValue(Config.PrivateIpCapacityThreshold.key()); String secondaryStorageCapacityThreshold = _configDao.getValue(Config.SecondaryStorageCapacityThreshold.key()); @@ -164,18 +157,11 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { String directNetworkPublicIpCapacityThreshold = _configDao.getValue(Config.DirectNetworkPublicIpCapacityThreshold.key()); String localStorageCapacityThreshold = _configDao.getValue(Config.LocalStorageCapacityThreshold.key()); - if (storageCapacityThreshold != null) { - _storageCapacityThreshold = Double.parseDouble(storageCapacityThreshold); - } - if (storageAllocCapacityThreshold != null) { - _storageAllocCapacityThreshold = Double.parseDouble(storageAllocCapacityThreshold); - } - if (cpuCapacityThreshold != null) { - _cpuCapacityThreshold = Double.parseDouble(cpuCapacityThreshold); - } - if (memoryCapacityThreshold != null) { - _memoryCapacityThreshold = Double.parseDouble(memoryCapacityThreshold); - } + _storageCapacityThreshold = _configDepot.get(StorageCapacityThreshold); + _cpuCapacityThreshold = _configDepot.get(CPUCapacityThreshold); + _memoryCapacityThreshold = _configDepot.get(MemoryCapacityThreshold); + _storageAllocCapacityThreshold = _configDepot.get(StorageAllocatedCapacityThreshold); + if (publicIPCapacityThreshold != null) { _publicIPCapacityThreshold = Double.parseDouble(publicIPCapacityThreshold); } @@ -195,10 +181,6 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { _localStorageCapacityThreshold = Double.parseDouble(localStorageCapacityThreshold); } - _capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_STORAGE, _storageCapacityThreshold); - _capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, _storageAllocCapacityThreshold); - _capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_CPU, _cpuCapacityThreshold); - _capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_MEMORY, _memoryCapacityThreshold); _capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP, _publicIPCapacityThreshold); _capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_PRIVATE_IP, _privateIPCapacityThreshold); _capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_SECONDARY_STORAGE, _secondaryStorageCapacityThreshold); @@ -214,14 +196,6 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { _capacityCheckPeriod = Long.parseLong(Config.CapacityCheckPeriod.getDefaultValue()); } - String cpuOverProvisioningFactorStr = configs.get("cpu.overprovisioning.factor"); - if (cpuOverProvisioningFactorStr != null) { - _cpuOverProvisioningFactor = NumbersUtil.parseFloat(cpuOverProvisioningFactorStr,1); - if(_cpuOverProvisioningFactor < 1){ - _cpuOverProvisioningFactor = 1; - } - } - _timer = new Timer("CapacityChecker"); return true; @@ -336,7 +310,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { // than this model right now, so when a VM is started, we update the amount allocated, and when a VM // is stopped we updated the amount allocated, and when VM sync reports a changed state, we update // the amount allocated. Hopefully it's limited to 3 entry points and will keep the amount allocated - // per host accurate. + // per host accurate. try { @@ -347,7 +321,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { // Calculate CPU and RAM capacities // get all hosts...even if they are not in 'UP' state - List hosts = _resourceMgr.listAllNotInMaintenanceHostsInOneZone(Host.Type.Routing, null); + List hosts = _resourceMgr.listAllNotInMaintenanceHostsInOneZone(Host.Type.Routing, null); for (HostVO host : hosts) { _capacityMgr.updateCapacityForHost(host); } @@ -377,13 +351,13 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { long dcId = datacenter.getId(); //NOTE - //What happens if we have multiple vlans? Dashboard currently shows stats + //What happens if we have multiple vlans? Dashboard currently shows stats //with no filter based on a vlan //ideal way would be to remove out the vlan param, and filter only on dcId //implementing the same // Calculate new Public IP capacity for Virtual Network - if (datacenter.getNetworkType() == NetworkType.Advanced){ + if (datacenter.getNetworkType() == NetworkType.Advanced){ createOrUpdateIpCapacity(dcId, null, CapacityVO.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP, datacenter.getAllocationState()); } @@ -394,7 +368,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { //Calculate VLAN's capacity createOrUpdateVlanCapacity(dcId, datacenter.getAllocationState()); } - } + } if (s_logger.isDebugEnabled()) { s_logger.debug("Done capacity updates for public ip and Vlans"); @@ -415,7 +389,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { s_logger.debug("Done recalculating system capacity"); } - } catch (Throwable t) { + } catch (Throwable t) { s_logger.error("Caught exception in recalculating capacity", t); } } @@ -439,14 +413,14 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { CapacityVO newVlanCapacity = new CapacityVO(null, dcId, null, null, allocatedVlans, totalVlans, Capacity.CAPACITY_TYPE_VLAN); if (capacityState == AllocationState.Disabled){ newVlanCapacity.setCapacityState(CapacityState.Disabled); - } + } _capacityDao.persist(newVlanCapacity); - }else if ( !(capacities.get(0).getUsedCapacity() == allocatedVlans + }else if ( !(capacities.get(0).getUsedCapacity() == allocatedVlans && capacities.get(0).getTotalCapacity() == totalVlans) ){ CapacityVO capacity = capacities.get(0); capacity.setUsedCapacity(allocatedVlans); capacity.setTotalCapacity(totalVlans); - _capacityDao.update(capacity.getId(), capacity); + _capacityDao.update(capacity.getId(), capacity); } @@ -479,9 +453,9 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { CapacityVO newPublicIPCapacity = new CapacityVO(null, dcId, podId, null, allocatedIPs, totalIPs, capacityType); if (capacityState == AllocationState.Disabled){ newPublicIPCapacity.setCapacityState(CapacityState.Disabled); - } + } _capacityDao.persist(newPublicIPCapacity); - }else if ( !(capacities.get(0).getUsedCapacity() == allocatedIPs + }else if ( !(capacities.get(0).getUsedCapacity() == allocatedIPs && capacities.get(0).getTotalCapacity() == totalIPs) ){ CapacityVO capacity = capacities.get(0); capacity.setUsedCapacity(allocatedIPs); @@ -504,19 +478,6 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { } } - private float getOverProvisioningFactor(long clusterId, short capacityType) { - float overProvisioinigFactor = 1f; - switch (capacityType) { - case Capacity.CAPACITY_TYPE_CPU: - overProvisioinigFactor = Float.parseFloat(_configServer.getConfigValue(Config.CPUOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), clusterId)); - break; - case Capacity.CAPACITY_TYPE_MEMORY: - overProvisioinigFactor = Float.parseFloat(_configServer.getConfigValue(Config.MemOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), clusterId)); - break; - } - return overProvisioinigFactor; - } - public void checkForAlerts(){ recalculateCapacity(); @@ -531,9 +492,9 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { List clusterList = _clusterDao.listAll(); List podList = _podDao.listAll(); //Get capacity types at different levels - List dataCenterCapacityTypes = getCapacityTypesAtZoneLevel(); - List podCapacityTypes = getCapacityTypesAtPodLevel(); - List clusterCapacityTypes = getCapacityTypesAtClusterLevel(); + List dataCenterCapacityTypes = getCapacityTypesAtZoneLevel(); + List podCapacityTypes = getCapacityTypesAtPodLevel(); + List clusterCapacityTypes = getCapacityTypesAtClusterLevel(); // Generate Alerts for Zone Level capacities for(DataCenterVO dc : dataCenterList){ @@ -547,7 +508,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { if (capacity == null || capacity.size() == 0){ continue; } - double totalCapacity = capacity.get(0).getTotalCapacity(); + double totalCapacity = capacity.get(0).getTotalCapacity(); double usedCapacity = capacity.get(0).getUsedCapacity(); if (totalCapacity != 0 && usedCapacity/totalCapacity > _capacityTypeThresholdMap.get(capacityType)){ generateEmailAlert(dc, null, null, totalCapacity, usedCapacity, capacityType); @@ -562,10 +523,10 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { if (capacity == null || capacity.size() == 0){ continue; } - double totalCapacity = capacity.get(0).getTotalCapacity(); + double totalCapacity = capacity.get(0).getTotalCapacity(); double usedCapacity = capacity.get(0).getUsedCapacity(); if (totalCapacity != 0 && usedCapacity/totalCapacity > _capacityTypeThresholdMap.get(capacityType)){ - generateEmailAlert(ApiDBUtils.findZoneById(pod.getDataCenterId()), pod, null, + generateEmailAlert(ApiDBUtils.findZoneById(pod.getDataCenterId()), pod, null, totalCapacity, usedCapacity, capacityType); } } @@ -582,16 +543,16 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { switch (capacityType) { case Capacity.CAPACITY_TYPE_STORAGE: capacity.add(getUsedStats(capacityType, cluster.getDataCenterId(), cluster.getPodId(), cluster.getId())); - threshold = Double.parseDouble(_configServer.getConfigValue(Config.StorageCapacityThreshold.key(), Config.ConfigurationParameterScope.cluster.toString(), cluster.getId())); + threshold = _storageCapacityThreshold.valueIn(cluster.getId()); break; case Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED: - threshold = Double.parseDouble(_configServer.getConfigValue(Config.StorageAllocatedCapacityThreshold.key(), Config.ConfigurationParameterScope.cluster.toString(), cluster.getId())); + threshold = _storageAllocCapacityThreshold.valueIn(cluster.getId()); break; case Capacity.CAPACITY_TYPE_CPU: - threshold = Double.parseDouble(_configServer.getConfigValue(Config.CPUCapacityThreshold.key(), Config.ConfigurationParameterScope.cluster.toString(), cluster.getId())); + threshold = _cpuCapacityThreshold.valueIn(cluster.getId()); break; case Capacity.CAPACITY_TYPE_MEMORY: - threshold = Double.parseDouble(_configServer.getConfigValue(Config.MemoryCapacityThreshold.key(), Config.ConfigurationParameterScope.cluster.toString(), cluster.getId())); + threshold = _memoryCapacityThreshold.valueIn(cluster.getId()); break; default: threshold = _capacityTypeThresholdMap.get(capacityType); @@ -619,7 +580,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { capacity = _storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId); } if (capacity != null){ - return new SummedCapacity(capacity.getUsedCapacity(), 0, capacity.getTotalCapacity(), capacityType, clusterId, podId); + return new SummedCapacity(capacity.getUsedCapacity(), 0, capacity.getTotalCapacity(), capacityType, clusterId, podId); }else{ return null; } @@ -676,8 +637,8 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { alertType = ALERT_TYPE_LOCAL_STORAGE; break; - //Pod Level - case CapacityVO.CAPACITY_TYPE_PRIVATE_IP: + //Pod Level + case CapacityVO.CAPACITY_TYPE_PRIVATE_IP: msgSubject = "System Alert: Number of unallocated private IPs is low in pod " +pod.getName()+ " of availability zone " + dc.getName(); totalStr = Double.toString(totalCapacity); usedStr = Double.toString(usedCapacity); @@ -686,7 +647,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { break; //Zone Level - case CapacityVO.CAPACITY_TYPE_SECONDARY_STORAGE: + case CapacityVO.CAPACITY_TYPE_SECONDARY_STORAGE: msgSubject = "System Alert: Low Available Secondary Storage in availability zone " + dc.getName(); totalStr = formatBytesToMegabytes(totalCapacity); usedStr = formatBytesToMegabytes(usedCapacity); @@ -723,7 +684,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { } _emailAlert.sendAlert(alertType, dc.getId(), podId, clusterId, msgSubject, msgContent); } catch (Exception ex) { - s_logger.error("Exception in CapacityChecker", ex); + s_logger.error("Exception in CapacityChecker", ex); } } @@ -741,7 +702,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { private List getCapacityTypesAtPodLevel(){ List podCapacityTypes = new ArrayList(); - podCapacityTypes.add(Capacity.CAPACITY_TYPE_PRIVATE_IP); + podCapacityTypes.add(Capacity.CAPACITY_TYPE_PRIVATE_IP); return podCapacityTypes; } @@ -897,4 +858,14 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { double megaBytes = (bytes / (1024 * 1024)); return _dfWhole.format(megaBytes); } + + @Override + public String getConfigComponentName() { + return AlertManager.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[] {CPUCapacityThreshold, MemoryCapacityThreshold, StorageAllocatedCapacityThreshold, StorageCapacityThreshold}; + } } diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 7e36f7524d1..6539289dd4a 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -103,6 +103,7 @@ import com.cloud.api.query.vo.TemplateJoinVO; import com.cloud.api.query.vo.UserAccountJoinVO; import com.cloud.api.query.vo.UserVmJoinVO; import com.cloud.api.query.vo.VolumeJoinVO; +import com.cloud.capacity.CapacityManager; import com.cloud.capacity.CapacityVO; import com.cloud.capacity.dao.CapacityDao; import com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity; @@ -1047,7 +1048,7 @@ public class ApiDBUtils { } public static float getCpuOverprovisioningFactor() { - String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key()); + String opFactor = _configDao.getValue(CapacityManager.CpuOverprovisioningFactorCK); float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1); return cpuOverprovisioningFactor; } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 8d01274f501..1ad0eab8a2a 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -842,7 +842,6 @@ public class ApiResponseHelper implements ResponseGenerator { public static List getDataCenterCapacityResponse(Long zoneId) { List capacities = ApiDBUtils.getCapacityByClusterPodZone(zoneId, null, null); Set capacityResponses = new HashSet(); - float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor(); for (SummedCapacity capacity : capacities) { CapacityResponse capacityResponse = new CapacityResponse(); diff --git a/server/src/com/cloud/capacity/CapacityManagerImpl.java b/server/src/com/cloud/capacity/CapacityManagerImpl.java index f4bc62d1275..348021c2efd 100755 --- a/server/src/com/cloud/capacity/CapacityManagerImpl.java +++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java @@ -28,8 +28,9 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.messagebus.MessageBus; import org.apache.cloudstack.framework.messagebus.PublishScope; @@ -71,7 +72,6 @@ import com.cloud.storage.VMTemplateVO; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.VMTemplatePoolDao; import com.cloud.storage.dao.VolumeDao; -import com.cloud.uservm.UserVm; import com.cloud.utils.DateUtil; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; @@ -83,27 +83,18 @@ import com.cloud.utils.db.Transaction; import com.cloud.utils.fsm.StateListener; import com.cloud.vm.UserVmDetailVO; import com.cloud.vm.UserVmVO; -import com.cloud.vm.UserVmDetailVO; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.Event; import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.UserVmDetailsDao; -import com.cloud.vm.dao.UserVmDetailsDao; import com.cloud.vm.dao.VMInstanceDao; -import com.cloud.vm.snapshot.VMSnapshot; -import com.cloud.vm.snapshot.VMSnapshotVO; import com.cloud.vm.snapshot.dao.VMSnapshotDao; -import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; - -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -@Component @Local(value = CapacityManager.class) -public class CapacityManagerImpl extends ManagerBase implements CapacityManager, StateListener, Listener, ResourceListener { +public class CapacityManagerImpl extends ManagerBase implements CapacityManager, StateListener, Listener, ResourceListener, + Configurable { private static final Logger s_logger = Logger.getLogger(CapacityManagerImpl.class); @Inject CapacityDao _capacityDao; @@ -932,4 +923,14 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager, } return false; } + + @Override + public String getConfigComponentName() { + return CapacityManager.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[] {CpuOverprovisioningFactor, MemOverprovisioningFactor}; + } } diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index f7c599221c6..cde8b03ae62 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -23,6 +23,7 @@ import java.util.StringTokenizer; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; +import org.apache.cloudstack.framework.config.ConfigKey; import com.cloud.agent.AgentManager; import com.cloud.consoleproxy.ConsoleProxyManager; @@ -50,25 +51,21 @@ public enum Config { AlertSMTPUseAuth("Alert", ManagementServer.class, String.class, "alert.smtp.useAuth", null, "If true, use SMTP authentication when sending emails.", null), AlertSMTPUsername("Alert", ManagementServer.class, String.class, "alert.smtp.username", null, "Username for SMTP authentication (applies only if alert.smtp.useAuth is true).", null), CapacityCheckPeriod("Alert", ManagementServer.class, Integer.class, "capacity.check.period", "300000", "The interval in milliseconds between capacity checks", null), - StorageAllocatedCapacityThreshold("Alert", ManagementServer.class, Float.class, "cluster.storage.allocated.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of allocated storage utilization above which alerts will be sent about low storage available.", null, ConfigurationParameterScope.cluster.toString()), - StorageCapacityThreshold("Alert", ManagementServer.class, Float.class, "cluster.storage.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of storage utilization above which alerts will be sent about low storage available.", null, ConfigurationParameterScope.cluster.toString()), - CPUCapacityThreshold("Alert", ManagementServer.class, Float.class, "cluster.cpu.allocated.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of cpu utilization above which alerts will be sent about low cpu available.", null, ConfigurationParameterScope.cluster.toString()), - MemoryCapacityThreshold("Alert", ManagementServer.class, Float.class, "cluster.memory.allocated.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of memory utilization above which alerts will be sent about low memory available.", null, ConfigurationParameterScope.cluster.toString()), PublicIpCapacityThreshold("Alert", ManagementServer.class, Float.class, "zone.virtualnetwork.publicip.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of public IP address space utilization above which alerts will be sent.", null), PrivateIpCapacityThreshold("Alert", ManagementServer.class, Float.class, "pod.privateip.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of private IP address space utilization above which alerts will be sent.", null), SecondaryStorageCapacityThreshold("Alert", ManagementServer.class, Float.class, "zone.secstorage.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of secondary storage utilization above which alerts will be sent about low storage available.", null), VlanCapacityThreshold("Alert", ManagementServer.class, Float.class, "zone.vlan.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of Zone Vlan utilization above which alerts will be sent about low number of Zone Vlans.", null), DirectNetworkPublicIpCapacityThreshold("Alert", ManagementServer.class, Float.class, "zone.directnetwork.publicip.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of Direct Network Public Ip Utilization above which alerts will be sent about low number of direct network public ips.", null), LocalStorageCapacityThreshold("Alert", ManagementServer.class, Float.class, "cluster.localStorage.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of local storage utilization above which alerts will be sent about low local storage available.", null), - StorageAllocatedCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "pool.storage.allocated.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of allocated storage utilization above which allocators will disable using the pool for low allocated storage available.", null, ConfigurationParameterScope.zone.toString()), - StorageCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "pool.storage.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of storage utilization above which allocators will disable using the pool for low storage available.", null, ConfigurationParameterScope.zone.toString()), - CPUCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "cluster.cpu.allocated.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of cpu utilization above which allocators will disable using the cluster for low cpu available. Keep the corresponding notification threshold lower than this to be notified beforehand.", null, ConfigurationParameterScope.cluster.toString()), - MemoryCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "cluster.memory.allocated.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of memory utilization above which allocators will disable using the cluster for low memory available. Keep the corresponding notification threshold lower than this to be notified beforehand.", null, ConfigurationParameterScope.cluster.toString()), + StorageAllocatedCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "pool.storage.allocated.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of allocated storage utilization above which allocators will disable using the pool for low allocated storage available.", null, ConfigKey.Scope.Zone.toString()), + StorageCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "pool.storage.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of storage utilization above which allocators will disable using the pool for low storage available.", null, ConfigKey.Scope.Zone.toString()), + CPUCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "cluster.cpu.allocated.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of cpu utilization above which allocators will disable using the cluster for low cpu available. Keep the corresponding notification threshold lower than this to be notified beforehand.", null, ConfigKey.Scope.Cluster.toString()), + MemoryCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "cluster.memory.allocated.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of memory utilization above which allocators will disable using the cluster for low memory available. Keep the corresponding notification threshold lower than this to be notified beforehand.", null, ConfigKey.Scope.Cluster.toString()), // Storage - StorageOverprovisioningFactor("Storage", StoragePoolAllocator.class, String.class, "storage.overprovisioning.factor", "2", "Used for storage overprovisioning calculation; available storage will be (actualStorageSize * storage.overprovisioning.factor)", null, ConfigurationParameterScope.zone.toString()), + StorageOverprovisioningFactor("Storage", StoragePoolAllocator.class, String.class, "storage.overprovisioning.factor", "2", "Used for storage overprovisioning calculation; available storage will be (actualStorageSize * storage.overprovisioning.factor)", null, ConfigKey.Scope.Zone.toString()), StorageStatsInterval("Storage", ManagementServer.class, String.class, "storage.stats.interval", "60000", "The interval (in milliseconds) when storage stats (per host) are retrieved from agents.", null), MaxVolumeSize("Storage", ManagementServer.class, Integer.class, "storage.max.volume.size", "2000", "The maximum size for a volume (in GB).", null), StorageCacheReplacementLRUTimeInterval("Storage", ManagementServer.class, Integer.class, "storage.cache.replacement.lru.interval", "30", "time interval for unused data on cache storage (in days).", null), @@ -96,13 +93,10 @@ public enum Config { GuestVlanBits("Network", ManagementServer.class, Integer.class, "guest.vlan.bits", "12", "The number of bits to reserve for the VLAN identifier in the guest subnet.", null), //MulticastThrottlingRate("Network", ManagementServer.class, Integer.class, "multicast.throttling.rate", "10", "Default multicast rate in megabits per second allowed.", null), - NetworkThrottlingRate("Network", ManagementServer.class, Integer.class, "network.throttling.rate", "200", "Default data transfer rate in megabits per second allowed in network.", null, ConfigurationParameterScope.zone.toString()), - GuestDomainSuffix("Network", AgentManager.class, String.class, "guest.domain.suffix", "cloud.internal", "Default domain name for vms inside virtualized networks fronted by router", null, ConfigurationParameterScope.zone.toString()), DirectNetworkNoDefaultRoute("Network", ManagementServer.class, Boolean.class, "direct.network.no.default.route", "false", "Direct Network Dhcp Server should not send a default route", "true/false"), OvsTunnelNetwork("Network", ManagementServer.class, Boolean.class, "sdn.ovs.controller", "false", "Enable/Disable Open vSwitch SDN controller for L2-in-L3 overlay networks", null), OvsTunnelNetworkDefaultLabel("Network", ManagementServer.class, String.class, "sdn.ovs.controller.default.label", "cloud-public", "Default network label to be used when fetching interface for GRE endpoints", null), VmNetworkThrottlingRate("Network", ManagementServer.class, Integer.class, "vm.network.throttling.rate", "200", "Default data transfer rate in megabits per second allowed in User vm's default network.", null), - NetworkLockTimeout("Network", ManagementServer.class, Integer.class, "network.lock.timeout", "600", "Lock wait timeout (seconds) while implementing network", null), SecurityGroupWorkCleanupInterval("Network", ManagementServer.class, Integer.class, "network.securitygroups.work.cleanup.interval", "120", "Time interval (seconds) in which finished work is cleaned up from the work table", null), SecurityGroupWorkerThreads("Network", ManagementServer.class, Integer.class, "network.securitygroups.workers.pool.size", "50", "Number of worker threads processing the security group update work queue", null), @@ -115,7 +109,6 @@ public enum Config { //VPN RemoteAccessVpnPskLength("Network", AgentManager.class, Integer.class, "remote.access.vpn.psk.length", "24", "The length of the ipsec preshared key (minimum 8, maximum 256)", null), - RemoteAccessVpnClientIpRange("Network", AgentManager.class, String.class, "remote.access.vpn.client.iprange", "10.1.2.1-10.1.2.8", "The range of ips to be allocated to remote access vpn clients. The first ip in the range is used by the VPN server", null, ConfigurationParameterScope.account.toString()), RemoteAccessVpnUserLimit("Network", AgentManager.class, String.class, "remote.access.vpn.user.limit", "8", "The maximum number of VPN users that can be created per account", null), Site2SiteVpnConnectionPerVpnGatewayLimit("Network", ManagementServer.class, Integer.class, "site2site.vpn.vpngateway.connection.limit", "4", "The maximum number of VPN connection per VPN gateway", null), Site2SiteVpnSubnetsPerCustomerGatewayLimit("Network", ManagementServer.class, Integer.class, "site2site.vpn.customergateway.subnets.limit", "10", "The maximum number of subnets per customer gateway", null), @@ -151,7 +144,6 @@ public enum Config { JobCancelThresholdMinutes("Advanced", ManagementServer.class, String.class, "job.cancel.threshold.minutes", "60", "Time (in minutes) for async-jobs to be forcely cancelled if it has been in process for long", null), EventPurgeInterval("Advanced", ManagementServer.class, Integer.class, "event.purge.interval", "86400", "The interval (in seconds) to wait before running the event purge thread", null), AccountCleanupInterval("Advanced", ManagementServer.class, Integer.class, "account.cleanup.interval", "86400", "The interval (in seconds) between cleanup for removed accounts", null), - AllowPublicUserTemplates("Advanced", ManagementServer.class, Integer.class, "allow.public.user.templates", "true", "If false, users will not be able to create public templates.", null, ConfigurationParameterScope.account.toString()), InstanceName("Advanced", AgentManager.class, String.class, "instance.name", "VM", "Name of the deployment instance.", "instanceName"), ExpungeDelay("Advanced", UserVmManager.class, Integer.class, "expunge.delay", "86400", "Determines how long (in seconds) to wait before actually expunging destroyed vm. The default value = the default value of expunge.interval", null), ExpungeInterval("Advanced", UserVmManager.class, Integer.class, "expunge.interval", "86400", "The interval (in seconds) to wait before running the expunge thread.", null), @@ -164,29 +156,20 @@ public enum Config { IntegrationAPIPort("Advanced", ManagementServer.class, Integer.class, "integration.api.port", null, "Defaul API port", null), InvestigateRetryInterval("Advanced", HighAvailabilityManager.class, Integer.class, "investigate.retry.interval", "60", "Time (in seconds) between VM pings when agent is disconnected", null), MigrateRetryInterval("Advanced", HighAvailabilityManager.class, Integer.class, "migrate.retry.interval", "120", "Time (in seconds) between migration retries", null), - ClusterDeltaSyncInterval("Advanced", AgentManager.class, Integer.class, "sync.interval", "60", "Cluster Delta sync interval in seconds", null), RouterCpuMHz("Advanced", NetworkOrchestrationService.class, Integer.class, "router.cpu.mhz", String.valueOf(VpcVirtualNetworkApplianceManager.DEFAULT_ROUTER_CPU_MHZ), "Default CPU speed (MHz) for router VM.", null), RestartRetryInterval("Advanced", HighAvailabilityManager.class, Integer.class, "restart.retry.interval", "600", "Time (in seconds) between retries to restart a vm", null), RouterStatsInterval("Advanced", NetworkOrchestrationService.class, Integer.class, "router.stats.interval", "300", "Interval (in seconds) to report router statistics.", null), ExternalNetworkStatsInterval("Advanced", NetworkOrchestrationService.class, Integer.class, "external.network.stats.interval", "300", "Interval (in seconds) to report external network statistics.", null), RouterCheckInterval("Advanced", NetworkOrchestrationService.class, Integer.class, "router.check.interval", "30", "Interval (in seconds) to report redundant router status.", null), RouterCheckPoolSize("Advanced", NetworkOrchestrationService.class, Integer.class, "router.check.poolsize", "10", "Numbers of threads using to check redundant router status.", null), - RouterTemplateXen("Advanced", NetworkOrchestrationService.class, String.class, "router.template.xen", "SystemVM Template (XenServer)", "Name of the default router template on Xenserver.", null, ConfigurationParameterScope.zone.toString()), - RouterTemplateKVM("Advanced", NetworkOrchestrationService.class, String.class, "router.template.kvm", "SystemVM Template (KVM)", "Name of the default router template on KVM.", null, ConfigurationParameterScope.zone.toString()), - RouterTemplateVmware("Advanced", NetworkOrchestrationService.class, String.class, "router.template.vmware", "SystemVM Template (vSphere)", "Name of the default router template on Vmware.", null, ConfigurationParameterScope.zone.toString()), - RouterTemplateHyperv("Advanced", NetworkOrchestrationService.class, String.class, "router.template.hyperv", "SystemVM Template (HyperV)", "Name of the default router template on Hyperv.", null, ConfigurationParameterScope.zone.toString()), - RouterTemplateLXC("Advanced", NetworkOrchestrationService.class, String.class, "router.template.lxc", "SystemVM Template (LXC)", "Name of the default router template on LXC.", null, ConfigurationParameterScope.zone.toString()), RouterExtraPublicNics("Advanced", NetworkOrchestrationService.class, Integer.class, "router.extra.public.nics", "2", "specify extra public nics used for virtual router(up to 5)", "0-5"), - StartRetry("Advanced", AgentManager.class, Integer.class, "start.retry", "10", "Number of times to retry create and start commands", null), - EnableDynamicallyScaleVm("Advanced", ManagementServer.class, Boolean.class, "enable.dynamic.scale.vm", "false", "Enables/Diables dynamically scaling a vm", null, ConfigurationParameterScope.zone.toString()), ScaleRetry("Advanced", ManagementServer.class, Integer.class, "scale.retry", "2", "Number of times to retry scaling up the vm", null), StopRetryInterval("Advanced", HighAvailabilityManager.class, Integer.class, "stop.retry.interval", "600", "Time in seconds between retries to stop or destroy a vm" , null), StorageCleanupInterval("Advanced", StorageManager.class, Integer.class, "storage.cleanup.interval", "86400", "The interval (in seconds) to wait before running the storage cleanup thread.", null), StorageCleanupEnabled("Advanced", StorageManager.class, Boolean.class, "storage.cleanup.enabled", "true", "Enables/disables the storage cleanup thread.", null), UpdateWait("Advanced", AgentManager.class, Integer.class, "update.wait", "600", "Time to wait (in seconds) before alerting on a updating agent", null), - Wait("Advanced", AgentManager.class, Integer.class, "wait", "1800", "Time in seconds to wait for control commands to return", null), XapiWait("Advanced", AgentManager.class, Integer.class, "xapiwait", "600", "Time (in seconds) to wait for XAPI to return", null), - MigrateWait("Advanced", AgentManager.class, Integer.class, "migratewait", "3600", "Time (in seconds) to wait for VM migrate finish", null), + MigrateWait("Advanced", AgentManager.class, Integer.class, "migratewait", "3600", "Time (in seconds) to wait for VM migrate finish", null), HAWorkers("Advanced", AgentManager.class, Integer.class, "ha.workers", "5", "Number of ha worker threads.", null), MountParent("Advanced", ManagementServer.class, String.class, "mount.parent", "/var/cloudstack/mnt", "The mount point on the Management Server for Secondary Storage.", null), // UpgradeURL("Advanced", ManagementServer.class, String.class, "upgrade.url", "http://example.com:8080/client/agent/update.zip", "The upgrade URL is the URL of the management server that agents will connect to in order to automatically upgrade.", null), @@ -194,8 +177,6 @@ public enum Config { SystemVMAutoReserveCapacity("Advanced", ManagementServer.class, Boolean.class, "system.vm.auto.reserve.capacity", "true", "Indicates whether or not to automatically reserver system VM standby capacity.", null), SystemVMDefaultHypervisor("Advanced", ManagementServer.class, String.class, "system.vm.default.hypervisor", null, "Hypervisor type used to create system vm", null), SystemVMRandomPassword("Advanced", ManagementServer.class, Boolean.class, "system.vm.random.password", "false", "Randomize system vm password the first time management server starts", null), - CPUOverprovisioningFactor("Advanced", ManagementServer.class, String.class, "cpu.overprovisioning.factor", "1", "Used for CPU overprovisioning calculation; available CPU will be (actualCpuCapacity * cpu.overprovisioning.factor)", null, ConfigurationParameterScope.cluster.toString()), - MemOverprovisioningFactor("Advanced", ManagementServer.class, String.class, "mem.overprovisioning.factor", "1", "Used for memory overprovisioning calculation", null, ConfigurationParameterScope.cluster.toString()), LinkLocalIpNums("Advanced", ManagementServer.class, Integer.class, "linkLocalIp.nums", "10", "The number of link local ip that needed by domR(in power of 2)", null), HypervisorList("Advanced", ManagementServer.class, String.class, "hypervisor.list", HypervisorType.Hyperv + "," + HypervisorType.KVM + "," + HypervisorType.XenServer + "," + HypervisorType.VMware + "," + HypervisorType.BareMetal + "," + HypervisorType.Ovm + "," + HypervisorType.LXC, "The list of hypervisors that this deployment will use.", "hypervisorList"), ManagementHostIPAdr("Advanced", ManagementServer.class, String.class, "host", "localhost", "The ip address of management server", null), @@ -213,15 +194,6 @@ public enum Config { AlertPurgeInterval("Advanced", ManagementServer.class, Integer.class, "alert.purge.interval", "86400", "The interval (in seconds) to wait before running the alert purge thread", null), AlertPurgeDelay("Advanced", ManagementServer.class, Integer.class, "alert.purge.delay", "0", "Alerts older than specified number days will be purged. Set this value to 0 to never delete alerts", null), HostReservationReleasePeriod("Advanced", ManagementServer.class, Integer.class, "host.reservation.release.period", "300000", "The interval in milliseconds between host reservation release checks", null), - UseSystemPublicIps("Advanced", ManagementServer.class, Boolean.class, "use.system.public.ips", "true", - "If true, when account has dedicated public ip range(s), once the ips dedicated to the account have been" + - " consumed ips will be acquired from the system pool", - null, ConfigurationParameterScope.account.toString()), - UseSystemGuestVlans("Advanced", ManagementServer.class, Boolean.class, "use.system.guest.vlans", "true", - "If true, when account has dedicated guest vlan range(s), once the vlans dedicated to the account have been" + - " consumed vlans will be allocated from the system pool", - null, ConfigurationParameterScope.account.toString()), - // LB HealthCheck Interval. LBHealthCheck("Advanced", ManagementServer.class, String.class, "healthcheck.update.interval", "600", "Time Interval to fetch the LB health check states (in sec)", null), @@ -235,7 +207,6 @@ public enum Config { VmStatsInterval("Advanced", ManagementServer.class, Integer.class, "vm.stats.interval", "60000", "The interval (in milliseconds) when vm stats are retrieved from agents.", null), VmDiskStatsInterval("Advanced", ManagementServer.class, Integer.class, "vm.disk.stats.interval", "0", "Interval (in seconds) to report vm disk statistics.", null), VmTransitionWaitInterval("Advanced", ManagementServer.class, Integer.class, "vm.tranisition.wait.interval", "3600", "Time (in seconds) to wait before taking over a VM in transition state", null), - VmDestroyForcestop("Advanced", ManagementServer.class, Boolean.class, "vm.destroy.forcestop", "false", "On destroy, force-stop takes this value ", null), VmDiskThrottlingIopsReadRate("Advanced", ManagementServer.class, Integer.class, "vm.disk.throttling.iops_read_rate", "0", "Default disk I/O read rate in requests per second allowed in User vm's disk.", null), VmDiskThrottlingIopsWriteRate("Advanced", ManagementServer.class, Integer.class, "vm.disk.throttling.iops_write_rate", "0", "Default disk I/O writerate in requests per second allowed in User vm's disk.", null), VmDiskThrottlingBytesReadRate("Advanced", ManagementServer.class, Integer.class, "vm.disk.throttling.bytes_read_rate", "0", "Default disk I/O read rate in bytes per second allowed in User vm's disk.", null), @@ -328,12 +299,6 @@ public enum Config { EncryptionIV("Hidden", ManagementServer.class, String.class, "security.encryption.iv", null, "base64 encoded IV data", null), RouterRamSize("Hidden", NetworkOrchestrationService.class, Integer.class, "router.ram.size", "128", "Default RAM for router VM (in MB).", null), - VmOpWaitInterval("Advanced", ManagementServer.class, Integer.class, "vm.op.wait.interval", "120", "Time (in seconds) to wait before checking if a previous operation has succeeded", null), - VmOpLockStateRetry("Advanced", ManagementServer.class, Integer.class, "vm.op.lock.state.retry", "5", "Times to retry locking the state of a VM for operations", "-1 means try forever"), - VmOpCleanupInterval("Advanced", ManagementServer.class, Long.class, "vm.op.cleanup.interval", "86400", "Interval to run the thread that cleans up the vm operations (in seconds)", "Seconds"), - VmOpCleanupWait("Advanced", ManagementServer.class, Long.class, "vm.op.cleanup.wait", "3600", "Time (in seconds) to wait before cleanuping up any vm work items", "Seconds"), - VmOpCancelInterval("Advanced", ManagementServer.class, Long.class, "vm.op.cancel.interval", "3600", "Time (in seconds) to wait before cancelling a operation", "Seconds"), - DefaultPageSize("Advanced", ManagementServer.class, Long.class, "default.page.size", "500", "Default page size for API list* commands", null), TaskCleanupRetryInterval("Advanced", ManagementServer.class, Integer.class, "task.cleanup.retry.interval", "600", "Time (in seconds) to wait before retrying cleanup of tasks if the cleanup failed previously. 0 means to never retry.", "Seconds"), @@ -355,7 +320,6 @@ public enum Config { //disabling lb as cluster sync does not work with distributed cluster SubDomainNetworkAccess("Advanced", NetworkOrchestrationService.class, Boolean.class, "allow.subdomain.network.access", "true", "Allow subdomains to use networks dedicated to their parent domain(s)", null), - UseExternalDnsServers("Advanced", NetworkOrchestrationService.class, Boolean.class, "use.external.dns", "false", "Bypass internal dns, use external dns1 and dns2", null, ConfigurationParameterScope.zone.toString()), EncodeApiResponse("Advanced", ManagementServer.class, Boolean.class, "encode.api.response", "false", "Do URL encoding for the api response, false by default", null), DnsBasicZoneUpdates("Advanced", NetworkOrchestrationService.class, String.class, "network.dns.basiczone.updates", "all", "This parameter can take 2 values: all (default) and pod. It defines if DHCP/DNS requests have to be send to all dhcp servers in cloudstack, or only to the one in the same pod", "all,pod"), @@ -436,8 +400,7 @@ public enum Config { CloudDnsName("Advanced", ManagementServer.class, String.class, "cloud.dns.name", null, "DNS name of the cloud for the GSLB service", null), BlacklistedRoutes("Advanced", VpcManager.class, String.class, "blacklisted.routes", null, "Routes that are blacklisted, can not be used for Static Routes creation for the VPC Private Gateway", - "routes", ConfigurationParameterScope.zone.toString()), - + "routes", ConfigKey.Scope.Zone.toString()), InternalLbVmServiceOfferingId("Advanced", ManagementServer.class, String.class, "internallbvm.service.offering", null, "Uuid of the service offering used by internal lb vm; if NULL - default system internal lb offering will be used", null), ExecuteInSequence("Advanced", ManagementServer.class, Boolean.class, "execute.in.sequence.hypervisor.commands", "false", "If set to true, StartCommand, StopCommand, CopyCommand will be synchronized on the agent side." + " If set to false, these commands become asynchronous. Default value is false.", null), @@ -455,21 +418,13 @@ public enum Config { private final String _range; private final String _scope; // Parameter can be at different levels (Zone/cluster/pool/account), by default every parameter is at global - public static enum ConfigurationParameterScope { - global, - zone, - cluster, - storagepool, - account - } - private static final HashMap> _scopeLevelConfigsMap = new HashMap>(); static { - _scopeLevelConfigsMap.put(ConfigurationParameterScope.zone.toString(), new ArrayList()); - _scopeLevelConfigsMap.put(ConfigurationParameterScope.cluster.toString(), new ArrayList()); - _scopeLevelConfigsMap.put(ConfigurationParameterScope.storagepool.toString(), new ArrayList()); - _scopeLevelConfigsMap.put(ConfigurationParameterScope.account.toString(), new ArrayList()); - _scopeLevelConfigsMap.put(ConfigurationParameterScope.global.toString(), new ArrayList()); + _scopeLevelConfigsMap.put(ConfigKey.Scope.Zone.toString(), new ArrayList()); + _scopeLevelConfigsMap.put(ConfigKey.Scope.Cluster.toString(), new ArrayList()); + _scopeLevelConfigsMap.put(ConfigKey.Scope.StoragePool.toString(), new ArrayList()); + _scopeLevelConfigsMap.put(ConfigKey.Scope.Account.toString(), new ArrayList()); + _scopeLevelConfigsMap.put(ConfigKey.Scope.Global.toString(), new ArrayList()); for (Config c : Config.values()) { //Creating group of parameters per each level (zone/cluster/pool/account) @@ -517,7 +472,7 @@ public enum Config { _defaultValue = defaultValue; _description = description; _range = range; - _scope = ConfigurationParameterScope.global.toString(); + _scope = ConfigKey.Scope.Global.toString(); } private Config(String category, Class componentClass, Class type, String name, String defaultValue, String description, String range, String scope) { _category = category; diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index d960c58166a..425937af46e 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -71,6 +71,8 @@ import org.apache.cloudstack.config.Configuration; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.ConfigValue; import org.apache.cloudstack.framework.config.ConfigurationVO; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.region.PortableIp; @@ -90,6 +92,7 @@ import org.apache.log4j.Logger; import com.cloud.alert.AlertManager; import com.cloud.api.ApiDBUtils; +import com.cloud.capacity.CapacityManager; import com.cloud.capacity.dao.CapacityDao; import com.cloud.configuration.Resource.ResourceType; import com.cloud.dc.AccountVlanMapVO; @@ -359,10 +362,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati private void weightBasedParametersForValidation() { weightBasedParametersForValidation = new HashSet(); - weightBasedParametersForValidation.add(Config.CPUCapacityThreshold.key()); - weightBasedParametersForValidation.add(Config.StorageAllocatedCapacityThreshold.key()); - weightBasedParametersForValidation.add(Config.StorageCapacityThreshold.key()); - weightBasedParametersForValidation.add(Config.MemoryCapacityThreshold.key()); + weightBasedParametersForValidation.add(AlertManager.CPUCapacityThreshold.key()); + weightBasedParametersForValidation.add(AlertManager.StorageAllocatedCapacityThreshold.key()); + weightBasedParametersForValidation.add(AlertManager.StorageCapacityThreshold.key()); + weightBasedParametersForValidation.add(AlertManager.MemoryCapacityThreshold.key()); weightBasedParametersForValidation.add(Config.PublicIpCapacityThreshold.key()); weightBasedParametersForValidation.add(Config.PrivateIpCapacityThreshold.key()); weightBasedParametersForValidation.add(Config.SecondaryStorageCapacityThreshold.key()); @@ -381,8 +384,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati private void overProvisioningFactorsForValidation() { overprovisioningFactorsForValidation = new HashSet(); - overprovisioningFactorsForValidation.add(Config.MemOverprovisioningFactor.key()); - overprovisioningFactorsForValidation.add(Config.CPUOverprovisioningFactor.key()); + overprovisioningFactorsForValidation.add(CapacityManager.MemOverprovisioningFactor.key()); + overprovisioningFactorsForValidation.add(CapacityManager.CpuOverprovisioningFactor.key()); overprovisioningFactorsForValidation.add(Config.StorageOverprovisioningFactor.key()); } @@ -444,9 +447,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // if scope is mentioned as global or not mentioned then it is normal // global parameter updation if (scope != null && !scope.isEmpty() - && !Config.ConfigurationParameterScope.global.toString().equalsIgnoreCase(scope)) { - switch (Config.ConfigurationParameterScope.valueOf(scope)) { - case zone: + && !ConfigKey.Scope.Global.toString().equalsIgnoreCase(scope)) { + switch (ConfigKey.Scope.valueOf(scope)) { + case Zone: DataCenterVO zone = _zoneDao.findById(resourceId); if (zone == null) { throw new InvalidParameterValueException("unable to find zone by id " + resourceId); @@ -460,7 +463,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati _dcDetailsDao.update(dcDetailVO.getId(), dcDetailVO); } break; - case cluster: + case Cluster: ClusterVO cluster = _clusterDao.findById(resourceId); if (cluster == null) { throw new InvalidParameterValueException("unable to find cluster by id " + resourceId); @@ -475,7 +478,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } break; - case storagepool: + case StoragePool: StoragePoolVO pool = _storagePoolDao.findById(resourceId); if (pool == null) { throw new InvalidParameterValueException("unable to find storage pool by id " + resourceId); @@ -491,7 +494,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } break; - case account: + case Account: AccountVO account = _accountDao.findById(resourceId); if (account == null) { throw new InvalidParameterValueException("unable to find account by id " + resourceId); @@ -655,22 +658,22 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati int paramCountCheck = 0; if (zoneId != null) { - scope = Config.ConfigurationParameterScope.zone.toString(); + scope = ConfigKey.Scope.Zone.toString(); id = zoneId; paramCountCheck++; } if (clusterId != null) { - scope = Config.ConfigurationParameterScope.cluster.toString(); + scope = ConfigKey.Scope.Cluster.toString(); id = clusterId; paramCountCheck++; } if (accountId != null) { - scope = Config.ConfigurationParameterScope.account.toString(); + scope = ConfigKey.Scope.Account.toString(); id = accountId; paramCountCheck++; } if (storagepoolId != null) { - scope = Config.ConfigurationParameterScope.storagepool.toString(); + scope = ConfigKey.Scope.StoragePool.toString(); id = storagepoolId; paramCountCheck++; } @@ -4624,6 +4627,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } } + @InjectConfig(key = NetworkOrchestrationService.NetworkThrottlingRateCK) + ConfigValue _networkThrottlingRate; + @Override public Integer getNetworkOfferingNetworkRate(long networkOfferingId, Long dataCenterId) { @@ -4637,8 +4643,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (no.getRateMbps() != null) { networkRate = no.getRateMbps(); } else { - networkRate = Integer.parseInt(_configServer.getConfigValue(Config.NetworkThrottlingRate.key(), - Config.ConfigurationParameterScope.zone.toString(), dataCenterId)); + networkRate = _networkThrottlingRate.valueIn(dataCenterId); } // networkRate is unsigned int in netowrkOfferings table, and can't be @@ -4761,8 +4766,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // for domain router service offering, get network rate from if (offering.getSystemVmType() != null && offering.getSystemVmType().equalsIgnoreCase(VirtualMachine.Type.DomainRouter.toString())) { - networkRate = Integer.parseInt(_configServer.getConfigValue(Config.NetworkThrottlingRate.key(), - Config.ConfigurationParameterScope.zone.toString(), dataCenterId)); + networkRate = _networkThrottlingRate.valueIn(dataCenterId); } else { networkRate = Integer.parseInt(_configDao.getValue(Config.VmNetworkThrottlingRate.key())); } diff --git a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java index 8a9df03015d..b1b2d400806 100644 --- a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java +++ b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java @@ -21,18 +21,21 @@ import java.util.Map; import javax.inject.Inject; +import org.apache.cloudstack.framework.config.ConfigValue; + import com.cloud.agent.api.Command; import com.cloud.agent.api.to.DiskTO; import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.VirtualMachineTO; -import com.cloud.configuration.Config; import com.cloud.offering.ServiceOffering; import com.cloud.server.ConfigurationServer; import com.cloud.storage.dao.VMTemplateDetailsDao; import com.cloud.utils.Pair; import com.cloud.utils.component.AdapterBase; +import com.cloud.utils.component.InjectConfig; import com.cloud.vm.NicProfile; import com.cloud.vm.NicVO; +import com.cloud.vm.UserVmManager; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; @@ -48,6 +51,9 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis @Inject NicSecondaryIpDao _nicSecIpDao; @Inject ConfigurationServer _configServer; + @InjectConfig(key = UserVmManager.EnableDynamicallyScaleVmCK) + ConfigValue _enableDynamicallyScaleVm; + protected HypervisorGuruBase() { super(); } @@ -124,7 +130,7 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis // Workaround to make sure the TO has the UUID we need for Niciri integration VMInstanceVO vmInstance = _virtualMachineDao.findById(to.getId()); // check if XStools/VMWare tools are present in the VM and dynamic scaling feature is enabled (per zone/global) - Boolean isDynamicallyScalable = vmInstance.isDynamicallyScalable() && Boolean.parseBoolean(_configServer.getConfigValue(Config.EnableDynamicallyScaleVm.key(), Config.ConfigurationParameterScope.zone.toString(), vm.getDataCenterId())); + Boolean isDynamicallyScalable = vmInstance.isDynamicallyScalable() && _enableDynamicallyScaleVm.valueIn(vm.getDataCenterId()); to.setEnableDynamicallyScaleVm(isDynamicallyScalable); to.setUuid(vmInstance.getUuid()); diff --git a/server/src/com/cloud/network/IpAddressManagerImpl.java b/server/src/com/cloud/network/IpAddressManagerImpl.java index 37552f63f2d..2daea2d90a7 100644 --- a/server/src/com/cloud/network/IpAddressManagerImpl.java +++ b/server/src/com/cloud/network/IpAddressManagerImpl.java @@ -34,6 +34,9 @@ import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.ConfigValue; +import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.region.PortableIp; import org.apache.cloudstack.region.PortableIpDao; @@ -43,7 +46,6 @@ import org.apache.cloudstack.region.Region; import com.cloud.agent.AgentManager; import com.cloud.alert.AlertManager; import com.cloud.api.ApiDBUtils; -import com.cloud.configuration.Config; import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.Resource.ResourceType; import com.cloud.dc.AccountVlanMapVO; @@ -123,7 +125,6 @@ import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.offerings.dao.NetworkOfferingDetailsDao; import com.cloud.offerings.dao.NetworkOfferingServiceMapDao; import com.cloud.org.Grouping; -import com.cloud.server.ConfigurationServer; import com.cloud.user.Account; import com.cloud.user.AccountManager; import com.cloud.user.ResourceLimitService; @@ -133,6 +134,7 @@ import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; import com.cloud.utils.Journal; import com.cloud.utils.Pair; +import com.cloud.utils.component.InjectConfig; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.db.DB; import com.cloud.utils.db.EntityManager; @@ -158,9 +160,12 @@ import com.cloud.vm.dao.NicSecondaryIpDao; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.VMInstanceDao; -public class IpAddressManagerImpl extends ManagerBase implements IpAddressManager { +public class IpAddressManagerImpl extends ManagerBase implements IpAddressManager, Configurable { private static final Logger s_logger = Logger.getLogger(IpAddressManagerImpl.class); + @InjectConfig(key = UseSystemPublicIpsCK) + ConfigValue _useSystemPublicIps; + @Inject NetworkOrchestrationService _networkMgr = null; @Inject @@ -206,8 +211,6 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage @Inject NetworkOfferingDetailsDao _ntwkOffDetailsDao; @Inject - ConfigurationServer _configServer; - @Inject AccountGuestVlanMapDao _accountGuestVlanMapDao; @Inject DataCenterVnetDao _datacenterVnetDao; @@ -724,9 +727,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage // If all the dedicated IPs of the owner are in use fetch an IP from the system pool if (addrs.size() == 0 && fetchFromDedicatedRange) { // Verify if account is allowed to acquire IPs from the system - boolean useSystemIps = Boolean.parseBoolean(_configServer.getConfigValue(Config.UseSystemPublicIps.key(), - Config.ConfigurationParameterScope.account.toString(), - owner.getId())); + boolean useSystemIps = _useSystemPublicIps.valueIn(owner.getId()); if (useSystemIps && nonDedicatedVlanDbIds != null && !nonDedicatedVlanDbIds.isEmpty()) { fetchFromDedicatedRange = false; sc.setParameters("vlanId", nonDedicatedVlanDbIds.toArray()); @@ -1917,4 +1918,14 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage ipaddr = acquireGuestIpAddress(network, requestedIp); return ipaddr; } + + @Override + public String getConfigComponentName() { + return IpAddressManager.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[] {UseSystemPublicIps}; + } } diff --git a/server/src/com/cloud/network/NetworkModelImpl.java b/server/src/com/cloud/network/NetworkModelImpl.java index c040a1af38f..df9f651b8f2 100755 --- a/server/src/com/cloud/network/NetworkModelImpl.java +++ b/server/src/com/cloud/network/NetworkModelImpl.java @@ -205,7 +205,6 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel { SearchBuilder NicForTrafficTypeSearch; - private String _networkDomain; private boolean _allowSubdomainNetworkAccess; private Map _configs; @@ -969,11 +968,6 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel { return networkDomain; } - @Override - public String getGlobalGuestDomainSuffix() { - return _networkDomain; - } - @Override public String getStartIpAddress(long networkId) { List vlans = _vlanDao.listVlansByNetworkId(networkId); @@ -1596,11 +1590,6 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel { return _networksDao.listByVpc(vpcId); } - @Override - public String getDefaultNetworkDomain(long zoneId) { - return _configServer.getConfigValue(Config.GuestDomainSuffix.key(), Config.ConfigurationParameterScope.zone.toString(), zoneId); - } - @Override public List getNtwkOffDistinctProviders(long ntkwOffId) { List providerNames = _ntwkOfferingSrvcDao.getDistinctProviders(ntkwOffId); @@ -1900,7 +1889,6 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel { @Override public boolean configure(String name, Map params) throws ConfigurationException { _configs = _configDao.getConfiguration("Network", params); - _networkDomain = _configs.get(Config.GuestDomainSuffix.key()); _allowSubdomainNetworkAccess = Boolean.valueOf(_configs.get(Config.SubDomainNetworkAccess.key())); _executeInSequenceNtwkElmtCmd = Boolean.valueOf(_configs.get(Config.ExecuteInSequenceNetworkElementCommands.key())); diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java index cf4f503e22d..5d2ef4f7d5b 100755 --- a/server/src/com/cloud/network/NetworkServiceImpl.java +++ b/server/src/com/cloud/network/NetworkServiceImpl.java @@ -293,6 +293,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { NetworkACLDao _networkACLDao; @Inject IpAddressManager _ipAddrMgr; + @Inject + EntityManager _entityMgr; int _cidrLimit; boolean _allowSubdomainNetworkAccess; @@ -1930,7 +1932,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { //perform below validation if the network is vpc network if (network.getVpcId() != null && networkOfferingId != null) { - Vpc vpc = _vpcMgr.getVpc(network.getVpcId()); + Vpc vpc = _entityMgr.findById(Vpc.class, network.getVpcId()); _vpcMgr.validateNtwkOffForNtwkInVpc(networkId, networkOfferingId, null, null, vpc, null, _accountMgr.getAccount(network.getAccountId()), null); } diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index b45d1c1dc9e..c512dda0058 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -25,9 +25,6 @@ import java.util.Set; import javax.ejb.Local; import javax.inject.Inject; -import com.cloud.network.dao.NetworkDao; -import com.cloud.network.vpc.*; -import com.cloud.network.vpc.dao.VpcGatewayDao; import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; @@ -46,27 +43,37 @@ import com.cloud.network.Site2SiteVpnConnection; import com.cloud.network.Site2SiteVpnGateway; import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType; import com.cloud.network.dao.IPAddressDao; +import com.cloud.network.dao.NetworkDao; import com.cloud.network.dao.Site2SiteVpnGatewayDao; import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VirtualRouter.Role; import com.cloud.network.router.VpcVirtualNetworkApplianceManager; +import com.cloud.network.vpc.NetworkACLItem; +import com.cloud.network.vpc.NetworkACLItemDao; +import com.cloud.network.vpc.NetworkACLItemVO; +import com.cloud.network.vpc.PrivateGateway; +import com.cloud.network.vpc.StaticRouteProfile; +import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcGateway; +import com.cloud.network.vpc.VpcManager; +import com.cloud.network.vpc.dao.VpcGatewayDao; import com.cloud.offering.NetworkOffering; +import com.cloud.utils.db.EntityManager; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.Type; import com.cloud.vm.VirtualMachineProfile; -@Local(value = {NetworkElement.class, FirewallServiceProvider.class, - DhcpServiceProvider.class, UserDataServiceProvider.class, +@Local(value = {NetworkElement.class, FirewallServiceProvider.class, + DhcpServiceProvider.class, UserDataServiceProvider.class, StaticNatServiceProvider.class, LoadBalancingServiceProvider.class, PortForwardingServiceProvider.class, IpDeployer.class, VpcProvider.class, Site2SiteVpnServiceProvider.class, NetworkACLServiceProvider.class}) public class VpcVirtualRouterElement extends VirtualRouterElement implements VpcProvider, Site2SiteVpnServiceProvider, NetworkACLServiceProvider{ private static final Logger s_logger = Logger.getLogger(VpcVirtualRouterElement.class); - @Inject + @Inject VpcManager _vpcMgr; @Inject VpcVirtualNetworkApplianceManager _vpcRouterMgr; @@ -82,6 +89,8 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc VpcGatewayDao _vpcGatewayDao; @Inject NetworkACLItemDao _networkACLItemDao; + @Inject + EntityManager _entityMgr; private static final Map> capabilities = setCapabilities(); @@ -107,17 +116,17 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc } } else { if (!_networkMgr.isProviderSupportServiceInNetwork(network.getId(), service, getProvider())) { - s_logger.trace("Element " + getProvider().getName() + " doesn't support service " + service.getName() + s_logger.trace("Element " + getProvider().getName() + " doesn't support service " + service.getName() + " in the network " + network); return false; - } + } } return true; } @Override - public boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, + public boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { Map params = new HashMap(1); @@ -181,12 +190,12 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc } } - return true; + return true; } @Override - public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, - DeployDestination dest, ReservationContext context) + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, + DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { Long vpcId = network.getVpcId(); @@ -204,7 +213,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc if (vm.getType() == Type.User) { Map params = new HashMap(1); params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true); - List routers = _vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, + List routers = _vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params); if ((routers == null) || (routers.size() == 0)) { throw new ResourceUnavailableException("Can't find at least one running router!", @@ -230,7 +239,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc } @Override - public boolean shutdown(Network network, ReservationContext context, boolean cleanup) + public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException { boolean success = true; Long vpcId = network.getVpcId(); @@ -330,7 +339,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc List routers = _vpcRouterMgr.getVpcRouters(gateway.getVpcId()); if (routers == null || routers.isEmpty()) { - s_logger.debug(this.getName() + " element doesn't need to create Private gateway on the backend; VPC virtual " + + s_logger.debug(getName() + " element doesn't need to create Private gateway on the backend; VPC virtual " + "router doesn't exist in the vpc id=" + gateway.getVpcId()); return true; } @@ -365,7 +374,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc List routers = _vpcRouterMgr.getVpcRouters(gateway.getVpcId()); if (routers == null || routers.isEmpty()) { - s_logger.debug(this.getName() + " element doesn't need to delete Private gateway on the backend; VPC virtual " + + s_logger.debug(getName() + " element doesn't need to delete Private gateway on the backend; VPC virtual " + "router doesn't exist in the vpc id=" + gateway.getVpcId()); return true; } @@ -381,7 +390,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc @Override - public boolean applyIps(Network network, List ipAddress, Set services) + public boolean applyIps(Network network, List ipAddress, Set services) throws ResourceUnavailableException { boolean canHandle = true; for (Service service : services) { @@ -393,7 +402,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc if (canHandle) { List routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug(this.getName() + " element doesn't need to associate ip addresses on the backend; VPC virtual " + + s_logger.debug(getName() + " element doesn't need to associate ip addresses on the backend; VPC virtual " + "router doesn't exist in the network " + network.getId()); return true; } @@ -479,7 +488,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc } Long vpcId = ip.getVpcId(); - Vpc vpc = _vpcMgr.getVpc(vpcId); + Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); if (!_ntwkModel.isProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) { throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(), @@ -507,7 +516,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc } Long vpcId = ip.getVpcId(); - Vpc vpc = _vpcMgr.getVpc(vpcId); + Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); if (!_ntwkModel.isProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) { throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(), diff --git a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java index e26fe744435..199da0568e9 100644 --- a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java @@ -139,8 +139,8 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { // Get a vlan tag int vlanTag; if (config.getBroadcastUri() == null) { - String vnet = _dcDao.allocateVnet(zone.getId(), config.getPhysicalNetworkId(), config.getAccountId(), - context.getReservationId(), canUseSystemGuestVlan(config.getAccountId())); + String vnet = _dcDao.allocateVnet(zone.getId(), config.getPhysicalNetworkId(), config.getAccountId(), context.getReservationId(), + _useSystemGuestVlans.valueIn(config.getAccountId())); try { vlanTag = Integer.parseInt(vnet); diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java index a3eab0f5452..cbb5ac739e5 100755 --- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java @@ -27,6 +27,9 @@ import org.apache.log4j.Logger; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.ConfigValue; +import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import com.cloud.configuration.Config; @@ -66,6 +69,7 @@ import com.cloud.server.ConfigurationServer; import com.cloud.user.Account; import com.cloud.utils.Pair; import com.cloud.utils.component.AdapterBase; +import com.cloud.utils.component.InjectConfig; import com.cloud.utils.db.DB; import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; @@ -78,7 +82,7 @@ import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.NicDao; @Local(value = NetworkGuru.class) -public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGuru { +public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGuru, Configurable { private static final Logger s_logger = Logger.getLogger(GuestNetworkGuru.class); @Inject protected NetworkOrchestrationService _networkMgr; @@ -103,6 +107,13 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur @Inject IpAddressManager _ipAddrMgr; Random _rand = new Random(System.currentTimeMillis()); + + static final ConfigKey UseSystemGuestVlans = new ConfigKey("Advanced", Boolean.class, "use.system.guest.vlans", "true", + "If true, when account has dedicated guest vlan range(s), once the vlans dedicated to the account have been consumed vlans will be allocated from the system pool", false, + ConfigKey.Scope.Account); + + @InjectConfig(key = "use.system.guest.vlans") + ConfigValue _useSystemGuestVlans; private static final TrafficType[] _trafficTypes = {TrafficType.Guest}; @@ -159,11 +170,6 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur return _isolationMethods; } - public boolean canUseSystemGuestVlan(long accountId) { - return Boolean.parseBoolean(_configServer.getConfigValue(Config.UseSystemGuestVlans.key(), - Config.ConfigurationParameterScope.account.toString(), accountId)); - } - protected abstract boolean canHandle(NetworkOffering offering, final NetworkType networkType, PhysicalNetwork physicalNetwork); @Override @@ -269,8 +275,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur protected void allocateVnet(Network network, NetworkVO implemented, long dcId, long physicalNetworkId, String reservationId) throws InsufficientVirtualNetworkCapcityException { if (network.getBroadcastUri() == null) { - String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId, - canUseSystemGuestVlan(network.getAccountId())); + String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId, _useSystemGuestVlans.valueIn(network.getAccountId())); if (vnet == null) { throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a " + "part of network " + network + " implement ", DataCenter.class, dcId); @@ -434,4 +439,14 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur networkProfile.setDns1(dc.getDns1()); networkProfile.setDns2(dc.getDns2()); } + + @Override + public String getConfigComponentName() { + return GuestNetworkGuru.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[] {UseSystemGuestVlans}; + } } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java index dbbc2d543ed..4ea09e5d35d 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java @@ -5,7 +5,7 @@ // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, @@ -16,6 +16,11 @@ // under the License. package com.cloud.network.router; +import java.util.List; +import java.util.Map; + +import org.apache.cloudstack.framework.config.ConfigKey; + import com.cloud.deploy.DeployDestination; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -30,20 +35,33 @@ import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.StaticNat; import com.cloud.user.Account; import com.cloud.user.User; -import com.cloud.uservm.UserVm; import com.cloud.utils.component.Manager; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.NicProfile; import com.cloud.vm.VirtualMachineProfile; -import java.util.List; -import java.util.Map; - /** * NetworkManager manages the network for the different end users. * */ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkApplianceService{ + static final String RouterTemplateXenCK = "router.template.xen"; + static final String RouterTemplateKvmCK = "router.template.kvm"; + static final String RouterTemplateVmwareCK = "router.template.vmware"; + static final String RouterTemplateHyperVCK = "router.template.hyperv"; + static final String RouterTemplateLxcCK = "router.template.lxc"; + + static final ConfigKey RouterTemplateXen = new ConfigKey(String.class, RouterTemplateXenCK, "Advanced", "SystemVM Template (XenServer)", + "Name of the default router template on Xenserver.", true, ConfigKey.Scope.Zone, null); + static final ConfigKey RouterTemplateKvm = new ConfigKey(String.class, RouterTemplateKvmCK, "Advanced", "SystemVM Template (KVM)", + "Name of the default router template on KVM.", true, ConfigKey.Scope.Zone, null); + static final ConfigKey RouterTemplateVmware = new ConfigKey(String.class, RouterTemplateVmwareCK, "Advanced", "SystemVM Template (vSphere)", + "Name of the default router template on Vmware.", true, ConfigKey.Scope.Zone, null); + static final ConfigKey RouterTemplateHyperV = new ConfigKey(String.class, RouterTemplateHyperVCK, "Advanced", "SystemVM Template (HyperV)", + "Name of the default router template on Hyperv.", true, ConfigKey.Scope.Zone, null); + static final ConfigKey RouterTemplateLxc = new ConfigKey(String.class, RouterTemplateLxcCK, "Advanced", "SystemVM Template (LXC)", + "Name of the default router template on LXC.", true, ConfigKey.Scope.Zone, null); + public static final int DEFAULT_ROUTER_VM_RAMSIZE = 128; // 128M public static final int DEFAULT_ROUTER_CPU_MHZ = 500; // 500 MHz public static final boolean USE_POD_VLAN = false; @@ -61,7 +79,7 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA * @param routers TODO * */ - boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, + boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, List routers) throws ResourceUnavailableException; boolean saveSSHPublicKeyToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, @@ -70,39 +88,39 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA boolean saveUserDataToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, List routers) throws ResourceUnavailableException; - List deployVirtualRouterInGuestNetwork(Network guestNetwork, DeployDestination dest, Account owner, + List deployVirtualRouterInGuestNetwork(Network guestNetwork, DeployDestination dest, Account owner, Map params, boolean isRedundant) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException; - boolean startRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) + boolean startRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) throws ResourceUnavailableException; - boolean deleteRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) + boolean deleteRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List routers) throws ResourceUnavailableException; - boolean associatePublicIP (Network network, final List ipAddress, + boolean associatePublicIP (Network network, final List ipAddress, List routers) throws ResourceUnavailableException; - boolean applyFirewallRules(Network network, final List rules, + boolean applyFirewallRules(Network network, final List rules, List routers) throws ResourceUnavailableException; List getRoutersForNetwork(long networkId); - String[] applyVpnUsers(Network network, List users, List routers) + String[] applyVpnUsers(Network network, List users, List routers) throws ResourceUnavailableException; - VirtualRouter stop(VirtualRouter router, boolean forced, User callingUser, Account callingAccount) + VirtualRouter stop(VirtualRouter router, boolean forced, User callingUser, Account callingAccount) throws ConcurrentOperationException, ResourceUnavailableException; String getDnsBasicZoneUpdate(); - boolean applyStaticNats(Network network, final List rules, List routers) + boolean applyStaticNats(Network network, final List rules, List routers) throws ResourceUnavailableException; - boolean applyDhcpEntry(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, + boolean applyDhcpEntry(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, List routers) throws ResourceUnavailableException; - boolean applyUserData(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, + boolean applyUserData(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, List routers) throws ResourceUnavailableException; boolean applyLoadBalancingRules(Network network, List rules, List routers) throws ResourceUnavailableException; diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 90a4bff7d90..d033760c95a 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -47,6 +47,9 @@ import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.context.ServerContexts; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; +import org.apache.cloudstack.framework.config.ConfigDepot; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.ConfigValue; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.utils.identity.ManagementServerNode; @@ -218,6 +221,7 @@ import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; import com.cloud.utils.PasswordGenerator; import com.cloud.utils.StringUtils; +import com.cloud.utils.component.InjectConfig; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.DB; @@ -363,6 +367,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V NetworkService _networkSvc; @Inject IpAddressManager _ipAddrMgr; + @Inject + ConfigDepot _configDepot; int _routerRamSize; @@ -635,9 +641,28 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V } } + @InjectConfig(key = RouterTemplateXenCK) + ConfigValue _routerTemplateXen; + @InjectConfig(key = RouterTemplateKvmCK) + ConfigValue _routerTemplateKvm; + @InjectConfig(key = RouterTemplateVmwareCK) + ConfigValue _routerTemplateVmware; + @InjectConfig(key = RouterTemplateHyperVCK) + ConfigValue _routerTemplateHyperV; + @InjectConfig(key = RouterTemplateLxcCK) + ConfigValue _routerTemplateLxc; + @InjectConfig(key = NetworkOrchestrationService.NetworkLockTimeoutCK) + ConfigValue _networkLockTimeout; + @InjectConfig(key = "use.external.dns") + ConfigValue _useExternalDnsServers; + + static final ConfigKey UseExternalDnsServers = new ConfigKey(Boolean.class, "use.external.dns", "Advanced", "false", + "Bypass internal dns, use external dns1 and dns2", true, ConfigKey.Scope.Zone, null); @Override public boolean configure(final String name, final Map params) throws ConfigurationException { + _useExternalDnsServers = _configDepot.get(UseExternalDnsServers); + _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("RouterMonitor")); _checkExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("RouterStatusMonitor")); _networkStatsUpdateExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("NetworkStatsUpdater")); @@ -1426,7 +1451,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V InsufficientCapacityException, ResourceUnavailableException { List routers = new ArrayList(); - Network lock = _networkDao.acquireInLockTable(guestNetwork.getId(), _networkMgr.getNetworkLockTimeout()); + Network lock = _networkDao.acquireInLockTable(guestNetwork.getId(), _networkLockTimeout.value()); if (lock == null) { throw new ConcurrentOperationException("Unable to lock network " + guestNetwork.getId()); } @@ -1621,19 +1646,19 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V String templateName = null; switch (hType) { case XenServer: - templateName = _configServer.getConfigValue(Config.RouterTemplateXen.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); + templateName = _routerTemplateXen.valueIn(dest.getDataCenter().getId()); break; case KVM: - templateName = _configServer.getConfigValue(Config.RouterTemplateKVM.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); + templateName = _routerTemplateKvm.valueIn(dest.getDataCenter().getId()); break; case VMware: - templateName = _configServer.getConfigValue(Config.RouterTemplateVmware.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); + templateName = _routerTemplateVmware.valueIn(dest.getDataCenter().getId()); break; case Hyperv: - templateName = _configServer.getConfigValue(Config.RouterTemplateHyperv.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); + templateName = _routerTemplateHyperV.valueIn(dest.getDataCenter().getId()); break; case LXC: - templateName = _configServer.getConfigValue(Config.RouterTemplateLXC.key(), Config.ConfigurationParameterScope.zone.toString(), dest.getDataCenter().getId()); + templateName = _routerTemplateLxc.valueIn(dest.getDataCenter().getId()); break; default: break; } @@ -2151,10 +2176,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V boolean useExtDns = !dnsProvided; /* For backward compatibility */ - String use_external_dns = _configServer.getConfigValue(Config.UseExternalDnsServers.key(), Config.ConfigurationParameterScope.zone.toString(), dc.getId()); - if (use_external_dns != null && use_external_dns.equals("true")) { - useExtDns = true; - } + useExtDns = _useExternalDnsServers.valueIn(dc.getId()); if (useExtDns) { buf.append(" useextdns=true"); diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index abe07464eda..68e68d765e9 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -161,6 +161,8 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian VpcGatewayDao _vpcGatewayDao; @Inject NetworkACLItemDao _networkACLItemDao; + @Inject + EntityManager _entityMgr; @Override public List deployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner, @@ -627,7 +629,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian //add vpc cidr/dns/networkdomain to the boot load args StringBuilder buf = profile.getBootArgsBuilder(); - Vpc vpc = _vpcMgr.getVpc(vr.getVpcId()); + Vpc vpc = _entityMgr.findById(Vpc.class, vr.getVpcId()); buf.append(" vpccidr=" + vpc.getCidr() + " domain=" + vpc.getNetworkDomain()); buf.append(" dns1=").append(defaultDns1); @@ -829,7 +831,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian for (StaticRoute route : routes) { VpcGateway gateway = gatewayMap.get(route.getVpcGatewayId()); if (gateway == null) { - gateway = _vpcMgr.getVpcGateway(route.getVpcGatewayId()); + gateway = _entityMgr.findById(VpcGateway.class, route.getVpcGatewayId()); gatewayMap.put(gateway.getId(), gateway); } staticRouteProfiles.add(new StaticRouteProfile(route, gateway)); diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java index 4620ed8e108..965bd6243cd 100755 --- a/server/src/com/cloud/network/rules/RulesManagerImpl.java +++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java @@ -57,6 +57,7 @@ import com.cloud.network.rules.FirewallRule.FirewallRuleType; import com.cloud.network.rules.FirewallRule.Purpose; import com.cloud.network.rules.dao.PortForwardingRulesDao; import com.cloud.network.vpc.VpcManager; +import com.cloud.network.vpc.VpcService; import com.cloud.offering.NetworkOffering; import com.cloud.projects.Project.ListProjectResourcesCriteria; import com.cloud.server.ResourceTag.TaggedResourceType; @@ -140,6 +141,8 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules NicSecondaryIpDao _nicSecondaryDao; @Inject LoadBalancerVMMapDao _loadBalancerVMMapDao; + @Inject + VpcService _vpcService; protected void checkIpAndUserVm(IpAddress ipAddress, UserVm userVm, Account caller, Boolean ignoreVmState) { @@ -506,7 +509,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules // associate portable IP to vpc, if network is part of VPC if (network.getVpcId() != null) { - _vpcMgr.associateIPToVpc(ipId, network.getVpcId()); + _vpcService.associateIPToVpc(ipId, network.getVpcId()); } // associate portable IP with guest network diff --git a/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java b/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java index cdb284ac2f6..9923db56461 100644 --- a/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java +++ b/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java @@ -55,8 +55,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLManager{ private static final Logger s_logger = Logger.getLogger(NetworkACLManagerImpl.class); - @Inject - EntityManager _entityMgr; @Inject AccountManager _accountMgr; @Inject @@ -81,6 +79,8 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana NetworkModel _ntwkModel; @Inject ConfigurationManager _configMgr; + @Inject + EntityManager _entityMgr; @Override public NetworkACL createNetworkACL(String name, String description, long vpcId) { @@ -105,7 +105,7 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana List vpcGateways = _vpcGatewayDao.listByAclIdAndType(aclId, VpcGateway.Type.Private); for (VpcGatewayVO vpcGateway : vpcGateways) { - PrivateGateway privateGateway = _vpcMgr.getVpcPrivateGateway(vpcGateway.getId()); + PrivateGateway privateGateway = _entityMgr.findById(PrivateGateway.class, vpcGateway.getId()); if (!applyACLToPrivateGw(privateGateway)) { aclApplyStatus = false; s_logger.debug("failed to apply network acl item on private gateway " + privateGateway.getId() + "acl id " + aclId); diff --git a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java index 274ca44b6eb..50dd8e30741 100644 --- a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java +++ b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java @@ -16,6 +16,23 @@ // under the License. package com.cloud.network.vpc; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.ejb.Local; +import javax.inject.Inject; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd; +import org.apache.cloudstack.api.command.user.network.ListNetworkACLsCmd; +import org.apache.cloudstack.context.CallContext; + import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network; @@ -34,6 +51,7 @@ import com.cloud.user.AccountManager; import com.cloud.utils.Pair; import com.cloud.utils.Ternary; import com.cloud.utils.component.ManagerBase; +import com.cloud.utils.db.EntityManager; import com.cloud.utils.db.Filter; import com.cloud.utils.db.JoinBuilder; import com.cloud.utils.db.SearchBuilder; @@ -42,23 +60,6 @@ import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; -import org.apache.cloudstack.api.ApiErrorCode; -import org.apache.cloudstack.api.ServerApiException; -import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd; -import org.apache.cloudstack.api.command.user.network.ListNetworkACLsCmd; -import org.apache.cloudstack.context.CallContext; - -import org.apache.commons.lang.StringUtils; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import javax.ejb.Local; -import javax.inject.Inject; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - @Component @Local(value = { NetworkACLService.class}) @@ -85,11 +86,13 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ VpcGatewayDao _vpcGatewayDao; @Inject VpcManager _vpcMgr; + @Inject + EntityManager _entityMgr; @Override public NetworkACL createNetworkACL(String name, String description, long vpcId) { Account caller = CallContext.current().getCallingAccount(); - Vpc vpc = _vpcMgr.getVpc(vpcId); + Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); if(vpc == null){ throw new InvalidParameterValueException("Unable to find VPC"); } @@ -151,7 +154,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ throw new InvalidParameterValueException("Default ACL cannot be removed"); } - Vpc vpc = _vpcMgr.getVpc(acl.getVpcId()); + Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); if(vpc == null){ throw new InvalidParameterValueException("Unable to find specified VPC associated with the ACL"); } @@ -182,7 +185,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ } if(aclId != NetworkACL.DEFAULT_DENY && aclId != NetworkACL.DEFAULT_ALLOW) { - Vpc vpc = _vpcMgr.getVpc(acl.getVpcId()); + Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); if(vpc == null){ throw new InvalidParameterValueException("Unable to find Vpc associated with the NetworkACL"); } @@ -192,7 +195,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ } } - PrivateGateway privateGateway = _vpcMgr.getVpcPrivateGateway(privateGatewayId); + PrivateGateway privateGateway = _entityMgr.findById(PrivateGateway.class, privateGatewayId); _accountMgr.checkAccess(caller, null, true, privateGateway); return _networkAclMgr.replaceNetworkACLForPrivateGw(acl, privateGateway); @@ -224,7 +227,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ if(aclId != NetworkACL.DEFAULT_DENY && aclId != NetworkACL.DEFAULT_ALLOW) { //ACL is not default DENY/ALLOW // ACL should be associated with a VPC - Vpc vpc = _vpcMgr.getVpc(acl.getVpcId()); + Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); if(vpc == null){ throw new InvalidParameterValueException("Unable to find Vpc associated with the NetworkACL"); } @@ -262,7 +265,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ throw new InvalidParameterValueException("Network Offering does not support NetworkACL service"); } - Vpc vpc = _vpcMgr.getVpc(network.getVpcId()); + Vpc vpc = _entityMgr.findById(Vpc.class, network.getVpcId()); if(vpc == null){ throw new InvalidParameterValueException("Unable to find Vpc associated with the Network"); } @@ -297,7 +300,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ throw new InvalidParameterValueException("Default ACL cannot be modified"); } - Vpc vpc = _vpcMgr.getVpc(acl.getVpcId()); + Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); if(vpc == null){ throw new InvalidParameterValueException("Unable to find Vpc associated with the NetworkACL"); } @@ -519,7 +522,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ NetworkACL acl = _networkAclMgr.getNetworkACL(aclItem.getAclId()); - Vpc vpc = _vpcMgr.getVpc(acl.getVpcId()); + Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId()); Account caller = CallContext.current().getCallingAccount(); diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index 4f9f286b72e..597a7b09548 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -32,13 +32,14 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.api.command.user.vpc.ListPrivateGatewaysCmd; import org.apache.cloudstack.api.command.user.vpc.ListStaticRoutesCmd; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; +import org.apache.cloudstack.framework.config.ConfigDepot; +import org.apache.cloudstack.framework.config.ConfigValue; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import com.cloud.configuration.Config; @@ -126,9 +127,8 @@ import com.cloud.vm.ReservationContextImpl; import com.cloud.vm.dao.DomainRouterDao; -@Component @Local(value = { VpcManager.class, VpcService.class, VpcProvisioningService.class }) -public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvisioningService{ +public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvisioningService, VpcService { private static final Logger s_logger = Logger.getLogger(VpcManagerImpl.class); @Inject EntityManager _entityMgr; @@ -190,12 +190,15 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis NetworkACLDao _networkAclDao; @Inject IpAddressManager _ipAddrMgr; + @Inject + ConfigDepot _configDepot; private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("VpcChecker")); private List vpcElements = null; private final List nonSupportedServices = Arrays.asList(Service.SecurityGroup, Service.Firewall); private final List supportedProviders = Arrays.asList(Provider.VPCVirtualRouter, Provider.NiciraNvp, Provider.InternalLbVm, Provider.Netscaler); + ConfigValue _networkDomain; int _cleanupInterval; int _maxNetworks; @@ -256,7 +259,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis String maxNtwks = configs.get(Config.VpcMaxNetworks.key()); _maxNetworks = NumbersUtil.parseInt(maxNtwks, 3); // max=3 is default - + + _networkDomain = _configDepot.get(NetworkOrchestrationService.GuestDomainSuffix); IpAddressSearch = _ipAddressDao.createSearchBuilder(); IpAddressSearch.and("accountId", IpAddressSearch.entity().getAllocatedToAccountId(), Op.EQ); @@ -397,11 +401,6 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis return offering; } - @Override - public Vpc getVpc(long vpcId) { - return _vpcDao.findById(vpcId); - } - @Override public Vpc getActiveVpc(long vpcId) { return _vpcDao.getActiveVpcById(vpcId); @@ -621,7 +620,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis // 2) If null, generate networkDomain using domain suffix from the global config variables if (networkDomain == null) { - networkDomain = "cs" + Long.toHexString(owner.getId()) + _ntwkModel.getDefaultNetworkDomain(zoneId); + networkDomain = "cs" + Long.toHexString(owner.getId()) + _networkDomain.valueIn(zoneId); } } @@ -709,7 +708,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis CallContext ctx = CallContext.current(); // Verify vpc id - Vpc vpc = getVpc(vpcId); + Vpc vpc = _vpcDao.findById(vpcId); if (vpc == null) { throw new InvalidParameterValueException("unable to find VPC id=" + vpcId); } @@ -1017,7 +1016,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis Account caller = ctx.getCallingAccount(); //check if vpc exists - Vpc vpc = getVpc(vpcId); + Vpc vpc = _vpcDao.findById(vpcId); if (vpc == null) { throw new InvalidParameterValueException("Unable to find vpc by id " + vpcId); } @@ -1353,11 +1352,6 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis return getPrivateGatewayProfile(gateway); } - @Override - public VpcGateway getVpcGateway(long id) { - return _vpcGatewayDao.findById(id); - } - protected PrivateGateway getPrivateGatewayProfile(VpcGateway gateway) { Network network = _ntwkModel.getNetwork(gateway.getNetworkId()); return new PrivateGatewayProfile(gateway, network.getPhysicalNetworkId()); @@ -1659,7 +1653,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis s_logger.debug("No static routes to apply"); return true; } - Vpc vpc = getVpc(routes.get(0).getVpcId()); + Vpc vpc = _vpcDao.findById(routes.get(0).getVpcId()); s_logger.debug("Applying static routes for vpc " + vpc); String staticNatProvider = _vpcSrvcDao.getProviderForServiceInVpc(vpc.getId(), Service.StaticNat); @@ -1778,7 +1772,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } protected boolean isCidrBlacklisted(String cidr, long zoneId) { - String routesStr = _configServer.getConfigValue(Config.BlacklistedRoutes.key(), Config.ConfigurationParameterScope.zone.toString(), zoneId); + String routesStr = _networkDomain.valueIn(zoneId); if (routesStr != null && !routesStr.isEmpty()) { String[] cidrBlackList = routesStr.split(","); @@ -1959,7 +1953,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis return null; } - Vpc vpc = getVpc(vpcId); + Vpc vpc = _vpcDao.findById(vpcId); if (vpc == null) { throw new InvalidParameterValueException("Invalid VPC id provided"); } diff --git a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java index 8d497c9bdcb..022493d421d 100755 --- a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java +++ b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java @@ -5,7 +5,7 @@ // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, @@ -25,14 +25,16 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; +import org.apache.log4j.Logger; + import org.apache.cloudstack.api.command.user.vpn.ListRemoteAccessVpnsCmd; import org.apache.cloudstack.api.command.user.vpn.ListVpnUsersCmd; import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.ConfigValue; +import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - import com.cloud.configuration.Config; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; @@ -45,8 +47,12 @@ import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network; import com.cloud.network.Network.Service; -import com.cloud.network.*; +import com.cloud.network.NetworkModel; +import com.cloud.network.PublicIpAddress; +import com.cloud.network.RemoteAccessVpn; +import com.cloud.network.VpnUser; import com.cloud.network.VpnUser.State; +import com.cloud.network.VpnUserVO; import com.cloud.network.dao.FirewallRulesDao; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.IPAddressVO; @@ -69,16 +75,27 @@ import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; import com.cloud.utils.PasswordGenerator; import com.cloud.utils.Ternary; +import com.cloud.utils.component.InjectConfig; import com.cloud.utils.component.ManagerBase; -import com.cloud.utils.db.*; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.JoinBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.utils.db.Transaction; import com.cloud.utils.net.NetUtils; -@Component @Local(value = RemoteAccessVpnService.class) -public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAccessVpnService { +public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAccessVpnService, Configurable { private final static Logger s_logger = Logger.getLogger(RemoteAccessVpnManagerImpl.class); + static final ConfigKey RemoteAccessVpnClientIpRange = new ConfigKey("Network", String.class, RemoteAccessVpnClientIpRangeCK, "10.1.2.1-10.1.2.8", + "The range of ips to be allocated to remote access vpn clients. The first ip in the range is used by the VPN server", false, ConfigKey.Scope.Account); + + @InjectConfig(key = RemoteAccessVpnClientIpRangeCK) + ConfigValue _remoteAccessVpnClientIpRange; + @Inject AccountDao _accountDao; @Inject VpnUserDao _vpnUsersDao; @Inject RemoteAccessVpnDao _remoteAccessVpnDao; @@ -98,12 +115,11 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc int _userLimit; int _pskLength; - String _clientIpRange; SearchBuilder VpnSearch; @Override @DB - public RemoteAccessVpn createRemoteAccessVpn(long publicIpId, String ipRange, boolean openFirewall, long networkId) + public RemoteAccessVpn createRemoteAccessVpn(long publicIpId, String ipRange, boolean openFirewall, long networkId) throws NetworkRuleConflictException { CallContext ctx = CallContext.current(); Account caller = ctx.getCallingAccount(); @@ -150,7 +166,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc } if (ipRange == null) { - ipRange = _configServer.getConfigValue(Config.RemoteAccessVpnClientIpRange.key(), Config.ConfigurationParameterScope.account.toString(), ipAddr.getAccountId()); + ipRange = _remoteAccessVpnClientIpRange.valueIn(ipAddr.getAccountId()); } String[] range = ipRange.split("-"); if (range.length != 2) { @@ -192,7 +208,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc } private void validateRemoteAccessVpnConfiguration() throws ConfigurationException { - String ipRange = _clientIpRange; + String ipRange = _remoteAccessVpnClientIpRange.value(); if (ipRange == null) { s_logger.warn("Remote Access VPN global configuration missing client ip range -- ignoring"); return; @@ -241,7 +257,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc break; } } - } finally { + } finally { if (success) { //Cleanup corresponding ports List vpnFwRules = _rulesDao.listByIpAndPurpose(ipId, Purpose.Vpn); @@ -258,7 +274,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc txn.start(); for (FirewallRule vpnFwRule : vpnFwRules) { - //don't apply on the backend yet; send all 3 rules in a banch + //don't apply on the backend yet; send all 3 rules in a banch _firewallMgr.revokeRelatedFirewallRule(vpnFwRule.getId(), false); fwRules.add(_rulesDao.findByRelatedId(vpnFwRule.getId())); } @@ -276,7 +292,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc try { txn.start(); _remoteAccessVpnDao.remove(vpn.getId()); - // Stop billing of VPN users when VPN is removed. VPN_User_ADD events will be generated when VPN is created again + // Stop billing of VPN users when VPN is removed. VPN_User_ADD events will be generated when VPN is created again List vpnUsers = _vpnUsersDao.listByAccount(vpn.getAccountId()); for(VpnUserVO user : vpnUsers){ // VPN_USER_REMOVE event is already generated for users in Revoke state @@ -291,7 +307,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc s_logger.debug("Successfully removed firewall rule with ip id=" + vpnFwRule.getSourceIpAddressId() + " and port " + vpnFwRule.getSourcePortStart() + " as a part of vpn cleanup"); } } - txn.commit(); + txn.commit(); } catch (Exception ex) { txn.rollback(); s_logger.warn("Unable to release the three vpn ports from the firewall rules", ex); @@ -401,7 +417,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc vpn.setState(RemoteAccessVpn.State.Running); _remoteAccessVpnDao.update(vpn.getId(), vpn); - // Start billing of existing VPN users in ADD and Active state + // Start billing of existing VPN users in ADD and Active state List vpnUsers = _vpnUsersDao.listByAccount(vpn.getAccountId()); for(VpnUserVO user : vpnUsers){ if(user.getState() != VpnUser.State.Revoke){ @@ -410,7 +426,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc } } txn.commit(); - } + } } } @@ -469,7 +485,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc for (int i = 0; i < finals.length; i++) { VpnUserVO user = users.get(i); - if (finals[i]) { + if (finals[i]) { if (user.getState() == State.Add) { user.setState(State.Active); _vpnUsersDao.update(user.getId(), user); @@ -479,7 +495,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc } else { if (user.getState() == State.Add && (user.getUsername()).equals(userName)) { Transaction txn = Transaction.currentTxn(); - txn.start(); + txn.start(); _vpnUsersDao.remove(user.getId()); UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VPN_USER_REMOVE, user.getAccountId(), 0, user.getId(), user.getUsername(), user.getClass().getName(), user.getUuid()); @@ -556,9 +572,9 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc _accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false); Long domainId = domainIdRecursiveListProject.first(); Boolean isRecursive = domainIdRecursiveListProject.second(); - ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); + ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); - Filter filter = new Filter(RemoteAccessVpnVO.class, "serverAddressId", false, cmd.getStartIndex(), cmd.getPageSizeVal()); + Filter filter = new Filter(RemoteAccessVpnVO.class, "serverAddressId", false, cmd.getStartIndex(), cmd.getPageSizeVal()); SearchBuilder sb = _remoteAccessVpnDao.createSearchBuilder(); _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); @@ -585,8 +601,6 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc _userLimit = NumbersUtil.parseInt(configs.get(Config.RemoteAccessVpnUserLimit.key()), 8); - _clientIpRange = configs.get(Config.RemoteAccessVpnClientIpRange.key()); - _pskLength = NumbersUtil.parseInt(configs.get(Config.RemoteAccessVpnPskLength.key()), 24); validateRemoteAccessVpnConfiguration(); @@ -619,4 +633,14 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc return result; } + + @Override + public String getConfigComponentName() { + return RemoteAccessVpnService.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[] {RemoteAccessVpnClientIpRange}; + } } diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index 59c70970ef6..8f4b43c70ab 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -45,6 +45,7 @@ import org.apache.cloudstack.api.command.admin.host.ReconnectHostCmd; import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd; import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd; import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.framework.config.ConfigValue; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.region.dao.RegionDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; @@ -69,6 +70,7 @@ import com.cloud.agent.manager.ClusteredAgentManagerImpl; import com.cloud.agent.transport.Request; import com.cloud.api.ApiDBUtils; import com.cloud.capacity.Capacity; +import com.cloud.capacity.CapacityManager; import com.cloud.capacity.CapacityVO; import com.cloud.capacity.dao.CapacityDao; import com.cloud.cluster.ClusterManager; @@ -136,6 +138,7 @@ import com.cloud.user.AccountManager; import com.cloud.user.User; import com.cloud.utils.StringUtils; import com.cloud.utils.UriUtils; +import com.cloud.utils.component.InjectConfig; import com.cloud.utils.component.Manager; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.db.DB; @@ -166,6 +169,11 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, Gson _gson; + @InjectConfig(key = CapacityManager.CpuOverprovisioningFactorCK) + ConfigValue _cpuOverprovisioningFactor; + @InjectConfig(key = CapacityManager.MemOverprovisioningFactorCK) + ConfigValue _memOverprovisioningFactor; + @Inject AccountManager _accountMgr; @Inject @@ -472,8 +480,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, if (clusterType == Cluster.ClusterType.CloudManaged) { Map details = new HashMap(); - details.put("cpuOvercommitRatio", _configDao.getValue(Config.CPUOverprovisioningFactor.key())); - details.put("memoryOvercommitRatio", _configDao.getValue(Config.MemOverprovisioningFactor.key())); + details.put("cpuOvercommitRatio", _cpuOverprovisioningFactor.value().toString()); + details.put("memoryOvercommitRatio", _memOverprovisioningFactor.value().toString()); _clusterDetailsDao.persist(cluster.getId(), details); return result; } @@ -483,8 +491,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, details.put("url", url); details.put("username", username); details.put("password", password); - details.put("cpuOvercommitRatio", _configDao.getValue(Config.CPUOverprovisioningFactor.key())); - details.put("memoryOvercommitRatio", _configDao.getValue(Config.MemOverprovisioningFactor.key())); + details.put("cpuOvercommitRatio", _cpuOverprovisioningFactor.value().toString()); + details.put("memoryOvercommitRatio", _memOverprovisioningFactor.value().toString()); _clusterDetailsDao.persist(cluster.getId(), details); boolean success = false; diff --git a/server/src/com/cloud/server/ConfigurationServer.java b/server/src/com/cloud/server/ConfigurationServer.java index 1c8ccfec62d..1d999732dba 100644 --- a/server/src/com/cloud/server/ConfigurationServer.java +++ b/server/src/com/cloud/server/ConfigurationServer.java @@ -34,6 +34,5 @@ public interface ConfigurationServer { */ public void persistDefaultValues() throws InternalErrorException; public void updateKeyPairs(); - public String getConfigValue(String name, String scope, Long resourceId); public List getConfigListByScope(String scope, Long resourceId); } diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index b3ead6381fe..aed60195f30 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -46,31 +46,23 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; import org.apache.log4j.Logger; +import org.apache.cloudstack.framework.config.ConfigDepot; import org.apache.cloudstack.framework.config.ConfigDepotAdmin; import org.apache.cloudstack.framework.config.ConfigurationVO; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; -import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO; -import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; -import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import com.cloud.configuration.Config; +import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.Resource; import com.cloud.configuration.Resource.ResourceOwnerType; import com.cloud.configuration.Resource.ResourceType; import com.cloud.configuration.ResourceCountVO; import com.cloud.configuration.dao.ResourceCountDao; -import com.cloud.dc.ClusterDetailsDao; -import com.cloud.dc.ClusterDetailsVO; -import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenter.NetworkType; import com.cloud.dc.DataCenterVO; -import com.cloud.dc.DcDetailVO; import com.cloud.dc.HostPodVO; import com.cloud.dc.VlanVO; -import com.cloud.dc.dao.ClusterDao; import com.cloud.dc.dao.DataCenterDao; -import com.cloud.dc.dao.DcDetailsDao; import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.VlanDao; import com.cloud.domain.DomainVO; @@ -104,8 +96,6 @@ import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.test.IPRangeConfig; import com.cloud.user.Account; -import com.cloud.user.AccountDetailVO; -import com.cloud.user.AccountDetailsDao; import com.cloud.user.AccountVO; import com.cloud.user.User; import com.cloud.user.dao.AccountDao; @@ -126,8 +116,6 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio @Inject private ConfigurationDao _configDao; @Inject private DataCenterDao _zoneDao; - @Inject private ClusterDao _clusterDao; - @Inject private PrimaryDataStoreDao _storagePoolDao; @Inject private HostPodDao _podDao; @Inject private DiskOfferingDao _diskOfferingDao; @Inject private ServiceOfferingDao _serviceOfferingDao; @@ -139,12 +127,12 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio @Inject private AccountDao _accountDao; @Inject private ResourceCountDao _resourceCountDao; @Inject private NetworkOfferingServiceMapDao _ntwkOfferingServiceMapDao; - @Inject private DcDetailsDao _dcDetailsDao; - @Inject private ClusterDetailsDao _clusterDetailsDao; - @Inject private StoragePoolDetailsDao _storagePoolDetailsDao; - @Inject private AccountDetailsDao _accountDetailsDao; @Inject protected ConfigDepotAdmin _configDepotAdmin; + @Inject + protected ConfigDepot _configDepot; + @Inject + protected ConfigurationManager _configMgr; public ConfigurationServerImpl() { setRunLevel(ComponentLifecycle.RUN_LEVEL_FRAMEWORK_BOOTSTRAP); @@ -691,61 +679,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio } } - @Override - public String getConfigValue(String name, String scope, Long resourceId) { - // If either of scope or resourceId is null then return global config value otherwise return value at the scope - Config c = Config.getConfig(name); - if (c == null) { - throw new CloudRuntimeException("Missing configuration variable " + name + " in configuration table"); - } - String configScope = c.getScope(); - if (scope != null && !scope.isEmpty()) { - if (!configScope.contains(scope)) { - throw new CloudRuntimeException("Invalid scope " + scope + " for the parameter " + name ); - } - if (resourceId != null) { - switch (Config.ConfigurationParameterScope.valueOf(scope)) { - case zone: DataCenterVO zone = _zoneDao.findById(resourceId); - if (zone == null) { - throw new InvalidParameterValueException("unable to find zone by id " + resourceId); - } - DcDetailVO dcDetailVO = _dcDetailsDao.findDetail(resourceId, name); - if (dcDetailVO != null && dcDetailVO.getValue() != null) { - return dcDetailVO.getValue(); - } break; - case cluster: ClusterVO cluster = _clusterDao.findById(resourceId); - if (cluster == null) { - throw new InvalidParameterValueException("unable to find cluster by id " + resourceId); - } - ClusterDetailsVO clusterDetailsVO = _clusterDetailsDao.findDetail(resourceId, name); - if (clusterDetailsVO != null && clusterDetailsVO.getValue() != null) { - return clusterDetailsVO.getValue(); - } break; - - case storagepool: StoragePoolVO pool = _storagePoolDao.findById(resourceId); - if (pool == null) { - throw new InvalidParameterValueException("unable to find storage pool by id " + resourceId); - } - StoragePoolDetailVO storagePoolDetailVO = _storagePoolDetailsDao.findDetail(resourceId, name); - if (storagePoolDetailVO != null && storagePoolDetailVO.getValue() != null) { - return storagePoolDetailVO.getValue(); - } break; - - case account: AccountVO account = _accountDao.findById(resourceId); - if (account == null) { - throw new InvalidParameterValueException("unable to find account by id " + resourceId); - } - AccountDetailVO accountDetailVO = _accountDetailsDao.findDetail(resourceId, name); - if (accountDetailVO != null && accountDetailVO.getValue() != null) { - return accountDetailVO.getValue(); - } break; - default: - } - } - } - return _configDao.getValue(name); - } @Override public List getConfigListByScope(String scope, Long resourceId) { @@ -755,7 +689,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio List configVOList = new ArrayList(); for (Config param:configList){ ConfigurationVO configVo = _configDao.findByName(param.toString()); - configVo.setValue(getConfigValue(param.toString(), scope, resourceId)); + configVo.setValue(_configDepot.get(param.toString()).valueIn(resourceId).toString()); configVOList.add(configVo); } return configVOList; diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 069a1d819de..a10f0a0ba24 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -429,6 +429,8 @@ import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationSer import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.ConfigValue; import org.apache.cloudstack.framework.config.ConfigurationVO; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.storage.datastore.db.ImageStoreDao; @@ -452,6 +454,7 @@ import com.cloud.capacity.dao.CapacityDao; import com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity; import com.cloud.cluster.ClusterManager; import com.cloud.configuration.Config; +import com.cloud.configuration.ConfigurationManager; import com.cloud.consoleproxy.ConsoleProxyManagementState; import com.cloud.consoleproxy.ConsoleProxyManager; import com.cloud.dc.AccountVlanMapVO; @@ -555,6 +558,7 @@ import com.cloud.utils.Pair; import com.cloud.utils.PasswordGenerator; import com.cloud.utils.Ternary; import com.cloud.utils.component.ComponentLifecycle; +import com.cloud.utils.component.InjectConfig; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.crypt.DBEncryptionUtil; @@ -702,6 +706,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe VolumeDataFactory _volFactory; @Inject AccountService _accountService; + @Inject + ConfigurationManager _configMgr; @Inject DeploymentPlanningManager _dpMgr; @@ -1625,22 +1631,22 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe int paramCountCheck = 0; if (zoneId != null) { - scope = Config.ConfigurationParameterScope.zone.toString(); + scope = ConfigKey.Scope.Zone.toString(); id = zoneId; paramCountCheck++; } if (clusterId != null) { - scope = Config.ConfigurationParameterScope.cluster.toString(); + scope = ConfigKey.Scope.Cluster.toString(); id = clusterId; paramCountCheck++; } if (accountId != null) { - scope = Config.ConfigurationParameterScope.account.toString(); + scope = ConfigKey.Scope.Account.toString(); id = accountId; paramCountCheck++; } if (storagepoolId != null) { - scope = Config.ConfigurationParameterScope.storagepool.toString(); + scope = ConfigKey.Scope.StoragePool.toString(); id = storagepoolId; paramCountCheck++; } @@ -3232,6 +3238,9 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe return cloudParams; } + + @InjectConfig(key = TemplateManager.AllowPublicUserTemplatesCK) + ConfigValue _allowPublicUserTemplates; @Override public Map listCapabilities(ListCapabilitiesCmd cmd) { @@ -3256,7 +3265,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe long diskOffMaxSize = Long.valueOf(_configDao.getValue(Config.CustomDiskOfferingMaxSize.key())); - String userPublicTemplateEnabled = _configServer.getConfigValue(Config.AllowPublicUserTemplates.key(), Config.ConfigurationParameterScope.account.toString(), caller.getId()); + boolean userPublicTemplateEnabled = _allowPublicUserTemplates.valueIn(caller.getId()); // add some parameters UI needs to handle API throttling boolean apiLimitEnabled = Boolean.parseBoolean(_configDao.getValue(Config.ApiLimitEnabled.key())); @@ -3271,8 +3280,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe } capabilities.put("securityGroupsEnabled", securityGroupsEnabled); - capabilities - .put("userPublicTemplateEnabled", (userPublicTemplateEnabled == null || userPublicTemplateEnabled.equals("false") ? false : true)); + capabilities.put("userPublicTemplateEnabled", userPublicTemplateEnabled); capabilities.put("cloudStackVersion", getVersion()); capabilities.put("supportELB", supportELB); capabilities.put("projectInviteRequired", _projectMgr.projectInviteRequired()); diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index c13837335ac..e89d0fd0d9d 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -73,6 +73,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult; import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; import org.apache.cloudstack.framework.async.AsyncCallFuture; +import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.storage.datastore.db.ImageStoreDao; import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao; @@ -282,9 +283,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C private int _createVolumeFromSnapshotWait; private int _copyvolumewait; int _storagePoolAcquisitionWaitSeconds = 1800; // 30 minutes - protected int _retry = 2; - protected int _pingInterval = 60; // seconds - protected int _hostRetry; // protected BigDecimal _overProvisioningFactor = new BigDecimal(1); private long _maxVolumeSizeInGb; private long _serverId; @@ -444,9 +442,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C Map configs = _configDao.getConfiguration("management-server", params); - _retry = NumbersUtil.parseInt(configs.get(Config.StartRetry.key()), 10); - _pingInterval = NumbersUtil.parseInt(configs.get("ping.interval"), 60); - _hostRetry = NumbersUtil.parseInt(configs.get("host.retry"), 2); _storagePoolAcquisitionWaitSeconds = NumbersUtil.parseInt(configs.get("pool.acquisition.wait.seconds"), 1800); s_logger.info("pool.acquisition.wait.seconds is configured as " + _storagePoolAcquisitionWaitSeconds + " seconds"); @@ -894,7 +889,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C @Override public BigDecimal getStorageOverProvisioningFactor(Long dcId) { return new BigDecimal(_configServer.getConfigValue(Config.StorageOverprovisioningFactor.key(), - Config.ConfigurationParameterScope.zone.toString(), dcId)); + ConfigKey.Scope.Zone.toString(), dcId)); } @Override @@ -1504,7 +1499,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C private boolean checkUsagedSpace(StoragePool pool) { StatsCollector sc = StatsCollector.getInstance(); double storageUsedThreshold = Double.parseDouble(_configServer.getConfigValue(Config.StorageCapacityDisableThreshold.key(), - Config.ConfigurationParameterScope.zone.toString(), pool.getDataCenterId())); + ConfigKey.Scope.Zone.toString(), pool.getDataCenterId())); if (sc != null) { long totalSize = pool.getCapacityBytes(); StorageStats stats = sc.getStoragePoolStats(pool.getId()); @@ -1610,7 +1605,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C } double storageAllocatedThreshold = Double.parseDouble(_configServer.getConfigValue(Config.StorageAllocatedCapacityDisableThreshold.key(), - Config.ConfigurationParameterScope.zone.toString(), pool.getDataCenterId())); + ConfigKey.Scope.Zone.toString(), pool.getDataCenterId())); if (s_logger.isDebugEnabled()) { s_logger.debug("Checking pool: " + pool.getId() + " for volume allocation " + volumes.toString() + ", maxSize : " + totalOverProvCapacity + ", totalAllocatedSize : " + allocatedSizeWithtemplate + ", askingSize : " + totalAskingSize + ", allocated disable threshold: " diff --git a/server/src/com/cloud/template/TemplateAdapterBase.java b/server/src/com/cloud/template/TemplateAdapterBase.java index 6f38c84255c..e75e699630e 100755 --- a/server/src/com/cloud/template/TemplateAdapterBase.java +++ b/server/src/com/cloud/template/TemplateAdapterBase.java @@ -30,13 +30,13 @@ import org.apache.cloudstack.api.command.user.template.DeleteTemplateCmd; import org.apache.cloudstack.api.command.user.template.ExtractTemplateCmd; import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd; import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.framework.config.ConfigValue; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.storage.datastore.db.ImageStoreDao; import org.apache.cloudstack.storage.datastore.db.ImageStoreVO; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; import com.cloud.api.ApiDBUtils; -import com.cloud.configuration.Config; import com.cloud.configuration.Resource.ResourceType; import com.cloud.dc.DataCenterVO; import com.cloud.dc.dao.DataCenterDao; @@ -91,6 +91,10 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat @Inject ConfigurationServer _configServer; @Inject ProjectManager _projectMgr; + @InjectConfig(key = TemplateManager.AllowPublicUserTemplatesCK) + ConfigValue _allowPublicUserTemplates; + + @Override public boolean stop() { return true; @@ -170,7 +174,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat } // check whether owner can create public templates - boolean allowPublicUserTemplates = Boolean.parseBoolean(_configServer.getConfigValue(Config.AllowPublicUserTemplates.key(), Config.ConfigurationParameterScope.account.toString(), templateOwner.getId())); + boolean allowPublicUserTemplates = _allowPublicUserTemplates.valueIn(templateOwner.getId()); if (!isAdmin && !allowPublicUserTemplates && isPublic) { throw new InvalidParameterValueException("Only private templates/ISO can be created."); } @@ -216,10 +220,10 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat } Long id = _tmpltDao.getNextInSequence(Long.class, "id"); - CallContext.current().setEventDetails("Id: " +id+ " name: " + name); - return new TemplateProfile(id, userId, name, displayText, bits, passwordEnabled, requiresHVM, url, isPublic, - featured, isExtractable, imgfmt, guestOSId, zoneId, hypervisorType, templateOwner.getAccountName(), templateOwner.getDomainId(), - templateOwner.getAccountId(), chksum, bootable, templateTag, details, sshkeyEnabled, null, isDynamicallyScalable, templateType); + CallContext.current().setEventDetails("Id: " + id + " name: " + name); + return new TemplateProfile(id, userId, name, displayText, bits, passwordEnabled, requiresHVM, url, isPublic, featured, isExtractable, imgfmt, guestOSId, zoneId, + hypervisorType, templateOwner.getAccountName(), templateOwner.getDomainId(), templateOwner.getAccountId(), chksum, bootable, templateTag, details, sshkeyEnabled, null, + isDynamicallyScalable, templateType); } @@ -284,7 +288,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat } template.setCrossZones(true); - for (DataCenterVO dc: dcs) { + for (DataCenterVO dc : dcs) { _tmpltDao.addTemplateToZone(template, dc.getId()); } @@ -386,7 +390,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat throw new InvalidParameterValueException("unable to find iso with id " + templateId); } - userId = accountAndUserValidation(account, userId, null, template, "Unable to delete iso " ); + userId = accountAndUserValidation(account, userId, null, template, "Unable to delete iso "); UserVO user = _userDao.findById(userId); if (user == null) { @@ -402,6 +406,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat @Override abstract public VMTemplateVO create(TemplateProfile profile); + @Override abstract public boolean delete(TemplateProfile profile); } diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index 8a5435503b9..3e6e71c6740 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -69,6 +69,9 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; import org.apache.cloudstack.framework.async.AsyncCallFuture; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.ConfigValue; +import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.jobs.AsyncJobManager; import org.apache.cloudstack.storage.command.AttachCommand; @@ -170,6 +173,7 @@ import com.cloud.utils.EnumUtils; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; import com.cloud.utils.component.AdapterBase; +import com.cloud.utils.component.InjectConfig; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.DB; @@ -183,8 +187,11 @@ import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.VMInstanceDao; @Local(value = { TemplateManager.class, TemplateApiService.class }) -public class TemplateManagerImpl extends ManagerBase implements TemplateManager, TemplateApiService { +public class TemplateManagerImpl extends ManagerBase implements TemplateManager, TemplateApiService, Configurable { private final static Logger s_logger = Logger.getLogger(TemplateManagerImpl.class); + @InjectConfig(key = TemplateManager.AllowPublicUserTemplatesCK) + ConfigValue _allowPublicUserTemplates; + @Inject VMTemplateDao _tmpltDao; @Inject @@ -1213,8 +1220,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, boolean isAdmin = _accountMgr.isAdmin(caller.getType()); // check configuration parameter(allow.public.user.templates) value for // the template owner - boolean allowPublicUserTemplates = Boolean.valueOf(_configServer.getConfigValue(Config.AllowPublicUserTemplates.key(), - Config.ConfigurationParameterScope.account.toString(), template.getAccountId())); + boolean allowPublicUserTemplates = _allowPublicUserTemplates.valueIn(template.getAccountId()); if (!isAdmin && !allowPublicUserTemplates && isPublic != null && isPublic) { throw new InvalidParameterValueException("Only private " + mediaType + "s can be created."); } @@ -1476,8 +1482,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, } boolean isDynamicScalingEnabled = cmd.isDynamicallyScalable(); // check whether template owner can create public templates - boolean allowPublicUserTemplates = Boolean.parseBoolean(_configServer.getConfigValue(Config.AllowPublicUserTemplates.key(), - Config.ConfigurationParameterScope.account.toString(), templateOwner.getId())); + boolean allowPublicUserTemplates = _allowPublicUserTemplates.valueIn(templateOwner.getId()); if (!isAdmin && !allowPublicUserTemplates && isPublic) { throw new PermissionDeniedException("Failed to create template " + name + ", only private templates can be created."); } @@ -1792,4 +1797,14 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, return _tmpltDao.findById(id); } + + @Override + public String getConfigComponentName() { + return TemplateManager.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[] {AllowPublicUserTemplates}; + } } diff --git a/server/src/com/cloud/vm/UserVmManager.java b/server/src/com/cloud/vm/UserVmManager.java index 635d15e76e1..e1bee8d1b31 100755 --- a/server/src/com/cloud/vm/UserVmManager.java +++ b/server/src/com/cloud/vm/UserVmManager.java @@ -20,6 +20,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.cloudstack.framework.config.ConfigKey; + import com.cloud.agent.api.VmDiskStatsEntry; import com.cloud.agent.api.VmStatsEntry; import com.cloud.api.query.vo.UserVmJoinVO; @@ -39,6 +41,10 @@ import com.cloud.utils.Pair; * */ public interface UserVmManager extends UserVmService { + static final String EnableDynamicallyScaleVmCK = "enable.dynamic.scale.vm"; + static final ConfigKey EnableDynamicallyScaleVm = new ConfigKey("Advanced", Boolean.class, EnableDynamicallyScaleVmCK, "false", + "Enables/Diables dynamically scaling a vm", true, ConfigKey.Scope.Zone); + static final int MAX_USER_DATA_LENGTH_BYTES = 2048; /** diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 326b96b97eb..2d6557cb2d9 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -68,6 +68,9 @@ import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationSer import org.apache.cloudstack.engine.service.api.OrchestrationService; import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory; import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.ConfigValue; +import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.jobs.AsyncJobManager; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; @@ -258,9 +261,8 @@ import com.cloud.vm.snapshot.VMSnapshotVO; import com.cloud.vm.snapshot.dao.VMSnapshotDao; @Local(value = { UserVmManager.class, UserVmService.class }) -public class UserVmManagerImpl extends ManagerBase implements UserVmManager, VirtualMachineGuru, UserVmService { - private static final Logger s_logger = Logger - .getLogger(UserVmManagerImpl.class); +public class UserVmManagerImpl extends ManagerBase implements UserVmManager, VirtualMachineGuru, UserVmService, Configurable { + private static final Logger s_logger = Logger.getLogger(UserVmManagerImpl.class); private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 3; // 3 // seconds @@ -270,6 +272,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir linked } + @InjectConfig(key = EnableDynamicallyScaleVmCK) + ConfigValue _enableDynamicallyScaleVm; + @Inject EntityManager _entityMgr; @Inject @@ -442,8 +447,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir protected int _scaleRetry; @Inject ConfigurationDao _configDao; - private int _createprivatetemplatefromvolumewait; - private int _createprivatetemplatefromsnapshotwait; private final int MAX_VM_NAME_LEN = 80; private final int MAX_HTTP_GET_LENGTH = 2 * MAX_USER_DATA_LENGTH_BYTES; private final int MAX_HTTP_POST_LENGTH = 16 * MAX_USER_DATA_LENGTH_BYTES; @@ -605,15 +608,15 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir Long vmId = cmd.getId(); UserVmVO userVm = _vmDao.findById(cmd.getId()); + if (userVm == null) { + throw new InvalidParameterValueException("unable to find a virtual machine by id" + cmd.getId()); + } + _vmDao.loadDetails(userVm); VMTemplateVO template = _templateDao.findByIdIncludingRemoved(userVm.getTemplateId()); // Do parameters input validation - if (userVm == null) { - throw new InvalidParameterValueException("unable to find a virtual machine by id" + cmd.getId()); - } - if (userVm.getState() == State.Error || userVm.getState() == State.Expunging) { s_logger.error("vm is not in the right state: " + vmId); throw new InvalidParameterValueException("Vm with specified id is not in the right state"); @@ -714,8 +717,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } User user = _userDao.findById(userId); - Account account = _accountDao.findById(user.getAccountId()); - try { VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid()); status = vmEntity.stop(new Long(userId).toString()); @@ -1269,7 +1270,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir if (vmInstance.getState().equals(State.Running)) { int retry = _scaleRetry; ExcludeList excludes = new ExcludeList(); - boolean enableDynamicallyScaleVm = Boolean.parseBoolean(_configServer.getConfigValue(Config.EnableDynamicallyScaleVm.key(), Config.ConfigurationParameterScope.zone.toString(), vmInstance.getDataCenterId())); + boolean enableDynamicallyScaleVm = _enableDynamicallyScaleVm.valueIn(vmInstance.getDataCenterId()); if(!enableDynamicallyScaleVm){ throw new PermissionDeniedException("Dynamically scaling virtual machines is disabled for this zone, please contact your admin"); } @@ -1496,19 +1497,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir _instance = "DEFAULT"; } - String value = _configDao - .getValue(Config.CreatePrivateTemplateFromVolumeWait.toString()); - _createprivatetemplatefromvolumewait = NumbersUtil.parseInt(value, - Integer.parseInt(Config.CreatePrivateTemplateFromVolumeWait - .getDefaultValue())); - - value = _configDao - .getValue(Config.CreatePrivateTemplateFromSnapshotWait - .toString()); - _createprivatetemplatefromsnapshotwait = NumbersUtil.parseInt(value, - Integer.parseInt(Config.CreatePrivateTemplateFromSnapshotWait - .getDefaultValue())); - String workers = configs.get("expunge.workers"); int wrks = NumbersUtil.parseInt(workers, 10); capacityReleaseInterval = NumbersUtil.parseInt(_configDao.getValue(Config.CapacitySkipcountingHours.key()), 3600); @@ -1770,12 +1758,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } - private static boolean isAdmin(short accountType) { - return ((accountType == Account.ACCOUNT_TYPE_ADMIN) - || (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) - || (accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN)); - } - @Override @ActionEvent(eventType = EventTypes.EVENT_VM_UPDATE, eventDescription = "updating Vm") public UserVm updateVirtualMachine(UpdateVMCmd cmd) @@ -4903,4 +4885,16 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } } + @Override + public String getConfigComponentName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public ConfigKey[] getConfigKeys() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/server/test/com/cloud/network/MockNetworkModelImpl.java b/server/test/com/cloud/network/MockNetworkModelImpl.java index 92e4cb1c5bf..8a9da832304 100644 --- a/server/test/com/cloud/network/MockNetworkModelImpl.java +++ b/server/test/com/cloud/network/MockNetworkModelImpl.java @@ -258,14 +258,6 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel { return null; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkModel#getGlobalGuestDomainSuffix() - */ - @Override - public String getGlobalGuestDomainSuffix() { - // TODO Auto-generated method stub - return null; - } /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getStartIpAddress(long) @@ -564,15 +556,6 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel { return null; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkModel#getDefaultNetworkDomain() - */ - @Override - public String getDefaultNetworkDomain(long zoneId) { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getNtwkOffDistinctProviders(long) */ @@ -870,6 +853,7 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel { return null; } + @Override public IsolationType[] listNetworkIsolationMethods() { // TODO Auto-generated method stub return null; diff --git a/server/test/com/cloud/network/MockRulesManagerImpl.java b/server/test/com/cloud/network/MockRulesManagerImpl.java deleted file mode 100644 index 331a47ffca6..00000000000 --- a/server/test/com/cloud/network/MockRulesManagerImpl.java +++ /dev/null @@ -1,258 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.network; - -import java.util.List; -import java.util.Map; - -import javax.ejb.Local; -import javax.naming.ConfigurationException; - -import org.apache.cloudstack.api.command.user.firewall.ListPortForwardingRulesCmd; - -import com.cloud.exception.InsufficientAddressCapacityException; -import com.cloud.exception.NetworkRuleConflictException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.network.rules.FirewallRule; -import com.cloud.network.rules.FirewallRuleVO; -import com.cloud.network.rules.PortForwardingRule; -import com.cloud.network.rules.PortForwardingRuleVO; -import com.cloud.network.rules.RulesManager; -import com.cloud.network.rules.RulesService; -import com.cloud.network.rules.StaticNatRule; -import com.cloud.network.rules.FirewallRule.Purpose; -import com.cloud.user.Account; -import com.cloud.uservm.UserVm; -import com.cloud.utils.Pair; -import com.cloud.utils.component.Manager; -import com.cloud.utils.component.ManagerBase; -import com.cloud.utils.net.Ip; -import com.cloud.vm.Nic; -import com.cloud.vm.VirtualMachine; - -@Local(value = {RulesManager.class, RulesService.class}) -public class MockRulesManagerImpl extends ManagerBase implements RulesManager, RulesService { - - @Override - public Pair, Integer> searchStaticNatRules( - Long ipId, Long id, Long vmId, Long start, Long size, - String accountName, Long domainId, Long projectId, - boolean isRecursive, boolean listAll) { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean revokePortForwardingRule(long ruleId, boolean apply) { - // TODO Auto-generated method stub - return false; - } - - @Override - public Pair, Integer> listPortForwardingRules( - ListPortForwardingRulesCmd cmd) { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean applyPortForwardingRules(long ipAdddressId, Account caller) - throws ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean enableStaticNat(long ipAddressId, long vmId, long networkId, - String ipAddr) throws NetworkRuleConflictException, ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - @Override - public PortForwardingRule getPortForwardigRule(long ruleId) { - // TODO Auto-generated method stub - return null; - } - - @Override - public FirewallRule getFirewallRule(long ruleId) { - // TODO Auto-generated method stub - return null; - } - - @Override - public StaticNatRule createStaticNatRule(StaticNatRule rule, - boolean openFirewall) throws NetworkRuleConflictException { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean revokeStaticNatRule(long ruleId, boolean apply) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean applyStaticNatRules(long ipAdddressId, Account caller) - throws ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - @Override - public StaticNatRule buildStaticNatRule(FirewallRule rule, boolean forRevoke) { - // TODO Auto-generated method stub - return null; - } - - @Override - public List getSourceCidrs(long ruleId) { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean disableStaticNat(long ipId) - throws ResourceUnavailableException, NetworkRuleConflictException, - InsufficientAddressCapacityException { - // TODO Auto-generated method stub - return false; - } - - - @Override - public boolean applyPortForwardingRulesForNetwork(long networkId, - boolean continueOnError, Account caller) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean applyStaticNatRulesForNetwork(long networkId, - boolean continueOnError, Account caller) { - // TODO Auto-generated method stub - return false; - } - - @Override - public void checkRuleAndUserVm(FirewallRule rule, UserVm userVm, - Account caller) { - // TODO Auto-generated method stub - - } - - @Override - public boolean revokeAllPFAndStaticNatRulesForIp(long ipId, long userId, - Account caller) throws ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean revokeAllPFStaticNatRulesForNetwork(long networkId, - long userId, Account caller) throws ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - - @Override - public boolean revokePortForwardingRulesForVm(long vmId) { - // TODO Auto-generated method stub - return false; - } - - - @Override - public FirewallRule[] reservePorts(IpAddress ip, String protocol, - Purpose purpose, boolean openFirewall, Account caller, int... ports) - throws NetworkRuleConflictException { - // TODO Auto-generated method stub - return null; - } - - - @Override - public boolean applyStaticNatsForNetwork(long networkId, - boolean continueOnError, Account caller) { - // TODO Auto-generated method stub - return false; - } - - @Override - public void getSystemIpAndEnableStaticNatForVm(VirtualMachine vm, - boolean getNewIp) throws InsufficientAddressCapacityException { - // TODO Auto-generated method stub - - } - - @Override - public boolean disableStaticNat(long ipAddressId, Account caller, - long callerUserId, boolean releaseIpIfElastic) - throws ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean applyStaticNatForNetwork(long networkId, - boolean continueOnError, Account caller, boolean forRevoke) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean configure(String name, Map params) - throws ConfigurationException { - - return true; - } - - @Override - public boolean start() { - return true; - } - - @Override - public boolean stop() { - // TODO Auto-generated method stub - return false; - } - - @Override - public String getName() { - // TODO Auto-generated method stub - return "MockRulesManagerImpl"; - } - - @Override - public PortForwardingRule createPortForwardingRule(PortForwardingRule rule, - Long vmId, Ip vmIp, boolean openFirewall) - throws NetworkRuleConflictException { - // TODO Auto-generated method stub - return null; - } - - @Override - public List listAssociatedRulesForGuestNic(Nic nic) { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java index aa376bc0133..003b7742afd 100644 --- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java @@ -939,19 +939,6 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkOrches } - - - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#getNetworkLockTimeout() - */ - @Override - public int getNetworkLockTimeout() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) * @see com.cloud.network.NetworkManager#restartNetwork(java.lang.Long, com.cloud.user.Account, com.cloud.user.User, boolean) */ diff --git a/server/test/com/cloud/vpc/MockNetworkModelImpl.java b/server/test/com/cloud/vpc/MockNetworkModelImpl.java index 9fbc65a8cb9..992a81da126 100644 --- a/server/test/com/cloud/vpc/MockNetworkModelImpl.java +++ b/server/test/com/cloud/vpc/MockNetworkModelImpl.java @@ -267,15 +267,6 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel { return null; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkModel#getGlobalGuestDomainSuffix() - */ - @Override - public String getGlobalGuestDomainSuffix() { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getStartIpAddress(long) */ @@ -579,15 +570,6 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel { return null; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkModel#getDefaultNetworkDomain() - */ - @Override - public String getDefaultNetworkDomain(long zoneId) { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getNtwkOffDistinctProviders(long) */ @@ -882,6 +864,7 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel { return null; } + @Override public IsolationType[] listNetworkIsolationMethods() { // TODO Auto-generated method stub return null; diff --git a/server/test/com/cloud/vpc/MockVpcManagerImpl.java b/server/test/com/cloud/vpc/MockVpcManagerImpl.java deleted file mode 100644 index 7e40083c8bd..00000000000 --- a/server/test/com/cloud/vpc/MockVpcManagerImpl.java +++ /dev/null @@ -1,386 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.vpc; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.ejb.Local; -import javax.inject.Inject; -import javax.naming.ConfigurationException; - -import org.apache.cloudstack.acl.ControlledEntity; -import org.apache.cloudstack.acl.ControlledEntity.ACLType; -import org.apache.cloudstack.api.command.user.vpc.ListPrivateGatewaysCmd; -import org.apache.cloudstack.api.command.user.vpc.ListStaticRoutesCmd; -import org.springframework.stereotype.Component; - -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InsufficientAddressCapacityException; -import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.NetworkRuleConflictException; -import com.cloud.exception.ResourceAllocationException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.network.IpAddress; -import com.cloud.network.Network; -import com.cloud.network.Network.Provider; -import com.cloud.network.Network.Service; -import com.cloud.network.PhysicalNetwork; -import com.cloud.network.addr.PublicIp; -import com.cloud.network.vpc.PrivateGateway; -import com.cloud.network.vpc.StaticRoute; -import com.cloud.network.vpc.Vpc; -import com.cloud.network.vpc.VpcGateway; -import com.cloud.network.vpc.VpcManager; -import com.cloud.network.vpc.VpcService; -import com.cloud.offering.NetworkOffering; -import com.cloud.user.Account; -import com.cloud.utils.Pair; -import com.cloud.utils.component.ManagerBase; -import com.cloud.vpc.dao.MockVpcDaoImpl; - -@Component -@Local(value = { VpcManager.class, VpcService.class }) -public class MockVpcManagerImpl extends ManagerBase implements VpcManager { - @Inject MockVpcDaoImpl _vpcDao; - - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#getVpc(long) - */ - @Override - public Vpc getVpc(long vpcId) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#getActiveVpc(long) - */ - @Override - public Vpc getActiveVpc(long vpcId) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#getVpcNetworks(long) - */ - @Override - public List getVpcNetworks(long vpcId) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#createVpc(long, long, long, java.lang.String, java.lang.String, java.lang.String, java.lang.String) - */ - @Override - public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr, String networkDomain) throws ResourceAllocationException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#deleteVpc(long) - */ - @Override - public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#updateVpc(long, java.lang.String, java.lang.String) - */ - @Override - public Vpc updateVpc(long vpcId, String vpcName, String displayText) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#listVpcs(java.lang.Long, java.lang.String, java.lang.String, java.util.List, java.lang.String, java.lang.Long, java.lang.String, java.lang.String, java.lang.Long, java.lang.String, java.lang.Long, java.lang.Long, java.lang.Long, java.lang.Boolean, java.lang.Boolean, java.lang.Boolean, java.util.Map, java.lang.Long) - */ - @Override - public List listVpcs(Long id, String vpcName, String displayText, List supportedServicesStr, String cidr, Long vpcOffId, String state, String accountName, Long domainId, String keyword, - Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll, Boolean restartRequired, Map tags, Long projectId) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#startVpc(long, boolean) - */ - @Override - public boolean startVpc(long vpcId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#shutdownVpc(long) - */ - @Override - public boolean shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#restartVpc(long) - */ - @Override - public boolean restartVpc(long id) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#getVpcPrivateGateway(long) - */ - @Override - public PrivateGateway getVpcPrivateGateway(long id) { - // TODO Auto-generated method stub - return null; - } - - @Override - public PrivateGateway createVpcPrivateGateway(long vpcId, Long physicalNetworkId, String vlan, String ipAddress, String gateway, String netmask, long gatewayOwnerId, Boolean isSoruceNat, Long aclId) throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException { - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#createVpcPrivateGateway(long, java.lang.Long, java.lang.String, java.lang.String, java.lang.String, java.lang.String, long) - */ - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#applyVpcPrivateGateway(long, boolean) - */ - @Override - public PrivateGateway applyVpcPrivateGateway(long gatewayId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#deleteVpcPrivateGateway(long) - */ - @Override - public boolean deleteVpcPrivateGateway(long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#listPrivateGateway(org.apache.cloudstack.api.commands.ListPrivateGatewaysCmd) - */ - @Override - public Pair, Integer> listPrivateGateway(ListPrivateGatewaysCmd listPrivateGatewaysCmd) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#getStaticRoute(long) - */ - @Override - public StaticRoute getStaticRoute(long routeId) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#applyStaticRoutes(long) - */ - @Override - public boolean applyStaticRoutes(long vpcId) throws ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#revokeStaticRoute(long) - */ - @Override - public boolean revokeStaticRoute(long routeId) throws ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#createStaticRoute(long, java.lang.String) - */ - @Override - public StaticRoute createStaticRoute(long gatewayId, String cidr) throws NetworkRuleConflictException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#listStaticRoutes(org.apache.cloudstack.api.commands.ListStaticRoutesCmd) - */ - @Override - public Pair, Integer> listStaticRoutes(ListStaticRoutesCmd cmd) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#getVpcGateway(long) - */ - @Override - public VpcGateway getVpcGateway(long id) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcService#associateIPToVpc(long, long) - */ - @Override - public IpAddress associateIPToVpc(long ipId, long vpcId) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcManager#getVpcsForAccount(long) - */ - @Override - public List getVpcsForAccount(long accountId) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcManager#destroyVpc(com.cloud.network.vpc.Vpc) - */ - @Override - public boolean destroyVpc(Vpc vpc, Account caller, Long callerUserId) throws ConcurrentOperationException, ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcManager#ipUsedInVpc(com.cloud.network.IpAddress) - */ - @Override - public boolean isIpAllocatedToVpc(IpAddress ip) { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcManager#unassignIPFromVpcNetwork(long, long) - */ - @Override - public void unassignIPFromVpcNetwork(long ipId, long networkId) { - // TODO Auto-generated method stub - - } - - @Override - public Network createVpcGuestNetwork(long ntwkOffId, String name, String displayText, String gateway, String cidr, String vlanId, String networkDomain, Account owner, Long domainId, PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, long vpcId, Long aclId, Account caller, Boolean displayNetworkEnabled) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcManager#assignSourceNatIpAddressToVpc(com.cloud.user.Account, com.cloud.network.vpc.Vpc) - */ - @Override - public PublicIp assignSourceNatIpAddressToVpc(Account owner, Vpc vpc) throws InsufficientAddressCapacityException, ConcurrentOperationException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.utils.component.Manager#configure(java.lang.String, java.util.Map) - */ - @Override - public boolean configure(String name, Map params) throws ConfigurationException { - // TODO Auto-generated method stub - return true; - } - - /* (non-Javadoc) - * @see com.cloud.utils.component.Manager#start() - */ - @Override - public boolean start() { - // TODO Auto-generated method stub - return true; - } - - /* (non-Javadoc) - * @see com.cloud.utils.component.Manager#stop() - */ - @Override - public boolean stop() { - // TODO Auto-generated method stub - return true; - } - - /* (non-Javadoc) - * @see com.cloud.utils.component.Manager#getName() - */ - @Override - public String getName() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcManager#validateNtwkOffForVpc(com.cloud.offering.NetworkOffering, java.util.List) - */ - @Override - public void validateNtwkOffForVpc(NetworkOffering guestNtwkOff, List supportedSvcs) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see com.cloud.network.vpc.VpcManager#getSupportedVpcHypervisors() - */ - @Override - public List getSupportedVpcHypervisors() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Map> getVpcOffSvcProvidersMap(long vpcOffId) { - // TODO Auto-generated method stub - return null; - } - - @Override - public void validateNtwkOffForNtwkInVpc(Long networkId, long newNtwkOffId, String newCidr, String newNetworkDomain, Vpc vpc, String gateway, Account networkOwner, Long aclId) { - // TODO Auto-generated method stub - - } - - @Override - public List getVpcPrivateGateways(long vpcId) { - return null; - } - -} diff --git a/server/test/com/cloud/vpc/NetworkACLServiceTest.java b/server/test/com/cloud/vpc/NetworkACLServiceTest.java index 2eb82738716..aa37810d5b2 100644 --- a/server/test/com/cloud/vpc/NetworkACLServiceTest.java +++ b/server/test/com/cloud/vpc/NetworkACLServiceTest.java @@ -54,6 +54,7 @@ import com.cloud.network.vpc.NetworkACLManager; import com.cloud.network.vpc.NetworkACLService; import com.cloud.network.vpc.NetworkACLServiceImpl; import com.cloud.network.vpc.NetworkACLVO; +import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.VpcManager; import com.cloud.network.vpc.VpcVO; import com.cloud.network.vpc.dao.NetworkACLDao; @@ -64,6 +65,7 @@ import com.cloud.user.AccountManager; import com.cloud.user.AccountVO; import com.cloud.user.UserVO; import com.cloud.utils.component.ComponentContext; +import com.cloud.utils.db.EntityManager; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) @@ -81,6 +83,8 @@ public class NetworkACLServiceTest extends TestCase{ NetworkACLDao _networkACLDao; @Inject NetworkACLItemDao _networkACLItemDao; + @Inject + EntityManager _entityMgr; private CreateNetworkACLCmd createACLItemCmd; private NetworkACLVO acl; @@ -143,7 +147,7 @@ public class NetworkACLServiceTest extends TestCase{ @Test public void testCreateACL() throws Exception { - Mockito.when(_vpcMgr.getVpc(Mockito.anyLong())).thenReturn(new VpcVO()); + Mockito.when(_entityMgr.findById(Vpc.class, Mockito.anyLong())).thenReturn(new VpcVO()); Mockito.when(_networkAclMgr.createNetworkACL("acl_new", "acl desc", 1L)).thenReturn(acl); assertNotNull(_aclService.createNetworkACL("acl_new", "acl desc", 1L)); } @@ -157,7 +161,7 @@ public class NetworkACLServiceTest extends TestCase{ @Test public void testCreateACLItem() throws Exception { - Mockito.when(_vpcMgr.getVpc(Mockito.anyLong())).thenReturn(new VpcVO()); + Mockito.when(_entityMgr.findById(Vpc.class, Mockito.anyLong())).thenReturn(new VpcVO()); Mockito.when(_networkAclMgr.getNetworkACL(Mockito.anyLong())).thenReturn(acl); Mockito.when(_networkAclMgr.createNetworkACLItem(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString(), Mockito.anyList(), Mockito.anyInt(), Mockito.anyInt(), Mockito.any(NetworkACLItem.TrafficType.class), Mockito.anyLong(), Mockito.anyString(), Mockito.anyInt())).thenReturn(new NetworkACLItemVO()); @@ -167,7 +171,7 @@ public class NetworkACLServiceTest extends TestCase{ @Test(expected = InvalidParameterValueException.class) public void testCreateACLItemDuplicateNumber() throws Exception { - Mockito.when(_vpcMgr.getVpc(Mockito.anyLong())).thenReturn(new VpcVO()); + Mockito.when(_entityMgr.findById(Vpc.class, Mockito.anyLong())).thenReturn(new VpcVO()); Mockito.when(_networkAclMgr.getNetworkACL(Mockito.anyLong())).thenReturn(acl); Mockito.when(_networkACLItemDao.findByAclAndNumber(Mockito.anyLong(), Mockito.anyInt())).thenReturn(new NetworkACLItemVO()); _aclService.createNetworkACLItem(createACLItemCmd); @@ -186,6 +190,11 @@ public class NetworkACLServiceTest extends TestCase{ useDefaultFilters=false) public static class NetworkACLTestConfiguration extends SpringUtils.CloudStackTestConfiguration{ + @Bean + public EntityManager entityManager() { + return Mockito.mock(EntityManager.class); + } + @Bean public AccountManager accountManager() { return Mockito.mock(AccountManager.class); diff --git a/server/test/com/cloud/vpc/VpcApiUnitTest.java b/server/test/com/cloud/vpc/VpcApiUnitTest.java index 400e00c8f3e..4fe21c53cc3 100644 --- a/server/test/com/cloud/vpc/VpcApiUnitTest.java +++ b/server/test/com/cloud/vpc/VpcApiUnitTest.java @@ -26,21 +26,22 @@ import junit.framework.TestCase; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.Network.Service; import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.VpcManagerImpl; +import com.cloud.network.vpc.VpcVO; import com.cloud.user.AccountVO; import com.cloud.utils.component.ComponentContext; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "classpath:/VpcTestContext.xml") +//@ContextConfiguration(locations = "classpath:/VpcTestContext.xml") public class VpcApiUnitTest extends TestCase{ @Inject VpcManagerImpl _vpcService = null; + @Override @Before public void setUp() throws Exception { ComponentContext.initComponentsLifeCycle(); @@ -85,9 +86,10 @@ public class VpcApiUnitTest extends TestCase{ public void validateNtwkOffForVpc() { //validate network offering //1) correct network offering + VpcVO vo = new VpcVO(1, "new vpc", "new vpc", 1, 1, 1, "0.0.0.0/0", "vpc domain"); boolean result = false; try { - _vpcService.validateNtwkOffForNtwkInVpc(2L, 1, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO(), null); + _vpcService.validateNtwkOffForNtwkInVpc(2L, 1, "0.0.0.0", "111-", vo, "10.1.1.1", new AccountVO(), null); result = true; } catch (Exception ex) { } finally { @@ -97,7 +99,7 @@ public class VpcApiUnitTest extends TestCase{ //2) invalid offering - source nat is not included result = false; try { - _vpcService.validateNtwkOffForNtwkInVpc(2L, 2, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO(), null); + _vpcService.validateNtwkOffForNtwkInVpc(2L, 2, "0.0.0.0", "111-", vo, "10.1.1.1", new AccountVO(), null); result = true; } catch (InvalidParameterValueException ex) { } finally { @@ -107,7 +109,7 @@ public class VpcApiUnitTest extends TestCase{ //3) invalid offering - conserve mode is off result = false; try { - _vpcService.validateNtwkOffForNtwkInVpc(2L, 3, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO(), null); + _vpcService.validateNtwkOffForNtwkInVpc(2L, 3, "0.0.0.0", "111-", vo, "10.1.1.1", new AccountVO(), null); result = true; } catch (InvalidParameterValueException ex) { } finally { @@ -117,7 +119,7 @@ public class VpcApiUnitTest extends TestCase{ //4) invalid offering - guest type shared result = false; try { - _vpcService.validateNtwkOffForNtwkInVpc(2L, 4, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO(), null); + _vpcService.validateNtwkOffForNtwkInVpc(2L, 4, "0.0.0.0", "111-", vo, "10.1.1.1", new AccountVO(), null); result = true; } catch (InvalidParameterValueException ex) { } finally { @@ -127,7 +129,7 @@ public class VpcApiUnitTest extends TestCase{ //5) Invalid offering - no redundant router support result = false; try { - _vpcService.validateNtwkOffForNtwkInVpc(2L, 5, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO(), null); + _vpcService.validateNtwkOffForNtwkInVpc(2L, 5, "0.0.0.0", "111-", vo, "10.1.1.1", new AccountVO(), null); result = true; } catch (InvalidParameterValueException ex) { } finally { @@ -139,7 +141,7 @@ public class VpcApiUnitTest extends TestCase{ // public void destroyVpc() { // boolean result = false; // try { -// result = _vpcService.destroyVpc(_vpcService.getVpc(1), new AccountVO(), 1L); +// result = _vpcService.destroyVpc(vo, new AccountVO(), 1L); // } catch (Exception ex) { // s_logger.debug(ex); // } finally { @@ -158,7 +160,7 @@ public class VpcApiUnitTest extends TestCase{ // } finally { // assertTrue("Delete vpc: TEST FAILED, vpc failed to delete" + result, result); // } -// +// // //delete non-existing offering // result = false; // try { diff --git a/server/test/com/cloud/vpc/VpcTest.java b/server/test/com/cloud/vpc/VpcTest.java index 53beb8921e4..d461a08be92 100644 --- a/server/test/com/cloud/vpc/VpcTest.java +++ b/server/test/com/cloud/vpc/VpcTest.java @@ -121,11 +121,11 @@ public class VpcTest extends TestCase { @Test public void testCreateVpc() throws Exception { Mockito.when( - _vpcMgr.createVpc(Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyString(), + _vpcService.createVpc(Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(vpc); Mockito.when(_vpcOfferinDao.persist(Mockito.any(VpcOfferingVO.class))).thenReturn( new VpcOfferingVO("test", "test", 1L)); - Vpc vpc1 = _vpcMgr.createVpc(1, 1, 1, "myVpc", "my Vpc", "10.0.0.0/16", "test"); + Vpc vpc1 = _vpcService.createVpc(1, 1, 1, "myVpc", "my Vpc", "10.0.0.0/16", "test"); assertNotNull("Vpc is created", vpc1); } diff --git a/utils/src/com/cloud/utils/component/ComponentLifecycleBase.java b/utils/src/com/cloud/utils/component/ComponentLifecycleBase.java index 98cabe72c9a..9ce64fa2ac0 100644 --- a/utils/src/com/cloud/utils/component/ComponentLifecycleBase.java +++ b/utils/src/com/cloud/utils/component/ComponentLifecycleBase.java @@ -16,20 +16,34 @@ // under the License. package com.cloud.utils.component; +import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; +import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.utils.ReflectUtil; + public class ComponentLifecycleBase implements ComponentLifecycle { protected String _name; protected int _runLevel; protected Map _configParams = new HashMap(); + @Inject + protected ConfigInjector _configInjector; public ComponentLifecycleBase() { _name = this.getClass().getSimpleName(); _runLevel = RUN_LEVEL_COMPONENT; + + for (Field field : ReflectUtil.getAllFieldsForClass(this.getClass(), Object.class)) { + InjectConfig config = field.getAnnotation(InjectConfig.class); + if (config != null) { + field.setAccessible(true); + _configInjector.inject(field, this, config.key()); + } + } } @Override