From 455f9f642c5df881bb49e5d44a90f91b2bb3adcf Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 8 Aug 2011 18:28:34 -0700 Subject: [PATCH] bug 11014: 1. if there is no storage pool, don't try to start system VM 2. not use "consoleproxy.restart" as other meaning status 11014: resolved fixed --- .../consoleproxy/ConsoleProxyManagerImpl.java | 12 ++- .../cloud/server/ManagementServerImpl.java | 6 +- .../com/cloud/storage/StorageManagerImpl.java | 28 +------ .../com/cloud/storage/dao/StoragePoolDao.java | 3 +- .../cloud/storage/dao/StoragePoolDaoImpl.java | 73 ++++++------------- .../src/com/cloud/vm/UserVmManagerImpl.java | 2 +- 6 files changed, 36 insertions(+), 88 deletions(-) diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index aecce0e977c..57aba765d8a 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -92,9 +92,12 @@ import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.servlet.ConsoleProxyServlet; import com.cloud.storage.StorageManager; +import com.cloud.storage.StoragePoolStatus; +import com.cloud.storage.StoragePoolVO; import com.cloud.storage.VMTemplateHostVO; import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; import com.cloud.storage.VMTemplateVO; +import com.cloud.storage.dao.StoragePoolDao; import com.cloud.storage.dao.VMTemplateDao; import com.cloud.storage.dao.VMTemplateHostDao; import com.cloud.user.Account; @@ -190,6 +193,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx ServiceOfferingDao _offeringDao; @Inject NetworkOfferingDao _networkOfferingDao; + @Inject + StoragePoolDao _storagePoolDao; private ConsoleProxyListener _listener; @@ -1556,10 +1561,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx return false; } - // config var for consoleproxy.restart check - String restart = _configDao.getValue("consoleproxy.restart"); - if (restart != null && restart.equalsIgnoreCase("false")) { - s_logger.debug("Capacity scan disabled purposefully, consoleproxy.restart = false. This happens when the primarystorage is in maintenance mode"); + List upPools = _storagePoolDao.listByStatus(StoragePoolStatus.Up); + if (upPools == null || upPools.size() == 0 ) { + s_logger.debug("Skip capacity scan due to there is no Primary Storage UPintenance mode"); return false; } diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 6b7661f096f..68a790dac45 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -4228,9 +4228,9 @@ public class ManagementServerImpl implements ManagementServer { @Override public long getPsMaintenanceCount(long podId) { List poolsInTransition = new ArrayList(); - poolsInTransition.addAll(_poolDao.listPoolsByStatus(StoragePoolStatus.Maintenance)); - poolsInTransition.addAll(_poolDao.listPoolsByStatus(StoragePoolStatus.PrepareForMaintenance)); - poolsInTransition.addAll(_poolDao.listPoolsByStatus(StoragePoolStatus.ErrorInMaintenance)); + poolsInTransition.addAll(_poolDao.listByStatus(StoragePoolStatus.Maintenance)); + poolsInTransition.addAll(_poolDao.listByStatus(StoragePoolStatus.PrepareForMaintenance)); + poolsInTransition.addAll(_poolDao.listByStatus(StoragePoolStatus.ErrorInMaintenance)); return poolsInTransition.size(); } diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 7ca625334b2..70ab526a3ea 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -1274,11 +1274,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag } else { createCapacityEntry(pool); } - - // ensures cpvm is restarted even if the existing pools in system are in maintenance, hence flag below was hitherto in - // false state - _configMgr.updateConfiguration(UserContext.current().getCallerUserId(), "consoleproxy.restart", "true"); - return pool; } @@ -2064,7 +2059,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag // check to see if other ps exist // if they do, then we can migrate over the system vms to them // if they dont, then just stop all vms on this one - List upPools = _storagePoolDao.listPoolsByStatus(StoragePoolStatus.Up); + List upPools = _storagePoolDao.listByStatus(StoragePoolStatus.Up); if (upPools == null || upPools.size() == 0) { restart = false; @@ -2114,11 +2109,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag // if the instance is of type consoleproxy, call the console proxy if (vmInstance.getType().equals(VirtualMachine.Type.ConsoleProxy)) { - // make sure it is not restarted again, update config to set flag to false - if (!restart) { - _configMgr.updateConfiguration(userId, "consoleproxy.restart", "false"); - } - // call the consoleproxymanager ConsoleProxyVO consoleProxy = _consoleProxyDao.findById(vmInstance.getId()); if (!_vmMgr.advanceStop(consoleProxy, true, user, account)) { @@ -2132,8 +2122,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag } if (restart) { - // Restore config val for consoleproxy.restart to true - _configMgr.updateConfiguration(userId, "consoleproxy.restart", "true"); if (_vmMgr.advanceStart(consoleProxy, null, user, account) == null) { String errorMsg = "There was an error starting the console proxy id: " + vmInstance.getId() + " on another storage pool, cannot enable primary storage maintenance"; @@ -2366,20 +2354,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag } } } - - // Restore config val for consoleproxy.restart to true - try { - _configMgr.updateConfiguration(userId, "consoleproxy.restart", "true"); - } catch (InvalidParameterValueException e) { - String msg = "Error changing consoleproxy.restart back to false at end of cancel maintenance:"; - s_logger.warn(msg, e); - throw new ExecutionException(msg); - } catch (CloudRuntimeException e) { - String msg = "Error changing consoleproxy.restart back to false at end of cancel maintenance:"; - s_logger.warn(msg, e); - throw new ExecutionException(msg); - } - return primaryStorage; } catch (Exception e) { setPoolStateToError(primaryStorage); diff --git a/server/src/com/cloud/storage/dao/StoragePoolDao.java b/server/src/com/cloud/storage/dao/StoragePoolDao.java index 0c272980908..d232d5671b1 100644 --- a/server/src/com/cloud/storage/dao/StoragePoolDao.java +++ b/server/src/com/cloud/storage/dao/StoragePoolDao.java @@ -103,6 +103,5 @@ public interface StoragePoolDao extends GenericDao { List findIfDuplicatePoolsExistByUUID(String uuid); - List listPoolsByStatus(StoragePoolStatus status); - + List listByStatus(StoragePoolStatus status); } diff --git a/server/src/com/cloud/storage/dao/StoragePoolDaoImpl.java b/server/src/com/cloud/storage/dao/StoragePoolDaoImpl.java index 8af75336828..f5ce03de1ac 100644 --- a/server/src/com/cloud/storage/dao/StoragePoolDaoImpl.java +++ b/server/src/com/cloud/storage/dao/StoragePoolDaoImpl.java @@ -46,16 +46,10 @@ import com.cloud.utils.exception.CloudRuntimeException; @Local(value={StoragePoolDao.class}) @DB(txn=false) public class StoragePoolDaoImpl extends GenericDaoBase implements StoragePoolDao { - protected final SearchBuilder NameSearch; - protected final SearchBuilder UUIDSearch; - protected final SearchBuilder DatacenterSearch; + protected final SearchBuilder AllFieldSearch; protected final SearchBuilder DcPodSearch; - protected final SearchBuilder HostSearch; - protected final SearchBuilder HostPathDcPodSearch; - protected final SearchBuilder HostPathDcSearch; protected final SearchBuilder DcPodAnyClusterSearch; protected final SearchBuilder DeleteLvmSearch; - protected final SearchBuilder StatusSearch; protected final GenericSearchBuilder MaintenanceCountSearch; @@ -66,17 +60,15 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp private final String FindPoolTagDetails = "SELECT storage_pool_details.name FROM storage_pool_details WHERE pool_id = ? and value = ?"; protected StoragePoolDaoImpl() { - NameSearch = createSearchBuilder(); - NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ); - NameSearch.done(); - - UUIDSearch = createSearchBuilder(); - UUIDSearch.and("uuid", UUIDSearch.entity().getUuid(), SearchCriteria.Op.EQ); - UUIDSearch.done(); - - DatacenterSearch = createSearchBuilder(); - DatacenterSearch.and("datacenterId", DatacenterSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); - DatacenterSearch.done(); + AllFieldSearch = createSearchBuilder(); + AllFieldSearch.and("name", AllFieldSearch.entity().getName(), SearchCriteria.Op.EQ); + AllFieldSearch.and("uuid", AllFieldSearch.entity().getUuid(), SearchCriteria.Op.EQ); + AllFieldSearch.and("datacenterId", AllFieldSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); + AllFieldSearch.and("hostAddress", AllFieldSearch.entity().getHostAddress(), SearchCriteria.Op.EQ); + AllFieldSearch.and("status",AllFieldSearch.entity().getStatus(),SearchCriteria.Op.EQ); + AllFieldSearch.and("path", AllFieldSearch.entity().getPath(), SearchCriteria.Op.EQ); + AllFieldSearch.and("podId", AllFieldSearch.entity().getPodId(), Op.EQ); + AllFieldSearch.done(); DcPodSearch = createSearchBuilder(); DcPodSearch.and("datacenterId", DcPodSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); @@ -100,28 +92,7 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp DeleteLvmSearch.and().op("LVM", DeleteLvmSearch.entity().getPoolType(), SearchCriteria.Op.EQ); DeleteLvmSearch.or("Filesystem", DeleteLvmSearch.entity().getPoolType(), SearchCriteria.Op.EQ); DeleteLvmSearch.cp(); - DeleteLvmSearch.done(); - - HostSearch = createSearchBuilder(); - HostSearch.and("host", HostSearch.entity().getHostAddress(), SearchCriteria.Op.EQ); - HostSearch.done(); - - StatusSearch = createSearchBuilder(); - StatusSearch.and("status",StatusSearch.entity().getStatus(),SearchCriteria.Op.EQ); - StatusSearch.done(); - - HostPathDcPodSearch = createSearchBuilder(); - HostPathDcPodSearch.and("hostAddress", HostPathDcPodSearch.entity().getHostAddress(), SearchCriteria.Op.EQ); - HostPathDcPodSearch.and("path", HostPathDcPodSearch.entity().getPath(), SearchCriteria.Op.EQ); - HostPathDcPodSearch.and("datacenterId", HostPathDcPodSearch.entity().getDataCenterId(), Op.EQ); - HostPathDcPodSearch.and("podId", HostPathDcPodSearch.entity().getPodId(), Op.EQ); - HostPathDcPodSearch.and("uuid", HostPathDcPodSearch.entity().getUuid(), Op.EQ); - HostPathDcPodSearch.done(); - - HostPathDcSearch = createSearchBuilder(); - HostPathDcSearch.and("hostAddress", HostPathDcSearch.entity().getHostAddress(), SearchCriteria.Op.EQ); - HostPathDcSearch.and("path", HostPathDcSearch.entity().getPath(), SearchCriteria.Op.EQ); - HostPathDcSearch.done(); + DeleteLvmSearch.done(); MaintenanceCountSearch = createSearchBuilder(Long.class); MaintenanceCountSearch.and("pool", MaintenanceCountSearch.entity().getId(), SearchCriteria.Op.EQ); @@ -134,7 +105,7 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp @Override public List findPoolByName(String name) { - SearchCriteria sc = NameSearch.create(); + SearchCriteria sc = AllFieldSearch.create(); sc.setParameters("name", name); return listIncludingRemovedBy(sc); } @@ -142,7 +113,7 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp @Override public StoragePoolVO findPoolByUUID(String uuid) { - SearchCriteria sc = UUIDSearch.create(); + SearchCriteria sc = AllFieldSearch.create(); sc.setParameters("uuid", uuid); return findOneIncludingRemovedBy(sc); } @@ -151,7 +122,7 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp @Override public List findIfDuplicatePoolsExistByUUID(String uuid) { - SearchCriteria sc = UUIDSearch.create(); + SearchCriteria sc = AllFieldSearch.create(); sc.setParameters("uuid", uuid); return listBy(sc); } @@ -159,7 +130,7 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp @Override public List listByDataCenterId(long datacenterId) { - SearchCriteria sc = DatacenterSearch.create(); + SearchCriteria sc = AllFieldSearch.create(); sc.setParameters("datacenterId", datacenterId); return listBy(sc); } @@ -183,21 +154,21 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp @Override public List listByStorageHost(String hostFqdnOrIp) { - SearchCriteria sc = HostSearch.create(); - sc.setParameters("host", hostFqdnOrIp); + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("hostAddress", hostFqdnOrIp); return listIncludingRemovedBy(sc); } @Override - public List listPoolsByStatus(StoragePoolStatus status){ - SearchCriteria sc = StatusSearch.create(); + public List listByStatus(StoragePoolStatus status){ + SearchCriteria sc = AllFieldSearch.create(); sc.setParameters("status", status); return listBy(sc); } @Override public StoragePoolVO findPoolByHostPath(long datacenterId, Long podId, String host, String path, String uuid) { - SearchCriteria sc = HostPathDcPodSearch.create(); + SearchCriteria sc = AllFieldSearch.create(); sc.setParameters("hostAddress", host); sc.setParameters("path", path); sc.setParameters("datacenterId", datacenterId); @@ -226,7 +197,7 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp @Override public List listPoolByHostPath(String host, String path) { - SearchCriteria sc = HostPathDcSearch.create(); + SearchCriteria sc = AllFieldSearch.create(); sc.setParameters("hostAddress", host); sc.setParameters("path", path); @@ -235,7 +206,7 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp public StoragePoolVO listById(Integer id) { - SearchCriteria sc = HostSearch.create(); + SearchCriteria sc = AllFieldSearch.create(); sc.setParameters("id", id); return findOneIncludingRemovedBy(sc); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index a977ff2df5b..13c318139e8 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -2371,7 +2371,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } // check if we have available pools for vm deployment - List availablePools = _storagePoolDao.listPoolsByStatus(StoragePoolStatus.Up); + List availablePools = _storagePoolDao.listByStatus(StoragePoolStatus.Up); if (availablePools == null || availablePools.size() < 1) { throw new StorageUnavailableException("There are no available pools in the UP state for vm deployment", -1);