External UUID control support for AutoscaleVmProfile and AutoscaleVmGroup

This commit is contained in:
Alena Prokharchyk 2014-02-04 11:10:44 -08:00
parent 6af6ce7e9e
commit 7cd0ad336b
5 changed files with 46 additions and 16 deletions

View File

@ -19,25 +19,24 @@ package org.apache.cloudstack.api.command.user.autoscale;
import java.util.List;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandJobType;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.AutoScalePolicyResponse;
import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.log4j.Logger;
import com.cloud.event.EventTypes;
import com.cloud.network.as.AutoScaleVmGroup;
import com.cloud.user.Account;
@APICommand(name = "updateAutoScaleVmGroup", description = "Updates an existing autoscale vm group.", responseObject = AutoScaleVmGroupResponse.class)
public class UpdateAutoScaleVmGroupCmd extends BaseAsyncCmd {
public class UpdateAutoScaleVmGroupCmd extends BaseAsyncCustomIdCmd {
public static final Logger s_logger = Logger.getLogger(UpdateAutoScaleVmGroupCmd.class.getName());
private static final String s_name = "updateautoscalevmgroupresponse";
@ -154,4 +153,11 @@ public class UpdateAutoScaleVmGroupCmd extends BaseAsyncCmd {
public ApiCommandJobType getInstanceType() {
return ApiCommandJobType.AutoScaleVmGroup;
}
@Override
public void checkUuid(String id, Class<?> cls) {
if (this.getCustomId() != null) {
_uuidMgr.checkUuid(this.getCustomId(), AutoScaleVmGroup.class);
}
}
}

View File

@ -19,26 +19,25 @@ package org.apache.cloudstack.api.command.user.autoscale;
import java.util.Map;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandJobType;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
import org.apache.cloudstack.api.response.TemplateResponse;
import org.apache.cloudstack.api.response.UserResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.log4j.Logger;
import com.cloud.event.EventTypes;
import com.cloud.network.as.AutoScaleVmProfile;
import com.cloud.user.Account;
@APICommand(name = "updateAutoScaleVmProfile", description = "Updates an existing autoscale vm profile.", responseObject = AutoScaleVmProfileResponse.class)
public class UpdateAutoScaleVmProfileCmd extends BaseAsyncCmd {
public class UpdateAutoScaleVmProfileCmd extends BaseAsyncCustomIdCmd {
public static final Logger s_logger = Logger.getLogger(UpdateAutoScaleVmProfileCmd.class.getName());
private static final String s_name = "updateautoscalevmprofileresponse";
@ -146,4 +145,11 @@ public class UpdateAutoScaleVmProfileCmd extends BaseAsyncCmd {
public ApiCommandJobType getInstanceType() {
return ApiCommandJobType.AutoScaleVmProfile;
}
@Override
public void checkUuid(String id, Class<?> cls) {
if (this.getCustomId() != null) {
_uuidMgr.checkUuid(this.getCustomId(), AutoScaleVmProfile.class);
}
}
}

View File

@ -208,4 +208,8 @@ public class AutoScaleVmGroupVO implements AutoScaleVmGroup, InternalIdentity {
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}

View File

@ -216,4 +216,8 @@ public class AutoScaleVmProfileVO implements AutoScaleVmProfile, Identity, Inter
public long getAutoScaleUserId() {
return autoscaleUserId;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}

View File

@ -53,7 +53,6 @@ import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
import org.apache.cloudstack.config.ApiServiceConfiguration;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.log4j.Logger;
import com.cloud.api.ApiDBUtils;
@ -119,7 +118,6 @@ import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.UserVmManager;
import com.cloud.vm.UserVmService;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
@ -394,6 +392,8 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
AutoScaleVmProfileVO vmProfile = getEntityInDatabase(CallContext.current().getCallingAccount(), "Auto Scale Vm Profile", profileId, _autoScaleVmProfileDao);
boolean physicalParameterUpdate = (templateId != null || autoscaleUserId != null || counterParamList != null || destroyVmGraceperiod != null);
if (templateId != null) {
vmProfile.setTemplateId(templateId);
}
@ -410,9 +410,13 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
vmProfile.setDestroyVmGraceperiod(destroyVmGraceperiod);
}
final List<AutoScaleVmGroupVO> vmGroupList = _autoScaleVmGroupDao.listByAll(null, profileId);
for (final AutoScaleVmGroupVO vmGroupVO : vmGroupList) {
if (!vmGroupVO.getState().equals(AutoScaleVmGroup.State_Disabled)) {
if (cmd.getCustomId() != null) {
vmProfile.setUuid(cmd.getCustomId());
}
List<AutoScaleVmGroupVO> vmGroupList = _autoScaleVmGroupDao.listByAll(null, profileId);
for (AutoScaleVmGroupVO vmGroupVO : vmGroupList) {
if (physicalParameterUpdate && !vmGroupVO.getState().equals(AutoScaleVmGroup.State_Disabled)) {
throw new InvalidParameterValueException("The AutoScale Vm Profile can be updated only if the Vm Group it is associated with is disabled in state");
}
}
@ -976,8 +980,10 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
AutoScaleVmGroupVO vmGroupVO = getEntityInDatabase(CallContext.current().getCallingAccount(), "AutoScale Vm Group", vmGroupId, _autoScaleVmGroupDao);
if (!vmGroupVO.getState().equals(AutoScaleVmGroup.State_Disabled)) {
throw new InvalidParameterValueException("An AutoScale Vm Group can be updated only when it is in disabled state");
boolean physicalParametersUpdate = (minMembers != null || maxMembers != null || interval != null);
if (physicalParametersUpdate && !vmGroupVO.getState().equals(AutoScaleVmGroup.State_Disabled)) {
throw new InvalidParameterValueException("An AutoScale Vm Group can be updated with minMembers/maxMembers/Interval only when it is in disabled state");
}
if (minMembers != null) {
@ -988,10 +994,14 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
vmGroupVO.setMaxMembers(maxMembers);
}
if (interval != null) {
if (maxMembers != null) {
vmGroupVO.setInterval(interval);
}
if (cmd.getCustomId() != null) {
vmGroupVO.setUuid(cmd.getCustomId());
}
vmGroupVO = checkValidityAndPersist(vmGroupVO, scaleUpPolicyIds, scaleDownPolicyIds);
if (vmGroupVO != null) {
s_logger.debug("Updated Auto Scale VmGroup id:" + vmGroupId);