diff --git a/api/src/com/cloud/agent/api/to/LoadBalancerTO.java b/api/src/com/cloud/agent/api/to/LoadBalancerTO.java index 44f7ab3f04c..81b8234dfd2 100644 --- a/api/src/com/cloud/agent/api/to/LoadBalancerTO.java +++ b/api/src/com/cloud/agent/api/to/LoadBalancerTO.java @@ -281,8 +281,7 @@ public class LoadBalancerTO implements Serializable { private final String serviceOfferingId; private final String templateId; private final String otherDeployParams; - private final String snmpCommunity; - private final Integer snmpPort; + private final List> counterParamList; private final Integer destroyVmGraceperiod; private final String cloudStackApiUrl; private final String autoScaleUserApiKey; @@ -291,14 +290,13 @@ public class LoadBalancerTO implements Serializable { private final String networkId; public AutoScaleVmProfileTO(String zoneId, String domainId, String cloudStackApiUrl, String autoScaleUserApiKey, String autoScaleUserSecretKey, String serviceOfferingId, - String templateId, String vmName, String networkId, String otherDeployParams, String snmpCommunity, Integer snmpPort, Integer destroyVmGraceperiod) { + String templateId, String vmName, String networkId, String otherDeployParams, List> counterParamList, Integer destroyVmGraceperiod) { this.zoneId = zoneId; this.domainId = domainId; this.serviceOfferingId = serviceOfferingId; this.templateId = templateId; this.otherDeployParams = otherDeployParams; - this.snmpCommunity = snmpCommunity; - this.snmpPort = snmpPort; + this.counterParamList = counterParamList; this.destroyVmGraceperiod = destroyVmGraceperiod; this.cloudStackApiUrl = cloudStackApiUrl; this.autoScaleUserApiKey = autoScaleUserApiKey; @@ -327,12 +325,8 @@ public class LoadBalancerTO implements Serializable { return otherDeployParams; } - public String getSnmpCommunity() { - return snmpCommunity; - } - - public Integer getSnmpPort() { - return snmpPort; + public List> getCounterParamList() { + return counterParamList; } public Integer getDestroyVmGraceperiod() { @@ -446,8 +440,8 @@ public class LoadBalancerTO implements Serializable { AutoScaleVmProfileTO autoScaleVmProfileTO = new AutoScaleVmProfileTO(lbAutoScaleVmProfile.getZoneId(), lbAutoScaleVmProfile.getDomainId(), lbAutoScaleVmProfile.getCsUrl(), lbAutoScaleVmProfile.getAutoScaleUserApiKey(), lbAutoScaleVmProfile.getAutoScaleUserSecretKey(), lbAutoScaleVmProfile.getServiceOfferingId(), lbAutoScaleVmProfile.getTemplateId(), lbAutoScaleVmProfile.getVmName(), - lbAutoScaleVmProfile.getNetworkId(),autoScaleVmProfile.getOtherDeployParams(), autoScaleVmProfile.getSnmpCommunity(), - autoScaleVmProfile.getSnmpPort(), autoScaleVmProfile.getDestroyVmGraceperiod()); + lbAutoScaleVmProfile.getNetworkId(),autoScaleVmProfile.getOtherDeployParams(), autoScaleVmProfile.getCounterParams(), + autoScaleVmProfile.getDestroyVmGraceperiod()); AutoScaleVmGroup autoScaleVmGroup = lbAutoScaleVmGroup.getVmGroup(); autoScaleVmGroupTO = new AutoScaleVmGroupTO(autoScaleVmGroup.getUuid(), autoScaleVmGroup.getMinMembers(), autoScaleVmGroup.getMaxMembers(), autoScaleVmGroup.getMemberPort(), diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index da29c794032..e8687554d5a 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -383,8 +383,6 @@ public class ApiConstants { public static final String AGGR_VALUE = "aggrvalue"; public static final String THRESHOLD = "threshold"; public static final String RELATIONAL_OPERATOR = "relationaloperator"; - public static final String SNMP_COMMUNITY = "snmpcommunity"; - public static final String SNMP_PORT = "snmpport"; public static final String OTHER_DEPLOY_PARAMS = "otherdeployparams"; public static final String MIN_MEMBERS = "minmembers"; public static final String MAX_MEMBERS = "maxmembers"; @@ -401,6 +399,7 @@ public class ApiConstants { public static final String ACTION = "action"; public static final String CONDITION_ID = "conditionid"; public static final String CONDITION_IDS = "conditionids"; + public static final String COUNTERPARAM_LIST = "counterparam"; public static final String AUTOSCALE_USER_ID = "autoscaleuserid"; public enum HostDetails { @@ -410,7 +409,7 @@ public class ApiConstants { public enum VMDetails { all, group, nics, stats, secgrp, tmpl, servoff, iso, volume, min; } - + public enum VolumeDetails { all, vm, account, storage_type, disk_offering, min; } diff --git a/api/src/com/cloud/api/commands/CreateAutoScaleVmProfileCmd.java b/api/src/com/cloud/api/commands/CreateAutoScaleVmProfileCmd.java index d49cfbf39f0..0837848fd92 100644 --- a/api/src/com/cloud/api/commands/CreateAutoScaleVmProfileCmd.java +++ b/api/src/com/cloud/api/commands/CreateAutoScaleVmProfileCmd.java @@ -35,6 +35,7 @@ import com.cloud.user.User; import com.cloud.user.UserContext; @Implementation(description = "Creates a profile that contains information about the virtual machine which will be provisioned automatically by autoscale feature.", responseObject = AutoScaleVmProfileResponse.class) +@SuppressWarnings("rawtypes") public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd { public static final Logger s_logger = Logger.getLogger(CreateAutoScaleVmProfileCmd.class.getName()); @@ -62,11 +63,8 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd { @Parameter(name = ApiConstants.AUTOSCALE_VM_DESTROY_TIME, type = CommandType.INTEGER, description = "the time allowed for existing connections to get closed before a vm is destroyed") private Integer destroyVmGraceperiod; - @Parameter(name = ApiConstants.SNMP_COMMUNITY, type = CommandType.STRING, description = "snmp community string to be used to contact a virtual machine deployed by this profile") - private String snmpCommunity; - - @Parameter(name = ApiConstants.SNMP_PORT, type = CommandType.INTEGER, description = "port at which snmp agent is listening in a virtual machine deployed by this profile") - private Integer snmpPort; + @Parameter(name = ApiConstants.COUNTERPARAM_LIST, type = CommandType.MAP, description = "counterparam list. Example: counterparam[0].name=snmpcommunity&counterparam[0].value=public&counterparam[1].name=snmpport&counterparam[1].value=161") + private Map counterParamList; @IdentityMapper(entityTableName = "user") @Parameter(name = ApiConstants.AUTOSCALE_USER_ID, type = CommandType.LONG, description = "the ID of the user used to launch and destroy the VMs") @@ -105,12 +103,8 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd { return templateId; } - public Integer getSnmpPort() { - return snmpPort; - } - - public String getSnmpCommunity() { - return snmpCommunity; + public Map getCounterParamList() { + return counterParamList; } public String getOtherDeployParams() { diff --git a/api/src/com/cloud/api/commands/UpdateAutoScaleVmProfileCmd.java b/api/src/com/cloud/api/commands/UpdateAutoScaleVmProfileCmd.java index b6f32872544..986b41ee3fa 100644 --- a/api/src/com/cloud/api/commands/UpdateAutoScaleVmProfileCmd.java +++ b/api/src/com/cloud/api/commands/UpdateAutoScaleVmProfileCmd.java @@ -17,6 +17,8 @@ package com.cloud.api.commands; +import java.util.Map; + import org.apache.log4j.Logger; import com.cloud.api.ApiConstants; @@ -54,11 +56,8 @@ public class UpdateAutoScaleVmProfileCmd extends BaseAsyncCmd { @Parameter(name = ApiConstants.AUTOSCALE_VM_DESTROY_TIME, type = CommandType.INTEGER, description = "the time allowed for existing connections to get closed before a vm is destroyed") private Integer destroyVmGraceperiod; - @Parameter(name = ApiConstants.SNMP_COMMUNITY, type = CommandType.STRING, description = "snmp community string to be used to contact a virtual machine deployed by this profile") - private String snmpCommunity; - - @Parameter(name = ApiConstants.SNMP_PORT, type = CommandType.INTEGER, description = "port at which snmp agent is listening in a virtual machine deployed by this profile") - private Integer snmpPort; + @Parameter(name = ApiConstants.COUNTERPARAM_LIST, type = CommandType.MAP, description = "counterparam list. Example: counterparam[0].name=snmpcommunity&counterparam[0].value=public&counterparam[1].name=snmpport&counterparam[1].value=161") + private Map counterParamList; @IdentityMapper(entityTableName = "user") @Parameter(name = ApiConstants.AUTOSCALE_USER_ID, type = CommandType.LONG, description = "the ID of the user used to launch and destroy the VMs") @@ -93,12 +92,8 @@ public class UpdateAutoScaleVmProfileCmd extends BaseAsyncCmd { return templateId; } - public Integer getSnmpPort() { - return snmpPort; - } - - public String getSnmpCommunity() { - return snmpCommunity; + public Map getCounterParamList() { + return counterParamList; } public Long getAutoscaleUserId() { diff --git a/api/src/com/cloud/api/response/AutoScaleVmProfileResponse.java b/api/src/com/cloud/api/response/AutoScaleVmProfileResponse.java index 0fc2c627cb6..8baaa9d09c3 100644 --- a/api/src/com/cloud/api/response/AutoScaleVmProfileResponse.java +++ b/api/src/com/cloud/api/response/AutoScaleVmProfileResponse.java @@ -8,15 +8,20 @@ // 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.api.response; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import com.cloud.api.ApiConstants; import com.cloud.api.Parameter; import com.cloud.api.BaseCmd.CommandType; import com.cloud.serializer.Param; import com.cloud.utils.IdentityProxy; +import com.cloud.utils.Pair; import com.google.gson.annotations.SerializedName; public class AutoScaleVmProfileResponse extends BaseResponse implements ControlledEntityResponse { @@ -48,13 +53,9 @@ public class AutoScaleVmProfileResponse extends BaseResponse implements Controll private Integer destroyVmGraceperiod; /* Parameters related to a running virtual machine - monitoring aspects */ - @SerializedName(ApiConstants.SNMP_COMMUNITY) - @Param(description = "snmp community string to be used to contact a virtual machine deployed by this profile") - private String snmpCommunity; - - @SerializedName(ApiConstants.SNMP_PORT) - @Param(description = "port at which the snmp agent is listening in a virtual machine deployed by this profile") - private Integer snmpPort; + @SerializedName(ApiConstants.COUNTERPARAM_LIST) + @Parameter(name = ApiConstants.COUNTERPARAM_LIST, type = CommandType.MAP, description = "counterparam list. Example: counterparam[0].name=snmpcommunity&counterparam[0].value=public&counterparam[1].name=snmpport&counterparam[1].value=161") + private Map counterParams; @SerializedName(ApiConstants.AUTOSCALE_USER_ID) @Param(description = "the ID of the user used to launch and destroy the VMs") @@ -107,12 +108,13 @@ public class AutoScaleVmProfileResponse extends BaseResponse implements Controll this.otherDeployParams = otherDeployParams; } - public void setSnmpCommunity(String snmpCommunity) { - this.snmpCommunity = snmpCommunity; - } - - public void setSnmpPort(Integer snmpPort) { - this.snmpPort = snmpPort; + public void setCounterParams(List> counterParams) { + this.counterParams = new HashMap(); + for(Pair paramKV :counterParams){ + String key = paramKV.first(); + String value = paramKV.second(); + this.counterParams.put(key,value); + } } @Override diff --git a/api/src/com/cloud/network/as/AutoScaleCounter.java b/api/src/com/cloud/network/as/AutoScaleCounter.java new file mode 100644 index 00000000000..316a12d9785 --- /dev/null +++ b/api/src/com/cloud/network/as/AutoScaleCounter.java @@ -0,0 +1,117 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.as; + +import java.util.List; +import java.util.ArrayList; +import com.google.gson.annotations.SerializedName; + + +public class AutoScaleCounter { + public static class AutoScaleCounterType { + private String _name; + + public static final AutoScaleCounterType Snmp = new AutoScaleCounterType("snmp"); + public static final AutoScaleCounterType Netscaler = new AutoScaleCounterType("netscaler"); + public AutoScaleCounterType(String name) { + _name = name; + } + + public String getName() { + return _name; + } + } + + public class AutoScaleCounterParam { + @SerializedName("paramname") + private String _paramName; + + @SerializedName("required") + private Boolean _required; + + @SerializedName("isflag") + private Boolean _isFlag; + + @SerializedName("description") + private String _description; + + public AutoScaleCounterParam(String name, Boolean required, + String description, Boolean flag) { + this._paramName = name; + this._required = required; + this._description = description; + this._isFlag = flag; + } + + public String getParamName() { + return _paramName; + } + + public void setParamName(String paramName) { + this._paramName = paramName; + } + + public Boolean getIsflag() { + return _isFlag; + } + + public void setIsflag(Boolean isFlag) { + this._isFlag = isFlag; + } + + public Boolean getRequired() { + return _required; + } + + public void setRequired(Boolean required) { + this._required = required; + } + + public String getDescription() { + return _description; + } + + public void setDescription(String description) { + this._description = description; + } + } + + @SerializedName("methodname") + private String _counterName; + + @SerializedName("paramlist") + private List _paramList; + + public AutoScaleCounter(AutoScaleCounterType methodType) { + this._counterName = methodType.getName(); + this._paramList = new ArrayList(1); + } + + public void addParam(String name, Boolean required, String description, Boolean isFlag) { + AutoScaleCounterParam param = new AutoScaleCounterParam(name,required, description, isFlag); + _paramList.add(param); + return; + } + + public String getName() { + return _counterName; + } + + public List getParamList() { + return _paramList; + } + + public void setParamList(List paramList) { + this._paramList = paramList; + } +} diff --git a/api/src/com/cloud/network/as/AutoScaleVmProfile.java b/api/src/com/cloud/network/as/AutoScaleVmProfile.java index ce31887d40b..50b1f6a7e06 100644 --- a/api/src/com/cloud/network/as/AutoScaleVmProfile.java +++ b/api/src/com/cloud/network/as/AutoScaleVmProfile.java @@ -11,7 +11,10 @@ // package com.cloud.network.as; +import java.util.List; + import com.cloud.acl.ControlledEntity; +import com.cloud.utils.Pair; /** * AutoScaleVmProfile @@ -28,11 +31,10 @@ public interface AutoScaleVmProfile extends ControlledEntity { public String getOtherDeployParams(); - public String getSnmpCommunity(); - - public Integer getSnmpPort(); + List> getCounterParams(); public Integer getDestroyVmGraceperiod(); public long getAutoScaleUserId(); + } diff --git a/core/src/com/cloud/network/resource/NetscalerResource.java b/core/src/com/cloud/network/resource/NetscalerResource.java index b18793cc365..df6396dd7cc 100644 --- a/core/src/com/cloud/network/resource/NetscalerResource.java +++ b/core/src/com/cloud/network/resource/NetscalerResource.java @@ -104,6 +104,7 @@ class NitroError { public class NetscalerResource implements ServerResource { + public final static int DEFAULT_SNMP_PORT = 161; // deployment configuration private String _name; private String _zoneId; @@ -1624,10 +1625,21 @@ public class NetscalerResource implements ServerResource { AutoScaleVmProfileTO profileTO = vmGroupTO.getProfile(); List policies = vmGroupTO.getPolicies(); int interval = vmGroupTO.getInterval(); - int snmpPort = profileTO.getSnmpPort(); - String snmpCommunity = profileTO.getSnmpCommunity(); + List> counterParams = profileTO.getCounterParamList(); + String snmpCommunity = null; + int snmpPort = DEFAULT_SNMP_PORT; long cur_prirotiy = 1; + // get the session persistence parameters + List> paramsList = profileTO.getCounterParamList(); + for(Pair param : paramsList) { + if ("snmpcommunity".equalsIgnoreCase(param.first())) { + snmpCommunity = param.second(); + } else if ("snmpport".equalsIgnoreCase(param.first())) { + snmpPort = Integer.parseInt(param.second()); + } + } + try { // Set min and max autoscale members; @@ -1654,7 +1666,7 @@ public class NetscalerResource implements ServerResource { String secretKey = profileTO.getAutoScaleUserSecretKey(); String url = profileTO.getCloudStackApiUrl(); - com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleprofile autoscaleProfile = new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleprofile(); + autoscaleprofile autoscaleProfile = new autoscaleprofile(); try { autoscaleProfile.set_name(profileName); autoscaleProfile.set_type("CLOUDSTACK"); @@ -1995,7 +2007,7 @@ public class NetscalerResource implements ServerResource { } // Delete AutoScale Profile - com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleprofile autoscaleProfile = new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleprofile(); + autoscaleprofile autoscaleProfile = new autoscaleprofile(); try { autoscaleProfile.set_name(profileName); autoscaleProfile.delete(_netscalerService, autoscaleProfile); diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index b9fdbf903c2..1773e06daab 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -3841,8 +3841,7 @@ public class ApiResponseHelper implements ResponseGenerator { response.setServiceOfferingId(profile.getServiceOfferingId()); response.setTemplateId(profile.getTemplateId()); response.setOtherDeployParams(profile.getOtherDeployParams()); - response.setSnmpCommunity(profile.getSnmpCommunity()); - response.setSnmpPort(profile.getSnmpPort()); + response.setCounterParams(profile.getCounterParams()); response.setDestroyVmGraceperiod(profile.getDestroyVmGraceperiod()); response.setAutoscaleUserId(profile.getAutoScaleUserId()); response.setObjectName("autoscalevmprofile"); diff --git a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java index 1fa432d1007..69ac629761c 100644 --- a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java +++ b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java @@ -14,7 +14,6 @@ package com.cloud.network.as; import java.security.InvalidParameterException; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -55,6 +54,7 @@ import com.cloud.exception.ResourceInUseException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.LoadBalancerVO; import com.cloud.network.Network.Capability; +import com.cloud.network.as.AutoScaleCounter.AutoScaleCounterParam; import com.cloud.network.as.dao.AutoScalePolicyConditionMapDao; import com.cloud.network.as.dao.AutoScalePolicyDao; import com.cloud.network.as.dao.AutoScaleVmGroupDao; @@ -78,6 +78,7 @@ import com.cloud.user.UserContext; import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; import com.cloud.utils.IdentityProxy; +import com.cloud.utils.Pair; import com.cloud.utils.Ternary; import com.cloud.utils.component.Inject; import com.cloud.utils.component.Manager; @@ -90,6 +91,8 @@ import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.db.Transaction; import com.cloud.utils.net.NetUtils; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; @Local(value = { AutoScaleService.class, AutoScaleManager.class }) public class AutoScaleManagerImpl implements AutoScaleManager, AutoScaleService, Manager { @@ -156,25 +159,51 @@ public class AutoScaleManagerImpl implements AutoScaleManager, AutoScaleSe return _name; } - public List getSupportedAutoScaleCounters(long networkid) + public List getSupportedAutoScaleCounters(long networkid) { - String autoScaleCapability = _lbRulesMgr.getLBCapability(networkid, Capability.AutoScaleCounters.getName()); - if (autoScaleCapability == null || autoScaleCapability.length() == 0) { + String capability = _lbRulesMgr.getLBCapability(networkid, Capability.AutoScaleCounters.getName()); + if (capability == null) { return null; } - return Arrays.asList(autoScaleCapability.split(",")); + Gson gson = new Gson(); + java.lang.reflect.Type listType = new TypeToken>() { + }.getType(); + List result = gson.fromJson(capability, listType); + return result; } - public void validateAutoScaleCounters(long networkid, List counters) - { - List supportedCounters = getSupportedAutoScaleCounters(networkid); + public void validateAutoScaleCounters(long networkid, List counters, List> counterParamPassed) { + List supportedCounters = getSupportedAutoScaleCounters(networkid); if (supportedCounters == null) { throw new InvalidParameterException("AutoScale is not supported in the network"); } 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"); + String counterName = counter.getSource().name().toString(); + boolean isCounterSupported = false; + for (AutoScaleCounter autoScaleCounter : supportedCounters) { + if(autoScaleCounter.getName().equals(counterName)) { + isCounterSupported = true; + List counterParams = autoScaleCounter.getParamList(); + for (AutoScaleCounterParam autoScaleCounterParam : counterParams) { + boolean isRequiredParameter = autoScaleCounterParam.getRequired(); + if(isRequiredParameter) { + boolean isRequiredParamPresent = false; + for (Pair pair : counterParamPassed) { + if(pair.first().equals(autoScaleCounterParam.getParamName())) + isRequiredParamPresent = true; + + } + if(!isRequiredParamPresent) { + throw new InvalidParameterException("Parameter " + autoScaleCounterParam.getParamName() + " has to be set in AutoScaleVmProfile's " + + ApiConstants.COUNTERPARAM_LIST); + } + } + } + } + } + if (!isCounterSupported) { + throw new InvalidParameterException("AutoScale counter with source='" + counter.getSource().name() + "' is not supported " + + "in the network"); } } } @@ -329,8 +358,9 @@ public class AutoScaleManagerImpl implements AutoScaleManager, AutoScaleSe autoscaleUserId = UserContext.current().getCallerUserId(); } + // TODO: Donot checkin AutoScaleVmProfileVO profileVO = new AutoScaleVmProfileVO(cmd.getZoneId(), cmd.getDomainId(), cmd.getAccountId(), cmd.getServiceOfferingId(), cmd.getTemplateId(), cmd.getOtherDeployParams(), - cmd.getSnmpCommunity(), cmd.getSnmpPort(), cmd.getDestroyVmGraceperiod(), autoscaleUserId); + cmd.getCounterParamList(), cmd.getDestroyVmGraceperiod(), autoscaleUserId); profileVO = checkValidityAndPersist(profileVO); s_logger.info("Successfully create AutoScale Vm Profile with Id: " + profileVO.getId()); @@ -343,8 +373,8 @@ public class AutoScaleManagerImpl implements AutoScaleManager, AutoScaleSe Long profileId = cmd.getId(); Long templateId = cmd.getTemplateId(); Long autoscaleUserId = cmd.getAutoscaleUserId(); - Integer snmpPort = cmd.getSnmpPort(); - String snmpCommunity = cmd.getSnmpCommunity(); + Map counterParamList = cmd.getCounterParamList(); + Integer destroyVmGraceperiod = cmd.getDestroyVmGraceperiod(); AutoScaleVmProfileVO vmProfile = getEntityInDatabase(UserContext.current().getCaller(), "Auto Scale Vm Profile", profileId, _autoScaleVmProfileDao); @@ -357,12 +387,8 @@ public class AutoScaleManagerImpl implements AutoScaleManager, AutoScaleSe vmProfile.setAutoscaleUserId(autoscaleUserId); } - if (snmpCommunity != null) { - vmProfile.setSnmpCommunity(snmpCommunity); - } - - if (snmpPort != null) { - vmProfile.setSnmpPort(snmpPort); + if (counterParamList != null) { + vmProfile.setCounterParams(counterParamList); } if (destroyVmGraceperiod != null) { @@ -876,11 +902,11 @@ public class AutoScaleManagerImpl implements AutoScaleManager, AutoScaleSe getAutoScalePolicies("scaledownpolicyid", bakupScaleDownPolicyIds, counters, interval, true); policyIds.addAll(bakupScaleDownPolicyIds); } + AutoScaleVmProfileVO profileVO = getEntityInDatabase(UserContext.current().getCaller(), ApiConstants.VMPROFILE_ID, vmGroup.getProfileId(), _autoScaleVmProfileDao); LoadBalancerVO loadBalancer = getEntityInDatabase(UserContext.current().getCaller(), ApiConstants.LBID, vmGroup.getLoadBalancerId(), _lbDao); - validateAutoScaleCounters(loadBalancer.getNetworkId(), counters); + validateAutoScaleCounters(loadBalancer.getNetworkId(), counters, profileVO.getCounterParams()); - AutoScaleVmProfileVO profileVO = getEntityInDatabase(UserContext.current().getCaller(), ApiConstants.VMPROFILE_ID, vmGroup.getProfileId(), _autoScaleVmProfileDao); ControlledEntity[] sameOwnerEntities = policies.toArray(new ControlledEntity[policies.size() + 2]); sameOwnerEntities[sameOwnerEntities.length - 2] = loadBalancer; diff --git a/server/src/com/cloud/network/as/AutoScaleVmProfileVO.java b/server/src/com/cloud/network/as/AutoScaleVmProfileVO.java index 8b0604dc56a..4b57e0c8b68 100644 --- a/server/src/com/cloud/network/as/AutoScaleVmProfileVO.java +++ b/server/src/com/cloud/network/as/AutoScaleVmProfileVO.java @@ -12,7 +12,12 @@ // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.network.as; +import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.UUID; import javax.persistence.Column; @@ -25,6 +30,7 @@ import javax.persistence.InheritanceType; import javax.persistence.Table; import com.cloud.api.Identity; +import com.cloud.utils.Pair; import com.cloud.utils.db.GenericDao; import com.cloud.utils.net.NetUtils; @@ -65,11 +71,8 @@ public class AutoScaleVmProfileVO implements AutoScaleVmProfile, Identity { @Column(name = "destroy_vm_grace_period", updatable = true) private Integer destroyVmGraceperiod = NetUtils.DEFAULT_AUTOSCALE_VM_DESTROY_TIME; - @Column(name = "snmp_community", updatable = true) - private String snmpCommunity = NetUtils.DEFAULT_SNMP_COMMUNITY; - - @Column(name = "snmp_port", updatable = true) - private Integer snmpPort = NetUtils.DEFAULT_SNMP_PORT; + @Column(name = "counter_params", updatable = true) + private String counterParams; @Column(name = GenericDao.REMOVED_COLUMN) protected Date removed; @@ -80,7 +83,7 @@ public class AutoScaleVmProfileVO implements AutoScaleVmProfile, Identity { public AutoScaleVmProfileVO() { } - public AutoScaleVmProfileVO(long zoneId, long domainId, long accountId, long serviceOfferingId, long templateId, String otherDeployParams, String snmpCommunity, Integer snmpPort, Integer destroyVmGraceperiod, + public AutoScaleVmProfileVO(long zoneId, long domainId, long accountId, long serviceOfferingId, long templateId, String otherDeployParams, Map counterParamList, Integer destroyVmGraceperiod, long autoscaleUserId) { this.uuid = UUID.randomUUID().toString(); this.zoneId = zoneId; @@ -93,12 +96,8 @@ public class AutoScaleVmProfileVO implements AutoScaleVmProfile, Identity { if (destroyVmGraceperiod != null) { this.destroyVmGraceperiod = destroyVmGraceperiod; } - if (snmpCommunity != null) { - this.snmpCommunity = snmpCommunity; - } - if (snmpPort != null) { - this.snmpPort = snmpPort; - } + setCounterParams(counterParamList); + } @Override @@ -130,21 +129,36 @@ public class AutoScaleVmProfileVO implements AutoScaleVmProfile, Identity { } @Override - public String getSnmpCommunity() { - return snmpCommunity; + public List> getCounterParams() { + List> paramsList = new ArrayList>(); + if(counterParams != null) + { + String[] params = counterParams.split("[=&]"); + for (int i = 0; i < (params.length - 1); i = i + 2) { + paramsList.add(new Pair(params[i], params[i + 1])); + } + } + return paramsList; } - public void setSnmpCommunity(String snmpCommunity) { - this.snmpCommunity = snmpCommunity; - } - @Override - public Integer getSnmpPort() { - return snmpPort; - } - - public void setSnmpPort(Integer snmpPort) { - this.snmpPort = snmpPort; + public void setCounterParams(Map counterParamList) { + StringBuilder sb = new StringBuilder(""); + boolean isFirstParam = true; + if (counterParamList != null) { + Iterator> iter = counterParamList.values().iterator(); + while (iter.hasNext()) { + HashMap paramKVpair = iter.next(); + if(!isFirstParam) { + sb.append("&"); + } + String paramName = paramKVpair.get("name"); + String paramValue = paramKVpair.get("value"); + sb.append(paramName + "=" + paramValue); + isFirstParam = false; + } + } + counterParams = sb.toString(); } @Override diff --git a/server/src/com/cloud/network/element/NetscalerElement.java b/server/src/com/cloud/network/element/NetscalerElement.java index 165faa8d177..40dd7846135 100644 --- a/server/src/com/cloud/network/element/NetscalerElement.java +++ b/server/src/com/cloud/network/element/NetscalerElement.java @@ -71,6 +71,8 @@ import com.cloud.network.Networks.TrafficType; import com.cloud.network.PhysicalNetworkServiceProvider; import com.cloud.network.PhysicalNetworkVO; import com.cloud.network.PublicIpAddress; +import com.cloud.network.as.AutoScaleCounter; +import com.cloud.network.as.AutoScaleCounter.AutoScaleCounterType; import com.cloud.network.dao.ExternalLoadBalancerDeviceDao; import com.cloud.network.dao.NetworkDao; import com.cloud.network.dao.NetworkExternalLoadBalancerDao; @@ -99,7 +101,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,7 +152,7 @@ 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; @@ -176,7 +178,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl @Override public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, - InsufficientNetworkCapacityException, ResourceUnavailableException { + InsufficientNetworkCapacityException, ResourceUnavailableException { return true; } @@ -249,8 +251,20 @@ 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"); + // Specifies that load balancing rules can support autoscaling and the list of counters it supports + AutoScaleCounter counter; + List counterList = new ArrayList(); + counter = new AutoScaleCounter(AutoScaleCounterType.Snmp); + counterList.add(counter); + counter.addParam("snmpcommunity", true, "the community string that has to be used to do a SNMP GET on the AutoScaled Vm", false); + counter.addParam("snmpport", false, "the port at which SNMP agent is running on the AutoScaled Vm", false); + + counter = new AutoScaleCounter(AutoScaleCounterType.Netscaler); + counterList.add(counter); + + Gson gson = new Gson(); + String autoScaleCounterList = gson.toJson(counterList); + lbCapabilities.put(Capability.AutoScaleCounters, autoScaleCounterList); LbStickinessMethod method; List methodList = new ArrayList(); @@ -266,7 +280,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl methodList.add(method); method.addParam("holdtime", false, "time period for which persistence is in effect.", false); - Gson gson = new Gson(); + gson = new Gson(); String stickyMethodList = gson.toJson(methodList); lbCapabilities.put(Capability.SupportedStickinessMethods, stickyMethodList); @@ -523,7 +537,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; } diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java index d59a37e58d9..06b772ac87f 100755 --- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java +++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java @@ -1432,14 +1432,6 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa return loadBalancerInstances; } - public List getSupportedAutoScaleCounters(long networkid) - { - String capability = getLBCapability(networkid, Capability.AutoScaleCounters.getName()); - if (capability == null || capability.length() == 0) { - return null; - } - return Arrays.asList(capability.split(",")); - } @Override public List getStickinessMethods(long networkid) diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index f2daea19aa0..1916b0953ee 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -2382,8 +2382,7 @@ CREATE TABLE `cloud`.`autoscale_vmprofiles` ( `template_id` bigint unsigned NOT NULL, `other_deploy_params` varchar(1024) COMMENT 'other deployment parameters that is in addition to zoneid,serviceofferingid,domainid', `destroy_vm_grace_period` int unsigned COMMENT 'the time allowed for existing connections to get closed before a vm is destroyed', - `snmp_community` varchar(255) COMMENT 'the community string to be used to reach out to the VM deployed by this profile', - `snmp_port` int unsigned COMMENT 'the snmp port to be used to reach out to the VM deployed by this profile', + `counter_params` varchar(1024) COMMENT 'the parameters for the counter to be used to get metric information from VMs', `created` datetime NOT NULL COMMENT 'date created', `removed` datetime COMMENT 'date removed if not null', PRIMARY KEY (`id`), diff --git a/setup/db/db/schema-304to305.sql b/setup/db/db/schema-304to305.sql index 1f51465489b..c66e802ae74 100755 --- a/setup/db/db/schema-304to305.sql +++ b/setup/db/db/schema-304to305.sql @@ -216,8 +216,7 @@ CREATE TABLE `cloud`.`autoscale_vmprofiles` ( `template_id` bigint unsigned NOT NULL, `other_deploy_params` varchar(1024) COMMENT 'other deployment parameters that is in addition to zoneid,serviceofferingid,domainid', `destroy_vm_grace_period` int unsigned COMMENT 'the time allowed for existing connections to get closed before a vm is destroyed', - `snmp_community` varchar(255) COMMENT 'the community string to be used to reach out to the VM deployed by this profile', - `snmp_port` int unsigned COMMENT 'the snmp port to be used to reach out to the VM deployed by this profile', + `counter_params` varchar(1024) COMMENT 'the parameters for the counter to be used to get metric information from VMs', `created` datetime NOT NULL COMMENT 'date created', `removed` datetime COMMENT 'date removed if not null', PRIMARY KEY (`id`), diff --git a/utils/src/com/cloud/utils/net/NetUtils.java b/utils/src/com/cloud/utils/net/NetUtils.java index 1e87cd003a4..0e4847c1f5d 100755 --- a/utils/src/com/cloud/utils/net/NetUtils.java +++ b/utils/src/com/cloud/utils/net/NetUtils.java @@ -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.utils.net; @@ -55,9 +55,6 @@ public class NetUtils { public final static String ALL_CIDRS = "0.0.0.0/0"; - public final static String DEFAULT_SNMP_COMMUNITY = "public"; - public final static int DEFAULT_SNMP_PORT = 161; - public final static int DEFAULT_AUTOSCALE_VM_DESTROY_TIME = 2 * 60; // Grace period before Vm is destroyed public final static int DEFAULT_AUTOSCALE_POLICY_INTERVAL_TIME = 30; public final static int DEFAULT_AUTOSCALE_POLICY_QUIET_TIME = 5 * 60; @@ -159,7 +156,7 @@ public class NetUtils { try { Process result = Runtime.getRuntime().exec("route print -4"); BufferedReader output = new BufferedReader - (new InputStreamReader(result.getInputStream())); + (new InputStreamReader(result.getInputStream())); String line = output.readLine(); while(line != null){ @@ -169,8 +166,8 @@ public class NetUtils { } line = output.readLine(); } - } catch( Exception e ) { - } + } catch( Exception e ) { + } return null; } else { NetworkInterface nic = null; @@ -741,7 +738,7 @@ public class NetUtils { long result = ipAddr | (~subnet); return long2Ip(result); } - + public static String getCidrSubNet(String ip, long cidrSize) { long numericNetmask = (0xffffffff >> (32 - cidrSize)) << (32 - cidrSize); String netmask = NetUtils.long2Ip(numericNetmask); @@ -793,7 +790,7 @@ public class NetUtils { long shift = 32 - cidrBLong[1]; return ((cidrALong[0] >> shift) == (cidrBLong[0] >> shift)); } - + public static boolean isNetworksOverlap(String cidrA, String cidrB) { Long[] cidrALong = cidrToLong(cidrA); Long[] cidrBLong = cidrToLong(cidrB); @@ -1096,7 +1093,7 @@ public class NetUtils { if (instanceName.contains("-") || instanceName.contains(" ") || instanceName.contains("+")) { s_logger.warn("Instance name can not contain hyphen, spaces and \"+\" char"); return false; - } + } return true; } @@ -1144,7 +1141,7 @@ public class NetUtils { } return true; } - + public static boolean validateIcmpType(long icmpType) { //Source - http://www.erg.abdn.ac.uk/~gorry/course/inet-pages/icmp-code.html if(!(icmpType >=0 && icmpType <=255)) { @@ -1153,15 +1150,15 @@ public class NetUtils { } return true; } - + public static boolean validateIcmpCode(long icmpCode) { - + //Source - http://www.erg.abdn.ac.uk/~gorry/course/inet-pages/icmp-code.html if(!(icmpCode >=0 && icmpCode <=15)) { s_logger.warn("Icmp code should be within 0-15 range"); return false; } - + return true; } }