mirror of https://github.com/apache/cloudstack.git
Bug 13099 table physical-network-traffic-types needs to be updated when xen network device setting is modified in the global settings
Changes: - We do not need these global setting anymore. These will be hidden since 3.0 - The default traffic label will be picked from the global setting which is null by default. When traffic label is null it means the resource uses tag on the default gateway - Changes to invoke discoverer to reload the resource object on host connection - Since a zone can have many physical networks, there can be multiple guest, public networks. Only the zone wide storage and management traffic label will be stored in host_details henceforth. - If traffic labels are updated, discoverer should update the host_details
This commit is contained in:
parent
a6d4e59192
commit
dbe2305352
|
|
@ -4896,12 +4896,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
if (_privateNetworkName != null) {
|
||||
details.put("private.network.device", _privateNetworkName);
|
||||
}
|
||||
if (_publicNetworkName != null) {
|
||||
details.put("public.network.device", _publicNetworkName);
|
||||
}
|
||||
if (_guestNetworkName != null) {
|
||||
details.put("guest.network.device", _guestNetworkName);
|
||||
}
|
||||
|
||||
details.put("can_bridge_firewall", Boolean.toString(_canBridgeFirewall));
|
||||
cmd.setHostDetails(details);
|
||||
cmd.setName(hr.nameLabel);
|
||||
|
|
|
|||
|
|
@ -17,12 +17,9 @@
|
|||
*/
|
||||
package com.cloud.agent.manager;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
|
@ -91,6 +88,7 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
|||
import com.cloud.hypervisor.HypervisorGuruManager;
|
||||
import com.cloud.hypervisor.kvm.resource.KvmDummyResourceBase;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.resource.Discoverer;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.resource.ResourceState;
|
||||
import com.cloud.resource.ServerResource;
|
||||
|
|
@ -223,7 +221,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
|||
protected StateMachine2<Status, Status.Event, Host> _statusStateMachine = Status.getStateMachine();
|
||||
|
||||
@Inject ResourceManager _resourceMgr;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
|
||||
_name = name;
|
||||
|
|
@ -677,80 +675,26 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
|||
loadDirectlyConnectedHost(host, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected boolean loadDirectlyConnectedHost(HostVO host, boolean forRebalance) {
|
||||
boolean initialized = false;
|
||||
ServerResource resource = null;
|
||||
try {
|
||||
String resourceName = host.getResource();
|
||||
try {
|
||||
Class<?> clazz = Class.forName(resourceName);
|
||||
Constructor constructor = clazz.getConstructor();
|
||||
resource = (ServerResource) constructor.newInstance();
|
||||
} catch (ClassNotFoundException e) {
|
||||
s_logger.warn("Unable to find class " + host.getResource(), e);
|
||||
return false;
|
||||
} catch (InstantiationException e) {
|
||||
s_logger.warn("Unablet to instantiate class " + host.getResource(), e);
|
||||
return false;
|
||||
} catch (IllegalAccessException e) {
|
||||
s_logger.warn("Illegal access " + host.getResource(), e);
|
||||
return false;
|
||||
} catch (SecurityException e) {
|
||||
s_logger.warn("Security error on " + host.getResource(), e);
|
||||
return false;
|
||||
} catch (NoSuchMethodException e) {
|
||||
s_logger.warn("NoSuchMethodException error on " + host.getResource(), e);
|
||||
return false;
|
||||
} catch (IllegalArgumentException e) {
|
||||
s_logger.warn("IllegalArgumentException error on " + host.getResource(), e);
|
||||
return false;
|
||||
} catch (InvocationTargetException e) {
|
||||
s_logger.warn("InvocationTargetException error on " + host.getResource(), e);
|
||||
return false;
|
||||
}
|
||||
|
||||
_hostDao.loadDetails(host);
|
||||
|
||||
HashMap<String, Object> params = new HashMap<String, Object>(host.getDetails().size() + 5);
|
||||
params.putAll(host.getDetails());
|
||||
|
||||
params.put("guid", host.getGuid());
|
||||
params.put("zone", Long.toString(host.getDataCenterId()));
|
||||
if (host.getPodId() != null) {
|
||||
params.put("pod", Long.toString(host.getPodId()));
|
||||
}
|
||||
if (host.getClusterId() != null) {
|
||||
params.put("cluster", Long.toString(host.getClusterId()));
|
||||
String guid = null;
|
||||
ClusterVO cluster = _clusterDao.findById(host.getClusterId());
|
||||
if (cluster.getGuid() == null) {
|
||||
guid = host.getDetail("pool");
|
||||
} else {
|
||||
guid = cluster.getGuid();
|
||||
}
|
||||
if (guid != null && !guid.isEmpty()) {
|
||||
params.put("pool", guid);
|
||||
}
|
||||
}
|
||||
|
||||
params.put("ipaddress", host.getPrivateIpAddress());
|
||||
params.put("secondary.storage.vm", "false");
|
||||
params.put("max.template.iso.size", _configDao.getValue(Config.MaxTemplateAndIsoSize.toString()));
|
||||
params.put("migratewait", _configDao.getValue(Config.MigrateWait.toString()));
|
||||
|
||||
try {
|
||||
resource.configure(host.getName(), params);
|
||||
} catch (ConfigurationException e) {
|
||||
s_logger.warn("Unable to configure resource due to " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!resource.start()) {
|
||||
s_logger.warn("Unable to start the resource");
|
||||
return false;
|
||||
}
|
||||
//load the respective discoverer
|
||||
Discoverer discoverer = _resourceMgr.getMatchingDiscover(host.getHypervisorType());
|
||||
if(discoverer == null){
|
||||
s_logger.warn("Unable to find a Discoverer to load the resource: "+ host.getId() +" for hypervisor type: "+host.getHypervisorType());
|
||||
return false;
|
||||
}
|
||||
|
||||
resource = discoverer.reloadResource(host);
|
||||
|
||||
if(resource == null){
|
||||
s_logger.warn("Discoverer is unable to load the resource: "+ host.getId());
|
||||
return false;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -230,25 +230,25 @@ public enum Config {
|
|||
SortKeyAlgorithm("Advanced", ManagementServer.class, Boolean.class, "sortkey.algorithm", "false", "Sort algorithm for those who use sort key(template, disk offering, service offering, network offering), true means ascending sort while false means descending sort", null),
|
||||
|
||||
// Ovm
|
||||
OvmPublicNetwork("Advanced", ManagementServer.class, String.class, "ovm.public.network.device", null, "Specify the public bridge on host for public network", null),
|
||||
OvmPrivateNetwork("Advanced", ManagementServer.class, String.class, "ovm.private.network.device", null, "Specify the private bridge on host for private network", null),
|
||||
OvmGuestNetwork("Advanced", ManagementServer.class, String.class, "ovm.guest.network.device", null, "Specify the private bridge on host for private network", null),
|
||||
OvmPublicNetwork("Hidden", ManagementServer.class, String.class, "ovm.public.network.device", null, "Specify the public bridge on host for public network", null),
|
||||
OvmPrivateNetwork("Hidden", ManagementServer.class, String.class, "ovm.private.network.device", null, "Specify the private bridge on host for private network", null),
|
||||
OvmGuestNetwork("Hidden", ManagementServer.class, String.class, "ovm.guest.network.device", null, "Specify the private bridge on host for private network", null),
|
||||
|
||||
// XenServer
|
||||
XenPublicNetwork("Network", ManagementServer.class, String.class, "xen.public.network.device", null, "[ONLY IF THE PUBLIC NETWORK IS ON A DEDICATED NIC]:The network name label of the physical device dedicated to the public network on a XenServer host", null),
|
||||
XenStorageNetwork1("Network", ManagementServer.class, String.class, "xen.storage.network.device1", null, "Specify when there are storage networks", null),
|
||||
XenStorageNetwork2("Network", ManagementServer.class, String.class, "xen.storage.network.device2", null, "Specify when there are storage networks", null),
|
||||
XenPrivateNetwork("Network", ManagementServer.class, String.class, "xen.private.network.device", null, "Specify when the private network name is different", null),
|
||||
XenPublicNetwork("Hidden", ManagementServer.class, String.class, "xen.public.network.device", null, "[ONLY IF THE PUBLIC NETWORK IS ON A DEDICATED NIC]:The network name label of the physical device dedicated to the public network on a XenServer host", null),
|
||||
XenStorageNetwork1("Hidden", ManagementServer.class, String.class, "xen.storage.network.device1", null, "Specify when there are storage networks", null),
|
||||
XenStorageNetwork2("Hidden", ManagementServer.class, String.class, "xen.storage.network.device2", null, "Specify when there are storage networks", null),
|
||||
XenPrivateNetwork("Hidden", ManagementServer.class, String.class, "xen.private.network.device", null, "Specify when the private network name is different", null),
|
||||
NetworkGuestCidrLimit("Network", NetworkManager.class, Integer.class, "network.guest.cidr.limit", "22", "size limit for guest cidr; can't be less than this value", null),
|
||||
XenSetupMultipath("Advanced", ManagementServer.class, String.class, "xen.setup.multipath", "false", "Setup the host to do multipath", null),
|
||||
XenBondStorageNic("Advanced", ManagementServer.class, String.class, "xen.bond.storage.nics", null, "Attempt to bond the two networks if found", null),
|
||||
XenHeartBeatInterval("Advanced", ManagementServer.class, Integer.class, "xen.heartbeat.interval", "60", "heartbeat to use when implementing XenServer Self Fencing", null),
|
||||
XenGuestNetwork("Advanced", ManagementServer.class, String.class, "xen.guest.network.device", null, "Specify for guest network name label", null),
|
||||
XenGuestNetwork("Hidden", ManagementServer.class, String.class, "xen.guest.network.device", null, "Specify for guest network name label", null),
|
||||
|
||||
// VMware
|
||||
VmwarePrivateNetworkVSwitch("Advanced", ManagementServer.class, String.class, "vmware.private.vswitch", null, "Specify the vSwitch on host for private network", null),
|
||||
VmwarePublicNetworkVSwitch("Advanced", ManagementServer.class, String.class, "vmware.public.vswitch", null, "Specify the vSwitch on host for public network", null),
|
||||
VmwareGuestNetworkVSwitch("Advanced", ManagementServer.class, String.class, "vmware.guest.vswitch", null, "Specify the vSwitch on host for guest network", null),
|
||||
VmwarePrivateNetworkVSwitch("Hidden", ManagementServer.class, String.class, "vmware.private.vswitch", null, "Specify the vSwitch on host for private network", null),
|
||||
VmwarePublicNetworkVSwitch("Hidden", ManagementServer.class, String.class, "vmware.public.vswitch", null, "Specify the vSwitch on host for public network", null),
|
||||
VmwareGuestNetworkVSwitch("Hidden", ManagementServer.class, String.class, "vmware.guest.vswitch", null, "Specify the vSwitch on host for guest network", null),
|
||||
VmwareServiceConsole("Advanced", ManagementServer.class, String.class, "vmware.service.console", "Service Console", "Specify the service console network name(for ESX hosts)", null),
|
||||
VmwareManagementPortGroup("Advanced", ManagementServer.class, String.class, "vmware.management.portgroup", "Management Network", "Specify the management network name(for ESXi hosts)", null),
|
||||
VmwareAdditionalVncPortRangeStart("Advanced", ManagementServer.class, Integer.class, "vmware.additional.vnc.portrange.start", "50000", "Start port number of additional VNC port range", null),
|
||||
|
|
@ -262,9 +262,9 @@ public enum Config {
|
|||
VmwareRecycleHungWorker("Advanced", ManagementServer.class, Boolean.class, "vmware.recycle.hung.wokervm", "false", "Specify whether or not to recycle hung worker VMs", null),
|
||||
|
||||
// KVM
|
||||
KvmPublicNetwork("Advanced", ManagementServer.class, String.class, "kvm.public.network.device", null, "Specify the public bridge on host for public network", null),
|
||||
KvmPrivateNetwork("Advanced", ManagementServer.class, String.class, "kvm.private.network.device", null, "Specify the private bridge on host for private network", null),
|
||||
KvmGuestNetwork("Advanced", ManagementServer.class, String.class, "kvm.guest.network.device", null, "Specify the private bridge on host for private network", null),
|
||||
KvmPublicNetwork("Hidden", ManagementServer.class, String.class, "kvm.public.network.device", null, "Specify the public bridge on host for public network", null),
|
||||
KvmPrivateNetwork("Hidden", ManagementServer.class, String.class, "kvm.private.network.device", null, "Specify the private bridge on host for private network", null),
|
||||
KvmGuestNetwork("Hidden", ManagementServer.class, String.class, "kvm.guest.network.device", null, "Specify the private bridge on host for private network", null),
|
||||
// Premium
|
||||
UsageExecutionTimezone("Premium", ManagementServer.class, String.class, "usage.execution.timezone", null, "The timezone to use for usage job execution time", null),
|
||||
UsageStatsJobAggregationRange("Premium", ManagementServer.class, Integer.class, "usage.stats.job.aggregation.range", "1440", "The range of time for aggregating the user statistics specified in minutes (e.g. 1440 for daily, 60 for hourly.", null),
|
||||
|
|
|
|||
|
|
@ -47,11 +47,9 @@ import com.cloud.agent.api.StartupCommand;
|
|||
import com.cloud.agent.api.StartupRoutingCommand;
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
|
|
@ -63,7 +61,6 @@ import com.cloud.host.HostEnvironment;
|
|||
import com.cloud.host.HostInfo;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.hypervisor.xen.resource.CitrixResourceBase;
|
||||
|
|
@ -115,11 +112,8 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
|
|||
|
||||
@Inject protected AlertManager _alertMgr;
|
||||
@Inject protected AgentManager _agentMgr;
|
||||
@Inject protected HostDao _hostDao;
|
||||
@Inject VMTemplateDao _tmpltDao;
|
||||
@Inject VMTemplateHostDao _vmTemplateHostDao;
|
||||
@Inject ClusterDao _clusterDao;
|
||||
@Inject protected ConfigurationDao _configDao;
|
||||
@Inject ResourceManager _resourceMgr;
|
||||
@Inject HostPodDao _podDao;
|
||||
@Inject DataCenterDao _dcDao;
|
||||
|
|
@ -294,31 +288,21 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
|
|||
details.put(HostInfo.HOST_OS_VERSION, hostOSVer);
|
||||
details.put(HostInfo.HOST_OS_KERNEL_VERSION, hostKernelVer);
|
||||
details.put(HostInfo.HYPERVISOR_VERSION, xenVersion);
|
||||
|
||||
String privateNetworkLabel = _networkMgr.getDefaultManagementTrafficLabel(dcId, HypervisorType.XenServer);
|
||||
String storageNetworkLabel = _networkMgr.getDefaultStorageTrafficLabel(dcId, HypervisorType.XenServer);
|
||||
|
||||
if (!params.containsKey("private.network.device") && privateNetworkLabel != null) {
|
||||
params.put("private.network.device", privateNetworkLabel);
|
||||
details.put("private.network.device", privateNetworkLabel);
|
||||
}
|
||||
|
||||
if (!params.containsKey("storage.network.device1") && storageNetworkLabel != null) {
|
||||
params.put("storage.network.device1", storageNetworkLabel);
|
||||
details.put("storage.network.device1", storageNetworkLabel);
|
||||
}
|
||||
|
||||
/*if (!params.containsKey("public.network.device") && _publicNic != null) {
|
||||
params.put("public.network.device", _publicNic);
|
||||
details.put("public.network.device", _publicNic);
|
||||
}
|
||||
|
||||
if (!params.containsKey("guest.network.device") && _guestNic != null) {
|
||||
params.put("guest.network.device", _guestNic);
|
||||
details.put("guest.network.device", _guestNic);
|
||||
}
|
||||
|
||||
if (!params.containsKey("private.network.device") && _privateNic != null) {
|
||||
params.put("private.network.device", _privateNic);
|
||||
details.put("private.network.device", _privateNic);
|
||||
}
|
||||
|
||||
if (!params.containsKey("storage.network.device1") && _storageNic1 != null) {
|
||||
params.put("storage.network.device1", _storageNic1);
|
||||
details.put("storage.network.device1", _storageNic1);
|
||||
}
|
||||
|
||||
if (!params.containsKey("storage.network.device2") && _storageNic2 != null) {
|
||||
params.put("storage.network.device2", _storageNic2);
|
||||
details.put("storage.network.device2", _storageNic2);
|
||||
}*/
|
||||
params.put("wait", Integer.toString(_wait));
|
||||
details.put("wait", Integer.toString(_wait));
|
||||
params.put("migratewait", _configDao.getValue(Config.MigrateWait.toString()));
|
||||
|
|
|
|||
|
|
@ -301,4 +301,8 @@ public interface NetworkManager extends NetworkService {
|
|||
Network network, String requestedIp)
|
||||
throws InsufficientVirtualNetworkCapcityException,
|
||||
InsufficientAddressCapacityException;
|
||||
|
||||
String getDefaultManagementTrafficLabel(long zoneId, HypervisorType hypervisorType);
|
||||
|
||||
String getDefaultStorageTrafficLabel(long zoneId, HypervisorType hypervisorType);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5406,12 +5406,21 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
|
||||
if (xenLabel != null) {
|
||||
if("".equals(xenLabel)){
|
||||
xenLabel = null;
|
||||
}
|
||||
trafficType.setXenNetworkLabel(xenLabel);
|
||||
}
|
||||
if (kvmLabel != null) {
|
||||
if("".equals(kvmLabel)){
|
||||
kvmLabel = null;
|
||||
}
|
||||
trafficType.setKvmNetworkLabel(kvmLabel);
|
||||
}
|
||||
if (vmwareLabel != null) {
|
||||
if("".equals(vmwareLabel)){
|
||||
vmwareLabel = null;
|
||||
}
|
||||
trafficType.setVmwareNetworkLabel(vmwareLabel);
|
||||
}
|
||||
_pNTrafficTypeDao.update(id, trafficType);
|
||||
|
|
@ -5467,6 +5476,57 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
|
||||
return networkList.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultManagementTrafficLabel(long zoneId, HypervisorType hypervisorType){
|
||||
try{
|
||||
PhysicalNetwork mgmtPhyNetwork = getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Management);
|
||||
PhysicalNetworkTrafficTypeVO mgmtTraffic = _pNTrafficTypeDao.findBy(mgmtPhyNetwork.getId(), TrafficType.Management);
|
||||
if(mgmtTraffic != null){
|
||||
String label = null;
|
||||
switch(hypervisorType){
|
||||
case XenServer : label = mgmtTraffic.getXenNetworkLabel();
|
||||
break;
|
||||
case KVM : label = mgmtTraffic.getKvmNetworkLabel();
|
||||
break;
|
||||
case VMware : label = mgmtTraffic.getVmwareNetworkLabel();
|
||||
break;
|
||||
}
|
||||
return label;
|
||||
}
|
||||
}catch(Exception ex){
|
||||
if(s_logger.isDebugEnabled()){
|
||||
s_logger.debug("Failed to retrive the default label for management traffic:"+"zone: "+ zoneId +" hypervisor: "+hypervisorType +" due to:" + ex.getMessage());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultStorageTrafficLabel(long zoneId, HypervisorType hypervisorType){
|
||||
try{
|
||||
PhysicalNetwork storagePhyNetwork = getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId, TrafficType.Storage);
|
||||
PhysicalNetworkTrafficTypeVO storageTraffic = _pNTrafficTypeDao.findBy(storagePhyNetwork.getId(), TrafficType.Storage);
|
||||
if(storageTraffic != null){
|
||||
String label = null;
|
||||
switch(hypervisorType){
|
||||
case XenServer : label = storageTraffic.getXenNetworkLabel();
|
||||
break;
|
||||
case KVM : label = storageTraffic.getKvmNetworkLabel();
|
||||
break;
|
||||
case VMware : label = storageTraffic.getVmwareNetworkLabel();
|
||||
break;
|
||||
}
|
||||
return label;
|
||||
}
|
||||
}catch(Exception ex){
|
||||
if(s_logger.isDebugEnabled()){
|
||||
s_logger.debug("Failed to retrive the default label for storage traffic:"+"zone: "+ zoneId +" hypervisor: "+hypervisorType +" due to:" + ex.getMessage());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
|
||||
|
|
|
|||
|
|
@ -46,4 +46,7 @@ public interface Discoverer extends Adapter {
|
|||
boolean matchHypervisor(String hypervisor);
|
||||
Hypervisor.HypervisorType getHypervisorType();
|
||||
public void putParam(Map<String, String> params);
|
||||
|
||||
ServerResource reloadResource(HostVO host);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,20 +17,36 @@
|
|||
*/
|
||||
package com.cloud.resource;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.net.UrlUtil;
|
||||
|
||||
public abstract class DiscovererBase implements Discoverer {
|
||||
protected String _name;
|
||||
protected Map<String, String> _params;
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(DiscovererBase.class);
|
||||
@Inject protected ClusterDao _clusterDao;
|
||||
@Inject protected ConfigurationDao _configDao;
|
||||
@Inject protected NetworkManager _networkMgr;
|
||||
@Inject protected HostDao _hostDao;
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
ConfigurationDao dao = ComponentLocator.getCurrentLocator().getDao(ConfigurationDao.class);
|
||||
|
|
@ -68,5 +84,109 @@ public abstract class DiscovererBase implements Discoverer {
|
|||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected ServerResource getResource(String resourceName){
|
||||
ServerResource resource = null;
|
||||
try {
|
||||
Class<?> clazz = Class.forName(resourceName);
|
||||
Constructor constructor = clazz.getConstructor();
|
||||
resource = (ServerResource) constructor.newInstance();
|
||||
} catch (ClassNotFoundException e) {
|
||||
s_logger.warn("Unable to find class " + resourceName, e);
|
||||
} catch (InstantiationException e) {
|
||||
s_logger.warn("Unablet to instantiate class " + resourceName, e);
|
||||
} catch (IllegalAccessException e) {
|
||||
s_logger.warn("Illegal access " + resourceName, e);
|
||||
} catch (SecurityException e) {
|
||||
s_logger.warn("Security error on " + resourceName, e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
s_logger.warn("NoSuchMethodException error on " + resourceName, e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
s_logger.warn("IllegalArgumentException error on " + resourceName, e);
|
||||
} catch (InvocationTargetException e) {
|
||||
s_logger.warn("InvocationTargetException error on " + resourceName, e);
|
||||
}
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
protected HashMap<String, Object> buildConfigParams(HostVO host){
|
||||
HashMap<String, Object> params = new HashMap<String, Object>(host.getDetails().size() + 5);
|
||||
params.putAll(host.getDetails());
|
||||
|
||||
params.put("guid", host.getGuid());
|
||||
params.put("zone", Long.toString(host.getDataCenterId()));
|
||||
if (host.getPodId() != null) {
|
||||
params.put("pod", Long.toString(host.getPodId()));
|
||||
}
|
||||
if (host.getClusterId() != null) {
|
||||
params.put("cluster", Long.toString(host.getClusterId()));
|
||||
String guid = null;
|
||||
ClusterVO cluster = _clusterDao.findById(host.getClusterId());
|
||||
if (cluster.getGuid() == null) {
|
||||
guid = host.getDetail("pool");
|
||||
} else {
|
||||
guid = cluster.getGuid();
|
||||
}
|
||||
if (guid != null && !guid.isEmpty()) {
|
||||
params.put("pool", guid);
|
||||
}
|
||||
}
|
||||
|
||||
params.put("ipaddress", host.getPrivateIpAddress());
|
||||
params.put("secondary.storage.vm", "false");
|
||||
params.put("max.template.iso.size", _configDao.getValue(Config.MaxTemplateAndIsoSize.toString()));
|
||||
params.put("migratewait", _configDao.getValue(Config.MigrateWait.toString()));
|
||||
return params;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResource reloadResource(HostVO host) {
|
||||
String resourceName = host.getResource();
|
||||
ServerResource resource = getResource(resourceName);
|
||||
|
||||
if(resource != null){
|
||||
_hostDao.loadDetails(host);
|
||||
updateNetworkLabels(host);
|
||||
|
||||
HashMap<String, Object> params = buildConfigParams(host);
|
||||
try {
|
||||
resource.configure(host.getName(), params);
|
||||
} catch (ConfigurationException e) {
|
||||
s_logger.warn("Unable to configure resource due to " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
if (!resource.start()) {
|
||||
s_logger.warn("Unable to start the resource");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
private void updateNetworkLabels(HostVO host){
|
||||
//check if networkLabels need to be updated in details
|
||||
//we send only private and storage network label to the resource.
|
||||
String privateNetworkLabel = _networkMgr.getDefaultManagementTrafficLabel(host.getDataCenterId(), host.getHypervisorType());
|
||||
String storageNetworkLabel = _networkMgr.getDefaultStorageTrafficLabel(host.getDataCenterId(), host.getHypervisorType());
|
||||
|
||||
String privateDevice = host.getDetail("private.network.device");
|
||||
String storageDevice = host.getDetail("storage.network.device1");
|
||||
|
||||
boolean update = false;
|
||||
|
||||
if(privateNetworkLabel != null && !privateNetworkLabel.equalsIgnoreCase(privateDevice)){
|
||||
host.setDetail("private.network.device", privateNetworkLabel);
|
||||
update = true;
|
||||
}
|
||||
if(storageNetworkLabel != null && !storageNetworkLabel.equalsIgnoreCase(storageDevice)){
|
||||
host.setDetail("storage.network.device1", storageNetworkLabel);
|
||||
update = true;
|
||||
}
|
||||
if(update){
|
||||
_hostDao.saveDetails(host);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,5 +109,11 @@ public class DummyHostDiscoverer implements Discoverer {
|
|||
public void putParam(Map<String, String> params) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResource reloadResource(HostVO host) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,4 +137,6 @@ public interface ResourceManager extends ResourceService{
|
|||
HypervisorType getDefaultHypervisor(long zoneId);
|
||||
|
||||
HypervisorType getAvailableHypervisor(long zoneId);
|
||||
|
||||
Discoverer getMatchingDiscover(HypervisorType hypervisorType);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
*/
|
||||
package com.cloud.resource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLDecoder;
|
||||
|
|
@ -468,7 +467,8 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
|||
}
|
||||
}
|
||||
|
||||
private Discoverer getMatchingDiscover(Hypervisor.HypervisorType hypervisorType) {
|
||||
@Override
|
||||
public Discoverer getMatchingDiscover(Hypervisor.HypervisorType hypervisorType) {
|
||||
Enumeration<? extends Discoverer> en = _discoverers.enumeration();
|
||||
while (en.hasMoreElements()) {
|
||||
Discoverer discoverer = en.nextElement();
|
||||
|
|
|
|||
Loading…
Reference in New Issue