mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
VM Autoscaling with virtual router (#6571)
This commit is contained in:
parent
3d8ea4f3b3
commit
a63b2aba7a
@ -18,17 +18,13 @@ package com.cloud.agent.api.to;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.cloud.network.as.AutoScalePolicy;
|
import com.cloud.network.as.AutoScalePolicy;
|
||||||
import com.cloud.network.as.AutoScaleVmGroup;
|
import com.cloud.network.as.AutoScaleVmGroup;
|
||||||
import com.cloud.network.as.AutoScaleVmProfile;
|
|
||||||
import com.cloud.network.as.Condition;
|
import com.cloud.network.as.Condition;
|
||||||
import com.cloud.network.as.Counter;
|
import com.cloud.network.as.Counter;
|
||||||
import com.cloud.network.lb.LoadBalancingRule.LbAutoScalePolicy;
|
|
||||||
import com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup;
|
|
||||||
import com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmProfile;
|
|
||||||
import com.cloud.network.lb.LoadBalancingRule.LbCondition;
|
|
||||||
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
|
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
|
||||||
import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
|
import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
|
||||||
import com.cloud.network.lb.LoadBalancingRule.LbSslCert;
|
import com.cloud.network.lb.LoadBalancingRule.LbSslCert;
|
||||||
@ -377,46 +373,64 @@ public class LoadBalancerTO {
|
|||||||
|
|
||||||
public static class CounterTO implements Serializable {
|
public static class CounterTO implements Serializable {
|
||||||
private static final long serialVersionUID = 2L;
|
private static final long serialVersionUID = 2L;
|
||||||
|
private final Long id;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String source;
|
private final Counter.Source source;
|
||||||
private final String value;
|
private final String value;
|
||||||
|
private final String provider;
|
||||||
|
|
||||||
public CounterTO(String name, String source, String value) {
|
public CounterTO(Long id, String name, Counter.Source source, String value, String provider) {
|
||||||
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
this.provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSource() {
|
public Counter.Source getSource() {
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getProvider() {
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ConditionTO implements Serializable {
|
public static class ConditionTO implements Serializable {
|
||||||
private static final long serialVersionUID = 2L;
|
private static final long serialVersionUID = 2L;
|
||||||
|
private final Long id;
|
||||||
private final long threshold;
|
private final long threshold;
|
||||||
private final String relationalOperator;
|
private final Condition.Operator relationalOperator;
|
||||||
private final CounterTO counter;
|
private final CounterTO counter;
|
||||||
|
|
||||||
public ConditionTO(long threshold, String relationalOperator, CounterTO counter) {
|
public ConditionTO(Long id, long threshold, Condition.Operator relationalOperator, CounterTO counter) {
|
||||||
|
this.id = id;
|
||||||
this.threshold = threshold;
|
this.threshold = threshold;
|
||||||
this.relationalOperator = relationalOperator;
|
this.relationalOperator = relationalOperator;
|
||||||
this.counter = counter;
|
this.counter = counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
public long getThreshold() {
|
public long getThreshold() {
|
||||||
return threshold;
|
return threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRelationalOperator() {
|
public Condition.Operator getRelationalOperator() {
|
||||||
return relationalOperator;
|
return relationalOperator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,14 +444,16 @@ public class LoadBalancerTO {
|
|||||||
private final long id;
|
private final long id;
|
||||||
private final int duration;
|
private final int duration;
|
||||||
private final int quietTime;
|
private final int quietTime;
|
||||||
private String action;
|
private final Date lastQuietTime;
|
||||||
|
private AutoScalePolicy.Action action;
|
||||||
boolean revoked;
|
boolean revoked;
|
||||||
private final List<ConditionTO> conditions;
|
private final List<ConditionTO> conditions;
|
||||||
|
|
||||||
public AutoScalePolicyTO(long id, int duration, int quietTime, String action, List<ConditionTO> conditions, boolean revoked) {
|
public AutoScalePolicyTO(long id, int duration, int quietTime, Date lastQuietTime, AutoScalePolicy.Action action, List<ConditionTO> conditions, boolean revoked) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
this.quietTime = quietTime;
|
this.quietTime = quietTime;
|
||||||
|
this.lastQuietTime = lastQuietTime;
|
||||||
this.conditions = conditions;
|
this.conditions = conditions;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
this.revoked = revoked;
|
this.revoked = revoked;
|
||||||
@ -455,7 +471,11 @@ public class LoadBalancerTO {
|
|||||||
return quietTime;
|
return quietTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAction() {
|
public Date getLastQuietTime() {
|
||||||
|
return lastQuietTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutoScalePolicy.Action getAction() {
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,7 +496,7 @@ public class LoadBalancerTO {
|
|||||||
private final String templateId;
|
private final String templateId;
|
||||||
private final String otherDeployParams;
|
private final String otherDeployParams;
|
||||||
private final List<Pair<String, String>> counterParamList;
|
private final List<Pair<String, String>> counterParamList;
|
||||||
private final Integer destroyVmGraceperiod;
|
private final Integer expungeVmGracePeriod;
|
||||||
private final String cloudStackApiUrl;
|
private final String cloudStackApiUrl;
|
||||||
private final String autoScaleUserApiKey;
|
private final String autoScaleUserApiKey;
|
||||||
private final String autoScaleUserSecretKey;
|
private final String autoScaleUserSecretKey;
|
||||||
@ -485,14 +505,14 @@ public class LoadBalancerTO {
|
|||||||
|
|
||||||
public AutoScaleVmProfileTO(String zoneId, String domainId, String cloudStackApiUrl, String autoScaleUserApiKey, String autoScaleUserSecretKey,
|
public AutoScaleVmProfileTO(String zoneId, String domainId, String cloudStackApiUrl, String autoScaleUserApiKey, String autoScaleUserSecretKey,
|
||||||
String serviceOfferingId, String templateId, String vmName, String networkId, String otherDeployParams, List<Pair<String, String>> counterParamList,
|
String serviceOfferingId, String templateId, String vmName, String networkId, String otherDeployParams, List<Pair<String, String>> counterParamList,
|
||||||
Integer destroyVmGraceperiod) {
|
Integer expungeVmGracePeriod) {
|
||||||
this.zoneId = zoneId;
|
this.zoneId = zoneId;
|
||||||
this.domainId = domainId;
|
this.domainId = domainId;
|
||||||
this.serviceOfferingId = serviceOfferingId;
|
this.serviceOfferingId = serviceOfferingId;
|
||||||
this.templateId = templateId;
|
this.templateId = templateId;
|
||||||
this.otherDeployParams = otherDeployParams;
|
this.otherDeployParams = otherDeployParams;
|
||||||
this.counterParamList = counterParamList;
|
this.counterParamList = counterParamList;
|
||||||
this.destroyVmGraceperiod = destroyVmGraceperiod;
|
this.expungeVmGracePeriod = expungeVmGracePeriod;
|
||||||
this.cloudStackApiUrl = cloudStackApiUrl;
|
this.cloudStackApiUrl = cloudStackApiUrl;
|
||||||
this.autoScaleUserApiKey = autoScaleUserApiKey;
|
this.autoScaleUserApiKey = autoScaleUserApiKey;
|
||||||
this.autoScaleUserSecretKey = autoScaleUserSecretKey;
|
this.autoScaleUserSecretKey = autoScaleUserSecretKey;
|
||||||
@ -524,8 +544,8 @@ public class LoadBalancerTO {
|
|||||||
return counterParamList;
|
return counterParamList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getDestroyVmGraceperiod() {
|
public Integer getExpungeVmGracePeriod() {
|
||||||
return destroyVmGraceperiod;
|
return expungeVmGracePeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCloudStackApiUrl() {
|
public String getCloudStackApiUrl() {
|
||||||
@ -551,6 +571,8 @@ public class LoadBalancerTO {
|
|||||||
|
|
||||||
public static class AutoScaleVmGroupTO implements Serializable {
|
public static class AutoScaleVmGroupTO implements Serializable {
|
||||||
private static final long serialVersionUID = 2L;
|
private static final long serialVersionUID = 2L;
|
||||||
|
|
||||||
|
private final Long id;
|
||||||
private final String uuid;
|
private final String uuid;
|
||||||
private final int minMembers;
|
private final int minMembers;
|
||||||
private final int maxMembers;
|
private final int maxMembers;
|
||||||
@ -558,11 +580,13 @@ public class LoadBalancerTO {
|
|||||||
private final int interval;
|
private final int interval;
|
||||||
private final List<AutoScalePolicyTO> policies;
|
private final List<AutoScalePolicyTO> policies;
|
||||||
private final AutoScaleVmProfileTO profile;
|
private final AutoScaleVmProfileTO profile;
|
||||||
private final String state;
|
private final AutoScaleVmGroup.State state;
|
||||||
private final String currentState;
|
private final AutoScaleVmGroup.State currentState;
|
||||||
|
private final Long loadBalancerId;
|
||||||
|
|
||||||
AutoScaleVmGroupTO(String uuid, int minMembers, int maxMembers, int memberPort, int interval, List<AutoScalePolicyTO> policies, AutoScaleVmProfileTO profile,
|
public AutoScaleVmGroupTO(Long id, String uuid, int minMembers, int maxMembers, int memberPort, int interval, List<AutoScalePolicyTO> policies, AutoScaleVmProfileTO profile,
|
||||||
String state, String currentState) {
|
AutoScaleVmGroup.State state, AutoScaleVmGroup.State currentState, Long loadBalancerId) {
|
||||||
|
this.id = id;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.minMembers = minMembers;
|
this.minMembers = minMembers;
|
||||||
this.maxMembers = maxMembers;
|
this.maxMembers = maxMembers;
|
||||||
@ -572,6 +596,11 @@ public class LoadBalancerTO {
|
|||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.currentState = currentState;
|
this.currentState = currentState;
|
||||||
|
this.loadBalancerId = loadBalancerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUuid() {
|
public String getUuid() {
|
||||||
@ -602,44 +631,16 @@ public class LoadBalancerTO {
|
|||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getState() {
|
public AutoScaleVmGroup.State getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCurrentState() {
|
public AutoScaleVmGroup.State getCurrentState() {
|
||||||
return currentState;
|
return currentState;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void setAutoScaleVmGroup(LbAutoScaleVmGroup lbAutoScaleVmGroup) {
|
public Long getLoadBalancerId() {
|
||||||
List<LbAutoScalePolicy> lbAutoScalePolicies = lbAutoScaleVmGroup.getPolicies();
|
return loadBalancerId;
|
||||||
List<AutoScalePolicyTO> autoScalePolicyTOs = new ArrayList<AutoScalePolicyTO>(lbAutoScalePolicies.size());
|
|
||||||
for (LbAutoScalePolicy lbAutoScalePolicy : lbAutoScalePolicies) {
|
|
||||||
List<LbCondition> lbConditions = lbAutoScalePolicy.getConditions();
|
|
||||||
List<ConditionTO> conditionTOs = new ArrayList<ConditionTO>(lbConditions.size());
|
|
||||||
for (LbCondition lbCondition : lbConditions) {
|
|
||||||
Counter counter = lbCondition.getCounter();
|
|
||||||
CounterTO counterTO = new CounterTO(counter.getName(), counter.getSource().toString(), "" + counter.getValue());
|
|
||||||
Condition condition = lbCondition.getCondition();
|
|
||||||
ConditionTO conditionTO = new ConditionTO(condition.getThreshold(), condition.getRelationalOperator().toString(), counterTO);
|
|
||||||
conditionTOs.add(conditionTO);
|
|
||||||
}
|
|
||||||
AutoScalePolicy autoScalePolicy = lbAutoScalePolicy.getPolicy();
|
|
||||||
autoScalePolicyTOs.add(new AutoScalePolicyTO(autoScalePolicy.getId(), autoScalePolicy.getDuration(), autoScalePolicy.getQuietTime(),
|
|
||||||
autoScalePolicy.getAction(), conditionTOs, lbAutoScalePolicy.isRevoked()));
|
|
||||||
}
|
}
|
||||||
LbAutoScaleVmProfile lbAutoScaleVmProfile = lbAutoScaleVmGroup.getProfile();
|
|
||||||
AutoScaleVmProfile autoScaleVmProfile = lbAutoScaleVmProfile.getProfile();
|
|
||||||
|
|
||||||
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.getCounterParams(), autoScaleVmProfile.getDestroyVmGraceperiod());
|
|
||||||
|
|
||||||
AutoScaleVmGroup autoScaleVmGroup = lbAutoScaleVmGroup.getVmGroup();
|
|
||||||
autoScaleVmGroupTO =
|
|
||||||
new AutoScaleVmGroupTO(autoScaleVmGroup.getUuid(), autoScaleVmGroup.getMinMembers(), autoScaleVmGroup.getMaxMembers(), autoScaleVmGroup.getMemberPort(),
|
|
||||||
autoScaleVmGroup.getInterval(), autoScalePolicyTOs, autoScaleVmProfileTO, autoScaleVmGroup.getState(), lbAutoScaleVmGroup.getCurrentState());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -559,6 +559,7 @@ public class EventTypes {
|
|||||||
public static final String EVENT_COUNTER_DELETE = "COUNTER.DELETE";
|
public static final String EVENT_COUNTER_DELETE = "COUNTER.DELETE";
|
||||||
public static final String EVENT_CONDITION_CREATE = "CONDITION.CREATE";
|
public static final String EVENT_CONDITION_CREATE = "CONDITION.CREATE";
|
||||||
public static final String EVENT_CONDITION_DELETE = "CONDITION.DELETE";
|
public static final String EVENT_CONDITION_DELETE = "CONDITION.DELETE";
|
||||||
|
public static final String EVENT_CONDITION_UPDATE = "CONDITION.UPDATE";
|
||||||
public static final String EVENT_AUTOSCALEPOLICY_CREATE = "AUTOSCALEPOLICY.CREATE";
|
public static final String EVENT_AUTOSCALEPOLICY_CREATE = "AUTOSCALEPOLICY.CREATE";
|
||||||
public static final String EVENT_AUTOSCALEPOLICY_UPDATE = "AUTOSCALEPOLICY.UPDATE";
|
public static final String EVENT_AUTOSCALEPOLICY_UPDATE = "AUTOSCALEPOLICY.UPDATE";
|
||||||
public static final String EVENT_AUTOSCALEPOLICY_DELETE = "AUTOSCALEPOLICY.DELETE";
|
public static final String EVENT_AUTOSCALEPOLICY_DELETE = "AUTOSCALEPOLICY.DELETE";
|
||||||
@ -570,6 +571,8 @@ public class EventTypes {
|
|||||||
public static final String EVENT_AUTOSCALEVMGROUP_UPDATE = "AUTOSCALEVMGROUP.UPDATE";
|
public static final String EVENT_AUTOSCALEVMGROUP_UPDATE = "AUTOSCALEVMGROUP.UPDATE";
|
||||||
public static final String EVENT_AUTOSCALEVMGROUP_ENABLE = "AUTOSCALEVMGROUP.ENABLE";
|
public static final String EVENT_AUTOSCALEVMGROUP_ENABLE = "AUTOSCALEVMGROUP.ENABLE";
|
||||||
public static final String EVENT_AUTOSCALEVMGROUP_DISABLE = "AUTOSCALEVMGROUP.DISABLE";
|
public static final String EVENT_AUTOSCALEVMGROUP_DISABLE = "AUTOSCALEVMGROUP.DISABLE";
|
||||||
|
public static final String EVENT_AUTOSCALEVMGROUP_SCALEDOWN = "AUTOSCALEVMGROUP.SCALEDOWN";
|
||||||
|
public static final String EVENT_AUTOSCALEVMGROUP_SCALEUP = "AUTOSCALEVMGROUP.SCALEUP";
|
||||||
|
|
||||||
public static final String EVENT_BAREMETAL_DHCP_SERVER_ADD = "PHYSICAL.DHCP.ADD";
|
public static final String EVENT_BAREMETAL_DHCP_SERVER_ADD = "PHYSICAL.DHCP.ADD";
|
||||||
public static final String EVENT_BAREMETAL_DHCP_SERVER_DELETE = "PHYSICAL.DHCP.DELETE";
|
public static final String EVENT_BAREMETAL_DHCP_SERVER_DELETE = "PHYSICAL.DHCP.DELETE";
|
||||||
@ -1038,6 +1041,8 @@ public class EventTypes {
|
|||||||
entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_UPDATE, AutoScaleVmGroup.class);
|
entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_UPDATE, AutoScaleVmGroup.class);
|
||||||
entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_ENABLE, AutoScaleVmGroup.class);
|
entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_ENABLE, AutoScaleVmGroup.class);
|
||||||
entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_DISABLE, AutoScaleVmGroup.class);
|
entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_DISABLE, AutoScaleVmGroup.class);
|
||||||
|
entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_SCALEDOWN, AutoScaleVmGroup.class);
|
||||||
|
entityEventDetails.put(EVENT_AUTOSCALEVMGROUP_SCALEUP, AutoScaleVmGroup.class);
|
||||||
entityEventDetails.put(EVENT_GUEST_VLAN_RANGE_DEDICATE, GuestVlan.class);
|
entityEventDetails.put(EVENT_GUEST_VLAN_RANGE_DEDICATE, GuestVlan.class);
|
||||||
entityEventDetails.put(EVENT_DEDICATED_GUEST_VLAN_RANGE_RELEASE, GuestVlan.class);
|
entityEventDetails.put(EVENT_DEDICATED_GUEST_VLAN_RANGE_RELEASE, GuestVlan.class);
|
||||||
|
|
||||||
|
|||||||
@ -285,6 +285,7 @@ public interface Network extends ControlledEntity, StateObject<Network.State>, I
|
|||||||
public static final Capability NoVlan = new Capability("NoVlan");
|
public static final Capability NoVlan = new Capability("NoVlan");
|
||||||
public static final Capability PublicAccess = new Capability("PublicAccess");
|
public static final Capability PublicAccess = new Capability("PublicAccess");
|
||||||
public static final Capability ExtraDhcpOptions = new Capability("ExtraDhcpOptions");
|
public static final Capability ExtraDhcpOptions = new Capability("ExtraDhcpOptions");
|
||||||
|
public static final Capability VmAutoScaling = new Capability("VmAutoScaling");
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
|||||||
@ -25,10 +25,11 @@ public class AutoScaleCounter {
|
|||||||
public static class AutoScaleCounterType {
|
public static class AutoScaleCounterType {
|
||||||
private String _name;
|
private String _name;
|
||||||
|
|
||||||
public static final AutoScaleCounterType Snmp = new AutoScaleCounterType("snmp");
|
public static final AutoScaleCounterType Snmp = new AutoScaleCounterType(Counter.Source.SNMP.name());
|
||||||
public static final AutoScaleCounterType Netscaler = new AutoScaleCounterType("netscaler");
|
public static final AutoScaleCounterType Cpu = new AutoScaleCounterType(Counter.Source.CPU.name());
|
||||||
public static final AutoScaleCounterType Cpu = new AutoScaleCounterType("cpu");
|
public static final AutoScaleCounterType Memory = new AutoScaleCounterType(Counter.Source.MEMORY.name());
|
||||||
public static final AutoScaleCounterType Memory = new AutoScaleCounterType("memory");
|
public static final AutoScaleCounterType Netscaler = new AutoScaleCounterType(Counter.Source.NETSCALER.name());
|
||||||
|
public static final AutoScaleCounterType VirtualRouter = new AutoScaleCounterType(Counter.Source.VIRTUALROUTER.name());
|
||||||
|
|
||||||
public AutoScaleCounterType(String name) {
|
public AutoScaleCounterType(String name) {
|
||||||
_name = name;
|
_name = name;
|
||||||
|
|||||||
@ -21,9 +21,26 @@ import java.util.Date;
|
|||||||
|
|
||||||
import org.apache.cloudstack.acl.ControlledEntity;
|
import org.apache.cloudstack.acl.ControlledEntity;
|
||||||
import org.apache.cloudstack.api.InternalIdentity;
|
import org.apache.cloudstack.api.InternalIdentity;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
public interface AutoScalePolicy extends ControlledEntity, InternalIdentity {
|
public interface AutoScalePolicy extends ControlledEntity, InternalIdentity {
|
||||||
|
|
||||||
|
enum Action {
|
||||||
|
SCALEUP, SCALEDOWN;
|
||||||
|
|
||||||
|
public static Action fromValue(String action) {
|
||||||
|
if (StringUtils.isBlank(action)) {
|
||||||
|
return null;
|
||||||
|
} else if (action.equalsIgnoreCase("ScaleUp")) {
|
||||||
|
return SCALEUP;
|
||||||
|
} else if (action.equalsIgnoreCase("ScaleDown")) {
|
||||||
|
return SCALEDOWN;
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unexpected AutoScale action : " + action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
long getId();
|
long getId();
|
||||||
|
|
||||||
@ -33,8 +50,8 @@ public interface AutoScalePolicy extends ControlledEntity, InternalIdentity {
|
|||||||
|
|
||||||
public int getQuietTime();
|
public int getQuietTime();
|
||||||
|
|
||||||
public Date getLastQuiteTime();
|
public Date getLastQuietTime();
|
||||||
|
|
||||||
public String getAction();
|
public Action getAction();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import org.apache.cloudstack.api.command.user.autoscale.ListCountersCmd;
|
|||||||
import org.apache.cloudstack.api.command.user.autoscale.UpdateAutoScalePolicyCmd;
|
import org.apache.cloudstack.api.command.user.autoscale.UpdateAutoScalePolicyCmd;
|
||||||
import org.apache.cloudstack.api.command.user.autoscale.UpdateAutoScaleVmGroupCmd;
|
import org.apache.cloudstack.api.command.user.autoscale.UpdateAutoScaleVmGroupCmd;
|
||||||
import org.apache.cloudstack.api.command.user.autoscale.UpdateAutoScaleVmProfileCmd;
|
import org.apache.cloudstack.api.command.user.autoscale.UpdateAutoScaleVmProfileCmd;
|
||||||
|
import org.apache.cloudstack.api.command.user.autoscale.UpdateConditionCmd;
|
||||||
|
|
||||||
import com.cloud.exception.ResourceInUseException;
|
import com.cloud.exception.ResourceInUseException;
|
||||||
import com.cloud.exception.ResourceUnavailableException;
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
@ -57,7 +58,7 @@ public interface AutoScaleService {
|
|||||||
|
|
||||||
boolean configureAutoScaleVmGroup(CreateAutoScaleVmGroupCmd cmd) throws ResourceUnavailableException;
|
boolean configureAutoScaleVmGroup(CreateAutoScaleVmGroupCmd cmd) throws ResourceUnavailableException;
|
||||||
|
|
||||||
boolean deleteAutoScaleVmGroup(long vmGroupId);
|
boolean deleteAutoScaleVmGroup(long vmGroupId, Boolean cleanup);
|
||||||
|
|
||||||
AutoScaleVmGroup updateAutoScaleVmGroup(UpdateAutoScaleVmGroupCmd cmd);
|
AutoScaleVmGroup updateAutoScaleVmGroup(UpdateAutoScaleVmGroupCmd cmd);
|
||||||
|
|
||||||
@ -78,4 +79,6 @@ public interface AutoScaleService {
|
|||||||
List<? extends Condition> listConditions(ListConditionsCmd cmd);
|
List<? extends Condition> listConditions(ListConditionsCmd cmd);
|
||||||
|
|
||||||
boolean deleteCondition(long conditionId) throws ResourceInUseException;
|
boolean deleteCondition(long conditionId) throws ResourceInUseException;
|
||||||
|
|
||||||
|
Condition updateCondition(UpdateConditionCmd cmd) throws ResourceInUseException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,13 +22,31 @@ import java.util.Date;
|
|||||||
import org.apache.cloudstack.acl.ControlledEntity;
|
import org.apache.cloudstack.acl.ControlledEntity;
|
||||||
import org.apache.cloudstack.api.Displayable;
|
import org.apache.cloudstack.api.Displayable;
|
||||||
import org.apache.cloudstack.api.InternalIdentity;
|
import org.apache.cloudstack.api.InternalIdentity;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
public interface AutoScaleVmGroup extends ControlledEntity, InternalIdentity, Displayable {
|
public interface AutoScaleVmGroup extends ControlledEntity, InternalIdentity, Displayable {
|
||||||
|
|
||||||
String State_New = "new";
|
enum State {
|
||||||
String State_Revoke = "revoke";
|
NEW, REVOKE, ENABLED, DISABLED, SCALING;
|
||||||
String State_Enabled = "enabled";
|
|
||||||
String State_Disabled = "disabled";
|
public static State fromValue(String state) {
|
||||||
|
if (StringUtils.isBlank(state)) {
|
||||||
|
return null;
|
||||||
|
} else if (state.equalsIgnoreCase("new")) {
|
||||||
|
return NEW;
|
||||||
|
} else if (state.equalsIgnoreCase("revoke")) {
|
||||||
|
return REVOKE;
|
||||||
|
} else if (state.equalsIgnoreCase("enabled")) {
|
||||||
|
return ENABLED;
|
||||||
|
} else if (state.equalsIgnoreCase("disabled")) {
|
||||||
|
return DISABLED;
|
||||||
|
} else if (state.equalsIgnoreCase("scaling")) {
|
||||||
|
return SCALING;
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unexpected AutoScale VM group state : " + state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
long getId();
|
long getId();
|
||||||
@ -40,6 +58,8 @@ public interface AutoScaleVmGroup extends ControlledEntity, InternalIdentity, Di
|
|||||||
|
|
||||||
long getProfileId();
|
long getProfileId();
|
||||||
|
|
||||||
|
String getName();
|
||||||
|
|
||||||
int getMinMembers();
|
int getMinMembers();
|
||||||
|
|
||||||
int getMaxMembers();
|
int getMaxMembers();
|
||||||
@ -50,11 +70,12 @@ public interface AutoScaleVmGroup extends ControlledEntity, InternalIdentity, Di
|
|||||||
|
|
||||||
Date getLastInterval();
|
Date getLastInterval();
|
||||||
|
|
||||||
String getState();
|
State getState();
|
||||||
|
|
||||||
String getUuid();
|
String getUuid();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean isDisplay();
|
boolean isDisplay();
|
||||||
|
|
||||||
|
Date getCreated();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,6 +33,8 @@ public interface AutoScaleVmProfile extends ControlledEntity, InternalIdentity,
|
|||||||
@Override
|
@Override
|
||||||
public long getId();
|
public long getId();
|
||||||
|
|
||||||
|
String getUserData();
|
||||||
|
|
||||||
public String getUuid();
|
public String getUuid();
|
||||||
|
|
||||||
public Long getZoneId();
|
public Long getZoneId();
|
||||||
@ -43,11 +45,13 @@ public interface AutoScaleVmProfile extends ControlledEntity, InternalIdentity,
|
|||||||
|
|
||||||
public String getOtherDeployParams();
|
public String getOtherDeployParams();
|
||||||
|
|
||||||
|
public List<Pair<String, String>> getOtherDeployParamsList();
|
||||||
|
|
||||||
List<Pair<String, String>> getCounterParams();
|
List<Pair<String, String>> getCounterParams();
|
||||||
|
|
||||||
public Integer getDestroyVmGraceperiod();
|
public Integer getExpungeVmGracePeriod();
|
||||||
|
|
||||||
public long getAutoScaleUserId();
|
public Long getAutoScaleUserId();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean isDisplay();
|
boolean isDisplay();
|
||||||
|
|||||||
@ -27,7 +27,7 @@ public interface Condition extends ControlledEntity, Identity, InternalIdentity
|
|||||||
EQ, GT, LT, GE, LE
|
EQ, GT, LT, GE, LE
|
||||||
};
|
};
|
||||||
|
|
||||||
long getCounterid();
|
long getCounterId();
|
||||||
|
|
||||||
long getThreshold();
|
long getThreshold();
|
||||||
|
|
||||||
|
|||||||
@ -20,19 +20,27 @@ package com.cloud.network.as;
|
|||||||
import org.apache.cloudstack.api.Identity;
|
import org.apache.cloudstack.api.Identity;
|
||||||
import org.apache.cloudstack.api.InternalIdentity;
|
import org.apache.cloudstack.api.InternalIdentity;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface Counter extends InternalIdentity, Identity {
|
public interface Counter extends InternalIdentity, Identity {
|
||||||
|
|
||||||
public static enum Source {
|
enum Source {
|
||||||
netscaler,
|
NETSCALER,
|
||||||
snmp,
|
SNMP,
|
||||||
cpu,
|
CPU,
|
||||||
memory
|
MEMORY,
|
||||||
|
VIRTUALROUTER
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final List<Source> NativeSources = Arrays.asList(Source.CPU, Source.MEMORY);
|
||||||
|
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
String getValue();
|
String getValue();
|
||||||
|
|
||||||
Source getSource();
|
Source getSource();
|
||||||
|
|
||||||
|
String getProvider();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -406,9 +406,9 @@ public class LoadBalancingRule {
|
|||||||
AutoScaleVmGroup vmGroup;
|
AutoScaleVmGroup vmGroup;
|
||||||
private final List<LbAutoScalePolicy> policies;
|
private final List<LbAutoScalePolicy> policies;
|
||||||
private final LbAutoScaleVmProfile profile;
|
private final LbAutoScaleVmProfile profile;
|
||||||
private final String currentState;
|
private final AutoScaleVmGroup.State currentState;
|
||||||
|
|
||||||
public LbAutoScaleVmGroup(AutoScaleVmGroup vmGroup, List<LbAutoScalePolicy> policies, LbAutoScaleVmProfile profile, String currentState) {
|
public LbAutoScaleVmGroup(AutoScaleVmGroup vmGroup, List<LbAutoScalePolicy> policies, LbAutoScaleVmProfile profile, AutoScaleVmGroup.State currentState) {
|
||||||
this.vmGroup = vmGroup;
|
this.vmGroup = vmGroup;
|
||||||
this.policies = policies;
|
this.policies = policies;
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
@ -427,7 +427,7 @@ public class LoadBalancingRule {
|
|||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCurrentState() {
|
public AutoScaleVmGroup.State getCurrentState() {
|
||||||
return currentState;
|
return currentState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -98,11 +98,11 @@ public interface LoadBalancingRulesService {
|
|||||||
/**
|
/**
|
||||||
* Assign a virtual machine or list of virtual machines, or Map of <vmId vmIp> to a load balancer.
|
* Assign a virtual machine or list of virtual machines, or Map of <vmId vmIp> to a load balancer.
|
||||||
*/
|
*/
|
||||||
boolean assignToLoadBalancer(long lbRuleId, List<Long> vmIds, Map<Long, List<String>> vmIdIpMap);
|
boolean assignToLoadBalancer(long lbRuleId, List<Long> vmIds, Map<Long, List<String>> vmIdIpMap, boolean isAutoScaleVM);
|
||||||
|
|
||||||
boolean assignSSLCertToLoadBalancerRule(Long lbRuleId, String certName, String publicCert, String privateKey);
|
boolean assignSSLCertToLoadBalancerRule(Long lbRuleId, String certName, String publicCert, String privateKey);
|
||||||
|
|
||||||
boolean removeFromLoadBalancer(long lbRuleId, List<Long> vmIds, Map<Long, List<String>> vmIdIpMap);
|
boolean removeFromLoadBalancer(long lbRuleId, List<Long> vmIds, Map<Long, List<String>> vmIdIpMap, boolean isAutoScaleVM);
|
||||||
|
|
||||||
boolean applyLoadBalancerConfig(long lbRuleId) throws ResourceUnavailableException;
|
boolean applyLoadBalancerConfig(long lbRuleId) throws ResourceUnavailableException;
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,132 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
package com.cloud.network.router;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bridge internal and external traffic.
|
||||||
|
*/
|
||||||
|
public interface VirtualRouterAutoScale {
|
||||||
|
|
||||||
|
int MBITS_TO_BYTES = 1024 * 1024 / 8;
|
||||||
|
|
||||||
|
enum VirtualRouterAutoScaleCounter {
|
||||||
|
NETWORK_RECEIVED_AVERAGE_MBPS("public.network.received.average.mbps"),
|
||||||
|
NETWORK_TRANSMIT_AVERAGE_MBPS("public.network.transmit.average.mbps"),
|
||||||
|
LB_AVERAGE_CONNECTIONS("virtual.network.lb.average.connections");
|
||||||
|
|
||||||
|
String value;
|
||||||
|
VirtualRouterAutoScaleCounter(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
public static VirtualRouterAutoScaleCounter fromValue(String value) {
|
||||||
|
VirtualRouterAutoScaleCounter[] values = VirtualRouterAutoScaleCounter.values();
|
||||||
|
for(VirtualRouterAutoScaleCounter v : values) {
|
||||||
|
if(v.getValue().equals(value)) {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum AutoScaleValueType {
|
||||||
|
INSTANT_VM ("Instant data for a VM"),
|
||||||
|
INSTANT_VM_GROUP ("Instant data for AutoScale VM group"),
|
||||||
|
AGGREGATED_VM ("Aggregated data for a VM"),
|
||||||
|
AGGREGATED_VM_GROUP ("Aggregated data for AutoScale VM group");
|
||||||
|
|
||||||
|
String description;
|
||||||
|
|
||||||
|
private AutoScaleValueType(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AutoScaleMetrics {
|
||||||
|
VirtualRouterAutoScaleCounter counter;
|
||||||
|
Long policyId;
|
||||||
|
Long conditionId;
|
||||||
|
Long counterId;
|
||||||
|
Integer duration;
|
||||||
|
|
||||||
|
public AutoScaleMetrics(VirtualRouterAutoScaleCounter counter, Long policyId, Long conditionId, Long counterId, Integer duration) {
|
||||||
|
this.counter = counter;
|
||||||
|
this.policyId = policyId;
|
||||||
|
this.conditionId = conditionId;
|
||||||
|
this.counterId = counterId;
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VirtualRouterAutoScaleCounter getCounter() {
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getPolicyId() {
|
||||||
|
return policyId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getConditionId() {
|
||||||
|
return conditionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getCounterId() {
|
||||||
|
return counterId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDuration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AutoScaleMetricsValue {
|
||||||
|
AutoScaleMetrics metrics;
|
||||||
|
AutoScaleValueType type;
|
||||||
|
Double value;
|
||||||
|
|
||||||
|
public AutoScaleMetricsValue(AutoScaleMetrics metrics, AutoScaleValueType type, Double value) {
|
||||||
|
this.metrics = metrics;
|
||||||
|
this.type = type;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutoScaleMetrics getMetrics() {
|
||||||
|
return metrics;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutoScaleValueType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -143,6 +143,8 @@ public interface NetworkOffering extends InfrastructureEntity, InternalIdentity,
|
|||||||
|
|
||||||
boolean isSupportingPublicAccess();
|
boolean isSupportingPublicAccess();
|
||||||
|
|
||||||
|
boolean isSupportsVmAutoScaling();
|
||||||
|
|
||||||
String getServicePackage();
|
String getServicePackage();
|
||||||
|
|
||||||
Date getCreated();
|
Date getCreated();
|
||||||
|
|||||||
@ -31,6 +31,7 @@ public interface ResourceTag extends ControlledEntity, Identity, InternalIdentit
|
|||||||
Snapshot(true, false),
|
Snapshot(true, false),
|
||||||
Backup(true, false),
|
Backup(true, false),
|
||||||
Network(true, true, true),
|
Network(true, true, true),
|
||||||
|
DomainRouter(false, false),
|
||||||
Nic(false, true),
|
Nic(false, true),
|
||||||
LoadBalancer(true, true),
|
LoadBalancer(true, true),
|
||||||
PortForwardingRule(true, true),
|
PortForwardingRule(true, true),
|
||||||
|
|||||||
@ -44,7 +44,8 @@ public interface AnnotationService {
|
|||||||
TEMPLATE(true), ISO(true), KUBERNETES_CLUSTER(true),
|
TEMPLATE(true), ISO(true), KUBERNETES_CLUSTER(true),
|
||||||
SERVICE_OFFERING(false), DISK_OFFERING(false), NETWORK_OFFERING(false),
|
SERVICE_OFFERING(false), DISK_OFFERING(false), NETWORK_OFFERING(false),
|
||||||
ZONE(false), POD(false), CLUSTER(false), HOST(false), DOMAIN(false),
|
ZONE(false), POD(false), CLUSTER(false), HOST(false), DOMAIN(false),
|
||||||
PRIMARY_STORAGE(false), SECONDARY_STORAGE(false), VR(false), SYSTEM_VM(false);
|
PRIMARY_STORAGE(false), SECONDARY_STORAGE(false), VR(false), SYSTEM_VM(false),
|
||||||
|
AUTOSCALE_VM_GROUP(true);
|
||||||
|
|
||||||
private final boolean usersAllowed;
|
private final boolean usersAllowed;
|
||||||
|
|
||||||
|
|||||||
@ -40,6 +40,7 @@ public class ApiConstants {
|
|||||||
public static final String LIVE_PATCH = "livepatch";
|
public static final String LIVE_PATCH = "livepatch";
|
||||||
public static final String AVAILABLE = "available";
|
public static final String AVAILABLE = "available";
|
||||||
public static final String AVAILABLE_SUBNETS = "availablesubnets";
|
public static final String AVAILABLE_SUBNETS = "availablesubnets";
|
||||||
|
public static final String AVAILABLE_VIRTUAL_MACHINE_COUNT = "availablevirtualmachinecount";
|
||||||
public static final String BACKUP_ID = "backupid";
|
public static final String BACKUP_ID = "backupid";
|
||||||
public static final String BACKUP_OFFERING_NAME = "backupofferingname";
|
public static final String BACKUP_OFFERING_NAME = "backupofferingname";
|
||||||
public static final String BACKUP_OFFERING_ID = "backupofferingid";
|
public static final String BACKUP_OFFERING_ID = "backupofferingid";
|
||||||
@ -266,6 +267,7 @@ public class ApiConstants {
|
|||||||
public static final String LOCK = "lock";
|
public static final String LOCK = "lock";
|
||||||
public static final String LUN = "lun";
|
public static final String LUN = "lun";
|
||||||
public static final String LBID = "lbruleid";
|
public static final String LBID = "lbruleid";
|
||||||
|
public static final String LB_PROVIDER = "lbprovider";
|
||||||
public static final String MAC_ADDRESS = "macaddress";
|
public static final String MAC_ADDRESS = "macaddress";
|
||||||
public static final String MAX = "max";
|
public static final String MAX = "max";
|
||||||
public static final String MAX_SNAPS = "maxsnaps";
|
public static final String MAX_SNAPS = "maxsnaps";
|
||||||
@ -736,7 +738,7 @@ public class ApiConstants {
|
|||||||
public static final String OTHER_DEPLOY_PARAMS = "otherdeployparams";
|
public static final String OTHER_DEPLOY_PARAMS = "otherdeployparams";
|
||||||
public static final String MIN_MEMBERS = "minmembers";
|
public static final String MIN_MEMBERS = "minmembers";
|
||||||
public static final String MAX_MEMBERS = "maxmembers";
|
public static final String MAX_MEMBERS = "maxmembers";
|
||||||
public static final String AUTOSCALE_VM_DESTROY_TIME = "destroyvmgraceperiod";
|
public static final String AUTOSCALE_EXPUNGE_VM_GRACE_PERIOD = "expungevmgraceperiod";
|
||||||
public static final String VMPROFILE_ID = "vmprofileid";
|
public static final String VMPROFILE_ID = "vmprofileid";
|
||||||
public static final String VMGROUP_ID = "vmgroupid";
|
public static final String VMGROUP_ID = "vmgroupid";
|
||||||
public static final String CS_URL = "csurl";
|
public static final String CS_URL = "csurl";
|
||||||
@ -752,6 +754,8 @@ public class ApiConstants {
|
|||||||
public static final String CONDITION_IDS = "conditionids";
|
public static final String CONDITION_IDS = "conditionids";
|
||||||
public static final String COUNTERPARAM_LIST = "counterparam";
|
public static final String COUNTERPARAM_LIST = "counterparam";
|
||||||
public static final String AUTOSCALE_USER_ID = "autoscaleuserid";
|
public static final String AUTOSCALE_USER_ID = "autoscaleuserid";
|
||||||
|
public static final String AUTOSCALE_VMGROUP_ID = "autoscalevmgroupid";
|
||||||
|
public static final String AUTOSCALE_VMGROUP_NAME = "autoscalevmgroupname";
|
||||||
public static final String BAREMETAL_DISCOVER_NAME = "baremetaldiscovername";
|
public static final String BAREMETAL_DISCOVER_NAME = "baremetaldiscovername";
|
||||||
public static final String BAREMETAL_RCT_URL = "baremetalrcturl";
|
public static final String BAREMETAL_RCT_URL = "baremetalrcturl";
|
||||||
public static final String UCS_DN = "ucsdn";
|
public static final String UCS_DN = "ucsdn";
|
||||||
@ -833,6 +837,7 @@ public class ApiConstants {
|
|||||||
public static final String SUPPORTS_REGION_LEVEL_VPC = "supportsregionLevelvpc";
|
public static final String SUPPORTS_REGION_LEVEL_VPC = "supportsregionLevelvpc";
|
||||||
public static final String SUPPORTS_STRECHED_L2_SUBNET = "supportsstrechedl2subnet";
|
public static final String SUPPORTS_STRECHED_L2_SUBNET = "supportsstrechedl2subnet";
|
||||||
public static final String SUPPORTS_PUBLIC_ACCESS = "supportspublicaccess";
|
public static final String SUPPORTS_PUBLIC_ACCESS = "supportspublicaccess";
|
||||||
|
public static final String SUPPORTS_VM_AUTOSCALING = "supportsvmautoscaling";
|
||||||
public static final String REGION_LEVEL_VPC = "regionlevelvpc";
|
public static final String REGION_LEVEL_VPC = "regionlevelvpc";
|
||||||
public static final String STRECHED_L2_SUBNET = "strechedl2subnet";
|
public static final String STRECHED_L2_SUBNET = "strechedl2subnet";
|
||||||
public static final String NETWORK_NAME = "networkname";
|
public static final String NETWORK_NAME = "networkname";
|
||||||
|
|||||||
@ -32,7 +32,7 @@ import com.cloud.event.EventTypes;
|
|||||||
import com.cloud.network.as.Counter;
|
import com.cloud.network.as.Counter;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
|
|
||||||
@APICommand(name = "createCounter", description = "Adds metric counter", responseObject = CounterResponse.class,
|
@APICommand(name = "createCounter", description = "Adds metric counter for VM auto scaling", responseObject = CounterResponse.class,
|
||||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||||
public class CreateCounterCmd extends BaseAsyncCreateCmd {
|
public class CreateCounterCmd extends BaseAsyncCreateCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(CreateCounterCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(CreateCounterCmd.class.getName());
|
||||||
@ -51,6 +51,9 @@ public class CreateCounterCmd extends BaseAsyncCreateCmd {
|
|||||||
@Parameter(name = ApiConstants.VALUE, type = CommandType.STRING, required = true, description = "Value of the counter e.g. oid in case of snmp.")
|
@Parameter(name = ApiConstants.VALUE, type = CommandType.STRING, required = true, description = "Value of the counter e.g. oid in case of snmp.")
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, required = true, description = "Network provider of the counter.", since = "4.18.0")
|
||||||
|
private String provider;
|
||||||
|
|
||||||
// /////////////////////////////////////////////////
|
// /////////////////////////////////////////////////
|
||||||
// ///////////////// Accessors ///////////////////////
|
// ///////////////// Accessors ///////////////////////
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
@ -67,6 +70,10 @@ public class CreateCounterCmd extends BaseAsyncCreateCmd {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getProvider() {
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
// ///////////// API Implementation///////////////////
|
// ///////////// API Implementation///////////////////
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
|
|||||||
@ -33,7 +33,7 @@ import com.cloud.event.EventTypes;
|
|||||||
import com.cloud.exception.ResourceInUseException;
|
import com.cloud.exception.ResourceInUseException;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
|
|
||||||
@APICommand(name = "deleteCounter", description = "Deletes a counter", responseObject = SuccessResponse.class,
|
@APICommand(name = "deleteCounter", description = "Deletes a counter for VM auto scaling", responseObject = SuccessResponse.class,
|
||||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||||
public class DeleteCounterCmd extends BaseAsyncCmd {
|
public class DeleteCounterCmd extends BaseAsyncCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(DeleteCounterCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(DeleteCounterCmd.class.getName());
|
||||||
|
|||||||
@ -51,6 +51,12 @@ public class CreateAutoScalePolicyCmd extends BaseAsyncCreateCmd {
|
|||||||
// ////////////// API parameters /////////////////////
|
// ////////////// API parameters /////////////////////
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.NAME,
|
||||||
|
type = CommandType.STRING,
|
||||||
|
description = "the name of the autoscale policy",
|
||||||
|
since = "4.18.0")
|
||||||
|
private String name;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.ACTION,
|
@Parameter(name = ApiConstants.ACTION,
|
||||||
type = CommandType.STRING,
|
type = CommandType.STRING,
|
||||||
required = true,
|
required = true,
|
||||||
@ -60,12 +66,12 @@ public class CreateAutoScalePolicyCmd extends BaseAsyncCreateCmd {
|
|||||||
@Parameter(name = ApiConstants.DURATION,
|
@Parameter(name = ApiConstants.DURATION,
|
||||||
type = CommandType.INTEGER,
|
type = CommandType.INTEGER,
|
||||||
required = true,
|
required = true,
|
||||||
description = "the duration for which the conditions have to be true before action is taken")
|
description = "the duration in which the conditions have to be true before action is taken")
|
||||||
private int duration;
|
private int duration;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.QUIETTIME,
|
@Parameter(name = ApiConstants.QUIETTIME,
|
||||||
type = CommandType.INTEGER,
|
type = CommandType.INTEGER,
|
||||||
description = "the cool down period for which the policy should not be evaluated after the action has been taken")
|
description = "the cool down period in which the policy should not be evaluated after the action has been taken")
|
||||||
private Integer quietTime;
|
private Integer quietTime;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.CONDITION_IDS,
|
@Parameter(name = ApiConstants.CONDITION_IDS,
|
||||||
@ -83,6 +89,10 @@ public class CreateAutoScalePolicyCmd extends BaseAsyncCreateCmd {
|
|||||||
private Long conditionDomainId;
|
private Long conditionDomainId;
|
||||||
private Long conditionAccountId;
|
private Long conditionAccountId;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public int getDuration() {
|
public int getDuration() {
|
||||||
return duration;
|
return duration;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,6 +60,12 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd {
|
|||||||
description = "the ID of the load balancer rule")
|
description = "the ID of the load balancer rule")
|
||||||
private long lbRuleId;
|
private long lbRuleId;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.NAME,
|
||||||
|
type = CommandType.STRING,
|
||||||
|
description = "the name of the autoscale vmgroup",
|
||||||
|
since = "4.18.0")
|
||||||
|
private String name;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.MIN_MEMBERS,
|
@Parameter(name = ApiConstants.MIN_MEMBERS,
|
||||||
type = CommandType.INTEGER,
|
type = CommandType.INTEGER,
|
||||||
required = true,
|
required = true,
|
||||||
@ -72,7 +78,7 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd {
|
|||||||
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.")
|
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;
|
private int maxMembers;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.INTERVAL, type = CommandType.INTEGER, description = "the frequency at which the conditions have to be evaluated")
|
@Parameter(name = ApiConstants.INTERVAL, type = CommandType.INTEGER, description = "the frequency in which the performance counters to be collected")
|
||||||
private Integer interval;
|
private Integer interval;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.SCALEUP_POLICY_IDS,
|
@Parameter(name = ApiConstants.SCALEUP_POLICY_IDS,
|
||||||
@ -105,6 +111,11 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd {
|
|||||||
// ///////////////// Accessors ///////////////////////
|
// ///////////////// Accessors ///////////////////////
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public int getMinMembers() {
|
public int getMinMembers() {
|
||||||
return minMembers;
|
return minMembers;
|
||||||
}
|
}
|
||||||
@ -225,7 +236,7 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd {
|
|||||||
s_logger.warn("Failed to create autoscale vm group", ex);
|
s_logger.warn("Failed to create autoscale vm group", ex);
|
||||||
} finally {
|
} finally {
|
||||||
if (!success || vmGroup == null) {
|
if (!success || vmGroup == null) {
|
||||||
_autoScaleService.deleteAutoScaleVmGroup(getEntityId());
|
_autoScaleService.deleteAutoScaleVmGroup(getEntityId(), true);
|
||||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Autoscale Vm Group");
|
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Autoscale Vm Group");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.autoscale;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.collections.MapUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import org.apache.cloudstack.acl.RoleType;
|
import org.apache.cloudstack.acl.RoleType;
|
||||||
@ -30,6 +31,8 @@ import org.apache.cloudstack.api.BaseAsyncCreateCmd;
|
|||||||
import org.apache.cloudstack.api.Parameter;
|
import org.apache.cloudstack.api.Parameter;
|
||||||
import org.apache.cloudstack.api.ServerApiException;
|
import org.apache.cloudstack.api.ServerApiException;
|
||||||
import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
|
import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
|
||||||
|
import org.apache.cloudstack.api.response.DomainResponse;
|
||||||
|
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||||
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
|
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
|
||||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||||
import org.apache.cloudstack.api.response.UserResponse;
|
import org.apache.cloudstack.api.response.UserResponse;
|
||||||
@ -37,11 +40,8 @@ import org.apache.cloudstack.api.response.ZoneResponse;
|
|||||||
import org.apache.cloudstack.context.CallContext;
|
import org.apache.cloudstack.context.CallContext;
|
||||||
|
|
||||||
import com.cloud.event.EventTypes;
|
import com.cloud.event.EventTypes;
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
|
||||||
import com.cloud.exception.ResourceAllocationException;
|
import com.cloud.exception.ResourceAllocationException;
|
||||||
import com.cloud.network.as.AutoScaleVmProfile;
|
import com.cloud.network.as.AutoScaleVmProfile;
|
||||||
import com.cloud.user.Account;
|
|
||||||
import com.cloud.user.User;
|
|
||||||
|
|
||||||
@APICommand(name = "createAutoScaleVmProfile",
|
@APICommand(name = "createAutoScaleVmProfile",
|
||||||
description = "Creates a profile that contains information about the virtual machine which will be provisioned automatically by autoscale feature.",
|
description = "Creates a profile that contains information about the virtual machine which will be provisioned automatically by autoscale feature.",
|
||||||
@ -80,20 +80,33 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd {
|
|||||||
private Long templateId;
|
private Long templateId;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.OTHER_DEPLOY_PARAMS,
|
@Parameter(name = ApiConstants.OTHER_DEPLOY_PARAMS,
|
||||||
type = CommandType.STRING,
|
type = CommandType.MAP,
|
||||||
description = "parameters other than zoneId/serviceOfferringId/templateId of the auto deployed virtual machine")
|
description = "parameters other than zoneId/serviceOfferringId/templateId of the auto deployed virtual machine.\n"
|
||||||
private String otherDeployParams;
|
+ "Example: otherdeployparams[0].name=serviceofferingid&otherdeployparams[0].value=a7fb50f6-01d9-11ed-8bc1-77f8f0228926&otherdeployparams[1].name=rootdisksize&otherdeployparams[1].value=10 .\n"
|
||||||
|
+ "Possible parameters are \"rootdisksize\", \"diskofferingid\",\"size\", \"securitygroupids\", \"overridediskofferingid\", \"keypairs\", \"affinitygroupids'\" and \"networkids\".")
|
||||||
|
private Map<String, HashMap<String, String>> otherDeployParams;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.AUTOSCALE_VM_DESTROY_TIME,
|
@Parameter(name = ApiConstants.AUTOSCALE_EXPUNGE_VM_GRACE_PERIOD,
|
||||||
type = CommandType.INTEGER,
|
type = CommandType.INTEGER,
|
||||||
description = "the time allowed for existing connections to get closed before a vm is destroyed")
|
description = "the time allowed for existing connections to get closed before a vm is expunged")
|
||||||
private Integer destroyVmGraceperiod;
|
private Integer expungeVmGracePeriod;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.COUNTERPARAM_LIST,
|
@Parameter(name = ApiConstants.COUNTERPARAM_LIST,
|
||||||
type = CommandType.MAP,
|
type = CommandType.MAP,
|
||||||
description = "counterparam list. Example: counterparam[0].name=snmpcommunity&counterparam[0].value=public&counterparam[1].name=snmpport&counterparam[1].value=161")
|
description = "counterparam list. Example: counterparam[0].name=snmpcommunity&counterparam[0].value=public&counterparam[1].name=snmpport&counterparam[1].value=161")
|
||||||
private Map counterParamList;
|
private Map counterParamList;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.USER_DATA,
|
||||||
|
type = CommandType.STRING,
|
||||||
|
description = "an optional binary data that can be sent to the virtual machine upon a successful deployment. " +
|
||||||
|
"This binary data must be base64 encoded before adding it to the request. " +
|
||||||
|
"Using HTTP GET (via querystring), you can send up to 4KB of data after base64 encoding. " +
|
||||||
|
"Using HTTP POST(via POST body), you can send up to 1MB of data after base64 encoding." +
|
||||||
|
"You also need to change vm.userdata.max.length value",
|
||||||
|
length = 1048576,
|
||||||
|
since = "4.18.0")
|
||||||
|
private String userData;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.AUTOSCALE_USER_ID,
|
@Parameter(name = ApiConstants.AUTOSCALE_USER_ID,
|
||||||
type = CommandType.UUID,
|
type = CommandType.UUID,
|
||||||
entityType = UserResponse.class,
|
entityType = UserResponse.class,
|
||||||
@ -103,22 +116,19 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd {
|
|||||||
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the profile to the end user or not", since = "4.4", authorized = {RoleType.Admin})
|
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the profile to the end user or not", since = "4.4", authorized = {RoleType.Admin})
|
||||||
private Boolean display;
|
private Boolean display;
|
||||||
|
|
||||||
private Map<String, String> otherDeployParamMap;
|
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "account that will own the autoscale VM profile")
|
||||||
|
private String accountName;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "an optional project for the autoscale VM profile")
|
||||||
|
private Long projectId;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "domain ID of the account owning a autoscale VM profile")
|
||||||
|
private Long domainId;
|
||||||
|
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
// ///////////////// Accessors ///////////////////////
|
// ///////////////// Accessors ///////////////////////
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
private Long domainId;
|
|
||||||
private Long accountId;
|
|
||||||
|
|
||||||
public Long getDomainId() {
|
|
||||||
if (domainId == null) {
|
|
||||||
getAccountId();
|
|
||||||
}
|
|
||||||
return domainId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getZoneId() {
|
public Long getZoneId() {
|
||||||
return zoneId;
|
return zoneId;
|
||||||
}
|
}
|
||||||
@ -138,69 +148,31 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDisplay() {
|
public boolean isDisplay() {
|
||||||
if(display == null)
|
return display == null || display;
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return display;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getCounterParamList() {
|
public Map getCounterParamList() {
|
||||||
return counterParamList;
|
return counterParamList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOtherDeployParams() {
|
public Map<String, HashMap<String, String>> getOtherDeployParams() {
|
||||||
return otherDeployParams;
|
return otherDeployParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getAutoscaleUserId() {
|
public String getUserData() {
|
||||||
if (autoscaleUserId != null) {
|
return userData;
|
||||||
return autoscaleUserId;
|
|
||||||
} else {
|
|
||||||
return CallContext.current().getCallingUserId();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getDestroyVmGraceperiod() {
|
public Long getAutoscaleUserId() {
|
||||||
return destroyVmGraceperiod;
|
return autoscaleUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getAccountId() {
|
public Integer getExpungeVmGracePeriod() {
|
||||||
if (accountId != null) {
|
return expungeVmGracePeriod;
|
||||||
return accountId;
|
|
||||||
}
|
|
||||||
Account account = null;
|
|
||||||
if (autoscaleUserId != null) {
|
|
||||||
User user = _entityMgr.findById(User.class, autoscaleUserId);
|
|
||||||
account = _entityMgr.findById(Account.class, user.getAccountId());
|
|
||||||
} else {
|
|
||||||
account = CallContext.current().getCallingAccount();
|
|
||||||
}
|
|
||||||
accountId = account.getAccountId();
|
|
||||||
domainId = account.getDomainId();
|
|
||||||
return accountId;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createOtherDeployParamMap() {
|
|
||||||
if (otherDeployParamMap == null) {
|
|
||||||
otherDeployParamMap = new HashMap<String, String>();
|
|
||||||
}
|
|
||||||
if (otherDeployParams == null)
|
|
||||||
return;
|
|
||||||
String[] keyValues = otherDeployParams.split("&"); // hostid=123, hypervisor=xenserver
|
|
||||||
for (String keyValue : keyValues) { // keyValue == "hostid=123"
|
|
||||||
String[] keyAndValue = keyValue.split("="); // keyValue = hostid, 123
|
|
||||||
if (keyAndValue.length != 2) {
|
|
||||||
throw new InvalidParameterValueException("Invalid parameter in otherDeployParam : " + keyValue);
|
|
||||||
}
|
|
||||||
String paramName = keyAndValue[0]; // hostid
|
|
||||||
String paramValue = keyAndValue[1]; // 123
|
|
||||||
otherDeployParamMap.put(paramName, paramValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, String> getDeployParamMap() {
|
public HashMap<String, String> getDeployParamMap() {
|
||||||
createOtherDeployParamMap();
|
HashMap<String, String> deployParams = new HashMap<>(getOtherDeployParamsMap());
|
||||||
HashMap<String, String> deployParams = new HashMap<String, String>(otherDeployParamMap);
|
|
||||||
deployParams.put("command", "deployVirtualMachine");
|
deployParams.put("command", "deployVirtualMachine");
|
||||||
deployParams.put("zoneId", zoneId.toString());
|
deployParams.put("zoneId", zoneId.toString());
|
||||||
deployParams.put("serviceOfferingId", serviceOfferingId.toString());
|
deployParams.put("serviceOfferingId", serviceOfferingId.toString());
|
||||||
@ -208,12 +180,28 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd {
|
|||||||
return deployParams;
|
return deployParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOtherDeployParam(String param) {
|
private Map<String, String> getOtherDeployParamsMap() {
|
||||||
if (param == null) {
|
Map<String, String> otherDeployParamsMap = new HashMap<>();
|
||||||
return null;
|
if (MapUtils.isNotEmpty(otherDeployParams)) {
|
||||||
|
for (HashMap<String, String> paramKVpair : otherDeployParams.values()) {
|
||||||
|
String paramName = paramKVpair.get("name");
|
||||||
|
String paramValue = paramKVpair.get("value");
|
||||||
|
otherDeployParamsMap.put(paramName,paramValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
createOtherDeployParamMap();
|
return otherDeployParamsMap;
|
||||||
return otherDeployParamMap.get(param);
|
}
|
||||||
|
|
||||||
|
public String getAccountName() {
|
||||||
|
return accountName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getProjectId() {
|
||||||
|
return projectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getDomainId() {
|
||||||
|
return domainId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
@ -231,7 +219,12 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getEntityOwnerId() {
|
public long getEntityOwnerId() {
|
||||||
return getAccountId();
|
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||||
|
if (accountId == null) {
|
||||||
|
return CallContext.current().getCallingAccount().getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
return accountId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -29,13 +29,14 @@ import org.apache.cloudstack.api.ServerApiException;
|
|||||||
import org.apache.cloudstack.api.response.ConditionResponse;
|
import org.apache.cloudstack.api.response.ConditionResponse;
|
||||||
import org.apache.cloudstack.api.response.CounterResponse;
|
import org.apache.cloudstack.api.response.CounterResponse;
|
||||||
import org.apache.cloudstack.api.response.DomainResponse;
|
import org.apache.cloudstack.api.response.DomainResponse;
|
||||||
|
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||||
import org.apache.cloudstack.context.CallContext;
|
import org.apache.cloudstack.context.CallContext;
|
||||||
|
|
||||||
import com.cloud.event.EventTypes;
|
import com.cloud.event.EventTypes;
|
||||||
import com.cloud.exception.ResourceAllocationException;
|
import com.cloud.exception.ResourceAllocationException;
|
||||||
import com.cloud.network.as.Condition;
|
import com.cloud.network.as.Condition;
|
||||||
|
|
||||||
@APICommand(name = "createCondition", description = "Creates a condition", responseObject = ConditionResponse.class, entityType = {Condition.class},
|
@APICommand(name = "createCondition", description = "Creates a condition for VM auto scaling", responseObject = ConditionResponse.class, entityType = {Condition.class},
|
||||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||||
public class CreateConditionCmd extends BaseAsyncCreateCmd {
|
public class CreateConditionCmd extends BaseAsyncCreateCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(CreateConditionCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(CreateConditionCmd.class.getName());
|
||||||
@ -48,15 +49,18 @@ public class CreateConditionCmd extends BaseAsyncCreateCmd {
|
|||||||
@Parameter(name = ApiConstants.COUNTER_ID, type = CommandType.UUID, entityType = CounterResponse.class, required = true, description = "ID of the Counter.")
|
@Parameter(name = ApiConstants.COUNTER_ID, type = CommandType.UUID, entityType = CounterResponse.class, required = true, description = "ID of the Counter.")
|
||||||
private long counterId;
|
private long counterId;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.RELATIONAL_OPERATOR, type = CommandType.STRING, required = true, description = "Relational Operator to be used with threshold.")
|
@Parameter(name = ApiConstants.RELATIONAL_OPERATOR, type = CommandType.STRING, required = true, description = "Relational Operator to be used with threshold. Valid values are EQ, GT, LT, GE, LE.")
|
||||||
private String relationalOperator;
|
private String relationalOperator;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.THRESHOLD, type = CommandType.LONG, required = true, description = "Threshold value.")
|
@Parameter(name = ApiConstants.THRESHOLD, type = CommandType.LONG, required = true, description = "Value for which the Counter will be evaluated with the Operator selected.")
|
||||||
private Long threshold;
|
private Long threshold;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "the account of the condition. " + "Must be used with the domainId parameter.")
|
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "the account of the condition. " + "Must be used with the domainId parameter.")
|
||||||
private String accountName;
|
private String accountName;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "an optional project for condition")
|
||||||
|
private Long projectId;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "the domain ID of the account.")
|
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "the domain ID of the account.")
|
||||||
private Long domainId;
|
private Long domainId;
|
||||||
|
|
||||||
@ -103,17 +107,14 @@ public class CreateConditionCmd extends BaseAsyncCreateCmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getAccountName() {
|
public String getAccountName() {
|
||||||
if (accountName == null) {
|
|
||||||
return CallContext.current().getCallingAccount().getAccountName();
|
|
||||||
}
|
|
||||||
|
|
||||||
return accountName;
|
return accountName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getProjectId() {
|
||||||
|
return projectId;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getDomainId() {
|
public Long getDomainId() {
|
||||||
if (domainId == null) {
|
|
||||||
return CallContext.current().getCallingAccount().getDomainId();
|
|
||||||
}
|
|
||||||
return domainId;
|
return domainId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +139,7 @@ public class CreateConditionCmd extends BaseAsyncCreateCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getEntityOwnerId() {
|
public long getEntityOwnerId() {
|
||||||
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, null, true);
|
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true);
|
||||||
if (accountId == null) {
|
if (accountId == null) {
|
||||||
return CallContext.current().getCallingAccount().getId();
|
return CallContext.current().getCallingAccount().getId();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,6 +52,12 @@ public class DeleteAutoScaleVmGroupCmd extends BaseAsyncCmd {
|
|||||||
description = "the ID of the autoscale group")
|
description = "the ID of the autoscale group")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.CLEANUP,
|
||||||
|
type = CommandType.BOOLEAN,
|
||||||
|
description = "true if all VMs have to be cleaned up, false otherwise",
|
||||||
|
since = "4.18.0")
|
||||||
|
private Boolean cleanup;
|
||||||
|
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
// ///////////////// Accessors ///////////////////////
|
// ///////////////// Accessors ///////////////////////
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
@ -60,6 +66,10 @@ public class DeleteAutoScaleVmGroupCmd extends BaseAsyncCmd {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean getCleanup() {
|
||||||
|
return cleanup != null && cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
// ///////////// API Implementation///////////////////
|
// ///////////// API Implementation///////////////////
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
@ -93,7 +103,7 @@ public class DeleteAutoScaleVmGroupCmd extends BaseAsyncCmd {
|
|||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
CallContext.current().setEventDetails("AutoScale Vm Group Id: " + getId());
|
CallContext.current().setEventDetails("AutoScale Vm Group Id: " + getId());
|
||||||
boolean result = _autoScaleService.deleteAutoScaleVmGroup(id);
|
boolean result = _autoScaleService.deleteAutoScaleVmGroup(id, getCleanup());
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||||
|
|||||||
@ -36,7 +36,7 @@ import com.cloud.exception.ResourceInUseException;
|
|||||||
import com.cloud.network.as.Condition;
|
import com.cloud.network.as.Condition;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
|
|
||||||
@APICommand(name = "deleteCondition", description = "Removes a condition", responseObject = SuccessResponse.class, entityType = {Condition.class},
|
@APICommand(name = "deleteCondition", description = "Removes a condition for VM auto scaling", responseObject = SuccessResponse.class, entityType = {Condition.class},
|
||||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||||
public class DeleteConditionCmd extends BaseAsyncCmd {
|
public class DeleteConditionCmd extends BaseAsyncCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(DeleteConditionCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(DeleteConditionCmd.class.getName());
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import org.apache.log4j.Logger;
|
|||||||
|
|
||||||
import org.apache.cloudstack.api.APICommand;
|
import org.apache.cloudstack.api.APICommand;
|
||||||
import org.apache.cloudstack.api.ApiConstants;
|
import org.apache.cloudstack.api.ApiConstants;
|
||||||
import org.apache.cloudstack.api.BaseListAccountResourcesCmd;
|
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
|
||||||
import org.apache.cloudstack.api.Parameter;
|
import org.apache.cloudstack.api.Parameter;
|
||||||
import org.apache.cloudstack.api.response.AutoScalePolicyResponse;
|
import org.apache.cloudstack.api.response.AutoScalePolicyResponse;
|
||||||
import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse;
|
import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse;
|
||||||
@ -34,7 +34,7 @@ import com.cloud.network.as.AutoScalePolicy;
|
|||||||
|
|
||||||
@APICommand(name = "listAutoScalePolicies", description = "Lists autoscale policies.", responseObject = AutoScalePolicyResponse.class, entityType = {AutoScalePolicy.class},
|
@APICommand(name = "listAutoScalePolicies", description = "Lists autoscale policies.", responseObject = AutoScalePolicyResponse.class, entityType = {AutoScalePolicy.class},
|
||||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||||
public class ListAutoScalePoliciesCmd extends BaseListAccountResourcesCmd {
|
public class ListAutoScalePoliciesCmd extends BaseListProjectAndAccountResourcesCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(ListAutoScalePoliciesCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(ListAutoScalePoliciesCmd.class.getName());
|
||||||
|
|
||||||
private static final String s_name = "listautoscalepoliciesresponse";
|
private static final String s_name = "listautoscalepoliciesresponse";
|
||||||
@ -46,6 +46,9 @@ public class ListAutoScalePoliciesCmd extends BaseListAccountResourcesCmd {
|
|||||||
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = AutoScalePolicyResponse.class, description = "the ID of the autoscale policy")
|
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = AutoScalePolicyResponse.class, description = "the ID of the autoscale policy")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "the name of the autoscale policy", since = "4.18.0")
|
||||||
|
private String name;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.CONDITION_ID, type = CommandType.UUID, entityType = ConditionResponse.class, description = "the ID of the condition of the policy")
|
@Parameter(name = ApiConstants.CONDITION_ID, type = CommandType.UUID, entityType = ConditionResponse.class, description = "the ID of the condition of the policy")
|
||||||
private Long conditionId;
|
private Long conditionId;
|
||||||
|
|
||||||
@ -65,6 +68,10 @@ public class ListAutoScalePoliciesCmd extends BaseListAccountResourcesCmd {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getConditionId() {
|
public Long getConditionId() {
|
||||||
return conditionId;
|
return conditionId;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,6 +50,9 @@ public class ListAutoScaleVmGroupsCmd extends BaseListProjectAndAccountResources
|
|||||||
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = AutoScaleVmGroupResponse.class, description = "the ID of the autoscale vm group")
|
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = AutoScaleVmGroupResponse.class, description = "the ID of the autoscale vm group")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "the name of the autoscale vmgroup", since = "4.18.0")
|
||||||
|
private String name;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.LBID, type = CommandType.UUID, entityType = FirewallRuleResponse.class, description = "the ID of the loadbalancer")
|
@Parameter(name = ApiConstants.LBID, type = CommandType.UUID, entityType = FirewallRuleResponse.class, description = "the ID of the loadbalancer")
|
||||||
private Long loadBalancerId;
|
private Long loadBalancerId;
|
||||||
|
|
||||||
@ -73,6 +76,10 @@ public class ListAutoScaleVmGroupsCmd extends BaseListProjectAndAccountResources
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getLoadBalancerId() {
|
public Long getLoadBalancerId() {
|
||||||
return loadBalancerId;
|
return loadBalancerId;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import org.apache.log4j.Logger;
|
|||||||
|
|
||||||
import org.apache.cloudstack.api.APICommand;
|
import org.apache.cloudstack.api.APICommand;
|
||||||
import org.apache.cloudstack.api.ApiConstants;
|
import org.apache.cloudstack.api.ApiConstants;
|
||||||
import org.apache.cloudstack.api.BaseListAccountResourcesCmd;
|
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
|
||||||
import org.apache.cloudstack.api.Parameter;
|
import org.apache.cloudstack.api.Parameter;
|
||||||
import org.apache.cloudstack.api.response.AutoScalePolicyResponse;
|
import org.apache.cloudstack.api.response.AutoScalePolicyResponse;
|
||||||
import org.apache.cloudstack.api.response.ConditionResponse;
|
import org.apache.cloudstack.api.response.ConditionResponse;
|
||||||
@ -33,9 +33,9 @@ import org.apache.cloudstack.api.response.ListResponse;
|
|||||||
|
|
||||||
import com.cloud.network.as.Condition;
|
import com.cloud.network.as.Condition;
|
||||||
|
|
||||||
@APICommand(name = "listConditions", description = "List Conditions for the specific user", responseObject = ConditionResponse.class,
|
@APICommand(name = "listConditions", description = "List Conditions for VM auto scaling", responseObject = ConditionResponse.class,
|
||||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||||
public class ListConditionsCmd extends BaseListAccountResourcesCmd {
|
public class ListConditionsCmd extends BaseListProjectAndAccountResourcesCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(ListConditionsCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(ListConditionsCmd.class.getName());
|
||||||
private static final String s_name = "listconditionsresponse";
|
private static final String s_name = "listconditionsresponse";
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,7 @@ import org.apache.cloudstack.api.response.ListResponse;
|
|||||||
import com.cloud.network.as.Counter;
|
import com.cloud.network.as.Counter;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
|
|
||||||
@APICommand(name = "listCounters", description = "List the counters", responseObject = CounterResponse.class,
|
@APICommand(name = "listCounters", description = "List the counters for VM auto scaling", responseObject = CounterResponse.class,
|
||||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||||
public class ListCountersCmd extends BaseListCmd {
|
public class ListCountersCmd extends BaseListCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(ListCountersCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(ListCountersCmd.class.getName());
|
||||||
@ -51,6 +51,9 @@ public class ListCountersCmd extends BaseListCmd {
|
|||||||
@Parameter(name = ApiConstants.SOURCE, type = CommandType.STRING, description = "Source of the counter.")
|
@Parameter(name = ApiConstants.SOURCE, type = CommandType.STRING, description = "Source of the counter.")
|
||||||
private String source;
|
private String source;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, description = "Network provider of the counter.", since = "4.18.0")
|
||||||
|
private String provider;
|
||||||
|
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
// ///////////// API Implementation///////////////////
|
// ///////////// API Implementation///////////////////
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
@ -92,6 +95,10 @@ public class ListCountersCmd extends BaseListCmd {
|
|||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getProvider() {
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getEntityOwnerId() {
|
public long getEntityOwnerId() {
|
||||||
return Account.ACCOUNT_ID_SYSTEM;
|
return Account.ACCOUNT_ID_SYSTEM;
|
||||||
|
|||||||
@ -49,12 +49,18 @@ public class UpdateAutoScalePolicyCmd extends BaseAsyncCmd {
|
|||||||
// ////////////// API parameters /////////////////////
|
// ////////////// API parameters /////////////////////
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.DURATION, type = CommandType.INTEGER, description = "the duration for which the conditions have to be true before action is taken")
|
@Parameter(name = ApiConstants.NAME,
|
||||||
|
type = CommandType.STRING,
|
||||||
|
description = "the name of the autoscale policy",
|
||||||
|
since = "4.18.0")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.DURATION, type = CommandType.INTEGER, description = "the duration in which the conditions have to be true before action is taken")
|
||||||
private Integer duration;
|
private Integer duration;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.QUIETTIME,
|
@Parameter(name = ApiConstants.QUIETTIME,
|
||||||
type = CommandType.INTEGER,
|
type = CommandType.INTEGER,
|
||||||
description = "the cool down period for which the policy should not be evaluated after the action has been taken")
|
description = "the cool down period in which the policy should not be evaluated after the action has been taken")
|
||||||
private Integer quietTime;
|
private Integer quietTime;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.CONDITION_IDS,
|
@Parameter(name = ApiConstants.CONDITION_IDS,
|
||||||
@ -93,6 +99,10 @@ public class UpdateAutoScalePolicyCmd extends BaseAsyncCmd {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getDuration() {
|
public Integer getDuration() {
|
||||||
return duration;
|
return duration;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,6 +50,12 @@ public class UpdateAutoScaleVmGroupCmd extends BaseAsyncCustomIdCmd {
|
|||||||
// ////////////// API parameters /////////////////////
|
// ////////////// API parameters /////////////////////
|
||||||
// ///////////////////////////////////////////////////
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.NAME,
|
||||||
|
type = CommandType.STRING,
|
||||||
|
description = "the name of the autoscale vmgroup",
|
||||||
|
since = "4.18.0")
|
||||||
|
private String name;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.MIN_MEMBERS,
|
@Parameter(name = ApiConstants.MIN_MEMBERS,
|
||||||
type = CommandType.INTEGER,
|
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.")
|
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.")
|
||||||
@ -60,7 +66,7 @@ public class UpdateAutoScaleVmGroupCmd extends BaseAsyncCustomIdCmd {
|
|||||||
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.")
|
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;
|
private Integer maxMembers;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.INTERVAL, type = CommandType.INTEGER, description = "the frequency at which the conditions have to be evaluated")
|
@Parameter(name = ApiConstants.INTERVAL, type = CommandType.INTEGER, description = "the frequency in which the performance counters to be collected")
|
||||||
private Integer interval;
|
private Integer interval;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.SCALEUP_POLICY_IDS,
|
@Parameter(name = ApiConstants.SCALEUP_POLICY_IDS,
|
||||||
@ -113,6 +119,10 @@ public class UpdateAutoScaleVmGroupCmd extends BaseAsyncCustomIdCmd {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getMinMembers() {
|
public Integer getMinMembers() {
|
||||||
return minMembers;
|
return minMembers;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.cloudstack.api.command.user.autoscale;
|
package org.apache.cloudstack.api.command.user.autoscale;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@ -32,6 +33,7 @@ import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
|
|||||||
import org.apache.cloudstack.api.Parameter;
|
import org.apache.cloudstack.api.Parameter;
|
||||||
import org.apache.cloudstack.api.ServerApiException;
|
import org.apache.cloudstack.api.ServerApiException;
|
||||||
import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
|
import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
|
||||||
|
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
|
||||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||||
import org.apache.cloudstack.api.response.UserResponse;
|
import org.apache.cloudstack.api.response.UserResponse;
|
||||||
import org.apache.cloudstack.context.CallContext;
|
import org.apache.cloudstack.context.CallContext;
|
||||||
@ -59,22 +61,48 @@ public class UpdateAutoScaleVmProfileCmd extends BaseAsyncCustomIdCmd {
|
|||||||
description = "the ID of the autoscale vm profile")
|
description = "the ID of the autoscale vm profile")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.SERVICE_OFFERING_ID,
|
||||||
|
type = CommandType.UUID,
|
||||||
|
entityType = ServiceOfferingResponse.class,
|
||||||
|
description = "the service offering of the auto deployed virtual machine",
|
||||||
|
since = "4.18.0")
|
||||||
|
private Long serviceOfferingId;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.TEMPLATE_ID,
|
@Parameter(name = ApiConstants.TEMPLATE_ID,
|
||||||
type = CommandType.UUID,
|
type = CommandType.UUID,
|
||||||
entityType = TemplateResponse.class,
|
entityType = TemplateResponse.class,
|
||||||
description = "the template of the auto deployed virtual machine")
|
description = "the template of the auto deployed virtual machine")
|
||||||
private Long templateId;
|
private Long templateId;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.AUTOSCALE_VM_DESTROY_TIME,
|
@Parameter(name = ApiConstants.AUTOSCALE_EXPUNGE_VM_GRACE_PERIOD,
|
||||||
type = CommandType.INTEGER,
|
type = CommandType.INTEGER,
|
||||||
description = "the time allowed for existing connections to get closed before a vm is destroyed")
|
description = "the time allowed for existing connections to get closed before a vm is destroyed")
|
||||||
private Integer destroyVmGraceperiod;
|
private Integer expungeVmGracePeriod;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.COUNTERPARAM_LIST,
|
@Parameter(name = ApiConstants.COUNTERPARAM_LIST,
|
||||||
type = CommandType.MAP,
|
type = CommandType.MAP,
|
||||||
description = "counterparam list. Example: counterparam[0].name=snmpcommunity&counterparam[0].value=public&counterparam[1].name=snmpport&counterparam[1].value=161")
|
description = "counterparam list. Example: counterparam[0].name=snmpcommunity&counterparam[0].value=public&counterparam[1].name=snmpport&counterparam[1].value=161")
|
||||||
private Map counterParamList;
|
private Map counterParamList;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.OTHER_DEPLOY_PARAMS,
|
||||||
|
type = CommandType.MAP,
|
||||||
|
description = "parameters other than zoneId/serviceOfferringId/templateId of the auto deployed virtual machine. \n"
|
||||||
|
+ "Example: otherdeployparams[0].name=serviceofferingid&otherdeployparams[0].value=a7fb50f6-01d9-11ed-8bc1-77f8f0228926&otherdeployparams[1].name=rootdisksize&otherdeployparams[1].value=10 .\n"
|
||||||
|
+ "Possible parameters are \"rootdisksize\", \"diskofferingid\",\"size\", \"securitygroupids\", \"overridediskofferingid\", \"keypairs\", \"affinitygroupids'\" and \"networkids\".",
|
||||||
|
since = "4.18.0")
|
||||||
|
private Map<String, HashMap<String, String>> otherDeployParams;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.USER_DATA,
|
||||||
|
type = CommandType.STRING,
|
||||||
|
description = "an optional binary data that can be sent to the virtual machine upon a successful deployment. " +
|
||||||
|
"This binary data must be base64 encoded before adding it to the request. " +
|
||||||
|
"Using HTTP GET (via querystring), you can send up to 4KB of data after base64 encoding. " +
|
||||||
|
"Using HTTP POST(via POST body), you can send up to 1MB of data after base64 encoding." +
|
||||||
|
"You also need to change vm.userdata.max.length value",
|
||||||
|
length = 1048576,
|
||||||
|
since = "4.18.0")
|
||||||
|
private String userData;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.AUTOSCALE_USER_ID,
|
@Parameter(name = ApiConstants.AUTOSCALE_USER_ID,
|
||||||
type = CommandType.UUID,
|
type = CommandType.UUID,
|
||||||
entityType = UserResponse.class,
|
entityType = UserResponse.class,
|
||||||
@ -109,20 +137,32 @@ public class UpdateAutoScaleVmProfileCmd extends BaseAsyncCustomIdCmd {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getServiceOfferingId() {
|
||||||
|
return serviceOfferingId;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getTemplateId() {
|
public Long getTemplateId() {
|
||||||
return templateId;
|
return templateId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, HashMap<String, String>> getOtherDeployParams() {
|
||||||
|
return otherDeployParams;
|
||||||
|
}
|
||||||
|
|
||||||
public Map getCounterParamList() {
|
public Map getCounterParamList() {
|
||||||
return counterParamList;
|
return counterParamList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUserData() {
|
||||||
|
return userData;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getAutoscaleUserId() {
|
public Long getAutoscaleUserId() {
|
||||||
return autoscaleUserId;
|
return autoscaleUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getDestroyVmGraceperiod() {
|
public Integer getExpungeVmGracePeriod() {
|
||||||
return destroyVmGraceperiod;
|
return expungeVmGracePeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getDisplay() {
|
public Boolean getDisplay() {
|
||||||
|
|||||||
@ -0,0 +1,124 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
|
||||||
|
package org.apache.cloudstack.api.command.user.autoscale;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.acl.RoleType;
|
||||||
|
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
|
||||||
|
import org.apache.cloudstack.api.ACL;
|
||||||
|
import org.apache.cloudstack.api.APICommand;
|
||||||
|
import org.apache.cloudstack.api.ApiCommandResourceType;
|
||||||
|
import org.apache.cloudstack.api.ApiConstants;
|
||||||
|
import org.apache.cloudstack.api.ApiErrorCode;
|
||||||
|
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||||
|
import org.apache.cloudstack.api.BaseCmd;
|
||||||
|
import org.apache.cloudstack.api.Parameter;
|
||||||
|
import org.apache.cloudstack.api.ServerApiException;
|
||||||
|
import org.apache.cloudstack.api.response.ConditionResponse;
|
||||||
|
import org.apache.cloudstack.api.response.SuccessResponse;
|
||||||
|
|
||||||
|
import com.cloud.event.EventTypes;
|
||||||
|
import com.cloud.exception.ResourceInUseException;
|
||||||
|
import com.cloud.network.as.Condition;
|
||||||
|
import com.cloud.user.Account;
|
||||||
|
|
||||||
|
@APICommand(name = UpdateConditionCmd.API_NAME, description = "Updates a condition for VM auto scaling", responseObject = SuccessResponse.class, entityType = {Condition.class},
|
||||||
|
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User},
|
||||||
|
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18.0")
|
||||||
|
public class UpdateConditionCmd extends BaseAsyncCmd {
|
||||||
|
public static final Logger LOGGER = Logger.getLogger(UpdateConditionCmd.class.getName());
|
||||||
|
public static final String API_NAME = "updateCondition";
|
||||||
|
|
||||||
|
// ///////////////////////////////////////////////////
|
||||||
|
// ////////////// API parameters /////////////////////
|
||||||
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ACL(accessType = AccessType.OperateEntry)
|
||||||
|
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = ConditionResponse.class, required = true, description = "the ID of the condition.")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.RELATIONAL_OPERATOR, type = CommandType.STRING, required = true, description = "Relational Operator to be used with threshold. Valid values are EQ, GT, LT, GE, LE.")
|
||||||
|
private String relationalOperator;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.THRESHOLD, type = CommandType.LONG, required = true, description = "Value for which the Counter will be evaluated with the Operator selected.")
|
||||||
|
private Long threshold;
|
||||||
|
|
||||||
|
// ///////////////////////////////////////////////////
|
||||||
|
// ///////////// API Implementation///////////////////
|
||||||
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
try {
|
||||||
|
Condition condition = _autoScaleService.updateCondition(this);
|
||||||
|
ConditionResponse response = _responseGenerator.createConditionResponse(condition);
|
||||||
|
response.setResponseName(getCommandName());
|
||||||
|
setResponseObject(response);
|
||||||
|
} catch (ResourceInUseException ex) {
|
||||||
|
LOGGER.warn("Exception: ", ex);
|
||||||
|
throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ///////////////////////////////////////////////////
|
||||||
|
// ///////////////// Accessors ///////////////////////
|
||||||
|
// ///////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRelationalOperator() {
|
||||||
|
return relationalOperator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getThreshold() {
|
||||||
|
return threshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApiCommandResourceType getApiResourceType() {
|
||||||
|
return ApiCommandResourceType.Condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandName() {
|
||||||
|
return API_NAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getEntityOwnerId() {
|
||||||
|
Condition condition = _entityMgr.findById(Condition.class, getId());
|
||||||
|
if (condition != null) {
|
||||||
|
return condition.getAccountId();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getEventType() {
|
||||||
|
return EventTypes.EVENT_CONDITION_UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getEventDescription() {
|
||||||
|
return "Updating a condition.";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -169,7 +169,7 @@ public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd {
|
|||||||
boolean result = false;
|
boolean result = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = _lbService.assignToLoadBalancer(getLoadBalancerId(), virtualMachineIds, vmIdIpsMap);
|
result = _lbService.assignToLoadBalancer(getLoadBalancerId(), virtualMachineIds, vmIdIpsMap, false);
|
||||||
}catch (CloudRuntimeException ex) {
|
}catch (CloudRuntimeException ex) {
|
||||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign load balancer rule");
|
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign load balancer rule");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -159,7 +159,7 @@ public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd {
|
|||||||
CallContext.current().setEventDetails("Load balancer Id: " + getId() + " VmIds: " + StringUtils.join(getVirtualMachineIds(), ","));
|
CallContext.current().setEventDetails("Load balancer Id: " + getId() + " VmIds: " + StringUtils.join(getVirtualMachineIds(), ","));
|
||||||
Map<Long, List<String>> vmIdIpsMap = getVmIdIpListMap();
|
Map<Long, List<String>> vmIdIpsMap = getVmIdIpListMap();
|
||||||
try {
|
try {
|
||||||
boolean result = _lbService.removeFromLoadBalancer(id, virtualMachineIds, vmIdIpsMap);
|
boolean result = _lbService.removeFromLoadBalancer(id, virtualMachineIds, vmIdIpsMap, false);
|
||||||
if (result) {
|
if (result) {
|
||||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||||
this.setResponseObject(response);
|
this.setResponseObject(response);
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
|
|||||||
import org.apache.cloudstack.api.Parameter;
|
import org.apache.cloudstack.api.Parameter;
|
||||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||||
import org.apache.cloudstack.api.command.user.UserCmd;
|
import org.apache.cloudstack.api.command.user.UserCmd;
|
||||||
|
import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse;
|
||||||
import org.apache.cloudstack.api.response.BackupOfferingResponse;
|
import org.apache.cloudstack.api.response.BackupOfferingResponse;
|
||||||
import org.apache.cloudstack.api.response.InstanceGroupResponse;
|
import org.apache.cloudstack.api.response.InstanceGroupResponse;
|
||||||
import org.apache.cloudstack.api.response.IsoVmResponse;
|
import org.apache.cloudstack.api.response.IsoVmResponse;
|
||||||
@ -132,6 +133,9 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd implements UserCmd {
|
|||||||
@Parameter(name = ApiConstants.HA_ENABLE, type = CommandType.BOOLEAN, description = "list by the High Availability offering; true if filtering VMs with HA enabled; false for VMs with HA disabled", since = "4.15")
|
@Parameter(name = ApiConstants.HA_ENABLE, type = CommandType.BOOLEAN, description = "list by the High Availability offering; true if filtering VMs with HA enabled; false for VMs with HA disabled", since = "4.15")
|
||||||
private Boolean haEnabled;
|
private Boolean haEnabled;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.AUTOSCALE_VMGROUP_ID, type = CommandType.UUID, entityType = AutoScaleVmGroupResponse.class, description = "the ID of AutoScaling VM Group", since = "4.18.0")
|
||||||
|
private Long autoScaleVmGroupId;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.SHOW_RESOURCE_ICON, type = CommandType.BOOLEAN,
|
@Parameter(name = ApiConstants.SHOW_RESOURCE_ICON, type = CommandType.BOOLEAN,
|
||||||
description = "flag to display the resource icon for VMs", since = "4.16.0.0")
|
description = "flag to display the resource icon for VMs", since = "4.16.0.0")
|
||||||
private Boolean showIcon;
|
private Boolean showIcon;
|
||||||
@ -227,6 +231,10 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd implements UserCmd {
|
|||||||
return this.showUserData;
|
return this.showUserData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getAutoScaleVmGroupId() {
|
||||||
|
return autoScaleVmGroupId;
|
||||||
|
}
|
||||||
|
|
||||||
public EnumSet<VMDetails> getDetails() throws InvalidParameterValueException {
|
public EnumSet<VMDetails> getDetails() throws InvalidParameterValueException {
|
||||||
EnumSet<VMDetails> dv;
|
EnumSet<VMDetails> dv;
|
||||||
if (viewDetails == null || viewDetails.size() <= 0) {
|
if (viewDetails == null || viewDetails.size() <= 0) {
|
||||||
|
|||||||
@ -34,6 +34,10 @@ public class AutoScalePolicyResponse extends BaseResponse implements ControlledE
|
|||||||
@Param(description = "the autoscale policy ID")
|
@Param(description = "the autoscale policy ID")
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.NAME)
|
||||||
|
@Param(description = "name of the autoscale policy")
|
||||||
|
private String name;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.ACTION)
|
@SerializedName(ApiConstants.ACTION)
|
||||||
@Param(description = "the action to be executed if all the conditions evaluate to true for the specified duration.")
|
@Param(description = "the action to be executed if all the conditions evaluate to true for the specified duration.")
|
||||||
private String action;
|
private String action;
|
||||||
@ -79,6 +83,10 @@ public class AutoScalePolicyResponse extends BaseResponse implements ControlledE
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
public void setDuration(Integer duration) {
|
public void setDuration(Integer duration) {
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,11 +16,12 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package org.apache.cloudstack.api.response;
|
package org.apache.cloudstack.api.response;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.cloudstack.acl.RoleType;
|
import org.apache.cloudstack.acl.RoleType;
|
||||||
import org.apache.cloudstack.api.ApiConstants;
|
import org.apache.cloudstack.api.ApiConstants;
|
||||||
import org.apache.cloudstack.api.BaseResponse;
|
import org.apache.cloudstack.api.BaseResponseWithAnnotations;
|
||||||
import org.apache.cloudstack.api.EntityReference;
|
import org.apache.cloudstack.api.EntityReference;
|
||||||
|
|
||||||
import com.cloud.network.as.AutoScaleVmGroup;
|
import com.cloud.network.as.AutoScaleVmGroup;
|
||||||
@ -28,16 +29,48 @@ import com.cloud.serializer.Param;
|
|||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
@EntityReference(value = AutoScaleVmGroup.class)
|
@EntityReference(value = AutoScaleVmGroup.class)
|
||||||
public class AutoScaleVmGroupResponse extends BaseResponse implements ControlledEntityResponse {
|
public class AutoScaleVmGroupResponse extends BaseResponseWithAnnotations implements ControlledEntityResponse {
|
||||||
|
|
||||||
@SerializedName(ApiConstants.ID)
|
@SerializedName(ApiConstants.ID)
|
||||||
@Param(description = "the autoscale vm group ID")
|
@Param(description = "the autoscale vm group ID")
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.NAME)
|
||||||
|
@Param(description = "the name of the autoscale vm group ")
|
||||||
|
private String name;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.LBID)
|
@SerializedName(ApiConstants.LBID)
|
||||||
@Param(description = "the load balancer rule ID")
|
@Param(description = "the load balancer rule ID")
|
||||||
private String loadBalancerId;
|
private String loadBalancerId;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.ASSOCIATED_NETWORK_NAME)
|
||||||
|
@Param(description = "the name of the guest network the lb rule belongs to")
|
||||||
|
private String networkName;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.ASSOCIATED_NETWORK_ID)
|
||||||
|
@Param(description = "the id of the guest network the lb rule belongs to")
|
||||||
|
private String networkId;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.LB_PROVIDER)
|
||||||
|
@Param(description = "the lb provider of the guest network the lb rule belongs to")
|
||||||
|
private String lbProvider;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.PUBLIC_IP_ID)
|
||||||
|
@Param(description = "the public ip address id")
|
||||||
|
private String publicIpId;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.PUBLIC_IP)
|
||||||
|
@Param(description = "the public ip address")
|
||||||
|
private String publicIp;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.PUBLIC_PORT)
|
||||||
|
@Param(description = "the public port")
|
||||||
|
private String publicPort;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.PRIVATE_PORT)
|
||||||
|
@Param(description = "the private port")
|
||||||
|
private String privatePort;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.VMPROFILE_ID)
|
@SerializedName(ApiConstants.VMPROFILE_ID)
|
||||||
@Param(description = "the autoscale profile that contains information about the vms in the vm group.")
|
@Param(description = "the autoscale profile that contains information about the vms in the vm group.")
|
||||||
private String profileId;
|
private String profileId;
|
||||||
@ -50,6 +83,10 @@ public class AutoScaleVmGroupResponse extends BaseResponse implements Controlled
|
|||||||
@Param(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.")
|
@Param(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;
|
private int maxMembers;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.AVAILABLE_VIRTUAL_MACHINE_COUNT)
|
||||||
|
@Param(description = "the number of available virtual machines (in Running, Starting, Stopping or Migrating state) in the vmgroup", since = "4.18.0")
|
||||||
|
private int availableVirtualMachineCount;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.INTERVAL)
|
@SerializedName(ApiConstants.INTERVAL)
|
||||||
@Param(description = "the frequency at which the conditions have to be evaluated")
|
@Param(description = "the frequency at which the conditions have to be evaluated")
|
||||||
private int interval;
|
private int interval;
|
||||||
@ -67,31 +104,35 @@ public class AutoScaleVmGroupResponse extends BaseResponse implements Controlled
|
|||||||
private List<AutoScalePolicyResponse> scaleDownPolicies;
|
private List<AutoScalePolicyResponse> scaleDownPolicies;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.ACCOUNT)
|
@SerializedName(ApiConstants.ACCOUNT)
|
||||||
@Param(description = "the account owning the instance group")
|
@Param(description = "the account owning the vm group")
|
||||||
private String accountName;
|
private String accountName;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.PROJECT_ID)
|
@SerializedName(ApiConstants.PROJECT_ID)
|
||||||
@Param(description = "the project id vm profile")
|
@Param(description = "the project id of the vm group")
|
||||||
private String projectId;
|
private String projectId;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.PROJECT)
|
@SerializedName(ApiConstants.PROJECT)
|
||||||
@Param(description = "the project name of the vm profile")
|
@Param(description = "the project name of the vm group")
|
||||||
private String projectName;
|
private String projectName;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.DOMAIN_ID)
|
@SerializedName(ApiConstants.DOMAIN_ID)
|
||||||
@Param(description = "the domain ID of the vm profile")
|
@Param(description = "the domain ID of the vm group")
|
||||||
private String domainId;
|
private String domainId;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.DOMAIN)
|
@SerializedName(ApiConstants.DOMAIN)
|
||||||
@Param(description = "the domain name of the vm profile")
|
@Param(description = "the domain name of the vm group")
|
||||||
private String domainName;
|
private String domainName;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.FOR_DISPLAY)
|
@SerializedName(ApiConstants.FOR_DISPLAY)
|
||||||
@Param(description = "is group for display to the regular user", since = "4.4", authorized = {RoleType.Admin})
|
@Param(description = "is group for display to the regular user", since = "4.4", authorized = {RoleType.Admin})
|
||||||
private Boolean forDisplay;
|
private Boolean forDisplay;
|
||||||
|
|
||||||
public AutoScaleVmGroupResponse() {
|
@SerializedName(ApiConstants.CREATED)
|
||||||
|
@Param(description = "the date when this vm group was created")
|
||||||
|
private Date created;
|
||||||
|
|
||||||
|
public AutoScaleVmGroupResponse() {
|
||||||
|
// Empty constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -103,10 +144,42 @@ public class AutoScaleVmGroupResponse extends BaseResponse implements Controlled
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
public void setLoadBalancerId(String loadBalancerId) {
|
public void setLoadBalancerId(String loadBalancerId) {
|
||||||
this.loadBalancerId = loadBalancerId;
|
this.loadBalancerId = loadBalancerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNetworkName(String networkName) {
|
||||||
|
this.networkName = networkName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNetworkId(String networkId) {
|
||||||
|
this.networkId = networkId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLbProvider(String lbProvider) {
|
||||||
|
this.lbProvider = lbProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicIpId(String publicIpId) {
|
||||||
|
this.publicIpId = publicIpId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicIp(String publicIp) {
|
||||||
|
this.publicIp = publicIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicPort(String publicPort) {
|
||||||
|
this.publicPort = publicPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivatePort(String privatePort) {
|
||||||
|
this.privatePort = privatePort;
|
||||||
|
}
|
||||||
|
|
||||||
public void setProfileId(String profileId) {
|
public void setProfileId(String profileId) {
|
||||||
this.profileId = profileId;
|
this.profileId = profileId;
|
||||||
}
|
}
|
||||||
@ -119,6 +192,10 @@ public class AutoScaleVmGroupResponse extends BaseResponse implements Controlled
|
|||||||
this.maxMembers = maxMembers;
|
this.maxMembers = maxMembers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAvailableVirtualMachineCount(int availableVirtualMachineCount) {
|
||||||
|
this.availableVirtualMachineCount = availableVirtualMachineCount;
|
||||||
|
}
|
||||||
|
|
||||||
public void setState(String state) {
|
public void setState(String state) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
@ -163,4 +240,52 @@ public class AutoScaleVmGroupResponse extends BaseResponse implements Controlled
|
|||||||
public void setForDisplay(Boolean forDisplay) {
|
public void setForDisplay(Boolean forDisplay) {
|
||||||
this.forDisplay = forDisplay;
|
this.forDisplay = forDisplay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCreated(Date created) {
|
||||||
|
this.created = created;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinMembers() {
|
||||||
|
return minMembers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxMembers() {
|
||||||
|
return maxMembers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAvailableVirtualMachineCount() {
|
||||||
|
return availableVirtualMachineCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInterval() {
|
||||||
|
return interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNetworkName() {
|
||||||
|
return networkName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLbProvider() {
|
||||||
|
return lbProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublicIp() {
|
||||||
|
return publicIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublicPort() {
|
||||||
|
return publicPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrivatePort() {
|
||||||
|
return privatePort;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,12 +54,12 @@ public class AutoScaleVmProfileResponse extends BaseResponse implements Controll
|
|||||||
|
|
||||||
@SerializedName(ApiConstants.OTHER_DEPLOY_PARAMS)
|
@SerializedName(ApiConstants.OTHER_DEPLOY_PARAMS)
|
||||||
@Param(description = "parameters other than zoneId/serviceOfferringId/templateId to be used while deploying a virtual machine")
|
@Param(description = "parameters other than zoneId/serviceOfferringId/templateId to be used while deploying a virtual machine")
|
||||||
private String otherDeployParams;
|
private Map<String, String> otherDeployParams;
|
||||||
|
|
||||||
/* Parameters related to destroying a virtual machine */
|
/* Parameters related to destroying a virtual machine */
|
||||||
@SerializedName(ApiConstants.AUTOSCALE_VM_DESTROY_TIME)
|
@SerializedName(ApiConstants.AUTOSCALE_EXPUNGE_VM_GRACE_PERIOD)
|
||||||
@Param(description = "the time allowed for existing connections to get closed before a vm is destroyed")
|
@Param(description = "the time allowed for existing connections to get closed before a vm is destroyed")
|
||||||
private Integer destroyVmGraceperiod;
|
private Integer expungeVmGracePeriod;
|
||||||
|
|
||||||
/* Parameters related to a running virtual machine - monitoring aspects */
|
/* Parameters related to a running virtual machine - monitoring aspects */
|
||||||
@SerializedName(ApiConstants.COUNTERPARAM_LIST)
|
@SerializedName(ApiConstants.COUNTERPARAM_LIST)
|
||||||
@ -68,6 +68,10 @@ public class AutoScaleVmProfileResponse extends BaseResponse implements Controll
|
|||||||
description = "counterparam list. Example: counterparam[0].name=snmpcommunity&counterparam[0].value=public&counterparam[1].name=snmpport&counterparam[1].value=161")
|
description = "counterparam list. Example: counterparam[0].name=snmpcommunity&counterparam[0].value=public&counterparam[1].name=snmpport&counterparam[1].value=161")
|
||||||
private Map<String, String> counterParams;
|
private Map<String, String> counterParams;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.USER_DATA)
|
||||||
|
@Param(description = "Base 64 encoded VM user data")
|
||||||
|
private String userData;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.AUTOSCALE_USER_ID)
|
@SerializedName(ApiConstants.AUTOSCALE_USER_ID)
|
||||||
@Param(description = "the ID of the user used to launch and destroy the VMs")
|
@Param(description = "the ID of the user used to launch and destroy the VMs")
|
||||||
private String autoscaleUserId;
|
private String autoscaleUserId;
|
||||||
@ -103,6 +107,7 @@ public class AutoScaleVmProfileResponse extends BaseResponse implements Controll
|
|||||||
private Boolean forDisplay;
|
private Boolean forDisplay;
|
||||||
|
|
||||||
public AutoScaleVmProfileResponse() {
|
public AutoScaleVmProfileResponse() {
|
||||||
|
// Empty constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -126,12 +131,17 @@ public class AutoScaleVmProfileResponse extends BaseResponse implements Controll
|
|||||||
this.templateId = templateId;
|
this.templateId = templateId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOtherDeployParams(String otherDeployParams) {
|
public void setOtherDeployParams(List<Pair<String, String>> otherDeployParams) {
|
||||||
this.otherDeployParams = otherDeployParams;
|
this.otherDeployParams = new HashMap<>();
|
||||||
|
for (Pair<String, String> paramKV : otherDeployParams) {
|
||||||
|
String key = paramKV.first();
|
||||||
|
String value = paramKV.second();
|
||||||
|
this.otherDeployParams.put(key, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCounterParams(List<Pair<String, String>> counterParams) {
|
public void setCounterParams(List<Pair<String, String>> counterParams) {
|
||||||
this.counterParams = new HashMap<String, String>();
|
this.counterParams = new HashMap<>();
|
||||||
for (Pair<String, String> paramKV : counterParams) {
|
for (Pair<String, String> paramKV : counterParams) {
|
||||||
String key = paramKV.first();
|
String key = paramKV.first();
|
||||||
String value = paramKV.second();
|
String value = paramKV.second();
|
||||||
@ -139,6 +149,10 @@ public class AutoScaleVmProfileResponse extends BaseResponse implements Controll
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUserData(String userData) {
|
||||||
|
this.userData = userData;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAccountName(String accountName) {
|
public void setAccountName(String accountName) {
|
||||||
this.accountName = accountName;
|
this.accountName = accountName;
|
||||||
@ -168,8 +182,8 @@ public class AutoScaleVmProfileResponse extends BaseResponse implements Controll
|
|||||||
this.autoscaleUserId = autoscaleUserId;
|
this.autoscaleUserId = autoscaleUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDestroyVmGraceperiod(Integer destroyVmGraceperiod) {
|
public void setExpungeVmGracePeriod(Integer expungeVmGracePeriod) {
|
||||||
this.destroyVmGraceperiod = destroyVmGraceperiod;
|
this.expungeVmGracePeriod = expungeVmGracePeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCsUrl(String csUrl) {
|
public void setCsUrl(String csUrl) {
|
||||||
|
|||||||
@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
package org.apache.cloudstack.api.response;
|
package org.apache.cloudstack.api.response;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
import org.apache.cloudstack.api.ApiConstants;
|
import org.apache.cloudstack.api.ApiConstants;
|
||||||
@ -43,9 +41,17 @@ public class ConditionResponse extends BaseResponse implements ControlledEntityR
|
|||||||
@Param(description = "Relational Operator to be used with threshold.")
|
@Param(description = "Relational Operator to be used with threshold.")
|
||||||
private String relationalOperator;
|
private String relationalOperator;
|
||||||
|
|
||||||
|
@SerializedName("counterid")
|
||||||
|
@Param(description = "the Id of the Counter.")
|
||||||
|
private String counterId;
|
||||||
|
|
||||||
|
@SerializedName("countername")
|
||||||
|
@Param(description = "the Name of the Counter.")
|
||||||
|
private String counterName;
|
||||||
|
|
||||||
@SerializedName("counter")
|
@SerializedName("counter")
|
||||||
@Param(description = "Details of the Counter.")
|
@Param(description = "Details of the Counter.")
|
||||||
private List<CounterResponse> counterResponse;
|
private CounterResponse counterResponse;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.DOMAIN_ID)
|
@SerializedName(ApiConstants.DOMAIN_ID)
|
||||||
@Param(description = "the domain id of the Condition owner")
|
@Param(description = "the domain id of the Condition owner")
|
||||||
@ -84,6 +90,14 @@ public class ConditionResponse extends BaseResponse implements ControlledEntityR
|
|||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCounterId(String counterId) {
|
||||||
|
this.counterId = counterId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCounterName(String counterName) {
|
||||||
|
this.counterName = counterName;
|
||||||
|
}
|
||||||
|
|
||||||
public void setThreshold(long threshold) {
|
public void setThreshold(long threshold) {
|
||||||
this.threshold = threshold;
|
this.threshold = threshold;
|
||||||
}
|
}
|
||||||
@ -92,7 +106,7 @@ public class ConditionResponse extends BaseResponse implements ControlledEntityR
|
|||||||
this.relationalOperator = relationalOperator;
|
this.relationalOperator = relationalOperator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCounterResponse(List<CounterResponse> counterResponse) {
|
public void setCounterResponse(CounterResponse counterResponse) {
|
||||||
this.counterResponse = counterResponse;
|
this.counterResponse = counterResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -49,6 +49,10 @@ public class CounterResponse extends BaseResponse {
|
|||||||
@Param(description = "zone id of counter")
|
@Param(description = "zone id of counter")
|
||||||
private String zoneId;
|
private String zoneId;
|
||||||
|
|
||||||
|
@SerializedName(value = ApiConstants.PROVIDER)
|
||||||
|
@Param(description = "Provider of the counter.")
|
||||||
|
private String provider;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getObjectId() {
|
public String getObjectId() {
|
||||||
return this.id;
|
return this.id;
|
||||||
@ -69,4 +73,8 @@ public class CounterResponse extends BaseResponse {
|
|||||||
public void setValue(String value) {
|
public void setValue(String value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setProvider(String provider) {
|
||||||
|
this.provider = provider;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -255,6 +255,10 @@ public class NetworkResponse extends BaseResponseWithAssociatedNetwork implement
|
|||||||
@Param(description = "If the network has redundant routers enabled", since = "4.11.1")
|
@Param(description = "If the network has redundant routers enabled", since = "4.11.1")
|
||||||
private Boolean redundantRouter;
|
private Boolean redundantRouter;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.SUPPORTS_VM_AUTOSCALING)
|
||||||
|
@Param(description = "if network offering supports vm autoscaling feature", since = "4.18.0")
|
||||||
|
private Boolean supportsVmAutoScaling;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.RESOURCE_ICON)
|
@SerializedName(ApiConstants.RESOURCE_ICON)
|
||||||
@Param(description = "Base64 string representation of the resource icon", since = "4.16.0.0")
|
@Param(description = "Base64 string representation of the resource icon", since = "4.16.0.0")
|
||||||
ResourceIconResponse icon;
|
ResourceIconResponse icon;
|
||||||
@ -534,6 +538,14 @@ public class NetworkResponse extends BaseResponseWithAssociatedNetwork implement
|
|||||||
this.redundantRouter = redundantRouter;
|
this.redundantRouter = redundantRouter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean getSupportsVmAutoScaling() {
|
||||||
|
return supportsVmAutoScaling;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSupportsVmAutoScaling(Boolean supportsVmAutoScaling) {
|
||||||
|
this.supportsVmAutoScaling = supportsVmAutoScaling;
|
||||||
|
}
|
||||||
|
|
||||||
public String getVpcName() {
|
public String getVpcName() {
|
||||||
return vpcName;
|
return vpcName;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -329,9 +329,17 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co
|
|||||||
private Long bytesSent;
|
private Long bytesSent;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.RESOURCE_ICON)
|
@SerializedName(ApiConstants.RESOURCE_ICON)
|
||||||
@Param(description = "Base64 string representation of the resource icon", since = "4.16.0.0")
|
@Param(description = "Base64 string representation of the resource icon", since = "4.16.0")
|
||||||
ResourceIconResponse resourceIconResponse;
|
ResourceIconResponse resourceIconResponse;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.AUTOSCALE_VMGROUP_ID)
|
||||||
|
@Param(description = "ID of AutoScale VM group", since = "4.18.0")
|
||||||
|
String autoScaleVmGroupId;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.AUTOSCALE_VMGROUP_NAME)
|
||||||
|
@Param(description = "Name of AutoScale VM group", since = "4.18.0")
|
||||||
|
String autoScaleVmGroupName;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.USER_DATA)
|
@SerializedName(ApiConstants.USER_DATA)
|
||||||
@Param(description = "Base64 string containing the user data", since = "4.18.0.0")
|
@Param(description = "Base64 string containing the user data", since = "4.18.0.0")
|
||||||
private String userData;
|
private String userData;
|
||||||
@ -349,11 +357,11 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co
|
|||||||
private String userDataDetails;
|
private String userDataDetails;
|
||||||
|
|
||||||
public UserVmResponse() {
|
public UserVmResponse() {
|
||||||
securityGroupList = new LinkedHashSet<SecurityGroupResponse>();
|
securityGroupList = new LinkedHashSet<>();
|
||||||
nics = new TreeSet<>(Comparator.comparingInt(x -> Integer.parseInt(x.getDeviceId())));
|
nics = new TreeSet<>(Comparator.comparingInt(x -> Integer.parseInt(x.getDeviceId())));
|
||||||
tags = new LinkedHashSet<ResourceTagResponse>();
|
tags = new LinkedHashSet<>();
|
||||||
tagIds = new LinkedHashSet<Long>();
|
tagIds = new LinkedHashSet<>();
|
||||||
affinityGroupList = new LinkedHashSet<AffinityGroupResponse>();
|
affinityGroupList = new LinkedHashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHypervisor(String hypervisor) {
|
public void setHypervisor(String hypervisor) {
|
||||||
@ -973,6 +981,22 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co
|
|||||||
this.bytesSent = bytesSent;
|
this.bytesSent = bytesSent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAutoScaleVmGroupId(String autoScaleVmGroupId) {
|
||||||
|
this.autoScaleVmGroupId = autoScaleVmGroupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoScaleVmGroupName(String autoScaleVmGroupName) {
|
||||||
|
this.autoScaleVmGroupName = autoScaleVmGroupName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAutoScaleVmGroupId() {
|
||||||
|
return autoScaleVmGroupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAutoScaleVmGroupName() {
|
||||||
|
return autoScaleVmGroupName;
|
||||||
|
}
|
||||||
|
|
||||||
public void setUserData(String userData) {
|
public void setUserData(String userData) {
|
||||||
this.userData = userData;
|
this.userData = userData;
|
||||||
}
|
}
|
||||||
|
|||||||
176
api/src/test/java/com/cloud/agent/api/to/LoadBalancerTOTest.java
Normal file
176
api/src/test/java/com/cloud/agent/api/to/LoadBalancerTOTest.java
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
package com.cloud.agent.api.to;
|
||||||
|
|
||||||
|
import com.cloud.network.as.AutoScalePolicy;
|
||||||
|
import com.cloud.network.as.AutoScaleVmGroup;
|
||||||
|
import com.cloud.network.as.Condition;
|
||||||
|
import com.cloud.network.as.Counter;
|
||||||
|
import com.cloud.utils.Pair;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class LoadBalancerTOTest {
|
||||||
|
|
||||||
|
LoadBalancerTO.CounterTO counter;
|
||||||
|
LoadBalancerTO.ConditionTO condition;
|
||||||
|
LoadBalancerTO.AutoScalePolicyTO scaleUpPolicy;
|
||||||
|
LoadBalancerTO.AutoScalePolicyTO scaleDownPolicy;
|
||||||
|
|
||||||
|
LoadBalancerTO.AutoScaleVmProfileTO vmProfile;
|
||||||
|
LoadBalancerTO.AutoScaleVmGroupTO vmGroup;
|
||||||
|
|
||||||
|
private static final Long counterId = 1L;
|
||||||
|
private static final String counterName = "counter name";
|
||||||
|
private static final Counter.Source counterSource = Counter.Source.CPU;
|
||||||
|
private static final String counterValue = "counter value";
|
||||||
|
private static final String counterProvider = "VIRTUALROUTER";
|
||||||
|
|
||||||
|
private static final Long conditionId = 2L;
|
||||||
|
private static final Long threshold = 100L;
|
||||||
|
private static final Condition.Operator relationalOperator = Condition.Operator.GT;
|
||||||
|
|
||||||
|
private static final Long scaleUpPolicyId = 11L;
|
||||||
|
private static final int scaleUpPolicyDuration = 61;
|
||||||
|
private static final int scaleUpPolicyQuietTime = 31;
|
||||||
|
private static final Date scaleUpPolicyLastQuietTime = new Date();
|
||||||
|
|
||||||
|
private static final Long scaleDownPolicyId = 12L;
|
||||||
|
private static final int scaleDownPolicyDuration = 62;
|
||||||
|
private static final int scaleDownPolicyQuietTime = 32;
|
||||||
|
private static final Date scaleDownPolicyLastQuietTime = new Date();
|
||||||
|
|
||||||
|
private static final String zoneId = "1111-1111-1112";
|
||||||
|
private static final String domainId = "1111-1111-1113";
|
||||||
|
private static final String serviceOfferingId = "1111-1111-1114";
|
||||||
|
private static final String templateId = "1111-1111-1115";
|
||||||
|
private static final String otherDeployParams = "otherDeployParams";
|
||||||
|
private static final List<Pair<String, String>> counterParamList = new ArrayList<>();
|
||||||
|
private static final Integer expungeVmGracePeriod = 33;
|
||||||
|
private static final String cloudStackApiUrl = "cloudstack url";
|
||||||
|
private static final String autoScaleUserApiKey = "cloudstack api key";
|
||||||
|
private static final String autoScaleUserSecretKey = "cloudstack secret key";
|
||||||
|
private static final String vmName = "vm name";
|
||||||
|
private static final String networkId = "1111-1111-1116";
|
||||||
|
|
||||||
|
private static final Long vmGroupId = 22L;
|
||||||
|
private static final String vmGroupUuid = "2222-2222-1111";
|
||||||
|
private static final int minMembers = 2;
|
||||||
|
private static final int maxMembers = 3;
|
||||||
|
private static final int memberPort = 8080;
|
||||||
|
private static final int interval = 30;
|
||||||
|
private static final AutoScaleVmGroup.State state = AutoScaleVmGroup.State.ENABLED;
|
||||||
|
private static final AutoScaleVmGroup.State currentState = AutoScaleVmGroup.State.DISABLED;
|
||||||
|
private static final Long loadBalancerId = 21L;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
counter = new LoadBalancerTO.CounterTO(counterId, counterName, counterSource, counterValue, counterProvider);
|
||||||
|
condition = new LoadBalancerTO.ConditionTO(conditionId, threshold, relationalOperator, counter);
|
||||||
|
scaleUpPolicy = new LoadBalancerTO.AutoScalePolicyTO(scaleUpPolicyId, scaleUpPolicyDuration, scaleUpPolicyQuietTime,
|
||||||
|
scaleUpPolicyLastQuietTime, AutoScalePolicy.Action.SCALEUP,
|
||||||
|
Arrays.asList(new LoadBalancerTO.ConditionTO[]{ condition }), false);
|
||||||
|
scaleDownPolicy = new LoadBalancerTO.AutoScalePolicyTO(scaleDownPolicyId, scaleDownPolicyDuration, scaleDownPolicyQuietTime,
|
||||||
|
scaleDownPolicyLastQuietTime, AutoScalePolicy.Action.SCALEDOWN,
|
||||||
|
Arrays.asList(new LoadBalancerTO.ConditionTO[]{ condition }), false);
|
||||||
|
vmProfile = new LoadBalancerTO.AutoScaleVmProfileTO(zoneId, domainId, cloudStackApiUrl, autoScaleUserApiKey,
|
||||||
|
autoScaleUserSecretKey, serviceOfferingId, templateId, vmName, networkId, otherDeployParams,
|
||||||
|
counterParamList, expungeVmGracePeriod);
|
||||||
|
vmGroup = new LoadBalancerTO.AutoScaleVmGroupTO(vmGroupId, vmGroupUuid, minMembers, maxMembers, memberPort,
|
||||||
|
interval, Arrays.asList(new LoadBalancerTO.AutoScalePolicyTO[]{ scaleUpPolicy, scaleDownPolicy }),
|
||||||
|
vmProfile, state, currentState, loadBalancerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCounterTO() {
|
||||||
|
Assert.assertEquals(counterId, counter.getId());
|
||||||
|
Assert.assertEquals(counterName, counter.getName());
|
||||||
|
Assert.assertEquals(counterSource, counter.getSource());
|
||||||
|
Assert.assertEquals(counterValue, counter.getValue());
|
||||||
|
Assert.assertEquals(counterProvider, counter.getProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConditionTO() {
|
||||||
|
Assert.assertEquals(conditionId, condition.getId());
|
||||||
|
Assert.assertEquals((long) threshold, condition.getThreshold());
|
||||||
|
Assert.assertEquals(relationalOperator, condition.getRelationalOperator());
|
||||||
|
Assert.assertEquals(counter, condition.getCounter());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAutoScalePolicyTO() {
|
||||||
|
Assert.assertEquals((long) scaleUpPolicyId, scaleUpPolicy.getId());
|
||||||
|
Assert.assertEquals(scaleUpPolicyDuration, scaleUpPolicy.getDuration());
|
||||||
|
Assert.assertEquals(scaleUpPolicyQuietTime, scaleUpPolicy.getQuietTime());
|
||||||
|
Assert.assertEquals(scaleUpPolicyLastQuietTime, scaleUpPolicy.getLastQuietTime());
|
||||||
|
Assert.assertEquals(AutoScalePolicy.Action.SCALEUP, scaleUpPolicy.getAction());
|
||||||
|
Assert.assertFalse(scaleUpPolicy.isRevoked());
|
||||||
|
List<LoadBalancerTO.ConditionTO> scaleUpPolicyConditions = scaleUpPolicy.getConditions();
|
||||||
|
Assert.assertEquals(1, scaleUpPolicyConditions.size());
|
||||||
|
Assert.assertEquals(condition, scaleUpPolicyConditions.get(0));
|
||||||
|
|
||||||
|
Assert.assertEquals((long) scaleDownPolicyId, scaleDownPolicy.getId());
|
||||||
|
Assert.assertEquals(scaleDownPolicyDuration, scaleDownPolicy.getDuration());
|
||||||
|
Assert.assertEquals(scaleDownPolicyQuietTime, scaleDownPolicy.getQuietTime());
|
||||||
|
Assert.assertEquals(scaleDownPolicyLastQuietTime, scaleDownPolicy.getLastQuietTime());
|
||||||
|
Assert.assertEquals(AutoScalePolicy.Action.SCALEDOWN, scaleDownPolicy.getAction());
|
||||||
|
Assert.assertFalse(scaleDownPolicy.isRevoked());
|
||||||
|
List<LoadBalancerTO.ConditionTO> scaleDownPolicyConditions = scaleDownPolicy.getConditions();
|
||||||
|
Assert.assertEquals(1, scaleDownPolicyConditions.size());
|
||||||
|
Assert.assertEquals(condition, scaleDownPolicyConditions.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAutoScaleVmProfileTO() {
|
||||||
|
Assert.assertEquals(zoneId, vmProfile.getZoneId());
|
||||||
|
Assert.assertEquals(domainId, vmProfile.getDomainId());
|
||||||
|
Assert.assertEquals(templateId, vmProfile.getTemplateId());
|
||||||
|
Assert.assertEquals(serviceOfferingId, vmProfile.getServiceOfferingId());
|
||||||
|
Assert.assertEquals(otherDeployParams, vmProfile.getOtherDeployParams());
|
||||||
|
Assert.assertEquals(counterParamList, vmProfile.getCounterParamList());
|
||||||
|
Assert.assertEquals(expungeVmGracePeriod, vmProfile.getExpungeVmGracePeriod());
|
||||||
|
Assert.assertEquals(cloudStackApiUrl, vmProfile.getCloudStackApiUrl());
|
||||||
|
Assert.assertEquals(autoScaleUserApiKey, vmProfile.getAutoScaleUserApiKey());
|
||||||
|
Assert.assertEquals(autoScaleUserSecretKey, vmProfile.getAutoScaleUserSecretKey());
|
||||||
|
Assert.assertEquals(vmName, vmProfile.getVmName());
|
||||||
|
Assert.assertEquals(networkId, vmProfile.getNetworkId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAutoScaleVmGroupTO() {
|
||||||
|
Assert.assertEquals(vmGroupId, vmGroup.getId());
|
||||||
|
Assert.assertEquals(vmGroupUuid, vmGroup.getUuid());
|
||||||
|
Assert.assertEquals(minMembers, vmGroup.getMinMembers());
|
||||||
|
Assert.assertEquals(maxMembers, vmGroup.getMaxMembers());
|
||||||
|
Assert.assertEquals(memberPort, vmGroup.getMemberPort());
|
||||||
|
Assert.assertEquals(interval, vmGroup.getInterval());
|
||||||
|
Assert.assertEquals(vmProfile, vmGroup.getProfile());
|
||||||
|
Assert.assertEquals(state, vmGroup.getState());
|
||||||
|
Assert.assertEquals(currentState, vmGroup.getCurrentState());
|
||||||
|
Assert.assertEquals(loadBalancerId, vmGroup.getLoadBalancerId());
|
||||||
|
|
||||||
|
List<LoadBalancerTO.AutoScalePolicyTO> policies = vmGroup.getPolicies();
|
||||||
|
Assert.assertEquals(2, policies.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
package com.cloud.network.as;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class AutoScalePolicyTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testScaleUpAction() {
|
||||||
|
AutoScalePolicy.Action action = AutoScalePolicy.Action.fromValue("scaleup");
|
||||||
|
Assert.assertEquals(AutoScalePolicy.Action.SCALEUP, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testScaleDownAction() {
|
||||||
|
AutoScalePolicy.Action action = AutoScalePolicy.Action.fromValue("scaledown");
|
||||||
|
Assert.assertEquals(AutoScalePolicy.Action.SCALEDOWN, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNullAction() {
|
||||||
|
AutoScalePolicy.Action action = AutoScalePolicy.Action.fromValue(null);
|
||||||
|
Assert.assertNull(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBlankAction() {
|
||||||
|
AutoScalePolicy.Action action = AutoScalePolicy.Action.fromValue("");
|
||||||
|
Assert.assertNull(action);
|
||||||
|
|
||||||
|
action = AutoScalePolicy.Action.fromValue(" ");
|
||||||
|
Assert.assertNull(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testInvalidAction() {
|
||||||
|
AutoScalePolicy.Action action = AutoScalePolicy.Action.fromValue("invalid");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
package com.cloud.network.as;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class AutoScaleVmGroupTest {
|
||||||
|
|
||||||
|
private void testAutoScaleVmGroupState(String stateString) {
|
||||||
|
AutoScaleVmGroup.State state = AutoScaleVmGroup.State.fromValue(stateString);
|
||||||
|
Assert.assertEquals(state.toString().toLowerCase(), stateString.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAutoScaleVmGroupStates() {
|
||||||
|
testAutoScaleVmGroupState("new");
|
||||||
|
testAutoScaleVmGroupState("Enabled");
|
||||||
|
testAutoScaleVmGroupState("DisableD");
|
||||||
|
testAutoScaleVmGroupState("REVOKE");
|
||||||
|
testAutoScaleVmGroupState("scaling");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBlankStates() {
|
||||||
|
AutoScaleVmGroup.State state = AutoScaleVmGroup.State.fromValue("");
|
||||||
|
Assert.assertNull(state);
|
||||||
|
|
||||||
|
state = AutoScaleVmGroup.State.fromValue(" ");
|
||||||
|
Assert.assertNull(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testInvalidState() {
|
||||||
|
testAutoScaleVmGroupState("invalid");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,68 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
package com.cloud.network.router;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.VirtualRouterAutoScaleCounter;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleMetrics;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleMetricsValue;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleValueType;
|
||||||
|
|
||||||
|
public class VirtualRouterAutoScaleTest {
|
||||||
|
|
||||||
|
private void testVirtualRouterAutoScaleCounter(VirtualRouterAutoScaleCounter counter, String value) {
|
||||||
|
VirtualRouterAutoScaleCounter counterFromValue = VirtualRouterAutoScaleCounter.fromValue(value);
|
||||||
|
assertEquals(counter, counterFromValue);
|
||||||
|
if (counterFromValue != null) {
|
||||||
|
assertEquals(value, counterFromValue.getValue());
|
||||||
|
assertEquals(value, counterFromValue.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testVirtualRouterAutoScaleCounters() {
|
||||||
|
testVirtualRouterAutoScaleCounter(VirtualRouterAutoScaleCounter.NETWORK_RECEIVED_AVERAGE_MBPS, "public.network.received.average.mbps");
|
||||||
|
testVirtualRouterAutoScaleCounter(VirtualRouterAutoScaleCounter.NETWORK_TRANSMIT_AVERAGE_MBPS, "public.network.transmit.average.mbps");
|
||||||
|
testVirtualRouterAutoScaleCounter(VirtualRouterAutoScaleCounter.LB_AVERAGE_CONNECTIONS, "virtual.network.lb.average.connections");
|
||||||
|
testVirtualRouterAutoScaleCounter(null, "invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAutoScaleMetrics() {
|
||||||
|
AutoScaleMetrics metrics = new AutoScaleMetrics(VirtualRouterAutoScaleCounter.LB_AVERAGE_CONNECTIONS, 1L, 2L, 3L, 4);
|
||||||
|
|
||||||
|
assertEquals(VirtualRouterAutoScaleCounter.LB_AVERAGE_CONNECTIONS, metrics.getCounter());
|
||||||
|
assertEquals(1L, (long) metrics.getPolicyId());
|
||||||
|
assertEquals(2L, (long) metrics.getConditionId());
|
||||||
|
assertEquals(3L, (long) metrics.getCounterId());
|
||||||
|
assertEquals(4, (int) metrics.getDuration());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAutoScaleMetricsValue() {
|
||||||
|
AutoScaleMetrics metrics = new AutoScaleMetrics(VirtualRouterAutoScaleCounter.LB_AVERAGE_CONNECTIONS, 1L, 2L, 3L, 4);
|
||||||
|
|
||||||
|
AutoScaleMetricsValue value = new AutoScaleMetricsValue(metrics, AutoScaleValueType.INSTANT_VM, 123.45);
|
||||||
|
|
||||||
|
assertEquals(metrics, value.getMetrics());
|
||||||
|
assertEquals(AutoScaleValueType.INSTANT_VM, value.getType());
|
||||||
|
assertEquals(123.45, (double) value.getValue(), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,176 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
|
||||||
|
package org.apache.cloudstack.api.command.test;
|
||||||
|
|
||||||
|
import com.cloud.event.EventTypes;
|
||||||
|
import com.cloud.exception.ResourceAllocationException;
|
||||||
|
import com.cloud.network.as.AutoScaleService;
|
||||||
|
import com.cloud.network.as.AutoScaleVmProfile;
|
||||||
|
import com.cloud.utils.db.EntityManager;
|
||||||
|
import org.apache.cloudstack.api.ApiCommandResourceType;
|
||||||
|
import org.apache.cloudstack.api.ResponseGenerator;
|
||||||
|
import org.apache.cloudstack.api.ServerApiException;
|
||||||
|
import org.apache.cloudstack.api.command.user.autoscale.CreateAutoScaleVmProfileCmd;
|
||||||
|
import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
public class CreateAutoScaleVmProfileCmdTest {
|
||||||
|
private CreateAutoScaleVmProfileCmd createAutoScaleVmProfileCmd;
|
||||||
|
private AutoScaleService autoScaleService;
|
||||||
|
private AutoScaleVmProfile autoScaleVmProfile;
|
||||||
|
private EntityManager entityMgr;
|
||||||
|
private ResponseGenerator responseGenerator;
|
||||||
|
private AutoScaleVmProfileResponse response;
|
||||||
|
|
||||||
|
private static final Long domainId = 1L;
|
||||||
|
private static final Long projectId = 2L;
|
||||||
|
private static final String accountName = "testuser";
|
||||||
|
|
||||||
|
private static final Long zoneId = 1L;
|
||||||
|
private static final Long serviceOfferingId = 2L;
|
||||||
|
private static final Long templateId = 3L;
|
||||||
|
private static final String userData = "This is userdata";
|
||||||
|
private static final int expungeVmGracePeriod = 30;
|
||||||
|
private static final Long autoscaleUserId = 4L;
|
||||||
|
final Map<String, Object> otherDeployParams = new HashMap<>();
|
||||||
|
final Map<String, Object> counterParamList = new HashMap<>();
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
otherDeployParams.put("0", new HashMap<>(Map.ofEntries(
|
||||||
|
Map.entry("name", "rootdisksize"),
|
||||||
|
Map.entry("value", "10")
|
||||||
|
)));
|
||||||
|
otherDeployParams.put("1", new HashMap<>(Map.ofEntries(
|
||||||
|
Map.entry("name", "diskofferingid"),
|
||||||
|
Map.entry("value", "2222-3333-4444")
|
||||||
|
)));
|
||||||
|
otherDeployParams.put("2", new HashMap<>(Map.ofEntries(
|
||||||
|
Map.entry("name", "size"),
|
||||||
|
Map.entry("value", "20")
|
||||||
|
)));
|
||||||
|
|
||||||
|
autoScaleService = Mockito.spy(AutoScaleService.class);
|
||||||
|
entityMgr = Mockito.spy(EntityManager.class);
|
||||||
|
responseGenerator = Mockito.spy(ResponseGenerator.class);
|
||||||
|
|
||||||
|
createAutoScaleVmProfileCmd = new CreateAutoScaleVmProfileCmd();
|
||||||
|
ReflectionTestUtils.setField(createAutoScaleVmProfileCmd,"_autoScaleService", autoScaleService);
|
||||||
|
ReflectionTestUtils.setField(createAutoScaleVmProfileCmd,"_entityMgr", entityMgr);
|
||||||
|
ReflectionTestUtils.setField(createAutoScaleVmProfileCmd,"_responseGenerator", responseGenerator);
|
||||||
|
|
||||||
|
ReflectionTestUtils.setField(createAutoScaleVmProfileCmd,"zoneId", zoneId);
|
||||||
|
ReflectionTestUtils.setField(createAutoScaleVmProfileCmd,"serviceOfferingId", serviceOfferingId);
|
||||||
|
ReflectionTestUtils.setField(createAutoScaleVmProfileCmd,"templateId", templateId);
|
||||||
|
ReflectionTestUtils.setField(createAutoScaleVmProfileCmd,"userData", userData);
|
||||||
|
ReflectionTestUtils.setField(createAutoScaleVmProfileCmd,"expungeVmGracePeriod", expungeVmGracePeriod);
|
||||||
|
ReflectionTestUtils.setField(createAutoScaleVmProfileCmd,"autoscaleUserId", autoscaleUserId);
|
||||||
|
ReflectionTestUtils.setField(createAutoScaleVmProfileCmd,"otherDeployParams", otherDeployParams);
|
||||||
|
ReflectionTestUtils.setField(createAutoScaleVmProfileCmd,"counterParamList", counterParamList);
|
||||||
|
ReflectionTestUtils.setField(createAutoScaleVmProfileCmd,"domainId", domainId);
|
||||||
|
ReflectionTestUtils.setField(createAutoScaleVmProfileCmd,"projectId", projectId);
|
||||||
|
ReflectionTestUtils.setField(createAutoScaleVmProfileCmd,"accountName", accountName);
|
||||||
|
|
||||||
|
autoScaleVmProfile = Mockito.mock(AutoScaleVmProfile.class);
|
||||||
|
|
||||||
|
response = new AutoScaleVmProfileResponse();
|
||||||
|
response.setUserData(userData);
|
||||||
|
response.setExpungeVmGracePeriod(expungeVmGracePeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyCreateAutoScaleVmProfileCmd() {
|
||||||
|
Assert.assertEquals(zoneId, createAutoScaleVmProfileCmd.getZoneId());
|
||||||
|
Assert.assertEquals(serviceOfferingId, createAutoScaleVmProfileCmd.getServiceOfferingId());
|
||||||
|
Assert.assertEquals(templateId, createAutoScaleVmProfileCmd.getTemplateId());
|
||||||
|
Assert.assertNull(createAutoScaleVmProfileCmd.getDisplay());
|
||||||
|
Assert.assertTrue(createAutoScaleVmProfileCmd.isDisplay());
|
||||||
|
Assert.assertEquals(userData, createAutoScaleVmProfileCmd.getUserData());
|
||||||
|
Assert.assertEquals(autoscaleUserId, createAutoScaleVmProfileCmd.getAutoscaleUserId());
|
||||||
|
Assert.assertEquals(expungeVmGracePeriod, (long) createAutoScaleVmProfileCmd.getExpungeVmGracePeriod());
|
||||||
|
Assert.assertEquals(counterParamList, createAutoScaleVmProfileCmd.getCounterParamList());
|
||||||
|
Assert.assertEquals(otherDeployParams, createAutoScaleVmProfileCmd.getOtherDeployParams());
|
||||||
|
Assert.assertEquals(domainId, createAutoScaleVmProfileCmd.getDomainId());
|
||||||
|
Assert.assertEquals(projectId, createAutoScaleVmProfileCmd.getProjectId());
|
||||||
|
Assert.assertEquals(accountName, createAutoScaleVmProfileCmd.getAccountName());
|
||||||
|
|
||||||
|
Assert.assertEquals("autoscalevmprofileresponse", createAutoScaleVmProfileCmd.getCommandName());
|
||||||
|
Assert.assertEquals("autoscalevmprofile", CreateAutoScaleVmProfileCmd.getResultObjectName());
|
||||||
|
Assert.assertEquals(EventTypes.EVENT_AUTOSCALEVMPROFILE_CREATE, createAutoScaleVmProfileCmd.getEventType());
|
||||||
|
Assert.assertEquals("creating AutoScale Vm Profile", createAutoScaleVmProfileCmd.getEventDescription());
|
||||||
|
Assert.assertEquals(ApiCommandResourceType.AutoScaleVmProfile, createAutoScaleVmProfileCmd.getApiResourceType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyCreateAutoScaleVmProfileCmdParams() {
|
||||||
|
HashMap<String, String> deployParamMap = createAutoScaleVmProfileCmd.getDeployParamMap();
|
||||||
|
Assert.assertEquals(otherDeployParams.size() + 4, deployParamMap.size());
|
||||||
|
Assert.assertEquals("deployVirtualMachine", deployParamMap.get("command"));
|
||||||
|
Assert.assertEquals(zoneId.toString(), deployParamMap.get("zoneId"));
|
||||||
|
Assert.assertEquals(serviceOfferingId.toString(), deployParamMap.get("serviceOfferingId"));
|
||||||
|
Assert.assertEquals(templateId.toString(), deployParamMap.get("templateId"));
|
||||||
|
Assert.assertEquals("10", deployParamMap.get("rootdisksize"));
|
||||||
|
Assert.assertEquals("2222-3333-4444", deployParamMap.get("diskofferingid"));
|
||||||
|
Assert.assertEquals("20", deployParamMap.get("size"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateAutoScaleVmProfileSuccess() {
|
||||||
|
when(autoScaleVmProfile.getId()).thenReturn(1L);
|
||||||
|
when(autoScaleVmProfile.getUuid()).thenReturn("1111-2222-3333-4444");
|
||||||
|
when(autoScaleService.createAutoScaleVmProfile(createAutoScaleVmProfileCmd)).thenReturn(autoScaleVmProfile);
|
||||||
|
|
||||||
|
try {
|
||||||
|
createAutoScaleVmProfileCmd.create();
|
||||||
|
} catch (ResourceAllocationException ex) {
|
||||||
|
Assert.fail("Got exception: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
Assert.assertEquals(1L, (long) createAutoScaleVmProfileCmd.getEntityId());
|
||||||
|
|
||||||
|
when(entityMgr.findById(AutoScaleVmProfile.class, 1L)).thenReturn(autoScaleVmProfile);
|
||||||
|
when(responseGenerator.createAutoScaleVmProfileResponse(autoScaleVmProfile)).thenReturn(response);
|
||||||
|
|
||||||
|
createAutoScaleVmProfileCmd.execute();
|
||||||
|
|
||||||
|
AutoScaleVmProfileResponse autoScaleVmProfileResponse = (AutoScaleVmProfileResponse) createAutoScaleVmProfileCmd.getResponseObject();
|
||||||
|
Assert.assertEquals(createAutoScaleVmProfileCmd.getCommandName(), autoScaleVmProfileResponse.getResponseName());
|
||||||
|
Assert.assertEquals(userData, ReflectionTestUtils.getField(autoScaleVmProfileResponse, "userData"));
|
||||||
|
Assert.assertEquals(expungeVmGracePeriod, (int) ReflectionTestUtils.getField(autoScaleVmProfileResponse, "expungeVmGracePeriod"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = ServerApiException.class)
|
||||||
|
public void testCreateAutoScaleVmProfileFail() {
|
||||||
|
when(autoScaleService.createAutoScaleVmProfile(createAutoScaleVmProfileCmd)).thenReturn(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
createAutoScaleVmProfileCmd.create();
|
||||||
|
} catch (ResourceAllocationException ex) {
|
||||||
|
Assert.fail("Got exception: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,129 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
|
||||||
|
package org.apache.cloudstack.api.command.test;
|
||||||
|
|
||||||
|
import com.cloud.event.EventTypes;
|
||||||
|
import com.cloud.network.as.AutoScaleService;
|
||||||
|
import com.cloud.network.as.AutoScaleVmProfile;
|
||||||
|
import com.cloud.utils.db.EntityManager;
|
||||||
|
import org.apache.cloudstack.api.ResponseGenerator;
|
||||||
|
import org.apache.cloudstack.api.ServerApiException;
|
||||||
|
import org.apache.cloudstack.api.command.user.autoscale.UpdateAutoScaleVmProfileCmd;
|
||||||
|
import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
public class UpdateAutoScaleVmProfileCmdTest {
|
||||||
|
private UpdateAutoScaleVmProfileCmd updateAutoScaleVmProfileCmd;
|
||||||
|
private AutoScaleService autoScaleService;
|
||||||
|
private AutoScaleVmProfile autoScaleVmProfile;
|
||||||
|
private EntityManager entityMgr;
|
||||||
|
private ResponseGenerator responseGenerator;
|
||||||
|
private AutoScaleVmProfileResponse response;
|
||||||
|
|
||||||
|
private static final Long profileId = 1L;
|
||||||
|
private static final Long serviceOfferingId = 2L;
|
||||||
|
private static final Long templateId = 3L;
|
||||||
|
private static final String userData = "This is userdata";
|
||||||
|
private static final int expungeVmGracePeriod = 30;
|
||||||
|
private static final Long autoscaleUserId = 4L;
|
||||||
|
final Map<String, String> otherDeployParams = new HashMap<>();
|
||||||
|
final Map<String, Object> counterParamList = new HashMap<>();
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
otherDeployParams.put("rootdiskdize", "10");
|
||||||
|
otherDeployParams.put("diskofferingid", "2222-3333-4444");
|
||||||
|
otherDeployParams.put("size", "20");
|
||||||
|
|
||||||
|
autoScaleService = Mockito.spy(AutoScaleService.class);
|
||||||
|
entityMgr = Mockito.spy(EntityManager.class);
|
||||||
|
responseGenerator = Mockito.spy(ResponseGenerator.class);
|
||||||
|
|
||||||
|
updateAutoScaleVmProfileCmd = new UpdateAutoScaleVmProfileCmd();
|
||||||
|
ReflectionTestUtils.setField(updateAutoScaleVmProfileCmd,"_autoScaleService", autoScaleService);
|
||||||
|
ReflectionTestUtils.setField(updateAutoScaleVmProfileCmd,"_entityMgr", entityMgr);
|
||||||
|
ReflectionTestUtils.setField(updateAutoScaleVmProfileCmd,"_responseGenerator", responseGenerator);
|
||||||
|
|
||||||
|
ReflectionTestUtils.setField(updateAutoScaleVmProfileCmd,"id", profileId);
|
||||||
|
ReflectionTestUtils.setField(updateAutoScaleVmProfileCmd,"serviceOfferingId", serviceOfferingId);
|
||||||
|
ReflectionTestUtils.setField(updateAutoScaleVmProfileCmd,"templateId", templateId);
|
||||||
|
ReflectionTestUtils.setField(updateAutoScaleVmProfileCmd,"userData", userData);
|
||||||
|
ReflectionTestUtils.setField(updateAutoScaleVmProfileCmd,"expungeVmGracePeriod", expungeVmGracePeriod);
|
||||||
|
ReflectionTestUtils.setField(updateAutoScaleVmProfileCmd,"autoscaleUserId", autoscaleUserId);
|
||||||
|
ReflectionTestUtils.setField(updateAutoScaleVmProfileCmd,"otherDeployParams", otherDeployParams);
|
||||||
|
ReflectionTestUtils.setField(updateAutoScaleVmProfileCmd,"counterParamList", counterParamList);
|
||||||
|
|
||||||
|
autoScaleVmProfile = Mockito.mock(AutoScaleVmProfile.class);
|
||||||
|
|
||||||
|
response = new AutoScaleVmProfileResponse();
|
||||||
|
response.setUserData(userData);
|
||||||
|
response.setExpungeVmGracePeriod(expungeVmGracePeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyUpdateAutoScaleVmProfileCmd() {
|
||||||
|
Assert.assertEquals(profileId, updateAutoScaleVmProfileCmd.getId());
|
||||||
|
Assert.assertEquals(serviceOfferingId, updateAutoScaleVmProfileCmd.getServiceOfferingId());
|
||||||
|
Assert.assertEquals(templateId, updateAutoScaleVmProfileCmd.getTemplateId());
|
||||||
|
Assert.assertNull(updateAutoScaleVmProfileCmd.getDisplay());
|
||||||
|
Assert.assertTrue(updateAutoScaleVmProfileCmd.isDisplay());
|
||||||
|
Assert.assertEquals(userData, updateAutoScaleVmProfileCmd.getUserData());
|
||||||
|
Assert.assertEquals(autoscaleUserId, updateAutoScaleVmProfileCmd.getAutoscaleUserId());
|
||||||
|
Assert.assertEquals(expungeVmGracePeriod, (long) updateAutoScaleVmProfileCmd.getExpungeVmGracePeriod());
|
||||||
|
Assert.assertEquals(counterParamList, updateAutoScaleVmProfileCmd.getCounterParamList());
|
||||||
|
Assert.assertEquals(otherDeployParams, updateAutoScaleVmProfileCmd.getOtherDeployParams());
|
||||||
|
|
||||||
|
Assert.assertEquals("updateautoscalevmprofileresponse", updateAutoScaleVmProfileCmd.getCommandName());
|
||||||
|
Assert.assertEquals(EventTypes.EVENT_AUTOSCALEVMPROFILE_UPDATE, updateAutoScaleVmProfileCmd.getEventType());
|
||||||
|
Assert.assertEquals("Updating AutoScale Vm Profile. Vm Profile Id: " + profileId, updateAutoScaleVmProfileCmd.getEventDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAutoScaleVmProfileSuccess() {
|
||||||
|
when(autoScaleVmProfile.getId()).thenReturn(1L);
|
||||||
|
when(autoScaleVmProfile.getUuid()).thenReturn("1111-2222-3333-4444");
|
||||||
|
when(autoScaleService.updateAutoScaleVmProfile(updateAutoScaleVmProfileCmd)).thenReturn(autoScaleVmProfile);
|
||||||
|
|
||||||
|
when(entityMgr.findById(AutoScaleVmProfile.class, 1L)).thenReturn(autoScaleVmProfile);
|
||||||
|
when(responseGenerator.createAutoScaleVmProfileResponse(autoScaleVmProfile)).thenReturn(response);
|
||||||
|
|
||||||
|
updateAutoScaleVmProfileCmd.execute();
|
||||||
|
|
||||||
|
AutoScaleVmProfileResponse autoScaleVmProfileResponse = (AutoScaleVmProfileResponse) updateAutoScaleVmProfileCmd.getResponseObject();
|
||||||
|
Assert.assertEquals(updateAutoScaleVmProfileCmd.getCommandName(), autoScaleVmProfileResponse.getResponseName());
|
||||||
|
Assert.assertEquals(userData, ReflectionTestUtils.getField(autoScaleVmProfileResponse, "userData"));
|
||||||
|
Assert.assertEquals(expungeVmGracePeriod, (int) ReflectionTestUtils.getField(autoScaleVmProfileResponse, "expungeVmGracePeriod"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = ServerApiException.class)
|
||||||
|
public void testUpdateAutoScaleVmProfileFail() {
|
||||||
|
when(autoScaleService.updateAutoScaleVmProfile(updateAutoScaleVmProfileCmd)).thenReturn(null);
|
||||||
|
|
||||||
|
updateAutoScaleVmProfileCmd.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,132 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
|
||||||
|
package org.apache.cloudstack.api.command.test;
|
||||||
|
|
||||||
|
import com.cloud.event.EventTypes;
|
||||||
|
import com.cloud.exception.ResourceInUseException;
|
||||||
|
import com.cloud.network.as.AutoScaleService;
|
||||||
|
import com.cloud.network.as.Condition;
|
||||||
|
import com.cloud.user.Account;
|
||||||
|
import com.cloud.utils.db.EntityManager;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.api.ApiCommandResourceType;
|
||||||
|
import org.apache.cloudstack.api.ApiErrorCode;
|
||||||
|
import org.apache.cloudstack.api.ResponseGenerator;
|
||||||
|
import org.apache.cloudstack.api.ServerApiException;
|
||||||
|
import org.apache.cloudstack.api.command.user.autoscale.UpdateConditionCmd;
|
||||||
|
import org.apache.cloudstack.api.response.ConditionResponse;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
public class UpdateConditionCmdTest {
|
||||||
|
|
||||||
|
private UpdateConditionCmd updateConditionCmd;
|
||||||
|
private Condition condition;
|
||||||
|
|
||||||
|
private AutoScaleService autoScaleService;
|
||||||
|
private EntityManager entityMgr;
|
||||||
|
private ResponseGenerator responseGenerator;
|
||||||
|
|
||||||
|
private static final Long conditionId = 10L;
|
||||||
|
private static final String relationalOperator = "GT";
|
||||||
|
private static final Long threshold = 100L;
|
||||||
|
|
||||||
|
private static final long accountId = 5L;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
|
||||||
|
autoScaleService = Mockito.spy(AutoScaleService.class);
|
||||||
|
entityMgr = Mockito.spy(EntityManager.class);
|
||||||
|
responseGenerator = Mockito.spy(ResponseGenerator.class);
|
||||||
|
|
||||||
|
updateConditionCmd = new UpdateConditionCmd();
|
||||||
|
|
||||||
|
ReflectionTestUtils.setField(updateConditionCmd,"_autoScaleService", autoScaleService);
|
||||||
|
ReflectionTestUtils.setField(updateConditionCmd,"_entityMgr", entityMgr);
|
||||||
|
ReflectionTestUtils.setField(updateConditionCmd,"_responseGenerator", responseGenerator);
|
||||||
|
|
||||||
|
ReflectionTestUtils.setField(updateConditionCmd,"id", conditionId);
|
||||||
|
ReflectionTestUtils.setField(updateConditionCmd,"relationalOperator", relationalOperator);
|
||||||
|
ReflectionTestUtils.setField(updateConditionCmd,"threshold", threshold);
|
||||||
|
|
||||||
|
condition = Mockito.mock(Condition.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyUpdateConditionCmd() {
|
||||||
|
Assert.assertEquals(conditionId, updateConditionCmd.getId());
|
||||||
|
Assert.assertEquals(relationalOperator, updateConditionCmd.getRelationalOperator());
|
||||||
|
Assert.assertEquals(threshold, updateConditionCmd.getThreshold());
|
||||||
|
|
||||||
|
Assert.assertEquals(ApiCommandResourceType.Condition, updateConditionCmd.getApiResourceType());
|
||||||
|
Assert.assertEquals("updateconditionresponse", updateConditionCmd.getCommandName());
|
||||||
|
Assert.assertEquals(EventTypes.EVENT_CONDITION_UPDATE, updateConditionCmd.getEventType());
|
||||||
|
Assert.assertEquals("Updating a condition.", updateConditionCmd.getEventDescription());
|
||||||
|
|
||||||
|
when(entityMgr.findById(Condition.class, conditionId)).thenReturn(condition);
|
||||||
|
when(condition.getAccountId()).thenReturn(accountId);
|
||||||
|
Assert.assertEquals(accountId, updateConditionCmd.getEntityOwnerId());
|
||||||
|
|
||||||
|
when(entityMgr.findById(Condition.class, conditionId)).thenReturn(null);
|
||||||
|
Assert.assertEquals(Account.ACCOUNT_ID_SYSTEM, updateConditionCmd.getEntityOwnerId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateSuccess() {
|
||||||
|
try {
|
||||||
|
Mockito.when(autoScaleService.updateCondition(Mockito.any(UpdateConditionCmd.class))).thenReturn(condition);
|
||||||
|
} catch (ResourceInUseException ex) {
|
||||||
|
Assert.fail("Got exception: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
ConditionResponse conditionResponse = Mockito.mock(ConditionResponse.class);
|
||||||
|
Mockito.when(responseGenerator.createConditionResponse(condition)).thenReturn(conditionResponse);
|
||||||
|
|
||||||
|
try {
|
||||||
|
updateConditionCmd.execute();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Assert.fail("Got exception: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
Mockito.verify(responseGenerator).createConditionResponse(condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateFailure() {
|
||||||
|
|
||||||
|
ResourceInUseException exception = new ResourceInUseException("Resource in use");
|
||||||
|
try {
|
||||||
|
Mockito.when(autoScaleService.updateCondition(Mockito.any(UpdateConditionCmd.class))).thenThrow(exception);
|
||||||
|
} catch (ResourceInUseException ex) {
|
||||||
|
Assert.fail("Got exception: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
updateConditionCmd.execute();
|
||||||
|
} catch (ServerApiException ex) {
|
||||||
|
Assert.assertEquals(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getErrorCode());
|
||||||
|
Assert.assertEquals("Resource in use", ex.getDescription());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -21,7 +21,7 @@ package com.cloud.agent.api;
|
|||||||
|
|
||||||
import com.cloud.agent.api.LogLevel.Log4jLevel;
|
import com.cloud.agent.api.LogLevel.Log4jLevel;
|
||||||
|
|
||||||
@LogLevel(Log4jLevel.Trace)
|
@LogLevel(Log4jLevel.Debug)
|
||||||
public class NetworkUsageCommand extends Command {
|
public class NetworkUsageCommand extends Command {
|
||||||
private String privateIP;
|
private String privateIP;
|
||||||
private String domRName;
|
private String domRName;
|
||||||
|
|||||||
@ -0,0 +1,51 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
|
||||||
|
package com.cloud.agent.api.routing;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.Answer;
|
||||||
|
import com.cloud.agent.api.Command;
|
||||||
|
import com.cloud.agent.api.LogLevel;
|
||||||
|
import com.cloud.agent.api.LogLevel.Log4jLevel;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleMetricsValue;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@LogLevel(Log4jLevel.Debug)
|
||||||
|
public class GetAutoScaleMetricsAnswer extends Answer {
|
||||||
|
private List<AutoScaleMetricsValue> values;
|
||||||
|
|
||||||
|
public GetAutoScaleMetricsAnswer(Command cmd, boolean success) {
|
||||||
|
super(cmd, success, null);
|
||||||
|
this.values = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetAutoScaleMetricsAnswer(Command cmd, boolean success, List<AutoScaleMetricsValue> values) {
|
||||||
|
super(cmd, success, null);
|
||||||
|
this.values = values;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addValue(AutoScaleMetricsValue value) {
|
||||||
|
this.values.add(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AutoScaleMetricsValue> getValues() {
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
|
||||||
|
package com.cloud.agent.api.routing;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.Command;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleMetrics;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GetAutoScaleMetricsCommand extends Command {
|
||||||
|
|
||||||
|
private String privateIP;
|
||||||
|
boolean forVpc = false;
|
||||||
|
private String publicIP;
|
||||||
|
private Integer port;
|
||||||
|
private List<AutoScaleMetrics> metrics;
|
||||||
|
|
||||||
|
public GetAutoScaleMetricsCommand(String privateIP, boolean forVpc, String publicIP, Integer port, List<AutoScaleMetrics> metrics) {
|
||||||
|
this.privateIP = privateIP;
|
||||||
|
this.forVpc = forVpc;
|
||||||
|
this.publicIP = publicIP;
|
||||||
|
this.port = port;
|
||||||
|
this.metrics = metrics;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrivateIP() {
|
||||||
|
return privateIP;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isForVpc() {
|
||||||
|
return forVpc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublicIP() {
|
||||||
|
return publicIP;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AutoScaleMetrics> getMetrics() {
|
||||||
|
return metrics;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean executeInSequence() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -44,10 +44,10 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
|
|||||||
private static final Logger s_logger = Logger.getLogger(HAProxyConfigurator.class);
|
private static final Logger s_logger = Logger.getLogger(HAProxyConfigurator.class);
|
||||||
private static final String blankLine = "\t ";
|
private static final String blankLine = "\t ";
|
||||||
private static String[] globalSection = {"global", "\tlog 127.0.0.1:3914 local0 warning", "\tmaxconn 4096", "\tmaxpipes 1024", "\tchroot /var/lib/haproxy",
|
private static String[] globalSection = {"global", "\tlog 127.0.0.1:3914 local0 warning", "\tmaxconn 4096", "\tmaxpipes 1024", "\tchroot /var/lib/haproxy",
|
||||||
"\tuser haproxy", "\tgroup haproxy", "\tdaemon"};
|
"\tuser haproxy", "\tgroup haproxy", "\tstats socket /run/haproxy/admin.sock", "\tdaemon"};
|
||||||
|
|
||||||
private static String[] defaultsSection = {"defaults", "\tlog global", "\tmode tcp", "\toption dontlognull", "\tretries 3", "\toption redispatch",
|
private static String[] defaultsSection = {"defaults", "\tlog global", "\tmode tcp", "\toption dontlognull", "\tretries 3", "\toption redispatch",
|
||||||
"\toption forwardfor", "\toption forceclose", "\ttimeout connect 5000", "\ttimeout client 50000", "\ttimeout server 50000"};
|
"\toption forwardfor", "\toption httpclose", "\ttimeout connect 5000", "\ttimeout client 50000", "\ttimeout server 50000"};
|
||||||
|
|
||||||
private static String[] defaultListen = {"listen vmops", "\tbind 0.0.0.0:9", "\toption transparent"};
|
private static String[] defaultListen = {"listen vmops", "\tbind 0.0.0.0:9", "\toption transparent"};
|
||||||
|
|
||||||
@ -603,7 +603,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
|
|||||||
result.add(blankLine);
|
result.add(blankLine);
|
||||||
final List<String> dSection = Arrays.asList(defaultsSection);
|
final List<String> dSection = Arrays.asList(defaultsSection);
|
||||||
if (lbCmd.keepAliveEnabled) {
|
if (lbCmd.keepAliveEnabled) {
|
||||||
dSection.set(7, "\tno option forceclose");
|
dSection.set(7, "\tno option httpclose");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
|
|||||||
@ -829,7 +829,7 @@ public class VirtualRoutingResourceTest implements VirtualRouterDeployer {
|
|||||||
"\tretries 3\n" +
|
"\tretries 3\n" +
|
||||||
"\toption redispatch\n" +
|
"\toption redispatch\n" +
|
||||||
"\toption forwardfor\n" +
|
"\toption forwardfor\n" +
|
||||||
"\toption forceclose\n" +
|
"\toption httpclose\n" +
|
||||||
"\ttimeout connect 5000\n" +
|
"\ttimeout connect 5000\n" +
|
||||||
"\ttimeout client 50000\n" +
|
"\ttimeout client 50000\n" +
|
||||||
"\ttimeout server 50000\n" +
|
"\ttimeout server 50000\n" +
|
||||||
|
|||||||
@ -0,0 +1,93 @@
|
|||||||
|
//
|
||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
//
|
||||||
|
|
||||||
|
package org.apache.cloudstack.api.agent.test;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.routing.GetAutoScaleMetricsAnswer;
|
||||||
|
import com.cloud.agent.api.routing.GetAutoScaleMetricsCommand;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleMetrics;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleMetricsValue;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.VirtualRouterAutoScaleCounter;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class GetAutoScaleMetricsAnswerTest {
|
||||||
|
private GetAutoScaleMetricsCommand command;
|
||||||
|
|
||||||
|
private static final String privateIp = "privateip";
|
||||||
|
private static final String publicIP = "publicIP";
|
||||||
|
private static final Integer port = 8080;
|
||||||
|
|
||||||
|
List<AutoScaleMetrics> metrics = new ArrayList<>();
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
metrics.add(new AutoScaleMetrics(VirtualRouterAutoScaleCounter.LB_AVERAGE_CONNECTIONS, 1L, 2L, 3L, 4));
|
||||||
|
metrics.add(new AutoScaleMetrics(VirtualRouterAutoScaleCounter.NETWORK_RECEIVED_AVERAGE_MBPS, 1L, 2L, 3L, 4));
|
||||||
|
metrics.add(new AutoScaleMetrics(VirtualRouterAutoScaleCounter.NETWORK_TRANSMIT_AVERAGE_MBPS, 1L, 2L, 3L, 4));
|
||||||
|
|
||||||
|
command = new GetAutoScaleMetricsCommand(privateIp, true, publicIP, port, metrics);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFalseAnswer() {
|
||||||
|
GetAutoScaleMetricsAnswer answer = new GetAutoScaleMetricsAnswer(command, false);
|
||||||
|
|
||||||
|
assertFalse(answer.getResult());
|
||||||
|
assertEquals(0, answer.getValues().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTrueAnswer() {
|
||||||
|
GetAutoScaleMetricsAnswer answer = new GetAutoScaleMetricsAnswer(command, true);
|
||||||
|
|
||||||
|
assertTrue(answer.getResult());
|
||||||
|
assertEquals(0, answer.getValues().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAnswerWithValue() {
|
||||||
|
GetAutoScaleMetricsAnswer answer = new GetAutoScaleMetricsAnswer(command, true, new ArrayList<>());
|
||||||
|
|
||||||
|
assertTrue(answer.getResult());
|
||||||
|
assertEquals(0, answer.getValues().size());
|
||||||
|
|
||||||
|
answer.addValue(new AutoScaleMetricsValue(metrics.get(0), VirtualRouterAutoScale.AutoScaleValueType.INSTANT_VM, Double.valueOf(1)));
|
||||||
|
assertEquals(1, answer.getValues().size());
|
||||||
|
assertEquals(metrics.get(0), answer.getValues().get(0).getMetrics());
|
||||||
|
assertEquals(Double.valueOf(1), answer.getValues().get(0).getValue());
|
||||||
|
|
||||||
|
answer.addValue(new AutoScaleMetricsValue(metrics.get(1), VirtualRouterAutoScale.AutoScaleValueType.INSTANT_VM, Double.valueOf(2)));
|
||||||
|
assertEquals(2, answer.getValues().size());
|
||||||
|
assertEquals(metrics.get(1), answer.getValues().get(1).getMetrics());
|
||||||
|
assertEquals(Double.valueOf(2), answer.getValues().get(1).getValue());
|
||||||
|
|
||||||
|
answer.addValue(new AutoScaleMetricsValue(metrics.get(2), VirtualRouterAutoScale.AutoScaleValueType.INSTANT_VM, Double.valueOf(3)));
|
||||||
|
assertEquals(3, answer.getValues().size());
|
||||||
|
assertEquals(metrics.get(2), answer.getValues().get(2).getMetrics());
|
||||||
|
assertEquals(Double.valueOf(3), answer.getValues().get(2).getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
//
|
||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
//
|
||||||
|
|
||||||
|
package org.apache.cloudstack.api.agent.test;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.routing.GetAutoScaleMetricsCommand;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleMetrics;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.VirtualRouterAutoScaleCounter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class GetAutoScaleMetricsCommandTest {
|
||||||
|
|
||||||
|
private static final String privateIp = "privateip";
|
||||||
|
private static final String publicIP = "publicIP";
|
||||||
|
private static final Integer port = 8080;
|
||||||
|
|
||||||
|
List<AutoScaleMetrics> metrics = new ArrayList<>();
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
metrics.add(new AutoScaleMetrics(VirtualRouterAutoScaleCounter.LB_AVERAGE_CONNECTIONS, 1L, 2L, 3L, 4));
|
||||||
|
metrics.add(new AutoScaleMetrics(VirtualRouterAutoScaleCounter.NETWORK_RECEIVED_AVERAGE_MBPS, 1L, 2L, 3L, 4));
|
||||||
|
metrics.add(new AutoScaleMetrics(VirtualRouterAutoScaleCounter.NETWORK_TRANSMIT_AVERAGE_MBPS, 1L, 2L, 3L, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCommandForVpc() {
|
||||||
|
GetAutoScaleMetricsCommand command = new GetAutoScaleMetricsCommand(privateIp, true, publicIP, port, metrics);
|
||||||
|
|
||||||
|
assertEquals(privateIp, command.getPrivateIP());
|
||||||
|
assertEquals(publicIP, command.getPublicIP());
|
||||||
|
assertTrue(command.isForVpc());
|
||||||
|
assertEquals(port, command.getPort());
|
||||||
|
assertNotNull(command.getMetrics());
|
||||||
|
assertEquals(3, command.getMetrics().size());
|
||||||
|
assertFalse(command.executeInSequence());
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
|
||||||
|
public void testCommandForNetwork() {
|
||||||
|
GetAutoScaleMetricsCommand command = new GetAutoScaleMetricsCommand(privateIp, false, publicIP, port, metrics);
|
||||||
|
|
||||||
|
assertEquals(privateIp, command.getPrivateIP());
|
||||||
|
assertEquals(publicIP, command.getPublicIP());
|
||||||
|
assertFalse(command.isForVpc());
|
||||||
|
assertEquals(port, command.getPort());
|
||||||
|
assertNotNull(command.getMetrics());
|
||||||
|
assertEquals(3, command.getMetrics().size());
|
||||||
|
assertFalse(command.executeInSequence());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -132,7 +132,7 @@ public interface VirtualMachineEntity extends CloudStackEntity {
|
|||||||
* Destroys the VM.
|
* Destroys the VM.
|
||||||
* @param expunge indicates if vm should be expunged
|
* @param expunge indicates if vm should be expunged
|
||||||
*/
|
*/
|
||||||
boolean destroy(String caller, boolean expunge) throws AgentUnavailableException, CloudException, ConcurrentOperationException;
|
boolean destroy(boolean expunge) throws AgentUnavailableException, CloudException, ConcurrentOperationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Duplicate this VM in the database so that it will start new
|
* Duplicate this VM in the database so that it will start new
|
||||||
|
|||||||
@ -20,8 +20,13 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.apache.cloudstack.context.CallContext;
|
import org.apache.cloudstack.context.CallContext;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.to.LoadBalancerTO;
|
||||||
import com.cloud.exception.NetworkRuleConflictException;
|
import com.cloud.exception.NetworkRuleConflictException;
|
||||||
import com.cloud.exception.ResourceUnavailableException;
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
|
import com.cloud.network.Network;
|
||||||
|
import com.cloud.network.as.AutoScaleVmGroup;
|
||||||
|
import com.cloud.network.as.AutoScaleVmGroupVO;
|
||||||
|
import com.cloud.network.dao.LoadBalancerVO;
|
||||||
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
|
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
|
||||||
import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
|
import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
|
||||||
import com.cloud.network.lb.LoadBalancingRule.LbSslCert;
|
import com.cloud.network.lb.LoadBalancingRule.LbSslCert;
|
||||||
@ -61,7 +66,13 @@ public interface LoadBalancingRulesManager {
|
|||||||
|
|
||||||
String getLBCapability(long networkid, String capabilityName);
|
String getLBCapability(long networkid, String capabilityName);
|
||||||
|
|
||||||
boolean configureLbAutoScaleVmGroup(long vmGroupid, String currentState) throws ResourceUnavailableException;
|
LoadBalancerTO.AutoScaleVmGroupTO toAutoScaleVmGroupTO(LoadBalancingRule.LbAutoScaleVmGroup lbAutoScaleVmGroup);
|
||||||
|
|
||||||
|
LoadBalancerTO.AutoScaleVmGroupTO toAutoScaleVmGroupTO(AutoScaleVmGroupVO asGroup);
|
||||||
|
|
||||||
|
Network.Provider getLoadBalancerServiceProvider(LoadBalancerVO loadBalancer);
|
||||||
|
|
||||||
|
boolean configureLbAutoScaleVmGroup(long vmGroupid, AutoScaleVmGroup.State currentState) throws ResourceUnavailableException;
|
||||||
|
|
||||||
boolean revokeLoadBalancersForNetwork(long networkId, Scheme scheme) throws ResourceUnavailableException;
|
boolean revokeLoadBalancersForNetwork(long networkId, Scheme scheme) throws ResourceUnavailableException;
|
||||||
|
|
||||||
|
|||||||
@ -46,5 +46,5 @@ public interface VMEntityManager {
|
|||||||
|
|
||||||
boolean stopvirtualmachineforced(VMEntityVO vmEntityVO, String caller) throws ResourceUnavailableException;
|
boolean stopvirtualmachineforced(VMEntityVO vmEntityVO, String caller) throws ResourceUnavailableException;
|
||||||
|
|
||||||
boolean destroyVirtualMachine(VMEntityVO vmEntityVO, String caller, boolean expunge) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException;
|
boolean destroyVirtualMachine(VMEntityVO vmEntityVO, boolean expunge) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -277,7 +277,7 @@ public class VMEntityManagerImpl implements VMEntityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean destroyVirtualMachine(VMEntityVO vmEntityVO, String caller, boolean expunge) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException {
|
public boolean destroyVirtualMachine(VMEntityVO vmEntityVO, boolean expunge) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException {
|
||||||
|
|
||||||
VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
|
VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
|
||||||
_itMgr.destroy(vm.getUuid(), expunge);
|
_itMgr.destroy(vm.getUuid(), expunge);
|
||||||
|
|||||||
@ -231,8 +231,8 @@ public class VirtualMachineEntityImpl implements VirtualMachineEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean destroy(String caller, boolean expunge) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException {
|
public boolean destroy(boolean expunge) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException {
|
||||||
return manager.destroyVirtualMachine(this.vmEntityVO, caller, expunge);
|
return manager.destroyVirtualMachine(this.vmEntityVO, expunge);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -47,6 +47,9 @@ public class AutoScalePolicyVO implements AutoScalePolicy, InternalIdentity {
|
|||||||
@Column(name = "uuid")
|
@Column(name = "uuid")
|
||||||
String uuid;
|
String uuid;
|
||||||
|
|
||||||
|
@Column(name = "name")
|
||||||
|
String name;
|
||||||
|
|
||||||
@Column(name = "domain_id")
|
@Column(name = "domain_id")
|
||||||
private long domainId;
|
private long domainId;
|
||||||
|
|
||||||
@ -61,10 +64,10 @@ public class AutoScalePolicyVO implements AutoScalePolicy, InternalIdentity {
|
|||||||
|
|
||||||
@Column(name = "last_quiet_time", updatable = true)
|
@Column(name = "last_quiet_time", updatable = true)
|
||||||
@Temporal(value = TemporalType.TIMESTAMP)
|
@Temporal(value = TemporalType.TIMESTAMP)
|
||||||
private Date lastQuiteTime;
|
private Date lastQuietTime;
|
||||||
|
|
||||||
@Column(name = "action", updatable = false, nullable = false)
|
@Column(name = "action", updatable = false, nullable = false)
|
||||||
private String action;
|
private Action action;
|
||||||
|
|
||||||
@Column(name = GenericDao.REMOVED_COLUMN)
|
@Column(name = GenericDao.REMOVED_COLUMN)
|
||||||
protected Date removed;
|
protected Date removed;
|
||||||
@ -75,14 +78,15 @@ public class AutoScalePolicyVO implements AutoScalePolicy, InternalIdentity {
|
|||||||
public AutoScalePolicyVO() {
|
public AutoScalePolicyVO() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AutoScalePolicyVO(long domainId, long accountId, int duration,
|
public AutoScalePolicyVO(String name, long domainId, long accountId, int duration,
|
||||||
int quietTime, Date lastQuiteTime, String action) {
|
int quietTime, Date lastQuietTime, Action action) {
|
||||||
uuid = UUID.randomUUID().toString();
|
uuid = UUID.randomUUID().toString();
|
||||||
|
this.name = name;
|
||||||
this.domainId = domainId;
|
this.domainId = domainId;
|
||||||
this.accountId = accountId;
|
this.accountId = accountId;
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
this.quietTime = quietTime;
|
this.quietTime = quietTime;
|
||||||
this.lastQuiteTime = lastQuiteTime;
|
this.lastQuietTime = lastQuietTime;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,12 +126,12 @@ public class AutoScalePolicyVO implements AutoScalePolicy, InternalIdentity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Date getLastQuiteTime() {
|
public Date getLastQuietTime() {
|
||||||
return lastQuiteTime;
|
return lastQuietTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAction() {
|
public Action getAction() {
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,8 +151,8 @@ public class AutoScalePolicyVO implements AutoScalePolicy, InternalIdentity {
|
|||||||
this.quietTime = quietTime;
|
this.quietTime = quietTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastQuiteTime(Date lastQuiteTime) {
|
public void setLastQuietTime(Date lastQuietTime) {
|
||||||
this.lastQuiteTime = lastQuiteTime;
|
this.lastQuietTime = lastQuietTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -158,7 +162,10 @@ public class AutoScalePolicyVO implements AutoScalePolicy, InternalIdentity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return null;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,168 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
package com.cloud.network.as;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EnumType;
|
||||||
|
import javax.persistence.Enumerated;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale;
|
||||||
|
import com.cloud.server.ResourceTag;
|
||||||
|
import org.apache.cloudstack.api.InternalIdentity;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "autoscale_vmgroup_statistics")
|
||||||
|
public class AutoScaleVmGroupStatisticsVO implements InternalIdentity {
|
||||||
|
|
||||||
|
public enum State {
|
||||||
|
ACTIVE, INACTIVE
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final double INVALID_VALUE = -1;
|
||||||
|
public static final long DUMMY_ID = 0L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "id")
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
@Column(name = "vmgroup_id")
|
||||||
|
private long vmGroupId;
|
||||||
|
|
||||||
|
@Column(name = "policy_id")
|
||||||
|
private long policyId;
|
||||||
|
|
||||||
|
@Column(name = "counter_id")
|
||||||
|
private long counterId;
|
||||||
|
|
||||||
|
@Column(name = "resource_id")
|
||||||
|
private Long resourceId;
|
||||||
|
|
||||||
|
@Column(name = "resource_type")
|
||||||
|
@Enumerated(value = EnumType.STRING)
|
||||||
|
private ResourceTag.ResourceObjectType resourceType;
|
||||||
|
|
||||||
|
@Column(name = "raw_value")
|
||||||
|
private Double rawValue = null;
|
||||||
|
|
||||||
|
@Column(name = "value_type")
|
||||||
|
@Enumerated(value = EnumType.STRING)
|
||||||
|
private VirtualRouterAutoScale.AutoScaleValueType valueType;
|
||||||
|
|
||||||
|
@Column(name = "created")
|
||||||
|
@Temporal(value = TemporalType.TIMESTAMP)
|
||||||
|
private Date created = null;
|
||||||
|
|
||||||
|
@Column(name = "state")
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
State state;
|
||||||
|
|
||||||
|
public AutoScaleVmGroupStatisticsVO() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutoScaleVmGroupStatisticsVO(long vmGroupId, long policyId, long counterId, Long resourceId, ResourceTag.ResourceObjectType resourceType,
|
||||||
|
Double rawValue, VirtualRouterAutoScale.AutoScaleValueType valueType, Date created) {
|
||||||
|
this.vmGroupId = vmGroupId;
|
||||||
|
this.policyId = policyId;
|
||||||
|
this.counterId = counterId;
|
||||||
|
this.resourceId = resourceId;
|
||||||
|
this.resourceType = resourceType;
|
||||||
|
this.rawValue = rawValue;
|
||||||
|
this.valueType = valueType;
|
||||||
|
this.created = created;
|
||||||
|
this.state = State.ACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutoScaleVmGroupStatisticsVO(long vmGroupId, long policyId, long counterId, Long resourceId, ResourceTag.ResourceObjectType resourceType,
|
||||||
|
VirtualRouterAutoScale.AutoScaleValueType valueType, Date created) {
|
||||||
|
this.vmGroupId = vmGroupId;
|
||||||
|
this.policyId = policyId;
|
||||||
|
this.counterId = counterId;
|
||||||
|
this.resourceId = resourceId;
|
||||||
|
this.resourceType = resourceType;
|
||||||
|
this.rawValue = INVALID_VALUE;
|
||||||
|
this.valueType = valueType;
|
||||||
|
this.created = created;
|
||||||
|
this.state = State.INACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutoScaleVmGroupStatisticsVO(long vmGroupId) {
|
||||||
|
this.vmGroupId = vmGroupId;
|
||||||
|
this.policyId = DUMMY_ID;
|
||||||
|
this.counterId = DUMMY_ID;
|
||||||
|
this.resourceId = vmGroupId;
|
||||||
|
this.resourceType = ResourceTag.ResourceObjectType.AutoScaleVmGroup;
|
||||||
|
this.rawValue = INVALID_VALUE;
|
||||||
|
this.valueType = VirtualRouterAutoScale.AutoScaleValueType.INSTANT_VM_GROUP;
|
||||||
|
this.created = new Date();
|
||||||
|
this.state = State.INACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getVmGroupId() {
|
||||||
|
return vmGroupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getPolicyId() {
|
||||||
|
return policyId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCounterId() {
|
||||||
|
return counterId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getResourceId() {
|
||||||
|
return resourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceTag.ResourceObjectType getResourceType() {
|
||||||
|
return resourceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getRawValue() {
|
||||||
|
return rawValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VirtualRouterAutoScale.AutoScaleValueType getValueType() {
|
||||||
|
return valueType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreated() {
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
|
||||||
|
public State getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setState(State state) {
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -30,14 +30,16 @@ import javax.persistence.Table;
|
|||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.api.Identity;
|
||||||
import org.apache.cloudstack.api.InternalIdentity;
|
import org.apache.cloudstack.api.InternalIdentity;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "autoscale_vmgroups")
|
@Table(name = "autoscale_vmgroups")
|
||||||
@Inheritance(strategy = InheritanceType.JOINED)
|
@Inheritance(strategy = InheritanceType.JOINED)
|
||||||
public class AutoScaleVmGroupVO implements AutoScaleVmGroup, InternalIdentity {
|
public class AutoScaleVmGroupVO implements AutoScaleVmGroup, InternalIdentity, Identity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@ -59,6 +61,9 @@ public class AutoScaleVmGroupVO implements AutoScaleVmGroup, InternalIdentity {
|
|||||||
@Column(name = "load_balancer_id")
|
@Column(name = "load_balancer_id")
|
||||||
private Long loadBalancerId;
|
private Long loadBalancerId;
|
||||||
|
|
||||||
|
@Column(name = "name")
|
||||||
|
String name;
|
||||||
|
|
||||||
@Column(name = "min_members", updatable = true)
|
@Column(name = "min_members", updatable = true)
|
||||||
private int minMembers;
|
private int minMembers;
|
||||||
|
|
||||||
@ -85,20 +90,28 @@ public class AutoScaleVmGroupVO implements AutoScaleVmGroup, InternalIdentity {
|
|||||||
protected Date created;
|
protected Date created;
|
||||||
|
|
||||||
@Column(name = "state")
|
@Column(name = "state")
|
||||||
private String state;
|
private State state;
|
||||||
|
|
||||||
@Column(name = "display", updatable = true, nullable = false)
|
@Column(name = "display", updatable = true, nullable = false)
|
||||||
protected boolean display = true;
|
protected boolean display = true;
|
||||||
|
|
||||||
|
@Column(name = "next_vm_seq")
|
||||||
|
private long nextVmSeq = 1L;
|
||||||
|
|
||||||
public AutoScaleVmGroupVO() {
|
public AutoScaleVmGroupVO() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AutoScaleVmGroupVO(long lbRuleId, long zoneId, long domainId,
|
public AutoScaleVmGroupVO(long lbRuleId, long zoneId, long domainId,
|
||||||
long accountId, int minMembers, int maxMembers, int memberPort,
|
long accountId, String name, int minMembers, int maxMembers, int memberPort,
|
||||||
int interval, Date lastInterval, long profileId, String state) {
|
int interval, Date lastInterval, long profileId, State state) {
|
||||||
|
|
||||||
uuid = UUID.randomUUID().toString();
|
uuid = UUID.randomUUID().toString();
|
||||||
loadBalancerId = lbRuleId;
|
loadBalancerId = lbRuleId;
|
||||||
|
if (StringUtils.isBlank(name)) {
|
||||||
|
this.name = uuid;
|
||||||
|
} else {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
this.minMembers = minMembers;
|
this.minMembers = minMembers;
|
||||||
this.maxMembers = maxMembers;
|
this.maxMembers = maxMembers;
|
||||||
this.memberPort = memberPort;
|
this.memberPort = memberPort;
|
||||||
@ -113,7 +126,11 @@ public class AutoScaleVmGroupVO implements AutoScaleVmGroup, InternalIdentity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new StringBuilder("AutoScaleVmGroupVO[").append("id").append("]").toString();
|
return new StringBuilder("AutoScaleVmGroupVO[").append("id=").append(id)
|
||||||
|
.append("|name=").append(name)
|
||||||
|
.append("|loadBalancerId=").append(loadBalancerId)
|
||||||
|
.append("|profileId=").append(profileId)
|
||||||
|
.append("]").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -140,6 +157,11 @@ public class AutoScaleVmGroupVO implements AutoScaleVmGroup, InternalIdentity {
|
|||||||
return loadBalancerId;
|
return loadBalancerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMinMembers() {
|
public int getMinMembers() {
|
||||||
return minMembers;
|
return minMembers;
|
||||||
@ -174,19 +196,24 @@ public class AutoScaleVmGroupVO implements AutoScaleVmGroup, InternalIdentity {
|
|||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Date getCreated() {
|
public Date getCreated() {
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getState() {
|
public State getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setState(String state) {
|
public void setState(State state) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
public void setMinMembers(int minMembers) {
|
public void setMinMembers(int minMembers) {
|
||||||
this.minMembers = minMembers;
|
this.minMembers = minMembers;
|
||||||
}
|
}
|
||||||
@ -225,13 +252,16 @@ public class AutoScaleVmGroupVO implements AutoScaleVmGroup, InternalIdentity {
|
|||||||
return display;
|
return display;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getNextVmSeq() {
|
||||||
|
return nextVmSeq;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNextVmSeq(long nextVmSeq) {
|
||||||
|
this.nextVmSeq = nextVmSeq;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?> getEntityType() {
|
public Class<?> getEntityType() {
|
||||||
return AutoScaleVmGroup.class;
|
return AutoScaleVmGroup.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,8 +24,10 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.persistence.Basic;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.FetchType;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import javax.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
@ -35,6 +37,8 @@ import javax.persistence.Table;
|
|||||||
|
|
||||||
import org.apache.cloudstack.api.Identity;
|
import org.apache.cloudstack.api.Identity;
|
||||||
import org.apache.cloudstack.api.InternalIdentity;
|
import org.apache.cloudstack.api.InternalIdentity;
|
||||||
|
import org.apache.commons.collections.MapUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
@ -63,7 +67,7 @@ public class AutoScaleVmProfileVO implements AutoScaleVmProfile, Identity, Inter
|
|||||||
private long accountId;
|
private long accountId;
|
||||||
|
|
||||||
@Column(name = "autoscale_user_id")
|
@Column(name = "autoscale_user_id")
|
||||||
private long autoscaleUserId;
|
private Long autoscaleUserId;
|
||||||
|
|
||||||
@Column(name = "service_offering_id", updatable = true, nullable = false)
|
@Column(name = "service_offering_id", updatable = true, nullable = false)
|
||||||
private Long serviceOfferingId;
|
private Long serviceOfferingId;
|
||||||
@ -74,12 +78,16 @@ public class AutoScaleVmProfileVO implements AutoScaleVmProfile, Identity, Inter
|
|||||||
@Column(name = "other_deploy_params", updatable = true, length = 1024)
|
@Column(name = "other_deploy_params", updatable = true, length = 1024)
|
||||||
private String otherDeployParams;
|
private String otherDeployParams;
|
||||||
|
|
||||||
@Column(name = "destroy_vm_grace_period", updatable = true)
|
@Column(name = "expunge_vm_grace_period", updatable = true)
|
||||||
private Integer destroyVmGraceperiod = NetUtils.DEFAULT_AUTOSCALE_VM_DESTROY_TIME;
|
private Integer expungeVmGracePeriod = NetUtils.DEFAULT_AUTOSCALE_EXPUNGE_VM_GRACE_PERIOD;
|
||||||
|
|
||||||
@Column(name = "counter_params", updatable = true)
|
@Column(name = "counter_params", updatable = true)
|
||||||
private String counterParams;
|
private String counterParams;
|
||||||
|
|
||||||
|
@Column(name = "user_data", updatable = true, nullable = true, length = 1048576)
|
||||||
|
@Basic(fetch = FetchType.LAZY)
|
||||||
|
private String userData;
|
||||||
|
|
||||||
@Column(name = GenericDao.REMOVED_COLUMN)
|
@Column(name = GenericDao.REMOVED_COLUMN)
|
||||||
protected Date removed;
|
protected Date removed;
|
||||||
|
|
||||||
@ -92,20 +100,22 @@ public class AutoScaleVmProfileVO implements AutoScaleVmProfile, Identity, Inter
|
|||||||
public AutoScaleVmProfileVO() {
|
public AutoScaleVmProfileVO() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AutoScaleVmProfileVO(long zoneId, long domainId, long accountId, long serviceOfferingId, long templateId, String otherDeployParams, Map counterParamList,
|
public AutoScaleVmProfileVO(long zoneId, long domainId, long accountId, long serviceOfferingId, long templateId,
|
||||||
Integer destroyVmGraceperiod, long autoscaleUserId) {
|
Map<String, HashMap<String, String>> otherDeployParamsMap, Map counterParamList,
|
||||||
|
String userData, Integer expungeVmGracePeriod, Long autoscaleUserId) {
|
||||||
uuid = UUID.randomUUID().toString();
|
uuid = UUID.randomUUID().toString();
|
||||||
this.zoneId = zoneId;
|
this.zoneId = zoneId;
|
||||||
this.domainId = domainId;
|
this.domainId = domainId;
|
||||||
this.accountId = accountId;
|
this.accountId = accountId;
|
||||||
this.serviceOfferingId = serviceOfferingId;
|
this.serviceOfferingId = serviceOfferingId;
|
||||||
this.templateId = templateId;
|
this.templateId = templateId;
|
||||||
this.otherDeployParams = otherDeployParams;
|
|
||||||
this.autoscaleUserId = autoscaleUserId;
|
this.autoscaleUserId = autoscaleUserId;
|
||||||
if (destroyVmGraceperiod != null) {
|
if (expungeVmGracePeriod != null) {
|
||||||
this.destroyVmGraceperiod = destroyVmGraceperiod;
|
this.expungeVmGracePeriod = expungeVmGracePeriod;
|
||||||
}
|
}
|
||||||
|
this.userData = userData;
|
||||||
setCounterParamsForUpdate(counterParamList);
|
setCounterParamsForUpdate(counterParamList);
|
||||||
|
setOtherDeployParamsForUpdate(otherDeployParamsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -127,29 +137,61 @@ public class AutoScaleVmProfileVO implements AutoScaleVmProfile, Identity, Inter
|
|||||||
return serviceOfferingId;
|
return serviceOfferingId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setServiceOfferingId(Long serviceOfferingId) {
|
||||||
|
this.serviceOfferingId = serviceOfferingId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getOtherDeployParams() {
|
public String getOtherDeployParams() {
|
||||||
return otherDeployParams;
|
return otherDeployParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pair<String, String>> getOtherDeployParamsList() {
|
||||||
|
List<Pair<String, String>> paramsList = new ArrayList<>();
|
||||||
|
if (otherDeployParams != null) {
|
||||||
|
String[] params = otherDeployParams.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 setOtherDeployParams(String otherDeployParams) {
|
public void setOtherDeployParams(String otherDeployParams) {
|
||||||
this.otherDeployParams = otherDeployParams;
|
this.otherDeployParams = otherDeployParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOtherDeployParamsForUpdate(Map<String, HashMap<String, String>> otherDeployParamsMap) {
|
||||||
|
if (MapUtils.isNotEmpty(otherDeployParamsMap)) {
|
||||||
|
List<String> params = new ArrayList<>();
|
||||||
|
for (HashMap<String, String> paramKVpair : otherDeployParamsMap.values()) {
|
||||||
|
String paramName = paramKVpair.get("name");
|
||||||
|
String paramValue = paramKVpair.get("value");
|
||||||
|
params.add(paramName + "=" + paramValue);
|
||||||
|
}
|
||||||
|
setOtherDeployParams(StringUtils.join(params, "&"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Pair<String, String>> getCounterParams() {
|
public List<Pair<String, String>> getCounterParams() {
|
||||||
List<Pair<String, String>> paramsList = new ArrayList<Pair<String, String>>();
|
List<Pair<String, String>> paramsList = new ArrayList<>();
|
||||||
if (counterParams != null) {
|
if (counterParams != null) {
|
||||||
String[] params = counterParams.split("[=&]");
|
String[] params = counterParams.split("[=&]");
|
||||||
for (int i = 0; i < (params.length - 1); i = i + 2) {
|
for (int i = 0; i < (params.length - 1); i = i + 2) {
|
||||||
paramsList.add(new Pair<String, String>(params[i], params[i + 1]));
|
paramsList.add(new Pair<>(params[i], params[i + 1]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return paramsList;
|
return paramsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCounterParamsString() {
|
||||||
|
return this.counterParams;
|
||||||
|
}
|
||||||
|
|
||||||
public void setCounterParams(String counterParam) {
|
public void setCounterParams(String counterParam) {
|
||||||
counterParams = counterParam;
|
this.counterParams = counterParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCounterParamsForUpdate(Map counterParamList) {
|
public void setCounterParamsForUpdate(Map counterParamList) {
|
||||||
@ -177,12 +219,21 @@ public class AutoScaleVmProfileVO implements AutoScaleVmProfile, Identity, Inter
|
|||||||
setCounterParams(sb.toString());
|
setCounterParams(sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUserData(String userData) {
|
||||||
|
this.userData = userData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUserData() {
|
||||||
|
return userData;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUuid() {
|
public String getUuid() {
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAutoscaleUserId(long autoscaleUserId) {
|
public void setAutoscaleUserId(Long autoscaleUserId) {
|
||||||
this.autoscaleUserId = autoscaleUserId;
|
this.autoscaleUserId = autoscaleUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,16 +258,16 @@ public class AutoScaleVmProfileVO implements AutoScaleVmProfile, Identity, Inter
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getDestroyVmGraceperiod() {
|
public Integer getExpungeVmGracePeriod() {
|
||||||
return destroyVmGraceperiod;
|
return expungeVmGracePeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDestroyVmGraceperiod(Integer destroyVmGraceperiod) {
|
public void setExpungeVmGracePeriod(Integer expungeVmGracePeriod) {
|
||||||
this.destroyVmGraceperiod = destroyVmGraceperiod;
|
this.expungeVmGracePeriod = expungeVmGracePeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAutoScaleUserId() {
|
public Long getAutoScaleUserId() {
|
||||||
return autoscaleUserId;
|
return autoscaleUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -44,7 +44,7 @@ public class ConditionVO implements Condition, Identity, InternalIdentity {
|
|||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
@Column(name = "counter_id")
|
@Column(name = "counter_id")
|
||||||
private long counterid;
|
private long counterId;
|
||||||
|
|
||||||
@Column(name = "threshold")
|
@Column(name = "threshold")
|
||||||
private long threshold;
|
private long threshold;
|
||||||
@ -71,8 +71,8 @@ public class ConditionVO implements Condition, Identity, InternalIdentity {
|
|||||||
public ConditionVO() {
|
public ConditionVO() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConditionVO(long counterid, long threshold, long accountId, long domainId, Operator relationalOperator) {
|
public ConditionVO(long counterId, long threshold, long accountId, long domainId, Operator relationalOperator) {
|
||||||
this.counterid = counterid;
|
this.counterId = counterId;
|
||||||
this.threshold = threshold;
|
this.threshold = threshold;
|
||||||
this.relationalOperator = relationalOperator;
|
this.relationalOperator = relationalOperator;
|
||||||
this.accountId = accountId;
|
this.accountId = accountId;
|
||||||
@ -95,8 +95,8 @@ public class ConditionVO implements Condition, Identity, InternalIdentity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getCounterid() {
|
public long getCounterId() {
|
||||||
return counterid;
|
return counterId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -138,4 +138,11 @@ public class ConditionVO implements Condition, Identity, InternalIdentity {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setThreshold(long threshold) {
|
||||||
|
this.threshold = threshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRelationalOperator(Operator relationalOperator) {
|
||||||
|
this.relationalOperator = relationalOperator;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import javax.persistence.Table;
|
|||||||
import org.apache.cloudstack.api.Identity;
|
import org.apache.cloudstack.api.Identity;
|
||||||
import org.apache.cloudstack.api.InternalIdentity;
|
import org.apache.cloudstack.api.InternalIdentity;
|
||||||
|
|
||||||
|
import com.cloud.network.Network;
|
||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@ -62,14 +63,18 @@ public class CounterVO implements Counter, Identity, InternalIdentity {
|
|||||||
@Column(name = GenericDao.CREATED_COLUMN)
|
@Column(name = GenericDao.CREATED_COLUMN)
|
||||||
Date created;
|
Date created;
|
||||||
|
|
||||||
|
@Column(name = "provider")
|
||||||
|
private String provider;
|
||||||
|
|
||||||
public CounterVO() {
|
public CounterVO() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CounterVO(Source source, String name, String value) {
|
public CounterVO(Source source, String name, String value, Network.Provider provider) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.uuid = UUID.randomUUID().toString();
|
this.uuid = UUID.randomUUID().toString();
|
||||||
|
this.provider = provider.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -109,4 +114,9 @@ public class CounterVO implements Counter, Identity, InternalIdentity {
|
|||||||
public Date getCreated() {
|
public Date getCreated() {
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getProvider() {
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@ package com.cloud.network.as.dao;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.cloud.network.as.AutoScaleVmGroup;
|
||||||
import com.cloud.network.as.AutoScaleVmGroupVO;
|
import com.cloud.network.as.AutoScaleVmGroupVO;
|
||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
@ -27,4 +28,12 @@ public interface AutoScaleVmGroupDao extends GenericDao<AutoScaleVmGroupVO, Long
|
|||||||
boolean isProfileInUse(long profileId);
|
boolean isProfileInUse(long profileId);
|
||||||
|
|
||||||
boolean isAutoScaleLoadBalancer(Long loadBalancerId);
|
boolean isAutoScaleLoadBalancer(Long loadBalancerId);
|
||||||
|
|
||||||
|
boolean updateState(long groupId, AutoScaleVmGroup.State oldState, AutoScaleVmGroup.State newState);
|
||||||
|
|
||||||
|
List<AutoScaleVmGroupVO> listByLoadBalancer(Long loadBalancerId);
|
||||||
|
|
||||||
|
List<AutoScaleVmGroupVO> listByProfile(Long profileId);
|
||||||
|
|
||||||
|
List<AutoScaleVmGroupVO> listByAccount(Long accountId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,46 +18,96 @@ package com.cloud.network.as.dao;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.cloud.network.as.AutoScaleVmGroup;
|
||||||
import com.cloud.network.as.AutoScaleVmGroupVO;
|
import com.cloud.network.as.AutoScaleVmGroupVO;
|
||||||
import com.cloud.utils.db.GenericDaoBase;
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
import com.cloud.utils.db.GenericSearchBuilder;
|
import com.cloud.utils.db.GenericSearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
import com.cloud.utils.db.SearchCriteria;
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
import com.cloud.utils.db.SearchCriteria.Func;
|
import com.cloud.utils.db.SearchCriteria.Func;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class AutoScaleVmGroupDaoImpl extends GenericDaoBase<AutoScaleVmGroupVO, Long> implements AutoScaleVmGroupDao {
|
public class AutoScaleVmGroupDaoImpl extends GenericDaoBase<AutoScaleVmGroupVO, Long> implements AutoScaleVmGroupDao {
|
||||||
|
|
||||||
|
SearchBuilder<AutoScaleVmGroupVO> AllFieldsSearch;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
AllFieldsSearch = createSearchBuilder();
|
||||||
|
AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||||
|
AllFieldsSearch.and("loadBalancerId", AllFieldsSearch.entity().getLoadBalancerId(), SearchCriteria.Op.EQ);
|
||||||
|
AllFieldsSearch.and("profileId", AllFieldsSearch.entity().getProfileId(), SearchCriteria.Op.EQ);
|
||||||
|
AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), SearchCriteria.Op.EQ);
|
||||||
|
AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
|
||||||
|
AllFieldsSearch.done();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AutoScaleVmGroupVO> listByAll(Long loadBalancerId, Long profileId) {
|
public List<AutoScaleVmGroupVO> listByAll(Long loadBalancerId, Long profileId) {
|
||||||
SearchCriteria<AutoScaleVmGroupVO> sc = createSearchCriteria();
|
SearchCriteria<AutoScaleVmGroupVO> sc = AllFieldsSearch.create();
|
||||||
|
|
||||||
if (loadBalancerId != null)
|
if (loadBalancerId != null)
|
||||||
sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
|
sc.setParameters("loadBalancerId", loadBalancerId);
|
||||||
|
|
||||||
if (profileId != null)
|
if (profileId != null)
|
||||||
sc.addAnd("profileId", SearchCriteria.Op.EQ, profileId);
|
sc.setParameters("profileId", profileId);
|
||||||
|
|
||||||
return listBy(sc);
|
return listBy(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isProfileInUse(long profileId) {
|
public boolean isProfileInUse(long profileId) {
|
||||||
SearchCriteria<AutoScaleVmGroupVO> sc = createSearchCriteria();
|
SearchCriteria<AutoScaleVmGroupVO> sc = AllFieldsSearch.create();
|
||||||
sc.addAnd("profileId", SearchCriteria.Op.EQ, profileId);
|
sc.setParameters("profileId", profileId);
|
||||||
return findOneBy(sc) != null;
|
return findOneBy(sc) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAutoScaleLoadBalancer(Long loadBalancerId) {
|
public boolean isAutoScaleLoadBalancer(Long loadBalancerId) {
|
||||||
GenericSearchBuilder<AutoScaleVmGroupVO, Long> CountByAccount = createSearchBuilder(Long.class);
|
GenericSearchBuilder<AutoScaleVmGroupVO, Long> countByLoadBalancer = createSearchBuilder(Long.class);
|
||||||
CountByAccount.select(null, Func.COUNT, null);
|
countByLoadBalancer.select(null, Func.COUNT, null);
|
||||||
CountByAccount.and("loadBalancerId", CountByAccount.entity().getLoadBalancerId(), SearchCriteria.Op.EQ);
|
countByLoadBalancer.and("loadBalancerId", countByLoadBalancer.entity().getLoadBalancerId(), SearchCriteria.Op.EQ);
|
||||||
|
|
||||||
SearchCriteria<Long> sc = CountByAccount.create();
|
SearchCriteria<Long> sc = countByLoadBalancer.create();
|
||||||
sc.setParameters("loadBalancerId", loadBalancerId);
|
sc.setParameters("loadBalancerId", loadBalancerId);
|
||||||
return customSearch(sc, null).get(0) > 0;
|
return customSearch(sc, null).get(0) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateState(long groupId, AutoScaleVmGroup.State oldState, AutoScaleVmGroup.State newState) {
|
||||||
|
SearchCriteria<AutoScaleVmGroupVO> sc = AllFieldsSearch.create();
|
||||||
|
sc.setParameters("id", groupId);
|
||||||
|
sc.setParameters("state", oldState);
|
||||||
|
AutoScaleVmGroupVO group = findOneBy(sc);
|
||||||
|
if (group == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
group.setState(newState);
|
||||||
|
return update(groupId, group);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AutoScaleVmGroupVO> listByLoadBalancer(Long loadBalancerId) {
|
||||||
|
SearchCriteria<AutoScaleVmGroupVO> sc = AllFieldsSearch.create();
|
||||||
|
sc.setParameters("loadBalancerId", loadBalancerId);
|
||||||
|
return listBy(sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AutoScaleVmGroupVO> listByProfile(Long profileId) {
|
||||||
|
SearchCriteria<AutoScaleVmGroupVO> sc = AllFieldsSearch.create();
|
||||||
|
sc.setParameters("profileId", profileId);
|
||||||
|
return listBy(sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AutoScaleVmGroupVO> listByAccount(Long accountId) {
|
||||||
|
SearchCriteria<AutoScaleVmGroupVO> sc = AllFieldsSearch.create();
|
||||||
|
sc.setParameters("accountId", accountId);
|
||||||
|
return listBy(sc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,41 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
package com.cloud.network.as.dao;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.cloud.network.as.AutoScaleVmGroupStatisticsVO;
|
||||||
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
|
public interface AutoScaleVmGroupStatisticsDao extends GenericDao<AutoScaleVmGroupStatisticsVO, Long> {
|
||||||
|
boolean removeByGroupId(long vmGroupId);
|
||||||
|
|
||||||
|
boolean removeByGroupId(long vmGroupId, Date beforeDate);
|
||||||
|
|
||||||
|
boolean removeByGroupAndPolicy(long vmGroupId, long policyId, Date beforeDate);
|
||||||
|
|
||||||
|
List<AutoScaleVmGroupStatisticsVO> listDummyRecordsByVmGroup(long vmGroupId, Date afterDate);
|
||||||
|
|
||||||
|
List<AutoScaleVmGroupStatisticsVO> listInactiveByVmGroupAndPolicy(long vmGroupId, long policyId, Date afterDate);
|
||||||
|
|
||||||
|
List<AutoScaleVmGroupStatisticsVO> listByVmGroupAndPolicyAndCounter(long vmGroupId, long policyId, long counterId, Date afterDate);
|
||||||
|
|
||||||
|
void updateStateByGroup(Long groupId, Long policyId, AutoScaleVmGroupStatisticsVO.State state);
|
||||||
|
|
||||||
|
AutoScaleVmGroupStatisticsVO createInactiveDummyRecord(Long groupId);
|
||||||
|
}
|
||||||
@ -0,0 +1,138 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
package com.cloud.network.as.dao;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.cloud.network.as.AutoScaleVmGroupStatisticsVO;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.SearchCriteria.Op;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class AutoScaleVmGroupStatisticsDaoImpl extends GenericDaoBase<AutoScaleVmGroupStatisticsVO, Long> implements AutoScaleVmGroupStatisticsDao {
|
||||||
|
|
||||||
|
SearchBuilder<AutoScaleVmGroupStatisticsVO> groupAndCounterSearch;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
protected void init() {
|
||||||
|
groupAndCounterSearch = createSearchBuilder();
|
||||||
|
groupAndCounterSearch.and("vmGroupId", groupAndCounterSearch.entity().getVmGroupId(), Op.EQ);
|
||||||
|
groupAndCounterSearch.and("policyId", groupAndCounterSearch.entity().getPolicyId(), Op.EQ);
|
||||||
|
groupAndCounterSearch.and("counterId", groupAndCounterSearch.entity().getCounterId(), Op.EQ);
|
||||||
|
groupAndCounterSearch.and("createdLT", groupAndCounterSearch.entity().getCreated(), Op.LT);
|
||||||
|
groupAndCounterSearch.and("createdGT", groupAndCounterSearch.entity().getCreated(), Op.GT);
|
||||||
|
groupAndCounterSearch.and("state", groupAndCounterSearch.entity().getState(), Op.EQ);
|
||||||
|
groupAndCounterSearch.and("stateNEQ", groupAndCounterSearch.entity().getState(), Op.NEQ);
|
||||||
|
groupAndCounterSearch.done();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeByGroupId(long vmGroupId) {
|
||||||
|
SearchCriteria<AutoScaleVmGroupStatisticsVO> sc = groupAndCounterSearch.create();
|
||||||
|
sc.setParameters("vmGroupId", vmGroupId);
|
||||||
|
|
||||||
|
return expunge(sc) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeByGroupId(long vmGroupId, Date beforeDate) {
|
||||||
|
SearchCriteria<AutoScaleVmGroupStatisticsVO> sc = groupAndCounterSearch.create();
|
||||||
|
sc.setParameters("vmGroupId", vmGroupId);
|
||||||
|
if (beforeDate != null) {
|
||||||
|
sc.setParameters("createdLT", beforeDate);
|
||||||
|
}
|
||||||
|
return expunge(sc) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeByGroupAndPolicy(long vmGroupId, long policyId, Date beforeDate) {
|
||||||
|
SearchCriteria<AutoScaleVmGroupStatisticsVO> sc = groupAndCounterSearch.create();
|
||||||
|
sc.setParameters("vmGroupId", vmGroupId);
|
||||||
|
sc.setParameters("policyId", policyId);
|
||||||
|
if (beforeDate != null) {
|
||||||
|
sc.setParameters("createdLT", beforeDate);
|
||||||
|
}
|
||||||
|
return expunge(sc) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AutoScaleVmGroupStatisticsVO> listDummyRecordsByVmGroup(long vmGroupId, Date afterDate) {
|
||||||
|
SearchCriteria<AutoScaleVmGroupStatisticsVO> sc = groupAndCounterSearch.create();
|
||||||
|
sc.setParameters("vmGroupId", vmGroupId);
|
||||||
|
sc.setParameters("policyId", AutoScaleVmGroupStatisticsVO.DUMMY_ID);
|
||||||
|
if (afterDate != null) {
|
||||||
|
sc.setParameters("createdGT", afterDate);
|
||||||
|
}
|
||||||
|
sc.setParameters("state", AutoScaleVmGroupStatisticsVO.State.INACTIVE);
|
||||||
|
return listBy(sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AutoScaleVmGroupStatisticsVO> listInactiveByVmGroupAndPolicy(long vmGroupId, long policyId, Date afterDate) {
|
||||||
|
SearchCriteria<AutoScaleVmGroupStatisticsVO> sc = groupAndCounterSearch.create();
|
||||||
|
sc.setParameters("vmGroupId", vmGroupId);
|
||||||
|
sc.setParameters("policyId", policyId);
|
||||||
|
if (afterDate != null) {
|
||||||
|
sc.setParameters("createdGT", afterDate);
|
||||||
|
}
|
||||||
|
sc.setParameters("state", AutoScaleVmGroupStatisticsVO.State.INACTIVE);
|
||||||
|
return listBy(sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AutoScaleVmGroupStatisticsVO> listByVmGroupAndPolicyAndCounter(long vmGroupId, long policyId, long counterId, Date afterDate) {
|
||||||
|
SearchCriteria<AutoScaleVmGroupStatisticsVO> sc = groupAndCounterSearch.create();
|
||||||
|
sc.setParameters("vmGroupId", vmGroupId);
|
||||||
|
sc.setParameters("policyId", policyId);
|
||||||
|
sc.setParameters("counterId", counterId);
|
||||||
|
if (afterDate != null) {
|
||||||
|
sc.setParameters("createdGT", afterDate);
|
||||||
|
}
|
||||||
|
sc.setParameters("state", AutoScaleVmGroupStatisticsVO.State.ACTIVE);
|
||||||
|
return listBy(sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateStateByGroup(Long groupId, Long policyId, AutoScaleVmGroupStatisticsVO.State state) {
|
||||||
|
SearchCriteria<AutoScaleVmGroupStatisticsVO> sc = groupAndCounterSearch.create();
|
||||||
|
if (groupId != null) {
|
||||||
|
sc.setParameters("vmGroupId", groupId);
|
||||||
|
}
|
||||||
|
if (policyId != null) {
|
||||||
|
sc.setParameters("policyId", policyId);
|
||||||
|
}
|
||||||
|
sc.setParameters("stateNEQ", state);
|
||||||
|
|
||||||
|
AutoScaleVmGroupStatisticsVO vo = createForUpdate();
|
||||||
|
vo.setState(state);
|
||||||
|
update(vo, sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AutoScaleVmGroupStatisticsVO createInactiveDummyRecord(Long groupId) {
|
||||||
|
AutoScaleVmGroupStatisticsVO vo = new AutoScaleVmGroupStatisticsVO(groupId);
|
||||||
|
return persist(vo);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,10 +22,17 @@ import com.cloud.network.as.AutoScaleVmGroupVmMapVO;
|
|||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
public interface AutoScaleVmGroupVmMapDao extends GenericDao<AutoScaleVmGroupVmMapVO, Long> {
|
public interface AutoScaleVmGroupVmMapDao extends GenericDao<AutoScaleVmGroupVmMapVO, Long> {
|
||||||
|
int countAvailableVmsByGroup(long vmGroupId);
|
||||||
|
|
||||||
public Integer countByGroup(long vmGroupId);
|
public Integer countByGroup(long vmGroupId);
|
||||||
|
|
||||||
public List<AutoScaleVmGroupVmMapVO> listByGroup(long vmGroupId);
|
public List<AutoScaleVmGroupVmMapVO> listByGroup(long vmGroupId);
|
||||||
|
|
||||||
|
public List<AutoScaleVmGroupVmMapVO> listByVm(long vmId);
|
||||||
|
|
||||||
public int remove(long vmGroupId, long vmId);
|
public int remove(long vmGroupId, long vmId);
|
||||||
|
|
||||||
|
public boolean removeByVm(long vmId);
|
||||||
|
|
||||||
|
public boolean removeByGroup(long vmGroupId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,32 +23,96 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import com.cloud.network.as.AutoScaleVmGroupVmMapVO;
|
import com.cloud.network.as.AutoScaleVmGroupVmMapVO;
|
||||||
import com.cloud.utils.db.GenericDaoBase;
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.GenericSearchBuilder;
|
||||||
|
import com.cloud.utils.db.JoinBuilder;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
import com.cloud.utils.db.SearchCriteria;
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.vm.VMInstanceVO;
|
||||||
|
import com.cloud.vm.VirtualMachine.State;
|
||||||
|
import com.cloud.vm.dao.VMInstanceDao;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class AutoScaleVmGroupVmMapDaoImpl extends GenericDaoBase<AutoScaleVmGroupVmMapVO, Long> implements AutoScaleVmGroupVmMapDao {
|
public class AutoScaleVmGroupVmMapDaoImpl extends GenericDaoBase<AutoScaleVmGroupVmMapVO, Long> implements AutoScaleVmGroupVmMapDao {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
VMInstanceDao vmInstanceDao;
|
||||||
|
|
||||||
|
GenericSearchBuilder<AutoScaleVmGroupVmMapVO, Integer> CountBy;
|
||||||
|
|
||||||
|
SearchBuilder<AutoScaleVmGroupVmMapVO> AllFieldsSearch;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
protected void init() {
|
||||||
|
CountBy = createSearchBuilder(Integer.class);
|
||||||
|
CountBy.select(null, SearchCriteria.Func.COUNT, CountBy.entity().getId());
|
||||||
|
CountBy.and("vmGroupId", CountBy.entity().getVmGroupId(), SearchCriteria.Op.EQ);
|
||||||
|
final SearchBuilder<VMInstanceVO> vmSearch = vmInstanceDao.createSearchBuilder();
|
||||||
|
vmSearch.and("states", vmSearch.entity().getState(), SearchCriteria.Op.IN);
|
||||||
|
CountBy.join("vmSearch", vmSearch, CountBy.entity().getInstanceId(), vmSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||||
|
CountBy.done();
|
||||||
|
|
||||||
|
AllFieldsSearch = createSearchBuilder();
|
||||||
|
AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||||
|
AllFieldsSearch.and("vmGroupId", AllFieldsSearch.entity().getVmGroupId(), SearchCriteria.Op.EQ);
|
||||||
|
AllFieldsSearch.and("instanceId", AllFieldsSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
|
||||||
|
AllFieldsSearch.done();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int countAvailableVmsByGroup(long vmGroupId) {
|
||||||
|
|
||||||
|
SearchCriteria<Integer> sc = CountBy.create();
|
||||||
|
sc.setParameters("vmGroupId", vmGroupId);
|
||||||
|
sc.setJoinParameters("vmSearch", "states",
|
||||||
|
State.Starting, State.Running, State.Stopping, State.Migrating);
|
||||||
|
final List<Integer> results = customSearch(sc, null);
|
||||||
|
return results.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer countByGroup(long vmGroupId) {
|
public Integer countByGroup(long vmGroupId) {
|
||||||
|
|
||||||
SearchCriteria<AutoScaleVmGroupVmMapVO> sc = createSearchCriteria();
|
SearchCriteria<AutoScaleVmGroupVmMapVO> sc = AllFieldsSearch.create();
|
||||||
sc.addAnd("vmGroupId", SearchCriteria.Op.EQ, vmGroupId);
|
sc.setParameters("vmGroupId", vmGroupId);
|
||||||
return getCountIncludingRemoved(sc);
|
return getCountIncludingRemoved(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AutoScaleVmGroupVmMapVO> listByGroup(long vmGroupId) {
|
public List<AutoScaleVmGroupVmMapVO> listByGroup(long vmGroupId) {
|
||||||
SearchCriteria<AutoScaleVmGroupVmMapVO> sc = createSearchCriteria();
|
SearchCriteria<AutoScaleVmGroupVmMapVO> sc = AllFieldsSearch.create();
|
||||||
sc.addAnd("vmGroupId", SearchCriteria.Op.EQ, vmGroupId);
|
sc.setParameters("vmGroupId", vmGroupId);
|
||||||
|
return listBy(sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AutoScaleVmGroupVmMapVO> listByVm(long vmId) {
|
||||||
|
SearchCriteria<AutoScaleVmGroupVmMapVO> sc = AllFieldsSearch.create();
|
||||||
|
sc.setParameters("instanceId", vmId);
|
||||||
return listBy(sc);
|
return listBy(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int remove(long vmGroupId, long vmId) {
|
public int remove(long vmGroupId, long vmId) {
|
||||||
SearchCriteria<AutoScaleVmGroupVmMapVO> sc = createSearchCriteria();
|
SearchCriteria<AutoScaleVmGroupVmMapVO> sc = AllFieldsSearch.create();
|
||||||
sc.addAnd("vmGroupId", SearchCriteria.Op.EQ, vmGroupId);
|
sc.setParameters("vmGroupId", vmGroupId);
|
||||||
sc.addAnd("instanceId", SearchCriteria.Op.EQ, vmId);
|
sc.setParameters("instanceId", vmId);
|
||||||
return remove(sc);
|
return remove(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeByVm(long vmId) {
|
||||||
|
SearchCriteria<AutoScaleVmGroupVmMapVO> sc = AllFieldsSearch.create();
|
||||||
|
sc.setParameters("instanceId", vmId);
|
||||||
|
return remove(sc) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeByGroup(long vmGroupId) {
|
||||||
|
SearchCriteria<AutoScaleVmGroupVmMapVO> sc = AllFieldsSearch.create();
|
||||||
|
sc.setParameters("vmGroupId", vmGroupId);
|
||||||
|
return remove(sc) >= 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,7 +33,7 @@ public class ConditionDaoImpl extends GenericDaoBase<ConditionVO, Long> implemen
|
|||||||
protected ConditionDaoImpl() {
|
protected ConditionDaoImpl() {
|
||||||
AllFieldsSearch = createSearchBuilder();
|
AllFieldsSearch = createSearchBuilder();
|
||||||
AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
|
AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
|
||||||
AllFieldsSearch.and("counterId", AllFieldsSearch.entity().getCounterid(), Op.EQ);
|
AllFieldsSearch.and("counterId", AllFieldsSearch.entity().getCounterId(), Op.EQ);
|
||||||
AllFieldsSearch.done();
|
AllFieldsSearch.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,6 +24,6 @@ import com.cloud.utils.db.Filter;
|
|||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
public interface CounterDao extends GenericDao<CounterVO, Long> {
|
public interface CounterDao extends GenericDao<CounterVO, Long> {
|
||||||
public List<CounterVO> listCounters(Long id, String name, String source, String keyword, Filter filter);
|
public List<CounterVO> listCounters(Long id, String name, String source, String provider, String keyword, Filter filter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,11 +38,12 @@ public class CounterDaoImpl extends GenericDaoBase<CounterVO, Long> implements C
|
|||||||
AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
|
AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
|
||||||
AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), Op.LIKE);
|
AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), Op.LIKE);
|
||||||
AllFieldsSearch.and("source", AllFieldsSearch.entity().getSource(), Op.EQ);
|
AllFieldsSearch.and("source", AllFieldsSearch.entity().getSource(), Op.EQ);
|
||||||
|
AllFieldsSearch.and("provider", AllFieldsSearch.entity().getProvider(), Op.EQ);
|
||||||
AllFieldsSearch.done();
|
AllFieldsSearch.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CounterVO> listCounters(Long id, String name, String source, String keyword, Filter filter) {
|
public List<CounterVO> listCounters(Long id, String name, String source, String provider, String keyword, Filter filter) {
|
||||||
SearchCriteria<CounterVO> sc = AllFieldsSearch.create();
|
SearchCriteria<CounterVO> sc = AllFieldsSearch.create();
|
||||||
|
|
||||||
if (keyword != null) {
|
if (keyword != null) {
|
||||||
@ -52,15 +53,18 @@ public class CounterDaoImpl extends GenericDaoBase<CounterVO, Long> implements C
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
|
sc.setParameters("name", "%" + name + "%");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
sc.addAnd("id", SearchCriteria.Op.EQ, id);
|
sc.setParameters("id", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
sc.addAnd("source", SearchCriteria.Op.EQ, source);
|
sc.setParameters("source", source);
|
||||||
|
}
|
||||||
|
if (provider != null) {
|
||||||
|
sc.setParameters("provider", provider);
|
||||||
}
|
}
|
||||||
return listBy(sc, filter);
|
return listBy(sc, filter);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -148,6 +148,9 @@ public class NetworkOfferingVO implements NetworkOffering {
|
|||||||
@Column(name="supports_public_access")
|
@Column(name="supports_public_access")
|
||||||
boolean supportsPublicAccess = false;
|
boolean supportsPublicAccess = false;
|
||||||
|
|
||||||
|
@Column(name = "supports_vm_autoscaling")
|
||||||
|
boolean supportsVmAutoScaling = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayText() {
|
public String getDisplayText() {
|
||||||
return displayText;
|
return displayText;
|
||||||
@ -534,4 +537,13 @@ public class NetworkOfferingVO implements NetworkOffering {
|
|||||||
public String getServicePackage() {
|
public String getServicePackage() {
|
||||||
return servicePackageUuid;
|
return servicePackageUuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSupportsVmAutoScaling(boolean supportsVmAutoScaling) {
|
||||||
|
this.supportsVmAutoScaling = supportsVmAutoScaling;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSupportsVmAutoScaling() {
|
||||||
|
return supportsVmAutoScaling;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,6 +50,7 @@
|
|||||||
<bean id="autoScalePolicyDaoImpl" class="com.cloud.network.as.dao.AutoScalePolicyDaoImpl" />
|
<bean id="autoScalePolicyDaoImpl" class="com.cloud.network.as.dao.AutoScalePolicyDaoImpl" />
|
||||||
<bean id="autoScaleVmGroupDaoImpl" class="com.cloud.network.as.dao.AutoScaleVmGroupDaoImpl" />
|
<bean id="autoScaleVmGroupDaoImpl" class="com.cloud.network.as.dao.AutoScaleVmGroupDaoImpl" />
|
||||||
<bean id="autoScaleVmGroupPolicyMapDaoImpl" class="com.cloud.network.as.dao.AutoScaleVmGroupPolicyMapDaoImpl" />
|
<bean id="autoScaleVmGroupPolicyMapDaoImpl" class="com.cloud.network.as.dao.AutoScaleVmGroupPolicyMapDaoImpl" />
|
||||||
|
<bean id="autoScaleVmGroupStatisticsDaoImpl" class="com.cloud.network.as.dao.AutoScaleVmGroupStatisticsDaoImpl" />
|
||||||
<bean id="autoScaleVmGroupVmMapDaoImpl" class="com.cloud.network.as.dao.AutoScaleVmGroupVmMapDaoImpl" />
|
<bean id="autoScaleVmGroupVmMapDaoImpl" class="com.cloud.network.as.dao.AutoScaleVmGroupVmMapDaoImpl" />
|
||||||
<bean id="autoScaleVmProfileDaoImpl" class="com.cloud.network.as.dao.AutoScaleVmProfileDaoImpl" />
|
<bean id="autoScaleVmProfileDaoImpl" class="com.cloud.network.as.dao.AutoScaleVmProfileDaoImpl" />
|
||||||
<bean id="capacityDaoImpl" class="com.cloud.capacity.dao.CapacityDaoImpl" />
|
<bean id="capacityDaoImpl" class="com.cloud.capacity.dao.CapacityDaoImpl" />
|
||||||
|
|||||||
@ -252,6 +252,200 @@ FROM role_permissions role_perm
|
|||||||
INNER JOIN roles ON role_perm.role_id = roles.id
|
INNER JOIN roles ON role_perm.role_id = roles.id
|
||||||
WHERE roles.role_type != 'Admin' AND roles.is_default = 1 AND role_perm.rule = 'migrateVolume';
|
WHERE roles.role_type != 'Admin' AND roles.is_default = 1 AND role_perm.rule = 'migrateVolume';
|
||||||
|
|
||||||
|
-- VM autoscaling
|
||||||
|
|
||||||
|
-- Idempotent ADD COLUMN
|
||||||
|
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_COLUMN`;
|
||||||
|
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_COLUMN` (
|
||||||
|
IN in_table_name VARCHAR(200)
|
||||||
|
, IN in_column_name VARCHAR(200)
|
||||||
|
, IN in_column_definition VARCHAR(1000)
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
|
DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||||
|
|
||||||
|
-- Idempotent RENAME COLUMN
|
||||||
|
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_CHANGE_COLUMN`;
|
||||||
|
CREATE PROCEDURE `cloud`.`IDEMPOTENT_CHANGE_COLUMN` (
|
||||||
|
IN in_table_name VARCHAR(200)
|
||||||
|
, IN in_column_name VARCHAR(200)
|
||||||
|
, IN in_column_new_name VARCHAR(200)
|
||||||
|
, IN in_column_new_definition VARCHAR(1000)
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
|
DECLARE CONTINUE HANDLER FOR 1054 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'CHANGE COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_new_name); SET @ddl = CONCAT(@ddl, ' ', in_column_new_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||||
|
|
||||||
|
-- Idempotent ADD UNIQUE KEY
|
||||||
|
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_UNIQUE_KEY`;
|
||||||
|
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_UNIQUE_KEY` (
|
||||||
|
IN in_table_name VARCHAR(200)
|
||||||
|
, IN in_key_name VARCHAR(200)
|
||||||
|
, IN in_key_definition VARCHAR(1000)
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
|
DECLARE CONTINUE HANDLER FOR 1061 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', 'ADD UNIQUE KEY ', in_key_name); SET @ddl = CONCAT(@ddl, ' ', in_key_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||||
|
|
||||||
|
-- Idempotent DROP FOREIGN KEY
|
||||||
|
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY`;
|
||||||
|
CREATE PROCEDURE `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY` (
|
||||||
|
IN in_table_name VARCHAR(200)
|
||||||
|
, IN in_foreign_key_name VARCHAR(200)
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
|
DECLARE CONTINUE HANDLER FOR 1091, 1025 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', ' DROP FOREIGN KEY '); SET @ddl = CONCAT(@ddl, ' ', in_foreign_key_name); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
|
||||||
|
|
||||||
|
-- Add column 'supports_vm_autoscaling' to 'network_offerings' table
|
||||||
|
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.network_offerings', 'supports_vm_autoscaling', 'boolean default false');
|
||||||
|
|
||||||
|
-- Update column 'supports_vm_autoscaling' to 1 if network offerings support Lb
|
||||||
|
UPDATE `cloud`.`network_offerings`
|
||||||
|
JOIN `cloud`.`ntwk_offering_service_map`
|
||||||
|
ON network_offerings.id = ntwk_offering_service_map.network_offering_id
|
||||||
|
SET network_offerings.supports_vm_autoscaling = 1
|
||||||
|
WHERE ntwk_offering_service_map.service = 'Lb'
|
||||||
|
AND ntwk_offering_service_map.provider IN ('VirtualRouter', 'VpcVirtualRouter', 'Netscaler')
|
||||||
|
AND network_offerings.removed IS NULL;
|
||||||
|
|
||||||
|
-- Add column 'name' to 'autoscale_vmgroups' table
|
||||||
|
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.autoscale_vmgroups', 'name', 'VARCHAR(255) DEFAULT NULL COMMENT "name of the autoscale vm group" AFTER `load_balancer_id`');
|
||||||
|
UPDATE `cloud`.`autoscale_vmgroups` SET `name` = CONCAT('AutoScale-VmGroup-',id) WHERE `name` IS NULL;
|
||||||
|
|
||||||
|
-- Add column 'next_vm_seq' to 'autoscale_vmgroups' table
|
||||||
|
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.autoscale_vmgroups', 'next_vm_seq', 'BIGINT UNSIGNED NOT NULL DEFAULT 1');
|
||||||
|
|
||||||
|
-- Add column 'user_data' to 'autoscale_vmprofiles' table
|
||||||
|
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.autoscale_vmprofiles', 'user_data', 'TEXT(32768) AFTER `counter_params`');
|
||||||
|
|
||||||
|
-- Add column 'name' to 'autoscale_policies' table
|
||||||
|
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.autoscale_policies', 'name', 'VARCHAR(255) DEFAULT NULL COMMENT "name of the autoscale policy" AFTER `uuid`');
|
||||||
|
|
||||||
|
-- Add column 'provider' and update values
|
||||||
|
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.counter', 'provider', 'VARCHAR(255) NOT NULL COMMENT "Network provider name" AFTER `uuid`');
|
||||||
|
UPDATE `cloud`.`counter` SET provider = 'Netscaler' WHERE `provider` IS NULL OR `provider` = '';
|
||||||
|
|
||||||
|
CALL `cloud`.`IDEMPOTENT_ADD_UNIQUE_KEY`('cloud.counter', 'uc_counter__provider__source__value', '(provider, source, value)');
|
||||||
|
|
||||||
|
-- Add new counters for VM autoscaling
|
||||||
|
|
||||||
|
INSERT IGNORE INTO `cloud`.`counter` (uuid, provider, source, name, value, created) VALUES (UUID(), 'VirtualRouter', 'cpu', 'VM CPU - average percentage', 'vm.cpu.average.percentage', NOW());
|
||||||
|
INSERT IGNORE INTO `cloud`.`counter` (uuid, provider, source, name, value, created) VALUES (UUID(), 'VirtualRouter', 'memory', 'VM Memory - average percentage', 'vm.memory.average.percentage', NOW());
|
||||||
|
INSERT IGNORE INTO `cloud`.`counter` (uuid, provider, source, name, value, created) VALUES (UUID(), 'VirtualRouter', 'virtualrouter', 'Public Network - mbps received per vm', 'public.network.received.average.mbps', NOW());
|
||||||
|
INSERT IGNORE INTO `cloud`.`counter` (uuid, provider, source, name, value, created) VALUES (UUID(), 'VirtualRouter', 'virtualrouter', 'Public Network - mbps transmit per vm', 'public.network.transmit.average.mbps', NOW());
|
||||||
|
INSERT IGNORE INTO `cloud`.`counter` (uuid, provider, source, name, value, created) VALUES (UUID(), 'VirtualRouter', 'virtualrouter', 'Load Balancer - average connections per vm', 'virtual.network.lb.average.connections', NOW());
|
||||||
|
|
||||||
|
INSERT IGNORE INTO `cloud`.`counter` (uuid, provider, source, name, value, created) VALUES (UUID(), 'VpcVirtualRouter', 'cpu', 'VM CPU - average percentage', 'vm.cpu.average.percentage', NOW());
|
||||||
|
INSERT IGNORE INTO `cloud`.`counter` (uuid, provider, source, name, value, created) VALUES (UUID(), 'VpcVirtualRouter', 'memory', 'VM Memory - average percentage', 'vm.memory.average.percentage', NOW());
|
||||||
|
INSERT IGNORE INTO `cloud`.`counter` (uuid, provider, source, name, value, created) VALUES (UUID(), 'VpcVirtualRouter', 'virtualrouter', 'Public Network - mbps received per vm', 'public.network.received.average.mbps', NOW());
|
||||||
|
INSERT IGNORE INTO `cloud`.`counter` (uuid, provider, source, name, value, created) VALUES (UUID(), 'VpcVirtualRouter', 'virtualrouter', 'Public Network - mbps transmit per vm', 'public.network.transmit.average.mbps', NOW());
|
||||||
|
INSERT IGNORE INTO `cloud`.`counter` (uuid, provider, source, name, value, created) VALUES (UUID(), 'VpcVirtualRouter', 'virtualrouter', 'Load Balancer - average connections per vm', 'virtual.network.lb.average.connections', NOW());
|
||||||
|
|
||||||
|
INSERT IGNORE INTO `cloud`.`counter` (uuid, provider, source, name, value, created) VALUES (UUID(), 'None', 'cpu', 'VM CPU - average percentage', 'vm.cpu.average.percentage', NOW());
|
||||||
|
INSERT IGNORE INTO `cloud`.`counter` (uuid, provider, source, name, value, created) VALUES (UUID(), 'None', 'memory', 'VM Memory - average percentage', 'vm.memory.average.percentage', NOW());
|
||||||
|
|
||||||
|
-- Update autoscale_vmgroups to new state
|
||||||
|
|
||||||
|
UPDATE `cloud`.`autoscale_vmgroups` SET state= UPPER(state);
|
||||||
|
|
||||||
|
-- Update autoscale_vmgroups so records will not be removed when LB rule is removed
|
||||||
|
|
||||||
|
CALL `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY`('cloud.autoscale_vmgroups', 'fk_autoscale_vmgroup__load_balancer_id');
|
||||||
|
|
||||||
|
-- Update autoscale_vmprofiles to make autoscale_user_id optional
|
||||||
|
|
||||||
|
ALTER TABLE `cloud`.`autoscale_vmprofiles` MODIFY COLUMN `autoscale_user_id` bigint unsigned;
|
||||||
|
|
||||||
|
-- Update autoscale_vmprofiles to rename destroy_vm_grace_period
|
||||||
|
|
||||||
|
CALL `cloud`.`IDEMPOTENT_CHANGE_COLUMN`('cloud.autoscale_vmprofiles', 'destroy_vm_grace_period', 'expunge_vm_grace_period', 'int unsigned COMMENT "the time allowed for existing connections to get closed before a vm is expunged"');
|
||||||
|
|
||||||
|
-- Create table for VM autoscaling historic data
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `cloud`.`autoscale_vmgroup_statistics` (
|
||||||
|
`id` bigint unsigned NOT NULL auto_increment,
|
||||||
|
`vmgroup_id` bigint unsigned NOT NULL,
|
||||||
|
`policy_id` bigint unsigned NOT NULL,
|
||||||
|
`counter_id` bigint unsigned NOT NULL,
|
||||||
|
`resource_id` bigint unsigned DEFAULT NULL,
|
||||||
|
`resource_type` varchar(255) NOT NULL,
|
||||||
|
`raw_value` double NOT NULL,
|
||||||
|
`value_type` varchar(255) NOT NULL,
|
||||||
|
`created` datetime NOT NULL COMMENT 'Date this data is created',
|
||||||
|
`state` varchar(255) NOT NULL COMMENT 'State of the data',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
CONSTRAINT `fk_autoscale_vmgroup_statistics__vmgroup_id` FOREIGN KEY `fk_autoscale_vmgroup_statistics__vmgroup_id` (`vmgroup_id`) REFERENCES `autoscale_vmgroups` (`id`) ON DELETE CASCADE,
|
||||||
|
INDEX `i_autoscale_vmgroup_statistics__vmgroup_id`(`vmgroup_id`),
|
||||||
|
INDEX `i_autoscale_vmgroup_statistics__policy_id`(`policy_id`),
|
||||||
|
INDEX `i_autoscale_vmgroup_statistics__counter_id`(`counter_id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
|
||||||
|
-- Update Network offering view with supports_vm_autoscaling
|
||||||
|
DROP VIEW IF EXISTS `cloud`.`network_offering_view`;
|
||||||
|
CREATE VIEW `cloud`.`network_offering_view` AS
|
||||||
|
SELECT
|
||||||
|
`network_offerings`.`id` AS `id`,
|
||||||
|
`network_offerings`.`uuid` AS `uuid`,
|
||||||
|
`network_offerings`.`name` AS `name`,
|
||||||
|
`network_offerings`.`unique_name` AS `unique_name`,
|
||||||
|
`network_offerings`.`display_text` AS `display_text`,
|
||||||
|
`network_offerings`.`nw_rate` AS `nw_rate`,
|
||||||
|
`network_offerings`.`mc_rate` AS `mc_rate`,
|
||||||
|
`network_offerings`.`traffic_type` AS `traffic_type`,
|
||||||
|
`network_offerings`.`tags` AS `tags`,
|
||||||
|
`network_offerings`.`system_only` AS `system_only`,
|
||||||
|
`network_offerings`.`specify_vlan` AS `specify_vlan`,
|
||||||
|
`network_offerings`.`service_offering_id` AS `service_offering_id`,
|
||||||
|
`network_offerings`.`conserve_mode` AS `conserve_mode`,
|
||||||
|
`network_offerings`.`created` AS `created`,
|
||||||
|
`network_offerings`.`removed` AS `removed`,
|
||||||
|
`network_offerings`.`default` AS `default`,
|
||||||
|
`network_offerings`.`availability` AS `availability`,
|
||||||
|
`network_offerings`.`dedicated_lb_service` AS `dedicated_lb_service`,
|
||||||
|
`network_offerings`.`shared_source_nat_service` AS `shared_source_nat_service`,
|
||||||
|
`network_offerings`.`sort_key` AS `sort_key`,
|
||||||
|
`network_offerings`.`redundant_router_service` AS `redundant_router_service`,
|
||||||
|
`network_offerings`.`state` AS `state`,
|
||||||
|
`network_offerings`.`guest_type` AS `guest_type`,
|
||||||
|
`network_offerings`.`elastic_ip_service` AS `elastic_ip_service`,
|
||||||
|
`network_offerings`.`eip_associate_public_ip` AS `eip_associate_public_ip`,
|
||||||
|
`network_offerings`.`elastic_lb_service` AS `elastic_lb_service`,
|
||||||
|
`network_offerings`.`specify_ip_ranges` AS `specify_ip_ranges`,
|
||||||
|
`network_offerings`.`inline` AS `inline`,
|
||||||
|
`network_offerings`.`is_persistent` AS `is_persistent`,
|
||||||
|
`network_offerings`.`internal_lb` AS `internal_lb`,
|
||||||
|
`network_offerings`.`public_lb` AS `public_lb`,
|
||||||
|
`network_offerings`.`egress_default_policy` AS `egress_default_policy`,
|
||||||
|
`network_offerings`.`concurrent_connections` AS `concurrent_connections`,
|
||||||
|
`network_offerings`.`keep_alive_enabled` AS `keep_alive_enabled`,
|
||||||
|
`network_offerings`.`supports_streched_l2` AS `supports_streched_l2`,
|
||||||
|
`network_offerings`.`supports_public_access` AS `supports_public_access`,
|
||||||
|
`network_offerings`.`supports_vm_autoscaling` AS `supports_vm_autoscaling`,
|
||||||
|
`network_offerings`.`for_vpc` AS `for_vpc`,
|
||||||
|
`network_offerings`.`service_package_id` AS `service_package_id`,
|
||||||
|
GROUP_CONCAT(DISTINCT(domain.id)) AS domain_id,
|
||||||
|
GROUP_CONCAT(DISTINCT(domain.uuid)) AS domain_uuid,
|
||||||
|
GROUP_CONCAT(DISTINCT(domain.name)) AS domain_name,
|
||||||
|
GROUP_CONCAT(DISTINCT(domain.path)) AS domain_path,
|
||||||
|
GROUP_CONCAT(DISTINCT(zone.id)) AS zone_id,
|
||||||
|
GROUP_CONCAT(DISTINCT(zone.uuid)) AS zone_uuid,
|
||||||
|
GROUP_CONCAT(DISTINCT(zone.name)) AS zone_name,
|
||||||
|
`offering_details`.value AS internet_protocol
|
||||||
|
FROM
|
||||||
|
`cloud`.`network_offerings`
|
||||||
|
LEFT JOIN
|
||||||
|
`cloud`.`network_offering_details` AS `domain_details` ON `domain_details`.`network_offering_id` = `network_offerings`.`id` AND `domain_details`.`name`='domainid'
|
||||||
|
LEFT JOIN
|
||||||
|
`cloud`.`domain` AS `domain` ON FIND_IN_SET(`domain`.`id`, `domain_details`.`value`)
|
||||||
|
LEFT JOIN
|
||||||
|
`cloud`.`network_offering_details` AS `zone_details` ON `zone_details`.`network_offering_id` = `network_offerings`.`id` AND `zone_details`.`name`='zoneid'
|
||||||
|
LEFT JOIN
|
||||||
|
`cloud`.`data_center` AS `zone` ON FIND_IN_SET(`zone`.`id`, `zone_details`.`value`)
|
||||||
|
LEFT JOIN
|
||||||
|
`cloud`.`network_offering_details` AS `offering_details` ON `offering_details`.`network_offering_id` = `network_offerings`.`id` AND `offering_details`.`name`='internetProtocol'
|
||||||
|
GROUP BY
|
||||||
|
`network_offerings`.`id`;
|
||||||
|
|
||||||
|
-- UserData as first class resource (PR #6202)
|
||||||
CREATE TABLE `cloud`.`user_data` (
|
CREATE TABLE `cloud`.`user_data` (
|
||||||
`id` bigint unsigned NOT NULL auto_increment COMMENT 'id',
|
`id` bigint unsigned NOT NULL auto_increment COMMENT 'id',
|
||||||
`uuid` varchar(40) NOT NULL COMMENT 'UUID of the user data',
|
`uuid` varchar(40) NOT NULL COMMENT 'UUID of the user data',
|
||||||
@ -524,6 +718,9 @@ SELECT
|
|||||||
`affinity_group`.`uuid` AS `affinity_group_uuid`,
|
`affinity_group`.`uuid` AS `affinity_group_uuid`,
|
||||||
`affinity_group`.`name` AS `affinity_group_name`,
|
`affinity_group`.`name` AS `affinity_group_name`,
|
||||||
`affinity_group`.`description` AS `affinity_group_description`,
|
`affinity_group`.`description` AS `affinity_group_description`,
|
||||||
|
`autoscale_vmgroups`.`id` AS `autoscale_vmgroup_id`,
|
||||||
|
`autoscale_vmgroups`.`uuid` AS `autoscale_vmgroup_uuid`,
|
||||||
|
`autoscale_vmgroups`.`name` AS `autoscale_vmgroup_name`,
|
||||||
`vm_instance`.`dynamically_scalable` AS `dynamically_scalable`,
|
`vm_instance`.`dynamically_scalable` AS `dynamically_scalable`,
|
||||||
`user_data`.`id` AS `user_data_id`,
|
`user_data`.`id` AS `user_data_id`,
|
||||||
`user_data`.`uuid` AS `user_data_uuid`,
|
`user_data`.`uuid` AS `user_data_uuid`,
|
||||||
@ -531,7 +728,7 @@ SELECT
|
|||||||
`user_vm`.`user_data_details` AS `user_data_details`,
|
`user_vm`.`user_data_details` AS `user_data_details`,
|
||||||
`vm_template`.`user_data_link_policy` AS `user_data_policy`
|
`vm_template`.`user_data_link_policy` AS `user_data_policy`
|
||||||
FROM
|
FROM
|
||||||
(((((((((((((((((((((((((((((((((`user_vm`
|
(((((((((((((((((((((((((((((((((((`user_vm`
|
||||||
JOIN `vm_instance` ON (((`vm_instance`.`id` = `user_vm`.`id`)
|
JOIN `vm_instance` ON (((`vm_instance`.`id` = `user_vm`.`id`)
|
||||||
AND ISNULL(`vm_instance`.`removed`))))
|
AND ISNULL(`vm_instance`.`removed`))))
|
||||||
JOIN `account` ON ((`vm_instance`.`account_id` = `account`.`id`)))
|
JOIN `account` ON ((`vm_instance`.`account_id` = `account`.`id`)))
|
||||||
@ -569,6 +766,8 @@ FROM
|
|||||||
AND (`async_job`.`job_status` = 0))))
|
AND (`async_job`.`job_status` = 0))))
|
||||||
LEFT JOIN `affinity_group_vm_map` ON ((`vm_instance`.`id` = `affinity_group_vm_map`.`instance_id`)))
|
LEFT JOIN `affinity_group_vm_map` ON ((`vm_instance`.`id` = `affinity_group_vm_map`.`instance_id`)))
|
||||||
LEFT JOIN `affinity_group` ON ((`affinity_group_vm_map`.`affinity_group_id` = `affinity_group`.`id`)))
|
LEFT JOIN `affinity_group` ON ((`affinity_group_vm_map`.`affinity_group_id` = `affinity_group`.`id`)))
|
||||||
|
LEFT JOIN `autoscale_vmgroup_vm_map` ON ((`autoscale_vmgroup_vm_map`.`instance_id` = `vm_instance`.`id`)))
|
||||||
|
LEFT JOIN `autoscale_vmgroups` ON ((`autoscale_vmgroup_vm_map`.`vmgroup_id` = `autoscale_vmgroups`.`id`)))
|
||||||
LEFT JOIN `user_vm_details` `custom_cpu` ON (((`custom_cpu`.`vm_id` = `vm_instance`.`id`)
|
LEFT JOIN `user_vm_details` `custom_cpu` ON (((`custom_cpu`.`vm_id` = `vm_instance`.`id`)
|
||||||
AND (`custom_cpu`.`name` = 'CpuNumber'))))
|
AND (`custom_cpu`.`name` = 'CpuNumber'))))
|
||||||
LEFT JOIN `user_vm_details` `custom_speed` ON (((`custom_speed`.`vm_id` = `vm_instance`.`id`)
|
LEFT JOIN `user_vm_details` `custom_speed` ON (((`custom_speed`.`vm_id` = `vm_instance`.`id`)
|
||||||
|
|||||||
@ -0,0 +1,65 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
package com.cloud.network.as;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.cloud.utils.Pair;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class AutoScaleVmProfileVOTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCounterParamsForUpdate() {
|
||||||
|
AutoScaleVmProfileVO profile = new AutoScaleVmProfileVO();
|
||||||
|
|
||||||
|
Map<String, HashMap<String, String>> counterParamList = new HashMap<>();
|
||||||
|
counterParamList.put("0", new HashMap<>() {{ put("name", "snmpcommunity"); put("value", "public"); }});
|
||||||
|
counterParamList.put("1", new HashMap<>() {{ put("name", "snmpport"); put("value", "161"); }});
|
||||||
|
|
||||||
|
profile.setCounterParamsForUpdate(counterParamList);
|
||||||
|
Assert.assertEquals("snmpcommunity=public&snmpport=161", profile.getCounterParamsString());
|
||||||
|
|
||||||
|
List<Pair<String, String>> counterParams = profile.getCounterParams();
|
||||||
|
Assert.assertEquals(2, counterParams.size());
|
||||||
|
Assert.assertEquals("snmpcommunity", counterParams.get(0).first());
|
||||||
|
Assert.assertEquals("public", counterParams.get(0).second());
|
||||||
|
Assert.assertEquals("snmpport", counterParams.get(1).first());
|
||||||
|
Assert.assertEquals("161", counterParams.get(1).second());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void tstSetOtherDeployParamsForUpdate() {
|
||||||
|
AutoScaleVmProfileVO profile = new AutoScaleVmProfileVO();
|
||||||
|
|
||||||
|
Map<String, HashMap<String, String>> otherDeployParamsMap = new HashMap<>();
|
||||||
|
otherDeployParamsMap.put("0", new HashMap<>() {{ put("name", "serviceofferingid"); put("value", "a7fb50f6-01d9-11ed-8bc1-77f8f0228926"); }});
|
||||||
|
otherDeployParamsMap.put("1", new HashMap<>() {{ put("name", "rootdisksize"); put("value", "10"); }});
|
||||||
|
|
||||||
|
profile.setOtherDeployParamsForUpdate(otherDeployParamsMap);
|
||||||
|
|
||||||
|
List<Pair<String, String>> otherDeployParamsList = profile.getOtherDeployParamsList();
|
||||||
|
Assert.assertEquals(2, otherDeployParamsList.size());
|
||||||
|
Assert.assertEquals("serviceofferingid", otherDeployParamsList.get(0).first());
|
||||||
|
Assert.assertEquals("a7fb50f6-01d9-11ed-8bc1-77f8f0228926", otherDeployParamsList.get(0).second());
|
||||||
|
Assert.assertEquals("rootdisksize", otherDeployParamsList.get(1).first());
|
||||||
|
Assert.assertEquals("10", otherDeployParamsList.get(1).second());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,137 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cloud.network.as.dao;
|
||||||
|
|
||||||
|
import com.cloud.network.as.AutoScaleVmGroup;
|
||||||
|
import com.cloud.network.as.AutoScaleVmGroupVO;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.Spy;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
public class AutoScaleVmGroupDaoImplTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
SearchBuilder<AutoScaleVmGroupVO> searchBuilderAutoScaleVmGroupVOMock;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
SearchCriteria<AutoScaleVmGroupVO> searchCriteriaAutoScaleVmGroupVOMock;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
List<AutoScaleVmGroupVO> listAutoScaleVmGroupVOMock;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
AutoScaleVmGroupVO autoScaleVmGroupVOMock;
|
||||||
|
|
||||||
|
@Spy
|
||||||
|
AutoScaleVmGroupDaoImpl AutoScaleVmGroupDaoImplSpy = PowerMockito.spy(new AutoScaleVmGroupDaoImpl());
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
AutoScaleVmGroupDaoImplSpy.AllFieldsSearch = searchBuilderAutoScaleVmGroupVOMock;
|
||||||
|
Mockito.doReturn(searchCriteriaAutoScaleVmGroupVOMock).when(searchBuilderAutoScaleVmGroupVOMock).create();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListByLoadBalancer() throws Exception {
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupVOMock).setParameters(Mockito.anyString(), Mockito.any());
|
||||||
|
PowerMockito.doReturn(listAutoScaleVmGroupVOMock).when(AutoScaleVmGroupDaoImplSpy, "listBy", Mockito.any(SearchCriteria.class));
|
||||||
|
|
||||||
|
long loadBalancerId = 100L;
|
||||||
|
|
||||||
|
List<AutoScaleVmGroupVO> result = AutoScaleVmGroupDaoImplSpy.listByLoadBalancer(loadBalancerId);
|
||||||
|
|
||||||
|
Assert.assertEquals(listAutoScaleVmGroupVOMock, result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupVOMock).setParameters("loadBalancerId", loadBalancerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListByProfile() throws Exception {
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupVOMock).setParameters(Mockito.anyString(), Mockito.any());
|
||||||
|
PowerMockito.doReturn(listAutoScaleVmGroupVOMock).when(AutoScaleVmGroupDaoImplSpy, "listBy", Mockito.any(SearchCriteria.class));
|
||||||
|
|
||||||
|
long profileId = 101L;
|
||||||
|
|
||||||
|
List<AutoScaleVmGroupVO> result = AutoScaleVmGroupDaoImplSpy.listByProfile(profileId);
|
||||||
|
|
||||||
|
Assert.assertEquals(listAutoScaleVmGroupVOMock, result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupVOMock).setParameters("profileId", profileId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListByAccount() throws Exception {
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupVOMock).setParameters(Mockito.anyString(), Mockito.any());
|
||||||
|
PowerMockito.doReturn(listAutoScaleVmGroupVOMock).when(AutoScaleVmGroupDaoImplSpy, "listBy", Mockito.any(SearchCriteria.class));
|
||||||
|
|
||||||
|
long accountId = 102L;
|
||||||
|
|
||||||
|
List<AutoScaleVmGroupVO> result = AutoScaleVmGroupDaoImplSpy.listByAccount(accountId);
|
||||||
|
|
||||||
|
Assert.assertEquals(listAutoScaleVmGroupVOMock, result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupVOMock).setParameters("accountId", accountId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateState1() throws Exception {
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupVOMock).setParameters(Mockito.anyString(), Mockito.any());
|
||||||
|
PowerMockito.doReturn(null).when(AutoScaleVmGroupDaoImplSpy, "findOneBy", Mockito.any(SearchCriteria.class));
|
||||||
|
|
||||||
|
long groupId = 10L;
|
||||||
|
AutoScaleVmGroup.State oldState = AutoScaleVmGroup.State.ENABLED;
|
||||||
|
AutoScaleVmGroup.State newState = AutoScaleVmGroup.State.DISABLED;
|
||||||
|
|
||||||
|
boolean result = AutoScaleVmGroupDaoImplSpy.updateState(groupId, oldState, newState);
|
||||||
|
Assert.assertFalse(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateState2() throws Exception {
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupVOMock).setParameters(Mockito.anyString(), Mockito.any());
|
||||||
|
PowerMockito.doReturn(autoScaleVmGroupVOMock).when(AutoScaleVmGroupDaoImplSpy, "findOneBy", Mockito.any(SearchCriteria.class));
|
||||||
|
Mockito.doNothing().when(autoScaleVmGroupVOMock).setState(Mockito.any(AutoScaleVmGroup.State.class));
|
||||||
|
PowerMockito.doReturn(true).when(AutoScaleVmGroupDaoImplSpy).update(Mockito.anyLong(), Mockito.any(AutoScaleVmGroupVO.class));
|
||||||
|
|
||||||
|
long groupId = 10L;
|
||||||
|
AutoScaleVmGroup.State oldState = AutoScaleVmGroup.State.ENABLED;
|
||||||
|
AutoScaleVmGroup.State newState = AutoScaleVmGroup.State.DISABLED;
|
||||||
|
|
||||||
|
boolean result = AutoScaleVmGroupDaoImplSpy.updateState(groupId, oldState, newState);
|
||||||
|
Assert.assertTrue(result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupVOMock, Mockito.times(1)).setParameters("id", groupId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupVOMock, Mockito.times(1)).setParameters("state", oldState);
|
||||||
|
Mockito.verify(autoScaleVmGroupVOMock, Mockito.times(1)).setState(newState);
|
||||||
|
Mockito.verify(AutoScaleVmGroupDaoImplSpy, Mockito.times(1)).update(groupId, autoScaleVmGroupVOMock);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,247 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cloud.network.as.dao;
|
||||||
|
|
||||||
|
import com.cloud.network.as.AutoScaleVmGroupStatisticsVO;
|
||||||
|
import com.cloud.server.ResourceTag;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
public class AutoScaleVmGroupStatisticsDaoImplTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
SearchCriteria<AutoScaleVmGroupStatisticsVO> searchCriteriaAutoScaleVmGroupStatisticsVOMock;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
SearchBuilder<AutoScaleVmGroupStatisticsVO> searchBuilderAutoScaleVmGroupStatisticsVOMock;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
List<AutoScaleVmGroupStatisticsVO> listAutoScaleVmGroupStatisticsVOMock;
|
||||||
|
|
||||||
|
AutoScaleVmGroupStatisticsDaoImpl AutoScaleVmGroupStatisticsDaoImplSpy = PowerMockito.spy(new AutoScaleVmGroupStatisticsDaoImpl());
|
||||||
|
|
||||||
|
long groupId = 4L;
|
||||||
|
long policyId = 5L;
|
||||||
|
long counterId = 6L;
|
||||||
|
Date date = new Date();
|
||||||
|
AutoScaleVmGroupStatisticsVO autoScaleVmGroupStatisticsVO = new AutoScaleVmGroupStatisticsVO(groupId);
|
||||||
|
AutoScaleVmGroupStatisticsVO.State state = AutoScaleVmGroupStatisticsVO.State.INACTIVE;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
AutoScaleVmGroupStatisticsDaoImplSpy.groupAndCounterSearch = searchBuilderAutoScaleVmGroupStatisticsVOMock;
|
||||||
|
PowerMockito.doReturn(searchBuilderAutoScaleVmGroupStatisticsVOMock).when(AutoScaleVmGroupStatisticsDaoImplSpy).createSearchBuilder();
|
||||||
|
Mockito.doReturn(searchCriteriaAutoScaleVmGroupStatisticsVOMock).when(searchBuilderAutoScaleVmGroupStatisticsVOMock).create();
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters(Mockito.anyString(), Mockito.any());
|
||||||
|
|
||||||
|
PowerMockito.doReturn(listAutoScaleVmGroupStatisticsVOMock).when(AutoScaleVmGroupStatisticsDaoImplSpy, "listBy", Mockito.any(SearchCriteria.class));
|
||||||
|
|
||||||
|
PowerMockito.doReturn(autoScaleVmGroupStatisticsVO).when(AutoScaleVmGroupStatisticsDaoImplSpy).createForUpdate();
|
||||||
|
PowerMockito.doReturn(1).when(AutoScaleVmGroupStatisticsDaoImplSpy).update(Mockito.any(AutoScaleVmGroupStatisticsVO.class), Mockito.any(SearchCriteria.class));
|
||||||
|
PowerMockito.doReturn(autoScaleVmGroupStatisticsVO).when(AutoScaleVmGroupStatisticsDaoImplSpy).persist(Mockito.any(AutoScaleVmGroupStatisticsVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveByGroupId1() {
|
||||||
|
PowerMockito.doReturn(2).when(AutoScaleVmGroupStatisticsDaoImplSpy).expunge(Mockito.any(SearchCriteria.class));
|
||||||
|
boolean result = AutoScaleVmGroupStatisticsDaoImplSpy.removeByGroupId(groupId);
|
||||||
|
Assert.assertTrue(result);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveByGroupId2() {
|
||||||
|
PowerMockito.doReturn(-1).when(AutoScaleVmGroupStatisticsDaoImplSpy).expunge(Mockito.any(SearchCriteria.class));
|
||||||
|
boolean result = AutoScaleVmGroupStatisticsDaoImplSpy.removeByGroupId(groupId);
|
||||||
|
Assert.assertFalse(result);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveByGroupId3() {
|
||||||
|
PowerMockito.doReturn(-1).when(AutoScaleVmGroupStatisticsDaoImplSpy).expunge(Mockito.any(SearchCriteria.class));
|
||||||
|
boolean result = AutoScaleVmGroupStatisticsDaoImplSpy.removeByGroupId(groupId, date);
|
||||||
|
Assert.assertFalse(result);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("createdLT", date);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveByGroupAndPolicy1() {
|
||||||
|
PowerMockito.doReturn(2).when(AutoScaleVmGroupStatisticsDaoImplSpy).expunge(Mockito.any(SearchCriteria.class));
|
||||||
|
|
||||||
|
boolean result = AutoScaleVmGroupStatisticsDaoImplSpy.removeByGroupAndPolicy(groupId, policyId, null);
|
||||||
|
|
||||||
|
Assert.assertTrue(result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("policyId", policyId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock, Mockito.never()).setParameters("createdLT", date);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveByGroupAndPolicy2() {
|
||||||
|
PowerMockito.doReturn(-1).when(AutoScaleVmGroupStatisticsDaoImplSpy).expunge(Mockito.any(SearchCriteria.class));
|
||||||
|
|
||||||
|
boolean result = AutoScaleVmGroupStatisticsDaoImplSpy.removeByGroupAndPolicy(groupId, policyId, date);
|
||||||
|
|
||||||
|
Assert.assertFalse(result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("policyId", policyId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("createdLT", date);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListDummyRecordsByVmGroup1() {
|
||||||
|
List<AutoScaleVmGroupStatisticsVO> result = AutoScaleVmGroupStatisticsDaoImplSpy.listDummyRecordsByVmGroup(groupId, null);
|
||||||
|
|
||||||
|
Assert.assertEquals(listAutoScaleVmGroupStatisticsVOMock, result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("policyId", AutoScaleVmGroupStatisticsVO.DUMMY_ID);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("state", AutoScaleVmGroupStatisticsVO.State.INACTIVE);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock, Mockito.never()).setParameters(Mockito.eq("createdGT"), Mockito.any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListDummyRecordsByVmGroup2() {
|
||||||
|
List<AutoScaleVmGroupStatisticsVO> result = AutoScaleVmGroupStatisticsDaoImplSpy.listDummyRecordsByVmGroup(groupId, date);
|
||||||
|
|
||||||
|
Assert.assertEquals(listAutoScaleVmGroupStatisticsVOMock, result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("policyId", AutoScaleVmGroupStatisticsVO.DUMMY_ID);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("state", AutoScaleVmGroupStatisticsVO.State.INACTIVE);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("createdGT", date);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListInactiveByVmGroupAndPolicy1() {
|
||||||
|
List<AutoScaleVmGroupStatisticsVO> result = AutoScaleVmGroupStatisticsDaoImplSpy.listInactiveByVmGroupAndPolicy(groupId, policyId, null);
|
||||||
|
|
||||||
|
Assert.assertEquals(listAutoScaleVmGroupStatisticsVOMock, result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("policyId", policyId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("state", AutoScaleVmGroupStatisticsVO.State.INACTIVE);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock, Mockito.never()).setParameters(Mockito.eq("createdGT"), Mockito.any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListInactiveByVmGroupAndPolicy2() {
|
||||||
|
List<AutoScaleVmGroupStatisticsVO> result = AutoScaleVmGroupStatisticsDaoImplSpy.listInactiveByVmGroupAndPolicy(groupId, policyId, date);
|
||||||
|
|
||||||
|
Assert.assertEquals(listAutoScaleVmGroupStatisticsVOMock, result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("policyId", policyId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("state", AutoScaleVmGroupStatisticsVO.State.INACTIVE);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("createdGT", date);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testlistByVmGroupAndPolicyAndCounter1() {
|
||||||
|
List<AutoScaleVmGroupStatisticsVO> result = AutoScaleVmGroupStatisticsDaoImplSpy.listByVmGroupAndPolicyAndCounter(groupId, policyId, counterId, null);
|
||||||
|
|
||||||
|
Assert.assertEquals(listAutoScaleVmGroupStatisticsVOMock, result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("policyId", policyId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("state", AutoScaleVmGroupStatisticsVO.State.ACTIVE);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock, Mockito.never()).setParameters("createdGT", date);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testlistByVmGroupAndPolicyAndCounter2() {
|
||||||
|
List<AutoScaleVmGroupStatisticsVO> result = AutoScaleVmGroupStatisticsDaoImplSpy.listByVmGroupAndPolicyAndCounter(groupId, policyId, counterId, date);
|
||||||
|
|
||||||
|
Assert.assertEquals(listAutoScaleVmGroupStatisticsVOMock, result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("policyId", policyId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("state", AutoScaleVmGroupStatisticsVO.State.ACTIVE);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("createdGT", date);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateStateByGroup1() {
|
||||||
|
AutoScaleVmGroupStatisticsDaoImplSpy.updateStateByGroup(groupId, policyId, state);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("policyId", policyId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("stateNEQ", state);
|
||||||
|
Mockito.verify(AutoScaleVmGroupStatisticsDaoImplSpy).update(autoScaleVmGroupStatisticsVO, searchCriteriaAutoScaleVmGroupStatisticsVOMock);
|
||||||
|
|
||||||
|
Assert.assertEquals(state, autoScaleVmGroupStatisticsVO.getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateStateByGroup2() {
|
||||||
|
AutoScaleVmGroupStatisticsDaoImplSpy.updateStateByGroup(null, null, state);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock, Mockito.never()).setParameters("vmGroupId", groupId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock, Mockito.never()).setParameters("policyId", policyId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupStatisticsVOMock).setParameters("stateNEQ", state);
|
||||||
|
Mockito.verify(AutoScaleVmGroupStatisticsDaoImplSpy).update(autoScaleVmGroupStatisticsVO, searchCriteriaAutoScaleVmGroupStatisticsVOMock);
|
||||||
|
|
||||||
|
Assert.assertEquals(state, autoScaleVmGroupStatisticsVO.getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateInactiveDummyRecord() {
|
||||||
|
AutoScaleVmGroupStatisticsVO result = AutoScaleVmGroupStatisticsDaoImplSpy.createInactiveDummyRecord(groupId);
|
||||||
|
|
||||||
|
Assert.assertEquals(groupId, result.getVmGroupId());
|
||||||
|
Assert.assertEquals(AutoScaleVmGroupStatisticsVO.DUMMY_ID, result.getPolicyId());
|
||||||
|
Assert.assertEquals(AutoScaleVmGroupStatisticsVO.DUMMY_ID, result.getCounterId());
|
||||||
|
Assert.assertEquals(groupId, (long) result.getResourceId());
|
||||||
|
Assert.assertEquals(ResourceTag.ResourceObjectType.AutoScaleVmGroup, result.getResourceType());
|
||||||
|
Assert.assertEquals(AutoScaleVmGroupStatisticsVO.INVALID_VALUE, result.getRawValue(), 0);
|
||||||
|
Assert.assertEquals(AutoScaleVmGroupStatisticsVO.State.INACTIVE, result.getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInit() {
|
||||||
|
Mockito.when(searchBuilderAutoScaleVmGroupStatisticsVOMock.entity()).thenReturn(autoScaleVmGroupStatisticsVO);
|
||||||
|
|
||||||
|
AutoScaleVmGroupStatisticsDaoImplSpy.init();
|
||||||
|
|
||||||
|
Mockito.verify(searchBuilderAutoScaleVmGroupStatisticsVOMock, Mockito.times(4)).and(Mockito.anyString(), Mockito.any(), Mockito.eq(SearchCriteria.Op.EQ));
|
||||||
|
Mockito.verify(searchBuilderAutoScaleVmGroupStatisticsVOMock, Mockito.times(1)).and(Mockito.anyString(), Mockito.any(), Mockito.eq(SearchCriteria.Op.LT));
|
||||||
|
Mockito.verify(searchBuilderAutoScaleVmGroupStatisticsVOMock, Mockito.times(1)).and(Mockito.anyString(), Mockito.any(), Mockito.eq(SearchCriteria.Op.GT));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,204 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cloud.network.as.dao;
|
||||||
|
|
||||||
|
import com.cloud.network.as.AutoScaleVmGroupVmMapVO;
|
||||||
|
import com.cloud.utils.db.GenericSearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.vm.VirtualMachine;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.Spy;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
public class AutoScaleVmGroupVmMapDaoImplTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
SearchBuilder<AutoScaleVmGroupVmMapVO> searchBuilderAutoScaleVmGroupVmMapVOMock;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
SearchCriteria<AutoScaleVmGroupVmMapVO> searchCriteriaAutoScaleVmGroupVmMapVOMock;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
List<AutoScaleVmGroupVmMapVO> listAutoScaleVmGroupVmMapVOMock;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
GenericSearchBuilder<AutoScaleVmGroupVmMapVO, Integer> searchBuilderCountAvailableVmsByGroup;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
SearchCriteria<Integer> searchCriteriaCountAvailableVmsByGroup;
|
||||||
|
|
||||||
|
@Spy
|
||||||
|
AutoScaleVmGroupVmMapDaoImpl AutoScaleVmGroupVmMapDaoImplSpy = PowerMockito.spy(new AutoScaleVmGroupVmMapDaoImpl());
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
AutoScaleVmGroupVmMapDaoImplSpy.AllFieldsSearch = searchBuilderAutoScaleVmGroupVmMapVOMock;
|
||||||
|
AutoScaleVmGroupVmMapDaoImplSpy.CountBy = searchBuilderCountAvailableVmsByGroup;
|
||||||
|
Mockito.doReturn(searchCriteriaAutoScaleVmGroupVmMapVOMock).when(searchBuilderAutoScaleVmGroupVmMapVOMock).create();
|
||||||
|
Mockito.doReturn(searchCriteriaCountAvailableVmsByGroup).when(searchBuilderCountAvailableVmsByGroup).create();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCountAvailableVmsByGroup() throws Exception {
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters(Mockito.anyString(), Mockito.any());
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupVmMapVOMock).setJoinParameters(Mockito.anyString(), Mockito.anyString(), Mockito.any());
|
||||||
|
PowerMockito.doReturn(Arrays.asList(5)).when(AutoScaleVmGroupVmMapDaoImplSpy).customSearch(Mockito.any(SearchCriteria.class), Mockito.eq(null));
|
||||||
|
|
||||||
|
long groupId = 4L;
|
||||||
|
|
||||||
|
int result = AutoScaleVmGroupVmMapDaoImplSpy.countAvailableVmsByGroup(groupId);
|
||||||
|
|
||||||
|
Assert.assertEquals(5, result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaCountAvailableVmsByGroup).setParameters("vmGroupId", groupId);
|
||||||
|
Mockito.verify(searchCriteriaCountAvailableVmsByGroup).setJoinParameters("vmSearch", "states", new Object[] {VirtualMachine.State.Starting, VirtualMachine.State.Running, VirtualMachine.State.Stopping, VirtualMachine.State.Migrating});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCountByGroup() throws Exception {
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters(Mockito.anyString(), Mockito.any());
|
||||||
|
PowerMockito.doReturn(6).when(AutoScaleVmGroupVmMapDaoImplSpy, "getCountIncludingRemoved", Mockito.any(SearchCriteria.class));
|
||||||
|
|
||||||
|
long groupId = 4L;
|
||||||
|
|
||||||
|
int result = AutoScaleVmGroupVmMapDaoImplSpy.countByGroup(groupId);
|
||||||
|
|
||||||
|
Assert.assertEquals(6, result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListByGroup() throws Exception {
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters(Mockito.anyString(), Mockito.any());
|
||||||
|
PowerMockito.doReturn(listAutoScaleVmGroupVmMapVOMock).when(AutoScaleVmGroupVmMapDaoImplSpy, "listBy", Mockito.any(SearchCriteria.class));
|
||||||
|
|
||||||
|
long groupId = 4L;
|
||||||
|
|
||||||
|
List<AutoScaleVmGroupVmMapVO> result = AutoScaleVmGroupVmMapDaoImplSpy.listByGroup(groupId);
|
||||||
|
|
||||||
|
Assert.assertEquals(listAutoScaleVmGroupVmMapVOMock, result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListByVm() throws Exception {
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters(Mockito.anyString(), Mockito.any());
|
||||||
|
PowerMockito.doReturn(listAutoScaleVmGroupVmMapVOMock).when(AutoScaleVmGroupVmMapDaoImplSpy, "listBy", Mockito.any(SearchCriteria.class));
|
||||||
|
|
||||||
|
long vmId = 100L;
|
||||||
|
|
||||||
|
List<AutoScaleVmGroupVmMapVO> result = AutoScaleVmGroupVmMapDaoImplSpy.listByVm(vmId);
|
||||||
|
|
||||||
|
Assert.assertEquals(listAutoScaleVmGroupVmMapVOMock, result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters("instanceId", vmId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveByVm() {
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters(Mockito.anyString(), Mockito.any());
|
||||||
|
PowerMockito.doReturn(2).when(AutoScaleVmGroupVmMapDaoImplSpy).remove(Mockito.any(SearchCriteria.class));
|
||||||
|
|
||||||
|
long vmId = 3L;
|
||||||
|
|
||||||
|
boolean result = AutoScaleVmGroupVmMapDaoImplSpy.removeByVm(vmId);
|
||||||
|
|
||||||
|
Assert.assertTrue(result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters("instanceId", vmId);
|
||||||
|
Mockito.verify(AutoScaleVmGroupVmMapDaoImplSpy).remove(searchCriteriaAutoScaleVmGroupVmMapVOMock);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveByGroup() {
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters(Mockito.anyString(), Mockito.any());
|
||||||
|
PowerMockito.doReturn(2).when(AutoScaleVmGroupVmMapDaoImplSpy).remove(Mockito.any(SearchCriteria.class));
|
||||||
|
|
||||||
|
long groupId = 4L;
|
||||||
|
|
||||||
|
boolean result = AutoScaleVmGroupVmMapDaoImplSpy.removeByGroup(groupId);
|
||||||
|
|
||||||
|
Assert.assertTrue(result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
Mockito.verify(AutoScaleVmGroupVmMapDaoImplSpy).remove(searchCriteriaAutoScaleVmGroupVmMapVOMock);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveByGroupAndVm() {
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters(Mockito.anyString(), Mockito.any());
|
||||||
|
PowerMockito.doReturn(2).when(AutoScaleVmGroupVmMapDaoImplSpy).remove(Mockito.any(SearchCriteria.class));
|
||||||
|
|
||||||
|
long vmId = 3L;
|
||||||
|
long groupId = 4L;
|
||||||
|
|
||||||
|
int result = AutoScaleVmGroupVmMapDaoImplSpy.remove(groupId, vmId);
|
||||||
|
|
||||||
|
Assert.assertEquals(2, result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters("instanceId", vmId);
|
||||||
|
Mockito.verify(AutoScaleVmGroupVmMapDaoImplSpy).remove(searchCriteriaAutoScaleVmGroupVmMapVOMock);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveByVmFailed() {
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters(Mockito.anyString(), Mockito.any());
|
||||||
|
PowerMockito.doReturn(-1).when(AutoScaleVmGroupVmMapDaoImplSpy).remove(Mockito.any(SearchCriteria.class));
|
||||||
|
|
||||||
|
long vmId = 3L;
|
||||||
|
|
||||||
|
boolean result = AutoScaleVmGroupVmMapDaoImplSpy.removeByVm(vmId);
|
||||||
|
|
||||||
|
Assert.assertFalse(result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters("instanceId", vmId);
|
||||||
|
Mockito.verify(AutoScaleVmGroupVmMapDaoImplSpy).remove(searchCriteriaAutoScaleVmGroupVmMapVOMock);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveByGroupFailed() {
|
||||||
|
Mockito.doNothing().when(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters(Mockito.anyString(), Mockito.any());
|
||||||
|
PowerMockito.doReturn(-1).when(AutoScaleVmGroupVmMapDaoImplSpy).remove(Mockito.any(SearchCriteria.class));
|
||||||
|
|
||||||
|
long groupId = 4L;
|
||||||
|
|
||||||
|
boolean result = AutoScaleVmGroupVmMapDaoImplSpy.removeByGroup(groupId);
|
||||||
|
|
||||||
|
Assert.assertFalse(result);
|
||||||
|
|
||||||
|
Mockito.verify(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters("vmGroupId", groupId);
|
||||||
|
Mockito.verify(AutoScaleVmGroupVmMapDaoImplSpy).remove(searchCriteriaAutoScaleVmGroupVmMapVOMock);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2346,11 +2346,18 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String networkUsage(final String privateIpAddress, final String option, final String vif) {
|
public String networkUsage(final String privateIpAddress, final String option, final String vif) {
|
||||||
|
return networkUsage(privateIpAddress, option, vif, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String networkUsage(final String privateIpAddress, final String option, final String vif, String publicIp) {
|
||||||
final Script getUsage = new Script(_routerProxyPath, s_logger);
|
final Script getUsage = new Script(_routerProxyPath, s_logger);
|
||||||
getUsage.add("netusage.sh");
|
getUsage.add("netusage.sh");
|
||||||
getUsage.add(privateIpAddress);
|
getUsage.add(privateIpAddress);
|
||||||
if (option.equals("get")) {
|
if (option.equals("get")) {
|
||||||
getUsage.add("-g");
|
getUsage.add("-g");
|
||||||
|
if (StringUtils.isNotEmpty(publicIp)) {
|
||||||
|
getUsage.add("-l", publicIp);
|
||||||
|
}
|
||||||
} else if (option.equals("create")) {
|
} else if (option.equals("create")) {
|
||||||
getUsage.add("-c");
|
getUsage.add("-c");
|
||||||
} else if (option.equals("reset")) {
|
} else if (option.equals("reset")) {
|
||||||
@ -2371,7 +2378,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||||||
}
|
}
|
||||||
|
|
||||||
public long[] getNetworkStats(final String privateIP) {
|
public long[] getNetworkStats(final String privateIP) {
|
||||||
final String result = networkUsage(privateIP, "get", null);
|
return getNetworkStats(privateIP, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long[] getNetworkStats(final String privateIP, String publicIp) {
|
||||||
|
final String result = networkUsage(privateIP, "get", null, publicIp);
|
||||||
final long[] stats = new long[2];
|
final long[] stats = new long[2];
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
final String[] splitResult = result.split(":");
|
final String[] splitResult = result.split(":");
|
||||||
@ -2384,6 +2395,32 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getHaproxyStats(final String privateIP, final String publicIp, final Integer port) {
|
||||||
|
final Script getHaproxyStatsScript = new Script(_routerProxyPath, s_logger);
|
||||||
|
getHaproxyStatsScript.add("get_haproxy_stats.sh");
|
||||||
|
getHaproxyStatsScript.add(privateIP);
|
||||||
|
getHaproxyStatsScript.add(publicIp);
|
||||||
|
getHaproxyStatsScript.add(String.valueOf(port));
|
||||||
|
|
||||||
|
final OutputInterpreter.OneLineParser statsParser = new OutputInterpreter.OneLineParser();
|
||||||
|
final String result = getHaproxyStatsScript.execute(statsParser);
|
||||||
|
if (result != null) {
|
||||||
|
s_logger.debug("Failed to execute haproxy stats:" + result);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return statsParser.getLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long[] getNetworkLbStats(final String privateIp, final String publicIp, final Integer port) {
|
||||||
|
final String result = getHaproxyStats(privateIp, publicIp, port);
|
||||||
|
final long[] stats = new long[1];
|
||||||
|
if (result != null) {
|
||||||
|
final String[] splitResult = result.split(",");
|
||||||
|
stats[0] += Long.parseLong(splitResult[0]);
|
||||||
|
}
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
|
||||||
public String configureVPCNetworkUsage(final String privateIpAddress, final String publicIp, final String option, final String vpcCIDR) {
|
public String configureVPCNetworkUsage(final String privateIpAddress, final String publicIp, final String option, final String vpcCIDR) {
|
||||||
final Script getUsage = new Script(_routerProxyPath, s_logger);
|
final Script getUsage = new Script(_routerProxyPath, s_logger);
|
||||||
getUsage.add("vpc_netusage.sh");
|
getUsage.add("vpc_netusage.sh");
|
||||||
|
|||||||
@ -0,0 +1,76 @@
|
|||||||
|
//
|
||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
//
|
||||||
|
|
||||||
|
package com.cloud.hypervisor.kvm.resource.wrapper;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.Answer;
|
||||||
|
import com.cloud.agent.api.routing.GetAutoScaleMetricsAnswer;
|
||||||
|
import com.cloud.agent.api.routing.GetAutoScaleMetricsCommand;
|
||||||
|
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleMetrics;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleMetricsValue;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleValueType;
|
||||||
|
import com.cloud.resource.CommandWrapper;
|
||||||
|
import com.cloud.resource.ResourceWrapper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@ResourceWrapper(handles = GetAutoScaleMetricsCommand.class)
|
||||||
|
public class LibvirtGetAutoScaleMetricsCommandWrapper extends CommandWrapper<GetAutoScaleMetricsCommand, Answer, LibvirtComputingResource> {
|
||||||
|
|
||||||
|
static final String NETWORK_USAGE_GET_OPTION = "get";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Answer execute(final GetAutoScaleMetricsCommand command, final LibvirtComputingResource libvirtComputingResource) {
|
||||||
|
|
||||||
|
Long bytesSent;
|
||||||
|
Long bytesReceived;
|
||||||
|
if (command.isForVpc()) {
|
||||||
|
final long[] stats = libvirtComputingResource.getVPCNetworkStats(command.getPrivateIP(), command.getPublicIP(), NETWORK_USAGE_GET_OPTION);
|
||||||
|
bytesSent = stats[0];
|
||||||
|
bytesReceived = stats[1];
|
||||||
|
} else {
|
||||||
|
final long [] stats = libvirtComputingResource.getNetworkStats(command.getPrivateIP(), command.getPublicIP());
|
||||||
|
bytesSent = stats[0];
|
||||||
|
bytesReceived = stats[1];
|
||||||
|
}
|
||||||
|
final long [] lbStats = libvirtComputingResource.getNetworkLbStats(command.getPrivateIP(), command.getPublicIP(), command.getPort());
|
||||||
|
final long lbConnections = lbStats[0];
|
||||||
|
|
||||||
|
List<AutoScaleMetricsValue> values = new ArrayList<>();
|
||||||
|
|
||||||
|
for (AutoScaleMetrics metrics : command.getMetrics()) {
|
||||||
|
switch (metrics.getCounter()) {
|
||||||
|
case NETWORK_RECEIVED_AVERAGE_MBPS:
|
||||||
|
values.add(new AutoScaleMetricsValue(metrics, AutoScaleValueType.AGGREGATED_VM_GROUP, Double.valueOf(bytesReceived) / VirtualRouterAutoScale.MBITS_TO_BYTES));
|
||||||
|
break;
|
||||||
|
case NETWORK_TRANSMIT_AVERAGE_MBPS:
|
||||||
|
values.add(new AutoScaleMetricsValue(metrics, AutoScaleValueType.AGGREGATED_VM_GROUP, Double.valueOf(bytesSent) / VirtualRouterAutoScale.MBITS_TO_BYTES));
|
||||||
|
break;
|
||||||
|
case LB_AVERAGE_CONNECTIONS:
|
||||||
|
values.add(new AutoScaleMetricsValue(metrics, AutoScaleValueType.INSTANT_VM, Double.valueOf(lbConnections)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GetAutoScaleMetricsAnswer(command, true, values);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -19,13 +19,16 @@
|
|||||||
|
|
||||||
package com.cloud.hypervisor.kvm.resource;
|
package com.cloud.hypervisor.kvm.resource;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.ArgumentMatchers.nullable;
|
import static org.mockito.ArgumentMatchers.nullable;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
@ -54,7 +57,6 @@ import javax.xml.xpath.XPathConstants;
|
|||||||
import javax.xml.xpath.XPathExpressionException;
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
import javax.xml.xpath.XPathFactory;
|
import javax.xml.xpath.XPathFactory;
|
||||||
|
|
||||||
import com.cloud.utils.ssh.SshHelper;
|
|
||||||
import org.apache.cloudstack.storage.command.AttachAnswer;
|
import org.apache.cloudstack.storage.command.AttachAnswer;
|
||||||
import org.apache.cloudstack.storage.command.AttachCommand;
|
import org.apache.cloudstack.storage.command.AttachCommand;
|
||||||
import org.apache.cloudstack.utils.bytescale.ByteScaleUtils;
|
import org.apache.cloudstack.utils.bytescale.ByteScaleUtils;
|
||||||
@ -212,6 +214,8 @@ import com.cloud.template.VirtualMachineTemplate.BootloaderType;
|
|||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import com.cloud.utils.script.Script;
|
import com.cloud.utils.script.Script;
|
||||||
|
import com.cloud.utils.script.OutputInterpreter.OneLineParser;
|
||||||
|
import com.cloud.utils.ssh.SshHelper;
|
||||||
import com.cloud.vm.DiskProfile;
|
import com.cloud.vm.DiskProfile;
|
||||||
import com.cloud.vm.VirtualMachine;
|
import com.cloud.vm.VirtualMachine;
|
||||||
import com.cloud.vm.VirtualMachine.PowerState;
|
import com.cloud.vm.VirtualMachine.PowerState;
|
||||||
@ -236,7 +240,7 @@ public class LibvirtComputingResourceTest {
|
|||||||
LibvirtDomainXMLParser parserMock;
|
LibvirtDomainXMLParser parserMock;
|
||||||
|
|
||||||
@Spy
|
@Spy
|
||||||
private LibvirtComputingResource libvirtComputingResourceSpy = Mockito.spy(LibvirtComputingResource.class);
|
private LibvirtComputingResource libvirtComputingResourceSpy = Mockito.spy(new LibvirtComputingResource());
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
Domain domainMock;
|
Domain domainMock;
|
||||||
@ -254,6 +258,17 @@ public class LibvirtComputingResourceTest {
|
|||||||
"Active: 4260808 kB\n" +
|
"Active: 4260808 kB\n" +
|
||||||
"Inactive: 949392 kB\n";
|
"Inactive: 949392 kB\n";
|
||||||
|
|
||||||
|
final static long[] defaultStats = new long[2];
|
||||||
|
final static long[] vpcStats = { 1L, 2L };
|
||||||
|
final static long[] networkStats = { 3L, 4L };
|
||||||
|
final static long[] lbStats = { 5L };
|
||||||
|
final static String privateIp = "192.168.1.1";
|
||||||
|
final static String publicIp = "10.10.10.10";
|
||||||
|
final static Integer port = 8080;
|
||||||
|
|
||||||
|
final Script scriptMock = Mockito.mock(Script.class);
|
||||||
|
final OneLineParser statsParserMock = Mockito.mock(OneLineParser.class);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
libvirtComputingResourceSpy._qemuSocketsPath = new File("/var/run/qemu");
|
libvirtComputingResourceSpy._qemuSocketsPath = new File("/var/run/qemu");
|
||||||
@ -5942,6 +5957,114 @@ public class LibvirtComputingResourceTest {
|
|||||||
configLocalStorageTests(params);
|
configLocalStorageTests(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetNetworkStats() {
|
||||||
|
doReturn(networkStats[0] + ":" + networkStats[1]).when(libvirtComputingResourceSpy).networkUsage(privateIp, "get", null, publicIp);
|
||||||
|
doReturn(defaultStats[0] + ":" + defaultStats[1]).when(libvirtComputingResourceSpy).networkUsage(privateIp, "get", null, null);
|
||||||
|
|
||||||
|
long[] stats = libvirtComputingResourceSpy.getNetworkStats(privateIp, publicIp);
|
||||||
|
assertEquals(2, stats.length);
|
||||||
|
assertEquals(networkStats[0], stats[0]);
|
||||||
|
assertEquals(networkStats[1], stats[1]);
|
||||||
|
|
||||||
|
stats = libvirtComputingResourceSpy.getNetworkStats(privateIp);
|
||||||
|
assertEquals(2, stats.length);
|
||||||
|
Assert.assertEquals(0, stats[0]);
|
||||||
|
Assert.assertEquals(0, stats[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetVPCNetworkStats() {
|
||||||
|
doReturn(vpcStats[0] + ":" + vpcStats[1]).when(libvirtComputingResourceSpy).configureVPCNetworkUsage(privateIp, publicIp, "get", null);
|
||||||
|
doReturn(defaultStats[0] + ":" + defaultStats[1]).when(libvirtComputingResourceSpy).configureVPCNetworkUsage(privateIp, null, "get", null);
|
||||||
|
|
||||||
|
long[] stats = libvirtComputingResourceSpy.getVPCNetworkStats(privateIp, publicIp, "get");
|
||||||
|
assertEquals(2, stats.length);
|
||||||
|
assertEquals(vpcStats[0], stats[0]);
|
||||||
|
assertEquals(vpcStats[1], stats[1]);
|
||||||
|
|
||||||
|
stats = libvirtComputingResourceSpy.getVPCNetworkStats(privateIp, null, "get");
|
||||||
|
assertEquals(2, stats.length);
|
||||||
|
Assert.assertEquals(0, stats[0]);
|
||||||
|
Assert.assertEquals(0, stats[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetHaproxyStats() {
|
||||||
|
doReturn(lbStats[0] + "").when(libvirtComputingResourceSpy).getHaproxyStats(privateIp, publicIp, port);
|
||||||
|
long[] stats = libvirtComputingResourceSpy.getNetworkLbStats(privateIp, publicIp, port);
|
||||||
|
assertEquals(1, stats.length);
|
||||||
|
assertEquals(lbStats[0], stats[0]);
|
||||||
|
|
||||||
|
doReturn("0").when(libvirtComputingResourceSpy).getHaproxyStats(privateIp, publicIp, port);
|
||||||
|
stats = libvirtComputingResourceSpy.getNetworkLbStats(privateIp, publicIp, port);
|
||||||
|
assertEquals(1, stats.length);
|
||||||
|
Assert.assertEquals(0, stats[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@PrepareForTest(value = {LibvirtComputingResource.class})
|
||||||
|
public void testGetHaproxyStatsMethod() throws Exception {
|
||||||
|
PowerMockito.whenNew(Script.class).withAnyArguments().thenReturn(scriptMock);
|
||||||
|
doNothing().when(scriptMock).add(Mockito.anyString());
|
||||||
|
when(scriptMock.execute()).thenReturn(null);
|
||||||
|
when(scriptMock.execute(Mockito.any())).thenReturn(null);
|
||||||
|
|
||||||
|
PowerMockito.whenNew(OneLineParser.class).withNoArguments().thenReturn(statsParserMock);
|
||||||
|
when(statsParserMock.getLine()).thenReturn("result");
|
||||||
|
|
||||||
|
String result = libvirtComputingResourceSpy.getHaproxyStats(privateIp, publicIp, port);
|
||||||
|
|
||||||
|
Assert.assertEquals("result", result);
|
||||||
|
verify(scriptMock, times(4)).add(anyString());
|
||||||
|
verify(scriptMock).add("get_haproxy_stats.sh");
|
||||||
|
verify(scriptMock).add(privateIp);
|
||||||
|
verify(scriptMock).add(publicIp);
|
||||||
|
verify(scriptMock).add(String.valueOf(port));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@PrepareForTest(value = {LibvirtComputingResource.class})
|
||||||
|
public void testNetworkUsageMethod1() throws Exception {
|
||||||
|
PowerMockito.whenNew(Script.class).withAnyArguments().thenReturn(scriptMock);
|
||||||
|
doNothing().when(scriptMock).add(Mockito.anyString());
|
||||||
|
when(scriptMock.execute()).thenReturn(null);
|
||||||
|
when(scriptMock.execute(Mockito.any())).thenReturn(null);
|
||||||
|
|
||||||
|
PowerMockito.whenNew(OneLineParser.class).withNoArguments().thenReturn(statsParserMock);
|
||||||
|
when(statsParserMock.getLine()).thenReturn("result");
|
||||||
|
|
||||||
|
String result = libvirtComputingResourceSpy.networkUsage(privateIp, "get", "eth0", publicIp);
|
||||||
|
|
||||||
|
Assert.assertEquals("result", result);
|
||||||
|
verify(scriptMock, times(3)).add(anyString());
|
||||||
|
verify(scriptMock).add("netusage.sh");
|
||||||
|
verify(scriptMock).add(privateIp);
|
||||||
|
verify(scriptMock).add("-g");
|
||||||
|
|
||||||
|
verify(scriptMock).add("-l", publicIp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@PrepareForTest(value = {LibvirtComputingResource.class})
|
||||||
|
public void testNetworkUsageMethod2() throws Exception {
|
||||||
|
PowerMockito.whenNew(Script.class).withAnyArguments().thenReturn(scriptMock);
|
||||||
|
doNothing().when(scriptMock).add(Mockito.anyString());
|
||||||
|
when(scriptMock.execute()).thenReturn(null);
|
||||||
|
when(scriptMock.execute(Mockito.any())).thenReturn(null);
|
||||||
|
|
||||||
|
PowerMockito.whenNew(OneLineParser.class).withNoArguments().thenReturn(statsParserMock);
|
||||||
|
when(statsParserMock.getLine()).thenReturn("result");
|
||||||
|
|
||||||
|
String result = libvirtComputingResourceSpy.networkUsage(privateIp, "get", "eth0", null);
|
||||||
|
|
||||||
|
Assert.assertEquals("result", result);
|
||||||
|
verify(scriptMock, times(3)).add(anyString());
|
||||||
|
verify(scriptMock).add("netusage.sh");
|
||||||
|
verify(scriptMock).add(privateIp);
|
||||||
|
verify(scriptMock).add("-g");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getVmsToSetMemoryBalloonStatsPeriodTestLibvirtError() throws LibvirtException {
|
public void getVmsToSetMemoryBalloonStatsPeriodTestLibvirtError() throws LibvirtException {
|
||||||
Mockito.when(connMock.listDomains()).thenThrow(LibvirtException.class);
|
Mockito.when(connMock.listDomains()).thenThrow(LibvirtException.class);
|
||||||
|
|||||||
@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cloud.hypervisor.kvm.resource.wrapper;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.Answer;
|
||||||
|
import com.cloud.agent.api.routing.GetAutoScaleMetricsAnswer;
|
||||||
|
import com.cloud.agent.api.routing.GetAutoScaleMetricsCommand;
|
||||||
|
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleMetrics;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleMetricsValue;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.VirtualRouterAutoScaleCounter;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.Spy;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
public class LibvirtGetAutoScaleMetricsCommandWrapperTest {
|
||||||
|
|
||||||
|
@Spy
|
||||||
|
LibvirtGetAutoScaleMetricsCommandWrapper libvirtGetAutoScaleMetricsCommandWrapperSpy = Mockito.spy(LibvirtGetAutoScaleMetricsCommandWrapper.class);
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
LibvirtComputingResource libvirtComputingResourceMock;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
GetAutoScaleMetricsCommand getAutoScaleMetricsCommandMock;
|
||||||
|
|
||||||
|
final static long[] vpcStats = { 1000L, 2000L };
|
||||||
|
final static long[] networkStats = { 3000L, 4000L };
|
||||||
|
final static long[] lbStats = { 5L };
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init() {
|
||||||
|
List<AutoScaleMetrics> metrics = new ArrayList<>();
|
||||||
|
metrics.add(new AutoScaleMetrics(VirtualRouterAutoScaleCounter.LB_AVERAGE_CONNECTIONS, 1L, 2L, 3L, 4));
|
||||||
|
metrics.add(new AutoScaleMetrics(VirtualRouterAutoScaleCounter.NETWORK_RECEIVED_AVERAGE_MBPS, 1L, 2L, 3L, 4));
|
||||||
|
metrics.add(new AutoScaleMetrics(VirtualRouterAutoScaleCounter.NETWORK_TRANSMIT_AVERAGE_MBPS, 1L, 2L, 3L, 4));
|
||||||
|
|
||||||
|
Mockito.when(getAutoScaleMetricsCommandMock.getMetrics()).thenReturn(metrics);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void validateVpcStats() {
|
||||||
|
|
||||||
|
Mockito.when(getAutoScaleMetricsCommandMock.isForVpc()).thenReturn(true);
|
||||||
|
PowerMockito.when(libvirtComputingResourceMock.getVPCNetworkStats(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(vpcStats);
|
||||||
|
PowerMockito.when(libvirtComputingResourceMock.getNetworkLbStats(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(lbStats);
|
||||||
|
|
||||||
|
Answer answer = libvirtGetAutoScaleMetricsCommandWrapperSpy.execute(getAutoScaleMetricsCommandMock, libvirtComputingResourceMock);
|
||||||
|
assertTrue(answer instanceof GetAutoScaleMetricsAnswer);
|
||||||
|
|
||||||
|
GetAutoScaleMetricsAnswer getAutoScaleMetricsAnswer = (GetAutoScaleMetricsAnswer) answer;
|
||||||
|
List<AutoScaleMetricsValue> values = getAutoScaleMetricsAnswer.getValues();
|
||||||
|
|
||||||
|
assertEquals(3, values.size());
|
||||||
|
for (AutoScaleMetricsValue value : values) {
|
||||||
|
if (value.getMetrics().getCounter().equals(VirtualRouterAutoScaleCounter.LB_AVERAGE_CONNECTIONS)) {
|
||||||
|
assertEquals(Double.valueOf(lbStats[0]), value.getValue());
|
||||||
|
} else if (value.getMetrics().getCounter().equals(VirtualRouterAutoScaleCounter.NETWORK_TRANSMIT_AVERAGE_MBPS)) {
|
||||||
|
assertEquals(Double.valueOf(Double.valueOf(vpcStats[0]) / VirtualRouterAutoScale.MBITS_TO_BYTES), value.getValue());
|
||||||
|
} else if (value.getMetrics().getCounter().equals(VirtualRouterAutoScaleCounter.NETWORK_RECEIVED_AVERAGE_MBPS)) {
|
||||||
|
assertEquals(Double.valueOf(Double.valueOf(vpcStats[1]) / VirtualRouterAutoScale.MBITS_TO_BYTES), value.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Mockito.verify(libvirtComputingResourceMock, Mockito.never()).getNetworkStats(Mockito.any(), Mockito.any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void validateNetworkStats() {
|
||||||
|
|
||||||
|
Mockito.when(getAutoScaleMetricsCommandMock.isForVpc()).thenReturn(false);
|
||||||
|
PowerMockito.when(libvirtComputingResourceMock.getNetworkStats(Mockito.any(), Mockito.any())).thenReturn(networkStats);
|
||||||
|
PowerMockito.when(libvirtComputingResourceMock.getNetworkLbStats(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(lbStats);
|
||||||
|
|
||||||
|
Answer answer = libvirtGetAutoScaleMetricsCommandWrapperSpy.execute(getAutoScaleMetricsCommandMock, libvirtComputingResourceMock);
|
||||||
|
assertTrue(answer instanceof GetAutoScaleMetricsAnswer);
|
||||||
|
|
||||||
|
GetAutoScaleMetricsAnswer getAutoScaleMetricsAnswer = (GetAutoScaleMetricsAnswer) answer;
|
||||||
|
List<AutoScaleMetricsValue> values = getAutoScaleMetricsAnswer.getValues();
|
||||||
|
|
||||||
|
assertEquals(3, values.size());
|
||||||
|
for (AutoScaleMetricsValue value : values) {
|
||||||
|
if (value.getMetrics().getCounter().equals(VirtualRouterAutoScaleCounter.LB_AVERAGE_CONNECTIONS)) {
|
||||||
|
assertEquals(Double.valueOf(lbStats[0]), value.getValue());
|
||||||
|
} else if (value.getMetrics().getCounter().equals(VirtualRouterAutoScaleCounter.NETWORK_TRANSMIT_AVERAGE_MBPS)) {
|
||||||
|
assertEquals(Double.valueOf(Double.valueOf(networkStats[0]) / VirtualRouterAutoScale.MBITS_TO_BYTES), value.getValue());
|
||||||
|
} else if (value.getMetrics().getCounter().equals(VirtualRouterAutoScaleCounter.NETWORK_RECEIVED_AVERAGE_MBPS)) {
|
||||||
|
assertEquals(Double.valueOf(Double.valueOf(networkStats[1]) / VirtualRouterAutoScale.MBITS_TO_BYTES), value.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Mockito.verify(libvirtComputingResourceMock, Mockito.never()).getVPCNetworkStats(Mockito.any(), Mockito.any(), Mockito.any());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -183,6 +183,8 @@ import com.cloud.agent.api.VmStatsEntry;
|
|||||||
import com.cloud.agent.api.VolumeStatsEntry;
|
import com.cloud.agent.api.VolumeStatsEntry;
|
||||||
import com.cloud.agent.api.check.CheckSshAnswer;
|
import com.cloud.agent.api.check.CheckSshAnswer;
|
||||||
import com.cloud.agent.api.check.CheckSshCommand;
|
import com.cloud.agent.api.check.CheckSshCommand;
|
||||||
|
import com.cloud.agent.api.routing.GetAutoScaleMetricsAnswer;
|
||||||
|
import com.cloud.agent.api.routing.GetAutoScaleMetricsCommand;
|
||||||
import com.cloud.agent.api.routing.IpAssocCommand;
|
import com.cloud.agent.api.routing.IpAssocCommand;
|
||||||
import com.cloud.agent.api.routing.IpAssocVpcCommand;
|
import com.cloud.agent.api.routing.IpAssocVpcCommand;
|
||||||
import com.cloud.agent.api.routing.NetworkElementCommand;
|
import com.cloud.agent.api.routing.NetworkElementCommand;
|
||||||
@ -255,6 +257,7 @@ import com.cloud.network.Networks;
|
|||||||
import com.cloud.network.Networks.BroadcastDomainType;
|
import com.cloud.network.Networks.BroadcastDomainType;
|
||||||
import com.cloud.network.Networks.TrafficType;
|
import com.cloud.network.Networks.TrafficType;
|
||||||
import com.cloud.network.VmwareTrafficLabel;
|
import com.cloud.network.VmwareTrafficLabel;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale;
|
||||||
import com.cloud.resource.ServerResource;
|
import com.cloud.resource.ServerResource;
|
||||||
import com.cloud.serializer.GsonHelper;
|
import com.cloud.serializer.GsonHelper;
|
||||||
import com.cloud.storage.Storage;
|
import com.cloud.storage.Storage;
|
||||||
@ -599,6 +602,8 @@ public class VmwareResource extends ServerResourceBase implements StoragePoolRes
|
|||||||
answer = execute((SetupPersistentNetworkCommand) cmd);
|
answer = execute((SetupPersistentNetworkCommand) cmd);
|
||||||
} else if (clz == GetVmVncTicketCommand.class) {
|
} else if (clz == GetVmVncTicketCommand.class) {
|
||||||
answer = execute((GetVmVncTicketCommand) cmd);
|
answer = execute((GetVmVncTicketCommand) cmd);
|
||||||
|
} else if (clz == GetAutoScaleMetricsCommand.class) {
|
||||||
|
answer = execute((GetAutoScaleMetricsCommand) cmd);
|
||||||
} else {
|
} else {
|
||||||
answer = Answer.createUnsupportedCommandAnswer(cmd);
|
answer = Answer.createUnsupportedCommandAnswer(cmd);
|
||||||
}
|
}
|
||||||
@ -1094,7 +1099,7 @@ public class VmwareResource extends ServerResourceBase implements StoragePoolRes
|
|||||||
NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L, 0L);
|
NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L, 0L);
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
long[] stats = getNetworkStats(cmd.getPrivateIP());
|
long[] stats = getNetworkStats(cmd.getPrivateIP(), null);
|
||||||
|
|
||||||
NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "", stats[0], stats[1]);
|
NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "", stats[0], stats[1]);
|
||||||
return answer;
|
return answer;
|
||||||
@ -1104,13 +1109,18 @@ public class VmwareResource extends ServerResourceBase implements StoragePoolRes
|
|||||||
String privateIp = cmd.getPrivateIP();
|
String privateIp = cmd.getPrivateIP();
|
||||||
String option = cmd.getOption();
|
String option = cmd.getOption();
|
||||||
String publicIp = cmd.getGatewayIP();
|
String publicIp = cmd.getGatewayIP();
|
||||||
|
String vpcCIDR = cmd.getVpcCIDR();
|
||||||
|
|
||||||
|
final long[] stats = getVPCNetworkStats(privateIp, publicIp, option, vpcCIDR);
|
||||||
|
return new NetworkUsageAnswer(cmd, "", stats[0], stats[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected long[] getVPCNetworkStats(String privateIp, String publicIp, String option, String vpcCIDR) {
|
||||||
String args = "-l " + publicIp + " ";
|
String args = "-l " + publicIp + " ";
|
||||||
if (option.equals("get")) {
|
if (option.equals("get")) {
|
||||||
args += "-g";
|
args += "-g";
|
||||||
} else if (option.equals("create")) {
|
} else if (option.equals("create")) {
|
||||||
args += "-c";
|
args += "-c";
|
||||||
String vpcCIDR = cmd.getVpcCIDR();
|
|
||||||
args += " -v " + vpcCIDR;
|
args += " -v " + vpcCIDR;
|
||||||
} else if (option.equals("reset")) {
|
} else if (option.equals("reset")) {
|
||||||
args += "-r";
|
args += "-r";
|
||||||
@ -1119,7 +1129,7 @@ public class VmwareResource extends ServerResourceBase implements StoragePoolRes
|
|||||||
} else if (option.equals("remove")) {
|
} else if (option.equals("remove")) {
|
||||||
args += "-d";
|
args += "-d";
|
||||||
} else {
|
} else {
|
||||||
return new NetworkUsageAnswer(cmd, "success", 0L, 0L);
|
return new long[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecutionResult callResult = executeInVR(privateIp, "vpc_netusage.sh", args);
|
ExecutionResult callResult = executeInVR(privateIp, "vpc_netusage.sh", args);
|
||||||
@ -1141,10 +1151,66 @@ public class VmwareResource extends ServerResourceBase implements StoragePoolRes
|
|||||||
stats[0] += Long.parseLong(splitResult[i++]);
|
stats[0] += Long.parseLong(splitResult[i++]);
|
||||||
stats[1] += Long.parseLong(splitResult[i++]);
|
stats[1] += Long.parseLong(splitResult[i++]);
|
||||||
}
|
}
|
||||||
return new NetworkUsageAnswer(cmd, "success", stats[0], stats[1]);
|
return stats;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new NetworkUsageAnswer(cmd, "success", 0L, 0L);
|
return new long[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected long[] getNetworkLbStats(String privateIp, String publicIp, Integer port) {
|
||||||
|
String args = publicIp + " " + port;
|
||||||
|
ExecutionResult callResult = executeInVR(privateIp, "get_haproxy_stats.sh", args);
|
||||||
|
|
||||||
|
String result = callResult.getDetails();
|
||||||
|
if (!Boolean.TRUE.equals(callResult.isSuccess())) {
|
||||||
|
s_logger.error(String.format("Unable to get network loadbalancer stats on DomR (%s), domR may not be ready yet. failure due to %s", privateIp, callResult.getDetails()));
|
||||||
|
result = null;
|
||||||
|
} else if (result == null || result.isEmpty()) {
|
||||||
|
s_logger.error("Get network loadbalancer stats returns empty result");
|
||||||
|
}
|
||||||
|
long[] stats = new long[1];
|
||||||
|
if (result != null) {
|
||||||
|
final String[] splitResult = result.split(",");
|
||||||
|
stats[0] += Long.parseLong(splitResult[0]);
|
||||||
|
}
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Answer execute(GetAutoScaleMetricsCommand cmd) {
|
||||||
|
Long bytesSent;
|
||||||
|
Long bytesReceived;
|
||||||
|
if (cmd.isForVpc()) {
|
||||||
|
long[] stats = getVPCNetworkStats(cmd.getPrivateIP(), cmd.getPublicIP(), "get", "");
|
||||||
|
bytesSent = stats[0];
|
||||||
|
bytesReceived = stats[1];
|
||||||
|
} else {
|
||||||
|
long [] stats = getNetworkStats(cmd.getPrivateIP(), cmd.getPublicIP());
|
||||||
|
bytesSent = stats[0];
|
||||||
|
bytesReceived = stats[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
long [] lbStats = getNetworkLbStats(cmd.getPrivateIP(), cmd.getPublicIP(), cmd.getPort());
|
||||||
|
long lbConnections = lbStats[0];
|
||||||
|
|
||||||
|
List<VirtualRouterAutoScale.AutoScaleMetricsValue> values = new ArrayList<>();
|
||||||
|
|
||||||
|
for (VirtualRouterAutoScale.AutoScaleMetrics metrics : cmd.getMetrics()) {
|
||||||
|
switch (metrics.getCounter()) {
|
||||||
|
case NETWORK_RECEIVED_AVERAGE_MBPS:
|
||||||
|
values.add(new VirtualRouterAutoScale.AutoScaleMetricsValue(metrics, VirtualRouterAutoScale.AutoScaleValueType.AGGREGATED_VM_GROUP,
|
||||||
|
Double.valueOf(bytesReceived) / VirtualRouterAutoScale.MBITS_TO_BYTES));
|
||||||
|
break;
|
||||||
|
case NETWORK_TRANSMIT_AVERAGE_MBPS:
|
||||||
|
values.add(new VirtualRouterAutoScale.AutoScaleMetricsValue(metrics, VirtualRouterAutoScale.AutoScaleValueType.AGGREGATED_VM_GROUP,
|
||||||
|
Double.valueOf(bytesSent) / VirtualRouterAutoScale.MBITS_TO_BYTES));
|
||||||
|
break;
|
||||||
|
case LB_AVERAGE_CONNECTIONS:
|
||||||
|
values.add(new VirtualRouterAutoScale.AutoScaleMetricsValue(metrics, VirtualRouterAutoScale.AutoScaleValueType.INSTANT_VM, Double.valueOf(lbConnections)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GetAutoScaleMetricsAnswer(cmd, true, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -6549,9 +6615,16 @@ public class VmwareResource extends ServerResourceBase implements StoragePoolRes
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String networkUsage(final String privateIpAddress, final String option, final String ethName) {
|
protected String networkUsage(final String privateIpAddress, final String option, final String ethName) {
|
||||||
|
return networkUsage(privateIpAddress, option, ethName, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String networkUsage(final String privateIpAddress, final String option, final String ethName, final String publicIp) {
|
||||||
String args = null;
|
String args = null;
|
||||||
if (option.equals("get")) {
|
if (option.equals("get")) {
|
||||||
args = "-g";
|
args = "-g";
|
||||||
|
if (StringUtils.isNotEmpty(publicIp)) {
|
||||||
|
args += " -l " + publicIp;
|
||||||
|
}
|
||||||
} else if (option.equals("create")) {
|
} else if (option.equals("create")) {
|
||||||
args = "-c";
|
args = "-c";
|
||||||
} else if (option.equals("reset")) {
|
} else if (option.equals("reset")) {
|
||||||
@ -6573,8 +6646,8 @@ public class VmwareResource extends ServerResourceBase implements StoragePoolRes
|
|||||||
return result.getDetails();
|
return result.getDetails();
|
||||||
}
|
}
|
||||||
|
|
||||||
private long[] getNetworkStats(String privateIP) {
|
protected long[] getNetworkStats(String privateIP, String publicIp) {
|
||||||
String result = networkUsage(privateIP, "get", null);
|
String result = networkUsage(privateIP, "get", null, publicIp);
|
||||||
long[] stats = new long[2];
|
long[] stats = new long[2];
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.cloudstack.storage.command.CopyCommand;
|
import org.apache.cloudstack.storage.command.CopyCommand;
|
||||||
@ -50,9 +51,12 @@ import org.powermock.api.mockito.PowerMockito;
|
|||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.Answer;
|
||||||
import com.cloud.agent.api.Command;
|
import com.cloud.agent.api.Command;
|
||||||
import com.cloud.agent.api.ScaleVmAnswer;
|
import com.cloud.agent.api.ScaleVmAnswer;
|
||||||
import com.cloud.agent.api.ScaleVmCommand;
|
import com.cloud.agent.api.ScaleVmCommand;
|
||||||
|
import com.cloud.agent.api.routing.GetAutoScaleMetricsAnswer;
|
||||||
|
import com.cloud.agent.api.routing.GetAutoScaleMetricsCommand;
|
||||||
import com.cloud.agent.api.to.DataTO;
|
import com.cloud.agent.api.to.DataTO;
|
||||||
import com.cloud.agent.api.to.NfsTO;
|
import com.cloud.agent.api.to.NfsTO;
|
||||||
import com.cloud.agent.api.to.NicTO;
|
import com.cloud.agent.api.to.NicTO;
|
||||||
@ -65,9 +69,14 @@ import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
|
|||||||
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
|
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
|
||||||
import com.cloud.hypervisor.vmware.util.VmwareClient;
|
import com.cloud.hypervisor.vmware.util.VmwareClient;
|
||||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleMetrics;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.AutoScaleMetricsValue;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale.VirtualRouterAutoScaleCounter;
|
||||||
import com.cloud.storage.resource.VmwareStorageProcessor;
|
import com.cloud.storage.resource.VmwareStorageProcessor;
|
||||||
import com.cloud.storage.resource.VmwareStorageProcessor.VmwareStorageProcessorConfigurableFields;
|
import com.cloud.storage.resource.VmwareStorageProcessor.VmwareStorageProcessorConfigurableFields;
|
||||||
import com.cloud.storage.resource.VmwareStorageSubsystemCommandHandler;
|
import com.cloud.storage.resource.VmwareStorageSubsystemCommandHandler;
|
||||||
|
import com.cloud.utils.ExecutionResult;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import com.cloud.vm.VmDetailConstants;
|
import com.cloud.vm.VmDetailConstants;
|
||||||
import com.vmware.vim25.HostCapability;
|
import com.vmware.vim25.HostCapability;
|
||||||
@ -79,11 +88,15 @@ import com.vmware.vim25.VirtualMachineConfigSpec;
|
|||||||
import com.vmware.vim25.VirtualMachineVideoCard;
|
import com.vmware.vim25.VirtualMachineVideoCard;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({CopyCommand.class, DatacenterMO.class, VmwareResource.class})
|
@PrepareForTest({CopyCommand.class})
|
||||||
public class VmwareResourceTest {
|
public class VmwareResourceTest {
|
||||||
|
|
||||||
private static final String VOLUME_PATH = "XXXXXXXXXXXX";
|
private static final String VOLUME_PATH = "XXXXXXXXXXXX";
|
||||||
|
|
||||||
|
@Spy
|
||||||
|
@InjectMocks
|
||||||
|
VmwareResource vmwareResource = new VmwareResource();
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
VmwareStorageProcessor storageProcessor;
|
VmwareStorageProcessor storageProcessor;
|
||||||
@Mock
|
@Mock
|
||||||
@ -163,6 +176,10 @@ public class VmwareResourceTest {
|
|||||||
private static final long VIDEO_CARD_MEMORY_SIZE = 65536l;
|
private static final long VIDEO_CARD_MEMORY_SIZE = 65536l;
|
||||||
private static final Boolean FULL_CLONE_FLAG = true;
|
private static final Boolean FULL_CLONE_FLAG = true;
|
||||||
|
|
||||||
|
final static long[] vpcStats = { 1000L, 2000L };
|
||||||
|
final static long[] networkStats = { 3000L, 4000L };
|
||||||
|
final static long[] lbStats = { 5L };
|
||||||
|
|
||||||
private Map<String,String> specsArray = new HashMap<String,String>();
|
private Map<String,String> specsArray = new HashMap<String,String>();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@ -403,6 +420,7 @@ public class VmwareResourceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@PrepareForTest({DatacenterMO.class, VmwareResource.class})
|
||||||
public void testFindVmOnDatacenter() throws Exception {
|
public void testFindVmOnDatacenter() throws Exception {
|
||||||
when(hyperHost.getHyperHostDatacenter()).thenReturn(mor);
|
when(hyperHost.getHyperHostDatacenter()).thenReturn(mor);
|
||||||
when(datacenter.getMor()).thenReturn(mor);
|
when(datacenter.getMor()).thenReturn(mor);
|
||||||
@ -435,4 +453,105 @@ public class VmwareResourceTest {
|
|||||||
verify(vmMo, never()).getRunningHost();
|
verify(vmMo, never()).getRunningHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAutoScaleMetricsCommandForVpc() {
|
||||||
|
List<AutoScaleMetrics> metrics = new ArrayList<>();
|
||||||
|
metrics.add(new AutoScaleMetrics(VirtualRouterAutoScaleCounter.LB_AVERAGE_CONNECTIONS, 1L, 2L, 3L, 4));
|
||||||
|
metrics.add(new AutoScaleMetrics(VirtualRouterAutoScaleCounter.NETWORK_RECEIVED_AVERAGE_MBPS, 1L, 2L, 3L, 4));
|
||||||
|
metrics.add(new AutoScaleMetrics(VirtualRouterAutoScaleCounter.NETWORK_TRANSMIT_AVERAGE_MBPS, 1L, 2L, 3L, 4));
|
||||||
|
|
||||||
|
GetAutoScaleMetricsCommand getAutoScaleMetricsCommand = new GetAutoScaleMetricsCommand("192.168.10.1", true, "10.10.10.10", 8080, metrics);
|
||||||
|
|
||||||
|
doReturn(vpcStats).when(vmwareResource).getVPCNetworkStats(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
|
||||||
|
doReturn(lbStats).when(vmwareResource).getNetworkLbStats(Mockito.nullable(String.class), Mockito.nullable(String.class), Mockito.nullable(Integer.class));
|
||||||
|
|
||||||
|
Answer answer = vmwareResource.executeRequest(getAutoScaleMetricsCommand);
|
||||||
|
assertTrue(answer instanceof GetAutoScaleMetricsAnswer);
|
||||||
|
|
||||||
|
GetAutoScaleMetricsAnswer getAutoScaleMetricsAnswer = (GetAutoScaleMetricsAnswer) answer;
|
||||||
|
List<AutoScaleMetricsValue> values = getAutoScaleMetricsAnswer.getValues();
|
||||||
|
|
||||||
|
assertEquals(3, values.size());
|
||||||
|
for (AutoScaleMetricsValue value : values) {
|
||||||
|
if (value.getMetrics().getCounter().equals(VirtualRouterAutoScaleCounter.LB_AVERAGE_CONNECTIONS)) {
|
||||||
|
assertEquals(Double.valueOf(lbStats[0]), value.getValue());
|
||||||
|
} else if (value.getMetrics().getCounter().equals(VirtualRouterAutoScaleCounter.NETWORK_TRANSMIT_AVERAGE_MBPS)) {
|
||||||
|
assertEquals(Double.valueOf(Double.valueOf(vpcStats[0]) / VirtualRouterAutoScale.MBITS_TO_BYTES), value.getValue());
|
||||||
|
} else if (value.getMetrics().getCounter().equals(VirtualRouterAutoScaleCounter.NETWORK_RECEIVED_AVERAGE_MBPS)) {
|
||||||
|
assertEquals(Double.valueOf(Double.valueOf(vpcStats[1]) / VirtualRouterAutoScale.MBITS_TO_BYTES), value.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAutoScaleMetricsCommandForNetwork() {
|
||||||
|
List<AutoScaleMetrics> metrics = new ArrayList<>();
|
||||||
|
metrics.add(new AutoScaleMetrics(VirtualRouterAutoScaleCounter.LB_AVERAGE_CONNECTIONS, 1L, 2L, 3L, 4));
|
||||||
|
metrics.add(new AutoScaleMetrics(VirtualRouterAutoScaleCounter.NETWORK_RECEIVED_AVERAGE_MBPS, 1L, 2L, 3L, 4));
|
||||||
|
metrics.add(new AutoScaleMetrics(VirtualRouterAutoScaleCounter.NETWORK_TRANSMIT_AVERAGE_MBPS, 1L, 2L, 3L, 4));
|
||||||
|
|
||||||
|
GetAutoScaleMetricsCommand getAutoScaleMetricsCommand = new GetAutoScaleMetricsCommand("192.168.10.1", false, "10.10.10.10", 8080, metrics);
|
||||||
|
|
||||||
|
doReturn(networkStats).when(vmwareResource).getNetworkStats(Mockito.anyString(), Mockito.anyString());
|
||||||
|
doReturn(lbStats).when(vmwareResource).getNetworkLbStats(Mockito.nullable(String.class), Mockito.nullable(String.class), Mockito.nullable(Integer.class));
|
||||||
|
|
||||||
|
Answer answer = vmwareResource.executeRequest(getAutoScaleMetricsCommand);
|
||||||
|
assertTrue(answer instanceof GetAutoScaleMetricsAnswer);
|
||||||
|
|
||||||
|
GetAutoScaleMetricsAnswer getAutoScaleMetricsAnswer = (GetAutoScaleMetricsAnswer) answer;
|
||||||
|
List<AutoScaleMetricsValue> values = getAutoScaleMetricsAnswer.getValues();
|
||||||
|
|
||||||
|
assertEquals(3, values.size());
|
||||||
|
for (AutoScaleMetricsValue value : values) {
|
||||||
|
if (value.getMetrics().getCounter().equals(VirtualRouterAutoScale.VirtualRouterAutoScaleCounter.LB_AVERAGE_CONNECTIONS)) {
|
||||||
|
assertEquals(Double.valueOf(lbStats[0]), value.getValue());
|
||||||
|
} else if (value.getMetrics().getCounter().equals(VirtualRouterAutoScale.VirtualRouterAutoScaleCounter.NETWORK_TRANSMIT_AVERAGE_MBPS)) {
|
||||||
|
assertEquals(Double.valueOf(Double.valueOf(networkStats[0]) / VirtualRouterAutoScale.MBITS_TO_BYTES), value.getValue());
|
||||||
|
} else if (value.getMetrics().getCounter().equals(VirtualRouterAutoScale.VirtualRouterAutoScaleCounter.NETWORK_RECEIVED_AVERAGE_MBPS)) {
|
||||||
|
assertEquals(Double.valueOf(Double.valueOf(networkStats[1]) / VirtualRouterAutoScale.MBITS_TO_BYTES), value.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetStatsForVpcStats() {
|
||||||
|
GetAutoScaleMetricsCommand getAutoScaleMetricsCommand = new GetAutoScaleMetricsCommand("192.168.10.1", true, "10.10.10.10", 8080, null);
|
||||||
|
|
||||||
|
String args = "-l " + getAutoScaleMetricsCommand.getPublicIP() + " -g";
|
||||||
|
ExecutionResult executionResult = new ExecutionResult(true, vpcStats[0] + ":" + vpcStats[1]);
|
||||||
|
doReturn(executionResult).when(vmwareResource).executeInVR(getAutoScaleMetricsCommand.getPrivateIP(), "vpc_netusage.sh", args);
|
||||||
|
|
||||||
|
long[] stats = vmwareResource.getVPCNetworkStats(getAutoScaleMetricsCommand.getPrivateIP(), getAutoScaleMetricsCommand.getPublicIP(), "get", "");
|
||||||
|
assertEquals(2, stats.length);
|
||||||
|
assertEquals(vpcStats[0], stats[0]);
|
||||||
|
assertEquals(vpcStats[1], stats[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetStatsForNetworkStats() {
|
||||||
|
GetAutoScaleMetricsCommand getAutoScaleMetricsCommand = new GetAutoScaleMetricsCommand("192.168.10.1", false, "10.10.10.10", 8080, null);
|
||||||
|
|
||||||
|
String args = "-g -l " + getAutoScaleMetricsCommand.getPublicIP();
|
||||||
|
ExecutionResult executionResult = new ExecutionResult(true, networkStats[0] + ":" + networkStats[1]);
|
||||||
|
doReturn(executionResult).when(vmwareResource).executeInVR(getAutoScaleMetricsCommand.getPrivateIP(), "netusage.sh", args);
|
||||||
|
|
||||||
|
long[] stats = vmwareResource.getNetworkStats(getAutoScaleMetricsCommand.getPrivateIP(), getAutoScaleMetricsCommand.getPublicIP());
|
||||||
|
assertEquals(2, stats.length);
|
||||||
|
assertEquals(networkStats[0], stats[0]);
|
||||||
|
assertEquals(networkStats[1], stats[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetStatsForLbStats() {
|
||||||
|
GetAutoScaleMetricsCommand getAutoScaleMetricsCommand = new GetAutoScaleMetricsCommand("192.168.10.1", true, "10.10.10.10", 8080, null);
|
||||||
|
|
||||||
|
String args = getAutoScaleMetricsCommand.getPublicIP() + " " + getAutoScaleMetricsCommand.getPort();
|
||||||
|
ExecutionResult executionResult = new ExecutionResult(true, String.valueOf(lbStats[0]));
|
||||||
|
doReturn(executionResult).when(vmwareResource).executeInVR(getAutoScaleMetricsCommand.getPrivateIP(), "get_haproxy_stats.sh", args);
|
||||||
|
|
||||||
|
long[] stats = vmwareResource.getNetworkLbStats(getAutoScaleMetricsCommand.getPrivateIP(), getAutoScaleMetricsCommand.getPublicIP(), getAutoScaleMetricsCommand.getPort());
|
||||||
|
|
||||||
|
assertEquals(1, stats.length);
|
||||||
|
assertEquals(lbStats[0], stats[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2977,8 +2977,8 @@ public abstract class CitrixResourceBase extends ServerResourceBase implements S
|
|||||||
return earliestNetwork != null ? new XsLocalNetwork(this, earliestNetwork, earliestNetworkRecord, null, null) : null;
|
return earliestNetwork != null ? new XsLocalNetwork(this, earliestNetwork, earliestNetworkRecord, null, null) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long[] getNetworkStats(final Connection conn, final String privateIP) {
|
public long[] getNetworkStats(final Connection conn, final String privateIP, final String publicIp) {
|
||||||
final String result = networkUsage(conn, privateIP, "get", null);
|
final String result = networkUsage(conn, privateIP, "get", null, publicIp);
|
||||||
final long[] stats = new long[2];
|
final long[] stats = new long[2];
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
final String[] splitResult = result.split(":");
|
final String[] splitResult = result.split(":");
|
||||||
@ -2991,6 +2991,37 @@ public abstract class CitrixResourceBase extends ServerResourceBase implements S
|
|||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long[] getVPCNetworkStats(final String privateIP, final String publicIp) {
|
||||||
|
String args = " -l " + publicIp + " -g";
|
||||||
|
final ExecutionResult result = executeInVR(privateIP, "vpc_netusage.sh", args);
|
||||||
|
final String detail = result.getDetails();
|
||||||
|
final long[] stats = new long[2];
|
||||||
|
if (detail != null) {
|
||||||
|
final String[] splitResult = detail.split(":");
|
||||||
|
int i = 0;
|
||||||
|
while (i < splitResult.length - 1) {
|
||||||
|
stats[0] += Long.parseLong(splitResult[i++]);
|
||||||
|
stats[1] += Long.parseLong(splitResult[i++]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long[] getNetworkLbStats(final String privateIp, final String publicIp, final Integer port) {
|
||||||
|
String args = publicIp + " " + port;
|
||||||
|
ExecutionResult callResult = executeInVR(privateIp, "get_haproxy_stats.sh", args);
|
||||||
|
String detail = callResult.getDetails();
|
||||||
|
if (detail == null || detail.isEmpty()) {
|
||||||
|
s_logger.error("Get network loadbalancer stats returns empty result");
|
||||||
|
}
|
||||||
|
final long[] stats = new long[1];
|
||||||
|
if (detail != null) {
|
||||||
|
final String[] splitResult = detail.split(",");
|
||||||
|
stats[0] += Long.parseLong(splitResult[0]);
|
||||||
|
}
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
|
||||||
public SR getNfsSR(final Connection conn, final String poolid, final String uuid, final String server, String serverpath, final String pooldesc) {
|
public SR getNfsSR(final Connection conn, final String poolid, final String uuid, final String server, String serverpath, final String pooldesc) {
|
||||||
final Map<String, String> deviceConfig = new HashMap<String, String>();
|
final Map<String, String> deviceConfig = new HashMap<String, String>();
|
||||||
try {
|
try {
|
||||||
@ -4020,7 +4051,12 @@ public abstract class CitrixResourceBase extends ServerResourceBase implements S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String networkUsage(final Connection conn, final String privateIpAddress, final String option, final String vif) {
|
public String networkUsage(final Connection conn, final String privateIpAddress, final String option, final String vif) {
|
||||||
|
return networkUsage(conn, privateIpAddress, option, vif, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String networkUsage(final Connection conn, final String privateIpAddress, final String option, final String vif, final String publicIp) {
|
||||||
if (option.equals("get")) {
|
if (option.equals("get")) {
|
||||||
return "0:0";
|
return "0:0";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package com.cloud.hypervisor.xenserver.resource;
|
package com.cloud.hypervisor.xenserver.resource;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.apache.xmlrpc.XmlRpcException;
|
import org.apache.xmlrpc.XmlRpcException;
|
||||||
|
|
||||||
@ -101,4 +102,27 @@ public class XcpServerResource extends CitrixResourceBase {
|
|||||||
//For the supported XCPs dmc is default enabled, XCP 1.0.0, 1.1.0, 1.4.x, 1.5 beta, 1.6.x;
|
//For the supported XCPs dmc is default enabled, XCP 1.0.0, 1.1.0, 1.4.x, 1.5 beta, 1.6.x;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String networkUsage(final Connection conn, final String privateIpAddress, final String option, final String vif, final String publicIp) {
|
||||||
|
String args = "";
|
||||||
|
if (option.equals("get")) {
|
||||||
|
args += "-g";
|
||||||
|
if (StringUtils.isNotEmpty(publicIp)) {
|
||||||
|
args += " -l " + publicIp;
|
||||||
|
}
|
||||||
|
} else if (option.equals("create")) {
|
||||||
|
args += "-c";
|
||||||
|
} else if (option.equals("reset")) {
|
||||||
|
args += "-r";
|
||||||
|
} else if (option.equals("addVif")) {
|
||||||
|
args += "-a ";
|
||||||
|
args += vif;
|
||||||
|
} else if (option.equals("deleteVif")) {
|
||||||
|
args += "-d ";
|
||||||
|
args += vif;
|
||||||
|
}
|
||||||
|
|
||||||
|
return executeInVR(privateIpAddress, "netusage.sh", args).getDetails();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package com.cloud.hypervisor.xenserver.resource;
|
package com.cloud.hypervisor.xenserver.resource;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.agent.api.StartupCommand;
|
import com.cloud.agent.api.StartupCommand;
|
||||||
@ -82,10 +83,13 @@ public class XenServer56Resource extends CitrixResourceBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String networkUsage(final Connection conn, final String privateIpAddress, final String option, final String vif) {
|
public String networkUsage(final Connection conn, final String privateIpAddress, final String option, final String vif, final String publicIp) {
|
||||||
String args = "";
|
String args = "";
|
||||||
if (option.equals("get")) {
|
if (option.equals("get")) {
|
||||||
args += "-g";
|
args += "-g";
|
||||||
|
if (StringUtils.isNotEmpty(publicIp)) {
|
||||||
|
args += " -l " + publicIp;
|
||||||
|
}
|
||||||
} else if (option.equals("create")) {
|
} else if (option.equals("create")) {
|
||||||
args += "-c";
|
args += "-c";
|
||||||
} else if (option.equals("reset")) {
|
} else if (option.equals("reset")) {
|
||||||
|
|||||||
@ -0,0 +1,85 @@
|
|||||||
|
//
|
||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
//
|
||||||
|
|
||||||
|
package com.cloud.hypervisor.xenserver.resource.wrapper.xcp;
|
||||||
|
|
||||||
|
import com.cloud.hypervisor.xenserver.resource.XcpServerResource;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.Answer;
|
||||||
|
import com.cloud.agent.api.routing.GetAutoScaleMetricsAnswer;
|
||||||
|
import com.cloud.agent.api.routing.GetAutoScaleMetricsCommand;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale;
|
||||||
|
import com.cloud.resource.CommandWrapper;
|
||||||
|
import com.cloud.resource.ResourceWrapper;
|
||||||
|
import com.xensource.xenapi.Connection;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@ResourceWrapper(handles = GetAutoScaleMetricsCommand.class)
|
||||||
|
public final class XcpServerGetAutoScaleMetricsCommandWrapper extends CommandWrapper<GetAutoScaleMetricsCommand, Answer, XcpServerResource> {
|
||||||
|
|
||||||
|
private static final Logger s_logger = Logger.getLogger(XcpServerGetAutoScaleMetricsCommandWrapper.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Answer execute(final GetAutoScaleMetricsCommand command, final XcpServerResource xcpServer) {
|
||||||
|
final Connection conn = xcpServer.getConnection();
|
||||||
|
try {
|
||||||
|
Long bytesSent;
|
||||||
|
Long bytesReceived;
|
||||||
|
if (command.isForVpc()) {
|
||||||
|
final long[] stats = xcpServer.getVPCNetworkStats(command.getPrivateIP(), command.getPublicIP());
|
||||||
|
bytesSent = stats[0];
|
||||||
|
bytesReceived = stats[1];
|
||||||
|
} else {
|
||||||
|
final long[] stats = xcpServer.getNetworkStats(conn, command.getPrivateIP(), command.getPublicIP());
|
||||||
|
bytesSent = stats[0];
|
||||||
|
bytesReceived = stats[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
final long [] lbStats = xcpServer.getNetworkLbStats(command.getPrivateIP(), command.getPublicIP(), command.getPort());
|
||||||
|
final long lbConnections = lbStats[0];
|
||||||
|
|
||||||
|
List<VirtualRouterAutoScale.AutoScaleMetricsValue> values = new ArrayList<>();
|
||||||
|
|
||||||
|
for (VirtualRouterAutoScale.AutoScaleMetrics metrics : command.getMetrics()) {
|
||||||
|
switch (metrics.getCounter()) {
|
||||||
|
case NETWORK_RECEIVED_AVERAGE_MBPS:
|
||||||
|
values.add(new VirtualRouterAutoScale.AutoScaleMetricsValue(metrics, VirtualRouterAutoScale.AutoScaleValueType.AGGREGATED_VM_GROUP,
|
||||||
|
Double.valueOf(bytesReceived) / VirtualRouterAutoScale.MBITS_TO_BYTES));
|
||||||
|
break;
|
||||||
|
case NETWORK_TRANSMIT_AVERAGE_MBPS:
|
||||||
|
values.add(new VirtualRouterAutoScale.AutoScaleMetricsValue(metrics, VirtualRouterAutoScale.AutoScaleValueType.AGGREGATED_VM_GROUP,
|
||||||
|
Double.valueOf(bytesSent) / VirtualRouterAutoScale.MBITS_TO_BYTES));
|
||||||
|
break;
|
||||||
|
case LB_AVERAGE_CONNECTIONS:
|
||||||
|
values.add(new VirtualRouterAutoScale.AutoScaleMetricsValue(metrics, VirtualRouterAutoScale.AutoScaleValueType.INSTANT_VM, Double.valueOf(lbConnections)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GetAutoScaleMetricsAnswer(command, true, values);
|
||||||
|
} catch (final Exception ex) {
|
||||||
|
s_logger.warn("Failed to get autoscale metrics due to ", ex);
|
||||||
|
return new GetAutoScaleMetricsAnswer(command, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -43,7 +43,7 @@ public final class XcpServerNetworkUsageCommandWrapper extends CommandWrapper<Ne
|
|||||||
final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, result, 0L, 0L);
|
final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, result, 0L, 0L);
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
final long[] stats = xcpServerResource.getNetworkStats(conn, command.getPrivateIP());
|
final long[] stats = xcpServerResource.getNetworkStats(conn, command.getPrivateIP(), null);
|
||||||
final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, "", stats[0], stats[1]);
|
final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, "", stats[0], stats[1]);
|
||||||
return answer;
|
return answer;
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
|
|||||||
@ -0,0 +1,85 @@
|
|||||||
|
//
|
||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with 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.
|
||||||
|
//
|
||||||
|
|
||||||
|
package com.cloud.hypervisor.xenserver.resource.wrapper.xen56;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.Answer;
|
||||||
|
import com.cloud.agent.api.routing.GetAutoScaleMetricsAnswer;
|
||||||
|
import com.cloud.agent.api.routing.GetAutoScaleMetricsCommand;
|
||||||
|
import com.cloud.hypervisor.xenserver.resource.XenServer56Resource;
|
||||||
|
import com.cloud.network.router.VirtualRouterAutoScale;
|
||||||
|
import com.cloud.resource.CommandWrapper;
|
||||||
|
import com.cloud.resource.ResourceWrapper;
|
||||||
|
import com.xensource.xenapi.Connection;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@ResourceWrapper(handles = GetAutoScaleMetricsCommand.class)
|
||||||
|
public final class XenServer56GetAutoScaleMetricsCommandWrapper extends CommandWrapper<GetAutoScaleMetricsCommand, Answer, XenServer56Resource> {
|
||||||
|
|
||||||
|
private static final Logger s_logger = Logger.getLogger(XenServer56GetAutoScaleMetricsCommandWrapper.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Answer execute(final GetAutoScaleMetricsCommand command, final XenServer56Resource xenServer56) {
|
||||||
|
final Connection conn = xenServer56.getConnection();
|
||||||
|
try {
|
||||||
|
Long bytesSent;
|
||||||
|
Long bytesReceived;
|
||||||
|
if (command.isForVpc()) {
|
||||||
|
final long[] stats = xenServer56.getVPCNetworkStats(command.getPrivateIP(), command.getPublicIP());
|
||||||
|
bytesSent = stats[0];
|
||||||
|
bytesReceived = stats[1];
|
||||||
|
} else {
|
||||||
|
final long[] stats = xenServer56.getNetworkStats(conn, command.getPrivateIP(), command.getPublicIP());
|
||||||
|
bytesSent = stats[0];
|
||||||
|
bytesReceived = stats[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
final long [] lbStats = xenServer56.getNetworkLbStats(command.getPrivateIP(), command.getPublicIP(), command.getPort());
|
||||||
|
final long lbConnections = lbStats[0];
|
||||||
|
|
||||||
|
List<VirtualRouterAutoScale.AutoScaleMetricsValue> values = new ArrayList<>();
|
||||||
|
|
||||||
|
for (VirtualRouterAutoScale.AutoScaleMetrics metrics : command.getMetrics()) {
|
||||||
|
switch (metrics.getCounter()) {
|
||||||
|
case NETWORK_RECEIVED_AVERAGE_MBPS:
|
||||||
|
values.add(new VirtualRouterAutoScale.AutoScaleMetricsValue(metrics, VirtualRouterAutoScale.AutoScaleValueType.AGGREGATED_VM_GROUP,
|
||||||
|
Double.valueOf(bytesReceived) / VirtualRouterAutoScale.MBITS_TO_BYTES));
|
||||||
|
break;
|
||||||
|
case NETWORK_TRANSMIT_AVERAGE_MBPS:
|
||||||
|
values.add(new VirtualRouterAutoScale.AutoScaleMetricsValue(metrics, VirtualRouterAutoScale.AutoScaleValueType.AGGREGATED_VM_GROUP,
|
||||||
|
Double.valueOf(bytesSent) / VirtualRouterAutoScale.MBITS_TO_BYTES));
|
||||||
|
break;
|
||||||
|
case LB_AVERAGE_CONNECTIONS:
|
||||||
|
values.add(new VirtualRouterAutoScale.AutoScaleMetricsValue(metrics, VirtualRouterAutoScale.AutoScaleValueType.INSTANT_VM, Double.valueOf(lbConnections)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GetAutoScaleMetricsAnswer(command, true, values);
|
||||||
|
} catch (final Exception ex) {
|
||||||
|
s_logger.warn("Failed to get autoscale metrics due to ", ex);
|
||||||
|
return new GetAutoScaleMetricsAnswer(command, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -47,7 +47,7 @@ public final class XenServer56NetworkUsageCommandWrapper extends CommandWrapper<
|
|||||||
final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, result, 0L, 0L);
|
final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, result, 0L, 0L);
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
final long[] stats = xenServer56.getNetworkStats(conn, command.getPrivateIP());
|
final long[] stats = xenServer56.getNetworkStats(conn, command.getPrivateIP(), null);
|
||||||
final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, "", stats[0], stats[1]);
|
final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, "", stats[0], stats[1]);
|
||||||
return answer;
|
return answer;
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
|
|||||||
@ -23,7 +23,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.cloud.utils.StringUtils;
|
|
||||||
import org.apache.xmlrpc.XmlRpcException;
|
import org.apache.xmlrpc.XmlRpcException;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -44,6 +43,8 @@ import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase.SRType;
|
|||||||
import com.cloud.storage.Storage.StoragePoolType;
|
import com.cloud.storage.Storage.StoragePoolType;
|
||||||
import com.cloud.storage.Storage.StorageResourceType;
|
import com.cloud.storage.Storage.StorageResourceType;
|
||||||
import com.cloud.template.TemplateManager;
|
import com.cloud.template.TemplateManager;
|
||||||
|
import com.cloud.utils.ExecutionResult;
|
||||||
|
import com.cloud.utils.StringUtils;
|
||||||
import com.cloud.utils.script.Script;
|
import com.cloud.utils.script.Script;
|
||||||
import com.xensource.xenapi.Connection;
|
import com.xensource.xenapi.Connection;
|
||||||
import com.xensource.xenapi.Host;
|
import com.xensource.xenapi.Host;
|
||||||
@ -53,6 +54,8 @@ import com.xensource.xenapi.SR;
|
|||||||
import com.xensource.xenapi.Types.XenAPIException;
|
import com.xensource.xenapi.Types.XenAPIException;
|
||||||
|
|
||||||
import static com.cloud.hypervisor.xenserver.resource.CitrixResourceBase.PLATFORM_CORES_PER_SOCKET_KEY;
|
import static com.cloud.hypervisor.xenserver.resource.CitrixResourceBase.PLATFORM_CORES_PER_SOCKET_KEY;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({Host.class, Script.class, SR.class})
|
@PrepareForTest({Host.class, Script.class, SR.class})
|
||||||
@ -77,6 +80,13 @@ public class CitrixResourceBaseTest {
|
|||||||
|
|
||||||
private static final String platformString = "device-model:qemu-upstream-compat;vga:std;videoram:8;apic:true;viridian:false;timeoffset:0;pae:true;acpi:1;hpet:true;secureboot:false;nx:true";
|
private static final String platformString = "device-model:qemu-upstream-compat;vga:std;videoram:8;apic:true;viridian:false;timeoffset:0;pae:true;acpi:1;hpet:true;secureboot:false;nx:true";
|
||||||
|
|
||||||
|
final static long[] vpcStats = { 1L, 2L };
|
||||||
|
final static long[] networkStats = { 3L, 4L };
|
||||||
|
final static long[] lbStats = { 5L };
|
||||||
|
final static String privateIp = "192.168.1.1";
|
||||||
|
final static String publicIp = "10.10.10.10";
|
||||||
|
final static Integer port = 8080;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void beforeTest() throws XenAPIException, XmlRpcException {
|
public void beforeTest() throws XenAPIException, XmlRpcException {
|
||||||
citrixResourceBase._host.setUuid(hostUuidMock);
|
citrixResourceBase._host.setUuid(hostUuidMock);
|
||||||
@ -402,4 +412,58 @@ public class CitrixResourceBaseTest {
|
|||||||
Assert.assertTrue(platform.containsKey(PLATFORM_CORES_PER_SOCKET_KEY));
|
Assert.assertTrue(platform.containsKey(PLATFORM_CORES_PER_SOCKET_KEY));
|
||||||
Assert.assertEquals(coresPerSocket, platform.get(PLATFORM_CORES_PER_SOCKET_KEY));
|
Assert.assertEquals(coresPerSocket, platform.get(PLATFORM_CORES_PER_SOCKET_KEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetStatsForVpcStats() {
|
||||||
|
CitrixResourceBase citrixResourceBaseSpy = Mockito.spy(CitrixResourceBase.class);
|
||||||
|
|
||||||
|
String args = " -l " + publicIp + " -g";
|
||||||
|
ExecutionResult executionResult = new ExecutionResult(true, vpcStats[0] + ":" + vpcStats[1]);
|
||||||
|
doReturn(executionResult).when(citrixResourceBaseSpy).executeInVR(privateIp, "vpc_netusage.sh", args);
|
||||||
|
|
||||||
|
long[] stats = citrixResourceBaseSpy.getVPCNetworkStats(privateIp, publicIp);
|
||||||
|
assertEquals(2, stats.length);
|
||||||
|
assertEquals(vpcStats[0], stats[0]);
|
||||||
|
assertEquals(vpcStats[1], stats[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetStatsForNetworkStats() {
|
||||||
|
CitrixResourceBase citrixResourceBaseSpy = Mockito.spy(CitrixResourceBase.class);
|
||||||
|
Connection connection = Mockito.mock(Connection.class);
|
||||||
|
|
||||||
|
String args = "-g -l " + publicIp;
|
||||||
|
doReturn(networkStats[0] + ":" + networkStats[1]).when(citrixResourceBaseSpy).networkUsage(Mockito.any(Connection.class),
|
||||||
|
Mockito.eq(privateIp), Mockito.eq("get"), Mockito.any(), Mockito.eq(publicIp));
|
||||||
|
|
||||||
|
long[] stats = citrixResourceBaseSpy.getNetworkStats(connection, privateIp, publicIp);
|
||||||
|
assertEquals(2, stats.length);
|
||||||
|
assertEquals(networkStats[0], stats[0]);
|
||||||
|
assertEquals(networkStats[1], stats[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetStatsForLbStats() {
|
||||||
|
CitrixResourceBase citrixResourceBaseSpy = Mockito.spy(CitrixResourceBase.class);
|
||||||
|
|
||||||
|
String args = publicIp + " " + port;
|
||||||
|
ExecutionResult executionResult = new ExecutionResult(true, String.valueOf(lbStats[0]));
|
||||||
|
doReturn(executionResult).when(citrixResourceBaseSpy).executeInVR(privateIp, "get_haproxy_stats.sh", args);
|
||||||
|
|
||||||
|
long[] stats = citrixResourceBaseSpy.getNetworkLbStats(privateIp, publicIp, port);
|
||||||
|
|
||||||
|
assertEquals(1, stats.length);
|
||||||
|
assertEquals(lbStats[0], stats[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNetworkUsage() {
|
||||||
|
CitrixResourceBase citrixResourceBaseSpy = Mockito.spy(CitrixResourceBase.class);
|
||||||
|
|
||||||
|
String result = citrixResourceBaseSpy.networkUsage(connectionMock, null, "get", null);
|
||||||
|
Assert.assertEquals("0:0", result);
|
||||||
|
|
||||||
|
result = citrixResourceBaseSpy.networkUsage(connectionMock, null, "put", null);
|
||||||
|
Assert.assertNull(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,9 +21,13 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
|
import com.cloud.utils.ExecutionResult;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import com.xensource.xenapi.Types.XenAPIException;
|
import com.xensource.xenapi.Types.XenAPIException;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.anyString;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
|
||||||
public class XcpServerResourceTest extends CitrixResourceBaseTest {
|
public class XcpServerResourceTest extends CitrixResourceBaseTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@ -50,4 +54,25 @@ public class XcpServerResourceTest extends CitrixResourceBaseTest {
|
|||||||
public void testGetFilesListReturned() {
|
public void testGetFilesListReturned() {
|
||||||
testGetPathFilesListReturned();
|
testGetPathFilesListReturned();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void testNetworkUsageInternal(String option, String publicIp, String expectedArgs) {
|
||||||
|
String result = citrixResourceBase.networkUsage(null, "10.10.10.10", option, "eth0", publicIp);
|
||||||
|
|
||||||
|
Assert.assertEquals("result", result);
|
||||||
|
Mockito.verify(citrixResourceBase).executeInVR("10.10.10.10", "netusage.sh", expectedArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNetworkUsage() {
|
||||||
|
ExecutionResult executionResult = new ExecutionResult(true, "result");
|
||||||
|
|
||||||
|
doReturn(executionResult).when(citrixResourceBase).executeInVR(anyString(), anyString(), anyString());
|
||||||
|
|
||||||
|
testNetworkUsageInternal("get", "", "-g");
|
||||||
|
testNetworkUsageInternal("get", "20.20.20.20", "-g -l 20.20.20.20");
|
||||||
|
testNetworkUsageInternal("create", "", "-c");
|
||||||
|
testNetworkUsageInternal("reset", "", "-r");
|
||||||
|
testNetworkUsageInternal("addVif", "", "-a eth0");
|
||||||
|
testNetworkUsageInternal("deleteVif", "", "-d eth0");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,9 +21,13 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
|
import com.cloud.utils.ExecutionResult;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import com.xensource.xenapi.Types.XenAPIException;
|
import com.xensource.xenapi.Types.XenAPIException;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.anyString;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
|
||||||
public class XenServer56ResourceTest extends CitrixResourceBaseTest {
|
public class XenServer56ResourceTest extends CitrixResourceBaseTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,4 +54,25 @@ public class XenServer56ResourceTest extends CitrixResourceBaseTest {
|
|||||||
public void testGetFilesListReturned() {
|
public void testGetFilesListReturned() {
|
||||||
testGetPathFilesListReturned();
|
testGetPathFilesListReturned();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void testNetworkUsageInternal(String option, String publicIp, String expectedArgs) {
|
||||||
|
String result = citrixResourceBase.networkUsage(null, "10.10.10.10", option, "eth0", publicIp);
|
||||||
|
|
||||||
|
Assert.assertEquals("result", result);
|
||||||
|
Mockito.verify(citrixResourceBase).executeInVR("10.10.10.10", "netusage.sh", expectedArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNetworkUsage() {
|
||||||
|
ExecutionResult executionResult = new ExecutionResult(true, "result");
|
||||||
|
|
||||||
|
doReturn(executionResult).when(citrixResourceBase).executeInVR(anyString(), anyString(), anyString());
|
||||||
|
|
||||||
|
testNetworkUsageInternal("get", "", "-g");
|
||||||
|
testNetworkUsageInternal("get", "20.20.20.20", "-g -l 20.20.20.20");
|
||||||
|
testNetworkUsageInternal("create", "", "-c");
|
||||||
|
testNetworkUsageInternal("reset", "", "-r");
|
||||||
|
testNetworkUsageInternal("addVif", "", "-a eth0");
|
||||||
|
testNetworkUsageInternal("deleteVif", "", "-d eth0");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user