Merge remote-tracking branch 'apache/4.15' into main

This commit is contained in:
davidjumani 2021-09-03 16:55:10 +05:30
commit a000361238
No known key found for this signature in database
GPG Key ID: 92D88ECF4D63C923
7 changed files with 51 additions and 61 deletions

View File

@ -179,7 +179,8 @@ public class DataMigrationUtility {
List<TemplateDataStoreVO> templates = templateDataStoreDao.listByStoreId(srcDataStore.getId());
for (TemplateDataStoreVO template : templates) {
VMTemplateVO templateVO = templateDao.findById(template.getTemplateId());
if (template.getState() == ObjectInDataStoreStateMachine.State.Ready && templateVO != null && !templateVO.isPublicTemplate() &&
if (template.getState() == ObjectInDataStoreStateMachine.State.Ready && templateVO != null &&
(!templateVO.isPublicTemplate() || (templateVO.isPublicTemplate() && templateVO.getUrl() == null)) &&
templateVO.getHypervisorType() != Hypervisor.HypervisorType.Simulator) {
files.add(templateFactory.getTemplate(template.getTemplateId(), srcDataStore));
}

View File

@ -19,3 +19,4 @@
-- Schema upgrade from 4.15.1.0 to 4.15.2.0
--;
UPDATE `cloud`.`configuration` SET `value` = 20, `default_value` = 20 WHERE `name` = 'default.ui.page.size';

View File

@ -122,7 +122,11 @@ public class TemplateJoinDaoImpl extends GenericDaoBaseWithTagInformation<Templa
activeTmpltSearch.and("store_id", activeTmpltSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
activeTmpltSearch.and("type", activeTmpltSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
activeTmpltSearch.and("templateState", activeTmpltSearch.entity().getTemplateState(), SearchCriteria.Op.EQ);
activeTmpltSearch.and("public", activeTmpltSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
activeTmpltSearch.and().op("public", activeTmpltSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
activeTmpltSearch.or().op("publicNoUrl", activeTmpltSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
activeTmpltSearch.and("url", activeTmpltSearch.entity().getUrl(), SearchCriteria.Op.NULL);
activeTmpltSearch.cp();
activeTmpltSearch.cp();
activeTmpltSearch.done();
// select distinct pair (template_id, zone_id)
@ -526,6 +530,7 @@ public class TemplateJoinDaoImpl extends GenericDaoBaseWithTagInformation<Templa
sc.setParameters("type", TemplateType.USER);
sc.setParameters("templateState", VirtualMachineTemplate.State.Active);
sc.setParameters("public", Boolean.FALSE);
sc.setParameters("publicNoUrl",Boolean.TRUE);
return searchIncludingRemoved(sc, null, null, false);
}

View File

@ -39,7 +39,8 @@ const getters = {
server: state => state.app.server,
domainStore: state => state.user.domainStore,
darkMode: state => state.user.darkMode,
themeSetting: state => state.user.themeSetting
themeSetting: state => state.user.themeSetting,
defaultListViewPageSize: state => state.user.defaultListViewPageSize
}
export default getters

View File

@ -55,7 +55,8 @@ const user = {
usebrowsertimezone: false,
domainStore: {},
darkMode: false,
themeSetting: {}
themeSetting: {},
defaultListViewPageSize: 20
},
mutations: {
@ -118,6 +119,9 @@ const user = {
SET_THEME_SETTING (state, setting) {
state.themeSetting = setting
Vue.ls.set(THEME_SETTING, setting)
},
SET_DEFAULT_LISTVIEW_PAGE_SIZE: (state, defaultListViewPageSize) => {
state.defaultListViewPageSize = defaultListViewPageSize
}
},
@ -254,6 +258,13 @@ const user = {
reject(error)
})
api('listConfigurations', { name: 'default.ui.page.size' }).then(response => {
const defaultListViewPageSize = parseInt(response.listconfigurationsresponse.configuration[0].value)
commit('SET_DEFAULT_LISTVIEW_PAGE_SIZE', defaultListViewPageSize)
}).catch(error => {
reject(error)
})
api('listLdapConfigurations').then(response => {
const ldapEnable = (response.ldapconfigurationresponse.count > 0)
commit('SET_LDAP', ldapEnable)

View File

@ -361,7 +361,7 @@
:pageSize="pageSize"
:total="itemCount"
:showTotal="total => `${$t('label.showing')} ${Math.min(total, 1+((page-1)*pageSize))}-${Math.min(page*pageSize, total)} ${$t('label.of')} ${total} ${$t('label.items')}`"
:pageSizeOptions="device === 'desktop' ? ['20', '50', '100', '200'] : ['10', '20', '50', '100', '200']"
:pageSizeOptions="pageSizeOptions"
@change="changePage"
@showSizeChange="changePageSize"
showSizeChanger
@ -438,7 +438,7 @@ export default {
modalInfo: {},
itemCount: 0,
page: 1,
pageSize: 10,
pageSize: this.$store.getters.defaultListViewPageSize,
resource: {},
selectedRowKeys: [],
currentAction: {},
@ -545,9 +545,6 @@ export default {
}
})
if (this.device === 'desktop') {
this.pageSize = 20
}
this.currentPath = this.$route.fullPath
this.fetchData()
if ('projectid' in this.$route.query) {
@ -570,7 +567,6 @@ export default {
this.pageSize = Number(to.query.pagesize)
} else {
this.page = 1
this.pageSize = (this.device === 'desktop' ? 20 : 10)
}
this.itemCount = 0
this.fetchData()
@ -591,6 +587,15 @@ export default {
computed: {
hasSelected () {
return this.selectedRowKeys.length > 0
},
pageSizeOptions () {
var sizes = [20, 50, 100, 200, this.$store.getters.defaultListViewPageSize]
if (this.device !== 'desktop') {
sizes.unshift(10)
}
return [...new Set(sizes)].sort(function (a, b) {
return a - b
}).map(String)
}
},
methods: {

View File

@ -17,15 +17,13 @@
package com.cloud.usage.parser;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.apache.cloudstack.backup.Backup;
import org.apache.cloudstack.usage.UsageTypes;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@ -68,65 +66,33 @@ public class BackupUsageParser {
return true;
}
final Map<Long, BackupInfo> vmUsageMap = new HashMap<>();
for (final UsageBackupVO usageBackup : usageBackups) {
final Long vmId = usageBackup.getVmId();
final Long zoneId = usageBackup.getZoneId();
final Long offeringId = usageBackup.getBackupOfferingId();
if (vmUsageMap.get(vmId) == null) {
vmUsageMap.put(vmId, new BackupUsageParser.BackupInfo(new Backup.Metric(0L, 0L), zoneId, vmId, offeringId));
Date createdDate = usageBackup.getCreated();
Date removedDate = usageBackup.getRemoved();
if (createdDate.before(startDate)) {
createdDate = startDate;
}
final Backup.Metric metric = vmUsageMap.get(vmId).getMetric();
metric.setBackupSize(metric.getBackupSize() + usageBackup.getSize());
metric.setDataSize(metric.getDataSize() + usageBackup.getProtectedSize());
}
if (removedDate == null || removedDate.after(endDate)) {
removedDate = endDate;
}
final long duration = (removedDate.getTime() - createdDate.getTime()) + 1;
final float usage = duration / 1000f / 60f / 60f;
DecimalFormat dFormat = new DecimalFormat("#.######");
String usageDisplay = dFormat.format(usage);
for (final BackupInfo backupInfo : vmUsageMap.values()) {
final Long vmId = backupInfo.getVmId();
final Long zoneId = backupInfo.getZoneId();
final Long offeringId = backupInfo.getOfferingId();
final Double rawUsage = (double) backupInfo.getMetric().getBackupSize();
final Double sizeGib = rawUsage / (1024.0 * 1024.0 * 1024.0);
final String description = String.format("Backup usage VM ID: %d", vmId);
final String usageDisplay = String.format("%.4f GiB", sizeGib);
final Double rawUsage = (double) usageBackup.getSize();
final String description = String.format("Backup usage VM ID: %d, backup offering: %d", vmId, offeringId);
final UsageVO usageRecord =
new UsageVO(zoneId, account.getAccountId(), account.getDomainId(), description, usageDisplay,
UsageTypes.BACKUP, rawUsage, vmId, null, offeringId, null, vmId,
backupInfo.getMetric().getBackupSize(), backupInfo.getMetric().getDataSize(), startDate, endDate);
new UsageVO(zoneId, account.getAccountId(), account.getDomainId(), description, usageDisplay + " Hrs",
UsageTypes.BACKUP, new Double(usage), vmId, null, offeringId, null, vmId,
usageBackup.getSize(), usageBackup.getProtectedSize(), startDate, endDate);
s_usageDao.persist(usageRecord);
}
return true;
}
static class BackupInfo {
Backup.Metric metric;
Long zoneId;
Long vmId;
Long offeringId;
public BackupInfo(Backup.Metric metric, Long zoneId, Long vmId, Long offeringId) {
this.metric = metric;
this.zoneId = zoneId;
this.vmId = vmId;
this.offeringId = offeringId;
}
public Backup.Metric getMetric() {
return metric;
}
public Long getZoneId() {
return zoneId;
}
public Long getVmId() {
return vmId;
}
public Long getOfferingId() {
return offeringId;
}
}
}