AutoScale. Enabled Update commands with UnitTesting. Introduced and tested capability for NetScaler

This commit is contained in:
Vijay 2012-07-18 08:08:47 +05:30
parent a4a15aa737
commit deb70ad200
5 changed files with 57 additions and 63 deletions

View File

@ -35,7 +35,7 @@ public class UpdateAutoScalePolicyCmd extends BaseAsyncCmd {
private Integer quietTime;
@IdentityMapper(entityTableName = "conditions")
@Parameter(name = ApiConstants.CONDITION_IDS, type = CommandType.LIST, collectionType = CommandType.LONG, required = true, description = "the list of IDs of the conditions that are being evaluated on every interval")
@Parameter(name = ApiConstants.CONDITION_IDS, type = CommandType.LIST, collectionType = CommandType.LONG, description = "the list of IDs of the conditions that are being evaluated on every interval")
private List<Long> conditionIds;
@IdentityMapper(entityTableName = "autoscale_policies")

View File

@ -45,21 +45,21 @@ public class UpdateAutoScaleVmGroupCmd extends BaseAsyncCmd {
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@Parameter(name = ApiConstants.MIN_MEMBERS, type = CommandType.INTEGER, required = true, description = "the minimum number of members in the vmgroup, the number of instances in the vm group will be equal to or more than this number.")
private int minMembers;
@Parameter(name = ApiConstants.MIN_MEMBERS, type = CommandType.INTEGER, description = "the minimum number of members in the vmgroup, the number of instances in the vm group will be equal to or more than this number.")
private Integer minMembers;
@Parameter(name = ApiConstants.MAX_MEMBERS, type = CommandType.INTEGER, required = true, description = "the maximum number of members in the vmgroup, The number of instances in the vm group will be equal to or less than this number.")
private int maxMembers;
@Parameter(name = ApiConstants.MAX_MEMBERS, type = CommandType.INTEGER, description = "the maximum number of members in the vmgroup, The number of instances in the vm group will be equal to or less than this number.")
private Integer maxMembers;
@Parameter(name=ApiConstants.INTERVAL, type=CommandType.INTEGER, description="the frequency at which the conditions have to be evaluated")
private Integer interval;
@IdentityMapper(entityTableName = "autoscale_policies")
@Parameter(name = ApiConstants.SCALEUP_POLICY_IDS, type = CommandType.LIST, collectionType = CommandType.LONG, description = "list of provision autoscale policies")
@Parameter(name = ApiConstants.SCALEUP_POLICY_IDS, type = CommandType.LIST, collectionType = CommandType.LONG, description = "list of scaleup autoscale policies")
private List<Long> scaleUpPolicyIds;
@IdentityMapper(entityTableName = "autoscale_policies")
@Parameter(name = ApiConstants.SCALEDOWN_POLICY_IDS, type = CommandType.LIST, collectionType = CommandType.LONG, description = "list of de-provision autoscale policies")
@Parameter(name = ApiConstants.SCALEDOWN_POLICY_IDS, type = CommandType.LIST, collectionType = CommandType.LONG, description = "list of scaledown autoscale policies")
private List<Long> scaleDownPolicyIds;
@IdentityMapper(entityTableName = "autoscale_vmgroups")
@ -91,11 +91,11 @@ public class UpdateAutoScaleVmGroupCmd extends BaseAsyncCmd {
return id;
}
public int getMinMembers() {
public Integer getMinMembers() {
return minMembers;
}
public int getMaxMembers() {
public Integer getMaxMembers() {
return maxMembers;
}

View File

@ -152,6 +152,9 @@ listAutoScaleVmProfiles=com.cloud.api.commands.ListAutoScaleVmProfilesCmd;15
listAutoScaleVmGroups=com.cloud.api.commands.ListAutoScaleVmGroupsCmd;15
enableAutoScaleVmGroup=com.cloud.api.commands.EnableAutoScaleVmGroupCmd;15
disableAutoScaleVmGroup=com.cloud.api.commands.DisableAutoScaleVmGroupCmd;15
updateAutoScalePolicy=com.cloud.api.commands.UpdateAutoScalePolicyCmd;15
updateAutoScaleVmProfile=com.cloud.api.commands.UpdateAutoScaleVmProfileCmd;15
updateAutoScaleVmGroup=com.cloud.api.commands.UpdateAutoScaleVmGroupCmd;15
#### router commands
startRouter=com.cloud.api.commands.StartRouterCmd;7

View File

@ -170,7 +170,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
throw new InvalidParameterException("AutoScale is not supported in the network");
}
for (Counter counter : counters) {
if (!supportedCounters.contains(counter.getSource())) {
if (!supportedCounters.contains(counter.getSource().name().toString())) {
throw new InvalidParameterException("AutoScale counter with source='" + counter.getSource() + "' is not supported " +
"in the network where lb is configured");
}
@ -432,6 +432,9 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
counterIds.add(condition.getCounterid());
}
/* For update case remove the existing mappings and create fresh ones */
_autoScalePolicyConditionMapDao.removeByAutoScalePolicyId(autoScalePolicyVO.getId());
for (Long conditionId : conditionIds) {
AutoScalePolicyConditionMapVO policyConditionMapVO = new AutoScalePolicyConditionMapVO(autoScalePolicyVO.getId(), conditionId);
_autoScalePolicyConditionMapDao.persist(policyConditionMapVO);
@ -657,7 +660,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
AutoScaleVmGroupVO vmGroupVO = new AutoScaleVmGroupVO(cmd.getLbRuleId(), zoneId, loadBalancer.getDomainId(), loadBalancer.getAccountId(), minMembers, maxMembers,
loadBalancer.getDefaultPortStart(), interval, cmd.getProfileId(), AutoScaleVmGroup.State_New);
checkValidityAndPersist(vmGroupVO, cmd.getScaleUpPolicyIds(), cmd.getScaleDownPolicyIds());
vmGroupVO = checkValidityAndPersist(vmGroupVO, cmd.getScaleUpPolicyIds(), cmd.getScaleDownPolicyIds());
return vmGroupVO;
}
@ -779,6 +782,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
int interval = vmGroup.getInterval();
List<Counter> counters = new ArrayList<Counter>();
List<AutoScalePolicyVO> policies = new ArrayList<AutoScalePolicyVO>();
List<Long> policyIds = new ArrayList<Long>();
if (minMembers < 0) {
throw new InvalidParameterValueException(ApiConstants.MIN_MEMBERS + " is an invalid value: " + minMembers);
@ -789,7 +793,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
}
if (minMembers > maxMembers) {
throw new InvalidParameterValueException(ApiConstants.MIN_MEMBERS + " cannot be greater than " + ApiConstants.MAX_MEMBERS + ", range is invalid: " + minMembers + "-" + maxMembers);
throw new InvalidParameterValueException(ApiConstants.MIN_MEMBERS + " (" + minMembers + ")cannot be greater than " + ApiConstants.MAX_MEMBERS + " (" + maxMembers + ")");
}
if (interval < 0) {
@ -805,7 +809,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
}
LoadBalancerVO loadBalancer = getEntityInDatabase(UserContext.current().getCaller(), ApiConstants.LBID, vmGroup.getLoadBalancerId(), _lbDao);
// validateAutoScaleCounters(loadBalancer.getNetworkId(), counters);
validateAutoScaleCounters(loadBalancer.getNetworkId(), counters);
AutoScaleVmProfileVO profileVO = getEntityInDatabase(UserContext.current().getCaller(), ApiConstants.VMPROFILE_ID, vmGroup.getProfileId(), _autoScaleVmProfileDao);
@ -818,8 +822,26 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
txn.start();
vmGroup = _autoScaleVmGroupDao.persist(vmGroup);
for (AutoScalePolicyVO autoScalePolicyVO : policies) {
_autoScaleVmGroupPolicyMapDao.persist(new AutoScaleVmGroupPolicyMapVO(vmGroup.getId(), autoScalePolicyVO.getId()));
if(scaleUpPolicyIds != null || scaleDownPolicyIds != null) {
List<Long> bakupScaleUpPolicyIds = new ArrayList<Long>();
List<Long> bakupScaleDownPolicyIds = new ArrayList<Long>();
ApiDBUtils.getAutoScaleVmGroupPolicyIds(vmGroup.getId(), bakupScaleUpPolicyIds, bakupScaleDownPolicyIds);
if(scaleUpPolicyIds == null) {
policyIds.addAll(bakupScaleUpPolicyIds);
} else {
policyIds.addAll(scaleUpPolicyIds);
}
if(scaleDownPolicyIds == null) {
policyIds.addAll(bakupScaleDownPolicyIds);
} else {
policyIds.addAll(scaleDownPolicyIds);
}
_autoScaleVmGroupPolicyMapDao.removeByGroupId(vmGroup.getId());
for (Long policyId : policyIds) {
_autoScaleVmGroupPolicyMapDao.persist(new AutoScaleVmGroupPolicyMapVO(vmGroup.getId(), policyId));
}
}
txn.commit();
@ -846,8 +868,6 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
return vmGroupVO;
}
AutoScaleVmGroupVO bakUpVmGroupVO = getEntityInDatabase(UserContext.current().getCaller(), "AutoScale Vm Group", vmGroupId, _autoScaleVmGroupDao);
if (!vmGroupVO.getState().equals(AutoScaleVmGroup.State_Disabled)) {
throw new InvalidParameterValueException("An AutoScale Vm Group can be updated only when it is in disabled state");
}
@ -864,39 +884,8 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
vmGroupVO.setInterval(interval);
}
boolean success = true;
List<Long> bakupPolicyIds = new ArrayList<Long>();
if(scaleUpPolicyIds != null || scaleDownPolicyIds != null) {
List<Long> bakupScaleUpPolicyIds = new ArrayList<Long>();
List<Long> bakupScaleDownPolicyIds = new ArrayList<Long>();
ApiDBUtils.getAutoScaleVmGroupPolicyIds(vmGroupId, bakupScaleUpPolicyIds, bakupScaleDownPolicyIds);
if(scaleUpPolicyIds != null) {
bakupPolicyIds.addAll(bakupScaleUpPolicyIds);
}
if(scaleDownPolicyIds != null) {
bakupPolicyIds.addAll(bakupScaleDownPolicyIds);
}
success = _autoScaleVmGroupPolicyMapDao.removeByGroupAndPolicies(vmGroupId, bakupPolicyIds);
if(!success) {
s_logger.warn("Removal of existing policy mappings for vmgroup failed");
return null;
}
}
vmGroupVO = checkValidityAndPersist(vmGroupVO, scaleUpPolicyIds, scaleDownPolicyIds);
try {
success = configureAutoScaleVmGroup(vmGroupVO.getId());
} finally {
if (!success) {
Transaction.currentTxn().start();
for (Long backUpPolicyId : bakupPolicyIds) {
_autoScaleVmGroupPolicyMapDao.persist(new AutoScaleVmGroupPolicyMapVO(vmGroupId, backUpPolicyId));
}
_autoScaleVmGroupDao.update(bakUpVmGroupVO.getId(), bakUpVmGroupVO);
Transaction.currentTxn().commit();
}
}
if (success) {
if (vmGroupVO != null) {
s_logger.debug("Updated Auto Scale VmGroup id:" + vmGroupId);
return vmGroupVO;
} else
@ -916,7 +905,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
try {
vmGroup.setState(AutoScaleVmGroup.State_Enabled);
vmGroup = _autoScaleVmGroupDao.persist(vmGroup);
success = _lbRulesMgr.configureLbAutoScaleVmGroup(id);
success = configureAutoScaleVmGroup(id);
} finally {
if (!success) {
@ -943,7 +932,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
vmGroup.setState(AutoScaleVmGroup.State_Disabled);
vmGroup = _autoScaleVmGroupDao.persist(vmGroup);
success = _lbRulesMgr.configureLbAutoScaleVmGroup(id);
success = configureAutoScaleVmGroup(id);
} finally {
if (!success) {
vmGroup.setState(AutoScaleVmGroup.State_Enabled);

View File

@ -8,7 +8,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.element;
@ -84,7 +84,6 @@ import com.cloud.network.rules.LbStickinessMethod;
import com.cloud.network.rules.LbStickinessMethod.StickinessMethodType;
import com.cloud.network.rules.StaticNat;
import com.cloud.offering.NetworkOffering;
import com.cloud.resource.ServerResource;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.DB;
@ -99,7 +98,7 @@ import com.google.gson.Gson;
@Local(value = NetworkElement.class)
public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl implements LoadBalancingServiceProvider, NetscalerLoadBalancerElementService, ExternalLoadBalancerDeviceManager, IpDeployer,
StaticNatServiceProvider {
StaticNatServiceProvider {
private static final Logger s_logger = Logger.getLogger(NetscalerElement.class);
@ -150,14 +149,14 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
@Override
public boolean implement(Network guestConfig, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException,
InsufficientNetworkCapacityException {
InsufficientNetworkCapacityException {
if (!canHandle(guestConfig, Service.Lb)) {
return false;
}
if (_ntwkSrvcDao.canProviderSupportServiceInNetwork(guestConfig.getId(), Service.StaticNat, Network.Provider.Netscaler) && !isBasicZoneNetwok(guestConfig)) {
s_logger.error("NetScaler provider can not be Static Nat service provider for the network " + guestConfig.getGuestType() +
s_logger.error("NetScaler provider can not be Static Nat service provider for the network " + guestConfig.getGuestType() +
" and traffic type " + guestConfig.getTrafficType());
return false;
}
@ -171,7 +170,7 @@ 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 {
InsufficientNetworkCapacityException, ResourceUnavailableException {
return true;
}
@ -239,6 +238,9 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
// Specifies that load balancing rules can only be made with public IPs that aren't source NAT IPs
lbCapabilities.put(Capability.LoadBalancingSupportedIps, "additional");
// Specifies that load balancing rules can support autoscaling
lbCapabilities.put(Capability.AutoScaleCounters, "snmp,netscaler");
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");
@ -301,7 +303,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
throw new InvalidParameterValueException(msg);
}
ExternalLoadBalancerDeviceVO lbDeviceVO = addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceName, (ServerResource) new NetscalerResource());
ExternalLoadBalancerDeviceVO lbDeviceVO = addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceName, new NetscalerResource());
return lbDeviceVO;
}
@ -361,7 +363,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
}
if (inline != null) {
boolean _setInline = Boolean.parseBoolean((String) lbDetails.get("inline"));
boolean _setInline = Boolean.parseBoolean(lbDetails.get("inline"));
if (inline != _setInline) {
throw new CloudRuntimeException("There are networks already using this netscaler device to change the device inline or side-by-side configuration");
}
@ -497,7 +499,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
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
// state
if (lbDevices != null && !lbDevices.isEmpty()) {
for (ExternalLoadBalancerDeviceVO lbDevice : lbDevices) {
if (lbDevice.getState() == LBDeviceState.Enabled) {
@ -510,7 +512,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
@Override
public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException {
ResourceUnavailableException {
// TODO reset the configuration on all of the netscaler devices in this physical network
return true;
}
@ -538,8 +540,8 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
// NetScaler can only act as Lb and Static Nat service provider
if (services != null && !services.isEmpty() && !netscalerServices.containsAll(services)) {
s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination "
+ services + " is not supported.");
s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination "
+ services + " is not supported.");
return false;
}