Improved logging in AutoScale APIs

This commit is contained in:
Deepak Garg 2012-07-18 17:13:25 +05:30 committed by Vijay
parent 349ab92ffc
commit a96df19b68
5 changed files with 50 additions and 49 deletions

View File

@ -28,30 +28,29 @@ import com.cloud.network.as.AutoScalePolicy;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@Implementation(description="Deletes a autoscale policy.", responseObject=SuccessResponse.class)
@Implementation(description = "Deletes a autoscale policy.", responseObject = SuccessResponse.class)
public class DeleteAutoScalePolicyCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(DeleteAutoScalePolicyCmd.class.getName());
private static final String s_name = "deleteautoscalepolicyresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@IdentityMapper(entityTableName="autoscale_policies")
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the autoscale policy")
@IdentityMapper(entityTableName = "autoscale_policies")
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = true, description = "the ID of the autoscale policy")
private Long id;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public String getCommandName() {
@ -65,7 +64,8 @@ public class DeleteAutoScalePolicyCmd extends BaseAsyncCmd {
return autoScalePolicy.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 DeleteAutoScalePolicyCmd extends BaseAsyncCmd {
@Override
public String getEventDescription() {
return "deleting AutoScale Policy: " + getId();
return "deleting AutoScale Policy: " + getId();
}
@Override
public void execute(){
UserContext.current().setEventDetails("AutoScale Policy Id: "+getId());
public void execute() {
UserContext.current().setEventDetails("AutoScale Policy Id: " + getId());
boolean result = _autoScaleService.deleteAutoScalePolicy(id);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
s_logger.info("Successfully deleted autoscale policy id : " + getId());
this.setResponseObject(response);
} else {
s_logger.warn("Failed to delete autoscale policy " + getId());

View File

@ -28,30 +28,29 @@ import com.cloud.network.as.AutoScaleVmProfile;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@Implementation(description="Deletes a autoscale vm profile.", responseObject=SuccessResponse.class)
@Implementation(description = "Deletes a autoscale vm profile.", responseObject = SuccessResponse.class)
public class DeleteAutoScaleVmProfileCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(DeleteAutoScaleVmProfileCmd.class.getName());
private static final String s_name = "deleteautoscalevmprofileresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@IdentityMapper(entityTableName="autoscale_vmprofiles")
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the autoscale profile")
@IdentityMapper(entityTableName = "autoscale_vmprofiles")
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = true, description = "the ID of the autoscale profile")
private Long id;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public String getCommandName() {
@ -65,7 +64,8 @@ public class DeleteAutoScaleVmProfileCmd extends BaseAsyncCmd {
return autoScaleVmProfile.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,16 +75,15 @@ public class DeleteAutoScaleVmProfileCmd extends BaseAsyncCmd {
@Override
public String getEventDescription() {
return "deleting autoscale vm profile: " + getId();
return "deleting autoscale vm profile: " + getId();
}
@Override
public void execute(){
UserContext.current().setEventDetails("AutoScale VM Profile Id: "+getId());
public void execute() {
UserContext.current().setEventDetails("AutoScale VM Profile Id: " + getId());
boolean result = _autoScaleService.deleteAutoScaleVmProfile(id);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
s_logger.info("Successfully deleted autoscale vm profile id : " + getId());
this.setResponseObject(response);
} else {
s_logger.warn("Failed to delete autoscale vm profile " + getId());

View File

@ -61,7 +61,6 @@ public class DeleteConditionCmd extends BaseAsyncCmd {
}
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
s_logger.info("Successfully deleted condition id : " + getId());
this.setResponseObject(response);
} else {
s_logger.warn("Failed to delete condition " + getId());

View File

@ -61,10 +61,9 @@ public class DeleteCounterCmd extends BaseAsyncCmd {
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
s_logger.info("Successfully deleted counter id : " + getId());
this.setResponseObject(response);
} else {
s_logger.warn("Failed to delete counter");
s_logger.warn("Failed to delete counter with Id: " + getId());
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete counter.");
}
}

View File

@ -321,6 +321,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
AutoScaleVmProfileVO profileVO = new AutoScaleVmProfileVO(cmd.getZoneId(), cmd.getDomainId(), cmd.getAccountId(), cmd.getServiceOfferingId(), cmd.getTemplateId(), cmd.getOtherDeployParams(),
cmd.getSnmpCommunity(), cmd.getSnmpPort(), cmd.getDestroyVmGraceperiod(), autoscaleUserId, csUrl);
profileVO = checkValidityAndPersist(profileVO);
s_logger.info("Successfully create AutoScale Vm Profile with Id: " + profileVO.getId());
return profileVO;
}
@ -366,7 +367,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
}
vmProfile = checkValidityAndPersist(vmProfile);
s_logger.debug("Updated Auto Scale Vm Profile id:" + vmProfile.getId());
s_logger.info("Updated Auto Scale Vm Profile id:" + vmProfile.getId());
return vmProfile;
}
@ -380,7 +381,9 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
if (_autoScaleVmGroupDao.isProfileInUse(id)) {
throw new InvalidParameterValueException("Cannot delete AutoScale Vm Profile when it is in use by one more vm groups");
}
return _autoScaleVmProfileDao.remove(id);
boolean success = _autoScaleVmProfileDao.remove(id);
s_logger.info("Successfully deleted AutoScale Vm Profile with Id: " + id);
return success;
}
@Override
@ -486,7 +489,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
AutoScalePolicyVO policyVO = new AutoScalePolicyVO(cmd.getDomainId(), cmd.getAccountId(), duration, quietTime, action);
policyVO = checkValidityAndPersist(policyVO, cmd.getConditionIds());
s_logger.info("Successfully created AutoScale Policy with Id: " + policyVO.getId());
return policyVO;
}
@ -516,6 +519,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
return false;
}
txn.commit();
s_logger.info("Successfully deleted autoscale policy id : " + id);
return success; // successful
}
@ -638,8 +642,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
}
policy = checkValidityAndPersist(policy, conditionIds);
s_logger.debug("Updated Auto Scale Policy id:" + policyId);
s_logger.info("Successfully updated Auto Scale Policy id:" + policyId);
return policy;
}
@ -1003,8 +1006,8 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
}
ConditionVO condition = null;
s_logger.debug("Adding Condition ");
condition = _conditionDao.persist(new ConditionVO(cid, threshold, cmd.getEntityOwnerId(), cmd.getDomainId(), op));
s_logger.info("Successfully created condition with Id: " + condition.getId());
UserContext.current().setEventDetails(" Id: " + condition.getId());
return condition;
@ -1066,8 +1069,10 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
throw new ResourceInUseException("Counter is in use.");
}
s_logger.debug("Deleting Counter " + counter.getName());
return _counterDao.remove(counterId);
boolean success = _counterDao.remove(counterId);
s_logger.info("Successfully deleted counter with Id: " + counterId);
return success;
}
@Override
@ -1084,8 +1089,8 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
s_logger.info("Cannot delete condition " + conditionId + " as it is being used in a condition.");
throw new ResourceInUseException("Cannot delete Condition when it is in use by one or more AutoScale Policies.");
}
s_logger.debug("Deleting Condition " + condition.getId());
return _conditionDao.remove(conditionId);
boolean success = _conditionDao.remove(conditionId);
s_logger.info("Successfully deleted condition " + condition.getId());
}
}