Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8dce419
CreateAutoScaleVmGroup.vue: fix spelling (6609)
weizhouapache Jul 24, 2023
8c5b19b
CreateAutoScaleVmGroup.vue: Remove unsupported params listall (6686)
weizhouapache Jul 24, 2023
030024f
CreateAutoScaleVmGroup.vue: support userdata ids (6202)
weizhouapache Jul 24, 2023
5ab2faf
CreateAutoScaleVmGroup.vue: fix same issue as DeployVM.vue (7758)
weizhouapache Jul 24, 2023
87d81eb
AutoScaling: support userdata id and userdata details
weizhouapache Jul 25, 2023
7d14881
AutoScaling: use DbUpgradeUtils.addForeignKey instead of SQL procedure
weizhouapache Jul 25, 2023
7d379fd
PR7769: add method convertDetailsToMap to BaseCmd
weizhouapache Jul 25, 2023
6d0088b
PR7769: use convertDetailsToMap in two other APIs
weizhouapache Jul 26, 2023
3199dd2
AutoScaling: update marvin test
weizhouapache Jul 27, 2023
5118b19
PR6669: fix userdata details are not passed on UI
weizhouapache Jul 28, 2023
cb31541
PR6669: add userdata id/name/details/policy to vmprofile response
weizhouapache Jul 28, 2023
f8938af
PR6669: set httpmethod for Async commands
weizhouapache Jul 28, 2023
e23124b
Merge remote-tracking branch 'apache/4.18' into 4.18-asgroup-add-user…
weizhouapache Aug 14, 2023
6a94a1a
PR7769: add unit tests in AutoScaleVmProfileVOTest
weizhouapache Aug 15, 2023
1f9da7f
PR7796: add unit tests in AutoScaleManagerImplTest
weizhouapache Aug 16, 2023
ea32253
PR7769: add unit tests in ApiResponseHelperTest
weizhouapache Aug 16, 2023
6e12939
PR7769: add more unit tests in AutoScaleManagerImplTest
weizhouapache Aug 16, 2023
bb79878
Merge remote-tracking branch 'apache/4.18' into 4.18-asgroup-add-user…
weizhouapache Aug 16, 2023
63e9aff
PR7769: add more unit tests in ApiResponseHelperTest
weizhouapache Aug 16, 2023
6a1df6e
Merge remote-tracking branch 'apache/4.18' into 4.18-asgroup-add-user…
weizhouapache Aug 17, 2023
8d4aa1a
Merge branch '4.18' into 4.18-asgroup-add-userdata-support
weizhouapache Aug 17, 2023
5ba953d
Merge branch '4.18' into 4.18-asgroup-add-userdata-support
weizhouapache Aug 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/BaseCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
Expand All @@ -42,6 +44,7 @@
import org.apache.cloudstack.query.QueryService;
import org.apache.cloudstack.storage.ImageStoreService;
import org.apache.cloudstack.usage.UsageService;
import org.apache.commons.collections.MapUtils;
import org.apache.log4j.Logger;

import com.cloud.configuration.ConfigurationService;
Expand Down Expand Up @@ -456,4 +459,18 @@ public ApiCommandResourceType getApiResourceType() {
return ApiCommandResourceType.None;
}

public Map<String, String> convertDetailsToMap(Map details) {
Map<String, String> detailsMap = new HashMap<String, String>();
if (MapUtils.isNotEmpty(details)) {
Collection parameterCollection = details.values();
Iterator iter = parameterCollection.iterator();
while (iter.hasNext()) {
HashMap<String, String> value = (HashMap<String, String>)iter.next();
for (Map.Entry<String,String> entry: value.entrySet()) {
detailsMap.put(entry.getKey(),entry.getValue());
}
}
}
return detailsMap;
}
Comment thread
weizhouapache marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.cloudstack.api.response.ProjectResponse;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
import org.apache.cloudstack.api.response.TemplateResponse;
import org.apache.cloudstack.api.response.UserDataResponse;
import org.apache.cloudstack.api.response.UserResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.context.CallContext;
Expand Down Expand Up @@ -107,6 +108,12 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd {
since = "4.18.0")
private String userData;

@Parameter(name = ApiConstants.USER_DATA_ID, type = CommandType.UUID, entityType = UserDataResponse.class, description = "the ID of the Userdata", since = "4.18.1")
private Long userDataId;

@Parameter(name = ApiConstants.USER_DATA_DETAILS, type = CommandType.MAP, description = "used to specify the parameters values for the variables in userdata.", since = "4.18.1")
private Map userDataDetails;

