You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2013/04/06 02:35:26 UTC
[53/57] [abbrv] Renamed internal classes to use "imageStorexxx"
instead of previous "imageDataStorexxx". Add new addImageStoreCmd to use 3
image store provider plugins.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a872d6d3/server/src/com/cloud/resource/ResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java
index e9b0c82..27df1af 100755
--- a/server/src/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/com/cloud/resource/ResourceManagerImpl.java
@@ -41,20 +41,17 @@ import org.apache.cloudstack.api.command.admin.host.PrepareForMaintenanceCmd;
import org.apache.cloudstack.api.command.admin.host.ReconnectHostCmd;
import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd;
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
+import org.apache.cloudstack.api.command.admin.storage.AddImageStoreCmd;
import org.apache.cloudstack.api.command.admin.storage.AddS3Cmd;
import org.apache.cloudstack.api.command.admin.storage.ListS3sCmd;
import org.apache.cloudstack.api.command.admin.swift.AddSwiftCmd;
import org.apache.cloudstack.api.command.admin.swift.ListSwiftsCmd;
-import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
-import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
-import org.apache.cloudstack.region.RegionVO;
import org.apache.cloudstack.region.dao.RegionDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
@@ -118,7 +115,7 @@ import com.cloud.org.Grouping.AllocationState;
import com.cloud.org.Managed;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.GuestOSCategoryVO;
-import com.cloud.storage.ObjectStore;
+import com.cloud.storage.ImageStore;
import com.cloud.storage.S3;
import com.cloud.storage.S3VO;
import com.cloud.storage.ScopeType;
@@ -167,94 +164,95 @@ import com.cloud.vm.dao.VMInstanceDao;
@Component
@Local({ ResourceManager.class, ResourceService.class })
-public class ResourceManagerImpl extends ManagerBase implements ResourceManager, ResourceService,
- Manager {
- private static final Logger s_logger = Logger
- .getLogger(ResourceManagerImpl.class);
+public class ResourceManagerImpl extends ManagerBase implements ResourceManager, ResourceService, Manager {
+ private static final Logger s_logger = Logger.getLogger(ResourceManagerImpl.class);
@Inject
- AccountManager _accountMgr;
+ AccountManager _accountMgr;
@Inject
- AgentManager _agentMgr;
+ AgentManager _agentMgr;
@Inject
- StorageManager _storageMgr;
+ StorageManager _storageMgr;
@Inject
- protected SecondaryStorageVmManager _secondaryStorageMgr;
+ protected SecondaryStorageVmManager _secondaryStorageMgr;
@Inject
- DataStoreProviderManager _dataStoreProviderMgr;
+ DataStoreProviderManager _dataStoreProviderMgr;
@Inject
- protected RegionDao _regionDao;
+ protected RegionDao _regionDao;
@Inject
- protected DataCenterDao _dcDao;
+ protected DataCenterDao _dcDao;
@Inject
- protected HostPodDao _podDao;
+ protected HostPodDao _podDao;
@Inject
- protected ClusterDetailsDao _clusterDetailsDao;
+ protected ClusterDetailsDao _clusterDetailsDao;
@Inject
- protected ClusterDao _clusterDao;
+ protected ClusterDao _clusterDao;
@Inject
- protected CapacityDao _capacityDao;
+ protected CapacityDao _capacityDao;
@Inject
- protected HostDao _hostDao;
+ protected HostDao _hostDao;
@Inject
protected SwiftManager _swiftMgr;
@Inject
- protected S3Manager _s3Mgr;
+ protected S3Manager _s3Mgr;
@Inject
- protected HostDetailsDao _hostDetailsDao;
+ protected HostDetailsDao _hostDetailsDao;
@Inject
protected ConfigurationDao _configDao;
@Inject
- protected HostTagsDao _hostTagsDao;
+ protected HostTagsDao _hostTagsDao;
@Inject
- protected GuestOSCategoryDao _guestOSCategoryDao;
+ protected GuestOSCategoryDao _guestOSCategoryDao;
@Inject
- protected PrimaryDataStoreDao _storagePoolDao;
+ protected PrimaryDataStoreDao _storagePoolDao;
@Inject
- protected DataCenterIpAddressDao _privateIPAddressDao;
+ protected DataCenterIpAddressDao _privateIPAddressDao;
@Inject
- protected IPAddressDao _publicIPAddressDao;
+ protected IPAddressDao _publicIPAddressDao;
@Inject
- protected VirtualMachineManager _vmMgr;
+ protected VirtualMachineManager _vmMgr;
@Inject
- protected VMInstanceDao _vmDao;
+ protected VMInstanceDao _vmDao;
@Inject
- protected HighAvailabilityManager _haMgr;
+ protected HighAvailabilityManager _haMgr;
@Inject
- protected StorageService _storageSvr;
+ protected StorageService _storageSvr;
@Inject
DataStoreManager _dataStoreMgr;
-
protected List<? extends Discoverer> _discoverers;
+
public List<? extends Discoverer> getDiscoverers() {
- return _discoverers;
- }
- public void setDiscoverers(List<? extends Discoverer> _discoverers) {
- this._discoverers = _discoverers;
- }
-
- @Inject
- protected ClusterManager _clusterMgr;
+ return _discoverers;
+ }
+
+ public void setDiscoverers(List<? extends Discoverer> _discoverers) {
+ this._discoverers = _discoverers;
+ }
+
+ @Inject
+ protected ClusterManager _clusterMgr;
@Inject
- protected StoragePoolHostDao _storagePoolHostDao;
+ protected StoragePoolHostDao _storagePoolHostDao;
+
+ protected List<PodAllocator> _podAllocators;
- protected List<PodAllocator> _podAllocators;
public List<PodAllocator> getPodAllocators() {
- return _podAllocators;
- }
- public void setPodAllocators(List<PodAllocator> _podAllocators) {
- this._podAllocators = _podAllocators;
- }
-
- @Inject
- protected VMTemplateDao _templateDao;
+ return _podAllocators;
+ }
+
+ public void setPodAllocators(List<PodAllocator> _podAllocators) {
+ this._podAllocators = _podAllocators;
+ }
+
+ @Inject
+ protected VMTemplateDao _templateDao;
@Inject
- protected ConfigurationManager _configMgr;
+ protected ConfigurationManager _configMgr;
@Inject
- protected ClusterVSMMapDao _clusterVSMMapDao;
+ protected ClusterVSMMapDao _clusterVSMMapDao;
- protected long _nodeId = ManagementServerNode.getManagementServerId();
+ protected long _nodeId = ManagementServerNode.getManagementServerId();
protected HashMap<String, ResourceStateAdapter> _resourceStateAdapters = new HashMap<String, ResourceStateAdapter>();
@@ -271,8 +269,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
if (lst.contains(listener)) {
- throw new CloudRuntimeException("Duplicate resource lisener:"
- + listener.getClass().getSimpleName());
+ throw new CloudRuntimeException("Duplicate resource lisener:" + listener.getClass().getSimpleName());
}
lst.add(listener);
@@ -288,31 +285,22 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
insertListener(ResourceListener.EVENT_DISCOVER_AFTER, listener);
}
if ((event & ResourceListener.EVENT_DELETE_HOST_BEFORE) != 0) {
- insertListener(ResourceListener.EVENT_DELETE_HOST_BEFORE,
- listener);
+ insertListener(ResourceListener.EVENT_DELETE_HOST_BEFORE, listener);
}
if ((event & ResourceListener.EVENT_DELETE_HOST_AFTER) != 0) {
- insertListener(ResourceListener.EVENT_DELETE_HOST_AFTER,
- listener);
+ insertListener(ResourceListener.EVENT_DELETE_HOST_AFTER, listener);
}
if ((event & ResourceListener.EVENT_CANCEL_MAINTENANCE_BEFORE) != 0) {
- insertListener(
- ResourceListener.EVENT_CANCEL_MAINTENANCE_BEFORE,
- listener);
+ insertListener(ResourceListener.EVENT_CANCEL_MAINTENANCE_BEFORE, listener);
}
if ((event & ResourceListener.EVENT_CANCEL_MAINTENANCE_AFTER) != 0) {
- insertListener(ResourceListener.EVENT_CANCEL_MAINTENANCE_AFTER,
- listener);
+ insertListener(ResourceListener.EVENT_CANCEL_MAINTENANCE_AFTER, listener);
}
if ((event & ResourceListener.EVENT_PREPARE_MAINTENANCE_BEFORE) != 0) {
- insertListener(
- ResourceListener.EVENT_PREPARE_MAINTENANCE_BEFORE,
- listener);
+ insertListener(ResourceListener.EVENT_PREPARE_MAINTENANCE_BEFORE, listener);
}
if ((event & ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER) != 0) {
- insertListener(
- ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER,
- listener);
+ insertListener(ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER, listener);
}
}
}
@@ -322,15 +310,14 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
synchronized (_lifeCycleListeners) {
Iterator it = _lifeCycleListeners.entrySet().iterator();
while (it.hasNext()) {
- Map.Entry<Integer, List<ResourceListener>> items = (Map.Entry<Integer, List<ResourceListener>>) it
- .next();
+ Map.Entry<Integer, List<ResourceListener>> items = (Map.Entry<Integer, List<ResourceListener>>) it.next();
List<ResourceListener> lst = items.getValue();
lst.remove(listener);
}
}
}
- protected void processResourceEvent(Integer event, Object... params) {
+ protected void processResourceEvent(Integer event, Object... params) {
List<ResourceListener> lst = _lifeCycleListeners.get(event);
if (lst == null || lst.size() == 0) {
return;
@@ -339,10 +326,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
String eventName;
for (ResourceListener l : lst) {
if (event == ResourceListener.EVENT_DISCOVER_BEFORE) {
- l.processDiscoverEventBefore((Long) params[0],
- (Long) params[1], (Long) params[2], (URI) params[3],
- (String) params[4], (String) params[5],
- (List<String>) params[6]);
+ l.processDiscoverEventBefore((Long) params[0], (Long) params[1], (Long) params[2], (URI) params[3], (String) params[4],
+ (String) params[5], (List<String>) params[6]);
eventName = "EVENT_DISCOVER_BEFORE";
} else if (event == ResourceListener.EVENT_DISCOVER_AFTER) {
l.processDiscoverEventAfter((Map<? extends ServerResource, Map<String, String>>) params[0]);
@@ -366,20 +351,16 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
l.processPrepareMaintenaceEventAfter((Long) params[0]);
eventName = "EVENT_PREPARE_MAINTENANCE_AFTER";
} else {
- throw new CloudRuntimeException("Unknown resource event:"
- + event);
+ throw new CloudRuntimeException("Unknown resource event:" + event);
}
- s_logger.debug("Sent resource event " + eventName + " to listener "
- + l.getClass().getSimpleName());
+ s_logger.debug("Sent resource event " + eventName + " to listener " + l.getClass().getSimpleName());
}
}
@DB
@Override
- public List<? extends Cluster> discoverCluster(AddClusterCmd cmd)
- throws IllegalArgumentException, DiscoveryException,
- ResourceInUseException {
+ public List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException, ResourceInUseException {
long dcId = cmd.getZoneId();
long podId = cmd.getPodId();
String clusterName = cmd.getClusterName();
@@ -396,36 +377,31 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
// Check if the zone exists in the system
DataCenterVO zone = _dcDao.findById(dcId);
if (zone == null) {
- InvalidParameterValueException ex = new InvalidParameterValueException(
- "Can't find zone by the id specified");
+ InvalidParameterValueException ex = new InvalidParameterValueException("Can't find zone by the id specified");
ex.addProxyObject(zone, dcId, "dcId");
throw ex;
}
Account account = UserContext.current().getCaller();
- if (Grouping.AllocationState.Disabled == zone.getAllocationState()
- && !_accountMgr.isRootAdmin(account.getType())) {
- PermissionDeniedException ex = new PermissionDeniedException(
- "Cannot perform this operation, Zone with specified id is currently disabled");
+ if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
+ PermissionDeniedException ex = new PermissionDeniedException(
+ "Cannot perform this operation, Zone with specified id is currently disabled");
ex.addProxyObject(zone, dcId, "dcId");
throw ex;
}
HostPodVO pod = _podDao.findById(podId);
if (pod == null) {
- throw new InvalidParameterValueException(
- "Can't find pod with specified podId " + podId);
+ throw new InvalidParameterValueException("Can't find pod with specified podId " + podId);
}
// Check if the pod exists in the system
if (_podDao.findById(podId) == null) {
- throw new InvalidParameterValueException("Can't find pod by id "
- + podId);
+ throw new InvalidParameterValueException("Can't find pod by id " + podId);
}
// check if pod belongs to the zone
if (!Long.valueOf(pod.getDataCenterId()).equals(dcId)) {
- InvalidParameterValueException ex = new InvalidParameterValueException(
- "Pod with specified id doesn't belong to the zone " + dcId);
+ InvalidParameterValueException ex = new InvalidParameterValueException("Pod with specified id doesn't belong to the zone " + dcId);
ex.addProxyObject(pod, podId, "podId");
ex.addProxyObject(zone, dcId, "dcId");
throw ex;
@@ -433,22 +409,17 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
// Verify cluster information and create a new cluster if needed
if (clusterName == null || clusterName.isEmpty()) {
- throw new InvalidParameterValueException(
- "Please specify cluster name");
+ throw new InvalidParameterValueException("Please specify cluster name");
}
if (cmd.getHypervisor() == null || cmd.getHypervisor().isEmpty()) {
- throw new InvalidParameterValueException(
- "Please specify a hypervisor");
+ throw new InvalidParameterValueException("Please specify a hypervisor");
}
- Hypervisor.HypervisorType hypervisorType = Hypervisor.HypervisorType
- .getType(cmd.getHypervisor());
+ Hypervisor.HypervisorType hypervisorType = Hypervisor.HypervisorType.getType(cmd.getHypervisor());
if (hypervisorType == null) {
- s_logger.error("Unable to resolve " + cmd.getHypervisor()
- + " to a valid supported hypervisor type");
- throw new InvalidParameterValueException("Unable to resolve "
- + cmd.getHypervisor() + " to a supported ");
+ s_logger.error("Unable to resolve " + cmd.getHypervisor() + " to a valid supported hypervisor type");
+ throw new InvalidParameterValueException("Unable to resolve " + cmd.getHypervisor() + " to a supported ");
}
Cluster.ClusterType clusterType = null;
@@ -460,16 +431,11 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
Grouping.AllocationState allocationState = null;
- if (cmd.getAllocationState() != null
- && !cmd.getAllocationState().isEmpty()) {
+ if (cmd.getAllocationState() != null && !cmd.getAllocationState().isEmpty()) {
try {
- allocationState = Grouping.AllocationState.valueOf(cmd
- .getAllocationState());
+ allocationState = Grouping.AllocationState.valueOf(cmd.getAllocationState());
} catch (IllegalArgumentException ex) {
- throw new InvalidParameterValueException(
- "Unable to resolve Allocation State '"
- + cmd.getAllocationState()
- + "' to a supported state");
+ throw new InvalidParameterValueException("Unable to resolve Allocation State '" + cmd.getAllocationState() + "' to a supported state");
}
}
if (allocationState == null) {
@@ -479,9 +445,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
Discoverer discoverer = getMatchingDiscover(hypervisorType);
if (discoverer == null) {
- throw new InvalidParameterValueException(
- "Could not find corresponding resource manager for "
- + cmd.getHypervisor());
+ throw new InvalidParameterValueException("Could not find corresponding resource manager for " + cmd.getHypervisor());
}
if (hypervisorType == HypervisorType.VMware) {
@@ -501,9 +465,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
cluster = _clusterDao.persist(cluster);
} catch (Exception e) {
// no longer tolerate exception during the cluster creation phase
- CloudRuntimeException ex = new CloudRuntimeException(
- "Unable to create cluster " + clusterName
- + " in pod and data center with specified ids", e);
+ CloudRuntimeException ex = new CloudRuntimeException("Unable to create cluster " + clusterName
+ + " in pod and data center with specified ids", e);
// Get the pod VO object's table name.
ex.addProxyObject(pod, podId, "podId");
ex.addProxyObject(zone, dcId, "dcId");
@@ -512,10 +475,10 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
clusterId = cluster.getId();
result.add(cluster);
- ClusterDetailsVO cluster_detail_cpu = new ClusterDetailsVO(clusterId, "cpuOvercommitRatio", Float.toString(cmd.getCpuOvercommitRatio()));
- ClusterDetailsVO cluster_detail_ram = new ClusterDetailsVO(clusterId, "memoryOvercommitRatio", Float.toString(cmd.getMemoryOvercommitRaito()));
- _clusterDetailsDao.persist(cluster_detail_cpu);
- _clusterDetailsDao.persist(cluster_detail_ram);
+ ClusterDetailsVO cluster_detail_cpu = new ClusterDetailsVO(clusterId, "cpuOvercommitRatio", Float.toString(cmd.getCpuOvercommitRatio()));
+ ClusterDetailsVO cluster_detail_ram = new ClusterDetailsVO(clusterId, "memoryOvercommitRatio", Float.toString(cmd.getMemoryOvercommitRaito()));
+ _clusterDetailsDao.persist(cluster_detail_cpu);
+ _clusterDetailsDao.persist(cluster_detail_ram);
if (clusterType == Cluster.ClusterType.CloudManaged) {
return result;
@@ -530,66 +493,53 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
_clusterDetailsDao.persist(cluster_detail_cpu);
_clusterDetailsDao.persist(cluster_detail_ram);
- //create a new entry only if the overcommit ratios are greater than 1.
- if(cmd.getCpuOvercommitRatio().compareTo(1f) > 0) {
+ // create a new entry only if the overcommit ratios are greater than 1.
+ if (cmd.getCpuOvercommitRatio().compareTo(1f) > 0) {
cluster_detail_cpu = new ClusterDetailsVO(clusterId, "cpuOvercommitRatio", Float.toString(cmd.getCpuOvercommitRatio()));
_clusterDetailsDao.persist(cluster_detail_cpu);
}
-
- if(cmd.getMemoryOvercommitRaito().compareTo(1f) > 0) {
- cluster_detail_ram = new ClusterDetailsVO(clusterId, "memoryOvercommitRatio", Float.toString(cmd.getMemoryOvercommitRaito()));
+ if (cmd.getMemoryOvercommitRaito().compareTo(1f) > 0) {
+ cluster_detail_ram = new ClusterDetailsVO(clusterId, "memoryOvercommitRatio", Float.toString(cmd.getMemoryOvercommitRaito()));
_clusterDetailsDao.persist(cluster_detail_ram);
}
-
boolean success = false;
try {
try {
uri = new URI(UriUtils.encodeURIComponent(url));
if (uri.getScheme() == null) {
- throw new InvalidParameterValueException(
- "uri.scheme is null " + url
- + ", add http:// as a prefix");
+ throw new InvalidParameterValueException("uri.scheme is null " + url + ", add http:// as a prefix");
} else if (uri.getScheme().equalsIgnoreCase("http")) {
- if (uri.getHost() == null
- || uri.getHost().equalsIgnoreCase("")
- || uri.getPath() == null
- || uri.getPath().equalsIgnoreCase("")) {
- throw new InvalidParameterValueException(
- "Your host and/or path is wrong. Make sure it's of the format http://hostname/path");
+ if (uri.getHost() == null || uri.getHost().equalsIgnoreCase("") || uri.getPath() == null || uri.getPath().equalsIgnoreCase("")) {
+ throw new InvalidParameterValueException("Your host and/or path is wrong. Make sure it's of the format http://hostname/path");
}
}
} catch (URISyntaxException e) {
- throw new InvalidParameterValueException(url
- + " is not a valid uri");
+ throw new InvalidParameterValueException(url + " is not a valid uri");
}
List<HostVO> hosts = new ArrayList<HostVO>();
Map<? extends ServerResource, Map<String, String>> resources = null;
- resources = discoverer.find(dcId, podId, clusterId, uri, username,
- password, null);
+ resources = discoverer.find(dcId, podId, clusterId, uri, username, password, null);
if (resources != null) {
- for (Map.Entry<? extends ServerResource, Map<String, String>> entry : resources
- .entrySet()) {
+ for (Map.Entry<? extends ServerResource, Map<String, String>> entry : resources.entrySet()) {
ServerResource resource = entry.getKey();
- // For Hyper-V, we are here means agent have already started
- // and connected to management server
+ // For Hyper-V, we are here means agent have already started
+ // and connected to management server
if (hypervisorType == Hypervisor.HypervisorType.Hyperv) {
break;
}
- HostVO host = (HostVO) createHostAndAgent(resource,
- entry.getValue(), true, null, false);
+ HostVO host = (HostVO) createHostAndAgent(resource, entry.getValue(), true, null, false);
if (host != null) {
hosts.add(host);
}
discoverer.postDiscovery(hosts, _nodeId);
}
- s_logger.info("External cluster has been successfully discovered by "
- + discoverer.getName());
+ s_logger.info("External cluster has been successfully discovered by " + discoverer.getName());
success = true;
return result;
}
@@ -605,19 +555,16 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
@Override
- public Discoverer getMatchingDiscover(
- Hypervisor.HypervisorType hypervisorType) {
- for (Discoverer discoverer : _discoverers) {
- if (discoverer.getHypervisorType() == hypervisorType)
+ public Discoverer getMatchingDiscover(Hypervisor.HypervisorType hypervisorType) {
+ for (Discoverer discoverer : _discoverers) {
+ if (discoverer.getHypervisorType() == hypervisorType)
return discoverer;
- }
+ }
return null;
}
@Override
- public List<? extends Host> discoverHosts(AddHostCmd cmd)
- throws IllegalArgumentException, DiscoveryException,
- InvalidParameterValueException {
+ public List<? extends Host> discoverHosts(AddHostCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
Long dcId = cmd.getZoneId();
Long podId = cmd.getPodId();
Long clusterId = cmd.getClusterId();
@@ -627,8 +574,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
String password = cmd.getPassword();
List<String> hostTags = cmd.getHostTags();
- dcId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current()
- .getCaller(), dcId);
+ dcId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), dcId);
// this is for standalone option
if (clusterName == null && clusterId == null) {
@@ -638,16 +584,15 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
if (clusterId != null) {
ClusterVO cluster = _clusterDao.findById(clusterId);
if (cluster == null) {
- InvalidParameterValueException ex = new InvalidParameterValueException(
- "can not find cluster for specified clusterId");
+ InvalidParameterValueException ex = new InvalidParameterValueException("can not find cluster for specified clusterId");
ex.addProxyObject(cluster, clusterId, "clusterId");
throw ex;
} else {
if (cluster.getGuid() == null) {
List<HostVO> hosts = listAllHostsInCluster(clusterId);
if (!hosts.isEmpty()) {
- CloudRuntimeException ex = new CloudRuntimeException(
- "Guid is not updated for cluster with specified cluster id; need to wait for hosts in this cluster to come up");
+ CloudRuntimeException ex = new CloudRuntimeException(
+ "Guid is not updated for cluster with specified cluster id; need to wait for hosts in this cluster to come up");
ex.addProxyObject(cluster, clusterId, "clusterId");
throw ex;
}
@@ -655,17 +600,13 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
}
- return discoverHostsFull(dcId, podId, clusterId, clusterName, url, username, password, cmd.getHypervisor(), hostTags, cmd.getFullUrlParams(), true);
+ return discoverHostsFull(dcId, podId, clusterId, clusterName, url, username, password, cmd.getHypervisor(), hostTags, cmd.getFullUrlParams(),
+ true);
}
-
-
-
-
@Override
- public List<? extends Host> discoverHosts(AddSecondaryStorageCmd cmd)
- throws IllegalArgumentException, DiscoveryException,
- InvalidParameterValueException {
+ public List<? extends Host> discoverHosts(AddSecondaryStorageCmd cmd) throws IllegalArgumentException, DiscoveryException,
+ InvalidParameterValueException {
Long dcId = cmd.getZoneId();
String url = cmd.getUrl();
return discoverHostsFull(dcId, null, null, null, url, null, null, "SecondaryStorage", null, null, false);
@@ -678,7 +619,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
@Override
public Pair<List<? extends Swift>, Integer> listSwifts(ListSwiftsCmd cmd) {
- Pair<List<SwiftVO>, Integer> swifts = _swiftMgr.listSwifts(cmd);
+ Pair<List<SwiftVO>, Integer> swifts = _swiftMgr.listSwifts(cmd);
return new Pair<List<? extends Swift>, Integer>(swifts.first(), swifts.second());
}
@@ -693,53 +634,44 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
@Override
- public ObjectStore discoverObjectStore(AddSecondaryStorageCmd cmd) throws IllegalArgumentException, DiscoveryException,
+ public ImageStore discoverImageStore(AddImageStoreCmd cmd) throws IllegalArgumentException, DiscoveryException,
InvalidParameterValueException {
- String providerName = cmd.getImageProviderName();
+ String providerName = cmd.getProviderName();
DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(providerName);
if (storeProvider == null) {
storeProvider = _dataStoreProviderMgr.getDefaultImageDataStoreProvider();
if (storeProvider == null) {
- throw new InvalidParameterValueException(
- "can't find image store provider: " + providerName);
+ throw new InvalidParameterValueException("can't find image store provider: " + providerName);
}
}
Long dcId = cmd.getZoneId();
- Long regionId = cmd.getRegionId();
String url = cmd.getUrl();
Map details = cmd.getDetails();
- ScopeType scopeType = ScopeType.ZONE;
+ ScopeType scopeType = null;
String scope = cmd.getScope();
if (scope != null) {
try {
scopeType = Enum.valueOf(ScopeType.class, scope.toUpperCase());
} catch (Exception e) {
- throw new InvalidParameterValueException("invalid scope"
- + scope);
+ throw new InvalidParameterValueException("invalid scope" + scope);
}
}
if (scopeType == ScopeType.ZONE && dcId == null) {
- throw new InvalidParameterValueException(
- "zone id can't be null, if scope is zone");
- } else if (scopeType == ScopeType.REGION && regionId == null) {
- throw new InvalidParameterValueException(
- "region id can't be null, if scope is region");
+ throw new InvalidParameterValueException("zone id can't be null, if scope is zone");
}
- if ( dcId != null ){
+ if (dcId != null) {
// Check if the zone exists in the system
DataCenterVO zone = _dcDao.findById(dcId);
if (zone == null) {
- throw new InvalidParameterValueException("Can't find zone by id "
- + dcId);
+ throw new InvalidParameterValueException("Can't find zone by id " + dcId);
}
Account account = UserContext.current().getCaller();
- if (Grouping.AllocationState.Disabled == zone.getAllocationState()
- && !_accountMgr.isRootAdmin(account.getType())) {
+ if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
PermissionDeniedException ex = new PermissionDeniedException(
"Cannot perform this operation, Zone with specified id is currently disabled");
ex.addProxyObject(zone, dcId, "dcId");
@@ -747,57 +679,42 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
}
- if ( regionId != null ){
- // Check if the region exists in the system
- RegionVO region = _regionDao.findById(regionId.intValue());
- if (region == null) {
- throw new InvalidParameterValueException("Can't find region by id "
- + regionId);
- }
- }
Map<String, Object> params = new HashMap<String, Object>();
params.put("zoneId", dcId);
- params.put("regionId", regionId);
params.put("url", cmd.getUrl());
params.put("name", cmd.getUrl());
params.put("details", details);
+ params.put("scope", scopeType);
params.put("providerName", storeProvider.getName());
DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
DataStore store = null;
try {
store = lifeCycle.initialize(params);
-
- if (scopeType == ScopeType.ZONE) {
- ZoneScope zoneScope = new ZoneScope(dcId);
- lifeCycle.attachZone(store, zoneScope);
- }
} catch (Exception e) {
s_logger.debug("Failed to add data store", e);
throw new CloudRuntimeException("Failed to add data store", e);
}
- return (ObjectStore)_dataStoreMgr.getDataStore(store.getId(),
- DataStoreRole.Image);
+ return (ImageStore) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Image);
}
- private List<HostVO> discoverHostsFull(Long dcId, Long podId, Long clusterId, String clusterName, String url, String username, String password, String hypervisorType, List<String> hostTags,
- Map<String, String> params, boolean deferAgentCreation) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
+ private List<HostVO> discoverHostsFull(Long dcId, Long podId, Long clusterId, String clusterName, String url, String username, String password,
+ String hypervisorType, List<String> hostTags, Map<String, String> params, boolean deferAgentCreation) throws IllegalArgumentException,
+ DiscoveryException, InvalidParameterValueException {
URI uri = null;
// Check if the zone exists in the system
DataCenterVO zone = _dcDao.findById(dcId);
if (zone == null) {
- throw new InvalidParameterValueException("Can't find zone by id "
- + dcId);
+ throw new InvalidParameterValueException("Can't find zone by id " + dcId);
}
Account account = UserContext.current().getCaller();
- if (Grouping.AllocationState.Disabled == zone.getAllocationState()
- && !_accountMgr.isRootAdmin(account.getType())) {
- PermissionDeniedException ex = new PermissionDeniedException(
- "Cannot perform this operation, Zone with specified id is currently disabled");
+ if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
+ PermissionDeniedException ex = new PermissionDeniedException(
+ "Cannot perform this operation, Zone with specified id is currently disabled");
ex.addProxyObject(zone, dcId, "dcId");
throw ex;
}
@@ -806,16 +723,12 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
if (podId != null) {
HostPodVO pod = _podDao.findById(podId);
if (pod == null) {
- throw new InvalidParameterValueException(
- "Can't find pod by id " + podId);
+ throw new InvalidParameterValueException("Can't find pod by id " + podId);
}
// check if pod belongs to the zone
if (!Long.valueOf(pod.getDataCenterId()).equals(dcId)) {
- InvalidParameterValueException ex = new InvalidParameterValueException(
- "Pod with specified podId"
- + podId
- + " doesn't belong to the zone with specified zoneId"
- + dcId);
+ InvalidParameterValueException ex = new InvalidParameterValueException("Pod with specified podId" + podId
+ + " doesn't belong to the zone with specified zoneId" + dcId);
ex.addProxyObject(pod, podId, "podId");
ex.addProxyObject(zone, dcId, "dcId");
throw ex;
@@ -824,47 +737,40 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
// Verify cluster information and create a new cluster if needed
if (clusterName != null && clusterId != null) {
- throw new InvalidParameterValueException(
- "Can't specify cluster by both id and name");
+ throw new InvalidParameterValueException("Can't specify cluster by both id and name");
}
if (hypervisorType == null || hypervisorType.isEmpty()) {
- throw new InvalidParameterValueException(
- "Need to specify Hypervisor Type");
+ throw new InvalidParameterValueException("Need to specify Hypervisor Type");
}
if ((clusterName != null || clusterId != null) && podId == null) {
- throw new InvalidParameterValueException(
- "Can't specify cluster without specifying the pod");
+ throw new InvalidParameterValueException("Can't specify cluster without specifying the pod");
}
if (clusterId != null) {
if (_clusterDao.findById(clusterId) == null) {
- throw new InvalidParameterValueException(
- "Can't find cluster by id " + clusterId);
- }
-
- if (hypervisorType.equalsIgnoreCase(HypervisorType.VMware
- .toString())) {
- // VMware only allows adding host to an existing cluster, as we
- // already have a lot of information
- // in cluster object, to simplify user input, we will construct
- // neccessary information here
- Map<String, String> clusterDetails = this._clusterDetailsDao
- .findDetails(clusterId);
+ throw new InvalidParameterValueException("Can't find cluster by id " + clusterId);
+ }
+
+ if (hypervisorType.equalsIgnoreCase(HypervisorType.VMware.toString())) {
+ // VMware only allows adding host to an existing cluster, as we
+ // already have a lot of information
+ // in cluster object, to simplify user input, we will construct
+ // neccessary information here
+ Map<String, String> clusterDetails = this._clusterDetailsDao.findDetails(clusterId);
username = clusterDetails.get("username");
- assert (username != null);
+ assert (username != null);
password = clusterDetails.get("password");
- assert (password != null);
+ assert (password != null);
try {
uri = new URI(UriUtils.encodeURIComponent(url));
url = clusterDetails.get("url") + "/" + uri.getHost();
} catch (URISyntaxException e) {
- throw new InvalidParameterValueException(url
- + " is not a valid uri");
+ throw new InvalidParameterValueException(url + " is not a valid uri");
}
}
}
@@ -872,8 +778,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
if (clusterName != null) {
HostPodVO pod = _podDao.findById(podId);
if (pod == null) {
- throw new InvalidParameterValueException(
- "Can't find pod by id " + podId);
+ throw new InvalidParameterValueException("Can't find pod by id " + podId);
}
ClusterVO cluster = new ClusterVO(dcId, podId, clusterName);
cluster.setHypervisorType(hypervisorType);
@@ -882,22 +787,19 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
} catch (Exception e) {
cluster = _clusterDao.findBy(clusterName, podId);
if (cluster == null) {
- CloudRuntimeException ex = new CloudRuntimeException(
- "Unable to create cluster "
- + clusterName
- + " in pod with specified podId and data center with specified dcID",
- e);
+ CloudRuntimeException ex = new CloudRuntimeException("Unable to create cluster " + clusterName
+ + " in pod with specified podId and data center with specified dcID", e);
ex.addProxyObject(pod, podId, "podId");
ex.addProxyObject(zone, dcId, "dcId");
throw ex;
}
}
clusterId = cluster.getId();
- if (_clusterDetailsDao.findDetail(clusterId,"cpuOvercommitRatio") == null) {
- ClusterDetailsVO cluster_cpu_detail = new ClusterDetailsVO(clusterId,"cpuOvercommitRatio","1");
- ClusterDetailsVO cluster_memory_detail = new ClusterDetailsVO(clusterId,"memoryOvercommitRatio","1");
- _clusterDetailsDao.persist(cluster_cpu_detail);
- _clusterDetailsDao.persist(cluster_memory_detail);
+ if (_clusterDetailsDao.findDetail(clusterId, "cpuOvercommitRatio") == null) {
+ ClusterDetailsVO cluster_cpu_detail = new ClusterDetailsVO(clusterId, "cpuOvercommitRatio", "1");
+ ClusterDetailsVO cluster_memory_detail = new ClusterDetailsVO(clusterId, "memoryOvercommitRatio", "1");
+ _clusterDetailsDao.persist(cluster_cpu_detail);
+ _clusterDetailsDao.persist(cluster_memory_detail);
}
}
@@ -905,26 +807,20 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
try {
uri = new URI(UriUtils.encodeURIComponent(url));
if (uri.getScheme() == null) {
- throw new InvalidParameterValueException("uri.scheme is null "
- + url + ", add nfs:// as a prefix");
+ throw new InvalidParameterValueException("uri.scheme is null " + url + ", add nfs:// as a prefix");
} else if (uri.getScheme().equalsIgnoreCase("nfs")) {
- if (uri.getHost() == null || uri.getHost().equalsIgnoreCase("")
- || uri.getPath() == null
- || uri.getPath().equalsIgnoreCase("")) {
- throw new InvalidParameterValueException(
- "Your host and/or path is wrong. Make sure it's of the format nfs://hostname/path");
+ if (uri.getHost() == null || uri.getHost().equalsIgnoreCase("") || uri.getPath() == null || uri.getPath().equalsIgnoreCase("")) {
+ throw new InvalidParameterValueException("Your host and/or path is wrong. Make sure it's of the format nfs://hostname/path");
}
}
} catch (URISyntaxException e) {
- throw new InvalidParameterValueException(url
- + " is not a valid uri");
+ throw new InvalidParameterValueException(url + " is not a valid uri");
}
List<HostVO> hosts = new ArrayList<HostVO>();
- 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;
- for (Discoverer discoverer : _discoverers) {
+ for (Discoverer discoverer : _discoverers) {
if (params != null) {
discoverer.putParam(params);
}
@@ -935,43 +831,35 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
isHypervisorTypeSupported = true;
Map<? extends ServerResource, Map<String, String>> resources = null;
- processResourceEvent(ResourceListener.EVENT_DISCOVER_BEFORE, dcId,
- podId, clusterId, uri, username, password, hostTags);
+ processResourceEvent(ResourceListener.EVENT_DISCOVER_BEFORE, dcId, podId, clusterId, uri, username, password, hostTags);
try {
- resources = discoverer.find(dcId, podId, clusterId, uri,
- username, password, hostTags);
- } catch (DiscoveryException e) {
+ resources = discoverer.find(dcId, podId, clusterId, uri, username, password, hostTags);
+ } catch (DiscoveryException e) {
throw e;
} catch (Exception e) {
- s_logger.info("Exception in host discovery process with discoverer: "
- + discoverer.getName()
- + ", skip to another discoverer if there is any");
+ s_logger.info("Exception in host discovery process with discoverer: " + discoverer.getName()
+ + ", skip to another discoverer if there is any");
}
- processResourceEvent(ResourceListener.EVENT_DISCOVER_AFTER,
- resources);
+ processResourceEvent(ResourceListener.EVENT_DISCOVER_AFTER, resources);
if (resources != null) {
- for (Map.Entry<? extends ServerResource, Map<String, String>> entry : resources
- .entrySet()) {
+ for (Map.Entry<? extends ServerResource, Map<String, String>> entry : resources.entrySet()) {
ServerResource resource = entry.getKey();
/*
- * For KVM, if we go to here, that means kvm agent is
- * already connected to mgt svr.
+ * For KVM, if we go to here, that means kvm agent is
+ * already connected to mgt svr.
*/
if (resource instanceof KvmDummyResourceBase) {
Map<String, String> details = entry.getValue();
String guid = details.get("guid");
- List<HostVO> kvmHosts = listAllUpAndEnabledHosts(
- Host.Type.Routing, clusterId, podId, dcId);
+ List<HostVO> kvmHosts = listAllUpAndEnabledHosts(Host.Type.Routing, clusterId, podId, dcId);
for (HostVO host : kvmHosts) {
if (host.getGuid().equalsIgnoreCase(guid)) {
- if (hostTags != null) {
- if (s_logger.isTraceEnabled()) {
- s_logger.trace("Adding Host Tags for KVM host, tags: :"
- + hostTags);
+ if (hostTags != null) {
+ if (s_logger.isTraceEnabled()) {
+ s_logger.trace("Adding Host Tags for KVM host, tags: :" + hostTags);
}
- _hostTagsDao
- .persist(host.getId(), hostTags);
+ _hostTagsDao.persist(host.getId(), hostTags);
}
hosts.add(host);
return hosts;
@@ -982,9 +870,9 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
HostVO host = null;
if (deferAgentCreation) {
- host = (HostVO)createHostAndAgentDeferred(resource, entry.getValue(), true, hostTags, false);
+ host = (HostVO) createHostAndAgentDeferred(resource, entry.getValue(), true, hostTags, false);
} else {
- host = (HostVO)createHostAndAgent(resource, entry.getValue(), true, hostTags, false);
+ host = (HostVO) createHostAndAgent(resource, entry.getValue(), true, hostTags, false);
}
if (host != null) {
hosts.add(host);
@@ -992,14 +880,12 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
discoverer.postDiscovery(hosts, _nodeId);
}
- s_logger.info("server resources successfully discovered by "
- + discoverer.getName());
+ s_logger.info("server resources successfully discovered by " + discoverer.getName());
return hosts;
}
}
if (!isHypervisorTypeSupported) {
- String msg = "Do not support HypervisorType " + hypervisorType
- + " for " + url;
+ String msg = "Do not support HypervisorType " + hypervisorType + " for " + url;
s_logger.warn(msg);
throw new DiscoveryException(msg);
}
@@ -1013,42 +899,33 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
@DB
- protected boolean doDeleteHost(long hostId, boolean isForced,
- boolean isForceDeleteStorage) {
- User caller = _accountMgr.getActiveUser(UserContext.current()
- .getCallerUserId());
+ protected boolean doDeleteHost(long hostId, boolean isForced, boolean isForceDeleteStorage) {
+ User caller = _accountMgr.getActiveUser(UserContext.current().getCallerUserId());
// Verify that host exists
HostVO host = _hostDao.findById(hostId);
if (host == null) {
- throw new InvalidParameterValueException("Host with id " + hostId
- + " doesn't exist");
+ throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist");
}
- _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current()
- .getCaller(), host.getDataCenterId());
+ _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), host.getDataCenterId());
/*
- * TODO: check current agent status and updateAgentStatus to removed. If
- * it was already removed, that means someone is deleting host
- * concurrently, return. And consider the situation of CloudStack
- * shutdown during delete. A global lock?
+ * TODO: check current agent status and updateAgentStatus to removed. If
+ * it was already removed, that means someone is deleting host
+ * concurrently, return. And consider the situation of CloudStack
+ * shutdown during delete. A global lock?
*/
AgentAttache attache = _agentMgr.findAttache(hostId);
- // Get storage pool host mappings here because they can be removed as a
- // part of handleDisconnect later
- // TODO: find out the bad boy, what's a buggy logic!
- List<StoragePoolHostVO> pools = _storagePoolHostDao
- .listByHostIdIncludingRemoved(hostId);
+ // Get storage pool host mappings here because they can be removed as a
+ // part of handleDisconnect later
+ // TODO: find out the bad boy, what's a buggy logic!
+ List<StoragePoolHostVO> pools = _storagePoolHostDao.listByHostIdIncludingRemoved(hostId);
- ResourceStateAdapter.DeleteHostAnswer answer = (ResourceStateAdapter.DeleteHostAnswer) dispatchToStateAdapters(
- ResourceStateAdapter.Event.DELETE_HOST, false, host,
- new Boolean(isForced), new Boolean(isForceDeleteStorage));
+ ResourceStateAdapter.DeleteHostAnswer answer = (ResourceStateAdapter.DeleteHostAnswer) dispatchToStateAdapters(
+ ResourceStateAdapter.Event.DELETE_HOST, false, host, new Boolean(isForced), new Boolean(isForceDeleteStorage));
if (answer == null) {
- throw new CloudRuntimeException(
- "No resource adapter respond to DELETE_HOST event for "
- + host.getName() + " id = " + hostId
- + ", hypervisorType is " + host.getHypervisorType()
- + ", host type is " + host.getType());
+ throw new CloudRuntimeException("No resource adapter respond to DELETE_HOST event for " + host.getName() + " id = " + hostId
+ + ", hypervisorType is " + host.getHypervisorType() + ", host type is " + host.getType());
}
if (answer.getIsException()) {
@@ -1062,8 +939,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
Transaction txn = Transaction.currentTxn();
txn.start();
- _dcDao.releasePrivateIpAddress(host.getPrivateIpAddress(),
- host.getDataCenterId(), null);
+ _dcDao.releasePrivateIpAddress(host.getPrivateIpAddress(), host.getDataCenterId(), null);
_agentMgr.disconnectWithoutInvestigation(hostId, Status.Event.Remove);
// delete host details
@@ -1085,18 +961,16 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
try {
- resourceStateTransitTo(host, ResourceState.Event.DeleteHost,
- _nodeId);
+ resourceStateTransitTo(host, ResourceState.Event.DeleteHost, _nodeId);
} catch (NoTransitionException e) {
- s_logger.debug("Cannot transmit host " + host.getId()
- + "to Enabled state", e);
+ s_logger.debug("Cannot transmit host " + host.getId() + "to Enabled state", e);
}
// Delete the associated entries in host ref table
_storagePoolHostDao.deletePrimaryRecordsForHost(hostId);
- // For pool ids you got, delete local storage host entries in pool table
- // where
+ // For pool ids you got, delete local storage host entries in pool table
+ // where
for (StoragePoolHostVO pool : pools) {
Long poolId = pool.getPoolId();
StoragePoolVO storagePool = _storagePoolDao.findById(poolId);
@@ -1105,30 +979,24 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
storagePool.setClusterId(null);
_storagePoolDao.update(poolId, storagePool);
_storagePoolDao.remove(poolId);
- s_logger.debug("Local storage id=" + poolId
- + " is removed as a part of host removal id=" + hostId);
+ s_logger.debug("Local storage id=" + poolId + " is removed as a part of host removal id=" + hostId);
}
}
// delete the op_host_capacity entry
- Object[] capacityTypes = { Capacity.CAPACITY_TYPE_CPU,
- Capacity.CAPACITY_TYPE_MEMORY };
- SearchCriteria<CapacityVO> hostCapacitySC = _capacityDao
- .createSearchCriteria();
+ Object[] capacityTypes = { Capacity.CAPACITY_TYPE_CPU, Capacity.CAPACITY_TYPE_MEMORY };
+ SearchCriteria<CapacityVO> hostCapacitySC = _capacityDao.createSearchCriteria();
hostCapacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, hostId);
- hostCapacitySC.addAnd("capacityType", SearchCriteria.Op.IN,
- capacityTypes);
+ hostCapacitySC.addAnd("capacityType", SearchCriteria.Op.IN, capacityTypes);
_capacityDao.remove(hostCapacitySC);
txn.commit();
return true;
}
@Override
- public boolean deleteHost(long hostId, boolean isForced,
- boolean isForceDeleteStorage) {
+ public boolean deleteHost(long hostId, boolean isForced, boolean isForceDeleteStorage) {
try {
- Boolean result = _clusterMgr.propagateResourceEvent(hostId,
- ResourceState.Event.DeleteHost);
+ Boolean result = _clusterMgr.propagateResourceEvent(hostId, ResourceState.Event.DeleteHost);
if (result != null) {
return result;
}
@@ -1148,58 +1016,47 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
ClusterVO cluster = _clusterDao.lockRow(cmd.getId(), true);
if (cluster == null) {
if (s_logger.isDebugEnabled()) {
- s_logger.debug("Cluster: " + cmd.getId()
- + " does not even exist. Delete call is ignored.");
+ s_logger.debug("Cluster: " + cmd.getId() + " does not even exist. Delete call is ignored.");
}
txn.rollback();
- throw new CloudRuntimeException("Cluster: " + cmd.getId()
- + " does not exist");
+ throw new CloudRuntimeException("Cluster: " + cmd.getId() + " does not exist");
}
- Hypervisor.HypervisorType hypervisorType = cluster
- .getHypervisorType();
+ Hypervisor.HypervisorType hypervisorType = cluster.getHypervisorType();
List<HostVO> hosts = listAllHostsInCluster(cmd.getId());
if (hosts.size() > 0) {
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");
}
txn.rollback();
- throw new CloudRuntimeException("Cluster: " + cmd.getId()
- + " cannot be removed. Cluster still has hosts");
+ throw new CloudRuntimeException("Cluster: " + cmd.getId() + " cannot be removed. Cluster still has hosts");
}
- // don't allow to remove the cluster if it has non-removed storage
- // pools
- List<StoragePoolVO> storagePools = _storagePoolDao
- .listPoolsByCluster(cmd.getId());
+ // don't allow to remove the cluster if it has non-removed storage
+ // pools
+ List<StoragePoolVO> storagePools = _storagePoolDao.listPoolsByCluster(cmd.getId());
if (storagePools.size() > 0) {
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");
}
txn.rollback();
- throw new CloudRuntimeException("Cluster: " + cmd.getId()
- + " cannot be removed. Cluster still has storage pools");
+ throw new CloudRuntimeException("Cluster: " + cmd.getId() + " cannot be removed. Cluster still has storage pools");
}
- if (_clusterDao.remove(cmd.getId())) {
+ if (_clusterDao.remove(cmd.getId())) {
_capacityDao.removeBy(null, null, null, cluster.getId(), null);
- // If this cluster is of type vmware, and if the nexus vswitch
- // global parameter setting is turned
+ // If this cluster is of type vmware, and if the nexus vswitch
+ // global parameter setting is turned
// on, remove the row in cluster_vsm_map for this cluster id.
- if (hypervisorType == HypervisorType.VMware
- && Boolean.parseBoolean(_configDao
- .getValue(Config.VmwareUseNexusVSwitch
- .toString()))) {
+ if (hypervisorType == HypervisorType.VMware && Boolean.parseBoolean(_configDao.getValue(Config.VmwareUseNexusVSwitch.toString()))) {
_clusterVSMMapDao.removeByClusterId(cmd.getId());
}
}
txn.commit();
return true;
- } catch (CloudRuntimeException e) {
+ } catch (CloudRuntimeException e) {
throw e;
} catch (Throwable t) {
s_logger.error("Unable to delete cluster: " + cmd.getId(), t);
@@ -1210,21 +1067,18 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
@Override
@DB
- public Cluster updateCluster(Cluster clusterToUpdate, String clusterType,
- String hypervisor, String allocationState, String managedstate,Float memoryovercommitratio, Float cpuovercommitratio) {
+ public Cluster updateCluster(Cluster clusterToUpdate, String clusterType, String hypervisor, String allocationState, String managedstate,
+ Float memoryovercommitratio, Float cpuovercommitratio) {
ClusterVO cluster = (ClusterVO) clusterToUpdate;
// Verify cluster information and update the cluster if needed
boolean doUpdate = false;
if (hypervisor != null && !hypervisor.isEmpty()) {
- Hypervisor.HypervisorType hypervisorType = Hypervisor.HypervisorType
- .getType(hypervisor);
+ Hypervisor.HypervisorType hypervisorType = Hypervisor.HypervisorType.getType(hypervisor);
if (hypervisorType == null) {
- s_logger.error("Unable to resolve " + hypervisor
- + " to a valid supported hypervisor type");
- throw new InvalidParameterValueException("Unable to resolve "
- + hypervisor + " to a supported type");
+ s_logger.error("Unable to resolve " + hypervisor + " to a valid supported hypervisor type");
+ throw new InvalidParameterValueException("Unable to resolve " + hypervisor + " to a supported type");
} else {
cluster.setHypervisorType(hypervisor);
doUpdate = true;
@@ -1236,14 +1090,11 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
try {
newClusterType = Cluster.ClusterType.valueOf(clusterType);
} catch (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");
+ 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);
doUpdate = true;
@@ -1253,21 +1104,15 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
Grouping.AllocationState newAllocationState = null;
if (allocationState != null && !allocationState.isEmpty()) {
try {
- newAllocationState = Grouping.AllocationState
- .valueOf(allocationState);
+ newAllocationState = Grouping.AllocationState.valueOf(allocationState);
} catch (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");
+ 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 {
- _capacityDao.updateCapacityState(null, null, cluster.getId(),
- null, allocationState);
+ _capacityDao.updateCapacityState(null, null, cluster.getId(), null, allocationState);
cluster.setAllocationState(newAllocationState);
doUpdate = true;
}
@@ -1279,46 +1124,38 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
try {
newManagedState = Managed.ManagedState.valueOf(managedstate);
} catch (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");
+ 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;
}
}
- ClusterDetailsVO memory_detail = _clusterDetailsDao.findDetail(cluster.getId(),"memoryOvercommitRatio");
- if( memory_detail == null){
- if (memoryovercommitratio.compareTo(1f) > 0){
- memory_detail = new ClusterDetailsVO(cluster.getId(),"memoryOvercommitRatio",Float.toString(memoryovercommitratio));
- _clusterDetailsDao.persist(memory_detail);
- }
- }
- else {
- memory_detail.setValue(Float.toString(memoryovercommitratio));
- _clusterDetailsDao.update(memory_detail.getId(),memory_detail);
- }
+ ClusterDetailsVO memory_detail = _clusterDetailsDao.findDetail(cluster.getId(), "memoryOvercommitRatio");
+ if (memory_detail == null) {
+ if (memoryovercommitratio.compareTo(1f) > 0) {
+ memory_detail = new ClusterDetailsVO(cluster.getId(), "memoryOvercommitRatio", Float.toString(memoryovercommitratio));
+ _clusterDetailsDao.persist(memory_detail);
+ }
+ } else {
+ memory_detail.setValue(Float.toString(memoryovercommitratio));
+ _clusterDetailsDao.update(memory_detail.getId(), memory_detail);
+ }
- ClusterDetailsVO cpu_detail = _clusterDetailsDao.findDetail(cluster.getId(),"cpuOvercommitRatio");
- if( cpu_detail == null){
- if (cpuovercommitratio.compareTo(1f) > 0){
- cpu_detail = new ClusterDetailsVO(cluster.getId(),"cpuOvercommitRatio",Float.toString(cpuovercommitratio));
+ ClusterDetailsVO cpu_detail = _clusterDetailsDao.findDetail(cluster.getId(), "cpuOvercommitRatio");
+ if (cpu_detail == null) {
+ if (cpuovercommitratio.compareTo(1f) > 0) {
+ cpu_detail = new ClusterDetailsVO(cluster.getId(), "cpuOvercommitRatio", Float.toString(cpuovercommitratio));
_clusterDetailsDao.persist(cpu_detail);
}
- }
- else {
+ } else {
cpu_detail.setValue(Float.toString(cpuovercommitratio));
- _clusterDetailsDao.update(cpu_detail.getId(),cpu_detail);
+ _clusterDetailsDao.update(cpu_detail.getId(), cpu_detail);
}
-
if (doUpdate) {
Transaction txn = Transaction.currentTxn();
try {
@@ -1326,82 +1163,67 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
_clusterDao.update(cluster.getId(), cluster);
txn.commit();
} catch (Exception e) {
- s_logger.error(
- "Unable to update cluster due to " + e.getMessage(), e);
- throw new CloudRuntimeException(
- "Failed to update cluster. Please contact Cloud Support.");
+ s_logger.error("Unable to update cluster due to " + e.getMessage(), e);
+ throw new CloudRuntimeException("Failed to update cluster. Please contact Cloud Support.");
}
}
- if (newManagedState != null && !newManagedState.equals(oldManagedState)) {
+ if (newManagedState != null && !newManagedState.equals(oldManagedState)) {
Transaction txn = Transaction.currentTxn();
- if (newManagedState.equals(Managed.ManagedState.Unmanaged)) {
+ if (newManagedState.equals(Managed.ManagedState.Unmanaged)) {
boolean success = false;
try {
txn.start();
cluster.setManagedState(Managed.ManagedState.PrepareUnmanaged);
_clusterDao.update(cluster.getId(), cluster);
txn.commit();
- List<HostVO> hosts = listAllUpAndEnabledHosts(
- Host.Type.Routing, cluster.getId(),
- cluster.getPodId(), cluster.getDataCenterId());
- for (HostVO host : hosts) {
- if (host.getType().equals(Host.Type.Routing)
- && !host.getStatus().equals(Status.Down)
- && !host.getStatus()
- .equals(Status.Disconnected)
- && !host.getStatus().equals(Status.Up)
- && !host.getStatus().equals(Status.Alert)) {
- String msg = "host " + host.getPrivateIpAddress()
- + " should not be in "
- + host.getStatus().toString() + " status";
- throw new CloudRuntimeException(
- "PrepareUnmanaged Failed due to " + msg);
+ List<HostVO> hosts = listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
+ for (HostVO host : hosts) {
+ if (host.getType().equals(Host.Type.Routing) && !host.getStatus().equals(Status.Down)
+ && !host.getStatus().equals(Status.Disconnected) && !host.getStatus().equals(Status.Up)
+ && !host.getStatus().equals(Status.Alert)) {
+ String msg = "host " + host.getPrivateIpAddress() + " should not be in " + host.getStatus().toString() + " status";
+ throw new CloudRuntimeException("PrepareUnmanaged Failed due to " + msg);
}
}
- for (HostVO host : hosts) {
- if (host.getStatus().equals(Status.Up)) {
+ for (HostVO host : hosts) {
+ if (host.getStatus().equals(Status.Up)) {
umanageHost(host.getId());
}
}
int retry = 40;
boolean lsuccess = true;
- for (int i = 0; i < retry; i++) {
+ for (int i = 0; i < retry; i++) {
lsuccess = true;
try {
Thread.sleep(5 * 1000);
} catch (Exception e) {
}
- hosts = listAllUpAndEnabledHosts(Host.Type.Routing,
- cluster.getId(), cluster.getPodId(),
- cluster.getDataCenterId());
- for (HostVO host : hosts) {
- if (!host.getStatus().equals(Status.Down)
- && !host.getStatus().equals(
- Status.Disconnected)
+ hosts = listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
+ for (HostVO host : hosts) {
+ if (!host.getStatus().equals(Status.Down) && !host.getStatus().equals(Status.Disconnected)
&& !host.getStatus().equals(Status.Alert)) {
lsuccess = false;
break;
}
}
- if (lsuccess == true) {
+ if (lsuccess == true) {
success = true;
break;
}
}
- if (success == false) {
- throw new CloudRuntimeException(
- "PrepareUnmanaged Failed due to some hosts are still in UP status after 5 Minutes, please try later ");
+ if (success == false) {
+ throw new CloudRuntimeException(
+ "PrepareUnmanaged Failed due to some hosts are still in UP status after 5 Minutes, please try later ");
}
} finally {
txn.start();
- cluster.setManagedState(success ? Managed.ManagedState.Unmanaged
- : Managed.ManagedState.PrepareUnmanagedError);
+ cluster.setManagedState(success ? Managed.ManagedState.Unmanaged : Managed.ManagedState.PrepareUnmanagedError);
_clusterDao.update(cluster.getId(), cluster);
txn.commit();
}
- } else if (newManagedState.equals(Managed.ManagedState.Managed)) {
+ } else if (newManagedState.equals(Managed.ManagedState.Managed)) {
txn.start();
cluster.setManagedState(Managed.ManagedState.Managed);
_clusterDao.update(cluster.getId(), cluster);
@@ -1420,18 +1242,14 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
// verify input parameters
HostVO host = _hostDao.findById(hostId);
if (host == null || host.getRemoved() != null) {
- throw new InvalidParameterValueException("Host with id "
- + hostId.toString() + " doesn't exist");
+ throw new InvalidParameterValueException("Host with id " + hostId.toString() + " doesn't exist");
}
- processResourceEvent(ResourceListener.EVENT_CANCEL_MAINTENANCE_BEFORE,
- hostId);
+ processResourceEvent(ResourceListener.EVENT_CANCEL_MAINTENANCE_BEFORE, hostId);
boolean success = cancelMaintenance(hostId);
- processResourceEvent(ResourceListener.EVENT_CANCEL_MAINTENANCE_AFTER,
- hostId);
+ processResourceEvent(ResourceListener.EVENT_CANCEL_MAINTENANCE_AFTER, hostId);
if (!success) {
- throw new CloudRuntimeException(
- "Internal error cancelling maintenance.");
+ throw new CloudRuntimeException("Internal error cancelling maintenance.");
}
return host;
}
@@ -1442,63 +1260,51 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
HostVO host = _hostDao.findById(hostId);
if (host == null) {
- throw new InvalidParameterValueException("Host with id "
- + hostId.toString() + " doesn't exist");
+ throw new InvalidParameterValueException("Host with id " + hostId.toString() + " doesn't exist");
}
return (_agentMgr.reconnect(hostId) ? host : null);
}
@Override
- public boolean resourceStateTransitTo(Host host, ResourceState.Event event,
- long msId) throws NoTransitionException {
+ public boolean resourceStateTransitTo(Host host, ResourceState.Event event, long msId) throws NoTransitionException {
ResourceState currentState = host.getResourceState();
ResourceState nextState = currentState.getNextState(event);
if (nextState == null) {
- throw new NoTransitionException(
- "No next resource state found for current state ="
- + currentState + " event =" + event);
+ throw new NoTransitionException("No next resource state found for current state =" + currentState + " event =" + event);
}
- // TO DO - Make it more granular and have better conversion into
- // capacity type
+ // TO DO - Make it more granular and have better conversion into
+ // capacity type
- if (host.getType() == Type.Routing && host.getClusterId() != null) {
- AllocationState capacityState = _configMgr
- .findClusterAllocationState(ApiDBUtils.findClusterById(host
- .getClusterId()));
- if (capacityState == AllocationState.Enabled
- && nextState != ResourceState.Enabled) {
+ if (host.getType() == Type.Routing && host.getClusterId() != null) {
+ AllocationState capacityState = _configMgr.findClusterAllocationState(ApiDBUtils.findClusterById(host.getClusterId()));
+ if (capacityState == AllocationState.Enabled && nextState != ResourceState.Enabled) {
capacityState = AllocationState.Disabled;
}
- _capacityDao.updateCapacityState(null, null, null, host.getId(),
- capacityState.toString());
+ _capacityDao.updateCapacityState(null, null, null, host.getId(), capacityState.toString());
}
- return _hostDao.updateResourceState(currentState, event, nextState,
- host);
+ return _hostDao.updateResourceState(currentState, event, nextState, host);
}
private boolean doMaintain(final long hostId) {
HostVO host = _hostDao.findById(hostId);
- MaintainAnswer answer = (MaintainAnswer) _agentMgr.easySend(hostId,
- new MaintainCommand());
+ MaintainAnswer answer = (MaintainAnswer) _agentMgr.easySend(hostId, new MaintainCommand());
if (answer == null || !answer.getResult()) {
s_logger.warn("Unable to send MaintainCommand to host: " + hostId);
}
try {
- resourceStateTransitTo(host,
- ResourceState.Event.AdminAskMaintenace, _nodeId);
+ resourceStateTransitTo(host, ResourceState.Event.AdminAskMaintenace, _nodeId);
} catch (NoTransitionException e) {
- String err = "Cannot transimit resource state of host "
- + host.getId() + " to " + ResourceState.Maintenance;
+ String err = "Cannot transimit resource state of host " + host.getId() + " to " + ResourceState.Maintenance;
s_logger.debug(err, e);
throw new CloudRuntimeException(err + e.getMessage());
}
_agentMgr.pullAgentToMaintenance(hostId);
- /* TODO: move below to listener */
+ /* TODO: move below to listener */
if (host.getType() == Host.Type.Routing) {
final List<VMInstanceVO> vms = _vmDao.listByHostId(hostId);
@@ -1506,9 +1312,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
return true;
}
- List<HostVO> hosts = listAllUpAndEnabledHosts(Host.Type.Routing,
- host.getClusterId(), host.getPodId(),
- host.getDataCenterId());
+ List<HostVO> hosts = listAllUpAndEnabledHosts(Host.Type.Routing, host.getClusterId(), host.getPodId(), host.getDataCenterId());
for (final VMInstanceVO vm : vms) {
if (hosts == null || hosts.isEmpty() || !answer.getMigrate()) {
// for the last host in this cluster, stop all the VMs
@@ -1524,8 +1328,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
@Override
public boolean maintain(final long hostId) throws AgentUnavailableException {
- Boolean result = _clusterMgr.propagateResourceEvent(hostId,
- ResourceState.Event.AdminAskMaintenace);
+ Boolean result = _clusterMgr.propagateResourceEvent(hostId, ResourceState.Event.AdminAskMaintenace);
if (result != null) {
return result;
}
@@ -1540,39 +1343,29 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
if (host == null) {
s_logger.debug("Unable to find host " + hostId);
- throw new InvalidParameterValueException(
- "Unable to find host with ID: " + hostId
- + ". Please specify a valid host ID.");
+ throw new InvalidParameterValueException("Unable to find host with ID: " + hostId + ". Please specify a valid host ID.");
}
- if (_hostDao.countBy(host.getClusterId(),
- ResourceState.PrepareForMaintenance,
- ResourceState.ErrorInMaintenance) > 0) {
- throw new InvalidParameterValueException(
- "There are other servers in PrepareForMaintenance OR ErrorInMaintenance STATUS in cluster "
- + host.getClusterId());
+ if (_hostDao.countBy(host.getClusterId(), ResourceState.PrepareForMaintenance, ResourceState.ErrorInMaintenance) > 0) {
+ throw new InvalidParameterValueException("There are other servers in PrepareForMaintenance OR ErrorInMaintenance STATUS in cluster "
+ + host.getClusterId());
}
if (_storageMgr.isLocalStorageActiveOnHost(host.getId())) {
- throw new InvalidParameterValueException(
- "There are active VMs using the host's local storage pool. Please stop all VMs on this host that use local storage.");
+ throw new InvalidParameterValueException(
+ "There are active VMs using the host's local storage pool. Please stop all VMs on this host that use local storage.");
}
try {
- processResourceEvent(
- ResourceListener.EVENT_PREPARE_MAINTENANCE_BEFORE, hostId);
+ processResourceEvent(ResourceListener.EVENT_PREPARE_MAINTENANCE_BEFORE, hostId);
if (maintain(hostId)) {
- processResourceEvent(
- ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER,
- hostId);
+ processResourceEvent(ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER, hostId);
return _hostDao.findById(hostId);
} else {
- throw new CloudRuntimeException(
- "Unable to prepare for maintenance host " + hostId);
+ throw new CloudRuntimeException("Unable to prepare for maintenance host " + hostId);
}
} catch (AgentUnavailableException e) {
- throw new CloudRuntimeException(
- "Unable to prepare for maintenance host " + hostId);
+ throw new CloudRuntimeException("Unable to prepare for maintenance host " + hostId);
}
}
@@ -1584,18 +1377,13 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
// Verify that the host exists
HostVO host = _hostDao.findById(hostId);
if (host == null) {
- throw new InvalidParameterValueException("Host with id " + hostId
- + " doesn't exist");
+ throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist");
}
if (cmd.getAllocationState() != null) {
- ResourceState.Event resourceEvent = ResourceState.Event.toEvent(cmd
- .getAllocationState());
- if (resourceEvent != ResourceState.Event.Enable
- && resourceEvent != ResourceState.Event.Disable) {
- throw new CloudRuntimeException("Invalid allocation state:"
- + cmd.getAllocationState()
- + ", only Enable/Disable are allowed");
+ ResourceState.Event resourceEvent = ResourceState.Event.toEvent(cmd.getAllocationState());
+ if (resourceEvent != ResourceState.Event.Enable && resourceEvent != ResourceState.Event.Disable) {
+ throw new CloudRuntimeException("Invalid allocation state:" + cmd.getAllocationState() + ", only Enable/Disable are allowed");
}
resourceStateTransitTo(host, resourceEvent, _nodeId);
@@ -1605,22 +1393,16 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
// Verify that the guest OS Category exists
if (guestOSCategoryId > 0) {
if (_guestOSCategoryDao.findById(guestOSCategoryId) == null) {
- throw new InvalidParameterValueException(
- "Please specify a valid guest OS category.");
+ throw new InvalidParameterValueException("Please specify a valid guest OS category.");
}
}
- GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao
- .findById(guestOSCategoryId);
- Map<String, String> hostDetails = _hostDetailsDao
- .findDetails(hostId);
+ GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
+ Map<String, String> hostDetails = _hostDetailsDao.findDetails(hostId);
- if (guestOSCategory != null
- && !GuestOSCategoryVO.CATEGORY_NONE
- .equalsIgnoreCase(guestOSCategory.getName())) {
+ if (guestOSCategory != null && !GuestOSCategoryVO.CATEGORY_NONE.equalsIgnoreCase(guestOSCategory.getName())) {
// Save a new entry for guest.os.category.id
- hostDetails.put("guest.os.category.id",
- String.valueOf(guestOSCategory.getId()));
+ hostDetails.put("guest.os.category.id", String.valueOf(guestOSCategory.getId()));
} else {
// Delete any existing entry for guest.os.category.id
hostDetails.remove("guest.os.category.id");
@@ -1630,8 +1412,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
List<String> hostTags = cmd.getHostTags();
if (hostTags != null) {
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Updating Host Tags to :" + hostTags);
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Updating Host Tags to :" + hostTags);
}
_hostTagsDao.persist(hostId, hostTags);
}
@@ -1651,16 +1433,13 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
@Override
- public boolean configure(String name, Map<String, Object> params)
- throws ConfigurationException {
- _defaultSystemVMHypervisor = HypervisorType.getType(_configDao
- .getValue(Config.SystemVMDefaultHypervisor.toString()));
+ public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+ _defaultSystemVMHypervisor = HypervisorType.getType(_configDao.getValue(Config.SystemVMDefaultHypervisor.toString()));
return true;
}
@Override
- public List<HypervisorType> getSupportedHypervisorTypes(long zoneId,
- boolean forVirtualRouter, Long podId) {
+ public List<HypervisorType> getSupportedHypervisorTypes(long zoneId, boolean forVirtualRouter, Long podId) {
List<HypervisorType> hypervisorTypes = new ArrayList<HypervisorType>();
List<ClusterVO> clustersForZone = new ArrayList<ClusterVO>();
@@ -1672,8 +1451,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
for (ClusterVO cluster : clustersForZone) {
HypervisorType hType = cluster.getHypervisorType();
- if (!forVirtualRouter
- || (forVirtualRouter && hType != HypervisorType.BareMetal && hType != HypervisorType.Ovm)) {
+ if (!forVirtualRouter || (forVirtualRouter && hType != HypervisorType.BareMetal && hType != HypervisorType.Ovm)) {
hypervisorTypes.add(hType);
}
}
@@ -1693,14 +1471,12 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
return HypervisorType.None;
}
_dcDao.loadDetails(dc);
- String defaultHypervisorInZone = dc
- .getDetail("defaultSystemVMHypervisorType");
+ String defaultHypervisorInZone = dc.getDetail("defaultSystemVMHypervisorType");
if (defaultHypervisorInZone != null) {
defaultHyper = HypervisorType.getType(defaultHypervisorInZone);
}
- List<VMTemplateVO> systemTemplates = _templateDao
- .listAllSystemVMTemplates();
+ List<VMTemplateVO> systemTemplates = _templateDao.listAllSystemVMTemplates();
boolean isValid = false;
for (VMTemplateVO template : systemTemplates) {
if (template.getHypervisorType() == defaultHyper) {
@@ -1710,8 +1486,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
if (isValid) {
- List<ClusterVO> clusters = _clusterDao.listByDcHyType(zoneId,
- defaultHyper.toString());
+ List<ClusterVO> clusters = _clusterDao.listByDcHyType(zoneId, defaultHyper.toString());
if (clusters.size() <= 0) {
isValid = false;
}
@@ -1728,8 +1503,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
public HypervisorType getAvailableHypervisor(long zoneId) {
HypervisorType defaultHype = getDefaultHypervisor(zoneId);
if (defaultHype == HypervisorType.None) {
- List<HypervisorType> supportedHypes = getSupportedHypervisorTypes(
- zoneId, false, null);
+ List<HypervisorType> supportedHypes = getSupportedHypervisorTypes(zoneId, false, null);
if (supportedHypes.size() > 0) {
defaultHype = supportedHypes.get(0);
}
@@ -1742,8 +1516,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
@Override
- public void registerResourceStateAdapter(String name,
- ResourceStateAdapter adapter) {
+ public void registerResourceStateAdapter(String name, ResourceStateAdapter adapter) {
if (_resourceStateAdapters.get(name) != null) {
throw new CloudRuntimeException(name + " has registered");
}
@@ -1760,51 +1533,40 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
}
}
- private Object dispatchToStateAdapters(ResourceStateAdapter.Event event,
- boolean singleTaker, Object... args) {
+ private Object dispatchToStateAdapters(ResourceStateAdapter.Event event, boolean singleTaker, Object... args) {
synchronized (_resourceStateAdapters) {
Iterator it = _resourceStateAdapters.entrySet().iterator();
Object result = null;
while (it.hasNext()) {
- Map.Entry<String, ResourceStateAdapter> item = (Map.Entry<String, ResourceStateAdapter>) it
- .next();
+ Map.Entry<String, ResourceStateAdapter> item = (Map.Entry<String, ResourceStateAdapter>) it.next();
ResourceStateAdapter adapter = item.getValue();
- String msg = new String("Dispatching resource state event "
- + event + " to " + item.getKey());
+ String msg = new String("Dispatching resource state event " + event + " to " + item.getKey());
s_logger.debug(msg);
if (event == ResourceStateAdapter.Event.CREATE_HOST_VO_F
<TRUNCATED>