AutoScale.

NetScaler changes for deleteAutoScaleVmGroup and min/max member
    policies - Tested
    Introducing apikey/sharedsecret/csurl empty checks as well
    Introducing the autoscale change sheet that got deleted during the merge
This commit is contained in:
Vijay 2012-07-24 19:25:22 +05:30
parent 62082b0de6
commit 04b51bb6ba
6 changed files with 145 additions and 53 deletions

View File

@ -44,6 +44,13 @@ public class ListAutoScalePoliciesCmd extends BaseListAccountResourcesCmd {
@Parameter(name = ApiConstants.CONDITION_ID, type = CommandType.LONG, description = "the ID of the condition of the policy")
private Long conditionId;
@Parameter(name = ApiConstants.ACTION, type = CommandType.STRING, required = true, description = "the action to be executed if all the conditions evaluate to true for the specified duration.")
private String action;
@IdentityMapper(entityTableName="autoscale_vmgroups")
@Parameter(name = ApiConstants.VMGROUP_ID, type = CommandType.LONG, description = "the ID of the autoscale vm group")
private Long vmGroupId;
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@ -56,6 +63,13 @@ public class ListAutoScalePoliciesCmd extends BaseListAccountResourcesCmd {
return conditionId;
}
public String getAction() {
return action;
}
public Long getVmGroupId() {
return vmGroupId;
}
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////

View File

@ -49,6 +49,9 @@ public class ListConditionsCmd extends BaseListAccountResourcesCmd {
@Parameter(name = ApiConstants.COUNTER_ID, type = CommandType.LONG, required = false, description = "Counter-id of the condition.")
private Long counterId;
@IdentityMapper(entityTableName="autoscale_policies")
@Parameter(name = ApiConstants.POLICY_ID, type = CommandType.LONG, description = "the ID of the policy")
private Long policyId;
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@ -81,6 +84,10 @@ public class ListConditionsCmd extends BaseListAccountResourcesCmd {
return counterId;
}
public Long getPolicyId() {
return policyId;
}
@Override
public String getCommandName() {
return s_name;

View File

@ -13,7 +13,6 @@
package com.cloud.network.resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Formatter;
import java.util.HashMap;
import java.util.List;
@ -282,7 +281,7 @@ public class NetscalerResource implements ServerResource {
return;
}
try {
String[] features = _netscalerService.get_enabled_features();
String[] features = login_get_service(true).get_enabled_features();
if (features != null) {
for (String feature : features) {
if (feature.equalsIgnoreCase("LB")) {
@ -294,7 +293,7 @@ public class NetscalerResource implements ServerResource {
// enable load balancing on the device
String[] feature = new String[1];
feature[0] = "LB";
apiCallResult = _netscalerService.enable_features(feature);
apiCallResult = login_get_service(true).enable_features(feature);
if (apiCallResult.errorcode != 0) {
throw new ExecutionException("Enabling load balancing feature on the device failed.");
}
@ -466,18 +465,31 @@ public class NetscalerResource implements ServerResource {
return autoScalePolicyTO.getAction().equals("scaledown");
}
private long allocateNextAvailablePriority(List<Long> priorities) {
long cur_prirotiy = 1;
Collections.sort(priorities);
for (Long priority : priorities) {
if(cur_prirotiy != priority) {
priorities.add(cur_prirotiy);
return cur_prirotiy;
}
cur_prirotiy++;
private void removeAutoScalePolicy(String timerName, String policyName) throws Exception {
// unbind timer policy
// unbbind timer trigger lb_astimer -policyName lb_policy_scaleUp
com.citrix.netscaler.nitro.resource.config.timer.timertrigger_timerpolicy_binding timer_policy_binding = new com.citrix.netscaler.nitro.resource.config.timer.timertrigger_timerpolicy_binding();
try {
timer_policy_binding.set_name(timerName);
timer_policy_binding.set_policyname(policyName);
timer_policy_binding.set_global("DEFAULT");
timer_policy_binding.delete(login_get_service(true), timer_policy_binding);
} catch (Exception e) {
// Ignore Exception
throw e;
}
priorities.add(cur_prirotiy);;
return cur_prirotiy;
// Removing Timer policy
// rm timer policy lb_policy_scaleUp_cpu_mem
com.citrix.netscaler.nitro.resource.config.timer.timerpolicy timerPolicy = new com.citrix.netscaler.nitro.resource.config.timer.timerpolicy();
try {
timerPolicy.set_name(policyName);
timerPolicy.delete(login_get_service(true), timerPolicy);
} catch (Exception e) {
// Ignore Exception
throw e;
}
}
@SuppressWarnings("static-access")
@ -542,9 +554,18 @@ public class NetscalerResource implements ServerResource {
String scaleUpActionName = generateAutoScaleScaleUpActionName(srcIp, srcPort);
String mtName = generateSnmpMetricTableName(srcIp, srcPort);
String monitorName = generateSnmpMonitorName(srcIp, srcPort);
String serviceGroupName = generateAutoScaleServiceGroupName(srcIp, srcPort);
AutoScaleVmGroupTO vmGroupTO = loadBalancerTO.getAutoScaleVmGroupTO();
List<AutoScalePolicyTO> policies = vmGroupTO.getPolicies();
/* Delete min/max member policies */
String minMemberPolicyName = generateAutoScaleMinPolicyName(srcIp, srcPort);
removeAutoScalePolicy(timerName, minMemberPolicyName);
String maxMemberPolicyName = generateAutoScaleMaxPolicyName(srcIp, srcPort);
removeAutoScalePolicy(timerName, maxMemberPolicyName);
boolean isSnmp = false;
/* Create Counters */
for (AutoScalePolicyTO autoScalePolicyTO : policies) {
@ -558,27 +579,9 @@ public class NetscalerResource implements ServerResource {
}
String policyId = Long.toString(autoScalePolicyTO.getId());
String policyName = generateAutoScalePolicyName(srcIp, srcPort,policyId);
// unbind timer policy
// unbbind timer trigger lb_astimer -policyName lb_policy_scaleUp
com.citrix.netscaler.nitro.resource.config.timer.timertrigger_timerpolicy_binding timer_policy_binding = new com.citrix.netscaler.nitro.resource.config.timer.timertrigger_timerpolicy_binding();
try {
timer_policy_binding.set_name(timerName);
timer_policy_binding.set_policyname(policyName);
timer_policy_binding.delete(login_get_service(true), timer_policy_binding);
} catch (Exception e) {
// Ignore Exception
throw e;
}
// Removing Timer policy
// rm timer policy lb_policy_scaleUp_cpu_mem
com.citrix.netscaler.nitro.resource.config.timer.timerpolicy timerPolicy = new com.citrix.netscaler.nitro.resource.config.timer.timerpolicy();
try {
timerPolicy.set_name(policyName);
timerPolicy.delete(login_get_service(true), timerPolicy);
} catch (Exception e) {
// Ignore Exception
throw e;
}
removeAutoScalePolicy(timerName, policyName);
}
/* Delete AutoScale Config */
@ -623,11 +626,22 @@ public class NetscalerResource implements ServerResource {
}
if(isSnmp) {
com.citrix.netscaler.nitro.resource.config.lb.lbmonitor_servicegroup_binding monitor_servicegroup_binding = new com.citrix.netscaler.nitro.resource.config.lb.lbmonitor_servicegroup_binding();
try {
monitor_servicegroup_binding.set_monitorname(monitorName);
monitor_servicegroup_binding.set_servicegroupname(serviceGroupName);
monitor_servicegroup_binding.delete(login_get_service(true), monitor_servicegroup_binding);
} catch (Exception e) {
// Ignore Exception
throw e;
}
// Delete Monitor
// rm lb monitor lb_metric_table_mon
com.citrix.netscaler.nitro.resource.config.lb.lbmonitor monitor = new com.citrix.netscaler.nitro.resource.config.lb.lbmonitor();
try {
monitor.set_monitorname(monitorName);
monitor.set_type("LOAD");
monitor.delete(login_get_service(true), monitor);
} catch (Exception e) {
// Ignore Exception
@ -637,7 +651,7 @@ public class NetscalerResource implements ServerResource {
// Delete Metric Table
com.citrix.netscaler.nitro.resource.config.lb.lbmetrictable metricTable = new com.citrix.netscaler.nitro.resource.config.lb.lbmetrictable();
try {
metricTable.set_metric(mtName);
metricTable.set_metrictable(mtName);
metricTable.delete(login_get_service(true), metricTable);
} catch (Exception e) {
// Ignore Exception
@ -715,13 +729,11 @@ public class NetscalerResource implements ServerResource {
int interval = vmGroupTO.getInterval();
int snmpPort = profileTO.getSnmpPort();
String snmpCommunity = profileTO.getSnmpCommunity();
ArrayList<Long> priorities = new ArrayList<Long>();
long cur_prirotiy = 1;
// Set min and max autoscale members;
// add lb vserver lb http 10.102.31.100 80 -minAutoscaleMinMembers 3 -maxAutoscaleMembers 10
/*
int minAutoScaleMembers = vmGroupTO.getMinMembers();
int maxAutoScaleMembers = vmGroupTO.getMaxMembers();
com.citrix.netscaler.nitro.resource.config.lb.lbvserver lbvserver = new com.citrix.netscaler.nitro.resource.config.lb.lbvserver();
@ -734,7 +746,6 @@ public class NetscalerResource implements ServerResource {
// Ignore Exception
throw e;
}
*/
/* AutoScale Config */
// Add AutoScale Profile
@ -755,7 +766,7 @@ public class NetscalerResource implements ServerResource {
} catch (Exception e) {
// Ignore Exception
// throw e;
throw e;
}
// Add Timer
@ -841,7 +852,7 @@ public class NetscalerResource implements ServerResource {
interval, interval);
/* Create max member policy */
String maxMemberPolicyName = generateAutoScaleMinPolicyName(srcIp, srcPort);
String maxMemberPolicyName = generateAutoScaleMaxPolicyName(srcIp, srcPort);
String maxMemberPolicyExp = "SYS.VSERVER(\"" + nsVirtualServerName + "\").ACTIVESERVICES.GT(SYS.VSERVER(\"" + nsVirtualServerName + "\").MAXAUTOSCALEMEMBERS)";
addAutoScalePolicy(timerName, maxMemberPolicyName, cur_prirotiy++, maxMemberPolicyExp, scaleDownActionName,
interval, interval);
@ -2023,14 +2034,6 @@ public class NetscalerResource implements ServerResource {
vserver.set_persistencetype("NONE");
}
}
if(vmGroupTO != null) {
vserver.set_minautoscalemembers(vmGroupTO.getMinMembers());
vserver.set_maxautoscalemembers(vmGroupTO.getMaxMembers());
vserver.set_mysqlcharacterset(null);
vserver.set_mysqlprotocolversion(null);
vserver.set_mysqlservercapabilities(null);
vserver.set_mssqlserverversion(null);
}
if (vserverExisis) {
apiCallResult = lbvserver.update(login_get_service(vmGroupTO != null),vserver);
@ -2251,4 +2254,7 @@ public class NetscalerResource implements ServerResource {
return;
}
}

Binary file not shown.

View File

@ -43,7 +43,9 @@ import com.cloud.api.commands.ListCountersCmd;
import com.cloud.api.commands.UpdateAutoScalePolicyCmd;
import com.cloud.api.commands.UpdateAutoScaleVmGroupCmd;
import com.cloud.api.commands.UpdateAutoScaleVmProfileCmd;
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.dao.DataCenterDao;
import com.cloud.event.ActionEvent;
@ -127,6 +129,8 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
@Inject
UserDao _userDao;
@Inject
ConfigurationDao _configDao;
@Inject
IPAddressDao _ipAddressDao;
@Override
@ -168,7 +172,7 @@ 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");
}
}
}
@ -258,11 +262,27 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
throw new InvalidParameterValueException("Destroy Vm Grace Period cannot be less than 0.");
}
User autoscaleUser = _userDao.findById(autoscaleUserId);
if (autoscaleUser.getAccountId() != vmProfile.getAccountId()) {
User user = _userDao.findById(autoscaleUserId);
if (user.getAccountId() != vmProfile.getAccountId()) {
throw new InvalidParameterValueException("AutoScale User id does not belong to the same account");
}
String apiKey = user.getApiKey();
String secretKey = user.getSecretKey();
String csUrl = _configDao.getValue(Config.EndpointeUrl.key());
if(apiKey == null) {
throw new InvalidParameterValueException("apiKey for user: " + user.getUsername() + " is empty. Please generate it");
}
if(secretKey == null) {
throw new InvalidParameterValueException("secretKey for user: " + user.getUsername() + " is empty. Please generate it");
}
if(csUrl == null || csUrl.contains("localhost")) {
throw new InvalidParameterValueException("Global setting endpointe.url has to be set to the Management Server's API end point");
}
vmProfile = _autoScaleVmProfileDao.persist(vmProfile);
return vmProfile;
@ -304,6 +324,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
autoscaleUserId = UserContext.current().getCallerUserId();
}
AutoScaleVmProfileVO profileVO = new AutoScaleVmProfileVO(cmd.getZoneId(), cmd.getDomainId(), cmd.getAccountId(), cmd.getServiceOfferingId(), cmd.getTemplateId(), cmd.getOtherDeployParams(),
cmd.getSnmpCommunity(), cmd.getSnmpPort(), cmd.getDestroyVmGraceperiod(), autoscaleUserId);
profileVO = checkValidityAndPersist(profileVO);
@ -542,7 +563,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();
@ -574,8 +595,11 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
SearchBuilder<AutoScalePolicyVO> sb = searchWrapper.getSearchBuilder();
Long id = cmd.getId();
Long conditionId = cmd.getConditionId();
String action = cmd.getAction();
Long vmGroupId = cmd.getVmGroupId();
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("action", sb.entity().getAction(), SearchCriteria.Op.EQ);
if (conditionId != null) {
SearchBuilder<AutoScalePolicyConditionMapVO> asPolicyConditionSearch = _autoScalePolicyConditionMapDao.createSearchBuilder();
@ -583,15 +607,30 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
sb.join("asPolicyConditionSearch", asPolicyConditionSearch, sb.entity().getId(), asPolicyConditionSearch.entity().getPolicyId(), JoinBuilder.JoinType.INNER);
}
if (vmGroupId != null) {
SearchBuilder<AutoScaleVmGroupPolicyMapVO> asVmGroupPolicySearch = _autoScaleVmGroupPolicyMapDao.createSearchBuilder();
asVmGroupPolicySearch.and("vmGroupId", asVmGroupPolicySearch.entity().getVmGroupId(), SearchCriteria.Op.EQ);
sb.join("asVmGroupPolicySearch", asVmGroupPolicySearch, sb.entity().getId(), asVmGroupPolicySearch.entity().getPolicyId(), JoinBuilder.JoinType.INNER);
}
SearchCriteria<AutoScalePolicyVO> sc = searchWrapper.buildSearchCriteria();
if (id != null) {
sc.setParameters("id", id);
}
if (action != null) {
sc.setParameters("action", action);
}
if (conditionId != null) {
sc.setJoinParameters("asPolicyConditionSearch", "conditionId", conditionId);
}
if (vmGroupId != null) {
sc.setJoinParameters("asVmGroupPolicySearch", "vmGroupId", vmGroupId);
}
return searchWrapper.search();
}
@ -682,7 +721,11 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
AutoScaleVmGroup vmGroup = _autoScaleVmGroupDao.findById(vmGroupid);
if (isLoadBalancerBasedAutoScaleVmGroup(vmGroup)) {
return _lbRulesMgr.configureLbAutoScaleVmGroup(vmGroupid);
try {
return _lbRulesMgr.configureLbAutoScaleVmGroup(vmGroupid);
} catch (RuntimeException re) {
s_logger.warn("Exception during configureLbAutoScaleVmGrouop in lb rules manager", re);
}
}
// This should never happen, because today loadbalancerruleid is manadatory for AutoScaleVmGroup.
@ -1011,8 +1054,14 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
public List<? extends Condition> listConditions(ListConditionsCmd cmd) {
Long id = cmd.getId();
Long counterId = cmd.getCounterId();
Long policyId = cmd.getPolicyId();
SearchWrapper<ConditionVO> searchWrapper = new SearchWrapper<ConditionVO>(_conditionDao, ConditionVO.class, cmd, cmd.getId());
SearchBuilder<ConditionVO> sb = searchWrapper.getSearchBuilder();
if (policyId != null) {
SearchBuilder<AutoScalePolicyConditionMapVO> asPolicyConditionSearch = _autoScalePolicyConditionMapDao.createSearchBuilder();
asPolicyConditionSearch.and("policyId", asPolicyConditionSearch.entity().getPolicyId(), SearchCriteria.Op.EQ);
sb.join("asPolicyConditionSearch", asPolicyConditionSearch, sb.entity().getId(), asPolicyConditionSearch.entity().getConditionId(), JoinBuilder.JoinType.INNER);
}
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("counterId", sb.entity().getCounterid(), SearchCriteria.Op.EQ);
@ -1028,6 +1077,10 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
sc.setParameters("counterId", counterId);
}
if (policyId != null) {
sc.setJoinParameters("asPolicyConditionSearch", "policyId", policyId);
}
return searchWrapper.search();
}

View File

@ -259,6 +259,18 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
String secretKey = user.getSecretKey();
String csUrl = _configDao.getValue(Config.EndpointeUrl.key());
if(apiKey == null) {
throw new InvalidParameterValueException("apiKey for user: " + user.getUsername() + " is empty. Please generate it");
}
if(secretKey == null) {
throw new InvalidParameterValueException("secretKey for user: " + user.getUsername() + " is empty. Please generate it");
}
if(csUrl == null || csUrl.contains("localhost")) {
throw new InvalidParameterValueException("Global setting endpointe.url has to be set to the Management Server's API end point");
}
LbAutoScaleVmProfile lbAutoScaleVmProfile = new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, csUrl);
return new LbAutoScaleVmGroup(vmGroup, autoScalePolicies, lbAutoScaleVmProfile);
}