@Parameter(name = ApiConstants.AUTOSCALE_USER_ID,
type = CommandType.UUID,
entityType = UserResponse.class,
Expand Down Expand Up @@ -163,6 +170,14 @@ public String getUserData() {
return userData;
}

public Long getUserDataId() {
return userDataId;
}

public Map<String, String> getUserDataDetails() {
return convertDetailsToMap(userDataDetails);
}

public Long getAutoscaleUserId() {
return autoscaleUserId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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.UserDataResponse;
import org.apache.cloudstack.api.response.UserResponse;
import org.apache.cloudstack.context.CallContext;

Expand Down Expand Up @@ -102,6 +103,14 @@ public class UpdateAutoScaleVmProfileCmd extends BaseAsyncCustomIdCmd {
since = "4.18.0")
private String userData;

@Parameter(name = ApiConstants.USER_DATA_ID, type = CommandType.UUID, entityType = UserDataResponse.class, description = "the ID of the userdata",
since = "4.18.1")
private Long userdataId;

@Parameter(name = ApiConstants.USER_DATA_DETAILS, type = CommandType.MAP, description = "used to specify the parameters values for the variables in userdata.",
since = "4.18.1")
private Map userdataDetails;

@Parameter(name = ApiConstants.AUTOSCALE_USER_ID,
type = CommandType.UUID,
entityType = UserResponse.class,
Expand Down Expand Up @@ -156,6 +165,14 @@ public String getUserData() {
return userData;
}

public Long getUserdataId() {
return userdataId;
}

public Map<String, String> getUserdataDetails() {
return convertDetailsToMap(userdataDetails);
}

public Long getAutoscaleUserId() {
return autoscaleUserId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,8 @@ public ApiConstants.BootType getBootType() {
}

public Map<String, String> getDetails() {
Map<String, String> customparameterMap = new HashMap<String, String>();
if (details != null && details.size() != 0) {
Collection parameterCollection = details.values();
Iterator iter = parameterCollection.iterator();
while (iter.hasNext()) {
HashMap<String, String> value = (HashMap<String, String>)iter.next();
for (Map.Entry<String,String> entry: value.entrySet()) {
customparameterMap.put(entry.getKey(),entry.getValue());
}
}
}
Map<String, String> customparameterMap = convertDetailsToMap(details);

if (getBootType() != null) {
customparameterMap.put(getBootType().toString(), getBootMode().toString());
}
Expand Down Expand Up @@ -450,18 +441,7 @@ public Long getUserdataId() {
}

public Map<String, String> getUserdataDetails() {
Map<String, String> userdataDetailsMap = new HashMap<String, String>();
if (userdataDetails != null && userdataDetails.size() != 0) {
Collection parameterCollection = userdataDetails.values();
Iterator iter = parameterCollection.iterator();
while (iter.hasNext()) {
HashMap<String, String> value = (HashMap<String, String>)iter.next();
for (Map.Entry<String,String> entry: value.entrySet()) {
userdataDetailsMap.put(entry.getKey(),entry.getValue());
}
}
}
return userdataDetailsMap;
return convertDetailsToMap(userdataDetails);
}

public Long getZoneId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
import org.apache.cloudstack.context.CallContext;
import org.apache.log4j.Logger;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

@APICommand(name = "resetUserDataForVirtualMachine", responseObject = UserVmResponse.class, description = "Resets the UserData for virtual machine. " +
Expand Down Expand Up @@ -117,18 +114,7 @@ public Long getUserdataId() {
}

public Map<String, String> getUserdataDetails() {
Map<String, String> userdataDetailsMap = new HashMap<String, String>();
if (userdataDetails != null && userdataDetails.size() != 0) {
Collection parameterCollection = userdataDetails.values();
Iterator iter = parameterCollection.iterator();
while (iter.hasNext()) {
HashMap<String, String> value = (HashMap<String, String>)iter.next();
for (Map.Entry<String,String> entry: value.entrySet()) {
userdataDetailsMap.put(entry.getKey(),entry.getValue());
}
}
}
return userdataDetailsMap;
return convertDetailsToMap(userdataDetails);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -176,18 +175,7 @@ public Long getUserdataId() {
}

public Map<String, String> getUserdataDetails() {
Map<String, String> userdataDetailsMap = new HashMap<String, String>();
if (userdataDetails != null && userdataDetails.size() != 0) {
Collection parameterCollection = userdataDetails.values();
Iterator iter = parameterCollection.iterator();
while (iter.hasNext()) {
HashMap<String, String> value = (HashMap<String, String>)iter.next();
for (Map.Entry<String,String> entry: value.entrySet()) {
userdataDetailsMap.put(entry.getKey(),entry.getValue());
}
}
}
return userdataDetailsMap;
return convertDetailsToMap(userdataDetails);
}

public Boolean getDisplayVm() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ public class AutoScaleVmProfileVO implements AutoScaleVmProfile, Identity, Inter
@Basic(fetch = FetchType.LAZY)
private String userData;

@Column(name = "user_data_id", nullable = true)
private Long userDataId = null;

@Column(name = "user_data_details", updatable = true, length = 4096)
private String userDataDetails;

@Column(name = GenericDao.REMOVED_COLUMN)
protected Date removed;

Expand Down Expand Up @@ -228,6 +234,22 @@ public String getUserData() {
return userData;
}

public Long getUserDataId() {
return userDataId;
}

public void setUserDataId(Long userDataId) {
this.userDataId = userDataId;
}

public String getUserDataDetails() {
return userDataDetails;
}

public void setUserDataDetails(String userDataDetails) {
this.userDataDetails = userDataDetails;
}

@Override
public String getUuid() {
return uuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public InputStream[] getPrepareScripts() {
@Override
public void performDataMigration(Connection conn) {
fixForeignKeyNames(conn);
addForeignKeyToAutoscaleVmprofiles(conn);
}

@Override
Expand Down Expand Up @@ -111,4 +112,8 @@ private void fixForeignKeyNames(Connection conn) {
DbUpgradeUtils.dropKeysIfExist(conn, "cloud.volumes", keys, false);
DbUpgradeUtils.addForeignKey(conn, "volumes", "passphrase_id","passphrase", "id");
}

private void addForeignKeyToAutoscaleVmprofiles(Connection conn) {
DbUpgradeUtils.addForeignKey(conn, "autoscale_vmprofiles", "user_data_id","user_data", "id");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (6, 'Windows Server 2022 (64-bit)', 'VM
CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (6, 'Windows Server 2022 (64-bit)', 'VMware', '8.0', 'windows2019srvNext_64Guest');
CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (6, 'Windows Server 2022 (64-bit)', 'VMware', '8.0.0.1', 'windows2019srvNext_64Guest');
CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (6, 'Windows Server 2022 (64-bit)', 'Xenserver', '8.2.0', 'Windows Server 2022 (64-bit)');

-- Support userdata ids and details in VM AutoScaling
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.autoscale_vmprofiles', 'user_data_id', 'bigint unsigned DEFAULT NULL COMMENT "id of the user data" AFTER `user_data`');
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.autoscale_vmprofiles', 'user_data_details', 'mediumtext DEFAULT NULL COMMENT "value of the comma-separated list of parameters" AFTER `user_data_id`');
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ public AutoScaleVmProfile createAutoScaleVmProfile(CreateAutoScaleVmProfileCmd c
long zoneId = cmd.getZoneId();
long serviceOfferingId = cmd.getServiceOfferingId();
Long autoscaleUserId = cmd.getAutoscaleUserId();
String userData = cmd.getUserData();

DataCenter zone = entityMgr.findById(DataCenter.class, zoneId);

Expand All @@ -545,6 +544,11 @@ public AutoScaleVmProfile createAutoScaleVmProfile(CreateAutoScaleVmProfileCmd c
throw new InvalidParameterValueException("Unable to find service offering by id");
}

VirtualMachineTemplate template = entityMgr.findById(VirtualMachineTemplate.class, cmd.getTemplateId());
if (template == null) {
throw new InvalidParameterValueException("Unable to find template by id " + cmd.getTemplateId());
}

// validations
HashMap<String, String> deployParams = cmd.getDeployParamMap();
/*
Expand All @@ -562,9 +566,23 @@ public AutoScaleVmProfile createAutoScaleVmProfile(CreateAutoScaleVmProfileCmd c
profileVO.setDisplay(cmd.getDisplay());
}

String userData = cmd.getUserData();
Long userDataId = cmd.getUserDataId();
String userDataDetails = null;
if (MapUtils.isNotEmpty(cmd.getUserDataDetails())) {
userDataDetails = cmd.getUserDataDetails().toString();
}
userData = userVmMgr.finalizeUserData(userData, userDataId, template);
userData = userVmMgr.validateUserData(userData, cmd.getHttpMethod());
if (userData != null) {
profileVO.setUserData(userData);
}
if (userDataId != null) {
profileVO.setUserDataId(userDataId);
}
if (userDataDetails != null) {
profileVO.setUserDataDetails(userDataDetails);
}

profileVO = checkValidityAndPersist(profileVO, true);
s_logger.info("Successfully create AutoScale Vm Profile with Id: " + profileVO.getId());
Expand All @@ -582,12 +600,19 @@ public AutoScaleVmProfile updateAutoScaleVmProfile(UpdateAutoScaleVmProfileCmd c
Map<String, HashMap<String, String>> otherDeployParams = cmd.getOtherDeployParams();
Map counterParamList = cmd.getCounterParamList();
String userData = cmd.getUserData();
Long userDataId = cmd.getUserdataId();
String userDataDetails = null;
if (MapUtils.isNotEmpty(cmd.getUserdataDetails())) {
userDataDetails = cmd.getUserdataDetails().toString();
}
boolean userdataUpdate = userData != null || userDataId != null || MapUtils.isNotEmpty(cmd.getUserdataDetails());

Integer expungeVmGracePeriod = cmd.getExpungeVmGracePeriod();

AutoScaleVmProfileVO vmProfile = getEntityInDatabase(CallContext.current().getCallingAccount(), "Auto Scale Vm Profile", profileId, autoScaleVmProfileDao);

boolean physicalParameterUpdate = (templateId != null || autoscaleUserId != null || counterParamList != null || otherDeployParams != null || expungeVmGracePeriod != null || userData != null);
boolean physicalParameterUpdate = (templateId != null || autoscaleUserId != null || counterParamList != null
|| otherDeployParams != null || expungeVmGracePeriod != null || userdataUpdate);

if (serviceOfferingId != null) {
vmProfile.setServiceOfferingId(serviceOfferingId);
Expand All @@ -609,10 +634,6 @@ public AutoScaleVmProfile updateAutoScaleVmProfile(UpdateAutoScaleVmProfileCmd c
vmProfile.setCounterParamsForUpdate(counterParamList);
}

if (userData != null) {
vmProfile.setUserData(userData);
}

if (expungeVmGracePeriod != null) {
vmProfile.setExpungeVmGracePeriod(expungeVmGracePeriod);
}
Expand All @@ -625,6 +646,18 @@ public AutoScaleVmProfile updateAutoScaleVmProfile(UpdateAutoScaleVmProfileCmd c
vmProfile.setDisplay(cmd.getDisplay());
}

if (userdataUpdate) {
if (templateId == null) {
templateId = vmProfile.getTemplateId();
}
VirtualMachineTemplate template = entityMgr.findByIdIncludingRemoved(VirtualMachineTemplate.class, templateId);
userData = userVmMgr.finalizeUserData(userData, userDataId, template);
userData = userVmMgr.validateUserData(userData, cmd.getHttpMethod());
vmProfile.setUserDataId(userDataId);
vmProfile.setUserData(userData);
vmProfile.setUserDataDetails(userDataDetails);
}

List<AutoScaleVmGroupVO> vmGroupList = autoScaleVmGroupDao.listByAll(null, profileId);
for (AutoScaleVmGroupVO vmGroupVO : vmGroupList) {
if (physicalParameterUpdate && !vmGroupVO.getState().equals(AutoScaleVmGroup.State.DISABLED)) {
Expand Down Expand Up @@ -1740,6 +1773,8 @@ protected long createNewVM(AutoScaleVmGroupVO asGroup) {
}

String userData = profileVo.getUserData();
Long userDataId = profileVo.getUserDataId();
String userDataDetails = profileVo.getUserDataDetails();

UserVm vm = null;
IpAddresses addrs = new IpAddresses(null, null);
Expand All @@ -1763,20 +1798,20 @@ protected long createNewVM(AutoScaleVmGroupVO asGroup) {
if (zone.getNetworkType() == NetworkType.Basic) {
vm = userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, null, owner, vmHostName,
vmHostName, diskOfferingId, dataDiskSize, null,
hypervisorType, HTTPMethod.GET, userData, null, null, sshKeyPairs,
hypervisorType, HTTPMethod.GET, userData, userDataId, userDataDetails, sshKeyPairs,
null, null, true, null, affinityGroupIdList, customParameters, null, null, null,
null, true, overrideDiskOfferingId);
} else {
if (zone.isSecurityGroupEnabled()) {
vm = userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, networkIds, null,
owner, vmHostName,vmHostName, diskOfferingId, dataDiskSize, null,
hypervisorType, HTTPMethod.GET, userData, null, null, sshKeyPairs,
hypervisorType, HTTPMethod.GET, userData, userDataId, userDataDetails, sshKeyPairs,
null, null, true, null, affinityGroupIdList, customParameters, null, null, null,
null, true, overrideDiskOfferingId, null);
} else {
vm = userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, networkIds, owner, vmHostName, vmHostName,
diskOfferingId, dataDiskSize, null,
hypervisorType, HTTPMethod.GET, userData, null, null, sshKeyPairs,
hypervisorType, HTTPMethod.GET, userData, userDataId, userDataDetails, sshKeyPairs,
null, addrs, true, null, affinityGroupIdList, customParameters, null, null, null,
null, true, null, overrideDiskOfferingId);
}
Expand Down
Loading