mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
deal with null return for create deployment plan for maintenance (#10518)
* deal with null return for create deployment plan for maintenance * deal with ide warnings
This commit is contained in:
parent
f4a7c8ab89
commit
6c40a7bebb
@ -67,9 +67,9 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
|||||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||||
import org.apache.cloudstack.utils.identity.ManagementServerNode;
|
import org.apache.cloudstack.utils.identity.ManagementServerNode;
|
||||||
|
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang.ObjectUtils;
|
import org.apache.commons.lang.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -99,7 +99,6 @@ import com.cloud.capacity.CapacityVO;
|
|||||||
import com.cloud.capacity.dao.CapacityDao;
|
import com.cloud.capacity.dao.CapacityDao;
|
||||||
import com.cloud.cluster.ClusterManager;
|
import com.cloud.cluster.ClusterManager;
|
||||||
import com.cloud.configuration.Config;
|
import com.cloud.configuration.Config;
|
||||||
import com.cloud.configuration.ConfigurationManager;
|
|
||||||
import com.cloud.dc.ClusterDetailsDao;
|
import com.cloud.dc.ClusterDetailsDao;
|
||||||
import com.cloud.dc.ClusterDetailsVO;
|
import com.cloud.dc.ClusterDetailsVO;
|
||||||
import com.cloud.dc.ClusterVO;
|
import com.cloud.dc.ClusterVO;
|
||||||
@ -131,7 +130,6 @@ import com.cloud.exception.DiscoveryException;
|
|||||||
import com.cloud.exception.InsufficientServerCapacityException;
|
import com.cloud.exception.InsufficientServerCapacityException;
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
import com.cloud.exception.PermissionDeniedException;
|
import com.cloud.exception.PermissionDeniedException;
|
||||||
import com.cloud.exception.ResourceInUseException;
|
|
||||||
import com.cloud.exception.ResourceUnavailableException;
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
import com.cloud.gpu.GPU;
|
import com.cloud.gpu.GPU;
|
||||||
import com.cloud.gpu.HostGpuGroupsVO;
|
import com.cloud.gpu.HostGpuGroupsVO;
|
||||||
@ -169,7 +167,6 @@ import com.cloud.storage.StoragePoolHostVO;
|
|||||||
import com.cloud.storage.StoragePoolStatus;
|
import com.cloud.storage.StoragePoolStatus;
|
||||||
import com.cloud.storage.StorageService;
|
import com.cloud.storage.StorageService;
|
||||||
import com.cloud.storage.VMTemplateVO;
|
import com.cloud.storage.VMTemplateVO;
|
||||||
import com.cloud.storage.dao.DiskOfferingDao;
|
|
||||||
import com.cloud.storage.dao.GuestOSCategoryDao;
|
import com.cloud.storage.dao.GuestOSCategoryDao;
|
||||||
import com.cloud.storage.dao.StoragePoolHostDao;
|
import com.cloud.storage.dao.StoragePoolHostDao;
|
||||||
import com.cloud.storage.dao.VMTemplateDao;
|
import com.cloud.storage.dao.VMTemplateDao;
|
||||||
@ -201,6 +198,7 @@ import com.cloud.utils.net.NetUtils;
|
|||||||
import com.cloud.utils.ssh.SSHCmdHelper;
|
import com.cloud.utils.ssh.SSHCmdHelper;
|
||||||
import com.cloud.utils.ssh.SshException;
|
import com.cloud.utils.ssh.SshException;
|
||||||
import com.cloud.vm.UserVmManager;
|
import com.cloud.vm.UserVmManager;
|
||||||
|
import com.cloud.utils.StringUtils;
|
||||||
import com.cloud.vm.VMInstanceVO;
|
import com.cloud.vm.VMInstanceVO;
|
||||||
import com.cloud.vm.VirtualMachine;
|
import com.cloud.vm.VirtualMachine;
|
||||||
import com.cloud.vm.VirtualMachine.State;
|
import com.cloud.vm.VirtualMachine.State;
|
||||||
@ -235,8 +233,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
@Inject
|
@Inject
|
||||||
private CapacityDao _capacityDao;
|
private CapacityDao _capacityDao;
|
||||||
@Inject
|
@Inject
|
||||||
private DiskOfferingDao diskOfferingDao;
|
|
||||||
@Inject
|
|
||||||
private ServiceOfferingDao serviceOfferingDao;
|
private ServiceOfferingDao serviceOfferingDao;
|
||||||
@Inject
|
@Inject
|
||||||
private HostDao _hostDao;
|
private HostDao _hostDao;
|
||||||
@ -295,8 +291,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
@Inject
|
@Inject
|
||||||
private VMTemplateDao _templateDao;
|
private VMTemplateDao _templateDao;
|
||||||
@Inject
|
@Inject
|
||||||
private ConfigurationManager _configMgr;
|
|
||||||
@Inject
|
|
||||||
private ClusterVSMMapDao _clusterVSMMapDao;
|
private ClusterVSMMapDao _clusterVSMMapDao;
|
||||||
@Inject
|
@Inject
|
||||||
private UserVmDetailsDao userVmDetailsDao;
|
private UserVmDetailsDao userVmDetailsDao;
|
||||||
@ -311,9 +305,9 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
|
|
||||||
private final long _nodeId = ManagementServerNode.getManagementServerId();
|
private final long _nodeId = ManagementServerNode.getManagementServerId();
|
||||||
|
|
||||||
private final HashMap<String, ResourceStateAdapter> _resourceStateAdapters = new HashMap<String, ResourceStateAdapter>();
|
private final HashMap<String, ResourceStateAdapter> _resourceStateAdapters = new HashMap<>();
|
||||||
|
|
||||||
private final HashMap<Integer, List<ResourceListener>> _lifeCycleListeners = new HashMap<Integer, List<ResourceListener>>();
|
private final HashMap<Integer, List<ResourceListener>> _lifeCycleListeners = new HashMap<>();
|
||||||
private HypervisorType _defaultSystemVMHypervisor;
|
private HypervisorType _defaultSystemVMHypervisor;
|
||||||
|
|
||||||
private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 30; // seconds
|
private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 30; // seconds
|
||||||
@ -323,11 +317,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
private SearchBuilder<HostGpuGroupsVO> _gpuAvailability;
|
private SearchBuilder<HostGpuGroupsVO> _gpuAvailability;
|
||||||
|
|
||||||
private void insertListener(final Integer event, final ResourceListener listener) {
|
private void insertListener(final Integer event, final ResourceListener listener) {
|
||||||
List<ResourceListener> lst = _lifeCycleListeners.get(event);
|
List<ResourceListener> lst = _lifeCycleListeners.computeIfAbsent(event, k -> new ArrayList<>());
|
||||||
if (lst == null) {
|
|
||||||
lst = new ArrayList<ResourceListener>();
|
|
||||||
_lifeCycleListeners.put(event, lst);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lst.contains(listener)) {
|
if (lst.contains(listener)) {
|
||||||
throw new CloudRuntimeException("Duplicate resource lisener:" + listener.getClass().getSimpleName());
|
throw new CloudRuntimeException("Duplicate resource lisener:" + listener.getClass().getSimpleName());
|
||||||
@ -369,9 +359,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
@Override
|
@Override
|
||||||
public void unregisterResourceEvent(final ResourceListener listener) {
|
public void unregisterResourceEvent(final ResourceListener listener) {
|
||||||
synchronized (_lifeCycleListeners) {
|
synchronized (_lifeCycleListeners) {
|
||||||
final Iterator it = _lifeCycleListeners.entrySet().iterator();
|
for (Map.Entry<Integer, List<ResourceListener>> items : _lifeCycleListeners.entrySet()) {
|
||||||
while (it.hasNext()) {
|
|
||||||
final Map.Entry<Integer, List<ResourceListener>> items = (Map.Entry<Integer, List<ResourceListener>>)it.next();
|
|
||||||
final List<ResourceListener> lst = items.getValue();
|
final List<ResourceListener> lst = items.getValue();
|
||||||
lst.remove(listener);
|
lst.remove(listener);
|
||||||
}
|
}
|
||||||
@ -380,7 +368,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
|
|
||||||
protected void processResourceEvent(final Integer event, final Object... params) {
|
protected void processResourceEvent(final Integer event, final Object... params) {
|
||||||
final List<ResourceListener> lst = _lifeCycleListeners.get(event);
|
final List<ResourceListener> lst = _lifeCycleListeners.get(event);
|
||||||
if (lst == null || lst.size() == 0) {
|
if (lst == null || lst.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,7 +409,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
|
|
||||||
@DB
|
@DB
|
||||||
@Override
|
@Override
|
||||||
public List<? extends Cluster> discoverCluster(final AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException, ResourceInUseException {
|
public List<? extends Cluster> discoverCluster(final AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException {
|
||||||
final long dcId = cmd.getZoneId();
|
final long dcId = cmd.getZoneId();
|
||||||
final long podId = cmd.getPodId();
|
final long podId = cmd.getPodId();
|
||||||
final String clusterName = cmd.getClusterName();
|
final String clusterName = cmd.getClusterName();
|
||||||
@ -430,10 +418,10 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
final String password = cmd.getPassword();
|
final String password = cmd.getPassword();
|
||||||
|
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
url = URLDecoder.decode(url);
|
url = URLDecoder.decode(url, com.cloud.utils.StringUtils.getPreferredCharset());
|
||||||
}
|
}
|
||||||
|
|
||||||
URI uri = null;
|
URI uri;
|
||||||
|
|
||||||
// Check if the zone exists in the system
|
// Check if the zone exists in the system
|
||||||
final DataCenterVO zone = _dcDao.findById(dcId);
|
final DataCenterVO zone = _dcDao.findById(dcId);
|
||||||
@ -520,7 +508,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
discoverer.putParam(allParams);
|
discoverer.putParam(allParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<ClusterVO> result = new ArrayList<ClusterVO>();
|
final List<ClusterVO> result = new ArrayList<>();
|
||||||
|
|
||||||
ClusterVO cluster = new ClusterVO(dcId, podId, clusterName);
|
ClusterVO cluster = new ClusterVO(dcId, podId, clusterName);
|
||||||
cluster.setHypervisorType(hypervisorType.toString());
|
cluster.setHypervisorType(hypervisorType.toString());
|
||||||
@ -540,7 +528,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
result.add(cluster);
|
result.add(cluster);
|
||||||
|
|
||||||
if (clusterType == Cluster.ClusterType.CloudManaged) {
|
if (clusterType == Cluster.ClusterType.CloudManaged) {
|
||||||
final Map<String, String> details = new HashMap<String, String>();
|
final Map<String, String> details = new HashMap<>();
|
||||||
// should do this nicer perhaps ?
|
// should do this nicer perhaps ?
|
||||||
if (hypervisorType == HypervisorType.Ovm3) {
|
if (hypervisorType == HypervisorType.Ovm3) {
|
||||||
final Map<String, String> allParams = cmd.getFullUrlParams();
|
final Map<String, String> allParams = cmd.getFullUrlParams();
|
||||||
@ -578,8 +566,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
throw new InvalidParameterValueException(url + " is not a valid uri");
|
throw new InvalidParameterValueException(url + " is not a valid uri");
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<HostVO> hosts = new ArrayList<HostVO>();
|
final List<HostVO> hosts = new ArrayList<>();
|
||||||
Map<? extends ServerResource, Map<String, String>> resources = null;
|
Map<? extends ServerResource, Map<String, String>> resources;
|
||||||
resources = discoverer.find(dcId, podId, cluster.getId(), uri, username, password, null);
|
resources = discoverer.find(dcId, podId, cluster.getId(), uri, username, password, null);
|
||||||
|
|
||||||
if (resources != null) {
|
if (resources != null) {
|
||||||
@ -670,7 +658,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
private List<HostVO> discoverHostsFull(final Long dcId, final Long podId, Long clusterId, final String clusterName, String url, String username, String password,
|
private List<HostVO> discoverHostsFull(final Long dcId, final Long podId, Long clusterId, final String clusterName, String url, String username, String password,
|
||||||
final String hypervisorType, final List<String> hostTags, final Map<String, String> params, final boolean deferAgentCreation) throws IllegalArgumentException, DiscoveryException,
|
final String hypervisorType, final List<String> hostTags, final Map<String, String> params, final boolean deferAgentCreation) throws IllegalArgumentException, DiscoveryException,
|
||||||
InvalidParameterValueException {
|
InvalidParameterValueException {
|
||||||
URI uri = null;
|
URI uri;
|
||||||
|
|
||||||
// Check if the zone exists in the system
|
// Check if the zone exists in the system
|
||||||
final DataCenterVO zone = _dcDao.findById(dcId);
|
final DataCenterVO zone = _dcDao.findById(dcId);
|
||||||
@ -808,7 +796,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
throw new InvalidParameterValueException(url + " is not a valid uri");
|
throw new InvalidParameterValueException(url + " is not a valid uri");
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<HostVO> hosts = new ArrayList<HostVO>();
|
final List<HostVO> hosts = new ArrayList<>();
|
||||||
s_logger.info("Trying to add a new host at " + url + " in data center " + dcId);
|
s_logger.info("Trying to add a new host at " + url + " in data center " + dcId);
|
||||||
boolean isHypervisorTypeSupported = false;
|
boolean isHypervisorTypeSupported = false;
|
||||||
for (final Discoverer discoverer : _discoverers) {
|
for (final Discoverer discoverer : _discoverers) {
|
||||||
@ -870,7 +858,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
HostVO host = null;
|
HostVO host;
|
||||||
if (deferAgentCreation) {
|
if (deferAgentCreation) {
|
||||||
host = (HostVO)createHostAndAgentDeferred(resource, entry.getValue(), true, hostTags, false);
|
host = (HostVO)createHostAndAgentDeferred(resource, entry.getValue(), true, hostTags, false);
|
||||||
} else {
|
} else {
|
||||||
@ -964,7 +952,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
_hostDao.remove(hostId);
|
_hostDao.remove(hostId);
|
||||||
if (clusterId != null) {
|
if (clusterId != null) {
|
||||||
final List<HostVO> hosts = listAllHostsInCluster(clusterId);
|
final List<HostVO> hosts = listAllHostsInCluster(clusterId);
|
||||||
if (hosts.size() == 0) {
|
if (hosts.isEmpty()) {
|
||||||
final ClusterVO cluster = _clusterDao.findById(clusterId);
|
final ClusterVO cluster = _clusterDao.findById(clusterId);
|
||||||
cluster.setGuid(null);
|
cluster.setGuid(null);
|
||||||
_clusterDao.update(clusterId, cluster);
|
_clusterDao.update(clusterId, cluster);
|
||||||
@ -1089,7 +1077,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
final Hypervisor.HypervisorType hypervisorType = cluster.getHypervisorType();
|
final Hypervisor.HypervisorType hypervisorType = cluster.getHypervisorType();
|
||||||
|
|
||||||
final List<HostVO> hosts = listAllHostsInCluster(cmd.getId());
|
final List<HostVO> hosts = listAllHostsInCluster(cmd.getId());
|
||||||
if (hosts.size() > 0) {
|
if (!hosts.isEmpty()) {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Cluster: " + cmd.getId() + " still has hosts, can't remove");
|
s_logger.debug("Cluster: " + cmd.getId() + " still has hosts, can't remove");
|
||||||
}
|
}
|
||||||
@ -1099,7 +1087,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
// don't allow to remove the cluster if it has non-removed storage
|
// don't allow to remove the cluster if it has non-removed storage
|
||||||
// pools
|
// pools
|
||||||
final List<StoragePoolVO> storagePools = _storagePoolDao.listPoolsByCluster(cmd.getId());
|
final List<StoragePoolVO> storagePools = _storagePoolDao.listPoolsByCluster(cmd.getId());
|
||||||
if (storagePools.size() > 0) {
|
if (!storagePools.isEmpty()) {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Cluster: " + cmd.getId() + " still has storage pools, can't remove");
|
s_logger.debug("Cluster: " + cmd.getId() + " still has storage pools, can't remove");
|
||||||
}
|
}
|
||||||
@ -1167,37 +1155,27 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Cluster.ClusterType newClusterType = null;
|
Cluster.ClusterType newClusterType;
|
||||||
if (clusterType != null && !clusterType.isEmpty()) {
|
if (clusterType != null && !clusterType.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
newClusterType = Cluster.ClusterType.valueOf(clusterType);
|
newClusterType = Cluster.ClusterType.valueOf(clusterType);
|
||||||
} catch (final IllegalArgumentException ex) {
|
} catch (final IllegalArgumentException ex) {
|
||||||
throw new InvalidParameterValueException("Unable to resolve " + clusterType + " to a supported type");
|
throw new InvalidParameterValueException("Unable to resolve " + clusterType + " to a supported type");
|
||||||
}
|
}
|
||||||
if (newClusterType == null) {
|
|
||||||
s_logger.error("Unable to resolve " + clusterType + " to a valid supported cluster type");
|
|
||||||
throw new InvalidParameterValueException("Unable to resolve " + clusterType + " to a supported type");
|
|
||||||
} else {
|
|
||||||
cluster.setClusterType(newClusterType);
|
cluster.setClusterType(newClusterType);
|
||||||
doUpdate = true;
|
doUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Grouping.AllocationState newAllocationState = null;
|
Grouping.AllocationState newAllocationState;
|
||||||
if (allocationState != null && !allocationState.isEmpty()) {
|
if (allocationState != null && !allocationState.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
newAllocationState = Grouping.AllocationState.valueOf(allocationState);
|
newAllocationState = Grouping.AllocationState.valueOf(allocationState);
|
||||||
} catch (final IllegalArgumentException ex) {
|
} catch (final IllegalArgumentException ex) {
|
||||||
throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationState + "' to a supported state");
|
throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationState + "' to a supported state");
|
||||||
}
|
}
|
||||||
if (newAllocationState == null) {
|
|
||||||
s_logger.error("Unable to resolve " + allocationState + " to a valid supported allocation State");
|
|
||||||
throw new InvalidParameterValueException("Unable to resolve " + allocationState + " to a supported state");
|
|
||||||
} else {
|
|
||||||
cluster.setAllocationState(newAllocationState);
|
cluster.setAllocationState(newAllocationState);
|
||||||
doUpdate = true;
|
doUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Managed.ManagedState newManagedState = null;
|
Managed.ManagedState newManagedState = null;
|
||||||
final Managed.ManagedState oldManagedState = cluster.getManagedState();
|
final Managed.ManagedState oldManagedState = cluster.getManagedState();
|
||||||
@ -1207,13 +1185,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
} catch (final IllegalArgumentException ex) {
|
} catch (final IllegalArgumentException ex) {
|
||||||
throw new InvalidParameterValueException("Unable to resolve Managed State '" + managedstate + "' to a supported state");
|
throw new InvalidParameterValueException("Unable to resolve Managed State '" + managedstate + "' to a supported state");
|
||||||
}
|
}
|
||||||
if (newManagedState == null) {
|
|
||||||
s_logger.error("Unable to resolve Managed State '" + managedstate + "' to a supported state");
|
|
||||||
throw new InvalidParameterValueException("Unable to resolve Managed State '" + managedstate + "' to a supported state");
|
|
||||||
} else {
|
|
||||||
doUpdate = true;
|
doUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (doUpdate) {
|
if (doUpdate) {
|
||||||
_clusterDao.update(cluster.getId(), cluster);
|
_clusterDao.update(cluster.getId(), cluster);
|
||||||
@ -1240,12 +1213,13 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
final int retry = 40;
|
final int retry = 40;
|
||||||
boolean lsuccess = true;
|
boolean lsuccess;
|
||||||
for (int i = 0; i < retry; i++) {
|
for (int i = 0; i < retry; i++) {
|
||||||
lsuccess = true;
|
lsuccess = true;
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5 * 1000);
|
Thread.currentThread().wait(5 * 1000);
|
||||||
} catch (final Exception e) {
|
} catch (final InterruptedException e) {
|
||||||
|
s_logger.debug("thread unexpectedly interupted during wait, while updating cluster");
|
||||||
}
|
}
|
||||||
hosts = listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
|
hosts = listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
|
||||||
for (final HostVO host : hosts) {
|
for (final HostVO host : hosts) {
|
||||||
@ -1254,12 +1228,12 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lsuccess == true) {
|
if (lsuccess) {
|
||||||
success = true;
|
success = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (success == false) {
|
if (!success) {
|
||||||
throw new CloudRuntimeException("PrepareUnmanaged Failed due to some hosts are still in UP status after 5 Minutes, please try later ");
|
throw new CloudRuntimeException("PrepareUnmanaged Failed due to some hosts are still in UP status after 5 Minutes, please try later ");
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -1377,7 +1351,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
if (host.getType() == Host.Type.Routing) {
|
if (host.getType() == Host.Type.Routing) {
|
||||||
|
|
||||||
final List<VMInstanceVO> vms = _vmDao.listByHostId(hostId);
|
final List<VMInstanceVO> vms = _vmDao.listByHostId(hostId);
|
||||||
if (vms.size() == 0) {
|
if (vms.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1405,7 +1379,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
String logMessage = String.format(
|
String logMessage = String.format(
|
||||||
"Unsupported host.maintenance.local.storage.strategy: %s. Please set a strategy according to the global settings description: "
|
"Unsupported host.maintenance.local.storage.strategy: %s. Please set a strategy according to the global settings description: "
|
||||||
+ "'Error', 'Migration', or 'ForceStop'.",
|
+ "'Error', 'Migration', or 'ForceStop'.",
|
||||||
HOST_MAINTENANCE_LOCAL_STRATEGY.value().toString());
|
HOST_MAINTENANCE_LOCAL_STRATEGY.value());
|
||||||
s_logger.error(logMessage);
|
s_logger.error(logMessage);
|
||||||
throw new CloudRuntimeException("There are active VMs using the host's local storage pool. Please stop all VMs on this host that use local storage.");
|
throw new CloudRuntimeException("There are active VMs using the host's local storage pool. Please stop all VMs on this host that use local storage.");
|
||||||
}
|
}
|
||||||
@ -1461,13 +1435,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
ServiceOfferingVO offeringVO = serviceOfferingDao.findById(vm.getServiceOfferingId());
|
ServiceOfferingVO offeringVO = serviceOfferingDao.findById(vm.getServiceOfferingId());
|
||||||
final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, offeringVO, null, null);
|
final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, offeringVO, null, null);
|
||||||
plan.setMigrationPlan(true);
|
plan.setMigrationPlan(true);
|
||||||
DeployDestination dest = null;
|
DeployDestination dest = getDeployDestination(vm, profile, plan);
|
||||||
try {
|
|
||||||
dest = deploymentManager.planDeployment(profile, plan, new DeploymentPlanner.ExcludeList(), null);
|
|
||||||
} catch (InsufficientServerCapacityException e) {
|
|
||||||
throw new CloudRuntimeException(String.format("Maintenance failed, could not find deployment destination for VM [id=%s, name=%s].", vm.getId(), vm.getInstanceName()),
|
|
||||||
e);
|
|
||||||
}
|
|
||||||
Host destHost = dest.getHost();
|
Host destHost = dest.getHost();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -1479,6 +1447,20 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DeployDestination getDeployDestination(VMInstanceVO vm, VirtualMachineProfile profile, DataCenterDeployment plan) {
|
||||||
|
DeployDestination dest;
|
||||||
|
try {
|
||||||
|
dest = deploymentManager.planDeployment(profile, plan, new DeploymentPlanner.ExcludeList(), null);
|
||||||
|
} catch (InsufficientServerCapacityException e) {
|
||||||
|
throw new CloudRuntimeException(String.format("Maintenance failed, could not find deployment destination for VM [id=%s, name=%s].", vm.getId(), vm.getInstanceName()),
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
if (dest == null) {
|
||||||
|
throw new CloudRuntimeException(String.format("Maintenance failed, could not find deployment destination for VM [id=%s, name=%s], using plan: %s.", vm.getId(), vm.getInstanceName(), plan));
|
||||||
|
}
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean maintain(final long hostId) throws AgentUnavailableException {
|
public boolean maintain(final long hostId) throws AgentUnavailableException {
|
||||||
final Boolean result = propagateResourceEvent(hostId, ResourceState.Event.AdminAskMaintenance);
|
final Boolean result = propagateResourceEvent(hostId, ResourceState.Event.AdminAskMaintenance);
|
||||||
@ -1526,15 +1508,15 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
|
|
||||||
List<VMInstanceVO> migratingInVMs = _vmDao.findByHostInStates(hostId, State.Migrating);
|
List<VMInstanceVO> migratingInVMs = _vmDao.findByHostInStates(hostId, State.Migrating);
|
||||||
|
|
||||||
if (migratingInVMs.size() > 0) {
|
if (!migratingInVMs.isEmpty()) {
|
||||||
throw new CloudRuntimeException("Host contains incoming VMs migrating. Please wait for them to complete before putting to maintenance.");
|
throw new CloudRuntimeException("Host contains incoming VMs migrating. Please wait for them to complete before putting to maintenance.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_vmDao.findByHostInStates(hostId, State.Starting, State.Stopping).size() > 0) {
|
if (!_vmDao.findByHostInStates(hostId, State.Starting, State.Stopping).isEmpty()) {
|
||||||
throw new CloudRuntimeException("Host contains VMs in starting/stopping state. Please wait for them to complete before putting to maintenance.");
|
throw new CloudRuntimeException("Host contains VMs in starting/stopping state. Please wait for them to complete before putting to maintenance.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_vmDao.findByHostInStates(hostId, State.Error, State.Unknown).size() > 0) {
|
if (!_vmDao.findByHostInStates(hostId, State.Error, State.Unknown).isEmpty()) {
|
||||||
throw new CloudRuntimeException("Host contains VMs in error/unknown/shutdown state. Please fix errors to proceed.");
|
throw new CloudRuntimeException("Host contains VMs in error/unknown/shutdown state. Please fix errors to proceed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1555,25 +1537,22 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
if(StringUtils.isBlank(HOST_MAINTENANCE_LOCAL_STRATEGY.value())) {
|
if(StringUtils.isBlank(HOST_MAINTENANCE_LOCAL_STRATEGY.value())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return HOST_MAINTENANCE_LOCAL_STRATEGY.value().toLowerCase().equals(WorkType.Migration.toString().toLowerCase());
|
return HOST_MAINTENANCE_LOCAL_STRATEGY.value().equalsIgnoreCase(WorkType.Migration.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isMaintenanceLocalStrategyForceStop() {
|
protected boolean isMaintenanceLocalStrategyForceStop() {
|
||||||
if(StringUtils.isBlank(HOST_MAINTENANCE_LOCAL_STRATEGY.value())) {
|
if(StringUtils.isBlank(HOST_MAINTENANCE_LOCAL_STRATEGY.value())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return HOST_MAINTENANCE_LOCAL_STRATEGY.value().toLowerCase().equals(WorkType.ForceStop.toString().toLowerCase());
|
return HOST_MAINTENANCE_LOCAL_STRATEGY.value().equalsIgnoreCase(WorkType.ForceStop.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the host.maintenance.local.storage.strategy is the Default: "Error", blank, empty, or null.
|
* Returns true if the host.maintenance.local.storage.strategy is the Default: "Error", blank, empty, or null.
|
||||||
*/
|
*/
|
||||||
protected boolean isMaintenanceLocalStrategyDefault() {
|
protected boolean isMaintenanceLocalStrategyDefault() {
|
||||||
if (StringUtils.isBlank(HOST_MAINTENANCE_LOCAL_STRATEGY.value().toString())
|
return StringUtils.isBlank(HOST_MAINTENANCE_LOCAL_STRATEGY.value())
|
||||||
|| HOST_MAINTENANCE_LOCAL_STRATEGY.value().toLowerCase().equals(State.Error.toString().toLowerCase())) {
|
|| HOST_MAINTENANCE_LOCAL_STRATEGY.value().equalsIgnoreCase(State.Error.toString());
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1640,7 +1619,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
HostVO host = _hostDao.findById(hostId);
|
HostVO host = _hostDao.findById(hostId);
|
||||||
|
|
||||||
if (host == null || host.getRemoved() != null) {
|
if (host == null || host.getRemoved() != null) {
|
||||||
throw new InvalidParameterValueException(String.format("Host [id=%s] does not exist", host.getId()));
|
throw new InvalidParameterValueException(String.format("Host [id=%s] does not exist", host == null ? "<unknown>" : host.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (host.getResourceState() != ResourceState.Degraded) {
|
if (host.getResourceState() != ResourceState.Degraded) {
|
||||||
@ -1725,7 +1704,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
* Return true if host goes into Maintenance mode. There are various possibilities for VMs' states
|
* Return true if host goes into Maintenance mode. There are various possibilities for VMs' states
|
||||||
* on a host. We need to track the various VM states on each run and accordingly transit to the
|
* on a host. We need to track the various VM states on each run and accordingly transit to the
|
||||||
* appropriate state.
|
* appropriate state.
|
||||||
*
|
|
||||||
* We change states as follows -
|
* We change states as follows -
|
||||||
* 1. If there are no VMs in running, migrating, starting, stopping, error, unknown states we can move
|
* 1. If there are no VMs in running, migrating, starting, stopping, error, unknown states we can move
|
||||||
* to maintenance state. Note that there cannot be incoming migrations as the API Call prepare for
|
* to maintenance state. Note that there cannot be incoming migrations as the API Call prepare for
|
||||||
@ -1899,7 +1877,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
guestOSDetail.setValue(String.valueOf(guestOSCategory.getId()));
|
guestOSDetail.setValue(String.valueOf(guestOSCategory.getId()));
|
||||||
_hostDetailsDao.update(guestOSDetail.getId(), guestOSDetail);
|
_hostDetailsDao.update(guestOSDetail.getId(), guestOSDetail);
|
||||||
} else {
|
} else {
|
||||||
final Map<String, String> detail = new HashMap<String, String>();
|
final Map<String, String> detail = new HashMap<>();
|
||||||
detail.put("guest.os.category.id", String.valueOf(guestOSCategory.getId()));
|
detail.put("guest.os.category.id", String.valueOf(guestOSCategory.getId()));
|
||||||
_hostDetailsDao.persist(hostId, detail);
|
_hostDetailsDao.persist(hostId, detail);
|
||||||
}
|
}
|
||||||
@ -2049,9 +2027,9 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<HypervisorType> getSupportedHypervisorTypes(final long zoneId, final boolean forVirtualRouter, final Long podId) {
|
public List<HypervisorType> getSupportedHypervisorTypes(final long zoneId, final boolean forVirtualRouter, final Long podId) {
|
||||||
final List<HypervisorType> hypervisorTypes = new ArrayList<HypervisorType>();
|
final List<HypervisorType> hypervisorTypes = new ArrayList<>();
|
||||||
|
|
||||||
List<ClusterVO> clustersForZone = new ArrayList<ClusterVO>();
|
List<ClusterVO> clustersForZone;
|
||||||
if (podId != null) {
|
if (podId != null) {
|
||||||
clustersForZone = _clusterDao.listByPodId(podId);
|
clustersForZone = _clusterDao.listByPodId(podId);
|
||||||
} else {
|
} else {
|
||||||
@ -2060,7 +2038,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
|
|
||||||
for (final ClusterVO cluster : clustersForZone) {
|
for (final ClusterVO cluster : clustersForZone) {
|
||||||
final HypervisorType hType = cluster.getHypervisorType();
|
final HypervisorType hType = cluster.getHypervisorType();
|
||||||
if (!forVirtualRouter || forVirtualRouter && hType != HypervisorType.BareMetal && hType != HypervisorType.Ovm) {
|
if (!forVirtualRouter || (hType != HypervisorType.BareMetal && hType != HypervisorType.Ovm)) {
|
||||||
hypervisorTypes.add(hType);
|
hypervisorTypes.add(hType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2096,7 +2074,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
|
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
final List<ClusterVO> clusters = _clusterDao.listByDcHyType(zoneId, defaultHyper.toString());
|
final List<ClusterVO> clusters = _clusterDao.listByDcHyType(zoneId, defaultHyper.toString());
|
||||||
if (clusters.size() <= 0) {
|
if (clusters.isEmpty()) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2113,7 +2091,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
HypervisorType defaultHype = getDefaultHypervisor(zoneId);
|
HypervisorType defaultHype = getDefaultHypervisor(zoneId);
|
||||||
if (defaultHype == HypervisorType.None) {
|
if (defaultHype == HypervisorType.None) {
|
||||||
final List<HypervisorType> supportedHypes = getSupportedHypervisorTypes(zoneId, false, null);
|
final List<HypervisorType> supportedHypes = getSupportedHypervisorTypes(zoneId, false, null);
|
||||||
if (supportedHypes.size() > 0) {
|
if (!supportedHypes.isEmpty()) {
|
||||||
Collections.shuffle(supportedHypes);
|
Collections.shuffle(supportedHypes);
|
||||||
defaultHype = supportedHypes.get(0);
|
defaultHype = supportedHypes.get(0);
|
||||||
}
|
}
|
||||||
@ -2237,10 +2215,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
final String cidrNetmask = NetUtils.getCidrSubNet("255.255.255.255", cidrSize);
|
final String cidrNetmask = NetUtils.getCidrSubNet("255.255.255.255", cidrSize);
|
||||||
final long cidrNetmaskNumeric = NetUtils.ip2Long(cidrNetmask);
|
final long cidrNetmaskNumeric = NetUtils.ip2Long(cidrNetmask);
|
||||||
final long serverNetmaskNumeric = NetUtils.ip2Long(serverPrivateNetmask);
|
final long serverNetmaskNumeric = NetUtils.ip2Long(serverPrivateNetmask);
|
||||||
if (serverNetmaskNumeric > cidrNetmaskNumeric) {
|
return serverNetmaskNumeric <= cidrNetmaskNumeric;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private HostVO getNewHost(StartupCommand[] startupCommands) {
|
private HostVO getNewHost(StartupCommand[] startupCommands) {
|
||||||
@ -2254,11 +2229,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
|
|
||||||
host = findHostByGuid(startupCommand.getGuidWithoutResource());
|
host = findHostByGuid(startupCommand.getGuidWithoutResource());
|
||||||
|
|
||||||
if (host != null) {
|
return host; // even when host == null!
|
||||||
return host;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HostVO createHostVO(final StartupCommand[] cmds, final ServerResource resource, final Map<String, String> details, List<String> hostTags,
|
protected HostVO createHostVO(final StartupCommand[] cmds, final ServerResource resource, final Map<String, String> details, List<String> hostTags,
|
||||||
@ -2289,11 +2260,11 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long dcId = -1;
|
long dcId;
|
||||||
DataCenterVO dc = _dcDao.findByName(dataCenter);
|
DataCenterVO dc = _dcDao.findByName(dataCenter);
|
||||||
if (dc == null) {
|
if (dc == null) {
|
||||||
try {
|
try {
|
||||||
dcId = Long.parseLong(dataCenter);
|
dcId = Long.parseLong(dataCenter != null ? dataCenter : "-1");
|
||||||
dc = _dcDao.findById(dcId);
|
dc = _dcDao.findById(dcId);
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
s_logger.debug("Cannot parse " + dataCenter + " into Long.");
|
s_logger.debug("Cannot parse " + dataCenter + " into Long.");
|
||||||
@ -2307,7 +2278,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
HostPodVO p = _podDao.findByName(pod, dcId);
|
HostPodVO p = _podDao.findByName(pod, dcId);
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
try {
|
try {
|
||||||
final long podId = Long.parseLong(pod);
|
final long podId = Long.parseLong(pod != null ? pod : "-1");
|
||||||
p = _podDao.findById(podId);
|
p = _podDao.findById(podId);
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
s_logger.debug("Cannot parse " + pod + " into Long.");
|
s_logger.debug("Cannot parse " + pod + " into Long.");
|
||||||
@ -2326,9 +2297,9 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
clusterId = Long.valueOf(cluster);
|
clusterId = Long.valueOf(cluster);
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
if (podId != null) {
|
if (podId != null) {
|
||||||
ClusterVO c = _clusterDao.findBy(cluster, podId.longValue());
|
ClusterVO c = _clusterDao.findBy(cluster, podId);
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
c = new ClusterVO(dcId, podId.longValue(), cluster);
|
c = new ClusterVO(dcId, podId, cluster);
|
||||||
c = _clusterDao.persist(c);
|
c = _clusterDao.persist(c);
|
||||||
}
|
}
|
||||||
clusterId = c.getId();
|
clusterId = c.getId();
|
||||||
@ -2445,7 +2416,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
for (HostVO hostVO : hostVOs) {
|
for (HostVO hostVO : hostVOs) {
|
||||||
DetailVO hostDetailVO = _hostDetailsDao.findDetail(hostVO.getId(), name);
|
DetailVO hostDetailVO = _hostDetailsDao.findDetail(hostVO.getId(), name);
|
||||||
|
|
||||||
if (hostDetailVO == null || Boolean.parseBoolean(hostDetailVO.getValue()) == false) {
|
if (hostDetailVO == null || !Boolean.parseBoolean(hostDetailVO.getValue())) {
|
||||||
clusterSupportsResigning = false;
|
clusterSupportsResigning = false;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -2533,7 +2504,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
new Request(-1l, -1l, cmds, true, false).logD("Startup request from directly connected host: ", true);
|
new Request(-1L, -1L, cmds, true, false).logD("Startup request from directly connected host: ", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (old) {
|
if (old) {
|
||||||
@ -2603,7 +2574,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
new Request(-1l, -1l, cmds, true, false).logD("Startup request from directly connected host: ", true);
|
new Request(-1L, -1L, cmds, true, false).logD("Startup request from directly connected host: ", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (old) {
|
if (old) {
|
||||||
@ -2688,8 +2659,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Host createHostAndAgent(final Long hostId, final ServerResource resource, final Map<String, String> details, final boolean old, final List<String> hostTags, final boolean forRebalance) {
|
public Host createHostAndAgent(final Long hostId, final ServerResource resource, final Map<String, String> details, final boolean old, final List<String> hostTags, final boolean forRebalance) {
|
||||||
final Host host = createHostAndAgent(resource, details, old, hostTags, forRebalance);
|
return createHostAndAgent(resource, details, old, hostTags, forRebalance);
|
||||||
return host;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -2699,8 +2669,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
throw new InvalidParameterValueException("Can't find zone with id " + zoneId);
|
throw new InvalidParameterValueException("Can't find zone with id " + zoneId);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<String, String> details = hostDetails;
|
final String guid = hostDetails.get("guid");
|
||||||
final String guid = details.get("guid");
|
|
||||||
final List<HostVO> currentHosts = listAllUpAndEnabledHostsInOneZoneByType(hostType, zoneId);
|
final List<HostVO> currentHosts = listAllUpAndEnabledHostsInOneZoneByType(hostType, zoneId);
|
||||||
for (final HostVO currentHost : currentHosts) {
|
for (final HostVO currentHost : currentHosts) {
|
||||||
if (currentHost.getGuid().equals(guid)) {
|
if (currentHost.getGuid().equals(guid)) {
|
||||||
@ -2716,7 +2685,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
return createHostVO(cmds, null, null, null, ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_CONNECTED);
|
return createHostVO(cmds, null, null, null, ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_CONNECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkIPConflicts(final HostPodVO pod, final DataCenterVO dc, final String serverPrivateIP, final String serverPrivateNetmask, final String serverPublicIP, final String serverPublicNetmask) {
|
private void checkIPConflicts(final HostPodVO pod, final DataCenterVO dc, final String serverPrivateIP, final String serverPublicIP) {
|
||||||
// If the server's private IP is the same as is public IP, this host has
|
// If the server's private IP is the same as is public IP, this host has
|
||||||
// a host-only private network. Don't check for conflicts with the
|
// a host-only private network. Don't check for conflicts with the
|
||||||
// private IP address table.
|
// private IP address table.
|
||||||
@ -2745,7 +2714,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
// If the server's public IP address is already in the database,
|
// If the server's public IP address is already in the database,
|
||||||
// return false
|
// return false
|
||||||
final List<IPAddressVO> existingPublicIPs = _publicIPAddressDao.listByDcIdIpAddress(dc.getId(), serverPublicIP);
|
final List<IPAddressVO> existingPublicIPs = _publicIPAddressDao.listByDcIdIpAddress(dc.getId(), serverPublicIP);
|
||||||
if (existingPublicIPs.size() > 0) {
|
if (!existingPublicIPs.isEmpty()) {
|
||||||
throw new IllegalArgumentException("The public ip address of the server (" + serverPublicIP + ") is already in use in zone: " + dc.getName());
|
throw new IllegalArgumentException("The public ip address of the server (" + serverPublicIP + ") is already in use in zone: " + dc.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2775,7 +2744,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
|
|
||||||
final HostPodVO pod = _podDao.findById(host.getPodId());
|
final HostPodVO pod = _podDao.findById(host.getPodId());
|
||||||
final DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
|
final DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
|
||||||
checkIPConflicts(pod, dc, ssCmd.getPrivateIpAddress(), ssCmd.getPublicIpAddress(), ssCmd.getPublicIpAddress(), ssCmd.getPublicNetmask());
|
checkIPConflicts(pod, dc, ssCmd.getPrivateIpAddress(), ssCmd.getPublicIpAddress());
|
||||||
host.setType(com.cloud.host.Host.Type.Routing);
|
host.setType(com.cloud.host.Host.Type.Routing);
|
||||||
host.setDetails(details);
|
host.setDetails(details);
|
||||||
host.setCaps(ssCmd.getCapabilities());
|
host.setCaps(ssCmd.getCapabilities());
|
||||||
@ -2812,8 +2781,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
throw new UnableDeleteHostException("Failed to set primary storage into maintenance mode");
|
throw new UnableDeleteHostException("Failed to set primary storage into maintenance mode");
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
s_logger.debug("Failed to set primary storage into maintenance mode, due to: " + e.toString());
|
s_logger.debug("Failed to set primary storage into maintenance mode", e);
|
||||||
throw new UnableDeleteHostException("Failed to set primary storage into maintenance mode, due to: " + e.toString());
|
throw new UnableDeleteHostException("Failed to set primary storage into maintenance mode, due to: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2957,7 +2926,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
if (result.getReturnCode() != 0) {
|
if (result.getReturnCode() != 0) {
|
||||||
throw new CloudRuntimeException(String.format("Could not restart agent on %s due to: %s", host, result.getStdErr()));
|
throw new CloudRuntimeException(String.format("Could not restart agent on %s due to: %s", host, result.getStdErr()));
|
||||||
}
|
}
|
||||||
s_logger.debug("cloudstack-agent restart result: " + result.toString());
|
s_logger.debug("cloudstack-agent restart result: " + result);
|
||||||
} catch (final SshException e) {
|
} catch (final SshException e) {
|
||||||
throw new CloudRuntimeException("SSH to agent is enabled, but agent restart failed", e);
|
throw new CloudRuntimeException("SSH to agent is enabled, but agent restart failed", e);
|
||||||
}
|
}
|
||||||
@ -2978,7 +2947,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean executeUserRequest(final long hostId, final ResourceState.Event event) throws AgentUnavailableException {
|
public boolean executeUserRequest(final long hostId, final ResourceState.Event event) {
|
||||||
if (event == ResourceState.Event.AdminAskMaintenance) {
|
if (event == ResourceState.Event.AdminAskMaintenance) {
|
||||||
return doMaintain(hostId);
|
return doMaintain(hostId);
|
||||||
} else if (event == ResourceState.Event.AdminCancelMaintenance) {
|
} else if (event == ResourceState.Event.AdminCancelMaintenance) {
|
||||||
@ -3292,7 +3261,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
// The search is not able to return list of enums, so getting
|
// The search is not able to return list of enums, so getting
|
||||||
// list of hypervisors as strings and then converting them to enum
|
// list of hypervisors as strings and then converting them to enum
|
||||||
final List<String> hvs = _hostDao.customSearch(sc, null);
|
final List<String> hvs = _hostDao.customSearch(sc, null);
|
||||||
final List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
|
final List<HypervisorType> hypervisors = new ArrayList<>();
|
||||||
for (final String hv : hvs) {
|
for (final String hv : hvs) {
|
||||||
hypervisors.add(HypervisorType.getType(hv));
|
hypervisors.add(HypervisorType.getType(hv));
|
||||||
}
|
}
|
||||||
@ -3317,7 +3286,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
public HostStats getHostStatistics(final long hostId) {
|
public HostStats getHostStatistics(final long hostId) {
|
||||||
final Answer answer = _agentMgr.easySend(hostId, new GetHostStatsCommand(_hostDao.findById(hostId).getGuid(), _hostDao.findById(hostId).getName(), hostId));
|
final Answer answer = _agentMgr.easySend(hostId, new GetHostStatsCommand(_hostDao.findById(hostId).getGuid(), _hostDao.findById(hostId).getName(), hostId));
|
||||||
|
|
||||||
if (answer != null && answer instanceof UnsupportedAnswer) {
|
if (answer instanceof UnsupportedAnswer) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3354,20 +3323,16 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
@Override
|
@Override
|
||||||
public String getHostTags(final long hostId) {
|
public String getHostTags(final long hostId) {
|
||||||
final List<String> hostTags = _hostTagsDao.getHostTags(hostId).parallelStream().map(HostTagVO::getTag).collect(Collectors.toList());
|
final List<String> hostTags = _hostTagsDao.getHostTags(hostId).parallelStream().map(HostTagVO::getTag).collect(Collectors.toList());
|
||||||
if (hostTags == null) {
|
return StringUtils.listToCsvTags(hostTags);
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return com.cloud.utils.StringUtils.listToCsvTags(hostTags);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PodCluster> listByDataCenter(final long dcId) {
|
public List<PodCluster> listByDataCenter(final long dcId) {
|
||||||
final List<HostPodVO> pods = _podDao.listByDataCenterId(dcId);
|
final List<HostPodVO> pods = _podDao.listByDataCenterId(dcId);
|
||||||
final ArrayList<PodCluster> pcs = new ArrayList<PodCluster>();
|
final ArrayList<PodCluster> pcs = new ArrayList<>();
|
||||||
for (final HostPodVO pod : pods) {
|
for (final HostPodVO pod : pods) {
|
||||||
final List<ClusterVO> clusters = _clusterDao.listByPodId(pod.getId());
|
final List<ClusterVO> clusters = _clusterDao.listByPodId(pod.getId());
|
||||||
if (clusters.size() == 0) {
|
if (clusters.isEmpty()) {
|
||||||
pcs.add(new PodCluster(pod, null));
|
pcs.add(new PodCluster(pod, null));
|
||||||
} else {
|
} else {
|
||||||
for (final ClusterVO cluster : clusters) {
|
for (final ClusterVO cluster : clusters) {
|
||||||
@ -3412,7 +3377,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
public boolean isHostGpuEnabled(final long hostId) {
|
public boolean isHostGpuEnabled(final long hostId) {
|
||||||
final SearchCriteria<HostGpuGroupsVO> sc = _gpuAvailability.create();
|
final SearchCriteria<HostGpuGroupsVO> sc = _gpuAvailability.create();
|
||||||
sc.setParameters("hostId", hostId);
|
sc.setParameters("hostId", hostId);
|
||||||
return _hostGpuGroupsDao.customSearch(sc, null).size() > 0 ? true : false;
|
return !_hostGpuGroupsDao.customSearch(sc, null).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -3477,7 +3442,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
// Update GPU group capacity
|
// Update GPU group capacity
|
||||||
final TransactionLegacy txn = TransactionLegacy.currentTxn();
|
final TransactionLegacy txn = TransactionLegacy.currentTxn();
|
||||||
txn.start();
|
txn.start();
|
||||||
_hostGpuGroupsDao.persist(hostId, new ArrayList<String>(groupDetails.keySet()));
|
_hostGpuGroupsDao.persist(hostId, new ArrayList<>(groupDetails.keySet()));
|
||||||
_vgpuTypesDao.persist(hostId, groupDetails);
|
_vgpuTypesDao.persist(hostId, groupDetails);
|
||||||
txn.commit();
|
txn.commit();
|
||||||
}
|
}
|
||||||
@ -3485,7 +3450,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
@Override
|
@Override
|
||||||
public HashMap<String, HashMap<String, VgpuTypesInfo>> getGPUStatistics(final HostVO host) {
|
public HashMap<String, HashMap<String, VgpuTypesInfo>> getGPUStatistics(final HostVO host) {
|
||||||
final Answer answer = _agentMgr.easySend(host.getId(), new GetGPUStatsCommand(host.getGuid(), host.getName()));
|
final Answer answer = _agentMgr.easySend(host.getId(), new GetGPUStatsCommand(host.getGuid(), host.getName()));
|
||||||
if (answer != null && answer instanceof UnsupportedAnswer) {
|
if (answer instanceof UnsupportedAnswer) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (answer == null || !answer.getResult()) {
|
if (answer == null || !answer.getResult()) {
|
||||||
@ -3526,7 +3491,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
|||||||
@ActionEvent(eventType = EventTypes.EVENT_HOST_RESERVATION_RELEASE, eventDescription = "releasing host reservation", async = true)
|
@ActionEvent(eventType = EventTypes.EVENT_HOST_RESERVATION_RELEASE, eventDescription = "releasing host reservation", async = true)
|
||||||
public boolean releaseHostReservation(final Long hostId) {
|
public boolean releaseHostReservation(final Long hostId) {
|
||||||
try {
|
try {
|
||||||
return Transaction.execute(new TransactionCallback<Boolean>() {
|
return Transaction.execute(new TransactionCallback<>() {
|
||||||
@Override
|
@Override
|
||||||
public Boolean doInTransaction(final TransactionStatus status) {
|
public Boolean doInTransaction(final TransactionStatus status) {
|
||||||
final PlannerHostReservationVO reservationEntry = _plannerHostReserveDao.findByHostId(hostId);
|
final PlannerHostReservationVO reservationEntry = _plannerHostReserveDao.findByHostId(hostId);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user