Faster logic to see if a cluster supports resigning

This commit is contained in:
Mike Tutkowski 2016-05-13 13:52:49 -06:00
parent 2bd035d199
commit 9d215562eb
9 changed files with 66 additions and 69 deletions

View File

@ -46,5 +46,5 @@ public interface ClusterDao extends GenericDao<ClusterVO, Long> {
List<Long> listAllCusters(long zoneId);
boolean computeWhetherClusterSupportsResigning(long clusterId);
boolean getSupportsResigning(long clusterId);
}

View File

@ -28,11 +28,10 @@ import javax.inject.Inject;
import org.springframework.stereotype.Component;
import com.cloud.dc.ClusterDetailsDao;
import com.cloud.dc.ClusterDetailsVO;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostDetailsDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.org.Grouping;
import com.cloud.utils.db.GenericDaoBase;
@ -60,9 +59,7 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C
private static final String GET_POD_CLUSTER_MAP_PREFIX = "SELECT pod_id, id FROM cloud.cluster WHERE cluster.id IN( ";
private static final String GET_POD_CLUSTER_MAP_SUFFIX = " )";
@Inject
private HostDao hostDao;
@Inject
private HostDetailsDao hostDetailsDao;
private ClusterDetailsDao clusterDetailsDao;
@Inject
protected HostPodDao hostPodDao;
@ -269,33 +266,21 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C
}
@Override
public boolean computeWhetherClusterSupportsResigning(long clusterId) {
public boolean getSupportsResigning(long clusterId) {
ClusterVO cluster = findById(clusterId);
if (cluster == null || cluster.getAllocationState() != Grouping.AllocationState.Enabled) {
return false;
}
List<HostVO> hosts = hostDao.findByClusterId(clusterId);
ClusterDetailsVO clusterDetailsVO = clusterDetailsDao.findDetail(clusterId, "supportsResign");
if (hosts == null) {
return false;
if (clusterDetailsVO != null) {
String value = clusterDetailsVO.getValue();
return Boolean.parseBoolean(value);
}
Map<Long, String> mapSupportsResign = hostDetailsDao.findDetails("supportsResign");
for (HostVO host : hosts) {
if (host == null) {
return false;
}
String value = mapSupportsResign.get(host.getId());
if (Boolean.parseBoolean(value) == false) {
return false;
}
}
return true;
return false;
}
}

View File

@ -24,8 +24,6 @@ import com.cloud.utils.db.GenericDao;
public interface HostDetailsDao extends GenericDao<DetailVO, Long> {
Map<String, String> findDetails(long hostId);
Map<Long, String> findDetails(String name);
void persist(long hostId, Map<String, String> details);
DetailVO findDetail(long hostId, String name);

View File

@ -37,7 +37,6 @@ import com.cloud.utils.exception.CloudRuntimeException;
public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implements HostDetailsDao {
protected final SearchBuilder<DetailVO> HostSearch;
protected final SearchBuilder<DetailVO> DetailSearch;
protected final SearchBuilder<DetailVO> NameSearch;
public HostDetailsDaoImpl() {
HostSearch = createSearchBuilder();
@ -48,10 +47,6 @@ public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implement
DetailSearch.and("hostId", DetailSearch.entity().getHostId(), SearchCriteria.Op.EQ);
DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ);
DetailSearch.done();
NameSearch = createSearchBuilder();
NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
NameSearch.done();
}
@Override
@ -88,27 +83,6 @@ public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implement
return details;
}
@Override
public Map<Long, String> findDetails(String name) {
SearchCriteria<DetailVO> sc = NameSearch.create();
sc.setParameters("name", name);
List<DetailVO> results = search(sc, null);
Map<Long, String> details = new HashMap<>(results.size());
for (DetailVO result : results) {
if ("password".equals(result.getName())) {
details.put(result.getHostId(), DBEncryptionUtil.decrypt(result.getValue()));
} else {
details.put(result.getHostId(), result.getValue());
}
}
return details;
}
@Override
public void deleteDetails(long hostId) {
SearchCriteria sc = HostSearch.create();

View File

@ -291,7 +291,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy {
HostVO hostVO = getHost(snapshotInfo);
boolean usingBackendSnapshot = usingBackendSnapshotFor(snapshotInfo);
boolean computeClusterSupportsResign = clusterDao.computeWhetherClusterSupportsResigning(hostVO.getClusterId());
boolean computeClusterSupportsResign = clusterDao.getSupportsResigning(hostVO.getClusterId());
if (usingBackendSnapshot && !computeClusterSupportsResign) {
String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId();
@ -399,7 +399,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy {
throw new CloudRuntimeException("Unable to locate a host capable of resigning in the zone with the following ID: " + volumeInfo.getDataCenterId());
}
boolean computeClusterSupportsResign = clusterDao.computeWhetherClusterSupportsResigning(hostVO.getClusterId());
boolean computeClusterSupportsResign = clusterDao.getSupportsResigning(hostVO.getClusterId());
if (!computeClusterSupportsResign) {
String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId();
@ -467,7 +467,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy {
HostVO hostVO = getHost(snapshotInfo);
boolean usingBackendSnapshot = usingBackendSnapshotFor(snapshotInfo);
boolean computeClusterSupportsResign = clusterDao.computeWhetherClusterSupportsResigning(hostVO.getClusterId());
boolean computeClusterSupportsResign = clusterDao.getSupportsResigning(hostVO.getClusterId());
if (usingBackendSnapshot && !computeClusterSupportsResign) {
String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId();
@ -711,7 +711,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy {
continue;
}
if (clusterDao.computeWhetherClusterSupportsResigning(clusterId)) {
if (clusterDao.getSupportsResigning(clusterId)) {
return host;
}
else {

View File

@ -186,7 +186,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase {
HostVO hostVO = getHost(volumeInfo.getId());
boolean canStorageSystemCreateVolumeFromSnapshot = canStorageSystemCreateVolumeFromSnapshot(volumeInfo.getPoolId());
boolean computeClusterSupportsResign = clusterDao.computeWhetherClusterSupportsResigning(hostVO.getClusterId());
boolean computeClusterSupportsResign = clusterDao.getSupportsResigning(hostVO.getClusterId());
// if canStorageSystemCreateVolumeFromSnapshot && computeClusterSupportsResign, then take a back-end snapshot or create a back-end clone;
// else, just create a new back-end volume (eventually used to create a new SR on and to copy a VDI to)
@ -468,7 +468,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase {
for (HostVO host : hosts) {
if (host.getResourceState() == ResourceState.Enabled) {
if (computeClusterMustSupportResign) {
if (clusterDao.computeWhetherClusterSupportsResigning(cluster.getId())) {
if (clusterDao.getSupportsResigning(cluster.getId())) {
return Optional.of(host);
}
else {

View File

@ -1093,7 +1093,7 @@ public class VolumeServiceImpl implements VolumeService {
for (HostVO host : hosts) {
if (host.getResourceState() == ResourceState.Enabled) {
if (computeClusterMustSupportResign) {
if (clusterDao.computeWhetherClusterSupportsResigning(cluster.getId())) {
if (clusterDao.getSupportsResigning(cluster.getId())) {
return host;
}
else {

View File

@ -1736,7 +1736,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
if (startup instanceof StartupRoutingCommand) {
final StartupRoutingCommand ssCmd = (StartupRoutingCommand)startup;
updateHostDetails(host, ssCmd);
updateSupportsClonedVolumes(host, ssCmd.getSupportsClonedVolumes());
}
try {
@ -1756,21 +1756,61 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
return host;
}
private void updateHostDetails(HostVO host, StartupRoutingCommand startupRoutingCmd) {
private void updateSupportsClonedVolumes(HostVO host, boolean supportsClonedVolumes) {
final String name = "supportsResign";
final String value = String.valueOf(startupRoutingCmd.getSupportsClonedVolumes());
DetailVO hostDetail = _hostDetailsDao.findDetail(host.getId(), name);
if (hostDetail != null) {
hostDetail.setValue(value);
if (supportsClonedVolumes) {
hostDetail.setValue(Boolean.TRUE.toString());
_hostDetailsDao.update(hostDetail.getId(), hostDetail);
_hostDetailsDao.update(hostDetail.getId(), hostDetail);
}
else {
_hostDetailsDao.remove(hostDetail.getId());
}
}
else {
hostDetail = new DetailVO(host.getId(), name, value);
if (supportsClonedVolumes) {
hostDetail = new DetailVO(host.getId(), name, Boolean.TRUE.toString());
_hostDetailsDao.persist(hostDetail);
_hostDetailsDao.persist(hostDetail);
}
}
boolean clusterSupportsResigning = true;
List<HostVO> hostVOs = _hostDao.findByClusterId(host.getClusterId());
for (HostVO hostVO : hostVOs) {
DetailVO hostDetailVO = _hostDetailsDao.findDetail(hostVO.getId(), name);
if (hostDetailVO == null || Boolean.parseBoolean(hostDetailVO.getValue()) == false) {
clusterSupportsResigning = false;
break;
}
}
ClusterDetailsVO clusterDetailsVO = _clusterDetailsDao.findDetail(host.getClusterId(), name);
if (clusterDetailsVO != null) {
if (clusterSupportsResigning) {
clusterDetailsVO.setValue(Boolean.TRUE.toString());
_clusterDetailsDao.update(clusterDetailsVO.getId(), clusterDetailsVO);
}
else {
_clusterDetailsDao.remove(clusterDetailsVO.getId());
}
}
else {
if (clusterSupportsResigning) {
clusterDetailsVO = new ClusterDetailsVO(host.getClusterId(), name, Boolean.TRUE.toString());
_clusterDetailsDao.persist(clusterDetailsVO);
}
}
}

View File

@ -1751,7 +1751,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
// This next call leads to CloudStack asking how many more bytes it will need for the template (if the template is
// already stored on the primary storage, then the answer is 0).
if (clusterId != null && _clusterDao.computeWhetherClusterSupportsResigning(clusterId)) {
if (clusterId != null && _clusterDao.getSupportsResigning(clusterId)) {
totalAskingSize += getBytesRequiredForTemplate(tmpl, pool);
}
}