Skip to content

Commit 16282dd

Browse files
committed
wip
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 13ced5e commit 16282dd

File tree

9 files changed

+280
-150
lines changed

9 files changed

+280
-150
lines changed

engine/schema/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@
166166
</executions>
167167
</plugin>
168168
</plugins>
169+
<resources>
170+
<resource>
171+
<directory>src/main/resources</directory>
172+
<filtering>true</filtering>
173+
</resource>
174+
</resources>
169175
</build>
170176
<profiles>
171177
<profile>

engine/schema/src/main/java/com/cloud/dc/dao/ClusterDao.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.cloud.cpu.CPU;
2424
import com.cloud.dc.ClusterVO;
2525
import com.cloud.hypervisor.Hypervisor.HypervisorType;
26+
import com.cloud.utils.Pair;
2627
import com.cloud.utils.db.GenericDao;
2728

2829
public interface ClusterDao extends GenericDao<ClusterVO, Long> {
@@ -38,6 +39,8 @@ public interface ClusterDao extends GenericDao<ClusterVO, Long> {
3839

3940
Set<HypervisorType> getDistinctAvailableHypervisorsAcrossClusters();
4041

42+
List<Pair<HypervisorType, String>> getDistinctHypervisorsArchAcrossClusters();
43+
4144
List<ClusterVO> listByDcHyType(long dcId, String hyType);
4245

4346
Map<Long, List<Long>> getPodClusterIdMap(List<Long> clusterIds);

engine/schema/src/main/java/com/cloud/dc/dao/ClusterDaoImpl.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.cloud.hypervisor.Hypervisor.HypervisorType;
4040
import com.cloud.org.Grouping;
4141
import com.cloud.org.Managed;
42+
import com.cloud.utils.Pair;
4243
import com.cloud.utils.db.GenericDaoBase;
4344
import com.cloud.utils.db.GenericSearchBuilder;
4445
import com.cloud.utils.db.JoinBuilder;
@@ -182,6 +183,26 @@ public Set<HypervisorType> getDistinctAvailableHypervisorsAcrossClusters() {
182183
return new HashSet<>(getAvailableHypervisorInZone(null));
183184
}
184185

186+
@Override
187+
public List<Pair<HypervisorType, String>> getDistinctHypervisorsArchAcrossClusters() {
188+
List<Pair<HypervisorType, String>> hypervisorArchList = new ArrayList<>();
189+
String selectSql = "SELECT DISTINCT hypervisor_type, arch FROM cloud.cluster WHERE removed IS NULL";
190+
TransactionLegacy txn = TransactionLegacy.currentTxn();
191+
try {
192+
PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
193+
ResultSet rs = stmt.executeQuery();
194+
while (rs.next()) {
195+
HypervisorType hypervisorType = HypervisorType.valueOf(rs.getString("hypervisor_type"));
196+
String arch = rs.getString("arch");
197+
hypervisorArchList.add(new Pair<>(hypervisorType, arch));
198+
}
199+
} catch (SQLException ex) {
200+
logger.error("DB exception {}", ex.getMessage(), ex);
201+
return null;
202+
}
203+
return hypervisorArchList;
204+
}
205+
185206
@Override
186207
public Map<Long, List<Long>> getPodClusterIdMap(List<Long> clusterIds) {
187208
TransactionLegacy txn = TransactionLegacy.currentTxn();

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Arrays;
3131
import java.util.Date;
3232
import java.util.List;
33+
import java.util.Properties;
3334

3435
import javax.inject.Inject;
3536

@@ -443,6 +444,18 @@ protected void executeViewScripts() {
443444
public void check() {
444445
GlobalLock lock = GlobalLock.getInternLock("DatabaseUpgrade");
445446
try {
447+
448+
449+
Properties properties = new Properties();
450+
try (InputStream input = this.getClass().getClassLoader().getResourceAsStream("config.properties")) {
451+
if (input != null) {
452+
properties.load(input);
453+
LOGGER.info("----------------------{}", properties.getProperty("systemvm.template.location", "unknown"));
454+
}
455+
} catch (IOException e) {
456+
LOGGER.error("----------Error reading property", e);
457+
}
458+
446459
LOGGER.info("Grabbing lock to check for database upgrade.");
447460
if (!lock.lock(20 * 60)) {
448461
throw new CloudRuntimeException("Unable to acquire lock to check for database integrity.");

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

Lines changed: 211 additions & 124 deletions
Large diffs are not rendered by default.

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public interface ImageStoreDao extends GenericDao<ImageStoreVO, Long> {
4444

4545
List<ImageStoreVO> listStoresByZoneId(long zoneId);
4646

47-
List<ImageStoreVO> listAllStoresInZone(Long zoneId, String provider, DataStoreRole role);
47+
List<ImageStoreVO> listAllStoresInZoneExceptId(Long zoneId, String provider, DataStoreRole role, long storeId);
4848

4949
List<ImageStoreVO> findByProtocol(String protocol);
5050

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDaoImpl.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class ImageStoreDaoImpl extends GenericDaoBase<ImageStoreVO, Long> implem
4141
private SearchBuilder<ImageStoreVO> nameSearch;
4242
private SearchBuilder<ImageStoreVO> providerSearch;
4343
private SearchBuilder<ImageStoreVO> regionSearch;
44-
private SearchBuilder<ImageStoreVO> storeSearch;
44+
private SearchBuilder<ImageStoreVO> storesExceptIdSearch;
4545
private SearchBuilder<ImageStoreVO> protocolSearch;
4646
private SearchBuilder<ImageStoreVO> zoneProtocolSearch;
4747

@@ -88,11 +88,12 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
8888
regionSearch.and("role", regionSearch.entity().getRole(), SearchCriteria.Op.EQ);
8989
regionSearch.done();
9090

91-
storeSearch = createSearchBuilder();
92-
storeSearch.and("providerName", storeSearch.entity().getProviderName(), SearchCriteria.Op.EQ);
93-
storeSearch.and("role", storeSearch.entity().getRole(), SearchCriteria.Op.EQ);
94-
storeSearch.and("dataCenterId", storeSearch.entity().getDcId(), SearchCriteria.Op.EQ);
95-
storeSearch.done();
91+
storesExceptIdSearch = createSearchBuilder();
92+
storesExceptIdSearch.and("providerName", storesExceptIdSearch.entity().getProviderName(), SearchCriteria.Op.EQ);
93+
storesExceptIdSearch.and("role", storesExceptIdSearch.entity().getRole(), SearchCriteria.Op.EQ);
94+
storesExceptIdSearch.and("dataCenterId", storesExceptIdSearch.entity().getDcId(), SearchCriteria.Op.EQ);
95+
storesExceptIdSearch.and("id", storesExceptIdSearch.entity().getId(), SearchCriteria.Op.NEQ);
96+
storesExceptIdSearch.done();
9697

9798
return true;
9899
}
@@ -113,11 +114,12 @@ public List<ImageStoreVO> findByProvider(String provider) {
113114
}
114115

115116
@Override
116-
public List<ImageStoreVO> listAllStoresInZone(Long zoneId, String provider, DataStoreRole role) {
117-
SearchCriteria<ImageStoreVO> sc = storeSearch.create();
117+
public List<ImageStoreVO> listAllStoresInZoneExceptId(Long zoneId, String provider, DataStoreRole role, long id) {
118+
SearchCriteria<ImageStoreVO> sc = storesExceptIdSearch.create();
118119
sc.setParameters("providerName", provider);
119120
sc.setParameters("role", role);
120121
sc.setParameters("dataCenterId", zoneId);
122+
sc.setParameters("id", id);
121123
return listBy(sc);
122124
}
123125

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
systemvm.template.location=${project.systemvm.template.location}

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,12 +3590,11 @@ private void registerSystemVmTemplateOnFirstNfsStore(Long zoneId, String provide
35903590
Transaction.execute(new TransactionCallbackNoReturn() {
35913591
@Override
35923592
public void doInTransactionWithoutResult(final TransactionStatus status) {
3593-
List<ImageStoreVO> stores = _imageStoreDao.listAllStoresInZone(zoneId, providerName, DataStoreRole.Image);
3594-
stores = stores.stream().filter(str -> str.getId() != store.getId()).collect(Collectors.toList());
3595-
// Check if it's the only/first store in the zone
3596-
if (stores.size() == 0) {
3593+
List<ImageStoreVO> stores = _imageStoreDao.listAllStoresInZoneExceptId(zoneId, providerName,
3594+
DataStoreRole.Image, store.getId());
3595+
if (CollectionUtils.isEmpty(stores)) {
35973596
List<HypervisorType> hypervisorTypes = _clusterDao.getAvailableHypervisorInZone(zoneId);
3598-
Set<HypervisorType> hypSet = new HashSet<>(hypervisorTypes);
3597+
Set<HypervisorType> hypervisorTypeSet = new HashSet<>(hypervisorTypes);
35993598
TransactionLegacy txn = TransactionLegacy.open("AutomaticTemplateRegister");
36003599
SystemVmTemplateRegistration systemVmTemplateRegistration = new SystemVmTemplateRegistration();
36013600
String filePath = null;
@@ -3606,24 +3605,22 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
36063605
}
36073606
Pair<String, Long> storeUrlAndId = new Pair<>(url, store.getId());
36083607
String nfsVersion = imageStoreDetailsUtil.getNfsVersion(store.getId());
3609-
for (HypervisorType hypervisorType : hypSet) {
3608+
for (HypervisorType hypervisorType : hypervisorTypeSet) {
36103609
try {
36113610
if (HypervisorType.Simulator == hypervisorType) {
36123611
continue;
36133612
}
36143613
String templateName = getValidTemplateName(zoneId, hypervisorType);
3615-
Pair<Hypervisor.HypervisorType, String> hypervisorAndTemplateName =
3616-
new Pair<>(hypervisorType, templateName);
3617-
Long templateId = systemVmTemplateRegistration.getRegisteredTemplateId(hypervisorAndTemplateName);
3614+
Long templateId = systemVmTemplateRegistration.getRegisteredTemplateId(templateName);
36183615
VMTemplateVO vmTemplateVO = null;
3619-
TemplateDataStoreVO templateVO = null;
3616+
TemplateDataStoreVO templateDataStoreVO = null;
36203617
if (templateId != null) {
36213618
vmTemplateVO = _templateDao.findById(templateId);
3622-
templateVO = _templateStoreDao.findByStoreTemplate(store.getId(), templateId);
3623-
if (templateVO != null) {
3619+
templateDataStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(), templateId);
3620+
if (templateDataStoreVO != null) {
36243621
try {
3625-
if (systemVmTemplateRegistration.validateIfSeeded(
3626-
templateVO, url, templateVO.getInstallPath(), nfsVersion)) {
3622+
if (systemVmTemplateRegistration.validateIfSeeded(templateDataStoreVO,
3623+
url, templateDataStoreVO.getInstallPath(), nfsVersion)) {
36273624
continue;
36283625
}
36293626
} catch (Exception e) {
@@ -3632,10 +3629,10 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
36323629
}
36333630
}
36343631
SystemVmTemplateRegistration.mountStore(storeUrlAndId.first(), filePath, nfsVersion);
3635-
if (templateVO != null && vmTemplateVO != null) {
3636-
systemVmTemplateRegistration.registerTemplate(hypervisorAndTemplateName, storeUrlAndId, vmTemplateVO, templateVO, filePath);
3632+
if (templateDataStoreVO != null && vmTemplateVO != null) {
3633+
systemVmTemplateRegistration.registerTemplate(hypervisorType, templateName, storeUrlAndId, vmTemplateVO, templateDataStoreVO, filePath);
36373634
} else {
3638-
systemVmTemplateRegistration.registerTemplate(hypervisorAndTemplateName, storeUrlAndId, filePath);
3635+
systemVmTemplateRegistration.registerTemplate(hypervisorType, templateName, storeUrlAndId, filePath);
36393636
}
36403637
} catch (CloudRuntimeException e) {
36413638
SystemVmTemplateRegistration.unmountStore(filePath);

0 commit comments

Comments
 (0)