Merge remote-tracking branch 'origin/4.15'

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2021-02-24 17:39:12 +05:30
commit 1d8a4978e9
5 changed files with 71 additions and 9 deletions

View File

@ -34,6 +34,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import com.cloud.upgrade.dao.DbUpgrade;
import com.cloud.upgrade.dao.DbUpgradeSystemVmTemplate;
import com.cloud.upgrade.dao.Upgrade217to218;
import com.cloud.upgrade.dao.Upgrade218to22;
import com.cloud.upgrade.dao.Upgrade218to224DomainVlans;
@ -237,11 +238,42 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
}
private void updateSystemVmTemplates(DbUpgrade[] upgrades) {
for (int i = upgrades.length - 1; i >= 0; i--) {
DbUpgrade upgrade = upgrades[i];
if (upgrade instanceof DbUpgradeSystemVmTemplate) {
TransactionLegacy txn = TransactionLegacy.open("Upgrade");
txn.start();
try {
Connection conn;
try {
conn = txn.getConnection();
} catch (SQLException e) {
String errorMessage = "Unable to upgrade the database";
s_logger.error(errorMessage, e);
throw new CloudRuntimeException(errorMessage, e);
}
((DbUpgradeSystemVmTemplate)upgrade).updateSystemVmTemplates(conn);
txn.commit();
break;
} catch (CloudRuntimeException e) {
String errorMessage = "Unable to upgrade the database";
s_logger.error(errorMessage, e);
throw new CloudRuntimeException(errorMessage, e);
} finally {
txn.close();
}
}
}
}
protected void upgrade(CloudStackVersion dbVersion, CloudStackVersion currentVersion) {
s_logger.info("Database upgrade must be performed from " + dbVersion + " to " + currentVersion);
final DbUpgrade[] upgrades = calculateUpgradePath(dbVersion, currentVersion);
updateSystemVmTemplates(upgrades);
for (DbUpgrade upgrade : upgrades) {
VersionVO version;
s_logger.debug("Running upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade

View File

@ -0,0 +1,25 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.upgrade.dao;
import java.sql.Connection;
public interface DbUpgradeSystemVmTemplate {
void updateSystemVmTemplates(Connection conn);
}

View File

@ -32,7 +32,7 @@ import org.apache.log4j.Logger;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.utils.exception.CloudRuntimeException;
public class Upgrade41510to41600 implements DbUpgrade {
public class Upgrade41510to41600 implements DbUpgrade, DbUpgradeSystemVmTemplate {
final static Logger LOG = Logger.getLogger(Upgrade41510to41600.class);
@ -64,11 +64,11 @@ public class Upgrade41510to41600 implements DbUpgrade {
@Override
public void performDataMigration(Connection conn) {
updateSystemVmTemplates(conn);
}
@Override
@SuppressWarnings("serial")
private void updateSystemVmTemplates(final Connection conn) {
public void updateSystemVmTemplates(final Connection conn) {
LOG.debug("Updating System Vm template IDs");
final Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>();
try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) {

View File

@ -30,6 +30,7 @@ import com.cloud.deployasis.DeployAsIsConstants;
import com.cloud.deployasis.TemplateDeployAsIsDetailVO;
import com.cloud.deployasis.dao.TemplateDeployAsIsDetailsDao;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
import org.apache.cloudstack.utils.security.DigestHelper;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@ -161,10 +162,13 @@ public class TemplateJoinDaoImpl extends GenericDaoBaseWithTagInformation<Templa
HashMap<String, String> downloadDetailInImageStores = null;
for (TemplateDataStoreVO templateInStore : templatesInStore) {
downloadDetailInImageStores = new HashMap<>();
downloadDetailInImageStores.put("datastore", dataStoreDao.findById(templateInStore.getDataStoreId()).getName());
downloadDetailInImageStores.put("downloadPercent", Integer.toString(templateInStore.getDownloadPercent()));
downloadDetailInImageStores.put("downloadState", (templateInStore.getDownloadState() != null ? templateInStore.getDownloadState().toString() : ""));
downloadProgressDetails.add(downloadDetailInImageStores);
ImageStoreVO datastore = dataStoreDao.findById(templateInStore.getDataStoreId());
if (datastore != null) {
downloadDetailInImageStores.put("datastore", datastore.getName());
downloadDetailInImageStores.put("downloadPercent", Integer.toString(templateInStore.getDownloadPercent()));
downloadDetailInImageStores.put("downloadState", (templateInStore.getDownloadState() != null ? templateInStore.getDownloadState().toString() : ""));
downloadProgressDetails.add(downloadDetailInImageStores);
}
}
TemplateResponse templateResponse = new TemplateResponse();
@ -522,6 +526,7 @@ public class TemplateJoinDaoImpl extends GenericDaoBaseWithTagInformation<Templa
sc.setParameters("store_id", storeId);
sc.setParameters("type", TemplateType.USER);
sc.setParameters("templateState", VirtualMachineTemplate.State.Active);
sc.setParameters("public", Boolean.FALSE);
return searchIncludingRemoved(sc, null, null, false);
}

View File

@ -264,7 +264,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
private void createTemplateWithinZone(Long zId, TemplateProfile profile, VMTemplateVO template) {
// find all eligible image stores for this zone scope
List<DataStore> imageStores = storeMgr.getImageStoresByScope(new ZoneScope(zId));
List<DataStore> imageStores = storeMgr.getImageStoresByScopeExcludingReadOnly(new ZoneScope(zId));
if (imageStores == null || imageStores.size() == 0) {
throw new CloudRuntimeException("Unable to find image store to download template " + profile.getTemplate());
}
@ -331,7 +331,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
zoneId = profile.getZoneIdList().get(0);
// find all eligible image stores for this zone scope
List<DataStore> imageStores = storeMgr.getImageStoresByScope(new ZoneScope(zoneId));
List<DataStore> imageStores = storeMgr.getImageStoresByScopeExcludingReadOnly(new ZoneScope(zoneId));
if (imageStores == null || imageStores.size() == 0) {
throw new CloudRuntimeException("Unable to find image store to download template " + profile.getTemplate());
}