Skip to content

Commit 2cccd53

Browse files
committed
Merge branch 'main' of https://github.com/apache/cloudstack into nsx-integration
2 parents b0933bb + 2e6100d commit 2cccd53

File tree

21 files changed

+147
-172
lines changed

21 files changed

+147
-172
lines changed

api/src/main/java/com/cloud/configuration/Resource.java

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,55 +22,34 @@ public interface Resource {
2222
String UNLIMITED = "Unlimited";
2323

2424
enum ResourceType { // Primary and Secondary storage are allocated_storage and not the physical storage.
25-
user_vm("user_vm", 0, ResourceOwnerType.Account, ResourceOwnerType.Domain),
26-
public_ip("public_ip", 1, ResourceOwnerType.Account, ResourceOwnerType.Domain),
27-
volume("volume", 2, ResourceOwnerType.Account, ResourceOwnerType.Domain),
28-
snapshot("snapshot", 3, ResourceOwnerType.Account, ResourceOwnerType.Domain),
29-
template("template", 4, ResourceOwnerType.Account, ResourceOwnerType.Domain),
30-
project("project", 5, ResourceOwnerType.Account, ResourceOwnerType.Domain),
31-
network("network", 6, ResourceOwnerType.Account, ResourceOwnerType.Domain),
32-
vpc("vpc", 7, ResourceOwnerType.Account, ResourceOwnerType.Domain),
33-
cpu("cpu", 8, ResourceOwnerType.Account, ResourceOwnerType.Domain),
34-
memory("memory", 9, ResourceOwnerType.Account, ResourceOwnerType.Domain),
35-
primary_storage("primary_storage", 10, ResourceOwnerType.Account, ResourceOwnerType.Domain),
36-
secondary_storage("secondary_storage", 11, ResourceOwnerType.Account, ResourceOwnerType.Domain);
25+
user_vm("user_vm", 0),
26+
public_ip("public_ip", 1),
27+
volume("volume", 2),
28+
snapshot("snapshot", 3),
29+
template("template", 4),
30+
project("project", 5),
31+
network("network", 6),
32+
vpc("vpc", 7),
33+
cpu("cpu", 8),
34+
memory("memory", 9),
35+
primary_storage("primary_storage", 10),
36+
secondary_storage("secondary_storage", 11);
3737

3838
private String name;
39-
private ResourceOwnerType[] supportedOwners;
4039
private int ordinal;
4140
public static final long bytesToKiB = 1024;
4241
public static final long bytesToMiB = bytesToKiB * 1024;
4342
public static final long bytesToGiB = bytesToMiB * 1024;
4443

45-
ResourceType(String name, int ordinal, ResourceOwnerType... supportedOwners) {
44+
ResourceType(String name, int ordinal) {
4645
this.name = name;
47-
this.supportedOwners = supportedOwners;
4846
this.ordinal = ordinal;
4947
}
5048

5149
public String getName() {
5250
return name;
5351
}
5452

55-
public ResourceOwnerType[] getSupportedOwners() {
56-
return supportedOwners;
57-
}
58-
59-
public boolean supportsOwner(ResourceOwnerType ownerType) {
60-
boolean success = false;
61-
if (supportedOwners != null) {
62-
int length = supportedOwners.length;
63-
for (int i = 0; i < length; i++) {
64-
if (supportedOwners[i].getName().equalsIgnoreCase(ownerType.getName())) {
65-
success = true;
66-
break;
67-
}
68-
}
69-
}
70-
71-
return success;
72-
}
73-
7453
public int getOrdinal() {
7554
return ordinal;
7655
}

api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ public abstract class AbstractGetUploadParamsCmd extends BaseCmd {
3131

3232
public static final Logger s_logger = Logger.getLogger(AbstractGetUploadParamsCmd.class.getName());
3333

34-
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the volume/template")
34+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the volume/template/iso")
3535
private String name;
3636

37-
@Parameter(name = ApiConstants.FORMAT, type = CommandType.STRING, required = true, description = "the format for the volume/template. Possible values include QCOW2, OVA, "
37+
@Parameter(name = ApiConstants.FORMAT, type = CommandType.STRING, required = true, description = "the format for the volume/template/iso. Possible values include QCOW2, OVA, "
3838
+ "and VHD.")
3939
private String format;
4040

41-
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, description = "the ID of the zone the volume/template is "
41+
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, description = "the ID of the zone the volume/template/iso is "
4242
+ "to be hosted on")
4343
private Long zoneId;
4444

45-
@Parameter(name = ApiConstants.CHECKSUM, type = CommandType.STRING, description = "the checksum value of this volume/template " + ApiConstants.CHECKSUM_PARAMETER_PREFIX_DESCRIPTION)
45+
@Parameter(name = ApiConstants.CHECKSUM, type = CommandType.STRING, description = "the checksum value of this volume/template/iso " + ApiConstants.CHECKSUM_PARAMETER_PREFIX_DESCRIPTION)
4646
private String checksum;
4747

4848
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "an optional accountName. Must be used with domainId.")
@@ -52,7 +52,7 @@ public abstract class AbstractGetUploadParamsCmd extends BaseCmd {
5252
+ "domainId must also be used.")
5353
private Long domainId;
5454

55-
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "Upload volume/template for the project")
55+
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "Upload volume/template/iso for the project")
5656
private Long projectId;
5757

5858
public String getName() {

api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.apache.cloudstack.api.ServerApiException;
2929
import org.apache.cloudstack.api.response.GetUploadParamsResponse;
3030
import org.apache.cloudstack.api.response.GuestOSResponse;
31-
import org.apache.cloudstack.api.response.ZoneResponse;
3231
import org.apache.cloudstack.context.CallContext;
3332

3433
import com.cloud.exception.ConcurrentOperationException;
@@ -37,15 +36,13 @@
3736
import com.cloud.exception.ResourceAllocationException;
3837
import com.cloud.exception.ResourceUnavailableException;
3938

40-
@APICommand(name = GetUploadParamsForIsoCmd.APINAME,
39+
@APICommand(name = "getUploadParamsForIso",
4140
description = "upload an existing ISO into the CloudStack cloud.",
4241
responseObject = GetUploadParamsResponse.class, since = "4.13",
4342
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User},
4443
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
4544
public class GetUploadParamsForIsoCmd extends AbstractGetUploadParamsCmd {
4645

47-
public static final String APINAME = "getUploadParamsForIso";
48-
4946
private static final String s_name = "postuploadisoresponse";
5047

5148
/////////////////////////////////////////////////////
@@ -73,19 +70,12 @@ public class GetUploadParamsForIsoCmd extends AbstractGetUploadParamsCmd {
7370
@Parameter(name = ApiConstants.IS_EXTRACTABLE, type = BaseCmd.CommandType.BOOLEAN, description = "true if the ISO or its derivatives are extractable; default is false")
7471
private Boolean extractable;
7572

76-
@Parameter(name = ApiConstants.NAME, type = BaseCmd.CommandType.STRING, required = true, description = "the name of the ISO")
77-
private String isoName;
78-
7973
@Parameter(name = ApiConstants.OS_TYPE_ID,
8074
type = BaseCmd.CommandType.UUID,
8175
entityType = GuestOSResponse.class,
8276
description = "the ID of the OS type that best represents the OS of this ISO. If the ISO is bootable this parameter needs to be passed")
8377
private Long osTypeId;
8478

85-
@Parameter(name=ApiConstants.ZONE_ID, type= BaseCmd.CommandType.UUID, entityType = ZoneResponse.class,
86-
required=true, description="the ID of the zone you wish to register the ISO to.")
87-
protected Long zoneId;
88-
8979
/////////////////////////////////////////////////////
9080
/////////////////// Accessors ///////////////////////
9181
/////////////////////////////////////////////////////
@@ -110,17 +100,10 @@ public Boolean isExtractable() {
110100
return extractable;
111101
}
112102

113-
public String getIsoName() {
114-
return isoName;
115-
}
116-
117103
public Long getOsTypeId() {
118104
return osTypeId;
119105
}
120106

121-
public Long getZoneId() {
122-
return zoneId;
123-
}
124107

125108
/////////////////////////////////////////////////////
126109
/////////////// API Implementation///////////////////
@@ -134,7 +117,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
134117
response.setResponseName(getCommandName());
135118
setResponseObject(response);
136119
} catch (ResourceAllocationException | MalformedURLException e) {
137-
s_logger.error("Exception while registering template", e);
120+
s_logger.error("Exception while registering ISO", e);
138121
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Exception while registering ISO: " + e.getMessage());
139122
}
140123
}

api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ public Map<String, String> getDetails() {
323323
customparameterMap.put(getBootType().toString(), getBootMode().toString());
324324
}
325325

326-
if (rootdisksize != null && !customparameterMap.containsKey("rootdisksize")) {
327-
customparameterMap.put("rootdisksize", rootdisksize.toString());
326+
if (rootdisksize != null && !customparameterMap.containsKey(VmDetailConstants.ROOT_DISK_SIZE)) {
327+
customparameterMap.put(VmDetailConstants.ROOT_DISK_SIZE, rootdisksize.toString());
328328
}
329329

330330
IoDriverPolicy ioPolicy = getIoDriverPolicy();

debian/rules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ override_dh_auto_install:
135135
install -D systemvm/dist/* $(DESTDIR)/usr/share/$(PACKAGE)-common/vms/
136136
# We need jasypt for cloud-install-sys-tmplt, so this is a nasty hack to get it into the right place
137137
install -D agent/target/dependencies/jasypt-1.9.3.jar $(DESTDIR)/usr/share/$(PACKAGE)-common/lib
138-
install -D utils/target/cloud-utils-$(VERSION).jar $(DESTDIR)/usr/share/$(PACKAGE)-common/lib/$(PACKAGE)-utils.jar
138+
install -D utils/target/cloud-utils-$(VERSION)-SHADED.jar $(DESTDIR)/usr/share/$(PACKAGE)-common/lib/$(PACKAGE)-utils.jar
139139

140140
# cloudstack-python
141141
mkdir -p $(DESTDIR)/usr/share/pyshared

engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDaoImpl.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.cloud.configuration.ResourceLimit;
3737
import com.cloud.domain.DomainVO;
3838
import com.cloud.domain.dao.DomainDao;
39-
import com.cloud.exception.UnsupportedServiceException;
4039
import com.cloud.user.AccountVO;
4140
import com.cloud.user.dao.AccountDao;
4241
import com.cloud.utils.db.DB;
@@ -171,9 +170,6 @@ public void createResourceCounts(long ownerId, ResourceLimit.ResourceOwnerType o
171170

172171
ResourceType[] resourceTypes = Resource.ResourceType.values();
173172
for (ResourceType resourceType : resourceTypes) {
174-
if (!resourceType.supportsOwner(ownerType)) {
175-
continue;
176-
}
177173
ResourceCountVO resourceCountVO = new ResourceCountVO(resourceType, 0, ownerId, ownerType);
178174
persist(resourceCountVO);
179175
}
@@ -217,17 +213,6 @@ public List<ResourceCountVO> listResourceCountByOwnerType(ResourceOwnerType owne
217213
}
218214
}
219215

220-
@Override
221-
public ResourceCountVO persist(ResourceCountVO resourceCountVO) {
222-
ResourceOwnerType ownerType = resourceCountVO.getResourceOwnerType();
223-
ResourceType resourceType = resourceCountVO.getType();
224-
if (!resourceType.supportsOwner(ownerType)) {
225-
throw new UnsupportedServiceException("Resource type " + resourceType + " is not supported for owner of type " + ownerType.getName());
226-
}
227-
228-
return super.persist(resourceCountVO);
229-
}
230-
231216
@Override
232217
public long removeEntriesByOwner(long ownerId, ResourceOwnerType ownerType) {
233218
SearchCriteria<ResourceCountVO> sc = TypeSearch.create();

engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -509,13 +509,12 @@ private void createTemplateStoreRefEntry(SystemVMTemplateDetails details) {
509509
}
510510
}
511511

512-
public void updateTemplateDetails(SystemVMTemplateDetails details, boolean updateTemplateDetails) {
512+
public void updateTemplateDetails(SystemVMTemplateDetails details) {
513513
VMTemplateVO template = vmTemplateDao.findById(details.getId());
514-
if (updateTemplateDetails) {
515-
template.setSize(details.getSize());
516-
template.setState(VirtualMachineTemplate.State.Active);
517-
vmTemplateDao.update(template.getId(), template);
518-
}
514+
template.setSize(details.getSize());
515+
template.setState(VirtualMachineTemplate.State.Active);
516+
vmTemplateDao.update(template.getId(), template);
517+
519518
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByStoreTemplate(details.getStoreId(), template.getId());
520519
templateDataStoreVO.setSize(details.getSize());
521520
templateDataStoreVO.setPhysicalSize(details.getPhysicalSize());
@@ -613,7 +612,7 @@ private void setupTemplate(String templateName, Pair<Hypervisor.HypervisorType,
613612

614613
private Long performTemplateRegistrationOperations(Pair<Hypervisor.HypervisorType, String> hypervisorAndTemplateName,
615614
String url, String checksum, ImageFormat format, long guestOsId,
616-
Long storeId, Long templateId, String filePath, boolean updateTmpltDetails) {
615+
Long storeId, Long templateId, String filePath, TemplateDataStoreVO templateDataStoreVO) {
617616
Hypervisor.HypervisorType hypervisor = hypervisorAndTemplateName.first();
618617
String templateName = UUID.randomUUID().toString();
619618
Date created = new Date(DateUtil.currentGMTTime().getTime());
@@ -631,21 +630,24 @@ private Long performTemplateRegistrationOperations(Pair<Hypervisor.HypervisorTyp
631630
String destTempFolderName = String.valueOf(templateId);
632631
String destTempFolder = filePath + PARTIAL_TEMPLATE_FOLDER + destTempFolderName;
633632
details.setInstallPath(PARTIAL_TEMPLATE_FOLDER + destTempFolderName + File.separator + templateName + "." + hypervisorImageFormat.get(hypervisor).getFileExtension());
634-
createTemplateStoreRefEntry(details);
633+
if (templateDataStoreVO == null) {
634+
createTemplateStoreRefEntry(details);
635+
}
635636
setupTemplate(templateName, hypervisorAndTemplateName, destTempFolder);
636637
readTemplateProperties(destTempFolder + "/template.properties", details);
637638
details.setUpdated(new Date(DateUtil.currentGMTTime().getTime()));
638-
updateTemplateDetails(details, updateTmpltDetails);
639+
updateTemplateDetails(details);
639640
return templateId;
640641
}
641642

642643
public void registerTemplate(Pair<Hypervisor.HypervisorType, String> hypervisorAndTemplateName,
643-
Pair<String, Long> storeUrlAndId, VMTemplateVO templateVO, String filePath) {
644+
Pair<String, Long> storeUrlAndId, VMTemplateVO templateVO,
645+
TemplateDataStoreVO templateDataStoreVO, String filePath) {
644646
Long templateId = null;
645647
try {
646648
templateId = templateVO.getId();
647649
performTemplateRegistrationOperations(hypervisorAndTemplateName, templateVO.getUrl(), templateVO.getChecksum(),
648-
templateVO.getFormat(), templateVO.getGuestOSId(), storeUrlAndId.second(), templateId, filePath, false);
650+
templateVO.getFormat(), templateVO.getGuestOSId(), storeUrlAndId.second(), templateId, filePath, templateDataStoreVO);
649651
} catch (Exception e) {
650652
String errMsg = String.format("Failed to register template for hypervisor: %s", hypervisorAndTemplateName.first());
651653
LOGGER.error(errMsg, e);
@@ -662,7 +664,7 @@ public void registerTemplate(Pair<Hypervisor.HypervisorType, String> hypervisorA
662664
try {
663665
Hypervisor.HypervisorType hypervisor = hypervisorAndTemplateName.first();
664666
templateId = performTemplateRegistrationOperations(hypervisorAndTemplateName, NewTemplateUrl.get(hypervisor), NewTemplateChecksum.get(hypervisor),
665-
hypervisorImageFormat.get(hypervisor), hypervisorGuestOsMap.get(hypervisor), storeUrlAndId.second(), null, filePath, true);
667+
hypervisorImageFormat.get(hypervisor), hypervisorGuestOsMap.get(hypervisor), storeUrlAndId.second(), null, filePath, null);
666668
Map<String, String> configParams = new HashMap<>();
667669
configParams.put(RouterTemplateConfigurationNames.get(hypervisorAndTemplateName.first()), hypervisorAndTemplateName.second());
668670
configParams.put("minreq.sysvmtemplate.version", getSystemVmTemplateVersion());
@@ -783,7 +785,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
783785
if (validateIfSeeded(storeUrlAndId.first(), installPath)) {
784786
continue;
785787
} else if (templateVO != null) {
786-
registerTemplate(hypervisorAndTemplateName, storeUrlAndId, templateVO, filePath);
788+
registerTemplate(hypervisorAndTemplateName, storeUrlAndId, templateVO, templateDataStoreVO, filePath);
787789
continue;
788790
}
789791
}

framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManagerImpl.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
3737
import org.apache.commons.lang.StringEscapeUtils;
3838
import org.apache.commons.lang.text.StrSubstitutor;
39+
import org.apache.commons.lang3.StringUtils;
3940
import org.apache.log4j.Logger;
4041
import org.springframework.stereotype.Component;
4142

@@ -223,7 +224,7 @@ public void sendQuotaAlert(DeferredQuotaEmail emailToBeSent) {
223224
final String body = bodySubstitutor.replace(emailTemplate.getTemplateBody());
224225

225226
try {
226-
sendQuotaAlert(account.getUuid(), emailRecipients, subject, body);
227+
sendQuotaAlert(account, emailRecipients, subject, body);
227228
emailToBeSent.sentSuccessfully(_quotaAcc);
228229
} catch (Exception e) {
229230
s_logger.error(String.format("Unable to send quota alert email (subject=%s; body=%s) to account %s (%s) recipients (%s) due to error (%s)", subject, body, account.getAccountName(),
@@ -354,17 +355,20 @@ public void sentSuccessfully(final QuotaAccountDao quotaAccountDao) {
354355
}
355356
};
356357

357-
protected void sendQuotaAlert(String accountUuid, List<String> emails, String subject, String body) {
358+
protected void sendQuotaAlert(Account account, List<String> emails, String subject, String body) {
358359
SMTPMailProperties mailProperties = new SMTPMailProperties();
359360

360361
mailProperties.setSender(new MailAddress(senderAddress));
362+
363+
body = addHeaderAndFooter(body, QuotaConfig.QuotaEmailHeader.valueIn(account.getDomainId()), QuotaConfig.QuotaEmailFooter.valueIn(account.getDomainId()));
364+
361365
mailProperties.setSubject(subject);
362366
mailProperties.setContent(body);
363367
mailProperties.setContentType("text/html; charset=utf-8");
364368

365369
if (CollectionUtils.isEmpty(emails)) {
366370
s_logger.warn(String.format("Account [%s] does not have users with email registered, "
367-
+ "therefore we are unable to send quota alert email with subject [%s] and content [%s].", accountUuid, subject, body));
371+
+ "therefore we are unable to send quota alert email with subject [%s] and content [%s].", account.getUuid(), subject, body));
368372
return;
369373
}
370374

@@ -378,4 +382,16 @@ protected void sendQuotaAlert(String accountUuid, List<String> emails, String su
378382
mailSender.sendMail(mailProperties);
379383
}
380384

385+
protected String addHeaderAndFooter(String body, String header, String footer) {
386+
387+
if (StringUtils.isNotEmpty(header)) {
388+
body = String.format("%s%s", header, body);
389+
}
390+
if (StringUtils.isNotEmpty(footer)) {
391+
body = String.format("%s%s", body, footer);
392+
}
393+
394+
return body;
395+
}
396+
381397
}

0 commit comments

Comments
 (0)