mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
Fixed format style in a bunch of files (replaced tabs with spaces as a part of it)
This commit is contained in:
parent
1f0ea28cc4
commit
1490e45a1c
@ -1,4 +1,5 @@
|
||||
/**
|
||||
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
@ -25,43 +26,41 @@ import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.BaseCmd.CommandType;
|
||||
import com.cloud.api.response.SecurityGroupResponse;
|
||||
import com.cloud.network.security.SecurityGroup;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(responseObject=SecurityGroupResponse.class, description="Creates a security group")
|
||||
@Implementation(responseObject = SecurityGroupResponse.class, description = "Creates a security group")
|
||||
public class CreateSecurityGroupCmd extends BaseCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(CreateSecurityGroupCmd.class.getName());
|
||||
|
||||
private static final String s_name = "createsecuritygroupresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ////////////// API parameters /////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="an optional account for the security group. Must be used with domainId.")
|
||||
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "an optional account for the security group. Must be used with domainId.")
|
||||
private String accountName;
|
||||
|
||||
@IdentityMapper(entityTableName="domain")
|
||||
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="an optional domainId for the security group. If the account parameter is used, domainId must also be used.")
|
||||
@IdentityMapper(entityTableName = "domain")
|
||||
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.LONG, description = "an optional domainId for the security group. If the account parameter is used, domainId must also be used.")
|
||||
private Long domainId;
|
||||
|
||||
@Parameter(name=ApiConstants.DESCRIPTION, type=CommandType.STRING, description="the description of the security group")
|
||||
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "the description of the security group")
|
||||
private String description;
|
||||
|
||||
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="name of the security group")
|
||||
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "name of the security group")
|
||||
private String securityGroupName;
|
||||
|
||||
@IdentityMapper(entityTableName="projects")
|
||||
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="Deploy vm for the project")
|
||||
@IdentityMapper(entityTableName = "projects")
|
||||
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.LONG, description = "Deploy vm for the project")
|
||||
private Long projectId;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////////// Accessors ///////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
public String getAccountName() {
|
||||
return accountName;
|
||||
@ -83,10 +82,9 @@ public class CreateSecurityGroupCmd extends BaseCmd {
|
||||
return projectId;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////// API Implementation///////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
@ -109,11 +107,12 @@ public class CreateSecurityGroupCmd extends BaseCmd {
|
||||
return account.getId();
|
||||
}
|
||||
|
||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are
|
||||
// tracked
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
public void execute() {
|
||||
SecurityGroup group = _securityGroupService.createSecurityGroup(this);
|
||||
if (group != null) {
|
||||
SecurityGroupResponse response = _responseGenerator.createSecurityGroupResponse(group);
|
||||
|
||||
@ -29,33 +29,33 @@ import com.cloud.api.response.InstanceGroupResponse;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.vm.InstanceGroup;
|
||||
|
||||
@Implementation(description="Creates a vm group", responseObject=InstanceGroupResponse.class)
|
||||
public class CreateVMGroupCmd extends BaseCmd{
|
||||
@Implementation(description = "Creates a vm group", responseObject = InstanceGroupResponse.class)
|
||||
public class CreateVMGroupCmd extends BaseCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(CreateVMGroupCmd.class.getName());
|
||||
|
||||
private static final String s_name = "createinstancegroupresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ////////////// API parameters /////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the instance group")
|
||||
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the instance group")
|
||||
private String groupName;
|
||||
|
||||
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account of the instance group. The account parameter must be used with the domainId parameter.")
|
||||
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "the account of the instance group. The account parameter must be used with the domainId parameter.")
|
||||
private String accountName;
|
||||
|
||||
@IdentityMapper(entityTableName="domain")
|
||||
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID of account owning the instance group")
|
||||
@IdentityMapper(entityTableName = "domain")
|
||||
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.LONG, description = "the domain ID of account owning the instance group")
|
||||
private Long domainId;
|
||||
|
||||
@IdentityMapper(entityTableName="projects")
|
||||
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="The project of the instance group")
|
||||
@IdentityMapper(entityTableName = "projects")
|
||||
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.LONG, description = "The project of the instance group")
|
||||
private Long projectId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////////// Accessors ///////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
@ -73,9 +73,9 @@ public class CreateVMGroupCmd extends BaseCmd{
|
||||
return projectId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////// API Implementation///////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
@ -93,7 +93,7 @@ public class CreateVMGroupCmd extends BaseCmd{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
public void execute() {
|
||||
InstanceGroup result = _userVmService.createVmGroup(this);
|
||||
if (result != null) {
|
||||
InstanceGroupResponse response = _responseGenerator.createInstanceGroupResponse(result);
|
||||
|
||||
@ -68,7 +68,8 @@ public interface ConfigurationService {
|
||||
* Create a service offering through the API
|
||||
*
|
||||
* @param cmd
|
||||
* the command object that specifies the name, number of cpu cores, amount of RAM, etc. for the service offering
|
||||
* the command object that specifies the name, number of cpu cores, amount of RAM, etc. for the service
|
||||
* offering
|
||||
* @return the newly created service offering if successful, null otherwise
|
||||
*/
|
||||
ServiceOffering createServiceOffering(CreateServiceOfferingCmd cmd);
|
||||
@ -130,13 +131,21 @@ public interface ConfigurationService {
|
||||
|
||||
/**
|
||||
* Creates a new pod based on the parameters specified in the command object
|
||||
* @param zoneId TODO
|
||||
* @param name TODO
|
||||
* @param startIp TODO
|
||||
* @param endIp TODO
|
||||
* @param gateway TODO
|
||||
* @param netmask TODO
|
||||
* @param allocationState TODO
|
||||
*
|
||||
* @param zoneId
|
||||
* TODO
|
||||
* @param name
|
||||
* TODO
|
||||
* @param startIp
|
||||
* TODO
|
||||
* @param endIp
|
||||
* TODO
|
||||
* @param gateway
|
||||
* TODO
|
||||
* @param netmask
|
||||
* TODO
|
||||
* @param allocationState
|
||||
* TODO
|
||||
* @return the new pod if successful, null otherwise
|
||||
* @throws
|
||||
* @throws
|
||||
@ -188,12 +197,14 @@ public interface ConfigurationService {
|
||||
boolean deleteZone(DeleteZoneCmd cmd);
|
||||
|
||||
/**
|
||||
* Adds a VLAN to the database, along with an IP address range. Can add three types of VLANs: (1) zone-wide VLANs on the
|
||||
* Adds a VLAN to the database, along with an IP address range. Can add three types of VLANs: (1) zone-wide VLANs on
|
||||
* the
|
||||
* virtual public network (2) pod-wide direct attached VLANs (3) account-specific direct attached VLANs
|
||||
*
|
||||
* @param userId
|
||||
* @param vlanType
|
||||
* - either "DomR" (VLAN for a virtual public network) or "DirectAttached" (VLAN for IPs that will be directly
|
||||
* - either "DomR" (VLAN for a virtual public network) or "DirectAttached" (VLAN for IPs that will be
|
||||
* directly
|
||||
* attached to UserVMs)
|
||||
* @param zoneId
|
||||
* @param accountId
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
package com.cloud.configuration;
|
||||
|
||||
public interface ResourceLimit extends Resource{
|
||||
public interface ResourceLimit extends Resource {
|
||||
|
||||
public Long getId();
|
||||
|
||||
|
||||
@ -132,4 +132,5 @@ public interface NetworkService {
|
||||
Network getExclusiveGuestNetwork(long zoneId);
|
||||
|
||||
List<Pair<TrafficType, String>> listTrafficTypeImplementor(ListTrafficTypeImplementorsCmd cmd);
|
||||
|
||||
}
|
||||
|
||||
@ -10,11 +10,14 @@ import com.cloud.user.Account;
|
||||
|
||||
public interface FirewallService {
|
||||
FirewallRule createFirewallRule(FirewallRule rule) throws NetworkRuleConflictException;
|
||||
|
||||
List<? extends FirewallRule> listFirewallRules(ListFirewallRulesCmd cmd);
|
||||
|
||||
/**
|
||||
* Revokes a firewall rule
|
||||
* @param ruleId the id of the rule to revoke.
|
||||
*
|
||||
* @param ruleId
|
||||
* the id of the rule to revoke.
|
||||
* @return
|
||||
*/
|
||||
boolean revokeFirewallRule(long ruleId, boolean apply);
|
||||
@ -24,4 +27,5 @@ public interface FirewallService {
|
||||
FirewallRule getFirewallRule(long ruleId);
|
||||
|
||||
boolean revokeRelatedFirewallRule(long ruleId, boolean apply);
|
||||
|
||||
}
|
||||
|
||||
@ -18,28 +18,28 @@
|
||||
package com.cloud.network.lb;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.api.commands.CreateLBStickinessPolicyCmd;
|
||||
import com.cloud.api.commands.CreateLoadBalancerRuleCmd;
|
||||
import com.cloud.api.commands.ListLBStickinessPoliciesCmd;
|
||||
|
||||
import com.cloud.api.commands.ListLoadBalancerRuleInstancesCmd;
|
||||
import com.cloud.api.commands.ListLoadBalancerRulesCmd;
|
||||
import com.cloud.api.commands.UpdateLoadBalancerRuleCmd;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.NetworkRuleConflictException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.rules.StickinessPolicy;
|
||||
import com.cloud.network.rules.LoadBalancer;
|
||||
|
||||
|
||||
import com.cloud.network.rules.StickinessPolicy;
|
||||
import com.cloud.uservm.UserVm;
|
||||
|
||||
|
||||
public interface LoadBalancingRulesService {
|
||||
/**
|
||||
* Create a load balancer rule from the given ipAddress/port to the given private port
|
||||
* @param openFirewall TODO
|
||||
* @param cmd the command specifying the ip address, public port, protocol, private port, and algorithm
|
||||
*
|
||||
* @param openFirewall
|
||||
* TODO
|
||||
* @param cmd
|
||||
* the command specifying the ip address, public port, protocol, private port, and algorithm
|
||||
* @return the newly created LoadBalancerVO if successful, null otherwise
|
||||
* @throws InsufficientAddressCapacityException
|
||||
*/
|
||||
@ -48,9 +48,14 @@ public interface LoadBalancingRulesService {
|
||||
LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd);
|
||||
|
||||
boolean deleteLoadBalancerRule(long lbRuleId, boolean apply);
|
||||
|
||||
/**
|
||||
* Create a stickiness policy to a load balancer from the given stickiness method name and parameters in (name,value) pairs.
|
||||
* @param cmd the command specifying the stickiness method name, params (name,value pairs), policy name and description.
|
||||
* Create a stickiness policy to a load balancer from the given stickiness method name and parameters in
|
||||
* (name,value) pairs.
|
||||
*
|
||||
* @param cmd
|
||||
* the command specifying the stickiness method name, params (name,value pairs), policy name and
|
||||
* description.
|
||||
* @return the newly created stickiness policy if successfull, null otherwise
|
||||
* @thows NetworkRuleConflictException
|
||||
*/
|
||||
@ -59,6 +64,7 @@ public interface LoadBalancingRulesService {
|
||||
public boolean applyLBStickinessPolicy(CreateLBStickinessPolicyCmd cmd) throws ResourceUnavailableException;
|
||||
|
||||
boolean deleteLBStickinessPolicy(long stickinessPolicyId);
|
||||
|
||||
/**
|
||||
* Assign a virtual machine, or list of virtual machines, to a load balancer.
|
||||
*/
|
||||
@ -67,8 +73,11 @@ public interface LoadBalancingRulesService {
|
||||
boolean removeFromLoadBalancer(long lbRuleId, List<Long> vmIds);
|
||||
|
||||
boolean applyLoadBalancerConfig(long lbRuleId) throws ResourceUnavailableException;
|
||||
|
||||
/**
|
||||
* List instances that have either been applied to a load balancer or are eligible to be assigned to a load balancer.
|
||||
* List instances that have either been applied to a load balancer or are eligible to be assigned to a load
|
||||
* balancer.
|
||||
*
|
||||
* @param cmd
|
||||
* @return list of vm instances that have been or can be applied to a load balancer
|
||||
*/
|
||||
@ -76,19 +85,24 @@ public interface LoadBalancingRulesService {
|
||||
|
||||
/**
|
||||
* List load balancer rules based on the given criteria
|
||||
* @param cmd the command that specifies the criteria to use for listing load balancers. Load balancers can be listed
|
||||
*
|
||||
* @param cmd
|
||||
* the command that specifies the criteria to use for listing load balancers. Load balancers can be
|
||||
* listed
|
||||
* by id, name, public ip, and vm instance id
|
||||
* @return list of load balancers that match the criteria
|
||||
*/
|
||||
List<? extends LoadBalancer> searchForLoadBalancers(ListLoadBalancerRulesCmd cmd);
|
||||
|
||||
/**
|
||||
* List stickiness policies based on the given criteria
|
||||
* @param cmd the command specifies the load balancing rule id.
|
||||
*
|
||||
* @param cmd
|
||||
* the command specifies the load balancing rule id.
|
||||
* @return list of stickiness policies that match the criteria.
|
||||
*/
|
||||
List<? extends StickinessPolicy> searchForLBStickinessPolicies(ListLBStickinessPoliciesCmd cmd);
|
||||
|
||||
|
||||
List<LoadBalancingRule> listByNetworkId(long networkId);
|
||||
|
||||
LoadBalancer findById(long LoadBalancer);
|
||||
|
||||
@ -31,24 +31,34 @@ public interface RulesService {
|
||||
/**
|
||||
* Creates a port forwarding rule between two ip addresses or between
|
||||
* an ip address and a virtual machine.
|
||||
* @param rule rule to be created.
|
||||
* @param vmId vm to be linked to. If specified the destination ip address is ignored.
|
||||
* @param openFirewall TODO
|
||||
*
|
||||
* @param rule
|
||||
* rule to be created.
|
||||
* @param vmId
|
||||
* vm to be linked to. If specified the destination ip address is ignored.
|
||||
* @param openFirewall
|
||||
* TODO
|
||||
* @return PortForwardingRule if created.
|
||||
* @throws NetworkRuleConflictException if conflicts in the network rules are detected.
|
||||
* @throws NetworkRuleConflictException
|
||||
* if conflicts in the network rules are detected.
|
||||
*/
|
||||
PortForwardingRule createPortForwardingRule(PortForwardingRule rule, Long vmId, boolean openFirewall) throws NetworkRuleConflictException;
|
||||
|
||||
/**
|
||||
* Revokes a port forwarding rule
|
||||
* @param ruleId the id of the rule to revoke.
|
||||
*
|
||||
* @param ruleId
|
||||
* the id of the rule to revoke.
|
||||
* @param caller
|
||||
* @return
|
||||
*/
|
||||
boolean revokePortForwardingRule(long ruleId, boolean apply);
|
||||
|
||||
/**
|
||||
* List port forwarding rules assigned to an ip address
|
||||
* @param cmd the command object holding the criteria for listing port forwarding rules (the ipAddress)
|
||||
*
|
||||
* @param cmd
|
||||
* the command object holding the criteria for listing port forwarding rules (the ipAddress)
|
||||
* @return list of port forwarding rules on the given address, empty list if no rules exist
|
||||
*/
|
||||
public List<? extends PortForwardingRule> listPortForwardingRules(ListPortForwardingRulesCmd cmd);
|
||||
@ -58,6 +68,7 @@ public interface RulesService {
|
||||
boolean enableStaticNat(long ipAddressId, long vmId) throws NetworkRuleConflictException, ResourceUnavailableException;
|
||||
|
||||
PortForwardingRule getPortForwardigRule(long ruleId);
|
||||
|
||||
FirewallRule getFirewallRule(long ruleId);
|
||||
|
||||
StaticNatRule createStaticNatRule(StaticNatRule rule, boolean openFirewall) throws NetworkRuleConflictException;
|
||||
|
||||
@ -44,7 +44,7 @@ public interface NetworkOffering {
|
||||
public final static String DefaultSharedNetworkOfferingWithSGService = "DefaultSharedNetworkOfferingWithSGService";
|
||||
public final static String DefaultIsolatedNetworkOfferingWithSourceNatService = "DefaultIsolatedNetworkOfferingWithSourceNatService";
|
||||
public final static String DefaultSharedNetworkOffering = "DefaultSharedNetworkOffering";
|
||||
public final static String DefaultIsolatedNetworkOffering= "DefaultIsolatedNetworkOffering";
|
||||
public final static String DefaultIsolatedNetworkOffering = "DefaultIsolatedNetworkOffering";
|
||||
public final static String DefaultSharedEIPandELBNetworkOffering = "DefaultSharedNetscalerEIPandELBNetworkOffering";
|
||||
|
||||
long getId();
|
||||
@ -104,4 +104,5 @@ public interface NetworkOffering {
|
||||
boolean getElasticLb();
|
||||
|
||||
boolean getSpecifyIpRanges();
|
||||
|
||||
}
|
||||
|
||||
@ -46,4 +46,5 @@ public interface DomainService {
|
||||
|
||||
List<? extends Domain> searchForDomainChildren(ListDomainChildrenCmd cmd)
|
||||
throws PermissionDeniedException;
|
||||
|
||||
}
|
||||
|
||||
@ -29,10 +29,15 @@ public interface ResourceLimitService {
|
||||
|
||||
/**
|
||||
* Updates an existing resource limit with the specified details. If a limit doesn't exist, will create one.
|
||||
* @param accountId TODO
|
||||
* @param domainId TODO
|
||||
* @param resourceType TODO
|
||||
* @param max TODO
|
||||
*
|
||||
* @param accountId
|
||||
* TODO
|
||||
* @param domainId
|
||||
* TODO
|
||||
* @param resourceType
|
||||
* TODO
|
||||
* @param max
|
||||
* TODO
|
||||
*
|
||||
* @return the updated/created resource limit
|
||||
*/
|
||||
@ -40,19 +45,28 @@ public interface ResourceLimitService {
|
||||
|
||||
/**
|
||||
* Updates an existing resource count details for the account/domain
|
||||
* @param accountId TODO
|
||||
* @param domainId TODO
|
||||
* @param typeId TODO
|
||||
*
|
||||
* @param accountId
|
||||
* TODO
|
||||
* @param domainId
|
||||
* TODO
|
||||
* @param typeId
|
||||
* TODO
|
||||
* @return the updated/created resource counts
|
||||
*/
|
||||
List<? extends ResourceCount> recalculateResourceCount(Long accountId, Long domainId, Integer typeId);
|
||||
|
||||
/**
|
||||
* Search for resource limits for the given id and/or account and/or type and/or domain.
|
||||
* @param id TODO
|
||||
* @param accountId TODO
|
||||
* @param domainId TODO
|
||||
* @param type TODO
|
||||
*
|
||||
* @param id
|
||||
* TODO
|
||||
* @param accountId
|
||||
* TODO
|
||||
* @param domainId
|
||||
* TODO
|
||||
* @param type
|
||||
* TODO
|
||||
* @return a list of limits that match the criteria
|
||||
*/
|
||||
public List<? extends ResourceLimit> searchForLimits(Long id, Long accountId, Long domainId, Integer type, Long startIndex, Long pageSizeVal);
|
||||
@ -60,6 +74,7 @@ public interface ResourceLimitService {
|
||||
/**
|
||||
* Finds the resource limit for a specified account and type. If the account has an infinite limit, will check
|
||||
* the account's parent domain, and if that limit is also infinite, will return the ROOT domain's limit.
|
||||
*
|
||||
* @param account
|
||||
* @param type
|
||||
* @return resource limit
|
||||
@ -69,6 +84,7 @@ public interface ResourceLimitService {
|
||||
/**
|
||||
* Finds the resource limit for a specified domain and type. If the domain has an infinite limit, will check
|
||||
* up the domain hierarchy
|
||||
*
|
||||
* @param account
|
||||
* @param type
|
||||
* @return resource limit
|
||||
@ -77,31 +93,37 @@ public interface ResourceLimitService {
|
||||
|
||||
/**
|
||||
* Increments the resource count
|
||||
*
|
||||
* @param accountId
|
||||
* @param type
|
||||
* @param delta
|
||||
*/
|
||||
public void incrementResourceCount(long accountId, ResourceType type, Long...delta);
|
||||
public void incrementResourceCount(long accountId, ResourceType type, Long... delta);
|
||||
|
||||
/**
|
||||
* Decrements the resource count
|
||||
*
|
||||
* @param accountId
|
||||
* @param type
|
||||
* @param delta
|
||||
*/
|
||||
public void decrementResourceCount(long accountId, ResourceType type, Long...delta);
|
||||
public void decrementResourceCount(long accountId, ResourceType type, Long... delta);
|
||||
|
||||
/**
|
||||
* Checks if a limit has been exceeded for an account
|
||||
*
|
||||
* @param account
|
||||
* @param type
|
||||
* @param count the number of resources being allocated, count will be added to current allocation and compared against maximum allowed allocation
|
||||
* @param count
|
||||
* the number of resources being allocated, count will be added to current allocation and compared
|
||||
* against maximum allowed allocation
|
||||
* @throws ResourceAllocationException
|
||||
*/
|
||||
public void checkResourceLimit(Account account, ResourceCount.ResourceType type, long...count) throws ResourceAllocationException;
|
||||
public void checkResourceLimit(Account account, ResourceCount.ResourceType type, long... count) throws ResourceAllocationException;
|
||||
|
||||
/**
|
||||
* Gets the count of resources for a resource type and account
|
||||
*
|
||||
* @param account
|
||||
* @param type
|
||||
* @return count of resources
|
||||
|
||||
@ -28,28 +28,29 @@ import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name="resource_limit")
|
||||
@Table(name = "resource_limit")
|
||||
public class ResourceLimitVO implements ResourceLimit {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Long id = null;
|
||||
|
||||
@Column(name="type")
|
||||
@Column(name = "type")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private ResourceCount.ResourceType type;
|
||||
|
||||
@Column(name="domain_id")
|
||||
@Column(name = "domain_id")
|
||||
private Long domainId;
|
||||
|
||||
@Column(name="account_id")
|
||||
@Column(name = "account_id")
|
||||
private Long accountId;
|
||||
|
||||
@Column(name="max")
|
||||
@Column(name = "max")
|
||||
private Long max;
|
||||
|
||||
public ResourceLimitVO() {}
|
||||
public ResourceLimitVO() {
|
||||
}
|
||||
|
||||
public ResourceLimitVO(ResourceCount.ResourceType type, Long max, long ownerId, ResourceOwnerType ownerType) {
|
||||
this.type = type;
|
||||
|
||||
@ -278,7 +278,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
Long ipTotal = ApiDBUtils.getResourceCount(ResourceType.public_ip, account.getId());
|
||||
|
||||
Long ips = ipLimit - ipTotal;
|
||||
//check how many free ips are left, and if it's less than max allowed number of ips from account - use this value
|
||||
// check how many free ips are left, and if it's less than max allowed number of ips from account - use this
|
||||
// value
|
||||
Long ipsLeft = ApiDBUtils.countFreePublicIps();
|
||||
boolean unlimited = true;
|
||||
if (ips.longValue() > ipsLeft.longValue()) {
|
||||
@ -354,7 +355,6 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
return accountResponse;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UserResponse createUserResponse(UserAccount user) {
|
||||
UserResponse userResponse = new UserResponse();
|
||||
@ -529,7 +529,6 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
return policyResponse;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public HostResponse createHostResponse(Host host) {
|
||||
return createHostResponse(host, EnumSet.of(HostDetails.all));
|
||||
@ -558,7 +557,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
hostResponse.setCreated(host.getCreated());
|
||||
|
||||
if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity)
|
||||
|| details.contains(HostDetails.stats) || details.contains(HostDetails.events) ){
|
||||
|| details.contains(HostDetails.stats) || details.contains(HostDetails.events)) {
|
||||
|
||||
GuestOSCategoryVO guestOSCategory = ApiDBUtils.getHostGuestOSCategory(host.getId());
|
||||
if (guestOSCategory != null) {
|
||||
@ -584,10 +583,10 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
||||
if (host.getType() == Host.Type.Routing) {
|
||||
|
||||
if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity)){
|
||||
//set allocated capacities
|
||||
Long mem = ApiDBUtils.getMemoryOrCpuCapacitybyHost(host.getId(),Capacity.CAPACITY_TYPE_MEMORY);
|
||||
Long cpu = ApiDBUtils.getMemoryOrCpuCapacitybyHost(host.getId(),Capacity.CAPACITY_TYPE_CPU);
|
||||
if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity)) {
|
||||
// set allocated capacities
|
||||
Long mem = ApiDBUtils.getMemoryOrCpuCapacitybyHost(host.getId(), Capacity.CAPACITY_TYPE_MEMORY);
|
||||
Long cpu = ApiDBUtils.getMemoryOrCpuCapacitybyHost(host.getId(), Capacity.CAPACITY_TYPE_CPU);
|
||||
|
||||
hostResponse.setMemoryAllocated(mem);
|
||||
hostResponse.setMemoryTotal(host.getTotalMemory());
|
||||
@ -600,7 +599,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning);
|
||||
}
|
||||
|
||||
if (details.contains(HostDetails.all) || details.contains(HostDetails.stats)){
|
||||
if (details.contains(HostDetails.all) || details.contains(HostDetails.stats)) {
|
||||
// set CPU/RAM/Network stats
|
||||
String cpuUsed = null;
|
||||
HostStats hostStats = ApiDBUtils.getHostStatistics(host.getId());
|
||||
@ -608,16 +607,16 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
float cpuUtil = (float) hostStats.getCpuUtilization();
|
||||
cpuUsed = decimalFormat.format(cpuUtil) + "%";
|
||||
hostResponse.setCpuUsed(cpuUsed);
|
||||
hostResponse.setMemoryUsed( (new Double(hostStats.getUsedMemory())).longValue());
|
||||
hostResponse.setMemoryUsed((new Double(hostStats.getUsedMemory())).longValue());
|
||||
hostResponse.setNetworkKbsRead((new Double(hostStats.getNetworkReadKBs())).longValue());
|
||||
hostResponse.setNetworkKbsWrite((new Double(hostStats.getNetworkWriteKBs())).longValue());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}else if (host.getType() == Host.Type.SecondaryStorage){
|
||||
} else if (host.getType() == Host.Type.SecondaryStorage) {
|
||||
StorageStats secStorageStats = ApiDBUtils.getSecondaryStorageStatistics(host.getId());
|
||||
if (secStorageStats != null){
|
||||
if (secStorageStats != null) {
|
||||
hostResponse.setDiskSizeTotal(secStorageStats.getCapacityBytes());
|
||||
hostResponse.setDiskSizeAllocated(secStorageStats.getByteUsed());
|
||||
}
|
||||
@ -625,7 +624,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
|
||||
hostResponse.setLocalStorageActive(ApiDBUtils.isLocalStorageActiveOnHost(host));
|
||||
|
||||
if (details.contains(HostDetails.all) || details.contains(HostDetails.events)){
|
||||
if (details.contains(HostDetails.all) || details.contains(HostDetails.events)) {
|
||||
Set<com.cloud.host.Status.Event> possibleEvents = host.getStatus().getPossibleEvents();
|
||||
if ((possibleEvents != null) && !possibleEvents.isEmpty()) {
|
||||
String events = "";
|
||||
@ -809,22 +808,22 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
podResponse.setEndIp(((ipRange.length > 1) && (ipRange[1] != null)) ? ipRange[1] : "");
|
||||
podResponse.setGateway(pod.getGateway());
|
||||
podResponse.setAllocationState(pod.getAllocationState().toString());
|
||||
if (showCapacities != null && showCapacities){
|
||||
List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(null,pod.getId(),null);
|
||||
if (showCapacities != null && showCapacities) {
|
||||
List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(null, pod.getId(), null);
|
||||
Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
|
||||
float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor();
|
||||
|
||||
for (SummedCapacity capacity : capacities){
|
||||
for (SummedCapacity capacity : capacities) {
|
||||
CapacityResponse capacityResponse = new CapacityResponse();
|
||||
capacityResponse.setCapacityType(capacity.getCapacityType());
|
||||
capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
|
||||
if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU){
|
||||
capacityResponse.setCapacityTotal(new Long((long)(capacity.getTotalCapacity()*cpuOverprovisioningFactor)));
|
||||
}else if(capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED){
|
||||
List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(null, pod.getId() ,null);
|
||||
if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) {
|
||||
capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * cpuOverprovisioningFactor)));
|
||||
} else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
|
||||
List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(null, pod.getId(), null);
|
||||
capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity());
|
||||
capacityResponse.setCapacityUsed(capacity.getUsedCapacity() - c.get(0).getUsedCapacity());
|
||||
}else{
|
||||
} else {
|
||||
capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
|
||||
}
|
||||
if (capacityResponse.getCapacityTotal() != 0) {
|
||||
@ -862,22 +861,22 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
// FIXME zoneResponse.setVlan(dataCenter.get.getVnet());
|
||||
}
|
||||
|
||||
if (showCapacities != null && showCapacities){
|
||||
List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(dataCenter.getId(),null,null);
|
||||
if (showCapacities != null && showCapacities) {
|
||||
List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(dataCenter.getId(), null, null);
|
||||
Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
|
||||
float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor();
|
||||
|
||||
for (SummedCapacity capacity : capacities){
|
||||
for (SummedCapacity capacity : capacities) {
|
||||
CapacityResponse capacityResponse = new CapacityResponse();
|
||||
capacityResponse.setCapacityType(capacity.getCapacityType());
|
||||
capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
|
||||
if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU){
|
||||
capacityResponse.setCapacityTotal(new Long((long)(capacity.getTotalCapacity()*cpuOverprovisioningFactor)));
|
||||
}else if(capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED){
|
||||
List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(dataCenter.getId(), null ,null);
|
||||
if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) {
|
||||
capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * cpuOverprovisioningFactor)));
|
||||
} else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
|
||||
List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(dataCenter.getId(), null, null);
|
||||
capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity());
|
||||
capacityResponse.setCapacityUsed(capacity.getUsedCapacity() - c.get(0).getUsedCapacity());
|
||||
}else{
|
||||
} else {
|
||||
capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
|
||||
}
|
||||
if (capacityResponse.getCapacityTotal() != 0) {
|
||||
@ -893,10 +892,10 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
zoneResponse.setCapacitites(new ArrayList<CapacityResponse>(capacityResponses));
|
||||
}
|
||||
|
||||
//set network domain info
|
||||
// set network domain info
|
||||
zoneResponse.setDomain(dataCenter.getDomain());
|
||||
|
||||
//set domain info
|
||||
// set domain info
|
||||
Long domainId = dataCenter.getDomainId();
|
||||
if (domainId != null) {
|
||||
Domain domain = ApiDBUtils.findDomainById(domainId);
|
||||
@ -912,15 +911,15 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
return zoneResponse;
|
||||
}
|
||||
|
||||
private List<CapacityResponse> getStatsCapacityresponse(Long poolId, Long clusterId, Long podId, Long zoneId){
|
||||
private List<CapacityResponse> getStatsCapacityresponse(Long poolId, Long clusterId, Long podId, Long zoneId) {
|
||||
List<CapacityVO> capacities = new ArrayList<CapacityVO>();
|
||||
capacities.add(ApiDBUtils.getStoragePoolUsedStats(poolId, clusterId, podId, zoneId));
|
||||
if(clusterId == null && podId == null){
|
||||
if (clusterId == null && podId == null) {
|
||||
capacities.add(ApiDBUtils.getSecondaryStorageUsedStats(poolId, zoneId));
|
||||
}
|
||||
|
||||
List<CapacityResponse> capacityResponses = new ArrayList<CapacityResponse>();
|
||||
for (CapacityVO capacity : capacities){
|
||||
for (CapacityVO capacity : capacities) {
|
||||
CapacityResponse capacityResponse = new CapacityResponse();
|
||||
capacityResponse.setCapacityType(capacity.getCapacityType());
|
||||
capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
|
||||
@ -956,7 +955,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
Long instanceId = volume.getInstanceId();
|
||||
if (instanceId != null && volume.getState() != Volume.State.Destroy) {
|
||||
VMInstanceVO vm = ApiDBUtils.findVMInstanceById(instanceId);
|
||||
if(vm != null){
|
||||
if (vm != null) {
|
||||
volResponse.setVirtualMachineId(vm.getId());
|
||||
volResponse.setVirtualMachineName(vm.getHostName());
|
||||
UserVm userVm = ApiDBUtils.findUserVmById(vm.getId());
|
||||
@ -964,10 +963,10 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
volResponse.setVirtualMachineDisplayName(userVm.getDisplayName());
|
||||
volResponse.setVirtualMachineState(vm.getState().toString());
|
||||
} else {
|
||||
s_logger.error("User Vm with Id: "+instanceId+" does not exist for volume "+volume.getId());
|
||||
s_logger.error("User Vm with Id: " + instanceId + " does not exist for volume " + volume.getId());
|
||||
}
|
||||
} else {
|
||||
s_logger.error("Vm with Id: "+instanceId+" does not exist for volume "+volume.getId());
|
||||
s_logger.error("Vm with Id: " + instanceId + " does not exist for volume " + volume.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1020,7 +1019,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
// volResponse.setSourceType(volume.getSourceType().toString());
|
||||
// }
|
||||
|
||||
//return hypervisor for ROOT and Resource domain only
|
||||
// return hypervisor for ROOT and Resource domain only
|
||||
Account caller = UserContext.current().getCaller();
|
||||
if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
|
||||
volResponse.setHypervisor(ApiDBUtils.getVolumeHyperType(volume.getId()).toString());
|
||||
@ -1073,7 +1072,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
|
||||
StorageStats stats = ApiDBUtils.getStoragePoolStatistics(pool.getId());
|
||||
long allocatedSize = ApiDBUtils.getStorageCapacitybyPool(pool.getId(),Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED);
|
||||
long allocatedSize = ApiDBUtils.getStorageCapacitybyPool(pool.getId(), Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED);
|
||||
poolResponse.setDiskSizeTotal(pool.getCapacityBytes());
|
||||
poolResponse.setDiskSizeAllocated(allocatedSize);
|
||||
|
||||
@ -1109,23 +1108,23 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
DataCenterVO zone = ApiDBUtils.findZoneById(cluster.getDataCenterId());
|
||||
clusterResponse.setZoneName(zone.getName());
|
||||
if (showCapacities != null && showCapacities){
|
||||
List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(null,null,cluster.getId());
|
||||
if (showCapacities != null && showCapacities) {
|
||||
List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(null, null, cluster.getId());
|
||||
Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
|
||||
float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor();
|
||||
|
||||
for (SummedCapacity capacity : capacities){
|
||||
for (SummedCapacity capacity : capacities) {
|
||||
CapacityResponse capacityResponse = new CapacityResponse();
|
||||
capacityResponse.setCapacityType(capacity.getCapacityType());
|
||||
capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
|
||||
|
||||
if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU){
|
||||
capacityResponse.setCapacityTotal(new Long((long)(capacity.getTotalCapacity()*cpuOverprovisioningFactor)));
|
||||
}else if(capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED){
|
||||
if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) {
|
||||
capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * cpuOverprovisioningFactor)));
|
||||
} else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
|
||||
List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(null, null, cluster.getId());
|
||||
capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity());
|
||||
capacityResponse.setCapacityUsed(capacity.getUsedCapacity() - c.get(0).getUsedCapacity());
|
||||
}else{
|
||||
} else {
|
||||
capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
|
||||
}
|
||||
if (capacityResponse.getCapacityTotal() != 0) {
|
||||
@ -1209,9 +1208,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<UserVmResponse> createUserVmResponse(String objectName, EnumSet<VMDetails> details, UserVm...userVms) {
|
||||
public List<UserVmResponse> createUserVmResponse(String objectName, EnumSet<VMDetails> details, UserVm... userVms) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
Map<Long, DataCenter> dataCenters = new HashMap<Long, DataCenter>();
|
||||
Map<Long, Host> hosts = new HashMap<Long, Host>();
|
||||
@ -1234,8 +1232,6 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
userVmResponse.setName(userVm.getHostName());
|
||||
userVmResponse.setCreated(userVm.getCreated());
|
||||
|
||||
|
||||
|
||||
userVmResponse.setHaEnable(userVm.isHaEnabled());
|
||||
|
||||
if (userVm.getDisplayName() != null) {
|
||||
@ -1246,7 +1242,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
userVmResponse.setPassword(userVm.getPassword());
|
||||
}
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.group)){
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.group)) {
|
||||
InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(userVm.getId());
|
||||
if (group != null) {
|
||||
userVmResponse.setGroup(group.getName());
|
||||
@ -1265,7 +1261,6 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
userVmResponse.setZoneId(zone.getId());
|
||||
userVmResponse.setZoneName(zone.getName());
|
||||
|
||||
|
||||
// if user is an admin, display host id
|
||||
if (((caller == null) || (caller.getType() == Account.ACCOUNT_TYPE_ADMIN)) && (userVm.getHostId() != null)) {
|
||||
Host host = hosts.get(userVm.getHostId());
|
||||
@ -1298,12 +1293,12 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
|
||||
if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
|
||||
if (userVm.getHypervisorType() != null){
|
||||
if (userVm.getHypervisorType() != null) {
|
||||
userVmResponse.setHypervisor(userVm.getHypervisorType().toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.tmpl)){
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.tmpl)) {
|
||||
// Template Info
|
||||
VMTemplateVO template = templates.get(userVm.getTemplateId());
|
||||
if (template == null) {
|
||||
@ -1326,8 +1321,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.iso)){
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.iso)) {
|
||||
// ISO Info
|
||||
VMTemplateVO iso = templates.get(userVm.getIsoId());
|
||||
if (iso == null) {
|
||||
@ -1343,7 +1337,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.servoff)){
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.servoff)) {
|
||||
// Service Offering Info
|
||||
ServiceOffering offering = serviceOfferings.get(userVm.getServiceOfferingId());
|
||||
|
||||
@ -1359,7 +1353,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
userVmResponse.setMemory(offering.getRamSize());
|
||||
}
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.volume)){
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.volume)) {
|
||||
VolumeVO rootVolume = ApiDBUtils.findRootVolume(userVm.getId());
|
||||
if (rootVolume != null) {
|
||||
userVmResponse.setRootDeviceId(rootVolume.getDeviceId());
|
||||
@ -1372,7 +1366,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.stats)){
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.stats)) {
|
||||
// stats calculation
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
||||
String cpuUsed = null;
|
||||
@ -1392,12 +1386,12 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
|
||||
userVmResponse.setGuestOsId(userVm.getGuestOSId());
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.secgrp)){
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.secgrp)) {
|
||||
// security groups - list only when zone is security group enabled
|
||||
if (zone.isSecurityGroupEnabled()) {
|
||||
List<SecurityGroupVO> securityGroups = ApiDBUtils.getSecurityGroupsForVm(userVm.getId());
|
||||
List<SecurityGroupResponse> securityGroupResponse = new ArrayList<SecurityGroupResponse>();
|
||||
for(SecurityGroupVO grp : securityGroups) {
|
||||
for (SecurityGroupVO grp : securityGroups) {
|
||||
SecurityGroupResponse resp = new SecurityGroupResponse();
|
||||
resp.setId(grp.getId());
|
||||
resp.setName(grp.getName());
|
||||
@ -1409,7 +1403,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.nics)){
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.nics)) {
|
||||
List<NicProfile> nicProfiles = ApiDBUtils.getNics(userVm);
|
||||
List<NicResponse> nicResponses = new ArrayList<NicResponse>();
|
||||
for (NicProfile singleNicProfile : nicProfiles) {
|
||||
@ -1428,7 +1422,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
//Long networkId = singleNicProfile.getNetworkId();
|
||||
// Long networkId = singleNicProfile.getNetworkId();
|
||||
Network network = networks.get(singleNicProfile.getNetworkId());
|
||||
if (network == null) {
|
||||
network = ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId());
|
||||
@ -1465,10 +1459,10 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
|
||||
vmDataList = ApiDBUtils.listVmDetails(vmDataList);
|
||||
|
||||
//initialize vmresponse from vmdatalist
|
||||
// initialize vmresponse from vmdatalist
|
||||
List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
||||
for (UserVmData uvd: vmDataList.values()){
|
||||
for (UserVmData uvd : vmDataList.values()) {
|
||||
UserVmResponse userVmResponse = newUserVmResponse(uvd, caller_is_admin);
|
||||
|
||||
// stats calculation
|
||||
@ -1493,7 +1487,6 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
return vmResponses;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DomainRouterResponse createDomainRouterResponse(VirtualRouter router) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
@ -1553,7 +1546,6 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
|
||||
populateOwner(routerResponse, router);
|
||||
|
||||
|
||||
DataCenter zone = ApiDBUtils.findZoneById(router.getDataCenterIdToDeployIn());
|
||||
if (zone != null) {
|
||||
routerResponse.setZoneName(zone.getName());
|
||||
@ -1592,7 +1584,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
// for console proxies, add the active sessions
|
||||
if (vm.getType() == Type.ConsoleProxy) {
|
||||
ConsoleProxyVO proxy = ApiDBUtils.findConsoleProxy(vm.getId());
|
||||
//proxy can be already destroyed
|
||||
// proxy can be already destroyed
|
||||
if (proxy != null) {
|
||||
vmResponse.setActiveViewerSessions(proxy.getActiveSession());
|
||||
}
|
||||
@ -1617,7 +1609,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
vmResponse.setLinkLocalIp(singleNicProfile.getIp4Address());
|
||||
vmResponse.setLinkLocalMacAddress(singleNicProfile.getMacAddress());
|
||||
vmResponse.setLinkLocalNetmask(singleNicProfile.getNetmask());
|
||||
} else if (network.getTrafficType() == TrafficType.Public){
|
||||
} else if (network.getTrafficType() == TrafficType.Public) {
|
||||
vmResponse.setPublicIp(singleNicProfile.getIp4Address());
|
||||
vmResponse.setPublicMacAddress(singleNicProfile.getMacAddress());
|
||||
vmResponse.setPublicNetmask(singleNicProfile.getNetmask());
|
||||
@ -1729,7 +1721,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
return responses;
|
||||
}
|
||||
dcs.addAll(ApiDBUtils.listZones());
|
||||
for (DataCenterVO dc : dcs ) {
|
||||
for (DataCenterVO dc : dcs) {
|
||||
responses.addAll(createTemplateResponses(templateId, dc.getId(), readyOnly));
|
||||
}
|
||||
return responses;
|
||||
@ -1910,12 +1902,13 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
responses.add(templateResponse);
|
||||
return responses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TemplateResponse> createIsoResponses(long isoId, Long zoneId, boolean readyOnly) {
|
||||
|
||||
List<TemplateResponse> isoResponses = new ArrayList<TemplateResponse>();
|
||||
VirtualMachineTemplate iso = findTemplateById(isoId);
|
||||
if ( iso.getTemplateType() == TemplateType.PERHOST) {
|
||||
if (iso.getTemplateType() == TemplateType.PERHOST) {
|
||||
TemplateResponse isoResponse = new TemplateResponse();
|
||||
isoResponse.setId(iso.getId());
|
||||
isoResponse.setName(iso.getName());
|
||||
@ -1941,14 +1934,14 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
isoResponses.add(isoResponse);
|
||||
return isoResponses;
|
||||
} else {
|
||||
if (zoneId == null || zoneId == -1 ) {
|
||||
if (zoneId == null || zoneId == -1) {
|
||||
isoResponses = createSwiftIsoResponses(iso);
|
||||
if (!isoResponses.isEmpty()) {
|
||||
return isoResponses;
|
||||
}
|
||||
List<DataCenterVO> dcs = new ArrayList<DataCenterVO>();
|
||||
dcs.addAll(ApiDBUtils.listZones());
|
||||
for (DataCenterVO dc : dcs ) {
|
||||
for (DataCenterVO dc : dcs) {
|
||||
isoResponses.addAll(createIsoResponses(iso, dc.getId(), readyOnly));
|
||||
}
|
||||
return isoResponses;
|
||||
@ -2016,7 +2009,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
long isoId = iso.getId();
|
||||
List<TemplateResponse> isoResponses = new ArrayList<TemplateResponse>();
|
||||
VMTemplateHostVO isoHost = ApiDBUtils.findTemplateHostRef(isoId, zoneId, readyOnly);
|
||||
if( isoHost == null ) {
|
||||
if (isoHost == null) {
|
||||
return isoResponses;
|
||||
}
|
||||
TemplateResponse isoResponse = new TemplateResponse();
|
||||
@ -2153,6 +2146,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
response.setResponses(netGrpResponses);
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecurityGroupResponse createSecurityGroupResponse(SecurityGroup group) {
|
||||
SecurityGroupResponse response = new SecurityGroupResponse();
|
||||
@ -2225,7 +2219,6 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
jobResponse.setObjectName("asyncjobs");
|
||||
return jobResponse;
|
||||
}
|
||||
@ -2272,7 +2265,6 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
return responseEvent;
|
||||
}
|
||||
|
||||
|
||||
private List<CapacityVO> sumCapacities(List<? extends Capacity> hostCapacities) {
|
||||
Map<String, Long> totalCapacityMap = new HashMap<String, Long>();
|
||||
Map<String, Long> usedCapacityMap = new HashMap<String, Long>();
|
||||
@ -2293,7 +2285,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
// collect all the capacity types, sum allocated/used and sum total...get one capacity number for each
|
||||
for (Capacity capacity : hostCapacities) {
|
||||
|
||||
//check if zone exist
|
||||
// check if zone exist
|
||||
DataCenter zone = ApiDBUtils.findZoneById(capacity.getDataCenterId());
|
||||
if (zone == null) {
|
||||
continue;
|
||||
@ -2301,8 +2293,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
|
||||
short capacityType = capacity.getCapacityType();
|
||||
|
||||
//If local storage then ignore
|
||||
if ( (capacityType == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED || capacityType == Capacity.CAPACITY_TYPE_STORAGE)
|
||||
// If local storage then ignore
|
||||
if ((capacityType == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED || capacityType == Capacity.CAPACITY_TYPE_STORAGE)
|
||||
&& poolIdsToIgnore.contains(capacity.getHostOrPoolId())) {
|
||||
continue;
|
||||
}
|
||||
@ -2339,11 +2331,16 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
|
||||
if (capacityType == Capacity.CAPACITY_TYPE_CPU || capacityType == Capacity.CAPACITY_TYPE_MEMORY) { // Reserved
|
||||
// Capacity
|
||||
// accounts for
|
||||
// stopped vms
|
||||
// that have been
|
||||
// stopped within
|
||||
// an interval
|
||||
// accounts
|
||||
// for
|
||||
// stopped
|
||||
// vms
|
||||
// that
|
||||
// have been
|
||||
// stopped
|
||||
// within
|
||||
// an
|
||||
// interval
|
||||
usedCapacity += capacity.getReservedCapacity();
|
||||
}
|
||||
|
||||
@ -2376,10 +2373,13 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
// accounts
|
||||
// for
|
||||
// stopped
|
||||
// vms that
|
||||
// have been
|
||||
// vms
|
||||
// that
|
||||
// have
|
||||
// been
|
||||
// stopped
|
||||
// within an
|
||||
// within
|
||||
// an
|
||||
// interval
|
||||
usedCapacity += capacity.getReservedCapacity();
|
||||
}
|
||||
@ -2411,7 +2411,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
@Override
|
||||
public List<CapacityResponse> createCapacityResponse(List<? extends Capacity> result, DecimalFormat format) {
|
||||
List<CapacityResponse> capacityResponses = new ArrayList<CapacityResponse>();
|
||||
//List<CapacityVO> summedCapacities = sumCapacities(result);
|
||||
// List<CapacityVO> summedCapacities = sumCapacities(result);
|
||||
for (Capacity summedCapacity : result) {
|
||||
CapacityResponse capacityResponse = new CapacityResponse();
|
||||
capacityResponse.setCapacityTotal(summedCapacity.getTotalCapacity());
|
||||
@ -2429,7 +2429,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
ClusterVO cluster = ApiDBUtils.findClusterById(summedCapacity.getClusterId());
|
||||
if (cluster != null) {
|
||||
capacityResponse.setClusterName(cluster.getName());
|
||||
if (summedCapacity.getPodId() == null){
|
||||
if (summedCapacity.getPodId() == null) {
|
||||
long podId = cluster.getPodId();
|
||||
capacityResponse.setPodId(podId);
|
||||
capacityResponse.setPodName(ApiDBUtils.findPodById(podId).getName());
|
||||
@ -2470,7 +2470,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
response.setDomainId(templateOwnerDomain);
|
||||
}
|
||||
|
||||
//Set accounts
|
||||
// Set accounts
|
||||
List<String> projectIds = new ArrayList<String>();
|
||||
List<String> regularAccounts = new ArrayList<String>();
|
||||
for (String accountName : accountNames) {
|
||||
@ -2478,10 +2478,10 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
if (account.getType() != Account.ACCOUNT_TYPE_PROJECT) {
|
||||
regularAccounts.add(accountName);
|
||||
} else {
|
||||
//convert account to projectIds
|
||||
// convert account to projectIds
|
||||
Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
|
||||
|
||||
if(project.getUuid() != null && !project.getUuid().isEmpty())
|
||||
if (project.getUuid() != null && !project.getUuid().isEmpty())
|
||||
projectIds.add(project.getUuid());
|
||||
else
|
||||
projectIds.add(String.valueOf(project.getId()));
|
||||
@ -2610,7 +2610,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
|
||||
for (Service service : serviceProviderMap.keySet()) {
|
||||
ServiceResponse svcRsp = new ServiceResponse();
|
||||
//skip gateway service
|
||||
// skip gateway service
|
||||
if (service == Service.Gateway) {
|
||||
continue;
|
||||
}
|
||||
@ -2630,12 +2630,12 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
|
||||
CapabilityResponse lbIsoaltion = new CapabilityResponse();
|
||||
lbIsoaltion.setName(Capability.SupportedLBIsolation.getName());
|
||||
lbIsoaltion.setValue(offering.getDedicatedLB()?"dedicated":"shared");
|
||||
lbIsoaltion.setValue(offering.getDedicatedLB() ? "dedicated" : "shared");
|
||||
lbCapResponse.add(lbIsoaltion);
|
||||
|
||||
CapabilityResponse eLb = new CapabilityResponse();
|
||||
eLb.setName(Capability.ElasticLb.getName());
|
||||
eLb.setValue(offering.getElasticLb()?"true":"false");
|
||||
eLb.setValue(offering.getElasticLb() ? "true" : "false");
|
||||
lbCapResponse.add(eLb);
|
||||
|
||||
svcRsp.setCapabilities(lbCapResponse);
|
||||
@ -2643,12 +2643,12 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
List<CapabilityResponse> capabilities = new ArrayList<CapabilityResponse>();
|
||||
CapabilityResponse sharedSourceNat = new CapabilityResponse();
|
||||
sharedSourceNat.setName(Capability.SupportedSourceNatTypes.getName());
|
||||
sharedSourceNat.setValue(offering.getSharedSourceNat()?"perzone":"peraccount");
|
||||
sharedSourceNat.setValue(offering.getSharedSourceNat() ? "perzone" : "peraccount");
|
||||
capabilities.add(sharedSourceNat);
|
||||
|
||||
CapabilityResponse redundantRouter = new CapabilityResponse();
|
||||
redundantRouter.setName(Capability.RedundantRouter.getName());
|
||||
redundantRouter.setValue(offering.getRedundantRouter()?"true":"false");
|
||||
redundantRouter.setValue(offering.getRedundantRouter() ? "true" : "false");
|
||||
capabilities.add(redundantRouter);
|
||||
|
||||
svcRsp.setCapabilities(capabilities);
|
||||
@ -2657,7 +2657,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
|
||||
CapabilityResponse eIp = new CapabilityResponse();
|
||||
eIp.setName(Capability.ElasticIp.getName());
|
||||
eIp.setValue(offering.getElasticLb()?"true":"false");
|
||||
eIp.setValue(offering.getElasticLb() ? "true" : "false");
|
||||
staticNatCapResponse.add(eIp);
|
||||
|
||||
svcRsp.setCapabilities(staticNatCapResponse);
|
||||
@ -2692,13 +2692,13 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
|
||||
response.setGateway(network.getGateway());
|
||||
|
||||
//FIXME - either set netmask or cidr
|
||||
// FIXME - either set netmask or cidr
|
||||
response.setCidr(network.getCidr());
|
||||
if(network.getCidr() != null){
|
||||
if (network.getCidr() != null) {
|
||||
response.setNetmask(NetUtils.cidr2Netmask(network.getCidr()));
|
||||
}
|
||||
|
||||
//FIXME - either set broadcast URI or vlan
|
||||
// FIXME - either set broadcast URI or vlan
|
||||
if (network.getBroadcastUri() != null) {
|
||||
String broadcastUri = network.getBroadcastUri().toString();
|
||||
response.setBroadcastUri(broadcastUri);
|
||||
@ -2737,7 +2737,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
if (serviceCapabilitiesMap != null) {
|
||||
for (Service service : serviceCapabilitiesMap.keySet()) {
|
||||
ServiceResponse serviceResponse = new ServiceResponse();
|
||||
//skip gateway service
|
||||
// skip gateway service
|
||||
if (service == Service.Gateway) {
|
||||
continue;
|
||||
}
|
||||
@ -2767,7 +2767,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
if (network.getAclType() == null || network.getAclType() == ACLType.Account) {
|
||||
populateOwner(response, network);
|
||||
} else {
|
||||
//get domain from network_domain table
|
||||
// get domain from network_domain table
|
||||
Pair<Long, Boolean> domainNetworkDetails = ApiDBUtils.getDomainNetworkDetails(network.getId());
|
||||
response.setDomainId(domainNetworkDetails.first());
|
||||
response.setSubdomainAccess(domainNetworkDetails.second());
|
||||
@ -2787,7 +2787,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getSecurityGroupId (String groupName, long accountId) {
|
||||
public Long getSecurityGroupId(String groupName, long accountId) {
|
||||
SecurityGroup sg = ApiDBUtils.getSecurityGroup(groupName, accountId);
|
||||
if (sg == null) {
|
||||
return null;
|
||||
@ -2814,7 +2814,6 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FirewallResponse createFirewallResponse(FirewallRule fwRule) {
|
||||
FirewallResponse response = new FirewallResponse();
|
||||
@ -2850,9 +2849,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public UserVmData newUserVmData(UserVm userVm){
|
||||
public UserVmData newUserVmData(UserVm userVm) {
|
||||
UserVmData userVmData = new UserVmData();
|
||||
userVmData.setId(userVm.getId());
|
||||
userVmData.setName(userVm.getHostName());
|
||||
@ -2880,7 +2877,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
return userVmData;
|
||||
}
|
||||
|
||||
public UserVmResponse newUserVmResponse(UserVmData userVmData, boolean caller_is_admin){
|
||||
public UserVmResponse newUserVmResponse(UserVmData userVmData, boolean caller_is_admin) {
|
||||
UserVmResponse userVmResponse = new UserVmResponse();
|
||||
|
||||
userVmResponse.setHypervisor(userVmData.getHypervisor());
|
||||
@ -2898,7 +2895,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
userVmResponse.setGroup(userVmData.getGroup());
|
||||
userVmResponse.setZoneId(userVmData.getZoneId());
|
||||
userVmResponse.setZoneName(userVmData.getZoneName());
|
||||
if (caller_is_admin){
|
||||
if (caller_is_admin) {
|
||||
userVmResponse.setHostId(userVmData.getHostId());
|
||||
userVmResponse.setHostName(userVmData.getHostName());
|
||||
}
|
||||
@ -2926,7 +2923,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
userVmResponse.setForVirtualNetwork(userVmData.getForVirtualNetwork());
|
||||
|
||||
Set<SecurityGroupResponse> securityGroupResponse = new HashSet<SecurityGroupResponse>();
|
||||
for (SecurityGroupData sgd: userVmData.getSecurityGroupList()){
|
||||
for (SecurityGroupData sgd : userVmData.getSecurityGroupList()) {
|
||||
if (sgd.getId() != null) {
|
||||
SecurityGroupResponse sgr = new SecurityGroupResponse();
|
||||
sgr.setId(sgd.getId());
|
||||
@ -2946,7 +2943,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
userVmResponse.setSecurityGroupList(new ArrayList<SecurityGroupResponse>(securityGroupResponse));
|
||||
|
||||
Set<NicResponse> nicResponses = new HashSet<NicResponse>();
|
||||
for (NicData nd: userVmData.getNics()){
|
||||
for (NicData nd : userVmData.getNics()) {
|
||||
NicResponse nr = new NicResponse();
|
||||
nr.setId(nd.getId());
|
||||
nr.setNetworkid(nd.getNetworkid());
|
||||
@ -2968,7 +2965,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public HypervisorCapabilitiesResponse createHypervisorCapabilitiesResponse(HypervisorCapabilities hpvCapabilities){
|
||||
public HypervisorCapabilitiesResponse createHypervisorCapabilitiesResponse(HypervisorCapabilities hpvCapabilities) {
|
||||
HypervisorCapabilitiesResponse hpvCapabilitiesResponse = new HypervisorCapabilitiesResponse();
|
||||
hpvCapabilitiesResponse.setId(hpvCapabilities.getId());
|
||||
hpvCapabilitiesResponse.setHypervisor(hpvCapabilities.getHypervisorType());
|
||||
@ -2982,7 +2979,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
Account account = ApiDBUtils.findAccountByIdIncludingRemoved(object.getAccountId());
|
||||
|
||||
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
//find the project
|
||||
// find the project
|
||||
Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
|
||||
response.setProjectId(project.getId());
|
||||
response.setProjectName(project.getName());
|
||||
@ -2998,7 +2995,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
private void populateAccount(ControlledEntityResponse response, long accountId) {
|
||||
Account account = ApiDBUtils.findAccountByIdIncludingRemoved(accountId);
|
||||
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
//find the project
|
||||
// find the project
|
||||
Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
|
||||
response.setProjectId(project.getId());
|
||||
response.setProjectName(project.getName());
|
||||
@ -3066,7 +3063,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine vm){
|
||||
public SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine vm) {
|
||||
SystemVmInstanceResponse vmResponse = new SystemVmInstanceResponse();
|
||||
vmResponse.setId(vm.getId());
|
||||
vmResponse.setSystemVmType(vm.getType().toString().toLowerCase());
|
||||
@ -3078,8 +3075,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
vmResponse.setState(vm.getState().toString());
|
||||
}
|
||||
if (vm.getType() == Type.DomainRouter) {
|
||||
VirtualRouter router = (VirtualRouter)vm;
|
||||
if(router.getRole() != null){
|
||||
VirtualRouter router = (VirtualRouter) vm;
|
||||
if (router.getRole() != null) {
|
||||
vmResponse.setRole(router.getRole().toString());
|
||||
}
|
||||
}
|
||||
@ -3096,12 +3093,12 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
response.setVlan(result.getVnet());
|
||||
response.setDomainId(result.getDomainId());
|
||||
response.setId(result.getUuid());
|
||||
if(result.getBroadcastDomainRange() != null){
|
||||
if (result.getBroadcastDomainRange() != null) {
|
||||
response.setBroadcastDomainRange(result.getBroadcastDomainRange().toString());
|
||||
}
|
||||
response.setIsolationMethods(result.getIsolationMethods());
|
||||
response.setTags(result.getTags());
|
||||
if(result.getState() != null){
|
||||
if (result.getState() != null) {
|
||||
response.setState(result.getState().toString());
|
||||
}
|
||||
|
||||
@ -3112,20 +3109,20 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceResponse createNetworkServiceResponse(Service service){
|
||||
public ServiceResponse createNetworkServiceResponse(Service service) {
|
||||
ServiceResponse response = new ServiceResponse();
|
||||
response.setName(service.getName());
|
||||
|
||||
// set list of capabilities required for the service
|
||||
List<CapabilityResponse> capabilityResponses = new ArrayList<CapabilityResponse>();
|
||||
Capability[] capabilities = service.getCapabilities();
|
||||
for(Capability cap : capabilities){
|
||||
for (Capability cap : capabilities) {
|
||||
CapabilityResponse capabilityResponse = new CapabilityResponse();
|
||||
capabilityResponse.setName(cap.getName());
|
||||
capabilityResponse.setObjectName("capability");
|
||||
if (cap.getName().equals(Capability.SupportedLBIsolation.getName()) ||
|
||||
cap.getName().equals(Capability.SupportedSourceNatTypes.getName()) ||
|
||||
cap.getName().equals(Capability.RedundantRouter.getName()) ) {
|
||||
cap.getName().equals(Capability.RedundantRouter.getName())) {
|
||||
capabilityResponse.setCanChoose(true);
|
||||
} else {
|
||||
capabilityResponse.setCanChoose(false);
|
||||
@ -3134,11 +3131,11 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
response.setCapabilities(capabilityResponses);
|
||||
|
||||
//set list of providers providing this service
|
||||
// set list of providers providing this service
|
||||
List<? extends Network.Provider> serviceProviders = ApiDBUtils.getProvidersForService(service);
|
||||
List<ProviderResponse> serviceProvidersResponses = new ArrayList<ProviderResponse>();
|
||||
for (Network.Provider serviceProvider : serviceProviders) {
|
||||
//return only Virtual Router as a provider for the firewall
|
||||
// return only Virtual Router as a provider for the firewall
|
||||
if (service == Service.Firewall && !(serviceProvider == Provider.VirtualRouter)) {
|
||||
continue;
|
||||
}
|
||||
@ -3162,7 +3159,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderResponse createNetworkServiceProviderResponse(PhysicalNetworkServiceProvider result){
|
||||
public ProviderResponse createNetworkServiceProviderResponse(PhysicalNetworkServiceProvider result) {
|
||||
ProviderResponse response = new ProviderResponse();
|
||||
response.setId(result.getUuid());
|
||||
response.setName(result.getProviderName());
|
||||
@ -3170,9 +3167,9 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
response.setDestinationPhysicalNetworkId(result.getDestinationPhysicalNetworkId());
|
||||
response.setState(result.getState().toString());
|
||||
|
||||
//set enabled services
|
||||
// set enabled services
|
||||
List<String> services = new ArrayList<String>();
|
||||
for (Service service: result.getEnabledServices()){
|
||||
for (Service service : result.getEnabledServices()) {
|
||||
services.add(service.getName());
|
||||
}
|
||||
response.setServices(services);
|
||||
@ -3195,7 +3192,6 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VirtualRouterProviderResponse createVirtualRouterProviderResponse(VirtualRouterProvider result) {
|
||||
VirtualRouterProviderResponse response = new VirtualRouterProviderResponse();
|
||||
@ -3206,6 +3202,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
response.setObjectName("virtualrouterelement");
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LBStickinessResponse createLBStickinessPolicyResponse(
|
||||
StickinessPolicy stickinessPolicy, LoadBalancer lb) {
|
||||
@ -3236,7 +3233,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
List<? extends StickinessPolicy> stickinessPolicies, LoadBalancer lb) {
|
||||
LBStickinessResponse spResponse = new LBStickinessResponse();
|
||||
|
||||
if (lb == null) return spResponse ;
|
||||
if (lb == null)
|
||||
return spResponse;
|
||||
spResponse.setlbRuleId(lb.getId());
|
||||
Account account = ApiDBUtils.findAccountById(lb.getAccountId());
|
||||
if (account != null) {
|
||||
@ -3285,4 +3283,5 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
response.setObjectName("storagenetworkiprange");
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/**
|
||||
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
@ -173,44 +174,44 @@ public class ApiServer implements HttpRequestHandler {
|
||||
return _apiCommands;
|
||||
}
|
||||
|
||||
public static boolean isPluggableServiceCommand(String cmdClassName){
|
||||
if(s_pluggableServiceCommands != null){
|
||||
if(s_pluggableServiceCommands.contains(cmdClassName)){
|
||||
public static boolean isPluggableServiceCommand(String cmdClassName) {
|
||||
if (s_pluggableServiceCommands != null) {
|
||||
if (s_pluggableServiceCommands.contains(cmdClassName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String[] getPluggableServicesApiConfigs(){
|
||||
private String[] getPluggableServicesApiConfigs() {
|
||||
List<String> pluggableServicesApiConfigs = new ArrayList<String>();
|
||||
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
|
||||
List<PluggableService> services = locator.getAllPluggableServices();
|
||||
for(PluggableService service : services){
|
||||
for (PluggableService service : services) {
|
||||
pluggableServicesApiConfigs.add(service.getPropertiesFile());
|
||||
}
|
||||
return pluggableServicesApiConfigs.toArray(new String[0]);
|
||||
}
|
||||
|
||||
private void processConfigFiles(String[] apiConfig, boolean pluggableServicesConfig){
|
||||
try{
|
||||
if(_apiCommands == null){
|
||||
private void processConfigFiles(String[] apiConfig, boolean pluggableServicesConfig) {
|
||||
try {
|
||||
if (_apiCommands == null) {
|
||||
_apiCommands = new Properties();
|
||||
}
|
||||
Properties preProcessedCommands = new Properties();
|
||||
if (apiConfig != null) {
|
||||
for (String configFile : apiConfig) {
|
||||
File commandsFile = PropertiesUtil.findConfigFile(configFile);
|
||||
if(commandsFile != null){
|
||||
try{
|
||||
if (commandsFile != null) {
|
||||
try {
|
||||
preProcessedCommands.load(new FileInputStream(commandsFile));
|
||||
}catch (FileNotFoundException fnfex) {
|
||||
//in case of a file within a jar in classpath, try to open stream using url
|
||||
} catch (FileNotFoundException fnfex) {
|
||||
// in case of a file within a jar in classpath, try to open stream using url
|
||||
InputStream stream = PropertiesUtil.openStreamFromURL(configFile);
|
||||
if(stream != null){
|
||||
if (stream != null) {
|
||||
preProcessedCommands.load(stream);
|
||||
}else{
|
||||
} else {
|
||||
s_logger.error("Unable to find properites file", fnfex);
|
||||
}
|
||||
}
|
||||
@ -221,7 +222,7 @@ public class ApiServer implements HttpRequestHandler {
|
||||
String[] commandParts = preProcessedCommand.split(";");
|
||||
_apiCommands.put(key, commandParts[0]);
|
||||
|
||||
if(pluggableServicesConfig){
|
||||
if (pluggableServicesConfig) {
|
||||
s_pluggableServiceCommands.add(commandParts[0]);
|
||||
}
|
||||
|
||||
@ -263,7 +264,7 @@ public class ApiServer implements HttpRequestHandler {
|
||||
BaseListCmd.configure();
|
||||
processConfigFiles(apiConfig, false);
|
||||
|
||||
//get commands for all pluggable services
|
||||
// get commands for all pluggable services
|
||||
String[] pluggableServicesApiConfigs = getPluggableServicesApiConfigs();
|
||||
processConfigFiles(pluggableServicesApiConfigs, true);
|
||||
|
||||
@ -333,7 +334,8 @@ public class ApiServer implements HttpRequestHandler {
|
||||
if ("response".equalsIgnoreCase(paramValue[0])) {
|
||||
responseType = paramValue[1];
|
||||
} else {
|
||||
// according to the servlet spec, the parameter map should be in the form (name=String, value=String[]), so
|
||||
// according to the servlet spec, the parameter map should be in the form (name=String,
|
||||
// value=String[]), so
|
||||
// parameter values will be stored in an array
|
||||
parameterMap.put(/* name */paramValue[0], /* value */new String[] { paramValue[1] });
|
||||
}
|
||||
@ -557,10 +559,13 @@ public class ApiServer implements HttpRequestHandler {
|
||||
auditTrailSb.append(" " + HttpServletResponse.SC_OK + " ");
|
||||
auditTrailSb.append(result);
|
||||
/*
|
||||
* if (command.equals("queryAsyncJobResult")){ //For this command we need to also log job status and job resultcode for
|
||||
* if (command.equals("queryAsyncJobResult")){ //For this command we need to also log job status and job
|
||||
* resultcode for
|
||||
* (Pair<String,Object> pair : resultValues){ String key = pair.first(); if (key.equals("jobstatus")){
|
||||
* auditTrailSb.append(" "); auditTrailSb.append(key); auditTrailSb.append("="); auditTrailSb.append(pair.second());
|
||||
* }else if (key.equals("jobresultcode")){ auditTrailSb.append(" "); auditTrailSb.append(key); auditTrailSb.append("=");
|
||||
* auditTrailSb.append(" "); auditTrailSb.append(key); auditTrailSb.append("=");
|
||||
* auditTrailSb.append(pair.second());
|
||||
* }else if (key.equals("jobresultcode")){ auditTrailSb.append(" "); auditTrailSb.append(key);
|
||||
* auditTrailSb.append("=");
|
||||
* auditTrailSb.append(pair.second()); } } }else { for (Pair<String,Object> pair : resultValues){ if
|
||||
* (pair.first().equals("jobid")){ // Its an async job so report the jobid auditTrailSb.append(" ");
|
||||
* auditTrailSb.append(pair.first()); auditTrailSb.append("="); auditTrailSb.append(pair.second()); } } }
|
||||
@ -653,22 +658,22 @@ public class ApiServer implements HttpRequestHandler {
|
||||
}
|
||||
|
||||
Date expiresTS = null;
|
||||
if("3".equals(signatureVersion)){
|
||||
if ("3".equals(signatureVersion)) {
|
||||
// New signature authentication. Check for expire parameter and its validity
|
||||
if(expires == null){
|
||||
if (expires == null) {
|
||||
s_logger.info("missing Expires parameter -- ignoring request...sig: " + signature + ", apiKey: " + apiKey);
|
||||
return false;
|
||||
}
|
||||
synchronized (_dateFormat) {
|
||||
try{
|
||||
try {
|
||||
expiresTS = _dateFormat.parse(expires);
|
||||
} catch (ParseException pe){
|
||||
} catch (ParseException pe) {
|
||||
s_logger.info("Incorrect date format for Expires parameter", pe);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Date now = new Date(System.currentTimeMillis());
|
||||
if(expiresTS.before(now)){
|
||||
if (expiresTS.before(now)) {
|
||||
s_logger.info("Request expired -- ignoring ...sig: " + signature + ", apiKey: " + apiKey);
|
||||
return false;
|
||||
}
|
||||
@ -861,7 +866,8 @@ public class ApiServer implements HttpRequestHandler {
|
||||
|
||||
// FIXME: the following two threads are copied from
|
||||
// http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpServer.java
|
||||
// we have to cite a license if we are using this code directly, so we need to add the appropriate citation or modify the
|
||||
// we have to cite a license if we are using this code directly, so we need to add the appropriate citation or
|
||||
// modify the
|
||||
// code to be very specific to our needs
|
||||
static class ListenerThread extends Thread {
|
||||
private HttpService _httpService = null;
|
||||
@ -971,9 +977,9 @@ public class ApiServer implements HttpRequestHandler {
|
||||
responseName = "errorresponse";
|
||||
} else {
|
||||
Object cmdObj = apiCommandParams.get("command");
|
||||
//cmd name can be null when "command" parameter is missing in the request
|
||||
// cmd name can be null when "command" parameter is missing in the request
|
||||
if (cmdObj != null) {
|
||||
String cmdName = ((String[])cmdObj) [0];
|
||||
String cmdName = ((String[]) cmdObj)[0];
|
||||
cmdClassName = _apiCommands.getProperty(cmdName);
|
||||
if (cmdClassName != null) {
|
||||
Class<?> claz = Class.forName(cmdClassName);
|
||||
|
||||
@ -48,13 +48,15 @@ import com.cloud.utils.component.Manager;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
||||
/**
|
||||
* ConfigurationManager handles adding pods/zones, changing IP ranges, enabling external firewalls, and editing configuration values
|
||||
* ConfigurationManager handles adding pods/zones, changing IP ranges, enabling external firewalls, and editing
|
||||
* configuration values
|
||||
*
|
||||
*/
|
||||
public interface ConfigurationManager extends ConfigurationService, Manager {
|
||||
|
||||
/**
|
||||
* Updates a configuration entry with a new value
|
||||
*
|
||||
* @param userId
|
||||
* @param name
|
||||
* @param value
|
||||
@ -63,6 +65,7 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
|
||||
|
||||
/**
|
||||
* Creates a new service offering
|
||||
*
|
||||
* @param name
|
||||
* @param cpu
|
||||
* @param ramSize
|
||||
@ -72,15 +75,18 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
|
||||
* @param offerHA
|
||||
* @param domainId
|
||||
* @param hostTag
|
||||
* @param networkRate TODO
|
||||
* @param networkRate
|
||||
* TODO
|
||||
* @param id
|
||||
* @param useVirtualNetwork
|
||||
* @return ID
|
||||
*/
|
||||
ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, VirtualMachine.Type vm_typeType, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean limitResourceUse, String tags, Long domainId, String hostTag, Integer networkRate);
|
||||
ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, VirtualMachine.Type vm_typeType, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired,
|
||||
boolean offerHA, boolean limitResourceUse, String tags, Long domainId, String hostTag, Integer networkRate);
|
||||
|
||||
/**
|
||||
* Creates a new disk offering
|
||||
*
|
||||
* @param domainId
|
||||
* @param name
|
||||
* @param description
|
||||
@ -93,6 +99,7 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
|
||||
|
||||
/**
|
||||
* Creates a new pod
|
||||
*
|
||||
* @param userId
|
||||
* @param podName
|
||||
* @param zoneId
|
||||
@ -101,13 +108,15 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
|
||||
* @param startIp
|
||||
* @param endIp
|
||||
* @param allocationState
|
||||
* @param skipGatewayOverlapCheck (true if it is ok to not validate that gateway IP address overlap with Start/End IP of the POD)
|
||||
* @param skipGatewayOverlapCheck
|
||||
* (true if it is ok to not validate that gateway IP address overlap with Start/End IP of the POD)
|
||||
* @return Pod
|
||||
*/
|
||||
HostPodVO createPod(long userId, String podName, long zoneId, String gateway, String cidr, String startIp, String endIp, String allocationState, boolean skipGatewayOverlapCheck);
|
||||
|
||||
/**
|
||||
* Creates a new zone
|
||||
*
|
||||
* @param userId
|
||||
* @param zoneName
|
||||
* @param dns1
|
||||
@ -116,36 +125,44 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
|
||||
* @param internalDns2
|
||||
* @param zoneType
|
||||
* @param allocationState
|
||||
* @param networkDomain TODO
|
||||
* @param isSecurityGroupEnabled TODO
|
||||
* @param networkDomain
|
||||
* TODO
|
||||
* @param isSecurityGroupEnabled
|
||||
* TODO
|
||||
* @return
|
||||
* @throws
|
||||
* @throws
|
||||
*/
|
||||
DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String domain, Long domainId, NetworkType zoneType, String allocationState, String networkDomain, boolean isSecurityGroupEnabled);
|
||||
DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String domain, Long domainId, NetworkType zoneType, String allocationState,
|
||||
String networkDomain, boolean isSecurityGroupEnabled);
|
||||
|
||||
/**
|
||||
* Deletes a VLAN from the database, along with all of its IP addresses. Will not delete VLANs that have allocated IP addresses.
|
||||
* Deletes a VLAN from the database, along with all of its IP addresses. Will not delete VLANs that have allocated
|
||||
* IP addresses.
|
||||
*
|
||||
* @param userId
|
||||
* @param vlanDbId
|
||||
* @return success/failure
|
||||
*/
|
||||
boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId);
|
||||
|
||||
|
||||
/**
|
||||
* Adds/deletes private IPs
|
||||
* @param add - either true or false
|
||||
*
|
||||
* @param add
|
||||
* - either true or false
|
||||
* @param podId
|
||||
* @param startIP
|
||||
* @param endIP
|
||||
* @return Message to display to user
|
||||
* @throws if unable to add private ip range
|
||||
* @throws if
|
||||
* unable to add private ip range
|
||||
*/
|
||||
String changePrivateIPRange(boolean add, long podId, String startIP, String endIP);
|
||||
|
||||
/**
|
||||
* Converts a comma separated list of tags to a List
|
||||
*
|
||||
* @param tags
|
||||
* @return List of tags
|
||||
*/
|
||||
@ -153,6 +170,7 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
|
||||
|
||||
/**
|
||||
* Converts a List of tags to a comma separated list
|
||||
*
|
||||
* @param tags
|
||||
* @return String containing a comma separated list of tags
|
||||
*/
|
||||
@ -167,29 +185,40 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
|
||||
void checkDiskOfferingAccess(Account caller, DiskOffering dof)
|
||||
throws PermissionDeniedException;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new network offering
|
||||
*
|
||||
* @param name
|
||||
* @param displayText
|
||||
* @param trafficType
|
||||
* @param tags
|
||||
* @param networkRate TODO
|
||||
* @param serviceProviderMap TODO
|
||||
* @param isDefault TODO
|
||||
* @param type TODO
|
||||
* @param systemOnly TODO
|
||||
* @param networkRate
|
||||
* TODO
|
||||
* @param serviceProviderMap
|
||||
* TODO
|
||||
* @param isDefault
|
||||
* TODO
|
||||
* @param type
|
||||
* TODO
|
||||
* @param systemOnly
|
||||
* TODO
|
||||
* @param serviceOfferingId
|
||||
* @param specifyIpRanges TODO
|
||||
* @param specifyIpRanges
|
||||
* TODO
|
||||
* @param id
|
||||
* @param specifyVlan;
|
||||
* @param conserveMode;
|
||||
* @param specifyVlan
|
||||
* ;
|
||||
* @param conserveMode
|
||||
* ;
|
||||
* @return network offering object
|
||||
*/
|
||||
|
||||
NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate, Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId, boolean conserveMode, Map<Service, Map<Capability, String>> serviceCapabilityMap, boolean specifyIpRanges);
|
||||
NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate,
|
||||
Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId, boolean conserveMode,
|
||||
Map<Service, Map<Capability, String>> serviceCapabilityMap, boolean specifyIpRanges);
|
||||
|
||||
Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, long networkId, Long physicalNetworkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException;
|
||||
Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, long networkId,
|
||||
Long physicalNetworkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException;
|
||||
|
||||
void createDefaultSystemNetworks(long zoneId) throws ConcurrentOperationException;
|
||||
|
||||
@ -203,6 +232,7 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
|
||||
|
||||
/**
|
||||
* Edits a pod in the database. Will not allow you to edit pods that are being used anywhere in the system.
|
||||
*
|
||||
* @param id
|
||||
* @param name
|
||||
* @param startIp
|
||||
|
||||
@ -332,7 +332,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
throw new InvalidParameterValueException(validationMsg);
|
||||
}
|
||||
|
||||
//Execute all updates in a single transaction
|
||||
// Execute all updates in a single transaction
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
@ -341,7 +341,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
throw new CloudRuntimeException("Failed to update configuration value. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
if (Config.XenGuestNetwork.key().equalsIgnoreCase(name)) {
|
||||
String sql = "update host_details set value=? where name=?";
|
||||
@ -437,7 +436,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
Long userId = UserContext.current().getCallerUserId();
|
||||
String name = cmd.getCfgName();
|
||||
String value = cmd.getValue();
|
||||
UserContext.current().setEventDetails(" Name: "+name +" New Value: "+ (((name.toLowerCase()).contains("password")) ? "*****" :
|
||||
UserContext.current().setEventDetails(" Name: " + name + " New Value: " + (((name.toLowerCase()).contains("password")) ? "*****" :
|
||||
(((value == null) ? "" : value))));
|
||||
// check if config value exists
|
||||
ConfigurationVO config = _configDao.findByName(name);
|
||||
@ -536,7 +535,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
if (!NetUtils.verifyInstanceName(value)) {
|
||||
return "Instance name can not contain hyphen, spaces and plus sign";
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
String[] options = range.split(",");
|
||||
for (String option : options) {
|
||||
if (option.trim().equalsIgnoreCase(value)) {
|
||||
@ -705,7 +704,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
String checkPodCIDRs = _configDao.getValue("check.pod.cidrs");
|
||||
if (checkPodCIDRs == null || checkPodCIDRs.trim().isEmpty() || Boolean.parseBoolean(checkPodCIDRs)) {
|
||||
checkPodCidrSubnets(zoneId, podId, cidr);
|
||||
/* Commenting out due to Bug 11593 - CIDR conflicts with zone when extending pod but not when creating it
|
||||
/*
|
||||
* Commenting out due to Bug 11593 - CIDR conflicts with zone when extending pod but not when creating it
|
||||
*
|
||||
* checkCidrVlanOverlap(zoneId, cidr);
|
||||
*/
|
||||
@ -1177,8 +1177,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
List<HostPodVO> podsInZone = _podDao.listByDataCenterId(zoneId);
|
||||
for (HostPodVO hostPod : podsInZone) {
|
||||
String[] IpRange = hostPod.getDescription().split("-");
|
||||
if (IpRange[0]==null || IpRange[1]==null) continue;
|
||||
if (!NetUtils.isValidIp(IpRange[0]) || !NetUtils.isValidIp(IpRange[1])) continue;
|
||||
if (IpRange[0] == null || IpRange[1] == null)
|
||||
continue;
|
||||
if (!NetUtils.isValidIp(IpRange[0]) || !NetUtils.isValidIp(IpRange[1]))
|
||||
continue;
|
||||
if (NetUtils.ipRangesOverlap(startIp, endIp, IpRange[0], IpRange[1])) {
|
||||
throw new InvalidParameterValueException("The Start IP and endIP address range overlap with private IP :" + IpRange[0] + ":" + IpRange[1]);
|
||||
}
|
||||
@ -1218,7 +1220,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
success = _zoneDao.remove(zoneId);
|
||||
|
||||
if (success) {
|
||||
//delete all capacity records for the zone
|
||||
// delete all capacity records for the zone
|
||||
_capacityDao.removeBy(null, zoneId, null, null, null);
|
||||
}
|
||||
|
||||
@ -1228,7 +1230,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public boolean updateLDAP(LDAPConfigCmd cmd) {
|
||||
@ -1242,23 +1243,23 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
String bindDN = cmd.getBindDN();
|
||||
String bindPasswd = cmd.getBindPassword();
|
||||
|
||||
if (bindDN != null && bindPasswd == null ){
|
||||
if (bindDN != null && bindPasswd == null) {
|
||||
throw new InvalidParameterValueException("If you specify a bind name then you need to provide bind password too.");
|
||||
}
|
||||
|
||||
//System.setProperty("javax.net.ssl.keyStore", "/cygdrive/c/citrix/info/cacerts.jks");
|
||||
//System.setProperty("javax.net.ssl.keyStorePassword", "1111_aaaa");
|
||||
// System.setProperty("javax.net.ssl.keyStore", "/cygdrive/c/citrix/info/cacerts.jks");
|
||||
// System.setProperty("javax.net.ssl.keyStorePassword", "1111_aaaa");
|
||||
|
||||
// check if the info is correct
|
||||
Hashtable<String, String> env = new Hashtable<String, String>(11);
|
||||
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
|
||||
String protocol = "ldap://" ;
|
||||
if (new Boolean(useSSL)){
|
||||
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
|
||||
String protocol = "ldap://";
|
||||
if (new Boolean(useSSL)) {
|
||||
env.put(Context.SECURITY_PROTOCOL, "ssl");
|
||||
protocol="ldaps://" ;
|
||||
protocol = "ldaps://";
|
||||
}
|
||||
env.put(Context.PROVIDER_URL, protocol + hostname + ":" + port);
|
||||
if (bindDN != null && bindPasswd != null){
|
||||
if (bindDN != null && bindPasswd != null) {
|
||||
env.put(Context.SECURITY_PRINCIPAL, bindDN);
|
||||
env.put(Context.SECURITY_CREDENTIALS, bindPasswd);
|
||||
}
|
||||
@ -1266,53 +1267,60 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
DirContext ctx = new InitialDirContext(env);
|
||||
ctx.close();
|
||||
|
||||
|
||||
// store the result in DB COnfiguration
|
||||
ConfigurationVO cvo = _configDao.findByName(LDAPParams.hostname.toString());
|
||||
if (cvo==null){
|
||||
if (cvo == null) {
|
||||
cvo = new ConfigurationVO("Advanced", "DEFAULT", "management-server", LDAPParams.hostname.toString(), null, "Hostname or ip address of the ldap server eg: my.ldap.com");
|
||||
}
|
||||
cvo.setValue(hostname); _configDao.persist(cvo);
|
||||
cvo.setValue(hostname);
|
||||
_configDao.persist(cvo);
|
||||
|
||||
cvo = _configDao.findByName(LDAPParams.port.toString());
|
||||
if (cvo==null){
|
||||
if (cvo == null) {
|
||||
cvo = new ConfigurationVO("Advanced", "DEFAULT", "management-server", LDAPParams.port.toString(), null, "Specify the LDAP port if required, default is 389");
|
||||
}
|
||||
cvo.setValue(port.toString()); _configDao.persist(cvo);
|
||||
cvo.setValue(port.toString());
|
||||
_configDao.persist(cvo);
|
||||
|
||||
cvo = _configDao.findByName(LDAPParams.queryfilter.toString());
|
||||
if (cvo==null){
|
||||
cvo = new ConfigurationVO("Advanced","DEFAULT", "management-server", LDAPParams.queryfilter.toString(), null, "You specify a query filter here, which narrows down the users, who can be part of this domain");
|
||||
if (cvo == null) {
|
||||
cvo = new ConfigurationVO("Advanced", "DEFAULT", "management-server", LDAPParams.queryfilter.toString(), null,
|
||||
"You specify a query filter here, which narrows down the users, who can be part of this domain");
|
||||
}
|
||||
cvo.setValue(queryFilter); _configDao.persist(cvo);
|
||||
cvo.setValue(queryFilter);
|
||||
_configDao.persist(cvo);
|
||||
|
||||
cvo = _configDao.findByName(LDAPParams.searchbase.toString());
|
||||
if (cvo==null){
|
||||
cvo = new ConfigurationVO("Advanced","DEFAULT", "management-server", LDAPParams.searchbase.toString(), null, "The search base defines the starting point for the search in the directory tree Example: dc=cloud,dc=com.");
|
||||
if (cvo == null) {
|
||||
cvo = new ConfigurationVO("Advanced", "DEFAULT", "management-server", LDAPParams.searchbase.toString(), null,
|
||||
"The search base defines the starting point for the search in the directory tree Example: dc=cloud,dc=com.");
|
||||
}
|
||||
cvo.setValue(searchBase); _configDao.persist(cvo);
|
||||
cvo.setValue(searchBase);
|
||||
_configDao.persist(cvo);
|
||||
|
||||
cvo = _configDao.findByName(LDAPParams.usessl.toString());
|
||||
if (cvo==null){
|
||||
cvo = new ConfigurationVO("Advanced","DEFAULT", "management-server", LDAPParams.usessl.toString(), null, "Check Use SSL if the external LDAP server is configured for LDAP over SSL.");
|
||||
if (cvo == null) {
|
||||
cvo = new ConfigurationVO("Advanced", "DEFAULT", "management-server", LDAPParams.usessl.toString(), null, "Check Use SSL if the external LDAP server is configured for LDAP over SSL.");
|
||||
}
|
||||
cvo.setValue(useSSL.toString()); _configDao.persist(cvo);
|
||||
cvo.setValue(useSSL.toString());
|
||||
_configDao.persist(cvo);
|
||||
|
||||
cvo = _configDao.findByName(LDAPParams.dn.toString());
|
||||
if (cvo==null){
|
||||
cvo = new ConfigurationVO("Advanced","DEFAULT", "management-server", LDAPParams.dn.toString(), null, "Specify the distinguished name of a user with the search permission on the directory");
|
||||
if (cvo == null) {
|
||||
cvo = new ConfigurationVO("Advanced", "DEFAULT", "management-server", LDAPParams.dn.toString(), null, "Specify the distinguished name of a user with the search permission on the directory");
|
||||
}
|
||||
cvo.setValue(bindDN); _configDao.persist(cvo);
|
||||
cvo.setValue(bindDN);
|
||||
_configDao.persist(cvo);
|
||||
|
||||
cvo = _configDao.findByName(LDAPParams.passwd.toString());
|
||||
if (cvo==null){
|
||||
cvo = new ConfigurationVO("Advanced","DEFAULT", "management-server", LDAPParams.passwd.toString(), null, "Enter the password");
|
||||
if (cvo == null) {
|
||||
cvo = new ConfigurationVO("Advanced", "DEFAULT", "management-server", LDAPParams.passwd.toString(), null, "Enter the password");
|
||||
}
|
||||
cvo.setValue(bindPasswd); _configDao.persist(cvo);
|
||||
}
|
||||
catch (NamingException ne){
|
||||
cvo.setValue(bindPasswd);
|
||||
_configDao.persist(cvo);
|
||||
} catch (NamingException ne) {
|
||||
ne.printStackTrace();
|
||||
throw new InvalidParameterValueException("Naming Exception, check you ldap data ! " + ne.getMessage() + (ne.getCause() != null ? ( "Caused by:" + ne.getCause().getMessage()) : ""));
|
||||
throw new InvalidParameterValueException("Naming Exception, check you ldap data ! " + ne.getMessage() + (ne.getCause() != null ? ("Caused by:" + ne.getCause().getMessage()) : ""));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -1456,16 +1464,16 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
|
||||
Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr);
|
||||
|
||||
if(allocationState == Grouping.AllocationState.Enabled){
|
||||
//check if zone has necessary trafficTypes before enabling
|
||||
try{
|
||||
if (allocationState == Grouping.AllocationState.Enabled) {
|
||||
// check if zone has necessary trafficTypes before enabling
|
||||
try {
|
||||
PhysicalNetwork mgmtPhyNetwork;
|
||||
if(NetworkType.Advanced == zone.getNetworkType()){
|
||||
//zone should have a physical network with public and management traffiType
|
||||
if (NetworkType.Advanced == zone.getNetworkType()) {
|
||||
// zone should have a physical network with public and management traffiType
|
||||
_networkMgr.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Public);
|
||||
mgmtPhyNetwork = _networkMgr.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Management);
|
||||
}else{
|
||||
//zone should have a physical network with management traffiType
|
||||
} else {
|
||||
// zone should have a physical network with management traffiType
|
||||
mgmtPhyNetwork = _networkMgr.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Management);
|
||||
}
|
||||
|
||||
@ -1473,11 +1481,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
_networkMgr.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Storage);
|
||||
} catch (InvalidParameterValueException noStorage) {
|
||||
PhysicalNetworkTrafficTypeVO mgmtTraffic = _trafficTypeDao.findBy(mgmtPhyNetwork.getId(), TrafficType.Management);
|
||||
_networkMgr.addTrafficTypeToPhysicalNetwork(mgmtPhyNetwork.getId(), TrafficType.Storage.toString(), mgmtTraffic.getXenNetworkLabel(), mgmtTraffic.getKvmNetworkLabel(), mgmtTraffic.getVmwareNetworkLabel(), mgmtTraffic.getSimulatorNetworkLabel(), mgmtTraffic.getVlan());
|
||||
_networkMgr.addTrafficTypeToPhysicalNetwork(mgmtPhyNetwork.getId(), TrafficType.Storage.toString(), mgmtTraffic.getXenNetworkLabel(), mgmtTraffic.getKvmNetworkLabel(),
|
||||
mgmtTraffic.getVmwareNetworkLabel(), mgmtTraffic.getSimulatorNetworkLabel(), mgmtTraffic.getVlan());
|
||||
s_logger.info("No storage traffic type was specified by admin, create default storage traffic on physical network " + mgmtPhyNetwork.getId() + " with same configure of management traffic type");
|
||||
}
|
||||
}catch(InvalidParameterValueException ex){
|
||||
throw new InvalidParameterValueException("Cannot enable this Zone since: "+ ex.getMessage());
|
||||
} catch (InvalidParameterValueException ex) {
|
||||
throw new InvalidParameterValueException("Cannot enable this Zone since: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1526,8 +1535,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
|
||||
Grouping.AllocationState allocationState = Grouping.AllocationState.valueOf(allocationStateStr);
|
||||
zone.setAllocationState(allocationState);
|
||||
}else{
|
||||
//Zone will be disabled since 3.0. Admin shoul enable it after physical network and providers setup.
|
||||
} else {
|
||||
// Zone will be disabled since 3.0. Admin shoul enable it after physical network and providers setup.
|
||||
zone.setAllocationState(Grouping.AllocationState.Disabled);
|
||||
}
|
||||
zone = _zoneDao.persist(zone);
|
||||
@ -1547,7 +1556,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void createDefaultSystemNetworks(long zoneId) throws ConcurrentOperationException {
|
||||
DataCenterVO zone = _zoneDao.findById(zoneId);
|
||||
@ -2002,7 +2010,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
Long networkId = cmd.getNetworkID();
|
||||
String networkVlanId = null;
|
||||
Long physicalNetworkId = cmd.getPhysicalNetworkId();
|
||||
//projectId and accountName can't be specified together
|
||||
// projectId and accountName can't be specified together
|
||||
String accountName = cmd.getAccountName();
|
||||
Long projectId = cmd.getProjectId();
|
||||
Long domainId = cmd.getDomainId();
|
||||
@ -2039,15 +2047,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
}
|
||||
}
|
||||
|
||||
//verify that physical network exists
|
||||
// verify that physical network exists
|
||||
PhysicalNetworkVO pNtwk = null;
|
||||
if(physicalNetworkId != null){
|
||||
if (physicalNetworkId != null) {
|
||||
pNtwk = _physicalNetworkDao.findById(physicalNetworkId);
|
||||
if (pNtwk == null) {
|
||||
throw new InvalidParameterValueException("Unable to find Physical Network with id=" + physicalNetworkId);
|
||||
}
|
||||
}
|
||||
if(zoneId == null && pNtwk != null){
|
||||
if (zoneId == null && pNtwk != null) {
|
||||
zoneId = pNtwk.getDataCenterId();
|
||||
}
|
||||
// Verify that zone exists
|
||||
@ -2056,22 +2064,22 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
throw new InvalidParameterValueException("Unable to find zone by id " + zoneId);
|
||||
}
|
||||
|
||||
if(physicalNetworkId == null){
|
||||
//deduce physicalNetworkFrom Zone or Network.
|
||||
if(network != null && network.getPhysicalNetworkId() != null){
|
||||
if (physicalNetworkId == null) {
|
||||
// deduce physicalNetworkFrom Zone or Network.
|
||||
if (network != null && network.getPhysicalNetworkId() != null) {
|
||||
physicalNetworkId = network.getPhysicalNetworkId();
|
||||
}else{
|
||||
} else {
|
||||
if (forVirtualNetwork) {
|
||||
//default physical network with public traffic in the zone
|
||||
// default physical network with public traffic in the zone
|
||||
physicalNetworkId = _networkMgr.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Public).getId();
|
||||
} else {
|
||||
if (zone.getNetworkType() == DataCenter.NetworkType.Basic) {
|
||||
//default physical network with guest traffic in the zone
|
||||
// default physical network with guest traffic in the zone
|
||||
physicalNetworkId = _networkMgr.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Guest).getId();
|
||||
}else if(zone.getNetworkType() == DataCenter.NetworkType.Advanced) {
|
||||
if(zone.isSecurityGroupEnabled()){
|
||||
} else if (zone.getNetworkType() == DataCenter.NetworkType.Advanced) {
|
||||
if (zone.isSecurityGroupEnabled()) {
|
||||
physicalNetworkId = _networkMgr.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Guest).getId();
|
||||
}else{
|
||||
} else {
|
||||
throw new InvalidParameterValueException("Physical Network Id is null, please provide the Network id for Direct vlan creation ");
|
||||
}
|
||||
}
|
||||
@ -2118,7 +2126,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
network = _networkMgr.getNetwork(networkId);
|
||||
}
|
||||
|
||||
//Can add vlan range only to the network which allows it
|
||||
// Can add vlan range only to the network which allows it
|
||||
if (!network.getSpecifyIpRanges()) {
|
||||
throw new InvalidParameterValueException("Network " + network + " doesn't support adding multiple ip ranges");
|
||||
}
|
||||
@ -2399,7 +2407,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
vlan = _vlanDao.persist(vlan);
|
||||
|
||||
if (!savePublicIPRange(startIP, endIP, zoneId, vlan.getId(), networkId, physicalNetworkId)) {
|
||||
throw new CloudRuntimeException("Failed to save IP range. Please contact Cloud Support."); // It can be Direct IP or
|
||||
throw new CloudRuntimeException("Failed to save IP range. Please contact Cloud Support."); // It can be
|
||||
// Direct IP or
|
||||
// Public IP.
|
||||
}
|
||||
|
||||
@ -2722,7 +2731,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
HashMap<Long, List<Object>> currentPodCidrSubnets = _podDao.getCurrentPodCidrSubnets(dcId, skipPod);
|
||||
List<Object> newCidrPair = new ArrayList<Object>();
|
||||
newCidrPair.add(0, getCidrAddress(cidr));
|
||||
newCidrPair.add(1, (long)getCidrSize(cidr));
|
||||
newCidrPair.add(1, (long) getCidrSize(cidr));
|
||||
currentPodCidrSubnets.put(new Long(-1), newCidrPair);
|
||||
|
||||
String zoneName = getZoneName(dcId);
|
||||
@ -2925,7 +2934,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
throw new InvalidParameterValueException("Invalid value for traffictype. Supported traffic types: Public, Management, Control, Guest, Vlan or Storage");
|
||||
}
|
||||
|
||||
//Only GUEST traffic type is supported in Acton
|
||||
// Only GUEST traffic type is supported in Acton
|
||||
if (trafficType != TrafficType.Guest) {
|
||||
throw new InvalidParameterValueException("Only traffic type " + TrafficType.Guest + " is supported in the current release");
|
||||
}
|
||||
@ -2969,16 +2978,16 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
Map<Network.Service, Set<Network.Provider>> serviceProviderMap = new HashMap<Network.Service, Set<Network.Provider>>();
|
||||
Set<Network.Provider> defaultProviders = new HashSet<Network.Provider>();
|
||||
|
||||
//populate the services first
|
||||
// populate the services first
|
||||
for (String serviceName : cmd.getSupportedServices()) {
|
||||
//validate if the service is supported
|
||||
// validate if the service is supported
|
||||
Service service = Network.Service.getService(serviceName);
|
||||
if (service == null || service == Service.Gateway) {
|
||||
throw new InvalidParameterValueException("Invalid service " + serviceName);
|
||||
}
|
||||
|
||||
if (service == Service.SecurityGroup) {
|
||||
//allow security group service for Shared networks only
|
||||
// allow security group service for Shared networks only
|
||||
if (guestType != GuestType.Shared) {
|
||||
throw new InvalidParameterValueException("Secrity group service is supported for network offerings with guest ip type " + GuestType.Shared);
|
||||
}
|
||||
@ -2990,7 +2999,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
serviceProviderMap.put(service, defaultProviders);
|
||||
}
|
||||
|
||||
//add gateway provider (if sourceNat provider is enabled)
|
||||
// add gateway provider (if sourceNat provider is enabled)
|
||||
Set<Provider> sourceNatServiceProviders = serviceProviderMap.get(Service.SourceNat);
|
||||
if (sourceNatServiceProviders != null && !sourceNatServiceProviders.isEmpty()) {
|
||||
serviceProviderMap.put(Service.Gateway, sourceNatServiceProviders);
|
||||
@ -3004,7 +3013,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
Network.Service service = Network.Service.getService(serviceStr);
|
||||
if (serviceProviderMap.containsKey(service)) {
|
||||
Set<Provider> providers = new HashSet<Provider>();
|
||||
//in Acton, don't allow to specify more than 1 provider per service
|
||||
// in Acton, don't allow to specify more than 1 provider per service
|
||||
if (svcPrv.get(serviceStr) != null && svcPrv.get(serviceStr).size() > 1) {
|
||||
throw new InvalidParameterValueException("In the current release only one provider can be specified for the service");
|
||||
}
|
||||
@ -3015,7 +3024,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
throw new InvalidParameterValueException("Invalid service provider: " + prvNameStr);
|
||||
}
|
||||
|
||||
//Only VirtualRouter can be specified as a firewall provider
|
||||
// Only VirtualRouter can be specified as a firewall provider
|
||||
if (service == Service.Firewall && provider != Provider.VirtualRouter) {
|
||||
throw new InvalidParameterValueException("Only Virtual router can be specified as a provider for the Firewall service");
|
||||
}
|
||||
@ -3039,7 +3048,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
}
|
||||
}
|
||||
|
||||
//validate providers combination here
|
||||
// validate providers combination here
|
||||
_networkMgr.canProviderSupportServices(providerCombinationToVerify);
|
||||
|
||||
// validate the LB service capabilities specified in the network offering
|
||||
@ -3083,7 +3092,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
if (cap == Capability.SupportedLBIsolation) {
|
||||
boolean dedicatedLb = value.contains("dedicated");
|
||||
boolean sharedLB = value.contains("shared");
|
||||
if ((dedicatedLb && sharedLB) || (!dedicatedLb && !sharedLB)){
|
||||
if ((dedicatedLb && sharedLB) || (!dedicatedLb && !sharedLB)) {
|
||||
throw new InvalidParameterValueException("Either dedicated or shared isolation can be specified for " + Capability.SupportedLBIsolation.getName());
|
||||
}
|
||||
} else if (cap == Capability.ElasticLb) {
|
||||
@ -3126,7 +3135,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void validateStaticNatServiceCapablities(Map<Capability, String> staticNatServiceCapabilityMap) {
|
||||
if (staticNatServiceCapabilityMap != null && !staticNatServiceCapabilityMap.isEmpty()) {
|
||||
if (staticNatServiceCapabilityMap.keySet().size() > 1) {
|
||||
@ -3158,12 +3166,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr));
|
||||
tags = cleanupTags(tags);
|
||||
|
||||
//specifyIpRanges should always be true for Shared network offerings
|
||||
// specifyIpRanges should always be true for Shared network offerings
|
||||
if (!specifyIpRanges && type == GuestType.Shared) {
|
||||
throw new InvalidParameterValueException("SpecifyIpRanges should be true if network offering's type is " + type);
|
||||
}
|
||||
|
||||
//specifyVlan should always be true for Shared network offerings and Isolated network offerings with specifyIpRanges = true
|
||||
// specifyVlan should always be true for Shared network offerings and Isolated network offerings with
|
||||
// specifyIpRanges = true
|
||||
if (!specifyVlan) {
|
||||
if (type == GuestType.Shared) {
|
||||
throw new InvalidParameterValueException("SpecifyVlan should be true if network offering's type is " + type);
|
||||
@ -3172,14 +3181,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
}
|
||||
}
|
||||
|
||||
//validate availability value
|
||||
// validate availability value
|
||||
if (availability == NetworkOffering.Availability.Required) {
|
||||
boolean canOffBeRequired = (type == GuestType.Isolated && serviceProviderMap.containsKey(Service.SourceNat));
|
||||
if (!canOffBeRequired) {
|
||||
throw new InvalidParameterValueException("Availability can be " + NetworkOffering.Availability.Required + " only for networkOfferings of type " + GuestType.Isolated + " and with " + Service.SourceNat.getName() + " enabled");
|
||||
throw new InvalidParameterValueException("Availability can be " + NetworkOffering.Availability.Required + " only for networkOfferings of type " + GuestType.Isolated + " and with "
|
||||
+ Service.SourceNat.getName() + " enabled");
|
||||
}
|
||||
|
||||
//only one network offering in the system can be Required
|
||||
// only one network offering in the system can be Required
|
||||
List<NetworkOfferingVO> offerings = _networkOfferingDao.listByAvailability(Availability.Required, false);
|
||||
if (!offerings.isEmpty()) {
|
||||
throw new InvalidParameterValueException("System already has network offering id=" + offerings.get(0).getId() + " with availability " + Availability.Required);
|
||||
@ -3230,7 +3240,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
}
|
||||
}
|
||||
|
||||
NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb, sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges);
|
||||
NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb,
|
||||
sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges);
|
||||
|
||||
if (serviceOfferingId != null) {
|
||||
offering.setServiceOfferingId(serviceOfferingId);
|
||||
@ -3383,7 +3394,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
List<NetworkOfferingVO> offerings = _networkOfferingDao.search(sc, searchFilter);
|
||||
Boolean sourceNatSupported = cmd.getSourceNatSupported();
|
||||
|
||||
//filter by supported services
|
||||
// filter by supported services
|
||||
boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty());
|
||||
boolean checkIfProvidersAreEnabled = (zoneId != null);
|
||||
boolean parseOfferings = (listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled);
|
||||
@ -3528,10 +3539,11 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
if (availability == NetworkOffering.Availability.Required) {
|
||||
boolean canOffBeRequired = (offeringToUpdate.getGuestType() == GuestType.Isolated && _networkMgr.areServicesSupportedByNetworkOffering(offeringToUpdate.getId(), Service.SourceNat));
|
||||
if (!canOffBeRequired) {
|
||||
throw new InvalidParameterValueException("Availability can be " + NetworkOffering.Availability.Required + " only for networkOfferings of type " + GuestType.Isolated + " and with " + Service.SourceNat.getName() + " enabled");
|
||||
throw new InvalidParameterValueException("Availability can be " + NetworkOffering.Availability.Required + " only for networkOfferings of type " + GuestType.Isolated + " and with "
|
||||
+ Service.SourceNat.getName() + " enabled");
|
||||
}
|
||||
|
||||
//only one network offering in the system can be Required
|
||||
// only one network offering in the system can be Required
|
||||
List<NetworkOfferingVO> offerings = _networkOfferingDao.listByAvailability(Availability.Required, false);
|
||||
if (!offerings.isEmpty() && offerings.get(0).getId() != offeringToUpdate.getId()) {
|
||||
throw new InvalidParameterValueException("System already has network offering id=" + offerings.get(0).getId() + " with availability " + Availability.Required);
|
||||
|
||||
@ -28,7 +28,10 @@ import com.cloud.utils.db.GenericDao;
|
||||
public interface ResourceLimitDao extends GenericDao<ResourceLimitVO, Long> {
|
||||
|
||||
List<ResourceLimitVO> listByOwner(Long ownerId, ResourceOwnerType ownerType);
|
||||
|
||||
boolean update(Long id, Long max);
|
||||
|
||||
ResourceCount.ResourceType getLimitType(String type);
|
||||
|
||||
ResourceLimitVO findByOwnerIdAndType(long ownerId, ResourceOwnerType ownerType, ResourceCount.ResourceType type);
|
||||
}
|
||||
|
||||
@ -32,11 +32,11 @@ import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
||||
@Local(value={ResourceLimitDao.class})
|
||||
@Local(value = { ResourceLimitDao.class })
|
||||
public class ResourceLimitDaoImpl extends GenericDaoBase<ResourceLimitVO, Long> implements ResourceLimitDao {
|
||||
private SearchBuilder<ResourceLimitVO> IdTypeSearch;
|
||||
|
||||
public ResourceLimitDaoImpl () {
|
||||
public ResourceLimitDaoImpl() {
|
||||
IdTypeSearch = createSearchBuilder();
|
||||
IdTypeSearch.and("type", IdTypeSearch.entity().getType(), SearchCriteria.Op.EQ);
|
||||
IdTypeSearch.and("domainId", IdTypeSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
|
||||
@ -59,7 +59,6 @@ public class ResourceLimitDaoImpl extends GenericDaoBase<ResourceLimitVO, Long>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean update(Long id, Long max) {
|
||||
ResourceLimitVO limit = findById(id);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||
*
|
||||
*
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
@ -198,12 +198,12 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
public ExternalLoadBalancerDeviceVO addExternalLoadBalancer(long physicalNetworkId, String url, String username, String password, String deviceName, ServerResource resource) {
|
||||
|
||||
String guid;
|
||||
PhysicalNetworkVO pNetwork=null;
|
||||
PhysicalNetworkVO pNetwork = null;
|
||||
NetworkDevice ntwkDevice = NetworkDevice.getNetworkDevice(deviceName);
|
||||
Transaction txn = null;
|
||||
long zoneId;
|
||||
|
||||
if ((ntwkDevice == null) || (url == null) || (username == null) || (resource == null) || (password == null) ) {
|
||||
if ((ntwkDevice == null) || (url == null) || (username == null) || (resource == null) || (password == null)) {
|
||||
throw new InvalidParameterValueException("Atleast one of the required parameters (url, username, password," +
|
||||
" server resource, zone id/physical network id) is not specified or a valid parameter.");
|
||||
}
|
||||
@ -215,12 +215,12 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
zoneId = pNetwork.getDataCenterId();
|
||||
|
||||
PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(pNetwork.getId(), ntwkDevice.getNetworkServiceProvder());
|
||||
if (ntwkSvcProvider == null ) {
|
||||
if (ntwkSvcProvider == null) {
|
||||
throw new CloudRuntimeException("Network Service Provider: " + ntwkDevice.getNetworkServiceProvder() +
|
||||
" is not enabled in the physical network: " + physicalNetworkId + "to add this device" );
|
||||
" is not enabled in the physical network: " + physicalNetworkId + "to add this device");
|
||||
} else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
|
||||
throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() +
|
||||
" is in shutdown state in the physical network: " + physicalNetworkId + "to add this device" );
|
||||
" is in shutdown state in the physical network: " + physicalNetworkId + "to add this device");
|
||||
}
|
||||
|
||||
URI uri;
|
||||
@ -258,7 +258,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
|
||||
boolean dedicatedUse = (configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED) != null) ? Boolean.parseBoolean(configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED)) : false;
|
||||
boolean inline = (configParams.get(ApiConstants.INLINE) != null) ? Boolean.parseBoolean(configParams.get(ApiConstants.INLINE)) : false;
|
||||
long capacity = NumbersUtil.parseLong((String)configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_CAPACITY), 0);
|
||||
long capacity = NumbersUtil.parseLong((String) configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_CAPACITY), 0);
|
||||
|
||||
ExternalLoadBalancerDeviceVO lbDeviceVO = new ExternalLoadBalancerDeviceVO(host.getId(), pNetwork.getId(), ntwkSvcProvider.getProviderName(),
|
||||
deviceName, capacity, dedicatedUse, inline);
|
||||
@ -314,7 +314,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
public List<Host> listExternalLoadBalancers(long physicalNetworkId, String deviceName) {
|
||||
List<Host> lbHosts = new ArrayList<Host>();
|
||||
NetworkDevice lbNetworkDevice = NetworkDevice.getNetworkDevice(deviceName);
|
||||
PhysicalNetworkVO pNetwork=null;
|
||||
PhysicalNetworkVO pNetwork = null;
|
||||
|
||||
pNetwork = _physicalNetworkDao.findById(physicalNetworkId);
|
||||
|
||||
@ -324,7 +324,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
|
||||
PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(pNetwork.getId(),
|
||||
lbNetworkDevice.getNetworkServiceProvder());
|
||||
//if provider not configured in to physical network, then there can be no instances
|
||||
// if provider not configured in to physical network, then there can be no instances
|
||||
if (ntwkSvcProvider == null) {
|
||||
return null;
|
||||
}
|
||||
@ -359,7 +359,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
if (lbDeviceForNetwork != null) {
|
||||
long lbDeviceId = lbDeviceForNetwork.getExternalLBDeviceId();
|
||||
ExternalLoadBalancerDeviceVO lbDeviceVo = _externalLoadBalancerDeviceDao.findById(lbDeviceId);
|
||||
assert(lbDeviceVo != null);
|
||||
assert (lbDeviceVo != null);
|
||||
return lbDeviceVo;
|
||||
}
|
||||
return null;
|
||||
@ -385,7 +385,8 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
try {
|
||||
if (deviceMapLock.lock(120)) {
|
||||
try {
|
||||
boolean dedicatedLB = offering.getDedicatedLB(); // does network offering supports a dedicated load balancer?
|
||||
boolean dedicatedLB = offering.getDedicatedLB(); // does network offering supports a dedicated
|
||||
// load balancer?
|
||||
long lbDeviceId;
|
||||
|
||||
txn.start();
|
||||
@ -398,7 +399,8 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
lbDeviceId = lbDevice.getId();
|
||||
|
||||
// persist the load balancer device id that will be used for this network. Once a network
|
||||
// is implemented on a LB device then later on all rules will be programmed on to same device
|
||||
// is implemented on a LB device then later on all rules will be programmed on to same
|
||||
// device
|
||||
NetworkExternalLoadBalancerVO networkLB = new NetworkExternalLoadBalancerVO(guestConfig.getId(), lbDeviceId);
|
||||
_networkExternalLBDao.persist(networkLB);
|
||||
|
||||
@ -415,11 +417,13 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
// if already attempted to provision load balancer then throw out of capacity exception,
|
||||
if (tryLbProvisioning) {
|
||||
retry = false;
|
||||
//TODO: throwing warning instead of error for now as its possible another provider can service this network
|
||||
// TODO: throwing warning instead of error for now as its possible another provider can
|
||||
// service this network
|
||||
s_logger.warn("There are no load balancer device with the capacity for implementing this network");
|
||||
throw exception;
|
||||
} else {
|
||||
tryLbProvisioning = true; // if possible provision a LB appliance in to the physical network
|
||||
tryLbProvisioning = true; // if possible provision a LB appliance in to the physical
|
||||
// network
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@ -433,14 +437,16 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
deviceMapLock.releaseRef();
|
||||
}
|
||||
|
||||
// there are no LB devices or there is no free capacity on the devices in the physical network so provision a new LB appliance
|
||||
// there are no LB devices or there is no free capacity on the devices in the physical network so provision
|
||||
// a new LB appliance
|
||||
if (tryLbProvisioning) {
|
||||
// check if LB appliance can be dynamically provisioned
|
||||
List<ExternalLoadBalancerDeviceVO> providerLbDevices = _externalLoadBalancerDeviceDao.listByProviderAndDeviceAllocationState(physicalNetworkId, provider, LBDeviceAllocationState.Provider);
|
||||
if ((providerLbDevices != null) && (!providerLbDevices.isEmpty())) {
|
||||
for (ExternalLoadBalancerDeviceVO lbProviderDevice : providerLbDevices) {
|
||||
if (lbProviderDevice.getState() == LBDeviceState.Enabled) {
|
||||
// acquire a private IP from the data center which will be used as management IP of provisioned LB appliance,
|
||||
// acquire a private IP from the data center which will be used as management IP of
|
||||
// provisioned LB appliance,
|
||||
DataCenterIpAddressVO dcPrivateIp = _dcDao.allocatePrivateIpAddress(guestConfig.getDataCenterId(), lbProviderDevice.getUuid());
|
||||
if (dcPrivateIp == null) {
|
||||
throw new InsufficientNetworkCapacityException("failed to acquire a priavate IP in the zone " + guestConfig.getDataCenterId() +
|
||||
@ -470,10 +476,12 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
String publicIf = createLbAnswer.getPublicInterface();
|
||||
String privateIf = createLbAnswer.getPrivateInterface();
|
||||
|
||||
//we have provisioned load balancer so add the appliance as cloudstack provisioned external load balancer
|
||||
String dedicatedLb = offering.getDedicatedLB()?"true":"false";
|
||||
// we have provisioned load balancer so add the appliance as cloudstack provisioned external
|
||||
// load balancer
|
||||
String dedicatedLb = offering.getDedicatedLB() ? "true" : "false";
|
||||
|
||||
//acquire a public IP to associate with lb appliance (used as subnet IP to make the appliance part of private network)
|
||||
// acquire a public IP to associate with lb appliance (used as subnet IP to make the
|
||||
// appliance part of private network)
|
||||
PublicIp publicIp = _networkMgr.assignPublicIpAddress(guestConfig.getDataCenterId(), null, _accountMgr.getSystemAccount(), VlanType.VirtualNetwork, null, null, false);
|
||||
String publicIPNetmask = publicIp.getVlanNetmask();
|
||||
String publicIPgateway = publicIp.getVlanGateway();
|
||||
@ -481,7 +489,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
String publicIP = publicIp.getAddress().toString();
|
||||
|
||||
String url = "https://" + lbIP + "?publicinterface=" + publicIf + "&privateinterface=" + privateIf + "&lbdevicededicated=" + dedicatedLb +
|
||||
"&cloudmanaged=true" + "&publicip=" + publicIP + "&publicipnetmask=" + publicIPNetmask + "&publicipvlan="+ publicIPVlanTag + "&publicipgateway=" + publicIPgateway;
|
||||
"&cloudmanaged=true" + "&publicip=" + publicIP + "&publicipnetmask=" + publicIPNetmask + "&publicipvlan=" + publicIPVlanTag + "&publicipgateway=" + publicIPgateway;
|
||||
ExternalLoadBalancerDeviceVO lbAppliance = null;
|
||||
try {
|
||||
lbAppliance = addExternalLoadBalancer(physicalNetworkId, url, username, password, createLbAnswer.getDeviceName(), createLbAnswer.getServerResource());
|
||||
@ -490,7 +498,8 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
}
|
||||
|
||||
if (lbAppliance != null) {
|
||||
// mark the load balancer as cloudstack managed and set parent host id on which lb appliance is provisioned
|
||||
// mark the load balancer as cloudstack managed and set parent host id on which lb
|
||||
// appliance is provisioned
|
||||
ExternalLoadBalancerDeviceVO managedLb = _externalLoadBalancerDeviceDao.findById(lbAppliance.getId());
|
||||
managedLb.setIsManagedDevice(true);
|
||||
managedLb.setParentHostId(lbProviderDevice.getHostId());
|
||||
@ -504,7 +513,8 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
if (answer == null || !answer.getResult()) {
|
||||
s_logger.warn("Failed to destroy load balancer appliance created");
|
||||
} else {
|
||||
// release the public & private IP back to dc pool, as the load balancer appliance is now destroyed
|
||||
// release the public & private IP back to dc pool, as the load balancer
|
||||
// appliance is now destroyed
|
||||
_dcDao.releasePrivateIpAddress(lbIP, guestConfig.getDataCenterId(), null);
|
||||
_networkMgr.releasePublicIpAddress(publicIp.getId(), _accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount());
|
||||
}
|
||||
@ -524,9 +534,9 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
@Override
|
||||
public ExternalLoadBalancerDeviceVO findSuitableLoadBalancerForNetwork(Network network, boolean dedicatedLb) throws InsufficientCapacityException {
|
||||
long physicalNetworkId = network.getPhysicalNetworkId();
|
||||
List<ExternalLoadBalancerDeviceVO> lbDevices =null;
|
||||
List<ExternalLoadBalancerDeviceVO> lbDevices = null;
|
||||
String provider = _ntwkSrvcProviderDao.getProviderForServiceInNetwork(network.getId(), Service.Lb);
|
||||
assert(provider != null);
|
||||
assert (provider != null);
|
||||
|
||||
if (dedicatedLb) {
|
||||
lbDevices = _externalLoadBalancerDeviceDao.listByProviderAndDeviceAllocationState(physicalNetworkId, provider, LBDeviceAllocationState.Free);
|
||||
@ -548,7 +558,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
long maxFreeCapacity = 0;
|
||||
|
||||
// loop through the LB device in the physical network and pick the one with maximum free capacity
|
||||
for (ExternalLoadBalancerDeviceVO lbdevice: lbDevices) {
|
||||
for (ExternalLoadBalancerDeviceVO lbdevice : lbDevices) {
|
||||
|
||||
// skip if device is not enabled
|
||||
if (lbdevice.getState() != LBDeviceState.Enabled) {
|
||||
@ -557,7 +567,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
|
||||
// get the used capacity from the list of guest networks that are mapped to this load balancer
|
||||
List<NetworkExternalLoadBalancerVO> mappedNetworks = _networkExternalLBDao.listByLoadBalancerDeviceId(lbdevice.getId());
|
||||
long usedCapacity = ((mappedNetworks == null) || (mappedNetworks.isEmpty()))? 0 : mappedNetworks.size();
|
||||
long usedCapacity = ((mappedNetworks == null) || (mappedNetworks.isEmpty())) ? 0 : mappedNetworks.size();
|
||||
|
||||
// get the configured capacity for this device
|
||||
long fullCapacity = lbdevice.getCapacity();
|
||||
@ -583,7 +593,8 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
}
|
||||
}
|
||||
|
||||
// if we are here then there are no existing LB devices in shared use or the devices in shared use has no free capacity left
|
||||
// if we are here then there are no existing LB devices in shared use or the devices in shared use has no
|
||||
// free capacity left
|
||||
// so allocate a new load balancer configured for shared use from the pool of free LB devices
|
||||
lbDevices = _externalLoadBalancerDeviceDao.listByProviderAndDeviceAllocationState(physicalNetworkId, provider, LBDeviceAllocationState.Free);
|
||||
if (lbDevices != null && !lbDevices.isEmpty()) {
|
||||
@ -619,12 +630,13 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
boolean lbCloudManaged = lbDevice.getIsManagedDevice();
|
||||
|
||||
if (!lbInUse && !lbCloudManaged) {
|
||||
// this is the last network mapped to the load balancer device so set device allocation state to be free
|
||||
// this is the last network mapped to the load balancer device so set device allocation state to be
|
||||
// free
|
||||
lbDevice.setAllocationState(LBDeviceAllocationState.Free);
|
||||
_externalLoadBalancerDeviceDao.update(lbDevice.getId(), lbDevice);
|
||||
}
|
||||
|
||||
//commit the changes before sending agent command to destroy cloudstack managed LB
|
||||
// commit the changes before sending agent command to destroy cloudstack managed LB
|
||||
txn.commit();
|
||||
|
||||
if (!lbInUse && lbCloudManaged) {
|
||||
@ -669,7 +681,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
} catch (Exception exception) {
|
||||
txn.rollback();
|
||||
s_logger.error("Failed to release load balancer device for the network" + guestConfig.getId() + " due to " + exception.getMessage());
|
||||
}finally {
|
||||
} finally {
|
||||
deviceMapLock.releaseRef();
|
||||
}
|
||||
|
||||
@ -683,7 +695,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
String fwProvider = _ntwkSrvcProviderDao.getProviderForServiceInNetwork(network.getId(), Service.Firewall);
|
||||
|
||||
if (fwProvider.equalsIgnoreCase("VirtualRouter")) {
|
||||
//FIXME: use network service provider container framework support to implement on virtual router
|
||||
// FIXME: use network service provider container framework support to implement on virtual router
|
||||
} else {
|
||||
NetworkExternalFirewallVO fwDeviceForNetwork = _networkExternalFirewallDao.findByNetworkId(network.getId());
|
||||
assert (fwDeviceForNetwork != null) : "Why firewall provider is not ready for the network to apply static nat rules?";
|
||||
@ -822,7 +834,8 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
mapping = new InlineLoadBalancerNicMapVO(rule.getId(), srcIp, loadBalancingIpNic.getId());
|
||||
_inlineLoadBalancerNicMapDao.persist(mapping);
|
||||
|
||||
// On the firewall provider for the network, create a static NAT rule between the source IP address and the load balancing IP address
|
||||
// On the firewall provider for the network, create a static NAT rule between the source IP
|
||||
// address and the load balancing IP address
|
||||
applyStaticNatRuleForInlineLBRule(zone, network, firewallProviderHost, revoked, srcIp, loadBalancingIpNic.getIp4Address());
|
||||
} else {
|
||||
loadBalancingIpNic = _nicDao.findById(mapping.getNicId());
|
||||
@ -832,7 +845,8 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
// Find the NIC that the mapping refers to
|
||||
loadBalancingIpNic = _nicDao.findById(mapping.getNicId());
|
||||
|
||||
// On the firewall provider for the network, delete the static NAT rule between the source IP address and the load balancing IP address
|
||||
// On the firewall provider for the network, delete the static NAT rule between the source IP
|
||||
// address and the load balancing IP address
|
||||
applyStaticNatRuleForInlineLBRule(zone, network, firewallProviderHost, revoked, srcIp, loadBalancingIpNic.getIp4Address());
|
||||
|
||||
// Delete the mapping between the source IP address and the load balancing IP address
|
||||
@ -970,7 +984,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
_externalNetworkStatsInterval = NumbersUtil.parseInt(_configDao.getValue(Config.ExternalNetworkStatsInterval.key()), 300);
|
||||
if (_externalNetworkStatsInterval > 0){
|
||||
if (_externalNetworkStatsInterval > 0) {
|
||||
_executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("ExternalNetworkMonitor"));
|
||||
}
|
||||
|
||||
@ -981,7 +995,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
if (_externalNetworkStatsInterval > 0){
|
||||
if (_externalNetworkStatsInterval > 0) {
|
||||
_executor.scheduleAtFixedRate(new ExternalLoadBalancerDeviceNetworkUsageTask(), _externalNetworkStatsInterval, _externalNetworkStatsInterval, TimeUnit.SECONDS);
|
||||
}
|
||||
return true;
|
||||
@ -1030,8 +1044,8 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
for (DomainRouterVO domainRouter : domainRoutersInZone) {
|
||||
long accountId = domainRouter.getAccountId();
|
||||
|
||||
if(accountsProcessed.contains(new Long(accountId))){
|
||||
if(s_logger.isTraceEnabled()){
|
||||
if (accountsProcessed.contains(new Long(accountId))) {
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("Networks for Account " + accountId + " are already processed for external network usage, so skipping usage check.");
|
||||
}
|
||||
continue;
|
||||
@ -1060,7 +1074,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
HostVO externalLoadBalancer = _hostDao.findById(lbDeviceVO.getHostId());
|
||||
if (externalLoadBalancer != null) {
|
||||
Long lbDeviceId = new Long(externalLoadBalancer.getId());
|
||||
if(!lbDeviceUsageAnswerMap.containsKey(lbDeviceId)){
|
||||
if (!lbDeviceUsageAnswerMap.containsKey(lbDeviceId)) {
|
||||
ExternalNetworkResourceUsageCommand cmd = new ExternalNetworkResourceUsageCommand();
|
||||
lbAnswer = (ExternalNetworkResourceUsageAnswer) _agentMgr.easySend(externalLoadBalancer.getId(), cmd);
|
||||
if (lbAnswer == null || !lbAnswer.getResult()) {
|
||||
@ -1070,9 +1084,9 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
continue;
|
||||
}
|
||||
lbDeviceUsageAnswerMap.put(lbDeviceId, lbAnswer);
|
||||
}else{
|
||||
if(s_logger.isTraceEnabled()){
|
||||
s_logger.trace("Reusing usage Answer for device id "+ lbDeviceId + "for Network " + network.getId());
|
||||
} else {
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("Reusing usage Answer for device id " + lbDeviceId + "for Network " + network.getId());
|
||||
}
|
||||
lbAnswer = lbDeviceUsageAnswerMap.get(lbDeviceId);
|
||||
}
|
||||
@ -1118,7 +1132,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
return _userStatsDao.update(userStats.getId(), userStats);
|
||||
}
|
||||
|
||||
//Creates a new stats entry for the specified parameters, if one doesn't already exist.
|
||||
// Creates a new stats entry for the specified parameters, if one doesn't already exist.
|
||||
private boolean createStatsEntry(long accountId, long zoneId, long networkId, String publicIp, long hostId) {
|
||||
HostVO host = _hostDao.findById(hostId);
|
||||
UserStatisticsVO userStats = _userStatsDao.findBy(accountId, zoneId, networkId, publicIp, hostId, host.getType().toString());
|
||||
@ -1212,7 +1226,8 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
|
||||
/*
|
||||
* Creates/updates all necessary stats entries for an account and zone.
|
||||
* Stats entries are created for source NAT IP addresses, static NAT rules, port forwarding rules, and load balancing rules
|
||||
* Stats entries are created for source NAT IP addresses, static NAT rules, port forwarding rules, and load
|
||||
* balancing rules
|
||||
*/
|
||||
private boolean manageStatsEntries(boolean create, long accountId, long zoneId, Network network,
|
||||
HostVO externalLoadBalancer, ExternalNetworkResourceUsageAnswer lbAnswer) {
|
||||
@ -1390,4 +1405,5 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
||||
}
|
||||
return new DeleteHostAnswer(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -35,7 +35,6 @@ import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.Network.Capability;
|
||||
@ -73,11 +72,14 @@ public interface NetworkManager extends NetworkService {
|
||||
* @param owner
|
||||
* @param type
|
||||
* @param networkId
|
||||
* @param requestedIp TODO
|
||||
* @param allocatedBy TODO
|
||||
* @param requestedIp
|
||||
* TODO
|
||||
* @param allocatedBy
|
||||
* TODO
|
||||
* @return
|
||||
* @throws InsufficientAddressCapacityException
|
||||
*/
|
||||
|
||||
PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, boolean isElastic) throws InsufficientAddressCapacityException;
|
||||
|
||||
/**
|
||||
@ -169,7 +171,8 @@ public interface NetworkManager extends NetworkService {
|
||||
|
||||
/**
|
||||
* @throws InsufficientCapacityException
|
||||
* Associates an ip address list to an account. The list of ip addresses are all addresses associated with the
|
||||
* Associates an ip address list to an account. The list of ip addresses are all addresses associated
|
||||
* with the
|
||||
* given vlan id.
|
||||
* @param userId
|
||||
* @param accountId
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -56,4 +56,5 @@ public interface FirewallRulesDao extends GenericDao<FirewallRuleVO, Long> {
|
||||
List<FirewallRuleVO> listByIpAndNotRevoked(long ipAddressId);
|
||||
|
||||
long countRulesByIpId(long sourceIpId);
|
||||
|
||||
}
|
||||
|
||||
@ -39,7 +39,8 @@ import com.cloud.utils.db.SearchCriteria.Func;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@Local(value=FirewallRulesDao.class) @DB(txn=false)
|
||||
@Local(value = FirewallRulesDao.class)
|
||||
@DB(txn = false)
|
||||
public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> implements FirewallRulesDao {
|
||||
|
||||
protected final SearchBuilder<FirewallRuleVO> AllFieldsSearch;
|
||||
@ -196,7 +197,8 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@Override
|
||||
@DB
|
||||
public FirewallRuleVO persist(FirewallRuleVO firewallRule) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
@ -208,7 +210,6 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
|
||||
return dbfirewallRule;
|
||||
}
|
||||
|
||||
|
||||
public void saveSourceCidrs(FirewallRuleVO firewallRule, List<String> cidrList) {
|
||||
if (cidrList == null) {
|
||||
return;
|
||||
@ -216,7 +217,6 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
|
||||
_firewallRulesCidrsDao.persist(firewallRule.getId(), cidrList);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<FirewallRuleVO> listByIpPurposeAndProtocolAndNotRevoked(long ipAddressId, Integer startPort, Integer endPort, String protocol, FirewallRule.Purpose purpose) {
|
||||
SearchCriteria<FirewallRuleVO> sc = NotRevokedSearch.create();
|
||||
@ -270,4 +270,5 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
|
||||
sc.setParameters("ipAddressId", sourceIpId);
|
||||
return customSearch(sc, null).get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -25,9 +25,15 @@ import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface LoadBalancerDao extends GenericDao<LoadBalancerVO, Long> {
|
||||
List<Long> listInstancesByLoadBalancer(long loadBalancerId);
|
||||
|
||||
List<LoadBalancerVO> listByIpAddress(long ipAddressId);
|
||||
|
||||
LoadBalancerVO findByIpAddressAndPublicPort(long ipAddressId, String publicPort);
|
||||
|
||||
LoadBalancerVO findByAccountAndName(Long accountId, String name);
|
||||
|
||||
List<LoadBalancerVO> listByNetworkId(long networkId);
|
||||
|
||||
List<LoadBalancerVO> listInTransitionStateByNetworkId(long networkId);
|
||||
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@Local(value={LoadBalancerDao.class})
|
||||
@Local(value = { LoadBalancerDao.class })
|
||||
public class LoadBalancerDaoImpl extends GenericDaoBase<LoadBalancerVO, Long> implements LoadBalancerDao {
|
||||
private static final Logger s_logger = Logger.getLogger(LoadBalancerDaoImpl.class);
|
||||
private static final String LIST_INSTANCES_BY_LOAD_BALANCER = "SELECT vm.id " +
|
||||
@ -134,4 +134,5 @@ public class LoadBalancerDaoImpl extends GenericDaoBase<LoadBalancerVO, Long> im
|
||||
sc.setParameters("state", State.Add.toString(), State.Revoke.toString());
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -91,4 +91,5 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> {
|
||||
boolean update(Long networkId, NetworkVO network, Map<String, String> serviceProviderMap);
|
||||
|
||||
List<NetworkVO> listByZoneAndTrafficType(long zoneId, TrafficType trafficType);
|
||||
|
||||
}
|
||||
|
||||
@ -49,7 +49,8 @@ import com.cloud.utils.db.SequenceFetcher;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
||||
@Local(value=NetworkDao.class) @DB(txn=false)
|
||||
@Local(value = NetworkDao.class)
|
||||
@DB(txn = false)
|
||||
public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements NetworkDao {
|
||||
final SearchBuilder<NetworkVO> AllFieldsSearch;
|
||||
final SearchBuilder<NetworkVO> AccountSearch;
|
||||
@ -109,7 +110,6 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
|
||||
AccountNetworkSearch.join("networkSearch", mapJoin, AccountNetworkSearch.entity().getId(), mapJoin.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
|
||||
AccountNetworkSearch.done();
|
||||
|
||||
|
||||
ZoneBroadcastUriSearch = createSearchBuilder();
|
||||
ZoneBroadcastUriSearch.and("dataCenterId", ZoneBroadcastUriSearch.entity().getDataCenterId(), Op.EQ);
|
||||
ZoneBroadcastUriSearch.and("broadcastUri", ZoneBroadcastUriSearch.entity().getBroadcastUri(), Op.EQ);
|
||||
@ -128,7 +128,6 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
|
||||
CountByOfferingId.and("removed", CountByOfferingId.entity().getRemoved(), Op.NULL);
|
||||
CountByOfferingId.done();
|
||||
|
||||
|
||||
PhysicalNetworkSearch = createSearchBuilder();
|
||||
PhysicalNetworkSearch.and("physicalNetworkId", PhysicalNetworkSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
PhysicalNetworkSearch.done();
|
||||
@ -184,27 +183,28 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@Override
|
||||
@DB
|
||||
public NetworkVO persist(NetworkVO network, boolean gc, Map<String, String> serviceProviderMap) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
//1) create network
|
||||
// 1) create network
|
||||
NetworkVO newNetwork = super.persist(network);
|
||||
//2) add account to the network
|
||||
// 2) add account to the network
|
||||
addAccountToNetwork(network.getId(), network.getAccountId(), true);
|
||||
//3) add network to gc monitor table
|
||||
// 3) add network to gc monitor table
|
||||
NetworkOpVO op = new NetworkOpVO(network.getId(), gc);
|
||||
_opDao.persist(op);
|
||||
//4) add services/providers for the network
|
||||
// 4) add services/providers for the network
|
||||
persistNetworkServiceProviders(newNetwork.getId(), serviceProviderMap);
|
||||
|
||||
txn.commit();
|
||||
return newNetwork;
|
||||
}
|
||||
|
||||
|
||||
@Override @DB
|
||||
@Override
|
||||
@DB
|
||||
public boolean update(Long networkId, NetworkVO network, Map<String, String> serviceProviderMap) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
@ -255,7 +255,7 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
|
||||
SequenceFetcher fetch = SequenceFetcher.getInstance();
|
||||
|
||||
long seq = fetch.getNextSequence(Long.class, _tgMacAddress, networkConfigId);
|
||||
seq = seq | _prefix << 40| ((_rand.nextInt(Short.MAX_VALUE) << 16) & 0x00000000ffff0000l);
|
||||
seq = seq | _prefix << 40 | ((_rand.nextInt(Short.MAX_VALUE) << 16) & 0x00000000ffff0000l);
|
||||
return NetUtils.long2Mac(seq);
|
||||
}
|
||||
|
||||
@ -352,7 +352,7 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NetworkVO> listByPhysicalNetworkTrafficType(long physicalNetworkId, TrafficType trafficType){
|
||||
public List<NetworkVO> listByPhysicalNetworkTrafficType(long physicalNetworkId, TrafficType trafficType) {
|
||||
SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("trafficType", trafficType);
|
||||
sc.setParameters("physicalNetworkId", physicalNetworkId);
|
||||
@ -395,4 +395,5 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
|
||||
|
||||
return listBy(sc, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||
*
|
||||
*
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
@ -79,28 +79,37 @@ import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
|
||||
|
||||
@Local(value=NetworkElement.class)
|
||||
@Local(value = NetworkElement.class)
|
||||
public class CloudZonesNetworkElement extends AdapterBase implements NetworkElement, UserDataServiceProvider {
|
||||
private static final Logger s_logger = Logger.getLogger(CloudZonesNetworkElement.class);
|
||||
|
||||
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
|
||||
|
||||
@Inject NetworkDao _networkConfigDao;
|
||||
@Inject NetworkManager _networkMgr;
|
||||
@Inject VirtualNetworkApplianceManager _routerMgr;
|
||||
@Inject UserVmManager _userVmMgr;
|
||||
@Inject UserVmDao _userVmDao;
|
||||
@Inject DomainRouterDao _routerDao;
|
||||
@Inject ConfigurationManager _configMgr;
|
||||
@Inject DataCenterDao _dcDao;
|
||||
@Inject AgentManager _agentManager;
|
||||
@Inject ServiceOfferingDao _serviceOfferingDao;
|
||||
@Inject
|
||||
NetworkDao _networkConfigDao;
|
||||
@Inject
|
||||
NetworkManager _networkMgr;
|
||||
@Inject
|
||||
VirtualNetworkApplianceManager _routerMgr;
|
||||
@Inject
|
||||
UserVmManager _userVmMgr;
|
||||
@Inject
|
||||
UserVmDao _userVmDao;
|
||||
@Inject
|
||||
DomainRouterDao _routerDao;
|
||||
@Inject
|
||||
ConfigurationManager _configMgr;
|
||||
@Inject
|
||||
DataCenterDao _dcDao;
|
||||
@Inject
|
||||
AgentManager _agentManager;
|
||||
@Inject
|
||||
ServiceOfferingDao _serviceOfferingDao;
|
||||
|
||||
private boolean canHandle(DeployDestination dest, TrafficType trafficType) {
|
||||
DataCenterVO dc = (DataCenterVO)dest.getDataCenter();
|
||||
DataCenterVO dc = (DataCenterVO) dest.getDataCenter();
|
||||
|
||||
if (dc.getDhcpProvider().equalsIgnoreCase(Provider.ExternalDhcpServer.getName())){
|
||||
if (dc.getDhcpProvider().equalsIgnoreCase(Provider.ExternalDhcpServer.getName())) {
|
||||
_dcDao.loadDetails(dc);
|
||||
String dhcpStrategy = dc.getDetail(ZoneConfig.DhcpStrategy.key());
|
||||
if ("external".equalsIgnoreCase(dhcpStrategy)) {
|
||||
@ -112,7 +121,8 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
|
||||
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException,
|
||||
InsufficientCapacityException {
|
||||
if (!canHandle(dest, offering.getTrafficType())) {
|
||||
return false;
|
||||
}
|
||||
@ -121,7 +131,8 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
|
||||
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
|
||||
InsufficientCapacityException, ResourceUnavailableException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -132,12 +143,12 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem
|
||||
|
||||
@Override
|
||||
public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
return false; //assume that the agent will remove userdata etc
|
||||
return false; // assume that the agent will remove userdata etc
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean destroy(Network config) throws ConcurrentOperationException, ResourceUnavailableException{
|
||||
return false; //assume that the agent will remove userdata etc
|
||||
public boolean destroy(Network config) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
return false; // assume that the agent will remove userdata etc
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -158,7 +169,7 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
private VmDataCommand generateVmDataCommand( String vmPrivateIpAddress,
|
||||
private VmDataCommand generateVmDataCommand(String vmPrivateIpAddress,
|
||||
String userData, String serviceOffering, String zoneName, String guestIpAddress, String vmName, String vmInstanceName, long vmId, String publicKey) {
|
||||
VmDataCommand cmd = new VmDataCommand(vmPrivateIpAddress, vmName);
|
||||
|
||||
@ -202,9 +213,9 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>)vm;
|
||||
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>) vm;
|
||||
_userVmDao.loadDetails((UserVmVO) uservm.getVirtualMachine());
|
||||
String password = (String)uservm.getParameter(VirtualMachineProfile.Param.VmPassword);
|
||||
String password = (String) uservm.getParameter(VirtualMachineProfile.Param.VmPassword);
|
||||
String userData = uservm.getVirtualMachine().getUserData();
|
||||
String sshPublicKey = uservm.getVirtualMachine().getDetail("SSH.PublicKey");
|
||||
|
||||
@ -219,7 +230,8 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem
|
||||
|
||||
cmds.addCommand(
|
||||
"vmdata",
|
||||
generateVmDataCommand(nic.getIp4Address(), userData, serviceOffering, zoneName, nic.getIp4Address(), uservm.getVirtualMachine().getHostName(), uservm.getVirtualMachine().getInstanceName(), uservm.getId(), sshPublicKey));
|
||||
generateVmDataCommand(nic.getIp4Address(), userData, serviceOffering, zoneName, nic.getIp4Address(), uservm.getVirtualMachine().getHostName(), uservm.getVirtualMachine().getInstanceName(),
|
||||
uservm.getId(), sshPublicKey));
|
||||
try {
|
||||
_agentManager.send(dest.getHost().getId(), cmds);
|
||||
} catch (OperationTimedoutException e) {
|
||||
@ -247,4 +259,5 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem
|
||||
public boolean verifyServicesCombination(List<String> services) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||
*
|
||||
*
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
@ -52,10 +52,11 @@ import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
@Local(value=NetworkElement.class)
|
||||
@Local(value = NetworkElement.class)
|
||||
public class ExternalDhcpElement extends AdapterBase implements NetworkElement, DhcpServiceProvider {
|
||||
private static final Logger s_logger = Logger.getLogger(ExternalDhcpElement.class);
|
||||
@Inject ExternalDhcpManager _dhcpMgr;
|
||||
@Inject
|
||||
ExternalDhcpManager _dhcpMgr;
|
||||
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
|
||||
|
||||
private boolean canHandle(DeployDestination dest, TrafficType trafficType, GuestType networkType) {
|
||||
@ -72,7 +73,7 @@ public class ExternalDhcpElement extends AdapterBase implements NetworkElement,
|
||||
}
|
||||
|
||||
private static Map<Service, Map<Capability, String>> setCapabilities() {
|
||||
//No external dhcp support for Acton release
|
||||
// No external dhcp support for Acton release
|
||||
Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
|
||||
// capabilities.put(Service.Dhcp, null);
|
||||
return capabilities;
|
||||
@ -114,7 +115,6 @@ public class ExternalDhcpElement extends AdapterBase implements NetworkElement,
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean destroy(Network network) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
return true;
|
||||
@ -142,7 +142,7 @@ public class ExternalDhcpElement extends AdapterBase implements NetworkElement,
|
||||
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
|
||||
Host host = dest.getHost();
|
||||
if (host.getHypervisorType() == HypervisorType.BareMetal || !canHandle(dest, network.getTrafficType(), network.getGuestType())) {
|
||||
//BareMetalElement or DhcpElement handle this
|
||||
// BareMetalElement or DhcpElement handle this
|
||||
return false;
|
||||
}
|
||||
return _dhcpMgr.addVirtualMachineIntoNetwork(network, nic, vm, dest, context);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||
*
|
||||
*
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
@ -41,7 +41,6 @@ import com.cloud.api.response.F5LoadBalancerResponse;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
@ -57,15 +56,15 @@ import com.cloud.host.dao.HostDetailsDao;
|
||||
import com.cloud.network.ExternalLoadBalancerDeviceManager;
|
||||
import com.cloud.network.ExternalLoadBalancerDeviceManagerImpl;
|
||||
import com.cloud.network.ExternalLoadBalancerDeviceVO;
|
||||
import com.cloud.network.NetworkExternalLoadBalancerVO;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.ExternalLoadBalancerDeviceVO.LBDeviceState;
|
||||
import com.cloud.network.ExternalNetworkDeviceManager.NetworkDevice;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.NetworkExternalLoadBalancerVO;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.PhysicalNetworkVO;
|
||||
@ -91,22 +90,33 @@ import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
@Local(value=NetworkElement.class)
|
||||
@Local(value = NetworkElement.class)
|
||||
public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceManagerImpl implements LoadBalancingServiceProvider, IpDeployer, F5ExternalLoadBalancerElementService, ExternalLoadBalancerDeviceManager {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(F5ExternalLoadBalancerElement.class);
|
||||
|
||||
@Inject NetworkManager _networkManager;
|
||||
@Inject ConfigurationManager _configMgr;
|
||||
@Inject NetworkServiceMapDao _ntwkSrvcDao;
|
||||
@Inject DataCenterDao _dcDao;
|
||||
@Inject PhysicalNetworkDao _physicalNetworkDao;
|
||||
@Inject HostDao _hostDao;
|
||||
@Inject ExternalLoadBalancerDeviceDao _lbDeviceDao;
|
||||
@Inject NetworkExternalLoadBalancerDao _networkLBDao;
|
||||
@Inject NetworkDao _networkDao;
|
||||
@Inject HostDetailsDao _detailsDao;
|
||||
@Inject ConfigurationDao _configDao;
|
||||
@Inject
|
||||
NetworkManager _networkManager;
|
||||
@Inject
|
||||
ConfigurationManager _configMgr;
|
||||
@Inject
|
||||
NetworkServiceMapDao _ntwkSrvcDao;
|
||||
@Inject
|
||||
DataCenterDao _dcDao;
|
||||
@Inject
|
||||
PhysicalNetworkDao _physicalNetworkDao;
|
||||
@Inject
|
||||
HostDao _hostDao;
|
||||
@Inject
|
||||
ExternalLoadBalancerDeviceDao _lbDeviceDao;
|
||||
@Inject
|
||||
NetworkExternalLoadBalancerDao _networkLBDao;
|
||||
@Inject
|
||||
NetworkDao _networkDao;
|
||||
@Inject
|
||||
HostDetailsDao _detailsDao;
|
||||
@Inject
|
||||
ConfigurationDao _configDao;
|
||||
|
||||
private boolean canHandle(Network config) {
|
||||
if (config.getGuestType() != Network.GuestType.Isolated || config.getTrafficType() != TrafficType.Guest) {
|
||||
@ -114,12 +124,12 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
|
||||
return false;
|
||||
}
|
||||
|
||||
return (_networkManager.isProviderForNetwork(getProvider(), config.getId()) &&
|
||||
_ntwkSrvcDao.canProviderSupportServiceInNetwork(config.getId(), Service.Lb, Network.Provider.F5BigIp));
|
||||
return (_networkManager.isProviderForNetwork(getProvider(), config.getId()) && _ntwkSrvcDao.canProviderSupportServiceInNetwork(config.getId(), Service.Lb, Network.Provider.F5BigIp));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean implement(Network guestConfig, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, InsufficientNetworkCapacityException {
|
||||
public boolean implement(Network guestConfig, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException,
|
||||
InsufficientNetworkCapacityException {
|
||||
|
||||
if (!canHandle(guestConfig)) {
|
||||
return false;
|
||||
@ -128,13 +138,15 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
|
||||
try {
|
||||
return manageGuestNetworkWithExternalLoadBalancer(true, guestConfig);
|
||||
} catch (InsufficientCapacityException capacityException) {
|
||||
// TODO: handle out of capacity exception in graceful manner when multiple providers are avaialble for the network
|
||||
// TODO: handle out of capacity exception in graceful manner when multiple providers are avaialble for the
|
||||
// network
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException {
|
||||
public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
|
||||
InsufficientNetworkCapacityException, ResourceUnavailableException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -199,18 +211,18 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
|
||||
lbCapabilities.put(Capability.LoadBalancingSupportedIps, "additional");
|
||||
|
||||
LbStickinessMethod method;
|
||||
List <LbStickinessMethod> methodList = new ArrayList<LbStickinessMethod>();
|
||||
method = new LbStickinessMethod(StickinessMethodType.LBCookieBased,"This is cookie based sticky method, can be used only for http");
|
||||
List<LbStickinessMethod> methodList = new ArrayList<LbStickinessMethod>();
|
||||
method = new LbStickinessMethod(StickinessMethodType.LBCookieBased, "This is cookie based sticky method, can be used only for http");
|
||||
methodList.add(method);
|
||||
method.addParam("holdtime", false, "time period for which persistence is in effect.",false);
|
||||
method.addParam("holdtime", false, "time period for which persistence is in effect.", false);
|
||||
|
||||
method = new LbStickinessMethod(StickinessMethodType.SourceBased,"This is source based sticky method, can be used for any type of protocol.");
|
||||
method = new LbStickinessMethod(StickinessMethodType.SourceBased, "This is source based sticky method, can be used for any type of protocol.");
|
||||
methodList.add(method);
|
||||
method.addParam("holdtime", false, "time period for which persistence is in effect.",false);
|
||||
method.addParam("holdtime", false, "time period for which persistence is in effect.", false);
|
||||
|
||||
Gson gson = new Gson();
|
||||
String stickyMethodList = gson.toJson(methodList);
|
||||
lbCapabilities.put(Capability.SupportedStickinessMethods,stickyMethodList);
|
||||
lbCapabilities.put(Capability.SupportedStickinessMethods, stickyMethodList);
|
||||
|
||||
capabilities.put(Service.Lb, lbCapabilities);
|
||||
|
||||
@ -258,8 +270,8 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
|
||||
@Deprecated
|
||||
public Host addExternalLoadBalancer(AddExternalLoadBalancerCmd cmd) {
|
||||
Long zoneId = cmd.getZoneId();
|
||||
DataCenterVO zone =null;
|
||||
PhysicalNetworkVO pNetwork=null;
|
||||
DataCenterVO zone = null;
|
||||
PhysicalNetworkVO pNetwork = null;
|
||||
ExternalLoadBalancerDeviceVO lbDeviceVO = null;
|
||||
HostVO lbHost = null;
|
||||
|
||||
@ -295,8 +307,8 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
|
||||
@Deprecated
|
||||
public List<Host> listExternalLoadBalancers(ListExternalLoadBalancersCmd cmd) {
|
||||
Long zoneId = cmd.getZoneId();
|
||||
DataCenterVO zone =null;
|
||||
PhysicalNetworkVO pNetwork=null;
|
||||
DataCenterVO zone = null;
|
||||
PhysicalNetworkVO pNetwork = null;
|
||||
|
||||
if (zoneId != null) {
|
||||
zone = _dcDao.findById(zoneId);
|
||||
@ -378,7 +390,7 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
|
||||
Long physcialNetworkId = cmd.getPhysicalNetworkId();
|
||||
Long lbDeviceId = cmd.getLoadBalancerDeviceId();
|
||||
PhysicalNetworkVO pNetwork = null;
|
||||
List<ExternalLoadBalancerDeviceVO> lbDevices = new ArrayList<ExternalLoadBalancerDeviceVO> ();
|
||||
List<ExternalLoadBalancerDeviceVO> lbDevices = new ArrayList<ExternalLoadBalancerDeviceVO>();
|
||||
|
||||
if (physcialNetworkId == null && lbDeviceId == null) {
|
||||
throw new InvalidParameterValueException("Either physical network Id or load balancer device Id must be specified");
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||
*
|
||||
*
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
@ -26,6 +26,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.commands.AddExternalFirewallCmd;
|
||||
@ -41,8 +42,8 @@ import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
@ -54,14 +55,14 @@ import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.host.dao.HostDetailsDao;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.ExternalFirewallDeviceManagerImpl;
|
||||
import com.cloud.network.ExternalFirewallDeviceVO;
|
||||
import com.cloud.network.ExternalFirewallDeviceVO.FirewallDeviceState;
|
||||
import com.cloud.network.ExternalNetworkDeviceManager.NetworkDevice;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.ExternalFirewallDeviceManagerImpl;
|
||||
import com.cloud.network.ExternalFirewallDeviceVO;
|
||||
import com.cloud.network.NetworkExternalFirewallVO;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.NetworkVO;
|
||||
@ -90,27 +91,40 @@ import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
@Local(value=NetworkElement.class)
|
||||
@Local(value = NetworkElement.class)
|
||||
public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceManagerImpl implements SourceNatServiceProvider, FirewallServiceProvider,
|
||||
PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer, JuniperSRXFirewallElementService{
|
||||
PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer, JuniperSRXFirewallElementService {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(JuniperSRXExternalFirewallElement.class);
|
||||
|
||||
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
|
||||
|
||||
@Inject NetworkManager _networkManager;
|
||||
@Inject HostDao _hostDao;
|
||||
@Inject ConfigurationManager _configMgr;
|
||||
@Inject NetworkOfferingDao _networkOfferingDao;
|
||||
@Inject NetworkDao _networksDao;
|
||||
@Inject DataCenterDao _dcDao;
|
||||
@Inject PhysicalNetworkDao _physicalNetworkDao;
|
||||
@Inject ExternalFirewallDeviceDao _fwDevicesDao;
|
||||
@Inject NetworkExternalFirewallDao _networkFirewallDao;
|
||||
@Inject NetworkDao _networkDao;
|
||||
@Inject NetworkServiceMapDao _ntwkSrvcDao;
|
||||
@Inject HostDetailsDao _hostDetailDao;
|
||||
@Inject ConfigurationDao _configDao;
|
||||
@Inject
|
||||
NetworkManager _networkManager;
|
||||
@Inject
|
||||
HostDao _hostDao;
|
||||
@Inject
|
||||
ConfigurationManager _configMgr;
|
||||
@Inject
|
||||
NetworkOfferingDao _networkOfferingDao;
|
||||
@Inject
|
||||
NetworkDao _networksDao;
|
||||
@Inject
|
||||
DataCenterDao _dcDao;
|
||||
@Inject
|
||||
PhysicalNetworkDao _physicalNetworkDao;
|
||||
@Inject
|
||||
ExternalFirewallDeviceDao _fwDevicesDao;
|
||||
@Inject
|
||||
NetworkExternalFirewallDao _networkFirewallDao;
|
||||
@Inject
|
||||
NetworkDao _networkDao;
|
||||
@Inject
|
||||
NetworkServiceMapDao _ntwkSrvcDao;
|
||||
@Inject
|
||||
HostDetailsDao _hostDetailDao;
|
||||
@Inject
|
||||
ConfigurationDao _configDao;
|
||||
|
||||
private boolean canHandle(Network network, Service service) {
|
||||
DataCenter zone = _configMgr.getZone(network.getDataCenterId());
|
||||
@ -135,10 +149,11 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, InsufficientNetworkCapacityException {
|
||||
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException,
|
||||
InsufficientNetworkCapacityException {
|
||||
DataCenter zone = _configMgr.getZone(network.getDataCenterId());
|
||||
|
||||
//don't have to implement network is Basic zone
|
||||
// don't have to implement network is Basic zone
|
||||
if (zone.getNetworkType() == NetworkType.Basic) {
|
||||
s_logger.debug("Not handling network implement in zone of type " + NetworkType.Basic);
|
||||
return false;
|
||||
@ -151,13 +166,15 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
||||
try {
|
||||
return manageGuestNetworkWithExternalFirewall(true, network);
|
||||
} catch (InsufficientCapacityException capacityException) {
|
||||
// TODO: handle out of capacity exception in more gracefule manner when multiple providers are present for the network
|
||||
// TODO: handle out of capacity exception in more gracefule manner when multiple providers are present for
|
||||
// the network
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException {
|
||||
public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
|
||||
InsufficientNetworkCapacityException, ResourceUnavailableException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -170,7 +187,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
||||
public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ResourceUnavailableException, ConcurrentOperationException {
|
||||
DataCenter zone = _configMgr.getZone(network.getDataCenterId());
|
||||
|
||||
//don't have to implement network is Basic zone
|
||||
// don't have to implement network is Basic zone
|
||||
if (zone.getNetworkType() == NetworkType.Basic) {
|
||||
s_logger.debug("Not handling network shutdown in zone of type " + NetworkType.Basic);
|
||||
return false;
|
||||
@ -221,7 +238,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] applyVpnUsers(RemoteAccessVpn vpn, List<? extends VpnUser> users) throws ResourceUnavailableException{
|
||||
public String[] applyVpnUsers(RemoteAccessVpn vpn, List<? extends VpnUser> users) throws ResourceUnavailableException {
|
||||
Network config = _networksDao.findById(vpn.getNetworkId());
|
||||
|
||||
if (!canHandle(config, Service.Vpn)) {
|
||||
@ -257,7 +274,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
||||
firewallCapabilities.put(Capability.TrafficStatistics, "per public ip");
|
||||
capabilities.put(Service.Firewall, firewallCapabilities);
|
||||
|
||||
//Disabling VPN for Juniper in Acton as it 1) Was never tested 2) probably just doesn't work
|
||||
// Disabling VPN for Juniper in Acton as it 1) Was never tested 2) probably just doesn't work
|
||||
// // Set VPN capabilities
|
||||
// Map<Capability, String> vpnCapabilities = new HashMap<Capability, String>();
|
||||
// vpnCapabilities.put(Capability.SupportedVpnTypes, "ipsec");
|
||||
@ -317,11 +334,12 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated // should use more generic addNetworkDevice command to add firewall
|
||||
@Deprecated
|
||||
// should use more generic addNetworkDevice command to add firewall
|
||||
public Host addExternalFirewall(AddExternalFirewallCmd cmd) {
|
||||
Long zoneId = cmd.getZoneId();
|
||||
DataCenterVO zone =null;
|
||||
PhysicalNetworkVO pNetwork=null;
|
||||
DataCenterVO zone = null;
|
||||
PhysicalNetworkVO pNetwork = null;
|
||||
HostVO fwHost = null;
|
||||
|
||||
zone = _dcDao.findById(zoneId);
|
||||
@ -351,12 +369,13 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated // should use more generic listNetworkDevice command
|
||||
@Deprecated
|
||||
// should use more generic listNetworkDevice command
|
||||
public List<Host> listExternalFirewalls(ListExternalFirewallsCmd cmd) {
|
||||
List<Host> firewallHosts = new ArrayList<Host>();
|
||||
Long zoneId = cmd.getZoneId();
|
||||
DataCenterVO zone =null;
|
||||
PhysicalNetworkVO pNetwork=null;
|
||||
DataCenterVO zone = null;
|
||||
PhysicalNetworkVO pNetwork = null;
|
||||
|
||||
if (zoneId != null) {
|
||||
zone = _dcDao.findById(zoneId);
|
||||
@ -439,7 +458,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
|
||||
Long physcialNetworkId = cmd.getPhysicalNetworkId();
|
||||
Long fwDeviceId = cmd.getFirewallDeviceId();
|
||||
PhysicalNetworkVO pNetwork = null;
|
||||
List<ExternalFirewallDeviceVO> fwDevices = new ArrayList<ExternalFirewallDeviceVO> ();
|
||||
List<ExternalFirewallDeviceVO> fwDevices = new ArrayList<ExternalFirewallDeviceVO>();
|
||||
|
||||
if (physcialNetworkId == null && fwDeviceId == null) {
|
||||
throw new InvalidParameterValueException("Either physical network Id or load balancer device Id must be specified");
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||
*
|
||||
*
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
@ -31,15 +31,12 @@ import javax.ejb.Local;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.AgentManager.OnError;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
|
||||
import com.cloud.agent.api.routing.NetworkElementCommand;
|
||||
import com.cloud.agent.api.routing.SetStaticNatRulesAnswer;
|
||||
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
|
||||
import com.cloud.agent.api.to.LoadBalancerTO;
|
||||
import com.cloud.agent.api.to.StaticNatRuleTO;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.commands.AddNetscalerLoadBalancerCmd;
|
||||
import com.cloud.api.commands.ConfigureNetscalerLoadBalancerCmd;
|
||||
@ -51,7 +48,6 @@ import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
@ -67,9 +63,9 @@ import com.cloud.host.dao.HostDetailsDao;
|
||||
import com.cloud.network.ExternalLoadBalancerDeviceManager;
|
||||
import com.cloud.network.ExternalLoadBalancerDeviceManagerImpl;
|
||||
import com.cloud.network.ExternalLoadBalancerDeviceVO;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.ExternalLoadBalancerDeviceVO.LBDeviceState;
|
||||
import com.cloud.network.ExternalNetworkDeviceManager.NetworkDevice;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.Provider;
|
||||
@ -90,8 +86,8 @@ import com.cloud.network.lb.LoadBalancingRule;
|
||||
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
|
||||
import com.cloud.network.resource.NetscalerResource;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.rules.LbStickinessMethod;
|
||||
import com.cloud.network.rules.FirewallRule.Purpose;
|
||||
import com.cloud.network.rules.LbStickinessMethod;
|
||||
import com.cloud.network.rules.LbStickinessMethod.StickinessMethodType;
|
||||
import com.cloud.network.rules.StaticNat;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
@ -108,24 +104,38 @@ import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
@Local(value=NetworkElement.class)
|
||||
public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl implements LoadBalancingServiceProvider, NetscalerLoadBalancerElementService, ExternalLoadBalancerDeviceManager, IpDeployer, StaticNatServiceProvider {
|
||||
@Local(value = NetworkElement.class)
|
||||
public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl implements LoadBalancingServiceProvider, NetscalerLoadBalancerElementService, ExternalLoadBalancerDeviceManager, IpDeployer,
|
||||
StaticNatServiceProvider {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(NetscalerElement.class);
|
||||
|
||||
@Inject NetworkManager _networkManager;
|
||||
@Inject ConfigurationManager _configMgr;
|
||||
@Inject NetworkServiceMapDao _ntwkSrvcDao;
|
||||
@Inject AgentManager _agentMgr;
|
||||
@Inject NetworkManager _networkMgr;
|
||||
@Inject HostDao _hostDao;
|
||||
@Inject DataCenterDao _dcDao;
|
||||
@Inject ExternalLoadBalancerDeviceDao _lbDeviceDao;
|
||||
@Inject NetworkExternalLoadBalancerDao _networkLBDao;
|
||||
@Inject PhysicalNetworkDao _physicalNetworkDao;
|
||||
@Inject NetworkDao _networkDao;
|
||||
@Inject HostDetailsDao _detailsDao;
|
||||
@Inject ConfigurationDao _configDao;
|
||||
@Inject
|
||||
NetworkManager _networkManager;
|
||||
@Inject
|
||||
ConfigurationManager _configMgr;
|
||||
@Inject
|
||||
NetworkServiceMapDao _ntwkSrvcDao;
|
||||
@Inject
|
||||
AgentManager _agentMgr;
|
||||
@Inject
|
||||
NetworkManager _networkMgr;
|
||||
@Inject
|
||||
HostDao _hostDao;
|
||||
@Inject
|
||||
DataCenterDao _dcDao;
|
||||
@Inject
|
||||
ExternalLoadBalancerDeviceDao _lbDeviceDao;
|
||||
@Inject
|
||||
NetworkExternalLoadBalancerDao _networkLBDao;
|
||||
@Inject
|
||||
PhysicalNetworkDao _physicalNetworkDao;
|
||||
@Inject
|
||||
NetworkDao _networkDao;
|
||||
@Inject
|
||||
HostDetailsDao _detailsDao;
|
||||
@Inject
|
||||
ConfigurationDao _configDao;
|
||||
|
||||
private boolean canHandle(Network config, Service service) {
|
||||
DataCenter zone = _dcDao.findById(config.getDataCenterId());
|
||||
@ -137,8 +147,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
|
||||
return false;
|
||||
}
|
||||
|
||||
return (_networkManager.isProviderForNetwork(getProvider(), config.getId()) &&
|
||||
_ntwkSrvcDao.canProviderSupportServiceInNetwork(config.getId(), service, Network.Provider.Netscaler));
|
||||
return (_networkManager.isProviderForNetwork(getProvider(), config.getId()) && _ntwkSrvcDao.canProviderSupportServiceInNetwork(config.getId(), service, Network.Provider.Netscaler));
|
||||
}
|
||||
|
||||
private boolean isBasicZoneNetwok(Network config) {
|
||||
@ -147,7 +156,8 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean implement(Network guestConfig, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, InsufficientNetworkCapacityException {
|
||||
public boolean implement(Network guestConfig, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException,
|
||||
InsufficientNetworkCapacityException {
|
||||
|
||||
if (!canHandle(guestConfig, Service.Lb)) {
|
||||
return false;
|
||||
@ -162,7 +172,8 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException {
|
||||
public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
|
||||
InsufficientNetworkCapacityException, ResourceUnavailableException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -231,22 +242,22 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
|
||||
lbCapabilities.put(Capability.LoadBalancingSupportedIps, "additional");
|
||||
|
||||
LbStickinessMethod method;
|
||||
List <LbStickinessMethod> methodList = new ArrayList<LbStickinessMethod>();
|
||||
method = new LbStickinessMethod(StickinessMethodType.LBCookieBased,"This is cookie based sticky method, can be used only for http");
|
||||
List<LbStickinessMethod> methodList = new ArrayList<LbStickinessMethod>();
|
||||
method = new LbStickinessMethod(StickinessMethodType.LBCookieBased, "This is cookie based sticky method, can be used only for http");
|
||||
methodList.add(method);
|
||||
method.addParam("holdtime", false, "time period in minutes for which persistence is in effect.",false);
|
||||
method.addParam("holdtime", false, "time period in minutes for which persistence is in effect.", false);
|
||||
|
||||
method = new LbStickinessMethod(StickinessMethodType.AppCookieBased,"This is app session based sticky method, can be used only for http");
|
||||
method = new LbStickinessMethod(StickinessMethodType.AppCookieBased, "This is app session based sticky method, can be used only for http");
|
||||
methodList.add(method);
|
||||
method.addParam("name", true, "cookie name passed in http header by apllication to the client",false);
|
||||
method.addParam("name", true, "cookie name passed in http header by apllication to the client", false);
|
||||
|
||||
method = new LbStickinessMethod(StickinessMethodType.SourceBased,"This is source based sticky method, can be used for any type of protocol.");
|
||||
method = new LbStickinessMethod(StickinessMethodType.SourceBased, "This is source based sticky method, can be used for any type of protocol.");
|
||||
methodList.add(method);
|
||||
method.addParam("holdtime", false, "time period for which persistence is in effect.",false);
|
||||
method.addParam("holdtime", false, "time period for which persistence is in effect.", false);
|
||||
|
||||
Gson gson = new Gson();
|
||||
String stickyMethodList = gson.toJson(methodList);
|
||||
lbCapabilities.put(Capability.SupportedStickinessMethods,stickyMethodList);
|
||||
lbCapabilities.put(Capability.SupportedStickinessMethods, stickyMethodList);
|
||||
|
||||
lbCapabilities.put(Capability.ElasticLb, "true");
|
||||
|
||||
@ -256,8 +267,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
|
||||
staticNatCapabilities.put(Capability.ElasticIp, "true");
|
||||
capabilities.put(Service.StaticNat, staticNatCapabilities);
|
||||
|
||||
|
||||
//TODO - Murali, please put correct capabilities here
|
||||
// TODO - Murali, please put correct capabilities here
|
||||
Map<Capability, String> firewallCapabilities = new HashMap<Capability, String>();
|
||||
firewallCapabilities.put(Capability.TrafficStatistics, "per public ip");
|
||||
firewallCapabilities.put(Capability.SupportedProtocols, "tcp,udp,icmp");
|
||||
@ -349,7 +359,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
|
||||
throw new CloudRuntimeException("There are more number of networks already using this netscaler device than configured capacity");
|
||||
}
|
||||
|
||||
if (dedicatedUse !=null && dedicatedUse == true) {
|
||||
if (dedicatedUse != null && dedicatedUse == true) {
|
||||
throw new CloudRuntimeException("There are networks already using this netscaler device to make device dedicated");
|
||||
}
|
||||
|
||||
@ -370,7 +380,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
|
||||
// FIXME how to interpret configured capacity of the SDX device
|
||||
}
|
||||
|
||||
if(dedicatedUse != null) {
|
||||
if (dedicatedUse != null) {
|
||||
lbDeviceVo.setIsDedicatedDevice(dedicatedUse);
|
||||
}
|
||||
|
||||
@ -427,7 +437,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
|
||||
Long physcialNetworkId = cmd.getPhysicalNetworkId();
|
||||
Long lbDeviceId = cmd.getLoadBalancerDeviceId();
|
||||
PhysicalNetworkVO pNetwork = null;
|
||||
List<ExternalLoadBalancerDeviceVO> lbDevices = new ArrayList<ExternalLoadBalancerDeviceVO> ();
|
||||
List<ExternalLoadBalancerDeviceVO> lbDevices = new ArrayList<ExternalLoadBalancerDeviceVO>();
|
||||
|
||||
if (physcialNetworkId == null && lbDeviceId == null) {
|
||||
throw new InvalidParameterValueException("Either physical network Id or load balancer device Id must be specified");
|
||||
@ -489,7 +499,8 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
|
||||
public boolean isReady(PhysicalNetworkServiceProvider provider) {
|
||||
List<ExternalLoadBalancerDeviceVO> lbDevices = _lbDeviceDao.listByPhysicalNetworkAndProvider(provider.getPhysicalNetworkId(), Provider.Netscaler.getName());
|
||||
|
||||
// true if at-least one Netscaler device is added in to physical network and is in configured (in enabled state) state
|
||||
// true if at-least one Netscaler device is added in to physical network and is in configured (in enabled state)
|
||||
// state
|
||||
if (lbDevices != null && !lbDevices.isEmpty()) {
|
||||
for (ExternalLoadBalancerDeviceVO lbDevice : lbDevices) {
|
||||
if (lbDevice.getState() == LBDeviceState.Enabled) {
|
||||
@ -641,7 +652,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
|
||||
}
|
||||
|
||||
SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO);
|
||||
answer = (SetStaticNatRulesAnswer )_agentMgr.send(lbDevice.getHostId(), cmd);
|
||||
answer = (SetStaticNatRulesAnswer) _agentMgr.send(lbDevice.getHostId(), cmd);
|
||||
if (answer == null) {
|
||||
return false;
|
||||
} else {
|
||||
@ -652,4 +663,5 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -44,10 +44,12 @@ import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
@Local(value=NetworkElement.class)
|
||||
@Local(value = NetworkElement.class)
|
||||
public class OvsElement extends AdapterBase implements NetworkElement {
|
||||
@Inject OvsNetworkManager _ovsVlanMgr;
|
||||
@Inject OvsTunnelManager _ovsTunnelMgr;
|
||||
@Inject
|
||||
OvsNetworkManager _ovsVlanMgr;
|
||||
@Inject
|
||||
OvsTunnelManager _ovsTunnelMgr;
|
||||
|
||||
@Override
|
||||
public boolean destroy(Network network)
|
||||
@ -114,7 +116,6 @@ public class OvsElement extends AdapterBase implements NetworkElement {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shutdown(Network network, ReservationContext context, boolean cleanup)
|
||||
throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
|
||||
@ -54,14 +54,14 @@ import com.cloud.network.dao.LoadBalancerDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.dao.VirtualRouterProviderDao;
|
||||
import com.cloud.network.lb.LoadBalancingRule;
|
||||
import com.cloud.network.lb.LoadBalancingRulesManager;
|
||||
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.rules.LbStickinessMethod;
|
||||
import com.cloud.network.rules.LbStickinessMethod.StickinessMethodType;
|
||||
import com.cloud.network.router.VirtualRouter.Role;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.rules.LbStickinessMethod;
|
||||
import com.cloud.network.rules.LbStickinessMethod.StickinessMethodType;
|
||||
import com.cloud.network.rules.PortForwardingRule;
|
||||
import com.cloud.network.rules.RulesManager;
|
||||
import com.cloud.network.rules.StaticNat;
|
||||
@ -88,28 +88,43 @@ import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
|
||||
@Local(value=NetworkElement.class)
|
||||
public class VirtualRouterElement extends AdapterBase implements VirtualRouterElementService, DhcpServiceProvider, UserDataServiceProvider, SourceNatServiceProvider, StaticNatServiceProvider, FirewallServiceProvider, LoadBalancingServiceProvider, PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer {
|
||||
@Local(value = NetworkElement.class)
|
||||
public class VirtualRouterElement extends AdapterBase implements VirtualRouterElementService, DhcpServiceProvider, UserDataServiceProvider, SourceNatServiceProvider, StaticNatServiceProvider, FirewallServiceProvider,
|
||||
LoadBalancingServiceProvider, PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer {
|
||||
private static final Logger s_logger = Logger.getLogger(VirtualRouterElement.class);
|
||||
|
||||
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
|
||||
|
||||
@Inject NetworkDao _networksDao;
|
||||
@Inject NetworkManager _networkMgr;
|
||||
@Inject LoadBalancingRulesManager _lbMgr;
|
||||
@Inject NetworkOfferingDao _networkOfferingDao;
|
||||
@Inject VirtualNetworkApplianceManager _routerMgr;
|
||||
@Inject ConfigurationManager _configMgr;
|
||||
@Inject RulesManager _rulesMgr;
|
||||
@Inject UserVmManager _userVmMgr;
|
||||
@Inject UserVmDao _userVmDao;
|
||||
@Inject DomainRouterDao _routerDao;
|
||||
@Inject LoadBalancerDao _lbDao;
|
||||
@Inject HostDao _hostDao;
|
||||
@Inject AccountManager _accountMgr;
|
||||
@Inject ConfigurationDao _configDao;
|
||||
@Inject VirtualRouterProviderDao _vrProviderDao;
|
||||
@Inject
|
||||
NetworkDao _networksDao;
|
||||
@Inject
|
||||
NetworkManager _networkMgr;
|
||||
@Inject
|
||||
LoadBalancingRulesManager _lbMgr;
|
||||
@Inject
|
||||
NetworkOfferingDao _networkOfferingDao;
|
||||
@Inject
|
||||
VirtualNetworkApplianceManager _routerMgr;
|
||||
@Inject
|
||||
ConfigurationManager _configMgr;
|
||||
@Inject
|
||||
RulesManager _rulesMgr;
|
||||
@Inject
|
||||
UserVmManager _userVmMgr;
|
||||
@Inject
|
||||
UserVmDao _userVmDao;
|
||||
@Inject
|
||||
DomainRouterDao _routerDao;
|
||||
@Inject
|
||||
LoadBalancerDao _lbDao;
|
||||
@Inject
|
||||
HostDao _hostDao;
|
||||
@Inject
|
||||
AccountManager _accountMgr;
|
||||
@Inject
|
||||
ConfigurationDao _configDao;
|
||||
@Inject
|
||||
VirtualRouterProviderDao _vrProviderDao;
|
||||
|
||||
protected boolean canHandle(Network network, Service service) {
|
||||
Long physicalNetworkId = _networkMgr.getPhysicalNetworkId(network);
|
||||
@ -137,7 +152,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
|
||||
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException,
|
||||
InsufficientCapacityException {
|
||||
if (offering.isSystemOnly()) {
|
||||
return false;
|
||||
}
|
||||
@ -150,9 +166,9 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
|
||||
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
|
||||
InsufficientCapacityException, ResourceUnavailableException {
|
||||
if (vm.getType() != VirtualMachine.Type.User) {
|
||||
return false;
|
||||
}
|
||||
@ -170,7 +186,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>)vm;
|
||||
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>) vm;
|
||||
List<DomainRouterVO> routers = _routerMgr.deployVirtualRouter(network, dest, _accountMgr.getAccount(network.getAccountId()), uservm.getParameters(), offering.getRedundantRouter());
|
||||
if ((routers == null) || (routers.size() == 0)) {
|
||||
throw new ResourceUnavailableException("Can't find at least one running router!", this.getClass(), 0);
|
||||
@ -187,7 +203,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!_routerMgr.applyFirewallRules(config, rules, routers)){
|
||||
if (!_routerMgr.applyFirewallRules(config, rules, routers)) {
|
||||
throw new CloudRuntimeException("Failed to apply firewall rules in network " + config.getId());
|
||||
} else {
|
||||
return true;
|
||||
@ -196,6 +212,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function detects numbers like 12 ,32h ,42m .. etc,. 1) plain
|
||||
* number like 12 2) time or tablesize like 12h, 34m, 45k, 54m , here
|
||||
@ -314,7 +331,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!_routerMgr.applyFirewallRules(network, rules, routers)){
|
||||
if (!_routerMgr.applyFirewallRules(network, rules, routers)) {
|
||||
throw new CloudRuntimeException("Failed to apply firewall rules in network " + network.getId());
|
||||
} else {
|
||||
return true;
|
||||
@ -324,9 +341,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] applyVpnUsers(RemoteAccessVpn vpn, List<? extends VpnUser> users) throws ResourceUnavailableException{
|
||||
public String[] applyVpnUsers(RemoteAccessVpn vpn, List<? extends VpnUser> users) throws ResourceUnavailableException {
|
||||
Network network = _networksDao.findById(vpn.getNetworkId());
|
||||
|
||||
if (canHandle(network, Service.Vpn)) {
|
||||
@ -406,24 +422,58 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
|
||||
private static String getHAProxyStickinessCapability() {
|
||||
LbStickinessMethod method;
|
||||
List <LbStickinessMethod> methodList = new ArrayList<LbStickinessMethod>(1);
|
||||
List<LbStickinessMethod> methodList = new ArrayList<LbStickinessMethod>(1);
|
||||
|
||||
method = new LbStickinessMethod(StickinessMethodType.LBCookieBased, "This is loadbalancer cookie based stickiness method.");
|
||||
method.addParam("cookie-name", false, "Cookie name passed in http header by the LB to the client.", false);
|
||||
method.addParam("mode", false, "Valid values: insert, rewrite, prefix. Default value: insert. In the insert mode cookie will be created by the LB. In other modes, cookie will be created by the server and LB modifies it.", false);
|
||||
method.addParam("nocache", false, "This option is recommended in conjunction with the insert mode when there is a cache between the client and HAProxy, as it ensures that a cacheable response will be tagged non-cacheable if a cookie needs to be inserted. This is important because if all persistence cookies are added on a cacheable home page for instance, then all customers will then fetch the page from an outer cache and will all share the same persistence cookie, leading to one server receiving much more traffic than others. See also the insert and postonly options. ", true);
|
||||
method.addParam("indirect", false, "When this option is specified in insert mode, cookies will only be added when the server was not reached after a direct access, which means that only when a server is elected after applying a load-balancing algorithm, or after a redispatch, then the cookie will be inserted. If the client has all the required information to connect to the same server next time, no further cookie will be inserted. In all cases, when the indirect option is used in insert mode, the cookie is always removed from the requests transmitted to the server. The persistence mechanism then becomes totally transparent from the application point of view.", true);
|
||||
method.addParam("postonly",false, "This option ensures that cookie insertion will only be performed on responses to POST requests. It is an alternative to the nocache option, because POST responses are not cacheable, so this ensures that the persistence cookie will never get cached.Since most sites do not need any sort of persistence before the first POST which generally is a login request, this is a very efficient method to optimize caching without risking to find a persistence cookie in the cache. See also the insert and nocache options.", true);
|
||||
method.addParam("domain",false, "This option allows to specify the domain at which a cookie is inserted. It requires exactly one parameter: a valid domain name. If the domain begins with a dot, the browser is allowed to use it for any host ending with that name. It is also possible to specify several domain names by invoking this option multiple times. Some browsers might have small limits on the number of domains, so be careful when doing that. For the record, sending 10 domains to MSIE 6 or Firefox 2 works as expected.", false);
|
||||
method.addParam("mode", false,
|
||||
"Valid values: insert, rewrite, prefix. Default value: insert. In the insert mode cookie will be created by the LB. In other modes, cookie will be created by the server and LB modifies it.", false);
|
||||
method.addParam(
|
||||
"nocache",
|
||||
false,
|
||||
"This option is recommended in conjunction with the insert mode when there is a cache between the client and HAProxy, as it ensures that a cacheable response will be tagged non-cacheable if a cookie needs to be inserted. This is important because if all persistence cookies are added on a cacheable home page for instance, then all customers will then fetch the page from an outer cache and will all share the same persistence cookie, leading to one server receiving much more traffic than others. See also the insert and postonly options. ",
|
||||
true);
|
||||
method.addParam(
|
||||
"indirect",
|
||||
false,
|
||||
"When this option is specified in insert mode, cookies will only be added when the server was not reached after a direct access, which means that only when a server is elected after applying a load-balancing algorithm, or after a redispatch, then the cookie will be inserted. If the client has all the required information to connect to the same server next time, no further cookie will be inserted. In all cases, when the indirect option is used in insert mode, the cookie is always removed from the requests transmitted to the server. The persistence mechanism then becomes totally transparent from the application point of view.",
|
||||
true);
|
||||
method.addParam(
|
||||
"postonly",
|
||||
false,
|
||||
"This option ensures that cookie insertion will only be performed on responses to POST requests. It is an alternative to the nocache option, because POST responses are not cacheable, so this ensures that the persistence cookie will never get cached.Since most sites do not need any sort of persistence before the first POST which generally is a login request, this is a very efficient method to optimize caching without risking to find a persistence cookie in the cache. See also the insert and nocache options.",
|
||||
true);
|
||||
method.addParam(
|
||||
"domain",
|
||||
false,
|
||||
"This option allows to specify the domain at which a cookie is inserted. It requires exactly one parameter: a valid domain name. If the domain begins with a dot, the browser is allowed to use it for any host ending with that name. It is also possible to specify several domain names by invoking this option multiple times. Some browsers might have small limits on the number of domains, so be careful when doing that. For the record, sending 10 domains to MSIE 6 or Firefox 2 works as expected.",
|
||||
false);
|
||||
methodList.add(method);
|
||||
|
||||
method = new LbStickinessMethod(StickinessMethodType.AppCookieBased, "This is App session based sticky method. Define session stickiness on an existing application cookie. It can be used only for a specific http traffic");
|
||||
method = new LbStickinessMethod(StickinessMethodType.AppCookieBased,
|
||||
"This is App session based sticky method. Define session stickiness on an existing application cookie. It can be used only for a specific http traffic");
|
||||
method.addParam("cookie-name", true, "This is the name of the cookie used by the application and which LB will have to learn for each new session", false);
|
||||
method.addParam("length", true, "This is the max number of characters that will be memorized and checked in each cookie value", false);
|
||||
method.addParam("holdtime", true, "This is the time after which the cookie will be removed from memory if unused. The value should be in the format Example : 20s or 30m or 4h or 5d . only seconds(s), minutes(m) hours(h) and days(d) are valid , cannot use th combinations like 20h30m. ", false);
|
||||
method.addParam("request-learn", false, "If this option is specified, then haproxy will be able to learn the cookie found in the request in case the server does not specify any in response. This is typically what happens with PHPSESSID cookies, or when haproxy's session expires before the application's session and the correct server is selected. It is recommended to specify this option to improve reliability", true);
|
||||
method.addParam("prefix", false, "When this option is specified, haproxy will match on the cookie prefix (or URL parameter prefix). The appsession value is the data following this prefix. Example : appsession ASPSESSIONID len 64 timeout 3h prefix This will match the cookie ASPSESSIONIDXXXX=XXXXX, the appsession value will be XXXX=XXXXX.", true);
|
||||
method.addParam("mode", false, "This option allows to change the URL parser mode. 2 modes are currently supported : - path-parameters : The parser looks for the appsession in the path parameters part (each parameter is separated by a semi-colon), which is convenient for JSESSIONID for example.This is the default mode if the option is not set. - query-string : In this mode, the parser will look for the appsession in the query string.", false);
|
||||
method.addParam(
|
||||
"holdtime",
|
||||
true,
|
||||
"This is the time after which the cookie will be removed from memory if unused. The value should be in the format Example : 20s or 30m or 4h or 5d . only seconds(s), minutes(m) hours(h) and days(d) are valid , cannot use th combinations like 20h30m. ",
|
||||
false);
|
||||
method.addParam(
|
||||
"request-learn",
|
||||
false,
|
||||
"If this option is specified, then haproxy will be able to learn the cookie found in the request in case the server does not specify any in response. This is typically what happens with PHPSESSID cookies, or when haproxy's session expires before the application's session and the correct server is selected. It is recommended to specify this option to improve reliability",
|
||||
true);
|
||||
method.addParam(
|
||||
"prefix",
|
||||
false,
|
||||
"When this option is specified, haproxy will match on the cookie prefix (or URL parameter prefix). The appsession value is the data following this prefix. Example : appsession ASPSESSIONID len 64 timeout 3h prefix This will match the cookie ASPSESSIONIDXXXX=XXXXX, the appsession value will be XXXX=XXXXX.",
|
||||
true);
|
||||
method.addParam(
|
||||
"mode",
|
||||
false,
|
||||
"This option allows to change the URL parser mode. 2 modes are currently supported : - path-parameters : The parser looks for the appsession in the path parameters part (each parameter is separated by a semi-colon), which is convenient for JSESSIONID for example.This is the default mode if the option is not set. - query-string : In this mode, the parser will look for the appsession in the query string.",
|
||||
false);
|
||||
methodList.add(method);
|
||||
|
||||
method = new LbStickinessMethod(StickinessMethodType.SourceBased, "This is source based Stickiness method, it can be used for any type of protocol.");
|
||||
@ -435,10 +485,11 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
String capability = gson.toJson(methodList);
|
||||
return capability;
|
||||
}
|
||||
|
||||
private static Map<Service, Map<Capability, String>> setCapabilities() {
|
||||
Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
|
||||
|
||||
//Set capabilities for LB service
|
||||
// Set capabilities for LB service
|
||||
Map<Capability, String> lbCapabilities = new HashMap<Capability, String>();
|
||||
lbCapabilities.put(Capability.SupportedLBAlgorithms, "roundrobin,leastconn,source");
|
||||
lbCapabilities.put(Capability.SupportedLBIsolation, "dedicated");
|
||||
@ -448,7 +499,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
|
||||
capabilities.put(Service.Lb, lbCapabilities);
|
||||
|
||||
//Set capabilities for Firewall service
|
||||
// Set capabilities for Firewall service
|
||||
Map<Capability, String> firewallCapabilities = new HashMap<Capability, String>();
|
||||
firewallCapabilities.put(Capability.TrafficStatistics, "per public ip");
|
||||
firewallCapabilities.put(Capability.SupportedProtocols, "tcp,udp,icmp");
|
||||
@ -456,7 +507,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
|
||||
capabilities.put(Service.Firewall, firewallCapabilities);
|
||||
|
||||
//Set capabilities for vpn
|
||||
// Set capabilities for vpn
|
||||
Map<Capability, String> vpnCapabilities = new HashMap<Capability, String>();
|
||||
vpnCapabilities.put(Capability.SupportedVpnTypes, "pptp,l2tp,ipsec");
|
||||
capabilities.put(Service.Vpn, vpnCapabilities);
|
||||
@ -519,7 +570,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean destroy(Network config) throws ConcurrentOperationException, ResourceUnavailableException{
|
||||
public boolean destroy(Network config) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(config.getId(), Role.VIRTUAL_ROUTER);
|
||||
if (routers == null || routers.isEmpty()) {
|
||||
return true;
|
||||
@ -532,7 +583,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws ResourceUnavailableException{
|
||||
public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws ResourceUnavailableException {
|
||||
if (!canHandle(network, null)) {
|
||||
return false;
|
||||
}
|
||||
@ -543,7 +594,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>)vm;
|
||||
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>) vm;
|
||||
|
||||
return _routerMgr.savePasswordToRouter(network, nic, uservm, routers);
|
||||
}
|
||||
@ -588,7 +639,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!_routerMgr.applyFirewallRules(network, rules, routers)){
|
||||
if (!_routerMgr.applyFirewallRules(network, rules, routers)) {
|
||||
throw new CloudRuntimeException("Failed to apply firewall rules in network " + network.getId());
|
||||
} else {
|
||||
return true;
|
||||
@ -614,7 +665,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
if (element == null) {
|
||||
return true;
|
||||
}
|
||||
//Find domain routers
|
||||
// Find domain routers
|
||||
long elementId = element.getId();
|
||||
List<DomainRouterVO> routers = _routerDao.listByElementId(elementId);
|
||||
boolean result = true;
|
||||
@ -654,7 +705,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>)vm;
|
||||
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>) vm;
|
||||
|
||||
boolean publicNetwork = false;
|
||||
if (_networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, getProvider())) {
|
||||
@ -676,7 +727,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
}
|
||||
}
|
||||
|
||||
//for Basic zone, add all Running routers - we have to send Dhcp/vmData/password info to them when network.dns.basiczone.updates is set to "all"
|
||||
// for Basic zone, add all Running routers - we have to send Dhcp/vmData/password info to them when
|
||||
// network.dns.basiczone.updates is set to "all"
|
||||
Long podId = dest.getPod().getId();
|
||||
if (isPodBased && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) {
|
||||
List<DomainRouterVO> allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), podId, State.Running, Role.VIRTUAL_ROUTER);
|
||||
@ -702,7 +754,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>)vm;
|
||||
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>) vm;
|
||||
|
||||
boolean publicNetwork = false;
|
||||
if (_networkMgr.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, getProvider())) {
|
||||
@ -724,7 +776,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
}
|
||||
}
|
||||
|
||||
//for Basic zone, add all Running routers - we have to send Dhcp/vmData/password info to them when network.dns.basiczone.updates is set to "all"
|
||||
// for Basic zone, add all Running routers - we have to send Dhcp/vmData/password info to them when
|
||||
// network.dns.basiczone.updates is set to "all"
|
||||
Long podId = dest.getPod().getId();
|
||||
if (isPodBased && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) {
|
||||
List<DomainRouterVO> allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), podId, State.Running, Role.VIRTUAL_ROUTER);
|
||||
|
||||
@ -79,7 +79,7 @@ import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
|
||||
@Local(value = { FirewallService.class, FirewallManager.class })
|
||||
public class FirewallManagerImpl implements FirewallService, FirewallManager, Manager{
|
||||
public class FirewallManagerImpl implements FirewallService, FirewallManager, Manager {
|
||||
private static final Logger s_logger = Logger.getLogger(FirewallManagerImpl.class);
|
||||
String _name;
|
||||
|
||||
@ -108,7 +108,7 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
@Inject
|
||||
UserVmDao _vmDao;
|
||||
|
||||
private boolean _elbEnabled=false;
|
||||
private boolean _elbEnabled = false;
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
@ -137,13 +137,15 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
public FirewallRule createFirewallRule(FirewallRule rule) throws NetworkRuleConflictException {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
return createFirewallRule(rule.getSourceIpAddressId(), caller, rule.getXid(), rule.getSourcePortStart() ,rule.getSourcePortEnd(), rule.getProtocol(), rule.getSourceCidrList(), rule.getIcmpCode(), rule.getIcmpType(), null, rule.getType());
|
||||
return createFirewallRule(rule.getSourceIpAddressId(), caller, rule.getXid(), rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), rule.getSourceCidrList(), rule.getIcmpCode(),
|
||||
rule.getIcmpType(), null, rule.getType());
|
||||
}
|
||||
|
||||
@DB
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_FIREWALL_OPEN, eventDescription = "creating firewall rule", create = true)
|
||||
public FirewallRule createFirewallRule(long ipAddrId, Account caller, String xId, Integer portStart,Integer portEnd, String protocol, List<String> sourceCidrList, Integer icmpCode, Integer icmpType, Long relatedRuleId, FirewallRule.FirewallRuleType type) throws NetworkRuleConflictException{
|
||||
public FirewallRule createFirewallRule(long ipAddrId, Account caller, String xId, Integer portStart, Integer portEnd, String protocol, List<String> sourceCidrList, Integer icmpCode, Integer icmpType,
|
||||
Long relatedRuleId, FirewallRule.FirewallRuleType type) throws NetworkRuleConflictException {
|
||||
IPAddressVO ipAddress = _ipAddressDao.findById(ipAddrId);
|
||||
|
||||
// Validate ip address
|
||||
@ -153,7 +155,7 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
|
||||
validateFirewallRule(caller, ipAddress, portStart, portEnd, protocol, Purpose.Firewall, type);
|
||||
|
||||
//icmp code and icmp type can't be passed in for any other protocol rather than icmp
|
||||
// icmp code and icmp type can't be passed in for any other protocol rather than icmp
|
||||
if (!protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (icmpCode != null || icmpType != null)) {
|
||||
throw new InvalidParameterValueException("Can specify icmpCode and icmpType for ICMP protocol only");
|
||||
}
|
||||
@ -177,7 +179,7 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
FirewallRuleVO newRule = new FirewallRuleVO (xId, ipAddrId, portStart, portEnd, protocol.toLowerCase(), networkId, accountId, domainId, Purpose.Firewall, sourceCidrList, icmpCode, icmpType, relatedRuleId);
|
||||
FirewallRuleVO newRule = new FirewallRuleVO(xId, ipAddrId, portStart, portEnd, protocol.toLowerCase(), networkId, accountId, domainId, Purpose.Firewall, sourceCidrList, icmpCode, icmpType, relatedRuleId);
|
||||
newRule.setType(type);
|
||||
newRule = _firewallDao.persist(newRule);
|
||||
|
||||
@ -252,13 +254,14 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
continue; // Skips my own rule.
|
||||
}
|
||||
|
||||
boolean oneOfRulesIsFirewall = ((rule.getPurpose() == Purpose.Firewall || newRule.getPurpose() == Purpose.Firewall) && ((newRule.getPurpose() != rule.getPurpose()) || (!newRule.getProtocol().equalsIgnoreCase(rule.getProtocol()))));
|
||||
boolean oneOfRulesIsFirewall = ((rule.getPurpose() == Purpose.Firewall || newRule.getPurpose() == Purpose.Firewall) && ((newRule.getPurpose() != rule.getPurpose()) || (!newRule.getProtocol()
|
||||
.equalsIgnoreCase(rule.getProtocol()))));
|
||||
|
||||
//if both rules are firewall and their cidrs are different, we can skip port ranges verification
|
||||
// if both rules are firewall and their cidrs are different, we can skip port ranges verification
|
||||
boolean bothRulesFirewall = (rule.getPurpose() == newRule.getPurpose() && rule.getPurpose() == Purpose.Firewall);
|
||||
boolean duplicatedCidrs = false;
|
||||
if (bothRulesFirewall) {
|
||||
//Verify that the rules have different cidrs
|
||||
// Verify that the rules have different cidrs
|
||||
List<String> ruleCidrList = rule.getSourceCidrList();
|
||||
List<String> newRuleCidrList = newRule.getSourceCidrList();
|
||||
|
||||
@ -287,15 +290,17 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
}
|
||||
|
||||
if (newRule.getProtocol().equalsIgnoreCase(NetUtils.ICMP_PROTO) && newRule.getProtocol().equalsIgnoreCase(rule.getProtocol())) {
|
||||
if (newRule.getIcmpCode().longValue() == rule.getIcmpCode().longValue() && newRule.getIcmpType().longValue() == rule.getIcmpType().longValue() && newRule.getProtocol().equalsIgnoreCase(rule.getProtocol()) && duplicatedCidrs) {
|
||||
if (newRule.getIcmpCode().longValue() == rule.getIcmpCode().longValue() && newRule.getIcmpType().longValue() == rule.getIcmpType().longValue()
|
||||
&& newRule.getProtocol().equalsIgnoreCase(rule.getProtocol()) && duplicatedCidrs) {
|
||||
throw new InvalidParameterValueException("New rule conflicts with existing rule id=" + rule.getId());
|
||||
}
|
||||
}
|
||||
|
||||
boolean notNullPorts = (newRule.getSourcePortStart() != null && newRule.getSourcePortEnd() != null && rule.getSourcePortStart() != null && rule.getSourcePortEnd() != null) ;
|
||||
boolean notNullPorts = (newRule.getSourcePortStart() != null && newRule.getSourcePortEnd() != null && rule.getSourcePortStart() != null && rule.getSourcePortEnd() != null);
|
||||
if (!notNullPorts) {
|
||||
continue;
|
||||
} else if (!oneOfRulesIsFirewall && !(bothRulesFirewall && !duplicatedCidrs) && ((rule.getSourcePortStart().intValue() <= newRule.getSourcePortStart().intValue() && rule.getSourcePortEnd().intValue() >= newRule.getSourcePortStart().intValue())
|
||||
} else if (!oneOfRulesIsFirewall && !(bothRulesFirewall && !duplicatedCidrs)
|
||||
&& ((rule.getSourcePortStart().intValue() <= newRule.getSourcePortStart().intValue() && rule.getSourcePortEnd().intValue() >= newRule.getSourcePortStart().intValue())
|
||||
|| (rule.getSourcePortStart().intValue() <= newRule.getSourcePortEnd().intValue() && rule.getSourcePortEnd().intValue() >= newRule.getSourcePortEnd().intValue())
|
||||
|| (newRule.getSourcePortStart().intValue() <= rule.getSourcePortStart().intValue() && newRule.getSourcePortEnd().intValue() >= rule.getSourcePortStart().intValue())
|
||||
|| (newRule.getSourcePortStart().intValue() <= rule.getSourcePortEnd().intValue() && newRule.getSourcePortEnd().intValue() >= rule.getSourcePortEnd().intValue()))) {
|
||||
@ -316,7 +321,6 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void validateFirewallRule(Account caller, IPAddressVO ipAddress, Integer portStart, Integer portEnd, String proto, Purpose purpose, FirewallRuleType type) {
|
||||
if (portStart != null && !NetUtils.isValidPort(portStart)) {
|
||||
@ -347,7 +351,6 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
Network network = _networkMgr.getNetwork(networkId);
|
||||
assert network != null : "Can't create port forwarding rule as network associated with public ip address is null?";
|
||||
|
||||
|
||||
// Verify that the network guru supports the protocol specified
|
||||
Map<Network.Capability, String> protocolCapabilities = null;
|
||||
|
||||
@ -355,7 +358,7 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
if (!_elbEnabled) {
|
||||
protocolCapabilities = _networkMgr.getNetworkServiceCapabilities(network.getId(), Service.Lb);
|
||||
}
|
||||
} else if (purpose == Purpose.Firewall){
|
||||
} else if (purpose == Purpose.Firewall) {
|
||||
protocolCapabilities = _networkMgr.getNetworkServiceCapabilities(network.getId(), Service.Firewall);
|
||||
} else if (purpose == Purpose.PortForwarding) {
|
||||
protocolCapabilities = _networkMgr.getNetworkServiceCapabilities(network.getId(), Service.PortForwarding);
|
||||
@ -406,7 +409,6 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
return applyFirewallRules(rules, false, caller);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean applyFirewallRules(List<FirewallRuleVO> rules, boolean continueOnError, Account caller) {
|
||||
|
||||
@ -415,7 +417,7 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
return true;
|
||||
}
|
||||
|
||||
for (FirewallRuleVO rule: rules){
|
||||
for (FirewallRuleVO rule : rules) {
|
||||
// load cidrs if any
|
||||
rule.setSourceCidrList(_firewallCidrsDao.getSourceCidrs(rule.getId()));
|
||||
}
|
||||
@ -504,7 +506,6 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FirewallRule getFirewallRule(long ruleId) {
|
||||
return _firewallDao.findById(ruleId);
|
||||
@ -520,7 +521,8 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
}
|
||||
|
||||
for (FirewallRuleVO rule : fwRules) {
|
||||
// Mark all Firewall rules as Revoke, but don't revoke them yet - we have to revoke all rules for ip, no need to send them one by one
|
||||
// Mark all Firewall rules as Revoke, but don't revoke them yet - we have to revoke all rules for ip, no
|
||||
// need to send them one by one
|
||||
revokeFirewallRule(rule.getId(), false, caller, Account.ACCOUNT_ID_SYSTEM);
|
||||
}
|
||||
|
||||
@ -539,9 +541,10 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
}
|
||||
|
||||
@Override
|
||||
public FirewallRule createRuleForAllCidrs(long ipAddrId, Account caller, Integer startPort, Integer endPort, String protocol, Integer icmpCode, Integer icmpType, Long relatedRuleId) throws NetworkRuleConflictException{
|
||||
public FirewallRule createRuleForAllCidrs(long ipAddrId, Account caller, Integer startPort, Integer endPort, String protocol, Integer icmpCode, Integer icmpType, Long relatedRuleId)
|
||||
throws NetworkRuleConflictException {
|
||||
|
||||
//If firwallRule for this port range already exists, return it
|
||||
// If firwallRule for this port range already exists, return it
|
||||
List<FirewallRuleVO> rules = _firewallDao.listByIpPurposeAndProtocolAndNotRevoked(ipAddrId, startPort, endPort, protocol, Purpose.Firewall);
|
||||
if (!rules.isEmpty()) {
|
||||
return rules.get(0);
|
||||
@ -562,7 +565,8 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
}
|
||||
|
||||
for (FirewallRuleVO rule : fwRules) {
|
||||
// Mark all Firewall rules as Revoke, but don't revoke them yet - we have to revoke all rules for ip, no need to send them one by one
|
||||
// Mark all Firewall rules as Revoke, but don't revoke them yet - we have to revoke all rules for ip, no
|
||||
// need to send them one by one
|
||||
revokeFirewallRule(rule.getId(), false, caller, Account.ACCOUNT_ID_SYSTEM);
|
||||
}
|
||||
|
||||
@ -594,7 +598,6 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean revokeFirewallRulesForVm(long vmId) {
|
||||
boolean success = true;
|
||||
@ -607,7 +610,7 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
List<FirewallRuleVO> staticNatRules = _firewallDao.listStaticNatByVmId(vm.getId());
|
||||
List<FirewallRuleVO> firewallRules = new ArrayList<FirewallRuleVO>();
|
||||
|
||||
//Make a list of firewall rules to reprogram
|
||||
// Make a list of firewall rules to reprogram
|
||||
for (PortForwardingRuleVO pfRule : pfRules) {
|
||||
FirewallRuleVO relatedRule = _firewallDao.findByRelatedId(pfRule.getId());
|
||||
if (relatedRule != null) {
|
||||
@ -622,7 +625,6 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Set<Long> ipsToReprogram = new HashSet<Long>();
|
||||
|
||||
if (firewallRules.isEmpty()) {
|
||||
@ -642,7 +644,7 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
for (Long ipId : ipsToReprogram) {
|
||||
s_logger.debug("Applying firewall rules for ip address id=" + ipId + " as a part of vm expunge");
|
||||
try {
|
||||
success = success && applyFirewallRules(ipId,_accountMgr.getSystemAccount());
|
||||
success = success && applyFirewallRules(ipId, _accountMgr.getSystemAccount());
|
||||
} catch (ResourceUnavailableException ex) {
|
||||
s_logger.warn("Failed to apply port forwarding rules for ip id=" + ipId);
|
||||
success = false;
|
||||
@ -665,4 +667,5 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -278,7 +278,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
throw new InvalidParameterValueException("Failed to create Stickiness policy: Validation Failed " + cmd.getLbRuleId());
|
||||
}
|
||||
|
||||
/* Specific validations using network element validator for specific validations*/
|
||||
/* Specific validations using network element validator for specific validations */
|
||||
LBStickinessPolicyVO lbpolicy = new LBStickinessPolicyVO(loadBalancer.getId(), cmd.getLBStickinessPolicyName(), cmd.getStickinessMethodName(), cmd.getparamList(), cmd.getDescription());
|
||||
List<LbStickinessPolicy> policyList = new ArrayList<LbStickinessPolicy>();
|
||||
policyList.add(new LbStickinessPolicy(cmd.getStickinessMethodName(), lbpolicy.getParams()));
|
||||
@ -322,7 +322,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
}
|
||||
LoadBalancerVO loadBalancer = _lbDao.findById(Long.valueOf(stickinessPolicy.getLoadBalancerId()));
|
||||
if (loadBalancer == null) {
|
||||
throw new InvalidParameterException("Invalid Load balancer :"+stickinessPolicy.getLoadBalancerId()+" for Stickiness policy id: " + stickinessPolicyId);
|
||||
throw new InvalidParameterException("Invalid Load balancer :" + stickinessPolicy.getLoadBalancerId() + " for Stickiness policy id: " + stickinessPolicyId);
|
||||
}
|
||||
long loadBalancerId = loadBalancer.getId();
|
||||
_accountMgr.checkAccess(caller.getCaller(), null, true, loadBalancer);
|
||||
@ -422,7 +422,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
|
||||
}
|
||||
|
||||
if(!success){
|
||||
if (!success) {
|
||||
throw new CloudRuntimeException("Failed to add load balancer rule id " + loadBalancerId + " for vms " + instanceIds);
|
||||
}
|
||||
|
||||
@ -465,7 +465,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
} catch (ResourceUnavailableException e) {
|
||||
s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
|
||||
}
|
||||
if(!success){
|
||||
if (!success) {
|
||||
throw new CloudRuntimeException("Failed to remove load balancer rule id " + loadBalancerId + " for vms " + instanceIds);
|
||||
}
|
||||
return success;
|
||||
@ -521,7 +521,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
_accountMgr.checkAccess(caller, null, true, rule);
|
||||
|
||||
boolean result = deleteLoadBalancerRule(loadBalancerId, apply, caller, ctx.getCallerUserId());
|
||||
if(!result){
|
||||
if (!result) {
|
||||
throw new CloudRuntimeException("Unable to remove load balancer rule " + loadBalancerId);
|
||||
}
|
||||
return result;
|
||||
@ -563,9 +563,9 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
|
||||
txn.commit();
|
||||
|
||||
//gather external network usage stats for this lb rule
|
||||
// gather external network usage stats for this lb rule
|
||||
NetworkVO network = _networkDao.findById(lb.getNetworkId());
|
||||
if(network != null){
|
||||
if (network != null) {
|
||||
if (_networkMgr.networkIsConfiguredForExternalNetworking(network.getDataCenterId(), network.getId())) {
|
||||
_externalLBMgr.updateExternalLoadBalancerNetworkUsageStats(loadBalancerId);
|
||||
}
|
||||
@ -600,7 +600,6 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_CREATE, eventDescription = "creating load balancer")
|
||||
public LoadBalancer createLoadBalancerRule(CreateLoadBalancerRuleCmd lb, boolean openFirewall) throws NetworkRuleConflictException, InsufficientAddressCapacityException {
|
||||
@ -635,7 +634,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
}
|
||||
|
||||
LoadBalancer result = _elbMgr.handleCreateLoadBalancerRule(lb, lbOwner, lb.getNetworkId());
|
||||
if (result == null){
|
||||
if (result == null) {
|
||||
IpAddress ip = null;
|
||||
Network guestNetwork = _networkMgr.getNetwork(lb.getNetworkId());
|
||||
NetworkOffering off = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId());
|
||||
@ -655,8 +654,8 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
}
|
||||
}
|
||||
|
||||
if (result == null){
|
||||
throw new CloudRuntimeException("Failed to create load balancer rule: "+lb.getName());
|
||||
if (result == null) {
|
||||
throw new CloudRuntimeException("Failed to create load balancer rule: " + lb.getName());
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -681,7 +680,6 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
|
||||
_firewallMgr.validateFirewallRule(caller.getCaller(), ipAddr, srcPortStart, srcPortEnd, lb.getProtocol(), Purpose.LoadBalancing, FirewallRuleType.User);
|
||||
|
||||
|
||||
networkId = ipAddr.getAssociatedWithNetworkId();
|
||||
if (networkId == null) {
|
||||
throw new InvalidParameterValueException("Unable to create load balancer rule ; ip id=" + sourceIpId + " is not associated with any network");
|
||||
@ -744,7 +742,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
@Override
|
||||
public boolean applyLoadBalancerConfig(long lbRuleId) throws ResourceUnavailableException {
|
||||
LoadBalancerVO lb = _lbDao.findById(lbRuleId);
|
||||
//get all rules in transition state
|
||||
// get all rules in transition state
|
||||
List<LoadBalancerVO> lbs = _lbDao.listInTransitionStateByNetworkId(lb.getNetworkId());
|
||||
return applyLoadBalancerRules(lbs, true);
|
||||
}
|
||||
@ -768,7 +766,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
List<LbDestination> dstList = getExistingDestinations(lb.getId());
|
||||
List<LbStickinessPolicy> policyList = getStickinessPolicies(lb.getId());
|
||||
|
||||
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList,policyList);
|
||||
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList);
|
||||
rules.add(loadBalancing);
|
||||
}
|
||||
|
||||
@ -812,7 +810,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
|
||||
// remove LB-Stickiness policy mapping that were state to revoke
|
||||
List<LBStickinessPolicyVO> stickinesspolicies = _lb2stickinesspoliciesDao.listByLoadBalancerId(lb.getId(), true);
|
||||
if (!stickinesspolicies.isEmpty()){
|
||||
if (!stickinesspolicies.isEmpty()) {
|
||||
_lb2stickinesspoliciesDao.remove(lb.getId(), true);
|
||||
s_logger.debug("Load balancer rule id " + lb.getId() + " is removed stickiness policies");
|
||||
}
|
||||
@ -951,7 +949,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
throw new InvalidParameterValueException("Unable to find lb rule by id=" + lbRuleId);
|
||||
}
|
||||
|
||||
//check permissions
|
||||
// check permissions
|
||||
_accountMgr.checkAccess(caller, null, true, lb);
|
||||
|
||||
if (name != null) {
|
||||
@ -980,8 +978,8 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
}
|
||||
}
|
||||
|
||||
if(!success){
|
||||
throw new CloudRuntimeException("Failed to update load balancer rule: "+lbRuleId);
|
||||
if (!success) {
|
||||
throw new CloudRuntimeException("Failed to update load balancer rule: " + lbRuleId);
|
||||
}
|
||||
|
||||
return lb;
|
||||
@ -1037,14 +1035,17 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
|
||||
|
||||
return loadBalancerInstances;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LbStickinessMethod> getStickinessMethods(long networkid)
|
||||
{
|
||||
String capability = getLBStickinessCapability(networkid);
|
||||
if (capability == null) return null;
|
||||
if (capability == null)
|
||||
return null;
|
||||
Gson gson = new Gson();
|
||||
java.lang.reflect.Type listType = new TypeToken<List<LbStickinessMethod>>() {}.getType();
|
||||
List<LbStickinessMethod> result = gson.fromJson(capability,listType);
|
||||
java.lang.reflect.Type listType = new TypeToken<List<LbStickinessMethod>>() {
|
||||
}.getType();
|
||||
List<LbStickinessMethod> result = gson.fromJson(capability, listType);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ import com.cloud.network.rules.FirewallRule.FirewallRuleType;
|
||||
import com.cloud.network.rules.FirewallRule.Purpose;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
public interface FirewallManager extends FirewallService{
|
||||
public interface FirewallManager extends FirewallService {
|
||||
/**
|
||||
* detectRulesConflict finds conflicts in networking rules. It checks for
|
||||
* conflicts between the following types of netowrking rules;
|
||||
@ -42,8 +42,10 @@ public interface FirewallManager extends FirewallService{
|
||||
* only roll back one of the rules. However, the chances of that is low
|
||||
* and the user can simply re-add one of the rules themselves.
|
||||
*
|
||||
* @param newRule the new rule created.
|
||||
* @param ipAddress ip address that back up the new rule.
|
||||
* @param newRule
|
||||
* the new rule created.
|
||||
* @param ipAddress
|
||||
* ip address that back up the new rule.
|
||||
* @throws NetworkRuleConflictException
|
||||
*/
|
||||
void detectRulesConflict(FirewallRule newRule, IpAddress ipAddress) throws NetworkRuleConflictException;
|
||||
@ -60,14 +62,19 @@ public interface FirewallManager extends FirewallService{
|
||||
|
||||
/**
|
||||
* Revokes a firewall rule
|
||||
* @param ruleId the id of the rule to revoke.
|
||||
* @param caller TODO
|
||||
* @param userId TODO
|
||||
*
|
||||
* @param ruleId
|
||||
* the id of the rule to revoke.
|
||||
* @param caller
|
||||
* TODO
|
||||
* @param userId
|
||||
* TODO
|
||||
* @return
|
||||
*/
|
||||
boolean revokeFirewallRule(long ruleId, boolean apply, Account caller, long userId);
|
||||
|
||||
FirewallRule createFirewallRule(long ipAddrId, Account caller, String xId, Integer portStart, Integer portEnd, String protocol, List<String> sourceCidrList, Integer icmpCode, Integer icmpType, Long relatedRuleId, FirewallRule.FirewallRuleType type)
|
||||
FirewallRule createFirewallRule(long ipAddrId, Account caller, String xId, Integer portStart, Integer portEnd, String protocol, List<String> sourceCidrList, Integer icmpCode, Integer icmpType, Long relatedRuleId,
|
||||
FirewallRule.FirewallRuleType type)
|
||||
throws NetworkRuleConflictException;
|
||||
|
||||
FirewallRule createRuleForAllCidrs(long ipAddrId, Account caller, Integer startPort, Integer endPort, String protocol, Integer icmpCode, Integer icmpType, Long relatedRuleId) throws NetworkRuleConflictException;
|
||||
@ -77,4 +84,5 @@ public interface FirewallManager extends FirewallService{
|
||||
boolean revokeFirewallRulesForVm(long vmId);
|
||||
|
||||
boolean addSystemFirewallRules(IPAddressVO ip, Account acct);
|
||||
|
||||
}
|
||||
|
||||
@ -26,7 +26,6 @@ import com.cloud.network.IpAddress;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.uservm.UserVm;
|
||||
|
||||
|
||||
/**
|
||||
* Rules Manager manages the network rules created for different networks.
|
||||
*/
|
||||
@ -41,6 +40,7 @@ public interface RulesManager extends RulesService {
|
||||
boolean applyStaticNatRulesForNetwork(long networkId, boolean continueOnError, Account caller);
|
||||
|
||||
void checkIpAndUserVm(IpAddress ipAddress, UserVm userVm, Account caller);
|
||||
|
||||
void checkRuleAndUserVm(FirewallRule rule, UserVm userVm, Account caller);
|
||||
|
||||
boolean revokeAllPFAndStaticNatRulesForIp(long ipId, long userId, Account caller) throws ResourceUnavailableException;
|
||||
@ -52,6 +52,7 @@ public interface RulesManager extends RulesService {
|
||||
/**
|
||||
* Returns a list of port forwarding rules that are ready for application
|
||||
* to the network elements for this ip.
|
||||
*
|
||||
* @param ip
|
||||
* @return List of PortForwardingRule
|
||||
*/
|
||||
@ -64,6 +65,7 @@ public interface RulesManager extends RulesService {
|
||||
boolean revokeStaticNatRulesForVm(long vmId);
|
||||
|
||||
FirewallRule[] reservePorts(IpAddress ip, String protocol, FirewallRule.Purpose purpose, boolean openFirewall, Account caller, int... ports) throws NetworkRuleConflictException;
|
||||
|
||||
boolean releasePorts(long ipId, String protocol, FirewallRule.Purpose purpose, int... ports);
|
||||
|
||||
List<PortForwardingRuleVO> listByNetworkId(long networkId);
|
||||
|
||||
@ -155,7 +155,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_NET_RULE_ADD, eventDescription = "creating forwarding rule", create = true)
|
||||
public PortForwardingRule createPortForwardingRule(PortForwardingRule rule, Long vmId, boolean openFirewall) throws NetworkRuleConflictException {
|
||||
UserContext ctx = UserContext.current();
|
||||
@ -214,7 +215,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
rule.getDestinationPortEnd(), rule.getProtocol().toLowerCase(), networkId, accountId, domainId, vmId);
|
||||
newRule = _portForwardingDao.persist(newRule);
|
||||
|
||||
//create firewallRule for 0.0.0.0/0 cidr
|
||||
// create firewallRule for 0.0.0.0/0 cidr
|
||||
if (openFirewall) {
|
||||
_firewallMgr.createRuleForAllCidrs(ipAddrId, caller, rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), null, null, newRule.getId());
|
||||
}
|
||||
@ -231,11 +232,10 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
return newRule;
|
||||
} catch (Exception e) {
|
||||
|
||||
|
||||
if (newRule != null) {
|
||||
|
||||
txn.start();
|
||||
//no need to apply the rule as it wasn't programmed on the backend yet
|
||||
// no need to apply the rule as it wasn't programmed on the backend yet
|
||||
_firewallMgr.revokeRelatedFirewallRule(newRule.getId(), false);
|
||||
_portForwardingDao.remove(newRule.getId());
|
||||
|
||||
@ -249,7 +249,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_NET_RULE_ADD, eventDescription = "creating static nat rule", create = true)
|
||||
public StaticNatRule createStaticNatRule(StaticNatRule rule, boolean openFirewall) throws NetworkRuleConflictException {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
@ -284,18 +285,16 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
|
||||
FirewallRuleVO newRule = new FirewallRuleVO(rule.getXid(), rule.getSourceIpAddressId(), rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol().toLowerCase(),
|
||||
networkId, accountId, domainId, rule.getPurpose(), null, null, null, null);
|
||||
|
||||
newRule = _firewallDao.persist(newRule);
|
||||
|
||||
//create firewallRule for 0.0.0.0/0 cidr
|
||||
// create firewallRule for 0.0.0.0/0 cidr
|
||||
if (openFirewall) {
|
||||
_firewallMgr.createRuleForAllCidrs(ipAddrId, caller, rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), null, null, newRule.getId());
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
_firewallMgr.detectRulesConflict(newRule, ipAddress);
|
||||
if (!_firewallDao.setStateToAdd(newRule)) {
|
||||
@ -313,7 +312,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
|
||||
if (newRule != null) {
|
||||
txn.start();
|
||||
//no need to apply the rule as it wasn't programmed on the backend yet
|
||||
// no need to apply the rule as it wasn't programmed on the backend yet
|
||||
_firewallMgr.revokeRelatedFirewallRule(newRule.getId(), false);
|
||||
_portForwardingDao.remove(newRule.getId());
|
||||
txn.commit();
|
||||
@ -371,7 +370,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
ipAddress.setAssociatedWithVmId(vmId);
|
||||
|
||||
if (_ipAddressDao.update(ipAddress.getId(), ipAddress)) {
|
||||
//enable static nat on the backend
|
||||
// enable static nat on the backend
|
||||
s_logger.trace("Enabling static nat for ip address " + ipAddress + " and vm id=" + vmId + " on the backend");
|
||||
if (applyStaticNatForIp(ipId, false, caller, false)) {
|
||||
return true;
|
||||
@ -410,7 +409,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
IPAddressVO oldIP = _ipAddressDao.findByAssociatedVmId(vmId);
|
||||
|
||||
if (oldIP != null) {
|
||||
//If elasticIP functionality is supported in the network, we always have to disable static nat on the old ip in order to re-enable it on the new one
|
||||
// If elasticIP functionality is supported in the network, we always have to disable static nat on the old
|
||||
// ip in order to re-enable it on the new one
|
||||
Long networkId = oldIP.getAssociatedWithNetworkId();
|
||||
boolean reassignStaticNat = false;
|
||||
if (networkId != null) {
|
||||
@ -425,7 +425,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
if (!reassignStaticNat) {
|
||||
throw new InvalidParameterValueException("Failed to enable static nat for the ip address id=" + ipAddress.getId() + " as vm id=" + vmId + " is already associated with ip id=" + oldIP.getId());
|
||||
}
|
||||
//unassign old static nat rule
|
||||
// unassign old static nat rule
|
||||
s_logger.debug("Disassociating static nat for ip " + oldIP);
|
||||
if (!disableStaticNat(oldIP.getId(), caller, callerUserId, true)) {
|
||||
throw new CloudRuntimeException("Failed to disable old static nat rule for vm id=" + vmId + " and ip " + oldIP);
|
||||
@ -433,7 +433,6 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_NET_RULE_DELETE, eventDescription = "revoking forwarding rule", async = true)
|
||||
public boolean revokePortForwardingRule(long ruleId, boolean apply) {
|
||||
@ -447,7 +446,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
|
||||
_accountMgr.checkAccess(caller, null, true, rule);
|
||||
|
||||
if(!revokePortForwardingRuleInternal(ruleId, caller, ctx.getCallerUserId(), apply)){
|
||||
if (!revokePortForwardingRuleInternal(ruleId, caller, ctx.getCallerUserId(), apply)) {
|
||||
throw new CloudRuntimeException("Failed to delete port forwarding rule");
|
||||
}
|
||||
return true;
|
||||
@ -482,7 +481,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
|
||||
_accountMgr.checkAccess(caller, null, true, rule);
|
||||
|
||||
if(!revokeStaticNatRuleInternal(ruleId, caller, ctx.getCallerUserId(), apply)){
|
||||
if (!revokeStaticNatRuleInternal(ruleId, caller, ctx.getCallerUserId(), apply)) {
|
||||
throw new CloudRuntimeException("Failed to revoke forwarding rule");
|
||||
}
|
||||
return true;
|
||||
@ -625,7 +624,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSourceCidrs(long ruleId){
|
||||
public List<String> getSourceCidrs(long ruleId) {
|
||||
return _firewallCidrsDao.getSourceCidrs(ruleId);
|
||||
}
|
||||
|
||||
@ -638,7 +637,6 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (caller != null) {
|
||||
_accountMgr.checkAccess(caller, null, true, rules.toArray(new PortForwardingRuleVO[rules.size()]));
|
||||
}
|
||||
@ -739,7 +737,6 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean applyStaticNatsForNetwork(long networkId, boolean continueOnError, Account caller) {
|
||||
List<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(networkId);
|
||||
@ -799,7 +796,6 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
sb.and("purpose", sb.entity().getPurpose(), Op.EQ);
|
||||
sb.and("id", sb.entity().getId(), Op.EQ);
|
||||
|
||||
|
||||
if (vmId != null) {
|
||||
SearchBuilder<IPAddressVO> ipSearch = _ipAddressDao.createSearchBuilder();
|
||||
ipSearch.and("associatedWithVmId", ipSearch.entity().getAssociatedWithVmId(), Op.EQ);
|
||||
@ -828,7 +824,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_NET_RULE_ADD, eventDescription = "applying port forwarding rule", async = true)
|
||||
public boolean applyPortForwardingRules(long ipId, Account caller) throws ResourceUnavailableException {
|
||||
if(!applyPortForwardingRules(ipId, false, caller)){
|
||||
if (!applyPortForwardingRules(ipId, false, caller)) {
|
||||
throw new CloudRuntimeException("Failed to apply port forwarding rule");
|
||||
}
|
||||
return true;
|
||||
@ -837,7 +833,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_NET_RULE_ADD, eventDescription = "applying static nat rule", async = true)
|
||||
public boolean applyStaticNatRules(long ipId, Account caller) throws ResourceUnavailableException {
|
||||
if(!applyStaticNatRules(ipId, false, caller)){
|
||||
if (!applyStaticNatRules(ipId, false, caller)) {
|
||||
throw new CloudRuntimeException("Failed to apply static nat rule");
|
||||
}
|
||||
return true;
|
||||
@ -862,13 +858,12 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
s_logger.debug("Releasing " + staticNatRules.size() + " static nat rules for ip id=" + ipId);
|
||||
}
|
||||
|
||||
|
||||
for (FirewallRuleVO rule : staticNatRules) {
|
||||
// Mark all static nat rules as Revoke, but don't revoke them yet
|
||||
revokeStaticNatRuleInternal(rule.getId(), caller, userId, false);
|
||||
}
|
||||
|
||||
//revoke static nat for the ip address
|
||||
// revoke static nat for the ip address
|
||||
boolean success = applyStaticNatForIp(ipId, false, caller, true);
|
||||
|
||||
// revoke all port forwarding rules
|
||||
@ -1025,7 +1020,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disableStaticNat(long ipId) throws ResourceUnavailableException, NetworkRuleConflictException, InsufficientAddressCapacityException{
|
||||
public boolean disableStaticNat(long ipId) throws ResourceUnavailableException, NetworkRuleConflictException, InsufficientAddressCapacityException {
|
||||
UserContext ctx = UserContext.current();
|
||||
Account caller = ctx.getCaller();
|
||||
IPAddressVO ipAddress = _ipAddressDao.findById(ipId);
|
||||
@ -1040,8 +1035,9 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
throw new InvalidParameterValueException("IP address " + ipAddress + " is not associated with any vm Id");
|
||||
}
|
||||
|
||||
//if network has elastic IP functionality supported, we first have to disable static nat on old ip in order to re-enable it on the new one
|
||||
//enable static nat takes care of that
|
||||
// if network has elastic IP functionality supported, we first have to disable static nat on old ip in order to
|
||||
// re-enable it on the new one
|
||||
// enable static nat takes care of that
|
||||
Network guestNetwork = _networkMgr.getNetwork(ipAddress.getAssociatedWithNetworkId());
|
||||
NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId());
|
||||
if (offering.getElasticIp()) {
|
||||
@ -1052,7 +1048,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@Override
|
||||
@DB
|
||||
public boolean disableStaticNat(long ipId, Account caller, long callerUserId, boolean releaseIpIfElastic) throws ResourceUnavailableException {
|
||||
boolean success = true;
|
||||
|
||||
@ -1063,7 +1060,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
throw new InvalidParameterValueException("One to one nat is not enabled for the ip id=" + ipId);
|
||||
}
|
||||
|
||||
//Revoke all firewall rules for the ip
|
||||
// Revoke all firewall rules for the ip
|
||||
try {
|
||||
s_logger.debug("Revoking all " + Purpose.Firewall + "rules as a part of disabling static nat for public IP id=" + ipId);
|
||||
if (!_firewallMgr.revokeFirewallRulesForIp(ipId, callerUserId, caller)) {
|
||||
@ -1152,7 +1149,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
_accountMgr.checkAccess(caller, null, true, sourceIp);
|
||||
}
|
||||
|
||||
//create new static nat rule
|
||||
// create new static nat rule
|
||||
// Get nic IP4 address
|
||||
|
||||
String dstIp;
|
||||
@ -1177,19 +1174,18 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void enableElasticIpAndStaticNatForVm(UserVm vm, boolean getNewIp) throws InsufficientAddressCapacityException{
|
||||
public void enableElasticIpAndStaticNatForVm(UserVm vm, boolean getNewIp) throws InsufficientAddressCapacityException {
|
||||
boolean success = true;
|
||||
|
||||
//enable static nat if eIp capability is supported
|
||||
// enable static nat if eIp capability is supported
|
||||
List<? extends Nic> nics = _nicDao.listByVmId(vm.getId());
|
||||
for (Nic nic : nics) {
|
||||
Network guestNetwork = _networkMgr.getNetwork(nic.getNetworkId());
|
||||
NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId());
|
||||
if (offering.getElasticIp()) {
|
||||
|
||||
//check if there is already static nat enabled
|
||||
// check if there is already static nat enabled
|
||||
if (_ipAddressDao.findByAssociatedVmId(vm.getId()) != null && !getNewIp) {
|
||||
s_logger.debug("Vm " + vm + " already has elastic ip associated with it in guest network " + guestNetwork);
|
||||
continue;
|
||||
|
||||
@ -36,91 +36,91 @@ import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
@Entity
|
||||
@Table(name="network_offerings")
|
||||
@Table(name = "network_offerings")
|
||||
public class NetworkOfferingVO implements NetworkOffering, Identity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
long id;
|
||||
|
||||
@Column(name="name")
|
||||
@Column(name = "name")
|
||||
String name;
|
||||
|
||||
@Column(name="unique_name")
|
||||
@Column(name = "unique_name")
|
||||
private String uniqueName;
|
||||
|
||||
@Column(name="display_text")
|
||||
@Column(name = "display_text")
|
||||
String displayText;
|
||||
|
||||
@Column(name="nw_rate")
|
||||
@Column(name = "nw_rate")
|
||||
Integer rateMbps;
|
||||
|
||||
@Column(name="mc_rate")
|
||||
@Column(name = "mc_rate")
|
||||
Integer multicastRateMbps;
|
||||
|
||||
@Column(name="traffic_type")
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
@Column(name = "traffic_type")
|
||||
@Enumerated(value = EnumType.STRING)
|
||||
TrafficType trafficType;
|
||||
|
||||
@Column(name="specify_vlan")
|
||||
@Column(name = "specify_vlan")
|
||||
boolean specifyVlan;
|
||||
|
||||
@Column(name="system_only")
|
||||
@Column(name = "system_only")
|
||||
boolean systemOnly;
|
||||
|
||||
@Column(name="service_offering_id")
|
||||
@Column(name = "service_offering_id")
|
||||
Long serviceOfferingId;
|
||||
|
||||
@Column(name="tags", length=4096)
|
||||
@Column(name = "tags", length = 4096)
|
||||
String tags;
|
||||
|
||||
@Column(name="default")
|
||||
@Column(name = "default")
|
||||
boolean isDefault;
|
||||
|
||||
@Column(name="availability")
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
@Column(name = "availability")
|
||||
@Enumerated(value = EnumType.STRING)
|
||||
Availability availability;
|
||||
|
||||
@Column(name="state")
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
@Column(name = "state")
|
||||
@Enumerated(value = EnumType.STRING)
|
||||
State state = State.Disabled;
|
||||
|
||||
@Column(name=GenericDao.REMOVED_COLUMN)
|
||||
@Column(name = GenericDao.REMOVED_COLUMN)
|
||||
Date removed;
|
||||
|
||||
@Column(name=GenericDao.CREATED_COLUMN)
|
||||
@Column(name = GenericDao.CREATED_COLUMN)
|
||||
Date created;
|
||||
|
||||
@Column(name="guest_type")
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
@Column(name = "guest_type")
|
||||
@Enumerated(value = EnumType.STRING)
|
||||
Network.GuestType guestType;
|
||||
|
||||
@Column(name="dedicated_lb_service")
|
||||
@Column(name = "dedicated_lb_service")
|
||||
boolean dedicatedLB;
|
||||
|
||||
@Column(name="shared_source_nat_service")
|
||||
@Column(name = "shared_source_nat_service")
|
||||
boolean sharedSourceNat;
|
||||
|
||||
@Column(name="specify_ip_ranges")
|
||||
@Column(name = "specify_ip_ranges")
|
||||
boolean specifyIpRanges = false;
|
||||
|
||||
@Column(name="sort_key")
|
||||
@Column(name = "sort_key")
|
||||
int sortKey;
|
||||
|
||||
@Column(name="uuid")
|
||||
@Column(name = "uuid")
|
||||
String uuid;
|
||||
|
||||
@Column(name="redundant_router_service")
|
||||
@Column(name = "redundant_router_service")
|
||||
boolean redundantRouter;
|
||||
|
||||
@Column(name="conserve_mode")
|
||||
@Column(name = "conserve_mode")
|
||||
boolean conserveMode;
|
||||
|
||||
@Column(name="elastic_ip_service")
|
||||
@Column(name = "elastic_ip_service")
|
||||
boolean elasticIp;
|
||||
|
||||
@Column(name="elastic_lb_service")
|
||||
@Column(name = "elastic_lb_service")
|
||||
boolean elasticLb;
|
||||
|
||||
@Override
|
||||
@ -287,7 +287,8 @@ public class NetworkOfferingVO implements NetworkOffering, Identity {
|
||||
}
|
||||
|
||||
public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, boolean isDefault,
|
||||
Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean dedicatedLb, boolean sharedSourceNat, boolean redundantRouter, boolean elasticIp, boolean elasticLb, boolean specifyIpRanges) {
|
||||
Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean dedicatedLb, boolean sharedSourceNat, boolean redundantRouter, boolean elasticIp, boolean elasticLb,
|
||||
boolean specifyIpRanges) {
|
||||
this(name, displayText, trafficType, systemOnly, specifyVlan, rateMbps, multicastRateMbps, isDefault, availability, tags, guestType, conserveMode, specifyIpRanges);
|
||||
this.dedicatedLB = dedicatedLb;
|
||||
this.sharedSourceNat = sharedSourceNat;
|
||||
@ -301,9 +302,11 @@ public class NetworkOfferingVO implements NetworkOffering, Identity {
|
||||
|
||||
/**
|
||||
* Network Offering for all system vms.
|
||||
*
|
||||
* @param name
|
||||
* @param trafficType
|
||||
* @param specifyIpRanges TODO
|
||||
* @param specifyIpRanges
|
||||
* TODO
|
||||
*/
|
||||
public NetworkOfferingVO(String name, TrafficType trafficType, boolean specifyIpRanges) {
|
||||
this(name, "System Offering for " + name, trafficType, true, false, 0, 0, true, Availability.Required, null, null, true, specifyIpRanges);
|
||||
@ -356,4 +359,5 @@ public class NetworkOfferingVO implements NetworkOffering, Identity {
|
||||
public boolean getSpecifyIpRanges() {
|
||||
return specifyIpRanges;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -38,7 +38,9 @@ import com.cloud.utils.db.GenericDao;
|
||||
public interface NetworkOfferingDao extends GenericDao<NetworkOfferingVO, Long> {
|
||||
/**
|
||||
* Returns the network offering that matches the name.
|
||||
* @param uniqueName name
|
||||
*
|
||||
* @param uniqueName
|
||||
* name
|
||||
* @return NetworkOfferingVO
|
||||
*/
|
||||
NetworkOfferingVO findByUniqueName(String uniqueName);
|
||||
@ -48,7 +50,8 @@ public interface NetworkOfferingDao extends GenericDao<NetworkOfferingVO, Long>
|
||||
* is already there, then it returns the correct one in the database.
|
||||
* If not, then it persists it into the database.
|
||||
*
|
||||
* @param offering network offering to persist if not in the database.
|
||||
* @param offering
|
||||
* network offering to persist if not in the database.
|
||||
* @return NetworkOfferingVO backed by a row in the database
|
||||
*/
|
||||
NetworkOfferingVO persistDefaultNetworkOffering(NetworkOfferingVO offering);
|
||||
|
||||
@ -21,7 +21,6 @@
|
||||
*/
|
||||
package com.cloud.offerings.dao;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
@ -40,7 +39,8 @@ import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@Local(value=NetworkOfferingDao.class) @DB(txn=false)
|
||||
@Local(value = NetworkOfferingDao.class)
|
||||
@DB(txn = false)
|
||||
public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Long> implements NetworkOfferingDao {
|
||||
final SearchBuilder<NetworkOfferingVO> NameSearch;
|
||||
final SearchBuilder<NetworkOfferingVO> SystemOfferingSearch;
|
||||
@ -123,8 +123,9 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
|
||||
return listBy(sc, null);
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
public boolean remove(Long networkOfferingId){
|
||||
@Override
|
||||
@DB
|
||||
public boolean remove(Long networkOfferingId) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
NetworkOfferingVO offering = findById(networkOfferingId);
|
||||
@ -138,16 +139,16 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
|
||||
@Override
|
||||
public List<Long> getOfferingIdsToUpgradeFrom(NetworkOffering originalOffering) {
|
||||
SearchCriteria<Long> sc = UpgradeSearch.create();
|
||||
//exclude original offering
|
||||
// exclude original offering
|
||||
sc.addAnd("id", SearchCriteria.Op.NEQ, originalOffering.getId());
|
||||
|
||||
//list only non-system offerings
|
||||
// list only non-system offerings
|
||||
sc.addAnd("systemOnly", SearchCriteria.Op.EQ, false);
|
||||
|
||||
//Type of the network should be the same
|
||||
// Type of the network should be the same
|
||||
sc.addAnd("guestType", SearchCriteria.Op.EQ, originalOffering.getGuestType());
|
||||
|
||||
//Traffic types should be the same
|
||||
// Traffic types should be the same
|
||||
sc.addAnd("trafficType", SearchCriteria.Op.EQ, originalOffering.getTrafficType());
|
||||
|
||||
sc.addAnd("state", SearchCriteria.Op.EQ, NetworkOffering.State.Enabled);
|
||||
@ -163,4 +164,5 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
|
||||
sc.setParameters("state", state);
|
||||
return listBy(sc, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -79,8 +79,8 @@ import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
import edu.emory.mathcs.backport.java.util.Arrays;
|
||||
|
||||
@Local(value = { ResourceLimitService.class})
|
||||
public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
@Local(value = { ResourceLimitService.class })
|
||||
public class ResourceLimitManagerImpl implements ResourceLimitService, Manager {
|
||||
public static final Logger s_logger = Logger.getLogger(ResourceLimitManagerImpl.class);
|
||||
|
||||
private String _name;
|
||||
@ -117,10 +117,9 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
@Inject
|
||||
private ProjectAccountDao _projectAccountDao;
|
||||
|
||||
|
||||
protected SearchBuilder<ResourceCountVO> ResourceCountSearch;
|
||||
ScheduledExecutorService _rcExecutor;
|
||||
long _resourceCountCheckInterval=0;
|
||||
long _resourceCountCheckInterval = 0;
|
||||
Map<ResourceType, Long> accountResourceLimitMap = new EnumMap<ResourceType, Long>(ResourceType.class);
|
||||
Map<ResourceType, Long> projectResourceLimitMap = new EnumMap<ResourceType, Long>(ResourceType.class);
|
||||
|
||||
@ -131,7 +130,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
if (_resourceCountCheckInterval > 0){
|
||||
if (_resourceCountCheckInterval > 0) {
|
||||
_rcExecutor.scheduleAtFixedRate(new ResourceCountCheckTask(), _resourceCountCheckInterval, _resourceCountCheckInterval, TimeUnit.SECONDS);
|
||||
}
|
||||
return true;
|
||||
@ -153,7 +152,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
ResourceCountSearch.done();
|
||||
|
||||
_resourceCountCheckInterval = NumbersUtil.parseInt(_configDao.getValue(Config.ResourceCountCheckInterval.key()), 0);
|
||||
if (_resourceCountCheckInterval > 0){
|
||||
if (_resourceCountCheckInterval > 0) {
|
||||
_rcExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("ResourceCountChecker"));
|
||||
}
|
||||
|
||||
@ -174,7 +173,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
|
||||
@Override
|
||||
public void incrementResourceCount(long accountId, ResourceType type, Long... delta) {
|
||||
//don't upgrade resource count for system account
|
||||
// don't upgrade resource count for system account
|
||||
if (accountId == Account.ACCOUNT_ID_SYSTEM) {
|
||||
s_logger.trace("Not incrementing resource count for system accounts, returning");
|
||||
return;
|
||||
@ -182,14 +181,14 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
long numToIncrement = (delta.length == 0) ? 1 : delta[0].longValue();
|
||||
|
||||
if (!updateResourceCountForAccount(accountId, type, true, numToIncrement)) {
|
||||
//we should fail the operation (resource creation) when failed to update the resource count
|
||||
// we should fail the operation (resource creation) when failed to update the resource count
|
||||
throw new CloudRuntimeException("Failed to increment resource count of type " + type + " for account id=" + accountId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementResourceCount(long accountId, ResourceType type, Long... delta) {
|
||||
//don't upgrade resource count for system account
|
||||
// don't upgrade resource count for system account
|
||||
if (accountId == Account.ACCOUNT_ID_SYSTEM) {
|
||||
s_logger.trace("Not decrementing resource count for system accounts, returning");
|
||||
return;
|
||||
@ -205,7 +204,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
@Override
|
||||
public long findCorrectResourceLimitForAccount(Account account, ResourceType type) {
|
||||
|
||||
long max = Resource.RESOURCE_UNLIMITED; //if resource limit is not found, then we treat it as unlimited
|
||||
long max = Resource.RESOURCE_UNLIMITED; // if resource limit is not found, then we treat it as unlimited
|
||||
ResourceLimitVO limit = _resourceLimitDao.findByOwnerIdAndType(account.getId(), ResourceOwnerType.Account, type);
|
||||
|
||||
// Check if limit is configured for account
|
||||
@ -219,7 +218,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
} else {
|
||||
value = accountResourceLimitMap.get(type);
|
||||
}
|
||||
if (value != null){
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@ -231,8 +230,8 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
public long findCorrectResourceLimitForDomain(Domain domain, ResourceType type) {
|
||||
long max = Resource.RESOURCE_UNLIMITED;
|
||||
|
||||
//no limits on ROOT domain
|
||||
if(domain.getId() == Domain.ROOT_DOMAIN){
|
||||
// no limits on ROOT domain
|
||||
if (domain.getId() == Domain.ROOT_DOMAIN) {
|
||||
return Resource.RESOURCE_UNLIMITED;
|
||||
}
|
||||
// Check account
|
||||
@ -245,7 +244,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
Long domainId = domain.getParent();
|
||||
while ((domainId != null) && (limit == null)) {
|
||||
|
||||
if(domainId == Domain.ROOT_DOMAIN){
|
||||
if (domainId == Domain.ROOT_DOMAIN) {
|
||||
return Resource.RESOURCE_UNLIMITED;
|
||||
}
|
||||
limit = _resourceLimitDao.findByOwnerIdAndType(domainId, ResourceOwnerType.Domain, type);
|
||||
@ -261,8 +260,9 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
public void checkResourceLimit(Account account, ResourceType type, long... count) throws ResourceAllocationException{
|
||||
@Override
|
||||
@DB
|
||||
public void checkResourceLimit(Account account, ResourceType type, long... count) throws ResourceAllocationException {
|
||||
long numResources = ((count.length == 0) ? 1 : count[0]);
|
||||
Project project = null;
|
||||
|
||||
@ -278,7 +278,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
try {
|
||||
//Lock all rows first so nobody else can read it
|
||||
// Lock all rows first so nobody else can read it
|
||||
Set<Long> rowIdsToLock = _resourceCountDao.listAllRowsToUpdate(account.getId(), ResourceOwnerType.Account, type);
|
||||
SearchCriteria<ResourceCountVO> sc = ResourceCountSearch.create();
|
||||
sc.setParameters("id", rowIdsToLock.toArray());
|
||||
@ -307,8 +307,8 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
|
||||
while (domainId != null) {
|
||||
DomainVO domain = _domainDao.findById(domainId);
|
||||
//no limit check if it is ROOT domain
|
||||
if(domainId != Domain.ROOT_DOMAIN){
|
||||
// no limit check if it is ROOT domain
|
||||
if (domainId != Domain.ROOT_DOMAIN) {
|
||||
ResourceLimitVO domainLimit = _resourceLimitDao.findByOwnerIdAndType(domainId, ResourceOwnerType.Domain, type);
|
||||
if (domainLimit != null && domainLimit.getMax().longValue() != Resource.RESOURCE_UNLIMITED) {
|
||||
long domainCount = _resourceCountDao.getResourceCount(domainId, ResourceOwnerType.Domain, type);
|
||||
@ -335,20 +335,20 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
domainId = null;
|
||||
} else {
|
||||
if (domainId != null) {
|
||||
//verify domain information and permissions
|
||||
// verify domain information and permissions
|
||||
Domain domain = _domainDao.findById(domainId);
|
||||
if (domain == null) {
|
||||
//return empty set
|
||||
// return empty set
|
||||
return limits;
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, domain);
|
||||
|
||||
if (accountId != null) {
|
||||
//Verify account information and permissions
|
||||
// Verify account information and permissions
|
||||
Account account = _accountDao.findById(accountId);
|
||||
if (account == null) {
|
||||
//return empty set
|
||||
// return empty set
|
||||
return limits;
|
||||
}
|
||||
|
||||
@ -368,7 +368,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
}
|
||||
}
|
||||
|
||||
//If id is passed in, get the record and return it if permission check has passed
|
||||
// If id is passed in, get the record and return it if permission check has passed
|
||||
if (id != null) {
|
||||
ResourceLimitVO vo = _resourceLimitDao.findById(id);
|
||||
if (vo.getAccountId() != null) {
|
||||
@ -382,7 +382,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
return limits;
|
||||
}
|
||||
|
||||
//If account is not specified, default it to caller account
|
||||
// If account is not specified, default it to caller account
|
||||
if (accountId == null) {
|
||||
if (domainId == null) {
|
||||
accountId = caller.getId();
|
||||
@ -408,7 +408,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
|
||||
if (domainId != null) {
|
||||
sc.setParameters("domainId", domainId);
|
||||
sc.setParameters("accountId", (Object[])null);
|
||||
sc.setParameters("accountId", (Object[]) null);
|
||||
}
|
||||
|
||||
if (resourceType != null) {
|
||||
@ -430,7 +430,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
} else {
|
||||
limits.addAll(foundLimits);
|
||||
|
||||
//see if any limits are missing from the table, and if yes - get it from the config table and add
|
||||
// see if any limits are missing from the table, and if yes - get it from the config table and add
|
||||
ResourceType[] resourceTypes = ResourceCount.ResourceType.values();
|
||||
if (foundLimits.size() != resourceTypes.length) {
|
||||
List<String> accountLimitStr = new ArrayList<String>();
|
||||
@ -443,7 +443,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
}
|
||||
}
|
||||
|
||||
//get default from config values
|
||||
// get default from config values
|
||||
if (isAccount) {
|
||||
if (accountLimitStr.size() < resourceTypes.length) {
|
||||
for (ResourceType rt : resourceTypes) {
|
||||
@ -518,7 +518,6 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
throw new PermissionDeniedException("Cannot update resource limit for ROOT domain " + domainId + ", permission denied");
|
||||
}
|
||||
|
||||
|
||||
if ((caller.getDomainId() == domainId.longValue()) && caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
|
||||
// if the admin is trying to update their own domain, disallow...
|
||||
throw new PermissionDeniedException("Unable to update resource limit for domain " + domainId + ", permission denied");
|
||||
@ -551,9 +550,9 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceCountVO> recalculateResourceCount(Long accountId, Long domainId, Integer typeId) throws InvalidParameterValueException, CloudRuntimeException, PermissionDeniedException{
|
||||
public List<ResourceCountVO> recalculateResourceCount(Long accountId, Long domainId, Integer typeId) throws InvalidParameterValueException, CloudRuntimeException, PermissionDeniedException {
|
||||
Account callerAccount = UserContext.current().getCaller();
|
||||
long count=0;
|
||||
long count = 0;
|
||||
List<ResourceCountVO> counts = new ArrayList<ResourceCountVO>();
|
||||
List<ResourceType> resourceTypes = new ArrayList<ResourceType>();
|
||||
|
||||
@ -609,7 +608,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
|
||||
Set<Long> rowsToLock = _resourceCountDao.listAllRowsToUpdate(accountId, ResourceOwnerType.Account, type);
|
||||
|
||||
//Lock rows first
|
||||
// Lock rows first
|
||||
SearchCriteria<ResourceCountVO> sc = ResourceCountSearch.create();
|
||||
sc.setParameters("id", rowsToLock.toArray());
|
||||
List<ResourceCountVO> rowsToUpdate = _resourceCountDao.lockRows(sc, null, true);
|
||||
@ -631,13 +630,13 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
|
||||
@DB
|
||||
protected long recalculateDomainResourceCount(long domainId, ResourceType type) {
|
||||
long newCount=0;
|
||||
long newCount = 0;
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
try {
|
||||
//Lock all rows first so nobody else can read it
|
||||
// Lock all rows first so nobody else can read it
|
||||
Set<Long> rowIdsToLock = _resourceCountDao.listAllRowsToUpdate(domainId, ResourceOwnerType.Domain, type);
|
||||
SearchCriteria<ResourceCountVO> sc = ResourceCountSearch.create();
|
||||
sc.setParameters("id", rowIdsToLock.toArray());
|
||||
@ -650,7 +649,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
// for each child domain update the resource count
|
||||
if (type.supportsOwner(ResourceOwnerType.Domain)) {
|
||||
|
||||
//calculate project count here
|
||||
// calculate project count here
|
||||
if (type == ResourceType.project) {
|
||||
newCount = newCount + _projectDao.countProjectsForDomain(domainId);
|
||||
}
|
||||
@ -672,7 +671,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
|
||||
if (oldCount != newCount) {
|
||||
s_logger.info("Discrepency in the resource count " + "(original count=" + oldCount + " correct count = " +
|
||||
newCount + ") for type " + type + " for domain ID " + domainId + " is fixed during resource count recalculation." );
|
||||
newCount + ") for type " + type + " for domain ID " + domainId + " is fixed during resource count recalculation.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new CloudRuntimeException("Failed to update resource count for domain with Id " + domainId);
|
||||
@ -685,7 +684,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
|
||||
@DB
|
||||
protected long recalculateAccountResourceCount(long accountId, ResourceType type) {
|
||||
Long newCount=null;
|
||||
Long newCount = null;
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
@ -720,7 +719,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
|
||||
if (oldCount != newCount) {
|
||||
s_logger.info("Discrepency in the resource count " + "(original count=" + oldCount + " correct count = " +
|
||||
newCount + ") for type " + type + " for account ID " + accountId + " is fixed during resource count recalculation." );
|
||||
newCount + ") for type " + type + " for account ID " + accountId + " is fixed during resource count recalculation.");
|
||||
}
|
||||
txn.commit();
|
||||
|
||||
@ -744,7 +743,7 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
|
||||
// recalculateDomainResourceCount will take care of re-calculation of resource counts for sub-domains
|
||||
// and accounts of the sub-domains also. so just loop through immediate children of root domain
|
||||
for (Domain domain : domains ) {
|
||||
for (Domain domain : domains) {
|
||||
for (ResourceType type : ResourceCount.ResourceType.values()) {
|
||||
if (type.supportsOwner(ResourceOwnerType.Domain)) {
|
||||
recalculateDomainResourceCount(domain.getId(), type);
|
||||
|
||||
@ -29,7 +29,9 @@ public interface ConfigurationServer {
|
||||
|
||||
/**
|
||||
* Persists default values for the configuration table, pods/zones, and VLANs
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public void persistDefaultValues() throws InternalErrorException;
|
||||
|
||||
}
|
||||
|
||||
@ -143,7 +143,8 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
_identityDao = locator.getDao(IdentityDao.class);
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@Override
|
||||
@DB
|
||||
public void persistDefaultValues() throws InternalErrorException {
|
||||
|
||||
// Create system user and admin user
|
||||
@ -170,7 +171,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
for (Config c : configs) {
|
||||
String name = c.key();
|
||||
|
||||
//if the config value already present in the db, don't insert it again
|
||||
// if the config value already present in the db, don't insert it again
|
||||
if (_configDao.findByName(name) != null) {
|
||||
continue;
|
||||
}
|
||||
@ -194,7 +195,6 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
_configDao.update("secstorage.secure.copy.cert", "realhostip");
|
||||
s_logger.debug("ConfigurationServer made secondary storage copy use realhostip.");
|
||||
|
||||
|
||||
// Save default service offerings
|
||||
createServiceOffering(User.UID_SYSTEM, "Small Instance", 1, 512, 500, "Small Instance", false, false, null);
|
||||
createServiceOffering(User.UID_SYSTEM, "Medium Instance", 1, 1024, 1000, "Medium Instance", false, false, null);
|
||||
@ -221,16 +221,15 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
// generate a single sign-on key
|
||||
updateSSOKey();
|
||||
|
||||
//Create default network offerings
|
||||
// Create default network offerings
|
||||
createDefaultNetworkOfferings();
|
||||
|
||||
//Create default networks
|
||||
// Create default networks
|
||||
createDefaultNetworks();
|
||||
|
||||
//Create userIpAddress ranges
|
||||
// Create userIpAddress ranges
|
||||
|
||||
|
||||
//Update existing vlans with networkId
|
||||
// Update existing vlans with networkId
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
|
||||
List<VlanVO> vlans = _vlanDao.listAll();
|
||||
@ -240,7 +239,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
updateVlanWithNetworkId(vlan);
|
||||
}
|
||||
|
||||
//Create vlan user_ip_address range
|
||||
// Create vlan user_ip_address range
|
||||
String ipPange = vlan.getIpRange();
|
||||
String[] range = ipPange.split("-");
|
||||
String startIp = range[0];
|
||||
@ -255,7 +254,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
}
|
||||
}
|
||||
}
|
||||
//Update resource count if needed
|
||||
// Update resource count if needed
|
||||
updateResourceCount();
|
||||
|
||||
// keystore for SSL/TLS connection
|
||||
@ -272,7 +271,6 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
|
||||
updateUuids();
|
||||
|
||||
|
||||
// Set init to true
|
||||
_configDao.update("init", "Hidden", "true");
|
||||
}
|
||||
@ -320,7 +318,6 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@DB
|
||||
protected void saveUser() {
|
||||
// insert system account
|
||||
@ -377,7 +374,6 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
insertSql = "INSERT INTO `cloud`.`user` (id, username, password, account_id, firstname, lastname, created) " +
|
||||
"VALUES (" + id + ",'" + username + "','" + sb.toString() + "', 2, '" + firstname + "','" + lastname + "',now())";
|
||||
|
||||
|
||||
txn = Transaction.currentTxn();
|
||||
try {
|
||||
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
|
||||
@ -385,8 +381,6 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
try {
|
||||
String tableName = "security_group";
|
||||
try {
|
||||
@ -402,12 +396,12 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
if (!rs.next()) {
|
||||
//save default security group
|
||||
// save default security group
|
||||
if (tableName.equals("security_group")) {
|
||||
insertSql = "INSERT INTO " + tableName +" (name, description, account_id, domain_id) " +
|
||||
insertSql = "INSERT INTO " + tableName + " (name, description, account_id, domain_id) " +
|
||||
"VALUES ('default', 'Default Security Group', 2, 1)";
|
||||
} else {
|
||||
insertSql = "INSERT INTO " + tableName +" (name, description, account_id, domain_id, account_name) " +
|
||||
insertSql = "INSERT INTO " + tableName + " (name, description, account_id, domain_id, account_name) " +
|
||||
"VALUES ('default', 'Default Security Group', 2, 1, 'admin')";
|
||||
}
|
||||
|
||||
@ -430,7 +424,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
String currentCloudIdentifier = _configDao.getValue("cloud.identifier");
|
||||
if (currentCloudIdentifier == null || currentCloudIdentifier.isEmpty()) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
_configDao.update(Config.CloudIdentifier.key(),Config.CloudIdentifier.getCategory(), uuid);
|
||||
_configDao.update(Config.CloudIdentifier.key(), Config.CloudIdentifier.getCategory(), uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -477,7 +471,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
|
||||
String o = ou;
|
||||
String c = "Unknown";
|
||||
String dname = "cn=\"" + cn + "\",ou=\"" + ou +"\",o=\"" + o + "\",c=\"" + c + "\"";
|
||||
String dname = "cn=\"" + cn + "\",ou=\"" + ou + "\",o=\"" + o + "\",c=\"" + c + "\"";
|
||||
Script script = new Script(true, "keytool", 5000, null);
|
||||
script.add("-genkey");
|
||||
script.add("-keystore", keystorePath);
|
||||
@ -498,7 +492,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
}
|
||||
|
||||
String dbString = _configDao.getValue("ssl.keystore");
|
||||
File confFile= PropertiesUtil.findConfigFile("db.properties");
|
||||
File confFile = PropertiesUtil.findConfigFile("db.properties");
|
||||
/* This line may throw a NPE, but that's due to fail to find db.properities, meant some bugs in the other places */
|
||||
String confPath = confFile.getParent();
|
||||
String keystorePath = confPath + "/cloud.keystore";
|
||||
@ -553,7 +547,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
// Grab the SSH key pair and insert it into the database, if it is not present
|
||||
|
||||
String userid = System.getProperty("user.name");
|
||||
if (!userid.startsWith("cloud")){
|
||||
if (!userid.startsWith("cloud")) {
|
||||
return;
|
||||
}
|
||||
String already = _configDao.getValue("ssh.privatekey");
|
||||
@ -573,7 +567,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Systemvm keypairs not found in database. Need to store them in the database");
|
||||
}
|
||||
//FIXME: take a global database lock here for safety.
|
||||
// FIXME: take a global database lock here for safety.
|
||||
Script.runSimpleBashScript("if [ -f ~/.ssh/id_rsa ] ; then rm -f ~/.ssh/id_rsa ; fi; ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa -q");
|
||||
|
||||
byte[] arr1 = new byte[4094]; // configuration table column value size
|
||||
@ -581,7 +575,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
new DataInputStream(new FileInputStream(privkeyfile)).readFully(arr1);
|
||||
} catch (EOFException e) {
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Cannot read the private key file",e);
|
||||
s_logger.error("Cannot read the private key file", e);
|
||||
throw new CloudRuntimeException("Cannot read the private key file");
|
||||
}
|
||||
String privateKey = new String(arr1).trim();
|
||||
@ -590,15 +584,15 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
new DataInputStream(new FileInputStream(pubkeyfile)).readFully(arr2);
|
||||
} catch (EOFException e) {
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Cannot read the public key file",e);
|
||||
s_logger.warn("Cannot read the public key file", e);
|
||||
throw new CloudRuntimeException("Cannot read the public key file");
|
||||
}
|
||||
String publicKey = new String(arr2).trim();
|
||||
|
||||
String insertSql1 = "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " +
|
||||
"VALUES ('Hidden','DEFAULT', 'management-server','ssh.privatekey', '"+DBEncryptionUtil.encrypt(privateKey)+"','Private key for the entire CloudStack')";
|
||||
"VALUES ('Hidden','DEFAULT', 'management-server','ssh.privatekey', '" + DBEncryptionUtil.encrypt(privateKey) + "','Private key for the entire CloudStack')";
|
||||
String insertSql2 = "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " +
|
||||
"VALUES ('Hidden','DEFAULT', 'management-server','ssh.publickey', '"+DBEncryptionUtil.encrypt(publicKey)+"','Public key for the entire CloudStack')";
|
||||
"VALUES ('Hidden','DEFAULT', 'management-server','ssh.publickey', '" + DBEncryptionUtil.encrypt(publicKey) + "','Public key for the entire CloudStack')";
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try {
|
||||
@ -608,7 +602,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
s_logger.debug("Private key inserted into database");
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
s_logger.error("SQL of the private key failed",ex);
|
||||
s_logger.error("SQL of the private key failed", ex);
|
||||
throw new CloudRuntimeException("SQL of the private key failed");
|
||||
}
|
||||
|
||||
@ -619,7 +613,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
s_logger.debug("Public key inserted into database");
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
s_logger.error("SQL of the public key failed",ex);
|
||||
s_logger.error("SQL of the public key failed", ex);
|
||||
throw new CloudRuntimeException("SQL of the public key failed");
|
||||
}
|
||||
|
||||
@ -638,7 +632,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
|
||||
private void writeKeyToDisk(String key, String keyPath) {
|
||||
Script.runSimpleBashScript("mkdir -p ~/.ssh");
|
||||
File keyfile = new File( keyPath);
|
||||
File keyfile = new File(keyPath);
|
||||
if (!keyfile.exists()) {
|
||||
try {
|
||||
keyfile.createNewFile();
|
||||
@ -664,7 +658,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
|
||||
}
|
||||
|
||||
private void updateKeyPairsOnDisk(String homeDir ) {
|
||||
private void updateKeyPairsOnDisk(String homeDir) {
|
||||
|
||||
String pubKey = _configDao.getValue("ssh.publickey");
|
||||
String prvKey = _configDao.getValue("ssh.privatekey");
|
||||
@ -674,9 +668,9 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
|
||||
protected void injectSshKeysIntoSystemVmIsoPatch(String publicKeyPath, String privKeyPath) {
|
||||
String injectScript = "scripts/vm/systemvm/injectkeys.sh";
|
||||
String scriptPath = Script.findScript("" , injectScript);
|
||||
String scriptPath = Script.findScript("", injectScript);
|
||||
String systemVmIsoPath = Script.findScript("", "vms/systemvm.iso");
|
||||
if ( scriptPath == null ) {
|
||||
if (scriptPath == null) {
|
||||
throw new CloudRuntimeException("Unable to find key inject script " + injectScript);
|
||||
}
|
||||
if (systemVmIsoPath == null) {
|
||||
@ -712,7 +706,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
stmt1.executeUpdate();
|
||||
s_logger.debug("secondary storage vm copy password inserted into database");
|
||||
} catch (SQLException ex) {
|
||||
s_logger.warn("Failed to insert secondary storage vm copy password",ex);
|
||||
s_logger.warn("Failed to insert secondary storage vm copy password", ex);
|
||||
}
|
||||
|
||||
}
|
||||
@ -775,7 +769,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
if (nums > 16 || nums <= 0) {
|
||||
throw new InvalidParameterValueException("The linkLocalIp.nums: " + nums + "is wrong, should be 1~16");
|
||||
}
|
||||
/*local link ip address starts from 169.254.0.2 - 169.254.(nums)*/
|
||||
/* local link ip address starts from 169.254.0.2 - 169.254.(nums) */
|
||||
String[] linkLocalIpRanges = NetUtils.getLinkLocalIPRange(nums);
|
||||
if (linkLocalIpRanges == null) {
|
||||
throw new InvalidParameterValueException("The linkLocalIp.nums: " + nums + "may be wrong, should be 1~16");
|
||||
@ -785,7 +779,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
|
||||
txn.commit();
|
||||
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
txn.rollback();
|
||||
s_logger.error("Unable to create new pod due to " + e.getMessage(), e);
|
||||
throw new InternalErrorException("Failed to create new pod. Please contact Cloud Support.");
|
||||
@ -799,7 +793,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
diskSize = diskSize * 1024 * 1024 * 1024;
|
||||
tags = cleanupTags(tags);
|
||||
|
||||
DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize,tags,false);
|
||||
DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize, tags, false);
|
||||
newDiskOffering.setUniqueName("Cloud.Com-" + name);
|
||||
newDiskOffering = _diskOfferingDao.persistDeafultDiskOffering(newDiskOffering);
|
||||
return newDiskOffering;
|
||||
@ -839,7 +833,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemStorageNetwork, TrafficType.Storage, true);
|
||||
storageNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(storageNetworkOffering);
|
||||
|
||||
//populate providers
|
||||
// populate providers
|
||||
Map<Network.Service, Network.Provider> defaultSharedNetworkOfferingProviders = new HashMap<Network.Service, Network.Provider>();
|
||||
defaultSharedNetworkOfferingProviders.put(Service.Dhcp, Provider.VirtualRouter);
|
||||
defaultSharedNetworkOfferingProviders.put(Service.Dns, Provider.VirtualRouter);
|
||||
@ -873,12 +867,12 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
netscalerServiceProviders.put(Service.StaticNat, Provider.Netscaler);
|
||||
netscalerServiceProviders.put(Service.Lb, Provider.Netscaler);
|
||||
|
||||
|
||||
//The only one diff between 1 and 2 network offerings is that the first one has SG enabled. In Basic zone only first network offering has to be enabled, in Advance zone - the second one
|
||||
// The only one diff between 1 and 2 network offerings is that the first one has SG enabled. In Basic zone only
|
||||
// first network offering has to be enabled, in Advance zone - the second one
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
//Offering #1
|
||||
// Offering #1
|
||||
NetworkOfferingVO deafultSharedSGNetworkOffering = new NetworkOfferingVO(
|
||||
NetworkOffering.DefaultSharedNetworkOfferingWithSGService,
|
||||
"Offering for Shared Security group enabled networks",
|
||||
@ -895,7 +889,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
s_logger.trace("Added service for the network offering: " + offService);
|
||||
}
|
||||
|
||||
//Offering #2
|
||||
// Offering #2
|
||||
NetworkOfferingVO defaultSharedNetworkOffering = new NetworkOfferingVO(
|
||||
NetworkOffering.DefaultSharedNetworkOffering,
|
||||
"Offering for Shared networks",
|
||||
@ -912,7 +906,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
s_logger.trace("Added service for the network offering: " + offService);
|
||||
}
|
||||
|
||||
//Offering #3
|
||||
// Offering #3
|
||||
NetworkOfferingVO defaultIsolatedSourceNatEnabledNetworkOffering = new NetworkOfferingVO(
|
||||
NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService,
|
||||
"Offering for Isolated networks with Source Nat service enabled",
|
||||
@ -923,14 +917,13 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
defaultIsolatedSourceNatEnabledNetworkOffering.setState(NetworkOffering.State.Enabled);
|
||||
defaultIsolatedSourceNatEnabledNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultIsolatedSourceNatEnabledNetworkOffering);
|
||||
|
||||
|
||||
for (Service service : defaultIsolatedSourceNatEnabledNetworkOfferingProviders.keySet()) {
|
||||
NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(defaultIsolatedSourceNatEnabledNetworkOffering.getId(), service, defaultIsolatedSourceNatEnabledNetworkOfferingProviders.get(service));
|
||||
_ntwkOfferingServiceMapDao.persist(offService);
|
||||
s_logger.trace("Added service for the network offering: " + offService);
|
||||
}
|
||||
|
||||
//Offering #4
|
||||
// Offering #4
|
||||
NetworkOfferingVO defaultIsolatedEnabledNetworkOffering = new NetworkOfferingVO(
|
||||
NetworkOffering.DefaultIsolatedNetworkOffering,
|
||||
"Offering for Isolated networks with no Source Nat service",
|
||||
@ -947,7 +940,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
s_logger.trace("Added service for the network offering: " + offService);
|
||||
}
|
||||
|
||||
//Offering #5
|
||||
// Offering #5
|
||||
NetworkOfferingVO defaultNetscalerNetworkOffering = new NetworkOfferingVO(
|
||||
NetworkOffering.DefaultSharedEIPandELBNetworkOffering,
|
||||
"Offering for Shared networks with Elastic IP and Elastic LB capabilities",
|
||||
@ -986,7 +979,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
if (domainId == null) {
|
||||
domainId = 1L;
|
||||
}
|
||||
//Create default networks - system only
|
||||
// Create default networks - system only
|
||||
List<NetworkOfferingVO> ntwkOff = _networkOfferingDao.listSystemNetworkOfferings();
|
||||
|
||||
for (NetworkOfferingVO offering : ntwkOff) {
|
||||
@ -997,7 +990,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
String networkDomain = null;
|
||||
|
||||
BroadcastDomainType broadcastDomainType = null;
|
||||
TrafficType trafficType= offering.getTrafficType();
|
||||
TrafficType trafficType = offering.getTrafficType();
|
||||
|
||||
boolean specifyIpRanges = false;
|
||||
|
||||
@ -1018,7 +1011,8 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
}
|
||||
|
||||
if (broadcastDomainType != null) {
|
||||
NetworkVO network = new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, domainId, accountId, related, null, null, networkDomain, Network.GuestType.Shared, zoneId, null, null, specifyIpRanges);
|
||||
NetworkVO network = new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, domainId, accountId, related, null, null, networkDomain, Network.GuestType.Shared, zoneId, null,
|
||||
null, specifyIpRanges);
|
||||
network.setGuruName(guruNames.get(network.getTrafficType()));
|
||||
network.setDns1(zone.getDns1());
|
||||
network.setDns2(zone.getDns2());
|
||||
@ -1031,7 +1025,6 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateVlanWithNetworkId(VlanVO vlan) {
|
||||
long zoneId = vlan.getDataCenterId();
|
||||
long networkId = 0L;
|
||||
@ -1048,10 +1041,10 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
}
|
||||
|
||||
private long getSystemNetworkIdByZoneAndTrafficType(long zoneId, TrafficType trafficType) {
|
||||
//find system public network offering
|
||||
// find system public network offering
|
||||
Long networkOfferingId = null;
|
||||
List<NetworkOfferingVO> offerings = _networkOfferingDao.listSystemNetworkOfferings();
|
||||
for (NetworkOfferingVO offering: offerings) {
|
||||
for (NetworkOfferingVO offering : offerings) {
|
||||
if (offering.getTrafficType() == trafficType) {
|
||||
networkOfferingId = offering.getId();
|
||||
break;
|
||||
@ -1069,7 +1062,6 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
return networks.get(0).getId();
|
||||
}
|
||||
|
||||
|
||||
@DB
|
||||
public void updateResourceCount() {
|
||||
ResourceType[] resourceTypes = Resource.ResourceType.values();
|
||||
@ -1090,14 +1082,13 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int accountExpectedCount = accountSupportedResourceTypes.size();
|
||||
int domainExpectedCount = domainSupportedResourceTypes.size();
|
||||
|
||||
if ((domainResourceCount.size() < domainExpectedCount * domains.size())) {
|
||||
s_logger.debug("resource_count table has records missing for some domains...going to insert them");
|
||||
for (DomainVO domain : domains) {
|
||||
//Lock domain
|
||||
// Lock domain
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
_domainDao.lockRow(domain.getId(), true);
|
||||
@ -1123,7 +1114,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
if ((accountResourceCount.size() < accountExpectedCount * accounts.size())) {
|
||||
s_logger.debug("resource_count table has records missing for some accounts...going to insert them");
|
||||
for (AccountVO account : accounts) {
|
||||
//lock account
|
||||
// lock account
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
_accountDao.lockRow(account.getId(), true);
|
||||
|
||||
@ -334,7 +334,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
private int _customDiskOfferingMinSize = 1;
|
||||
private int _customDiskOfferingMaxSize = 1024;
|
||||
|
||||
|
||||
public boolean share(VMInstanceVO vm, List<VolumeVO> vols, HostVO host, boolean cancelPreviousShare) throws StorageUnavailableException {
|
||||
|
||||
// if pool is in maintenance and it is the ONLY pool available; reject
|
||||
@ -364,9 +363,9 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
@Override
|
||||
public VolumeVO allocateDuplicateVolume(VolumeVO oldVol, Long templateId) {
|
||||
VolumeVO newVol = new VolumeVO(oldVol.getVolumeType(), oldVol.getName(), oldVol.getDataCenterId(), oldVol.getDomainId(), oldVol.getAccountId(), oldVol.getDiskOfferingId(), oldVol.getSize());
|
||||
if(templateId != null){
|
||||
if (templateId != null) {
|
||||
newVol.setTemplateId(templateId);
|
||||
}else{
|
||||
} else {
|
||||
newVol.setTemplateId(oldVol.getTemplateId());
|
||||
}
|
||||
newVol.setDeviceId(oldVol.getDeviceId());
|
||||
@ -391,12 +390,12 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
public List<StoragePoolVO> ListByDataCenterHypervisor(long datacenterId, HypervisorType type) {
|
||||
List<StoragePoolVO> pools = _storagePoolDao.listByDataCenterId(datacenterId);
|
||||
List<StoragePoolVO> retPools = new ArrayList<StoragePoolVO>();
|
||||
for (StoragePoolVO pool : pools ) {
|
||||
if( pool.getStatus() != StoragePoolStatus.Up) {
|
||||
for (StoragePoolVO pool : pools) {
|
||||
if (pool.getStatus() != StoragePoolStatus.Up) {
|
||||
continue;
|
||||
}
|
||||
ClusterVO cluster = _clusterDao.findById(pool.getClusterId());
|
||||
if( type == cluster.getHypervisorType()) {
|
||||
if (type == cluster.getHypervisorType()) {
|
||||
retPools.add(pool);
|
||||
}
|
||||
}
|
||||
@ -689,7 +688,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
if (answer != null && answer.getResult()) {
|
||||
vdiUUID = answer.getVdi();
|
||||
} else {
|
||||
s_logger.error(basicErrMsg + " due to " + ((answer == null)?"null":answer.getDetails()));
|
||||
s_logger.error(basicErrMsg + " due to " + ((answer == null) ? "null" : answer.getDetails()));
|
||||
throw new CloudRuntimeException(basicErrMsg);
|
||||
}
|
||||
} catch (StorageUnavailableException e) {
|
||||
@ -830,7 +829,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Can't find the vm where host resides on(vm is destroyed? or volume is detached from vm), randomly choose a host
|
||||
* Can't find the vm where host resides on(vm is destroyed? or volume is detached from vm), randomly choose
|
||||
* a host
|
||||
* to send the cmd
|
||||
*/
|
||||
}
|
||||
@ -888,8 +888,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
String time = configs.get("storage.cleanup.interval");
|
||||
_storageCleanupInterval = NumbersUtil.parseInt(time, 86400);
|
||||
|
||||
|
||||
|
||||
s_logger.info("Storage cleanup enabled: " + _storageCleanupEnabled + ", interval: " + _storageCleanupInterval + ", template cleanup enabled: " + _templateCleanupEnabled);
|
||||
|
||||
String workers = configs.get("expunge.workers");
|
||||
@ -1032,10 +1030,10 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
@Override
|
||||
public HostVO getSecondaryStorageHost(long zoneId, long tmpltId) {
|
||||
List<HostVO> hosts = _ssvmMgr.listSecondaryStorageHostsInOneZone(zoneId);
|
||||
if( hosts == null || hosts.size() == 0) {
|
||||
if (hosts == null || hosts.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
for( HostVO host : hosts ) {
|
||||
for (HostVO host : hosts) {
|
||||
VMTemplateHostVO tmpltHost = _vmTemplateHostDao.findByHostTemplate(host.getId(), tmpltId);
|
||||
if (tmpltHost != null && !tmpltHost.getDestroyed() && tmpltHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
|
||||
return host;
|
||||
@ -1047,7 +1045,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
@Override
|
||||
public VMTemplateHostVO getTemplateHostRef(long zoneId, long tmpltId, boolean readyOnly) {
|
||||
List<HostVO> hosts = _ssvmMgr.listSecondaryStorageHostsInOneZone(zoneId);
|
||||
if( hosts == null || hosts.size() == 0) {
|
||||
if (hosts == null || hosts.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
VMTemplateHostVO inProgress = null;
|
||||
@ -1073,7 +1071,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
@Override
|
||||
public HostVO getSecondaryStorageHost(long zoneId) {
|
||||
List<HostVO> hosts = _ssvmMgr.listSecondaryStorageHostsInOneZone(zoneId);
|
||||
if( hosts == null || hosts.size() == 0) {
|
||||
if (hosts == null || hosts.size() == 0) {
|
||||
hosts = _ssvmMgr.listLocalSecondaryStorageHostsInOneZone(zoneId);
|
||||
if (hosts.isEmpty()) {
|
||||
return null;
|
||||
@ -1089,7 +1087,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
@Override
|
||||
public List<HostVO> getSecondaryStorageHosts(long zoneId) {
|
||||
List<HostVO> hosts = _ssvmMgr.listSecondaryStorageHostsInOneZone(zoneId);
|
||||
if( hosts == null || hosts.size() == 0) {
|
||||
if (hosts == null || hosts.size() == 0) {
|
||||
hosts = _ssvmMgr.listLocalSecondaryStorageHostsInOneZone(zoneId);
|
||||
if (hosts.isEmpty()) {
|
||||
return new ArrayList<HostVO>();
|
||||
@ -1476,7 +1474,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
_storagePoolDao.update(id, sPool);
|
||||
_storagePoolDao.remove(id);
|
||||
deletePoolStats(id);
|
||||
//Delete op_host_capacity entries
|
||||
// Delete op_host_capacity entries
|
||||
_capacityDao.removeBy(Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, null, null, null, id);
|
||||
txn.commit();
|
||||
|
||||
@ -1591,8 +1589,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
@Override
|
||||
public VolumeVO moveVolume(VolumeVO volume, long destPoolDcId, Long destPoolPodId, Long destPoolClusterId, HypervisorType dataDiskHyperType) throws ConcurrentOperationException {
|
||||
|
||||
|
||||
|
||||
// Find a destination storage pool with the specified criteria
|
||||
DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
|
||||
DiskProfile dskCh = new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSize(), diskOffering.getTagsArray(),
|
||||
@ -1617,10 +1613,12 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
}
|
||||
|
||||
/*
|
||||
* Just allocate a volume in the database, don't send the createvolume cmd to hypervisor. The volume will be finally created
|
||||
* Just allocate a volume in the database, don't send the createvolume cmd to hypervisor. The volume will be finally
|
||||
* created
|
||||
* only when it's attached to a VM.
|
||||
*/
|
||||
@Override @DB
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_CREATE, eventDescription = "creating volume", create = true)
|
||||
public VolumeVO allocVolume(CreateVolumeCmd cmd) throws ResourceAllocationException {
|
||||
// FIXME: some of the scheduled event stuff might be missing here...
|
||||
@ -1628,7 +1626,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
|
||||
long ownerId = cmd.getEntityOwnerId();
|
||||
|
||||
//permission check
|
||||
// permission check
|
||||
_accountMgr.checkAccess(caller, null, true, _accountMgr.getActiveAccountById(ownerId));
|
||||
|
||||
// Check that the resource limit for volumes won't be exceeded
|
||||
@ -1648,8 +1646,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
diskOfferingId = cmd.getDiskOfferingId();
|
||||
size = cmd.getSize();
|
||||
Long sizeInGB = size;
|
||||
if ( size != null ) {
|
||||
if ( size > 0 ) {
|
||||
if (size != null) {
|
||||
if (size > 0) {
|
||||
size = size * 1024 * 1024 * 1024; // user specify size in GB
|
||||
} else {
|
||||
throw new InvalidParameterValueException("Disk size must be larger than 0");
|
||||
@ -1665,11 +1663,11 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
}
|
||||
|
||||
if (diskOffering.isCustomized()) {
|
||||
if(size == null){
|
||||
if (size == null) {
|
||||
throw new InvalidParameterValueException("This disk offering requires a custom size specified");
|
||||
}
|
||||
if((sizeInGB < _customDiskOfferingMinSize) || (sizeInGB > _customDiskOfferingMaxSize)){
|
||||
throw new InvalidParameterValueException("Volume size: "+sizeInGB+"GB is out of allowed range. Max: "+_customDiskOfferingMaxSize+" Min:"+_customDiskOfferingMinSize);
|
||||
if ((sizeInGB < _customDiskOfferingMinSize) || (sizeInGB > _customDiskOfferingMaxSize)) {
|
||||
throw new InvalidParameterValueException("Volume size: " + sizeInGB + "GB is out of allowed range. Max: " + _customDiskOfferingMaxSize + " Min:" + _customDiskOfferingMinSize);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1705,16 +1703,17 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
zoneId = snapshotCheck.getDataCenterId();
|
||||
size = snapshotCheck.getSize(); // ; disk offering is used for tags purposes
|
||||
|
||||
//check snapshot permissions
|
||||
// check snapshot permissions
|
||||
_accountMgr.checkAccess(caller, null, true, snapshotCheck);
|
||||
|
||||
/*
|
||||
// bug #11428. Operation not supported if vmware and snapshots parent volume = ROOT
|
||||
if(snapshotCheck.getHypervisorType() == HypervisorType.VMware
|
||||
&& _volumeDao.findByIdIncludingRemoved(snapshotCheck.getVolumeId()).getVolumeType() == Type.ROOT){
|
||||
throw new UnsupportedServiceException("operation not supported, snapshot with id " + snapshotId + " is created from ROOT volume");
|
||||
}
|
||||
*/
|
||||
/*
|
||||
* // bug #11428. Operation not supported if vmware and snapshots parent volume = ROOT
|
||||
* if(snapshotCheck.getHypervisorType() == HypervisorType.VMware
|
||||
* && _volumeDao.findByIdIncludingRemoved(snapshotCheck.getVolumeId()).getVolumeType() == Type.ROOT){
|
||||
* throw new UnsupportedServiceException("operation not supported, snapshot with id " + snapshotId +
|
||||
* " is created from ROOT volume");
|
||||
* }
|
||||
*/
|
||||
}
|
||||
|
||||
// Verify that zone exists
|
||||
@ -1860,7 +1859,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createCapacityEntry(StoragePoolVO storagePool, short capacityType ,long allocated) {
|
||||
public void createCapacityEntry(StoragePoolVO storagePool, short capacityType, long allocated) {
|
||||
SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
|
||||
|
||||
List<CapacityVO> capacities = _capacityDao.search(capacitySC, null);
|
||||
@ -1873,8 +1872,9 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
|
||||
long totalOverProvCapacity;
|
||||
if (storagePool.getPoolType() == StoragePoolType.NetworkFilesystem) {
|
||||
totalOverProvCapacity = _overProvisioningFactor.multiply(new BigDecimal(storagePool.getCapacityBytes())).longValue();// All this for the inaccuracy of floats for big number multiplication.
|
||||
}else {
|
||||
totalOverProvCapacity = _overProvisioningFactor.multiply(new BigDecimal(storagePool.getCapacityBytes())).longValue();// All
|
||||
// this for the inaccuracy of floats for big number multiplication.
|
||||
} else {
|
||||
totalOverProvCapacity = storagePool.getCapacityBytes();
|
||||
}
|
||||
|
||||
@ -1896,13 +1896,12 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
_capacityDao.update(capacity.getId(), capacity);
|
||||
}
|
||||
}
|
||||
s_logger.debug("Successfully set Capacity - " + totalOverProvCapacity + " for capacity type - " +capacityType+ " , DataCenterId - "
|
||||
s_logger.debug("Successfully set Capacity - " + totalOverProvCapacity + " for capacity type - " + capacityType + " , DataCenterId - "
|
||||
+ storagePool.getDataCenterId() + ", HostOrPoolId - " + storagePool.getId() + ", PodId " + storagePool.getPodId());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Long> getUpHostsInPool(long poolId){
|
||||
public List<Long> getUpHostsInPool(long poolId) {
|
||||
SearchCriteria<Long> sc = UpHostsInPoolSearch.create();
|
||||
sc.setParameters("pool", poolId);
|
||||
sc.setJoinParameters("hosts", "status", Status.Up);
|
||||
@ -1925,8 +1924,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
if (hostIdsToAvoid != null) {
|
||||
hostIds.removeAll(hostIdsToAvoid);
|
||||
}
|
||||
if ( hostIds == null || hostIds.isEmpty() ) {
|
||||
throw new StorageUnavailableException("Unable to send command to the pool " + pool.getId() + " due to there is no enabled hosts up in this cluster", pool.getId() );
|
||||
if (hostIds == null || hostIds.isEmpty()) {
|
||||
throw new StorageUnavailableException("Unable to send command to the pool " + pool.getId() + " due to there is no enabled hosts up in this cluster", pool.getId());
|
||||
}
|
||||
for (Long hostId : hostIds) {
|
||||
try {
|
||||
@ -1963,7 +1962,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
if (scanLock.lock(3)) {
|
||||
try {
|
||||
// Cleanup primary storage pools
|
||||
if(_templateCleanupEnabled) {
|
||||
if (_templateCleanupEnabled) {
|
||||
List<StoragePoolVO> storagePools = _storagePoolDao.listAll();
|
||||
for (StoragePoolVO pool : storagePools) {
|
||||
try {
|
||||
@ -2032,7 +2031,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
|
||||
}
|
||||
|
||||
|
||||
List<String> findAllSnapshotForVolume(Long volumeId) {
|
||||
String sql = "SELECT backup_snap_id FROM snapshots WHERE volume_id=? and backup_snap_id is not NULL";
|
||||
try {
|
||||
@ -2176,9 +2174,9 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
}
|
||||
|
||||
List<StoragePoolVO> spes = _storagePoolDao.listBy(primaryStorage.getDataCenterId(), primaryStorage.getPodId(), primaryStorage.getClusterId());
|
||||
for( StoragePoolVO sp : spes ) {
|
||||
if( sp.getStatus() == StoragePoolStatus.PrepareForMaintenance ) {
|
||||
throw new CloudRuntimeException("Only one storage pool in a cluster can be in PrepareForMaintenance mode, " + sp.getId() + " is already in PrepareForMaintenance mode " );
|
||||
for (StoragePoolVO sp : spes) {
|
||||
if (sp.getStatus() == StoragePoolStatus.PrepareForMaintenance) {
|
||||
throw new CloudRuntimeException("Only one storage pool in a cluster can be in PrepareForMaintenance mode, " + sp.getId() + " is already in PrepareForMaintenance mode ");
|
||||
}
|
||||
}
|
||||
|
||||
@ -2186,9 +2184,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
throw new InvalidParameterValueException("Primary storage with id " + primaryStorageId + " is not ready for migration, as the status is:" + primaryStorage.getStatus().toString());
|
||||
}
|
||||
|
||||
|
||||
List<HostVO> hosts = _resourceMgr.listHostsInClusterByStatus(primaryStorage.getClusterId(), Status.Up);
|
||||
if( hosts == null || hosts.size() == 0 ) {
|
||||
if (hosts == null || hosts.size() == 0) {
|
||||
primaryStorage.setStatus(StoragePoolStatus.Maintenance);
|
||||
_storagePoolDao.update(primaryStorageId, primaryStorage);
|
||||
return _storagePoolDao.findById(primaryStorageId);
|
||||
@ -2198,7 +2195,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
_storagePoolDao.update(primaryStorageId, primaryStorage);
|
||||
}
|
||||
// remove heartbeat
|
||||
for ( HostVO host : hosts ) {
|
||||
for (HostVO host : hosts) {
|
||||
ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(false, primaryStorage);
|
||||
final Answer answer = _agentMgr.easySend(host.getId(), cmd);
|
||||
if (answer == null || !answer.getResult()) {
|
||||
@ -2417,11 +2414,11 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
_storagePoolDao.update(primaryStorageId, primaryStorage);
|
||||
txn.commit();
|
||||
List<HostVO> hosts = _resourceMgr.listHostsInClusterByStatus(primaryStorage.getClusterId(), Status.Up);
|
||||
if( hosts == null || hosts.size() == 0 ) {
|
||||
if (hosts == null || hosts.size() == 0) {
|
||||
return _storagePoolDao.findById(primaryStorageId);
|
||||
}
|
||||
// add heartbeat
|
||||
for ( HostVO host : hosts ) {
|
||||
for (HostVO host : hosts) {
|
||||
ModifyStoragePoolCommand msPoolCmd = new ModifyStoragePoolCommand(true, primaryStorage);
|
||||
final Answer answer = _agentMgr.easySend(host.getId(), msPoolCmd);
|
||||
if (answer == null || !answer.getResult()) {
|
||||
@ -2566,7 +2563,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
throw new InvalidParameterValueException("There are snapshot creating on it, Unable to delete the volume");
|
||||
}
|
||||
|
||||
//permission check
|
||||
// permission check
|
||||
_accountMgr.checkAccess(caller, null, true, volume);
|
||||
|
||||
// Check that the volume is not currently attached to any VM
|
||||
@ -2594,7 +2591,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
private boolean validateVolumeSizeRange(long size) {
|
||||
if (size < 0 || (size > 0 && size < (1024 * 1024 * 1024))) {
|
||||
throw new InvalidParameterValueException("Please specify a size of at least 1 Gb.");
|
||||
} else if (size > (_maxVolumeSizeInGb * 1024 * 1024 * 1024) ) {
|
||||
} else if (size > (_maxVolumeSizeInGb * 1024 * 1024 * 1024)) {
|
||||
throw new InvalidParameterValueException("volume size " + size + ", but the maximum size allowed is " + _maxVolumeSizeInGb + " Gb.");
|
||||
}
|
||||
|
||||
@ -2756,7 +2753,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
try {
|
||||
List<Long> volIds = new ArrayList<Long>();
|
||||
for (Volume volume : volumes) {
|
||||
if (!_snapshotMgr.canOperateOnVolume((VolumeVO)volume)) {
|
||||
if (!_snapshotMgr.canOperateOnVolume((VolumeVO) volume)) {
|
||||
throw new CloudRuntimeException("There are snapshots creating on this volume, can not move this volume");
|
||||
}
|
||||
|
||||
@ -2781,11 +2778,11 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
//At this stage, nobody can modify volumes. Send the copyvolume command
|
||||
List<Pair<StoragePoolVO,DestroyCommand>> destroyCmds = new ArrayList<Pair<StoragePoolVO,DestroyCommand>>();
|
||||
// At this stage, nobody can modify volumes. Send the copyvolume command
|
||||
List<Pair<StoragePoolVO, DestroyCommand>> destroyCmds = new ArrayList<Pair<StoragePoolVO, DestroyCommand>>();
|
||||
List<CopyVolumeAnswer> answers = new ArrayList<CopyVolumeAnswer>();
|
||||
try {
|
||||
for (Volume volume: volumes) {
|
||||
for (Volume volume : volumes) {
|
||||
String secondaryStorageURL = getSecondaryStorageURL(volume.getDataCenterId());
|
||||
StoragePoolVO srcPool = _storagePoolDao.findById(volume.getPoolId());
|
||||
CopyVolumeCommand cvCmd = new CopyVolumeCommand(volume.getId(), volume.getPath(), srcPool, secondaryStorageURL, true, _copyvolumewait);
|
||||
@ -2820,7 +2817,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
}
|
||||
} finally {
|
||||
if (answers.size() != volumes.size()) {
|
||||
//this means one of copying volume failed
|
||||
// this means one of copying volume failed
|
||||
for (Volume volume : volumes) {
|
||||
try {
|
||||
stateTransitTo(volume, Volume.Event.OperationFailed);
|
||||
@ -2830,7 +2827,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
}
|
||||
_checkPointMgr.popCheckPoint(checkPointTaskId);
|
||||
} else {
|
||||
//Need a transaction, make sure all the volumes get migrated to new storage pool
|
||||
// Need a transaction, make sure all the volumes get migrated to new storage pool
|
||||
txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
@ -2838,7 +2835,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
try {
|
||||
for (int i = 0; i < volumes.size(); i++) {
|
||||
CopyVolumeAnswer answer = answers.get(i);
|
||||
VolumeVO volume = (VolumeVO)volumes.get(i);
|
||||
VolumeVO volume = (VolumeVO) volumes.get(i);
|
||||
Long oldPoolId = volume.getPoolId();
|
||||
volume.setPath(answer.getVolumePath());
|
||||
volume.setFolder(destPool.getPath());
|
||||
@ -2867,11 +2864,10 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//all the volumes get migrated to new storage pool, need to delete the copy on old storage pool
|
||||
// all the volumes get migrated to new storage pool, need to delete the copy on old storage pool
|
||||
for (Pair<StoragePoolVO, DestroyCommand> cmd : destroyCmds) {
|
||||
try {
|
||||
Answer cvAnswer = sendToPool(cmd.first(), cmd.second());
|
||||
@ -2953,7 +2949,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
throw new StorageUnavailableException("Volume has no pool associate and also no storage pool assigned in DeployDestination, Unable to create " + vol, Volume.class, vol.getId());
|
||||
}
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("No need to recreate the volume: "+vol+ ", since it already has a pool assigned: "+vol.getPoolId()+", adding disk to VM");
|
||||
s_logger.debug("No need to recreate the volume: " + vol + ", since it already has a pool assigned: " + vol.getPoolId() + ", adding disk to VM");
|
||||
}
|
||||
StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
|
||||
vm.addDisk(new VolumeTO(vol, pool));
|
||||
@ -3027,7 +3023,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
long vmTemplateId = vm.getTemplateId();
|
||||
if (volTemplateId != null && volTemplateId.longValue() != vmTemplateId) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("switchVolume: Old Volume's templateId: "+volTemplateId + " does not match the VM's templateId: "+vmTemplateId+", updating templateId in the new Volume");
|
||||
s_logger.debug("switchVolume: Old Volume's templateId: " + volTemplateId + " does not match the VM's templateId: " + vmTemplateId + ", updating templateId in the new Volume");
|
||||
}
|
||||
templateIdToUse = vmTemplateId;
|
||||
}
|
||||
@ -3204,7 +3200,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onManagementNodeJoined(List<ManagementServerHostVO> nodeList, long selfNodeId) {
|
||||
// TODO Auto-generated method stub
|
||||
@ -3247,9 +3242,9 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
}
|
||||
|
||||
List<HostVO> hosts = new ArrayList<HostVO>();
|
||||
if(hostId != null){
|
||||
if (hostId != null) {
|
||||
hosts.add(ApiDBUtils.findHostById(hostId));
|
||||
}else{
|
||||
} else {
|
||||
hosts = _ssvmMgr.listSecondaryStorageHostsInOneZone(zoneId);
|
||||
}
|
||||
|
||||
@ -3304,10 +3299,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
return capacity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
public StoragePool getStoragePool(long id) {
|
||||
return _storagePoolDao.findById(id);
|
||||
}
|
||||
@ -3319,7 +3311,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
|
||||
List<HostVO> secHosts = _ssvmMgr.listSecondaryStorageHostsInOneZone(dcId);
|
||||
|
||||
//FIXME, for cloudzone, the local secondary storoge
|
||||
// FIXME, for cloudzone, the local secondary storoge
|
||||
if (pool.isLocal() && pool.getPoolType() == StoragePoolType.Filesystem && secHosts.isEmpty()) {
|
||||
List<StoragePoolHostVO> sphs = _storagePoolHostDao.listByPoolId(pool.getId());
|
||||
if (!sphs.isEmpty()) {
|
||||
@ -3336,13 +3328,13 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
}
|
||||
if (podId != null) {
|
||||
List<VMTemplateHostVO> templHosts = _templateHostDao.listByTemplateStatus(templateId, dcId, podId, VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
|
||||
if( templHosts != null && ! templHosts.isEmpty()) {
|
||||
if (templHosts != null && !templHosts.isEmpty()) {
|
||||
Collections.shuffle(templHosts);
|
||||
return templHosts.get(0);
|
||||
}
|
||||
}
|
||||
List<VMTemplateHostVO> templHosts = _templateHostDao.listByTemplateStatus(templateId, dcId, VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
|
||||
if( templHosts != null && ! templHosts.isEmpty()) {
|
||||
if (templHosts != null && !templHosts.isEmpty()) {
|
||||
Collections.shuffle(templHosts);
|
||||
return templHosts.get(0);
|
||||
}
|
||||
@ -3357,11 +3349,12 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
sc.setJoinParameters("vmVolume", "poolId", storagePoolId);
|
||||
return _vmInstanceDao.search(sc, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public StoragePoolVO findLocalStorageOnHost(long hostId) {
|
||||
SearchCriteria<StoragePoolVO> sc = LocalStorageSearch.create();
|
||||
sc.setParameters("type", new Object[]{StoragePoolType.Filesystem, StoragePoolType.LVM});
|
||||
sc.setParameters("type", new Object[] { StoragePoolType.Filesystem, StoragePoolType.LVM });
|
||||
sc.setJoinParameters("poolHost", "hostId", hostId);
|
||||
List<StoragePoolVO> storagePools = _storagePoolDao.search(sc, null);
|
||||
if (!storagePools.isEmpty()) {
|
||||
@ -3508,4 +3501,5 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
|
||||
return _volumeDao.search(sc, searchFilter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -305,7 +305,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
public void checkAccess(Account caller, AccessType accessType, boolean sameOwner, ControlledEntity... entities) {
|
||||
|
||||
if (caller.getId() == Account.ACCOUNT_ID_SYSTEM || isRootAdmin(caller.getType())) {
|
||||
//no need to make permission checks if the system/root admin makes the call
|
||||
// no need to make permission checks if the system/root admin makes the call
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("No need to make permission check for System/RootAdmin account, returning true");
|
||||
}
|
||||
@ -318,13 +318,14 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
|
||||
for (ControlledEntity entity : entities) {
|
||||
long domainId = entity.getDomainId();
|
||||
if (entity.getAccountId() != -1 && domainId == -1){ // If account exists domainId should too so calculate it. This condition might be hit for templates or entities which miss domainId in their tables
|
||||
if (entity.getAccountId() != -1 && domainId == -1) { // If account exists domainId should too so calculate
|
||||
// it. This condition might be hit for templates or entities which miss domainId in their tables
|
||||
Account account = ApiDBUtils.findAccountById(entity.getAccountId());
|
||||
domainId = account != null ? account.getDomainId() : -1 ;
|
||||
domainId = account != null ? account.getDomainId() : -1;
|
||||
}
|
||||
if (entity.getAccountId() != -1 && domainId != -1 && !(entity instanceof VirtualMachineTemplate) && !(accessType != null && accessType == AccessType.UseNetwork)) {
|
||||
List<ControlledEntity> toBeChecked = domains.get(entity.getDomainId());
|
||||
//for templates, we don't have to do cross domains check
|
||||
// for templates, we don't have to do cross domains check
|
||||
if (toBeChecked == null) {
|
||||
toBeChecked = new ArrayList<ControlledEntity>();
|
||||
domains.put(domainId, toBeChecked);
|
||||
@ -372,7 +373,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
//check that resources belong to the same account
|
||||
// check that resources belong to the same account
|
||||
|
||||
}
|
||||
|
||||
@ -509,7 +510,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
s_logger.debug("Expunging # of vms (accountId=" + accountId + "): " + vms.size());
|
||||
}
|
||||
|
||||
//no need to catch exception at this place as expunging vm should pass in order to perform further cleanup
|
||||
// no need to catch exception at this place as expunging vm should pass in order to perform further cleanup
|
||||
for (UserVmVO vm : vms) {
|
||||
if (!_vmMgr.expunge(vm, callerUserId, caller)) {
|
||||
s_logger.error("Unable to expunge vm: " + vm.getId());
|
||||
@ -570,7 +571,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
//release ip addresses belonging to the account
|
||||
// release ip addresses belonging to the account
|
||||
List<? extends IpAddress> ipsToRelease = _ipAddressDao.listByAccount(accountId);
|
||||
for (IpAddress ip : ipsToRelease) {
|
||||
s_logger.debug("Releasing ip " + ip + " as a part of account id=" + accountId + " cleanup");
|
||||
@ -580,7 +581,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
// delete account specific Virtual vlans (belong to system Public Network) - only when networks are cleaned up
|
||||
// delete account specific Virtual vlans (belong to system Public Network) - only when networks are cleaned
|
||||
// up
|
||||
// successfully
|
||||
if (networksDeleted) {
|
||||
if (!_configMgr.deleteAccountSpecificVirtualRanges(accountId)) {
|
||||
@ -595,7 +597,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
s_logger.warn("Failed to cleanup account " + account + " due to ", ex);
|
||||
accountCleanupNeeded = true;
|
||||
return true;
|
||||
}finally {
|
||||
} finally {
|
||||
s_logger.info("Cleanup for account " + account.getId() + (accountCleanupNeeded ? " is needed." : " is not needed."));
|
||||
if (accountCleanupNeeded) {
|
||||
_accountDao.markForCleanup(accountId);
|
||||
@ -658,7 +660,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_CREATE, eventDescription = "creating Account")
|
||||
public UserAccount createUserAccount(String userName, String password, String firstName, String lastName, String email, String timezone, String accountName, short accountType, Long domainId, String networkDomain, Map<String, String> details) {
|
||||
public UserAccount createUserAccount(String userName, String password, String firstName, String lastName, String email, String timezone, String accountName, short accountType, Long domainId, String networkDomain,
|
||||
Map<String, String> details) {
|
||||
|
||||
if (accountName == null) {
|
||||
accountName = userName;
|
||||
@ -667,16 +670,15 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
domainId = DomainVO.ROOT_DOMAIN;
|
||||
}
|
||||
|
||||
//Validate domain
|
||||
// Validate domain
|
||||
Domain domain = _domainMgr.getDomain(domainId);
|
||||
if (domain == null) {
|
||||
throw new InvalidParameterValueException("The domain " + domainId + " does not exist; unable to create account");
|
||||
}
|
||||
|
||||
//Check permissions
|
||||
// Check permissions
|
||||
checkAccess(UserContext.current().getCaller(), domain);
|
||||
|
||||
|
||||
if (!_userAccountDao.validateUsernameInDomain(userName, domainId)) {
|
||||
throw new InvalidParameterValueException("The user " + userName + " already exists in domain " + domainId);
|
||||
}
|
||||
@ -692,15 +694,15 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
//create account
|
||||
// create account
|
||||
Account account = createAccount(accountName, accountType, domainId, networkDomain, details);
|
||||
long accountId = account.getId();
|
||||
|
||||
//create the first user for the account
|
||||
// create the first user for the account
|
||||
UserVO user = createUser(accountId, userName, password, firstName, lastName, email, timezone);
|
||||
|
||||
if(accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN){
|
||||
//set registration token
|
||||
if (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
|
||||
// set registration token
|
||||
byte[] bytes = (domainId + accountName + userName + System.currentTimeMillis()).getBytes();
|
||||
String registrationToken = UUID.nameUUIDFromBytes(bytes).toString();
|
||||
user.setRegistrationToken(registrationToken);
|
||||
@ -768,7 +770,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
// If the account is an admin type, return an error. We do not allow this
|
||||
Account account = _accountDao.findById(user.getAccountId());
|
||||
|
||||
//don't allow updating project account
|
||||
// don't allow updating project account
|
||||
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
throw new InvalidParameterValueException("unable to find user by id");
|
||||
}
|
||||
@ -786,7 +788,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
user.setLastname(lastName);
|
||||
}
|
||||
if (userName != null) {
|
||||
//don't allow to have same user names in the same domain
|
||||
// don't allow to have same user names in the same domain
|
||||
List<UserVO> duplicatedUsers = _userDao.findUsersLike(userName);
|
||||
for (UserVO duplicatedUser : duplicatedUsers) {
|
||||
if (duplicatedUser.getId() != user.getId()) {
|
||||
@ -815,7 +817,6 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
user.setSecretKey(secretKey);
|
||||
}
|
||||
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("updating user with id: " + id);
|
||||
}
|
||||
@ -855,7 +856,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
|
||||
Account account = _accountDao.findById(user.getAccountId());
|
||||
|
||||
//don't allow disabling user belonging to project's account
|
||||
// don't allow disabling user belonging to project's account
|
||||
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
throw new InvalidParameterValueException("Unable to find active user by id " + userId);
|
||||
}
|
||||
@ -876,7 +877,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_USER_ENABLE, eventDescription = "enabling User")
|
||||
public UserAccount enableUser(long userId) {
|
||||
|
||||
@ -931,7 +933,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
|
||||
Account account = _accountDao.findById(user.getAccountId());
|
||||
|
||||
//don't allow to lock user of the account of type Project
|
||||
// don't allow to lock user of the account of type Project
|
||||
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
throw new InvalidParameterValueException("Unable to find user by id");
|
||||
}
|
||||
@ -944,7 +946,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
checkAccess(caller, null, true, account);
|
||||
|
||||
// make sure the account is enabled too
|
||||
// if the user is either locked already or disabled already, don't change state...only lock currently enabled users
|
||||
// if the user is either locked already or disabled already, don't change state...only lock currently enabled
|
||||
// users
|
||||
boolean success = true;
|
||||
if (user.getState().equals(State.locked)) {
|
||||
// already locked...no-op
|
||||
@ -1006,7 +1009,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
throw new PermissionDeniedException("Account id : " + accountId + " is a system account, delete is not allowed");
|
||||
}
|
||||
|
||||
//Account that manages project(s) can't be removed
|
||||
// Account that manages project(s) can't be removed
|
||||
List<Long> managedProjectIds = _projectAccountDao.listAdministratedProjects(accountId);
|
||||
if (!managedProjectIds.isEmpty()) {
|
||||
StringBuilder projectIds = new StringBuilder();
|
||||
@ -1025,14 +1028,14 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
|
||||
// Check if account exists
|
||||
Account account = null;
|
||||
if(accountId != null){
|
||||
if (accountId != null) {
|
||||
account = _accountDao.findById(accountId);
|
||||
}else{
|
||||
} else {
|
||||
account = _accountDao.findActiveAccount(accountName, domainId);
|
||||
}
|
||||
|
||||
if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
throw new InvalidParameterValueException("Unable to find account by accountId: "+accountId+" OR by name: "+ accountName + " in domain " + domainId);
|
||||
throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
}
|
||||
|
||||
// Don't allow to modify system account
|
||||
@ -1048,7 +1051,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
if (success) {
|
||||
return _accountDao.findById(account.getId());
|
||||
} else {
|
||||
throw new CloudRuntimeException("Unable to enable account by accountId: "+accountId+" OR by name: "+ accountName + " in domain " + domainId);
|
||||
throw new CloudRuntimeException("Unable to enable account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1058,14 +1061,14 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
Account account = null;
|
||||
if(accountId != null){
|
||||
if (accountId != null) {
|
||||
account = _accountDao.findById(accountId);
|
||||
}else{
|
||||
} else {
|
||||
account = _accountDao.findActiveAccount(accountName, domainId);
|
||||
}
|
||||
|
||||
if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
throw new InvalidParameterValueException("Unable to find active account by accountId: "+accountId+" OR by name: "+ accountName + " in domain " + domainId);
|
||||
throw new InvalidParameterValueException("Unable to find active account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
}
|
||||
|
||||
checkAccess(caller, null, true, account);
|
||||
@ -1078,7 +1081,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
if (lockAccount(account.getId())) {
|
||||
return _accountDao.findById(account.getId());
|
||||
} else {
|
||||
throw new CloudRuntimeException("Unable to lock account by accountId: "+accountId+" OR by name: "+ accountName + " in domain " + domainId);
|
||||
throw new CloudRuntimeException("Unable to lock account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1088,14 +1091,14 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
Account account = null;
|
||||
if(accountId != null){
|
||||
if (accountId != null) {
|
||||
account = _accountDao.findById(accountId);
|
||||
}else{
|
||||
} else {
|
||||
account = _accountDao.findActiveAccount(accountName, domainId);
|
||||
}
|
||||
|
||||
if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
throw new InvalidParameterValueException("Unable to find account by accountId: "+accountId+" OR by name: "+ accountName + " in domain " + domainId);
|
||||
throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
}
|
||||
|
||||
checkAccess(caller, null, true, account);
|
||||
@ -1103,31 +1106,32 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
if (disableAccount(account.getId())) {
|
||||
return _accountDao.findById(account.getId());
|
||||
} else {
|
||||
throw new CloudRuntimeException("Unable to update account by accountId: "+accountId+" OR by name: "+ accountName + " in domain " + domainId);
|
||||
throw new CloudRuntimeException("Unable to update account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@Override
|
||||
@DB
|
||||
public AccountVO updateAccount(UpdateAccountCmd cmd) {
|
||||
Long accountId = cmd.getId();
|
||||
Long domainId = cmd.getDomainId();
|
||||
String accountName = cmd.getAccountName();
|
||||
String newAccountName = cmd.getNewName();
|
||||
String networkDomain = cmd.getNetworkDomain();
|
||||
Map<String, String>details = cmd.getDetails();
|
||||
Map<String, String> details = cmd.getDetails();
|
||||
|
||||
boolean success = false;
|
||||
Account account = null;
|
||||
if(accountId != null){
|
||||
if (accountId != null) {
|
||||
account = _accountDao.findById(accountId);
|
||||
}else{
|
||||
} else {
|
||||
account = _accountDao.findEnabledAccount(accountName, domainId);
|
||||
}
|
||||
|
||||
// Check if account exists
|
||||
if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
s_logger.error("Unable to find account by accountId: "+accountId+" OR by name: "+ accountName + " in domain " + domainId);
|
||||
throw new InvalidParameterValueException("Unable to find account by accountId: "+accountId+" OR by name: "+ accountName + " in domain " + domainId);
|
||||
s_logger.error("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
}
|
||||
|
||||
// Don't allow to modify system account
|
||||
@ -1183,7 +1187,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
if (success) {
|
||||
return _accountDao.findById(account.getId());
|
||||
} else {
|
||||
throw new CloudRuntimeException("Unable to update account by accountId: "+accountId+" OR by name: "+ accountName + " in domain " + domainId);
|
||||
throw new CloudRuntimeException("Unable to update account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1200,7 +1204,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
|
||||
Account account = _accountDao.findById(user.getAccountId());
|
||||
|
||||
//don't allow to delete the user from the account of type Project
|
||||
// don't allow to delete the user from the account of type Project
|
||||
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
throw new InvalidParameterValueException("The specified user doesn't exist in the system");
|
||||
}
|
||||
@ -1213,7 +1217,6 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
return _userDao.remove(id);
|
||||
}
|
||||
|
||||
|
||||
public class ResourceCountCalculateTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -1240,7 +1243,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
try {
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
|
||||
//Cleanup removed accounts
|
||||
// Cleanup removed accounts
|
||||
List<AccountVO> removedAccounts = _accountDao.findCleanupsForRemovedAccounts(null);
|
||||
s_logger.info("Found " + removedAccounts.size() + " removed accounts to cleanup");
|
||||
for (AccountVO account : removedAccounts) {
|
||||
@ -1255,7 +1258,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
//cleanup disabled accounts
|
||||
// cleanup disabled accounts
|
||||
List<AccountVO> disabledAccounts = _accountDao.findCleanupsForDisabledAccounts();
|
||||
s_logger.info("Found " + disabledAccounts.size() + " disabled accounts to cleanup");
|
||||
for (AccountVO account : disabledAccounts) {
|
||||
@ -1270,7 +1273,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
//cleanup inactive domains
|
||||
// cleanup inactive domains
|
||||
List<? extends Domain> inactiveDomains = _domainMgr.findInactiveDomains();
|
||||
s_logger.info("Found " + inactiveDomains.size() + " inactive domains to cleanup");
|
||||
for (Domain inactiveDomain : inactiveDomains) {
|
||||
@ -1288,7 +1291,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
//cleanup inactive projects
|
||||
// cleanup inactive projects
|
||||
List<? extends Project> inactiveProjects = _projectDao.listByState(Project.State.Disabled);
|
||||
s_logger.info("Found " + inactiveProjects.size() + " disabled projects to cleanup");
|
||||
for (Project project : inactiveProjects) {
|
||||
@ -1327,7 +1330,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
throw new InvalidParameterValueException("Account and domainId are needed for resource creation");
|
||||
}
|
||||
|
||||
//projectId and account/domainId can't be specified together
|
||||
// projectId and account/domainId can't be specified together
|
||||
if ((accountName != null && domainId != null) && projectId != null) {
|
||||
throw new InvalidParameterValueException("ProjectId and account/domainId can't be specified together");
|
||||
}
|
||||
@ -1411,7 +1414,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<List<Long>,Long> finalizeAccountDomainForList(Account caller, String accountName, Long domainId, Long projectId) {
|
||||
public Pair<List<Long>, Long> finalizeAccountDomainForList(Account caller, String accountName, Long domainId, Long projectId) {
|
||||
List<Long> permittedAccounts = new ArrayList<Long>();
|
||||
|
||||
if (isAdmin(caller.getType())) {
|
||||
@ -1447,7 +1450,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
domainId = caller.getDomainId();
|
||||
}
|
||||
|
||||
//set project information
|
||||
// set project information
|
||||
if (projectId != null) {
|
||||
if (projectId == -1) {
|
||||
permittedAccounts.addAll(_projectMgr.listPermittedProjectAccounts(caller.getId()));
|
||||
@ -1479,9 +1482,10 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
_userDao.update(Long.valueOf(userId), userForUpdate);
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@Override
|
||||
@DB
|
||||
public Account createAccount(String accountName, short accountType, Long domainId, String networkDomain, Map details) {
|
||||
//Validate domain
|
||||
// Validate domain
|
||||
Domain domain = _domainMgr.getDomain(domainId);
|
||||
if (domain == null) {
|
||||
throw new InvalidParameterValueException("The domain " + domainId + " does not exist; unable to create account");
|
||||
@ -1495,8 +1499,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
throw new InvalidParameterValueException("Invalid account type " + accountType + " given for an account in domain " + domainId + "; unable to create user.");
|
||||
}
|
||||
|
||||
//Validate account/user/domain settings
|
||||
if ( _accountDao.findActiveAccount(accountName, domainId) != null) {
|
||||
// Validate account/user/domain settings
|
||||
if (_accountDao.findActiveAccount(accountName, domainId) != null) {
|
||||
throw new InvalidParameterValueException("The specified account: " + accountName + " already exists");
|
||||
}
|
||||
|
||||
@ -1508,7 +1512,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
//Verify account type
|
||||
// Verify account type
|
||||
if ((accountType < Account.ACCOUNT_TYPE_NORMAL) || (accountType > Account.ACCOUNT_TYPE_PROJECT)) {
|
||||
throw new InvalidParameterValueException("Invalid account type " + accountType + " given; unable to create user");
|
||||
}
|
||||
@ -1520,7 +1524,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
//Create the account
|
||||
// Create the account
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
@ -1536,13 +1540,12 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
_accountDetailsDao.persist(accountId, details);
|
||||
}
|
||||
|
||||
//Create resource count records for the account
|
||||
// Create resource count records for the account
|
||||
_resourceCountDao.createResourceCounts(accountId, ResourceLimit.ResourceOwnerType.Account);
|
||||
|
||||
//Create default security group
|
||||
// Create default security group
|
||||
_networkGroupMgr.createDefaultSecurityGroup(accountId);
|
||||
|
||||
|
||||
txn.commit();
|
||||
|
||||
return account;
|
||||
@ -1559,7 +1562,6 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void logoutUser(Long userId) {
|
||||
UserAccount userAcct = _userAccountDao.findById(userId);
|
||||
@ -1599,7 +1601,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
|
||||
String singleSignOnTolerance = _configDao.getValue("security.singlesignon.tolerance.millis");
|
||||
if (singleSignOnTolerance == null) {
|
||||
// the SSO tolerance is gone (how much time before/after system time we'll allow the login request to be valid),
|
||||
// the SSO tolerance is gone (how much time before/after system time we'll allow the login request to be
|
||||
// valid),
|
||||
// don't authenticate
|
||||
return null;
|
||||
}
|
||||
@ -1703,9 +1706,9 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
|
||||
boolean authenticated = false;
|
||||
for (Enumeration<UserAuthenticator> en = _userAuthenticators.enumeration(); en.hasMoreElements();){
|
||||
for (Enumeration<UserAuthenticator> en = _userAuthenticators.enumeration(); en.hasMoreElements();) {
|
||||
UserAuthenticator authenticator = en.nextElement();
|
||||
if (authenticator.authenticate(username, password, domainId, requestParameters)){
|
||||
if (authenticator.authenticate(username, password, domainId, requestParameters)) {
|
||||
authenticated = true;
|
||||
break;
|
||||
}
|
||||
@ -1916,7 +1919,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
sc.setParameters("accountName", accountName);
|
||||
}
|
||||
|
||||
//don't return account of type project to the end user
|
||||
// don't return account of type project to the end user
|
||||
sc.setParameters("typeNEQ", 5);
|
||||
|
||||
if (accountId != null) {
|
||||
@ -1939,7 +1942,6 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
public List<UserAccountVO> searchForUsers(ListUsersCmd cmd) throws PermissionDeniedException {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
|
||||
Long domainId = cmd.getDomainId();
|
||||
if (domainId != null) {
|
||||
Domain domain = _domainDao.findById(domainId);
|
||||
@ -2038,11 +2040,11 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
Long domainId, boolean isRecursive, List<Long> permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria) {
|
||||
|
||||
if (sb.entity() instanceof IPAddressVO) {
|
||||
sb.and("accountIdIN", ((IPAddressVO)sb.entity()).getAllocatedToAccountId(), SearchCriteria.Op.IN);
|
||||
sb.and("domainId", ((IPAddressVO)sb.entity()).getAllocatedInDomainId(), SearchCriteria.Op.EQ);
|
||||
sb.and("accountIdIN", ((IPAddressVO) sb.entity()).getAllocatedToAccountId(), SearchCriteria.Op.IN);
|
||||
sb.and("domainId", ((IPAddressVO) sb.entity()).getAllocatedInDomainId(), SearchCriteria.Op.EQ);
|
||||
} else if (sb.entity() instanceof ProjectInvitationVO) {
|
||||
sb.and("accountIdIN", ((ProjectInvitationVO)sb.entity()).getForAccountId(), SearchCriteria.Op.IN);
|
||||
sb.and("domainId", ((ProjectInvitationVO)sb.entity()).getInDomainId(), SearchCriteria.Op.EQ);
|
||||
sb.and("accountIdIN", ((ProjectInvitationVO) sb.entity()).getForAccountId(), SearchCriteria.Op.IN);
|
||||
sb.and("domainId", ((ProjectInvitationVO) sb.entity()).getInDomainId(), SearchCriteria.Op.EQ);
|
||||
} else {
|
||||
sb.and("accountIdIN", sb.entity().getAccountId(), SearchCriteria.Op.IN);
|
||||
sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ);
|
||||
@ -2054,10 +2056,10 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
domainSearch.and("path", domainSearch.entity().getPath(), SearchCriteria.Op.LIKE);
|
||||
|
||||
if (sb.entity() instanceof IPAddressVO) {
|
||||
sb.join("domainSearch", domainSearch, ((IPAddressVO)sb.entity()).getAllocatedInDomainId(), domainSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||
sb.join("domainSearch", domainSearch, ((IPAddressVO) sb.entity()).getAllocatedInDomainId(), domainSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||
} else if (sb.entity() instanceof ProjectInvitationVO) {
|
||||
sb.join("domainSearch", domainSearch, ((ProjectInvitationVO)sb.entity()).getInDomainId(), domainSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||
}else {
|
||||
sb.join("domainSearch", domainSearch, ((ProjectInvitationVO) sb.entity()).getInDomainId(), domainSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||
} else {
|
||||
sb.join("domainSearch", domainSearch, sb.entity().getDomainId(), domainSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||
}
|
||||
|
||||
@ -2071,9 +2073,9 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
|
||||
if (sb.entity() instanceof IPAddressVO) {
|
||||
sb.join("accountSearch", accountSearch, ((IPAddressVO)sb.entity()).getAllocatedToAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||
sb.join("accountSearch", accountSearch, ((IPAddressVO) sb.entity()).getAllocatedToAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||
} else if (sb.entity() instanceof ProjectInvitationVO) {
|
||||
sb.join("accountSearch", accountSearch, ((ProjectInvitationVO)sb.entity()).getForAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||
sb.join("accountSearch", accountSearch, ((ProjectInvitationVO) sb.entity()).getForAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||
} else {
|
||||
sb.join("accountSearch", accountSearch, sb.entity().getAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||
}
|
||||
@ -2101,7 +2103,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildACLSearchParameters(Account caller, Long id, String accountName, Long projectId, List<Long> permittedAccounts, Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject, boolean listAll) {
|
||||
public void buildACLSearchParameters(Account caller, Long id, String accountName, Long projectId, List<Long> permittedAccounts, Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject,
|
||||
boolean listAll) {
|
||||
Long domainId = domainIdRecursiveListProject.first();
|
||||
|
||||
if (domainId != null) {
|
||||
@ -2109,7 +2112,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
if (domain == null) {
|
||||
throw new InvalidParameterValueException("Unable to find domain by id " + domainId);
|
||||
}
|
||||
//check permissions
|
||||
// check permissions
|
||||
checkAccess(caller, domain);
|
||||
}
|
||||
|
||||
@ -2132,7 +2135,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
//set project information
|
||||
// set project information
|
||||
if (projectId != null) {
|
||||
if (projectId == -1) {
|
||||
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
|
||||
@ -2164,13 +2167,14 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
domainIdRecursiveListProject.first(caller.getDomainId());
|
||||
domainIdRecursiveListProject.second(true);
|
||||
}
|
||||
} else if (domainId == null){
|
||||
if (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN){
|
||||
} else if (domainId == null) {
|
||||
if (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
|
||||
domainIdRecursiveListProject.first(caller.getDomainId());
|
||||
domainIdRecursiveListProject.second(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ import java.util.Set;
|
||||
import com.cloud.domain.Domain;
|
||||
import com.cloud.domain.DomainVO;
|
||||
|
||||
public interface DomainManager extends DomainService{
|
||||
public interface DomainManager extends DomainService {
|
||||
Set<Long> getDomainChildrenIds(String parentDomainPath);
|
||||
|
||||
Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain);
|
||||
|
||||
@ -57,7 +57,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
||||
@Local(value = { DomainManager.class, DomainService.class })
|
||||
public class DomainManagerImpl implements DomainManager, DomainService, Manager{
|
||||
public class DomainManagerImpl implements DomainManager, DomainService, Manager {
|
||||
public static final Logger s_logger = Logger.getLogger(DomainManagerImpl.class);
|
||||
|
||||
private String _name;
|
||||
@ -141,7 +141,6 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager{
|
||||
|
||||
_accountMgr.checkAccess(caller, parentDomain);
|
||||
|
||||
|
||||
return createDomain(name, parentId, caller.getId(), networkDomain);
|
||||
|
||||
}
|
||||
@ -149,7 +148,7 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager{
|
||||
@Override
|
||||
@DB
|
||||
public Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain) {
|
||||
//Verify network domain
|
||||
// Verify network domain
|
||||
if (networkDomain != null) {
|
||||
if (!NetUtils.verifyDomainName(networkDomain)) {
|
||||
throw new InvalidParameterValueException(
|
||||
@ -178,7 +177,6 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager{
|
||||
return domain;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DomainVO findDomainByPath(String domainPath) {
|
||||
return _domainDao.findDomainByPath(domainPath);
|
||||
@ -219,7 +217,7 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager{
|
||||
|
||||
@Override
|
||||
public boolean deleteDomain(DomainVO domain, Boolean cleanup) {
|
||||
//mark domain as inactive
|
||||
// mark domain as inactive
|
||||
s_logger.debug("Marking domain id=" + domain.getId() + " as " + Domain.State.Inactive + " before actually deleting it");
|
||||
domain.setState(Domain.State.Inactive);
|
||||
_domainDao.update(domain.getId(), domain);
|
||||
@ -307,7 +305,7 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager{
|
||||
}
|
||||
}
|
||||
|
||||
//don't remove the domain if there are accounts required cleanup
|
||||
// don't remove the domain if there are accounts required cleanup
|
||||
boolean deleteDomainSuccess = true;
|
||||
List<AccountVO> accountsForCleanup = _accountDao.findCleanupsForRemovedAccounts(domainId);
|
||||
if (accountsForCleanup.isEmpty()) {
|
||||
@ -320,7 +318,7 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager{
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DomainVO> searchForDomains(ListDomainsCmd cmd){
|
||||
public List<DomainVO> searchForDomains(ListDomainsCmd cmd) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
Long domainId = cmd.getId();
|
||||
boolean listAll = cmd.listAll();
|
||||
@ -375,7 +373,7 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager{
|
||||
}
|
||||
}
|
||||
|
||||
//return only Active domains to the API
|
||||
// return only Active domains to the API
|
||||
sc.setParameters("state", Domain.State.Active);
|
||||
|
||||
return _domainDao.search(sc, searchFilter);
|
||||
@ -438,4 +436,5 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager{
|
||||
|
||||
return _domainDao.search(sc, searchFilter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
*/
|
||||
package com.cloud.upgrade;
|
||||
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -37,12 +36,14 @@ import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class Test2214To30DBUpgrade extends TestCase {
|
||||
private static final Logger s_logger = Logger.getLogger(Test2214To30DBUpgrade.class);
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(Test2214To30DBUpgrade.class);
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
DbTestUtils.executeScript("PreviousDatabaseSchema/clean-db.sql", false, true);
|
||||
DbTestUtils.executeScript("PreviousDatabaseSchema/clean-db.sql", false,
|
||||
true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,12 +51,17 @@ public class Test2214To30DBUpgrade extends TestCase {
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
public void test2213to30Upgrade() throws SQLException{
|
||||
public void test2213to30Upgrade() throws SQLException {
|
||||
s_logger.debug("Finding sample data from 2.2.14");
|
||||
DbTestUtils.executeScript("PreviousDatabaseSchema/2.2.14/cloud_usage_2214.sql", false, true);
|
||||
DbTestUtils.executeScript("PreviousDatabaseSchema/2.2.14/advance_zone_2.2.14.sql", false, true);
|
||||
DbTestUtils.executeScript(
|
||||
"PreviousDatabaseSchema/2.2.14/cloud_usage_2214.sql", false,
|
||||
true);
|
||||
DbTestUtils.executeScript(
|
||||
"PreviousDatabaseSchema/2.2.14/advance_zone_2.2.14.sql", false,
|
||||
true);
|
||||
|
||||
DatabaseUpgradeChecker checker = ComponentLocator.inject(DatabaseUpgradeChecker.class);
|
||||
DatabaseUpgradeChecker checker = ComponentLocator
|
||||
.inject(DatabaseUpgradeChecker.class);
|
||||
|
||||
checker.upgrade("2.2.14", "3.0.0");
|
||||
|
||||
@ -77,10 +83,12 @@ public class Test2214To30DBUpgrade extends TestCase {
|
||||
protected void checkPhysicalNetworks(Connection conn) throws SQLException {
|
||||
PreparedStatement pstmt;
|
||||
|
||||
pstmt = conn.prepareStatement("SELECT version FROM version ORDER BY id DESC LIMIT 1");
|
||||
pstmt = conn
|
||||
.prepareStatement("SELECT version FROM version ORDER BY id DESC LIMIT 1");
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
assert rs.next() : "No version selected";
|
||||
assert rs.getString(1).equals("3.0.0") : "VERSION stored is not 3.0.0: " + rs.getString(1);
|
||||
assert rs.getString(1).equals("3.0.0") : "VERSION stored is not 3.0.0: "
|
||||
+ rs.getString(1);
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
|
||||
@ -90,11 +98,10 @@ public class Test2214To30DBUpgrade extends TestCase {
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void checkNetworkOfferings(Connection conn) throws SQLException {
|
||||
//1) verify that all fields are present
|
||||
// 1) verify that all fields are present
|
||||
List<String> fields = new ArrayList<String>();
|
||||
fields.add("id");
|
||||
fields.add("name");
|
||||
@ -125,26 +132,29 @@ public class Test2214To30DBUpgrade extends TestCase {
|
||||
|
||||
PreparedStatement pstmt;
|
||||
for (String field : fields) {
|
||||
pstmt = conn.prepareStatement("SHOW COLUMNS FROM network_offerings LIKE ?");
|
||||
pstmt = conn
|
||||
.prepareStatement("SHOW COLUMNS FROM network_offerings LIKE ?");
|
||||
pstmt.setString(1, field);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (!rs.next()) {
|
||||
throw new CloudRuntimeException("Field " + field + " is missing in upgraded network_offerings table");
|
||||
throw new CloudRuntimeException("Field " + field
|
||||
+ " is missing in upgraded network_offerings table");
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
|
||||
}
|
||||
|
||||
//2) compare default network offerings
|
||||
// 2) compare default network offerings
|
||||
}
|
||||
|
||||
protected void checkNetworks(Connection conn) throws SQLException {
|
||||
|
||||
//1) verify that all fields are present
|
||||
// 1) verify that all fields are present
|
||||
List<String> fields = new ArrayList<String>();
|
||||
fields.add("id");
|
||||
fields.add("name");
|
||||
|
||||
fields.add("mode");
|
||||
fields.add("broadcast_domain_type");
|
||||
fields.add("traffic_type");
|
||||
@ -181,15 +191,14 @@ public class Test2214To30DBUpgrade extends TestCase {
|
||||
pstmt.setString(1, field);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (!rs.next()) {
|
||||
throw new CloudRuntimeException("Field " + field + " is missing in upgraded networks table");
|
||||
throw new CloudRuntimeException("Field " + field
|
||||
+ " is missing in upgraded networks table");
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user