Added more logging to AutoScale Vm Group

This commit is contained in:
Deepak Garg 2012-07-18 16:48:01 +05:30 committed by Vijay
parent 05e46cfd31
commit 349ab92ffc
4 changed files with 80 additions and 76 deletions

View File

@ -31,44 +31,44 @@ import com.cloud.exception.ResourceAllocationException;
import com.cloud.network.as.AutoScaleVmGroup;
import com.cloud.network.rules.LoadBalancer;
@Implementation(description="Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject=AutoScaleVmGroupResponse.class)
@Implementation(description = "Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject = AutoScaleVmGroupResponse.class)
public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd {
public static final Logger s_logger = Logger.getLogger(CreateAutoScaleVmGroupCmd.class.getName());
private static final String s_name = "autoscalevmgroupresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@IdentityMapper(entityTableName="firewall_rules")
@IdentityMapper(entityTableName = "firewall_rules")
@Parameter(name = ApiConstants.LBID, type = CommandType.LONG, required = true, description = "the ID of the load balancer rule")
private long lbRuleId;
@Parameter(name=ApiConstants.MIN_MEMBERS, type=CommandType.INTEGER, required=true, description="the minimum number of members in the vmgroup, the number of instances in the vm group will be equal to or more than this number.")
@Parameter(name = ApiConstants.MIN_MEMBERS, type = CommandType.INTEGER, required = true, description = "the minimum number of members in the vmgroup, the number of instances in the vm group will be equal to or more than this number.")
private int minMembers;
@Parameter(name=ApiConstants.MAX_MEMBERS, type=CommandType.INTEGER, required=true, description="the maximum number of members in the vmgroup, The number of instances in the vm group will be equal to or less than this number.")
@Parameter(name = ApiConstants.MAX_MEMBERS, type = CommandType.INTEGER, required = true, description = "the maximum number of members in the vmgroup, The number of instances in the vm group will be equal to or less than this number.")
private int maxMembers;
@Parameter(name=ApiConstants.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 at which the conditions have to be evaluated")
private Integer interval;
@IdentityMapper(entityTableName="autoscale_policies")
@Parameter(name=ApiConstants.SCALEUP_POLICY_IDS, type=CommandType.LIST, collectionType=CommandType.LONG, required=true, description="list of scaleup autoscale policies")
@IdentityMapper(entityTableName = "autoscale_policies")
@Parameter(name = ApiConstants.SCALEUP_POLICY_IDS, type = CommandType.LIST, collectionType = CommandType.LONG, required = true, description = "list of scaleup autoscale policies")
private List<Long> scaleUpPolicyIds;
@IdentityMapper(entityTableName="autoscale_policies")
@Parameter(name=ApiConstants.SCALEDOWN_POLICY_IDS, type=CommandType.LIST, collectionType=CommandType.LONG, required=true, description="list of scaledown autoscale policies")
@IdentityMapper(entityTableName = "autoscale_policies")
@Parameter(name = ApiConstants.SCALEDOWN_POLICY_IDS, type = CommandType.LIST, collectionType = CommandType.LONG, required = true, description = "list of scaledown autoscale policies")
private List<Long> scaleDownPolicyIds;
@IdentityMapper(entityTableName="autoscale_vmprofiles")
@Parameter(name=ApiConstants.VMPROFILE_ID, type=CommandType.LONG, required=true, description="the autoscale profile that contains information about the vms in the vm group.")
@IdentityMapper(entityTableName = "autoscale_vmprofiles")
@Parameter(name = ApiConstants.VMPROFILE_ID, type = CommandType.LONG, required = true, description = "the autoscale profile that contains information about the vms in the vm group.")
private long profileId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public String getEntityTable() {
@ -83,7 +83,6 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd {
return maxMembers;
}
public Integer getInterval() {
return interval;
}
@ -104,9 +103,9 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd {
return lbRuleId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public String getCommandName() {
@ -120,7 +119,7 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd {
@Override
public long getEntityOwnerId() {
LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getLbRuleId());
if(lb == null) {
if (lb == null) {
throw new InvalidParameterValueException("Unable to find loadbalancer from lbRuleId=" + getLbRuleId());
}
return lb.getAccountId();
@ -130,7 +129,6 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd {
this.lbRuleId = lbRuleId;
}
@Override
public String getEventType() {
return EventTypes.EVENT_AUTOSCALEVMGROUP_CREATE;
@ -148,7 +146,7 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd {
@Override
public String getEventDescription() {
return "configuring AutoScale Vm Group. Vm Group Id: "+getEntityId();
return "configuring AutoScale Vm Group. Vm Group Id: " + getEntityId();
}
@Override
@ -157,7 +155,7 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd {
}
@Override
public void create() throws ResourceAllocationException{
public void create() throws ResourceAllocationException {
AutoScaleVmGroup result = _autoScaleService.createAutoScaleVmGroup(this);
if (result != null) {
this.setEntityId(result.getId());
@ -167,23 +165,23 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd {
}
@Override
public void execute(){
public void execute() {
boolean success = false;
AutoScaleVmGroup vmGroup = null;
try
{
success = _autoScaleService.configureAutoScaleVmGroup(this);
if(success) {
if (success) {
vmGroup = _entityMgr.findById(AutoScaleVmGroup.class, getEntityId());
AutoScaleVmGroupResponse responseObject = _responseGenerator.createAutoScaleVmGroupResponse(vmGroup);
setResponseObject(responseObject);
responseObject.setResponseName(getCommandName());
}
} catch (Exception ex) {
//TODO what will happen if Resource Layer fails in a step inbetween
// TODO what will happen if Resource Layer fails in a step inbetween
s_logger.warn("Failed to create autoscale vm group", ex);
} finally {
if(!success || vmGroup == null) {
if (!success || vmGroup == null) {
_autoScaleService.deleteAutoScaleVmGroup(getEntityId());
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create Autoscale Vm Group");
}

View File

@ -28,30 +28,29 @@ import com.cloud.network.as.AutoScaleVmGroup;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@Implementation(description="Deletes a autoscale vm group.", responseObject=SuccessResponse.class)
@Implementation(description = "Deletes a autoscale vm group.", responseObject = SuccessResponse.class)
public class DeleteAutoScaleVmGroupCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(DeleteAutoScaleVmGroupCmd.class.getName());
private static final String s_name = "deleteautoscalevmgroupresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@IdentityMapper(entityTableName="autoscale_vmgroups")
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the autoscale group")
@IdentityMapper(entityTableName = "autoscale_vmgroups")
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = true, description = "the ID of the autoscale group")
private Long id;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public String getCommandName() {
@ -65,7 +64,8 @@ public class DeleteAutoScaleVmGroupCmd extends BaseAsyncCmd {
return autoScaleVmGroup.getAccountId();
}
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are
// tracked
}
@Override
@ -75,17 +75,16 @@ public class DeleteAutoScaleVmGroupCmd extends BaseAsyncCmd {
@Override
public String getEventDescription() {
return "deleting autoscale vm group: " + getId();
return "deleting autoscale vm group: " + getId();
}
@Override
public void execute(){
UserContext.current().setEventDetails("AutoScale Vm Group Id: "+getId());
public void execute() {
UserContext.current().setEventDetails("AutoScale Vm Group Id: " + getId());
boolean result = _autoScaleService.deleteAutoScaleVmGroup(id);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
s_logger.info("Successfully deleted autoscale vm group id : " + getId());
this.setResponseObject(response);
} else {
s_logger.warn("Failed to delete autoscale vm group " + getId());

View File

@ -676,6 +676,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
loadBalancer.getDefaultPortStart(), interval, cmd.getProfileId(), AutoScaleVmGroup.State_New);
vmGroupVO = checkValidityAndPersist(vmGroupVO, cmd.getScaleUpPolicyIds(), cmd.getScaleDownPolicyIds());
s_logger.info("Successfully created Autoscale Vm Group with Id: " + vmGroupVO.getId());
return vmGroupVO;
}
@ -747,6 +748,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
}
txn.commit();
s_logger.info("Successfully deleted autoscale vm group id : " + id);
return success; // Successfull
}
@ -923,6 +925,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
s_logger.warn("Failed to enable AutoScale Vm Group id : " + id);
return null;
}
s_logger.info("Successfully enabled AutoScale Vm Group with Id:" + id);
}
return vmGroup;
}
@ -940,7 +943,6 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
try {
vmGroup.setState(AutoScaleVmGroup.State_Disabled);
vmGroup = _autoScaleVmGroupDao.persist(vmGroup);
success = configureAutoScaleVmGroup(id);
} finally {
if (!success) {
@ -949,6 +951,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
s_logger.warn("Failed to disable AutoScale Vm Group id : " + id);
return null;
}
s_logger.info("Successfully disabled AutoScale Vm Group with Id:" + id);
}
return vmGroup;
}

View File

@ -220,7 +220,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
serviceResponse.setName(service.getName());
if ("Lb".equalsIgnoreCase(service.getName())) {
Map<Capability, String> serviceCapabilities = serviceCapabilitiesMap
.get(service);
.get(service);
if (serviceCapabilities != null) {
for (Capability capability : serviceCapabilities
.keySet()) {
@ -304,15 +304,18 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
} catch (ResourceUnavailableException e) {
s_logger.warn("Unable to configure AutoScaleVmGroup to the lb rule: " + loadBalancer.getId() + " because resource is unavaliable:", e);
} finally {
if (!success && isRollBackAllowedForProvider(loadBalancer)) {
if (!success) {
s_logger.warn("Failed to configure LB Auto Scale Vm Group with Id:" + vmGroupid);
if (isRollBackAllowedForProvider(loadBalancer)) {
loadBalancer.setState(backupState);
_lbDao.persist(loadBalancer);
s_logger.debug("LB Rollback rule id: " + loadBalancer.getId() + " lb state rolback while creating AutoscaleVmGroup");
}
}
success = false;
}
if(success) {
if (success) {
if (vmGroup.getState().equals(AutoScaleVmGroup.State_New)) {
Transaction.currentTxn().start();
loadBalancer.setState(FirewallRule.State.Active);
@ -320,10 +323,11 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
_lbDao.persist(loadBalancer);
vmGroup.setState(AutoScaleVmGroup.State_Enabled);
_autoScaleVmGroupDao.persist(vmGroup);
s_logger.debug("LB Auto Scale Vm Group with Id: " + vmGroupid + " is set to Enabled state.");
Transaction.currentTxn().commit();
}
s_logger.info("Successfully configured LB Autoscale Vm Group with Id: " + vmGroupid);
}
return success;
}
@ -457,7 +461,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
LoadBalancerVO loadBalancer = _lbDao.findById(cmd.getLbRuleId());
if (loadBalancer == null) {
throw new InvalidParameterException("Invalid Load balancer Id:" + cmd.getLbRuleId());
throw new InvalidParameterException("Invalid Load balancer Id:" + cmd.getLbRuleId());
}
FirewallRule.State backupState = loadBalancer.getState();
loadBalancer.setState(FirewallRule.State.Add);
@ -469,7 +473,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
if (isRollBackAllowedForProvider(loadBalancer)) {
loadBalancer.setState(backupState);
_lbDao.persist(loadBalancer);
s_logger.debug("LB Rollback rule id: " + loadBalancer.getId() + " lb state rolback while creating sticky policy" );
s_logger.debug("LB Rollback rule id: " + loadBalancer.getId() + " lb state rolback while creating sticky policy");
}
deleteLBStickinessPolicy(cmd.getEntityId(), false);
success = false;
@ -524,7 +528,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
success = false;
}
}else{
} else {
_lb2stickinesspoliciesDao.remove(stickinessPolicy.getLoadBalancerId());
}
@ -606,7 +610,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
}
txn.commit();
if(_autoScaleVmGroupDao.isAutoScaleLoadBalancer(loadBalancerId)) {
if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(loadBalancerId)) {
// Nothing needs to be done for an autoscaled loadbalancer,
// just persist and proceed.
return true;
@ -638,7 +642,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
}
if(!success){
if (!success) {
CloudRuntimeException ex = new CloudRuntimeException("Failed to add specified loadbalancerruleid for vms " + instanceIds);
ex.addProxyObject(loadBalancer, loadBalancerId, "loadBalancerId");
// TBD: Also pack in the instanceIds in the exception using the right VO object or table name.
@ -677,7 +681,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
s_logger.debug("Set load balancer rule for revoke: rule id " + loadBalancerId + ", vmId " + instanceId);
}
if(_autoScaleVmGroupDao.isAutoScaleLoadBalancer(loadBalancerId)) {
if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(loadBalancerId)) {
// Nothing needs to be done for an autoscaled loadbalancer,
// just persist and proceed.
return true;
@ -706,7 +710,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
}
s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
}
if(!success){
if (!success) {
CloudRuntimeException ex = new CloudRuntimeException("Failed to remove specified load balancer rule id for vms " + instanceIds);
ex.addProxyObject(loadBalancer, loadBalancerId, "loadBalancerId");
throw ex;
@ -879,7 +883,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
if (ipAddrId != null) {
ipVO = _ipAddressDao.findById(ipAddrId);
}
Network network = _networkMgr.getNetwork(lb.getNetworkId());
LoadBalancer result = _elbMgr.handleCreateLoadBalancerRule(lb, lbOwner, lb.getNetworkId());
@ -892,7 +896,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
lb.setSourceIpAddressId(systemIp.getId());
ipVO = _ipAddressDao.findById(systemIp.getId());
}
// Validate ip address
if (ipVO == null) {
throw new InvalidParameterValueException("Unable to create load balance rule; can't find/allocate source IP", null);
@ -901,20 +905,20 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
}
try {
if (ipVO.getAssociatedWithNetworkId() == null) {
boolean assignToVpcNtwk = network.getVpcId() != null
&& ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId();
if (assignToVpcNtwk) {
//set networkId just for verification purposes
_networkMgr.checkIpForService(ipVO, Service.Lb, lb.getNetworkId());
if (ipVO.getAssociatedWithNetworkId() == null) {
boolean assignToVpcNtwk = network.getVpcId() != null
&& ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId();
if (assignToVpcNtwk) {
//set networkId just for verification purposes
_networkMgr.checkIpForService(ipVO, Service.Lb, lb.getNetworkId());
s_logger.debug("The ip is not associated with the VPC network id="+ lb.getNetworkId() + " so assigning");
s_logger.debug("The ip is not associated with the VPC network id="+ lb.getNetworkId() + " so assigning");
ipVO = _networkMgr.associateIPToGuestNetwork(ipAddrId, lb.getNetworkId(), false);
performedIpAssoc = true;
}
} else {
_networkMgr.checkIpForService(ipVO, Service.Lb, null);
performedIpAssoc = true;
}
} else {
_networkMgr.checkIpForService(ipVO, Service.Lb, null);
}
if (ipVO.getAssociatedWithNetworkId() == null) {
throw new InvalidParameterValueException("Ip address " + ipVO + " is not assigned to the network " + network);
@ -939,9 +943,9 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
ipVO = _ipAddressDao.findById(ipVO.getId());
_networkMgr.unassignIPFromVpcNetwork(ipVO.getId(), lb.getNetworkId());
}
}
}
}
if (result == null) {
throw new CloudRuntimeException("Failed to create load balancer rule: " + lb.getName());
@ -1309,7 +1313,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
if (lbBackup.getDescription() != null) {
lb.setDescription(lbBackup.getDescription());
}
if (lbBackup.getAlgorithm() != null){
if (lbBackup.getAlgorithm() != null) {
lb.setAlgorithm(lbBackup.getAlgorithm());
}
lb.setState(lbBackup.getState());
@ -1461,7 +1465,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
if (tags != null && !tags.isEmpty()) {
SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
for (int count=0; count < tags.size(); count++) {
for (int count = 0; count < tags.size(); count++) {
tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
tagSearch.cp();
@ -1537,7 +1541,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
//remove the rule
_lbDao.remove(rule.getId());
//if the rule is the last one for the ip address assigned to VPC, unassign it from the network
// if the rule is the last one for the ip address assigned to VPC, unassign it from the network
IpAddress ip = _ipAddressDao.findById(rule.getSourceIpAddressId());
_networkMgr.unassignIPFromVpcNetwork(ip.getId(), rule.getNetworkId());