AutoScale. Enabling AutoScale to go to the Resource.

Tested the reachability for Basic Network.
Fixing compile error introduced due to a89919ce2ffd9a0a99f1810aeaa0488b0805f665
This commit is contained in:
Vijay 2012-07-18 22:55:46 +05:30
parent a96df19b68
commit f9bcf3186c
4 changed files with 68 additions and 47 deletions

View File

@ -42,6 +42,9 @@ public class LoadBalancerTO {
final static int MAX_STICKINESS_POLICIES = 1;
public LoadBalancerTO(Long id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<LbDestination> destinations) {
if(destinations == null) { // for autoscaleconfig destinations will be null;
destinations = new ArrayList<LbDestination>();
}
this.id = id;
this.srcIp = srcIp;
this.srcPort = srcPort;

View File

@ -37,6 +37,7 @@ import com.citrix.netscaler.nitro.resource.config.network.vlan_nsip_binding;
import com.citrix.netscaler.nitro.resource.config.ns.nsconfig;
import com.citrix.netscaler.nitro.resource.config.ns.nshardware;
import com.citrix.netscaler.nitro.resource.config.ns.nsip;
import com.citrix.netscaler.nitro.resource.config.autoscale.*;
import com.citrix.netscaler.nitro.resource.stat.lb.lbvserver_stats;
import com.citrix.netscaler.nitro.service.nitro_service;
import com.citrix.netscaler.nitro.util.filtervalue;
@ -850,13 +851,10 @@ public class NetscalerResource implements ServerResource {
}
}
// formatter.format("SYS.CUR_VSERVER.METRIC_TABLE(%s).AVG_VAL.%s(%ld)",counterName, operator,
// threshold);
boolean newMetric = !snmpMetrics.containsKey(counterName);
if(newMetric) {
snmpMetrics.put(counterName, snmpCounterNumber++);
}
formatter.format("SYS.VSERVER.SNMP_TABLE(%d).AVG_VAL.%s(%d)",snmpMetrics.get(counterName), operator, threshold);
if(newMetric)
{
@ -885,10 +883,14 @@ public class NetscalerResource implements ServerResource {
throw e;
}
}
// SYS.VSERVER("abcd").SNMP_TABLE(0).AVERAGE_VALUE.GT(80)
int counterIndex = snmpMetrics.get(counterName); // TODO: temporary fix. later on counter name will be added as a param to SNMP_TABLE.
formatter.format("SYS.VSERVER(%s).SNMP_TABLE(%d).AVERAGE_VALUE.%s(%d)",nsVirtualServerName, counterIndex, operator, threshold);
}
else if (counterTO.getSource().equals("netscaler"))
{
formatter.format("SYS.VSERVER(%s).%s.AVG_VAL.%s(%d)",nsVirtualServerName, counterName, operator, threshold);
//SYS.VSERVER("abcd").RESPTIME.GT(10)
formatter.format("SYS.VSERVER(%s).%s.%s(%d)",nsVirtualServerName, counterTO.getValue(), operator, threshold);
}
if(policyExpression.length() != 0) {
policyExpression += " && ";
@ -915,7 +917,9 @@ public class NetscalerResource implements ServerResource {
}
// bind timer policy
// For now it is bound globally.
// bind timer trigger lb_astimer -policyName lb_policy_scaleUp -vserver lb -priority 1 -samplesize 5
// TODO: later bind to lbvserver. bind timer trigger lb_astimer -policyName lb_policy_scaleUp -vserver lb -priority 1 -samplesize 5
// -thresholdsize 5
com.citrix.netscaler.nitro.resource.config.timer.timertrigger_timerpolicy_binding timer_policy_binding = new com.citrix.netscaler.nitro.resource.config.timer.timertrigger_timerpolicy_binding();
int sampleSize = autoScalePolicyTO.getDuration()/interval;
@ -923,7 +927,8 @@ public class NetscalerResource implements ServerResource {
try {
timer_policy_binding.set_name(timerName);
timer_policy_binding.set_policyname(policyName);
timer_policy_binding.set_vserver(nsVirtualServerName);
// timer_policy_binding.set_vserver(nsVirtualServerName);
timer_policy_binding.set_global("GLOBAL_DEFAULT"); // vserver name is present at the expression
timer_policy_binding.set_samplesize(sampleSize);
timer_policy_binding.set_thresholdsize(sampleSize); // We are not exposing this parameter as of now.
// i.e. n(m) is not exposed to CS user. So thresholdSize == sampleSize
@ -941,6 +946,9 @@ public class NetscalerResource implements ServerResource {
private synchronized void applyAutoScaleConfig(LoadBalancerTO loadBalancer) throws Exception, ExecutionException {
AutoScaleVmGroupTO vmGroupTO = loadBalancer.getAutoScaleVmGroupTO();
if(!isAutoScaleSupportedInNetScaler()) {
}
if(vmGroupTO.getState().equals("New")) {
assert !loadBalancer.isRevoked();
createAutoScaleConfig(loadBalancer);
@ -958,6 +966,21 @@ public class NetscalerResource implements ServerResource {
}
}
private boolean isAutoScaleSupportedInNetScaler() throws ExecutionException {
autoscaleprofile autoscaleProfile = new autoscaleprofile();
try {
autoscaleProfile.get(_netscalerService);
} catch (Exception ex) {
// Looks like autoscale is not supported in this netscaler.
// TODO: Config team has introduce a new command to check
// the list of entities supported in a NetScaler. Can use that
// once it is present in AutoScale branch.
throw new ExecutionException("AutoScale is not supported in NetScaler");
}
// TODO Auto-generated method stub
return false;
}
private synchronized Answer execute(LoadBalancerConfigCommand cmd, int numRetries) {
try {
if (_isSdx) {

View File

@ -89,7 +89,7 @@ import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.net.NetUtils;
@Local(value = { AutoScaleService.class })
@Local(value = { AutoScaleService.class })
public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
private static final Logger s_logger = Logger.getLogger(AutoScaleManagerImpl.class);
@ -172,12 +172,12 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
for (Counter counter : counters) {
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");
"in the network where lb is configured");
}
}
}
private <VO extends ControlledEntity> VO getEntityInDatabase(Account caller, String paramName, Long id, GenericDao<VO, Long> dao)
private <VO extends ControlledEntity> VO getEntityInDatabase(Account caller,String paramName, Long id, GenericDao<VO, Long> dao)
{
VO vo = dao.findById(id);
@ -247,7 +247,8 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
return policies;
}
private AutoScaleVmProfileVO checkValidityAndPersist(AutoScaleVmProfileVO vmProfile) {
@DB
protected AutoScaleVmProfileVO checkValidityAndPersist(AutoScaleVmProfileVO vmProfile) {
long templateId = vmProfile.getTemplateId();
long autoscaleUserId = vmProfile.getAutoScaleUserId();
int destroyVmGraceperiod = vmProfile.getDestroyVmGraceperiod();
@ -273,7 +274,6 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMPROFILE_CREATE, eventDescription = "creating autoscale vm profile")
public AutoScaleVmProfile createAutoScaleVmProfile(CreateAutoScaleVmProfileCmd cmd) {
@ -314,7 +314,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
String mgmtIP = _configDao.getValue(Config.ManagementHostIPAdr.key());
csUrl = "http://" + mgmtIP + ":8080/client/api?";
} else {
if (!csUrl.endsWith("?"))
if(!csUrl.endsWith("?"))
csUrl += "?";
}
@ -327,7 +327,6 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMPROFILE_UPDATE, eventDescription = "updating autoscale vm profile")
public AutoScaleVmProfile updateAutoScaleVmProfile(UpdateAutoScaleVmProfileCmd cmd) {
Long profileId = cmd.getId();
@ -382,7 +381,9 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
throw new InvalidParameterValueException("Cannot delete AutoScale Vm Profile when it is in use by one more vm groups");
}
boolean success = _autoScaleVmProfileDao.remove(id);
s_logger.info("Successfully deleted AutoScale Vm Profile with Id: " + id);
if(success) {
s_logger.info("Successfully deleted AutoScale Vm Profile with Id: " + id);
}
return success;
}
@ -412,6 +413,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
return searchWrapper.search();
}
@DB
private AutoScalePolicyVO checkValidityAndPersist(AutoScalePolicyVO autoScalePolicyVO, List<Long> conditionIds) {
int duration = autoScalePolicyVO.getDuration();
int quietTime = autoScalePolicyVO.getQuietTime();
@ -429,7 +431,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
autoScalePolicyVO = _autoScalePolicyDao.persist(autoScalePolicyVO);
if (conditionIds != null) {
if(conditionIds != null) {
SearchBuilder<ConditionVO> conditionsSearch = _conditionDao.createSearchBuilder();
conditionsSearch.and("ids", conditionsSearch.entity().getId(), Op.IN);
conditionsSearch.done();
@ -469,7 +471,6 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEPOLICY_CREATE, eventDescription = "creating autoscale policy")
public AutoScalePolicy createAutoScalePolicy(CreateAutoScalePolicyCmd cmd) {
@ -488,7 +489,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
AutoScalePolicyVO policyVO = new AutoScalePolicyVO(cmd.getDomainId(), cmd.getAccountId(), duration, quietTime, action);
policyVO = checkValidityAndPersist(policyVO, cmd.getConditionIds());
policyVO = checkValidityAndPersist(policyVO, cmd.getConditionIds());
s_logger.info("Successfully created AutoScale Policy with Id: " + policyVO.getId());
return policyVO;
}
@ -520,7 +521,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
}
txn.commit();
s_logger.info("Successfully deleted autoscale policy id : " + id);
return success; // successful
return true; // successful
}
public void checkCallerAccess(String accountName, Long domainId)
@ -556,7 +557,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
Account caller = UserContext.current().getCaller();
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
ListProjectResourcesCriteria>(domainId, isRecursive, null);
ListProjectResourcesCriteria>(domainId, isRecursive, null);
_accountMgr.buildACLSearchParameters(caller, id, accountName, null, permittedAccounts, domainIdRecursiveListProject,
listAll, false);
domainId = domainIdRecursiveListProject.first();
@ -610,7 +611,6 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEPOLICY_UPDATE, eventDescription = "updating autoscale policy")
public AutoScalePolicy updateAutoScalePolicy(UpdateAutoScalePolicyCmd cmd) {
Long policyId = cmd.getId();
@ -633,41 +633,35 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
if (!vmGroupVO.getState().equals(AutoScaleVmGroup.State_Disabled)) {
throw new InvalidParameterValueException("The AutoScale Policy can be updated only if the Vm Group it is associated with is disabled in state");
}
if (vmGroupVO.getInterval() < policy.getDuration()) {
if(vmGroupVO.getInterval() < policy.getDuration()) {
throw new InvalidParameterValueException("duration is less than the associated AutoScaleVmGroup's interval");
}
if (vmGroupVO.getInterval() < policy.getQuietTime()) {
if(vmGroupVO.getInterval() < policy.getQuietTime()) {
throw new InvalidParameterValueException("quietTime is less than the associated AutoScaleVmGroup's interval");
}
}
policy = checkValidityAndPersist(policy, conditionIds);
s_logger.info("Successfully updated Auto Scale Policy id:" + policyId);
return policy;
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMGROUP_CREATE, eventDescription = "creating autoscale vm group")
public AutoScaleVmGroup createAutoScaleVmGroup(CreateAutoScaleVmGroupCmd cmd) {
int minMembers = cmd.getMinMembers();
int maxMembers = cmd.getMaxMembers();
Integer interval = cmd.getInterval();
if (interval == null) {
if(interval == null) {
interval = NetUtils.DEFAULT_AUTOSCALE_POLICY_INTERVAL_TIME;
}
LoadBalancerVO loadBalancer = getEntityInDatabase(UserContext.current().getCaller(), ApiConstants.LBID, cmd.getLbRuleId(), _lbDao);
// Account owner = _accountDao.findById(loadBalancer.getAccountId());
// Account caller = UserContext.current().getCaller();
// _accountMgr.checkAccess(caller, null, true, owner);
Long zoneId = _ipAddressDao.findById(loadBalancer.getSourceIpAddressId()).getDataCenterId();
if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(loadBalancer.getId())) {
if(_autoScaleVmGroupDao.isAutoScaleLoadBalancer(loadBalancer.getId())) {
throw new InvalidParameterValueException("an AutoScaleVmGroup is already attached to the lb rule, the existing vm group has to be first deleted");
}
@ -696,12 +690,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
public boolean configureAutoScaleVmGroup(long vmGroupid) {
AutoScaleVmGroup vmGroup = _autoScaleVmGroupDao.findById(vmGroupid);
/* TODO remove later */
if (true) {
return true;
}
if (isLoadBalancerBasedAutoScaleVmGroup(vmGroup)) {
if(isLoadBalancerBasedAutoScaleVmGroup(vmGroup)) {
return _lbRulesMgr.configureLbAutoScaleVmGroup(vmGroupid);
}
@ -715,7 +704,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
public boolean deleteAutoScaleVmGroup(long id) {
AutoScaleVmGroupVO autoScaleVmGroupVO = getEntityInDatabase(UserContext.current().getCaller(), "AutoScale Vm Group", id, _autoScaleVmGroupDao);
if (autoScaleVmGroupVO.getState().equals(AutoScaleVmGroup.State_New)) {
if(autoScaleVmGroupVO.getState().equals(AutoScaleVmGroup.State_New)) {
/* This condition is for handling failures during creation command */
return _autoScaleVmGroupDao.remove(id);
}
@ -727,7 +716,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
try {
success = configureAutoScaleVmGroup(id);
} finally {
if (!success) {
if(!success) {
s_logger.warn("Could not delete AutoScale Vm Group id : " + id);
autoScaleVmGroupVO.setState(bakupState);
_autoScaleVmGroupDao.persist(autoScaleVmGroupVO);
@ -796,7 +785,8 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
return searchWrapper.search();
}
private AutoScaleVmGroupVO checkValidityAndPersist(AutoScaleVmGroupVO vmGroup, List<Long> scaleUpPolicyIds, List<Long> scaleDownPolicyIds) {
@DB
protected AutoScaleVmGroupVO checkValidityAndPersist(AutoScaleVmGroupVO vmGroup, List<Long> scaleUpPolicyIds, List<Long> scaleDownPolicyIds) {
int minMembers = vmGroup.getMinMembers();
int maxMembers = vmGroup.getMaxMembers();
int interval = vmGroup.getInterval();
@ -820,11 +810,11 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
throw new InvalidParameterValueException("interval is an invalid value: " + interval);
}
if (scaleUpPolicyIds != null) {
if(scaleUpPolicyIds != null) {
policies.addAll(getAutoScalePolicies("scaleuppolicyid", scaleUpPolicyIds, counters, interval, true));
}
if (scaleDownPolicyIds != null) {
if(scaleDownPolicyIds != null) {
policies.addAll(getAutoScalePolicies("scaledownpolicyid", scaleDownPolicyIds, counters, interval, false));
}
@ -842,16 +832,16 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
txn.start();
vmGroup = _autoScaleVmGroupDao.persist(vmGroup);
if (scaleUpPolicyIds != null || scaleDownPolicyIds != null) {
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) {
if(scaleUpPolicyIds == null) {
policyIds.addAll(bakupScaleUpPolicyIds);
} else {
policyIds.addAll(scaleUpPolicyIds);
}
if (scaleDownPolicyIds == null) {
if(scaleDownPolicyIds == null) {
policyIds.addAll(bakupScaleDownPolicyIds);
} else {
policyIds.addAll(scaleDownPolicyIds);
@ -870,7 +860,6 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
@Override
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMGROUP_UPDATE, eventDescription = "updating autoscale vm group")
@DB
public AutoScaleVmGroup updateAutoScaleVmGroup(UpdateAutoScaleVmGroupCmd cmd) {
Long vmGroupId = cmd.getId();
Integer minMembers = cmd.getMinMembers();
@ -1018,7 +1007,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
String name = cmd.getName();
Long id = cmd.getId();
String source = cmd.getSource();
if (source != null)
if(source != null )
source = source.toLowerCase();
Filter searchFilter = new Filter(CounterVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal());
@ -1090,7 +1079,10 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
throw new ResourceInUseException("Cannot delete Condition when it is in use by one or more AutoScale Policies.");
}
boolean success = _conditionDao.remove(conditionId);
s_logger.info("Successfully deleted condition " + condition.getId());
if(success) {
s_logger.info("Successfully deleted condition " + condition.getId());
}
return success;
}
}

View File

@ -600,8 +600,11 @@ StaticNatServiceProvider {
int srcPort = rule.getSourcePortStart();
List<LbDestination> destinations = rule.getDestinations();
if (destinations != null && !destinations.isEmpty()) {
if (destinations != null && !destinations.isEmpty() || rule.isAutoScaleConfig()) {
LoadBalancerTO loadBalancer = new LoadBalancerTO(rule.getId(), srcIp, srcPort, protocol, algorithm, revoked, false, destinations, rule.getStickinessPolicies());
if(rule.isAutoScaleConfig()) {
loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup());
}
loadBalancersToApply.add(loadBalancer);
}
}