bug 10710: Basic zone setup - send dhcp entries to all domRs (in every Pod) only when network.dns.basiczone.updates is set to "all"

status 10710: resolved fixed
This commit is contained in:
alena 2011-07-14 16:26:41 -07:00
parent 161b7f1cad
commit 731c3bc20a
7 changed files with 90 additions and 45 deletions

View File

@ -28,7 +28,6 @@ import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.StoragePoolResponse;
import com.cloud.api.response.TemplateResponse;
import com.cloud.async.AsyncJob;

View File

@ -244,7 +244,8 @@ public enum Config {
AgentLbEnable("Advanced", ClusterManager.class, Boolean.class, "agent.lb.enabled", "true", "If agent load balancing enabled in cluster setup", null),
SubDomainNetworkAccess("Advanced", NetworkManager.class, Boolean.class, "allow.subdomain.network.access", "true", "Allow subdomains to use networks dedicated to their parent domain(s)", null),
EncodeApiResponse("Advanced", ManagementServer.class, Boolean.class, "encode.api.response", "false", "Do UTF-8 encoding for the api response, false by default", null);
EncodeApiResponse("Advanced", ManagementServer.class, Boolean.class, "encode.api.response", "false", "Do UTF-8 encoding for the api response, false by default", null),
DnsBasicZoneUpdates("Advanced", NetworkManager.class, String.class, "network.dns.basiczone.updates", "all", "This parameter can take 2 values: all (default) and pod. It defines if DHCP/DNS requests have to be send to all dhcp servers in cloudstack, or only to the one in the same pod", "all,pod");
private final String _category;

View File

@ -407,10 +407,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
return "Please enter valid hypervisor type";
}
}
} else {
}else {
String[] options = range.split(",");
for (String option : options) {
if (option.trim().equals(value)) {
if (option.trim().equalsIgnoreCase(value)) {
return null;
}
}

View File

@ -295,6 +295,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
int _checkRouterInterval = 30;
private ServiceOfferingVO _offering;
private String trafficSentinelHostname;
private String _dnsBasicZoneUpdates = "all";
ScheduledExecutorService _executor;
ScheduledExecutorService _checkExecutor;
@ -558,6 +559,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
if (_instance == null) {
_instance = "DEFAULT";
}
_dnsBasicZoneUpdates = String.valueOf(_configDao.getValue(Config.DnsBasicZoneUpdates.key()));
s_logger.info("Router configurations: " + "ramsize=" + _routerRamSize);
@ -942,13 +945,14 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
DataCenterDeployment plan = null;
DataCenter dc = dest.getDataCenter();
long dcId = dc.getId();
boolean isPodBased = (dc.getNetworkType() == NetworkType.Basic || guestNetwork.isSecurityGroupEnabled()) && guestNetwork.getTrafficType() == TrafficType.Guest;
DomainRouterVO router = null;
List<DomainRouterVO> routers = null;
Long podId = dest.getPod().getId();
// In Basic zone and Guest network we have to start domR per pod, not per network
if ((dc.getNetworkType() == NetworkType.Basic || guestNetwork.isSecurityGroupEnabled()) && guestNetwork.getTrafficType() == TrafficType.Guest) {
if (isPodBased) {
routers = _routerDao.findByNetworkAndPod(guestNetwork.getId(), podId);
plan = new DataCenterDeployment(dcId, podId, null, null, null);
} else {
@ -957,6 +961,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
if (!routers.isEmpty()) {
//for Basic zone, add all Running routers - we have to send Dhcp/vmData/password info to them when network.dns.basiczone.updates is set to "all"
if (isPodBased) {
List<DomainRouterVO> allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(guestNetwork.getId(), podId, State.Running);
routers.addAll(allRunningRoutersOutsideThePod);
}
return routers;
}
@ -1435,12 +1444,28 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
List<VirtualRouter> rets = new ArrayList<VirtualRouter>(routers.size());
for (DomainRouterVO router : routers) {
if (router.getState() != State.Running) {
s_logger.warn("Unable to add virtual machine " + profile.getVirtualMachine() + " to the router " + router + " as the router is not in Running state");
continue;
}
boolean sendPasswordAndVmData = true;
boolean sendDnsDhcpData = true;
_userVmDao.loadDetails((UserVmVO) profile.getVirtualMachine());
//for basic zone:
//1) send vm data/password information only to the dhcp in the same pod
//2) send dhcp/dns information to all routers in the cloudstack only when _dnsBasicZoneUpdates is set to "all" value
DataCenter dc = dest.getDataCenter();
if (dc.getNetworkType() == NetworkType.Basic) {
Long podId = dest.getPod().getId();
if (router.getPodIdToDeployIn().longValue() != podId.longValue()) {
sendPasswordAndVmData = false;
if (_dnsBasicZoneUpdates.equalsIgnoreCase("pod")) {
sendDnsDhcpData = false;
}
}
}
String password = (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword);
String userData = profile.getVirtualMachine().getUserData();
String sshPublicKey = profile.getVirtualMachine().getDetail("SSH.PublicKey");
Commands cmds = new Commands(OnError.Stop);
String routerControlIpAddress = null;
@ -1452,26 +1477,22 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
}
DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), profile.getVirtualMachine().getHostName());
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_IP, routerControlIpAddress);
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress());
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
DataCenterVO dcVo = _dcDao.findById(router.getDataCenterIdToDeployIn());
dhcpCommand.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
cmds.addCommand("dhcp", dhcpCommand);
//for basic zone, send vm data/password information only to the dhcp in the same pod
DataCenter dc = dest.getDataCenter();
if (dc.getNetworkType() == NetworkType.Basic) {
Long podId = dest.getPod().getId();
if (router.getPodIdToDeployIn().longValue() != podId.longValue()) {
sendPasswordAndVmData = false;
}
if (sendDnsDhcpData) {
DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), profile.getVirtualMachine().getHostName());
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_IP, routerControlIpAddress);
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress());
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
dhcpCommand.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dc.getNetworkType().toString());
cmds.addCommand("dhcp", dhcpCommand);
}
if (sendPasswordAndVmData) {
String password = (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword);
String userData = profile.getVirtualMachine().getUserData();
String sshPublicKey = profile.getVirtualMachine().getDetail("SSH.PublicKey");
// password should be set only on default network element
if (password != null && network.isDefault()) {
final String encodedPassword = PasswordGenerator.rot13(password);
@ -1479,7 +1500,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, router.getPrivateIpAddress());
cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress());
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dc.getNetworkType().toString());
cmds.addCommand("password", cmd);
}
@ -1493,29 +1514,32 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
.getInstanceName(), profile.getId(), sshPublicKey));
}
try {
_agentMgr.send(router.getHostId(), cmds);
} catch (OperationTimedoutException e) {
throw new AgentUnavailableException("Unable to reach the agent ", router.getHostId(), e);
}
if (cmds.size() > 0) {
try {
_agentMgr.send(router.getHostId(), cmds);
} catch (OperationTimedoutException e) {
throw new AgentUnavailableException("Unable to reach the agent ", router.getHostId(), e);
}
Answer answer = cmds.getAnswer("dhcp");
if (!answer.getResult()) {
s_logger.error("Unable to set dhcp entry for " + profile + " on domR: " + router.getHostName() + " due to " + answer.getDetails());
throw new ResourceUnavailableException("Unable to set dhcp entry for " + profile + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterIdToDeployIn());
}
Answer answer = cmds.getAnswer("dhcp");
if (!answer.getResult()) {
s_logger.error("Unable to set dhcp entry for " + profile + " on domR: " + router.getHostName() + " due to " + answer.getDetails());
throw new ResourceUnavailableException("Unable to set dhcp entry for " + profile + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterIdToDeployIn());
}
answer = cmds.getAnswer("password");
if (answer != null && !answer.getResult()) {
s_logger.error("Unable to set password for " + profile + " due to " + answer.getDetails());
throw new ResourceUnavailableException("Unable to set password due to " + answer.getDetails(), DataCenter.class, router.getDataCenterIdToDeployIn());
}
answer = cmds.getAnswer("password");
if (answer != null && !answer.getResult()) {
s_logger.error("Unable to set password for " + profile + " due to " + answer.getDetails());
throw new ResourceUnavailableException("Unable to set password due to " + answer.getDetails(), DataCenter.class, router.getDataCenterIdToDeployIn());
}
answer = cmds.getAnswer("vmdata");
if (answer != null && !answer.getResult()) {
s_logger.error("Unable to set VM data for " + profile + " due to " + answer.getDetails());
throw new ResourceUnavailableException("Unable to set VM data due to " + answer.getDetails(), DataCenter.class, router.getDataCenterIdToDeployIn());
answer = cmds.getAnswer("vmdata");
if (answer != null && !answer.getResult()) {
s_logger.error("Unable to set VM data for " + profile + " due to " + answer.getDetails());
throw new ResourceUnavailableException("Unable to set VM data due to " + answer.getDetails(), DataCenter.class, router.getDataCenterIdToDeployIn());
}
}
rets.add(router);
}
return rets;

View File

@ -91,4 +91,6 @@ public interface DomainRouterDao extends GenericDao<DomainRouterVO, Long> {
* @return
*/
List<DomainRouterVO> listByStateAndNetworkType(State state, GuestIpType ipType);
List<DomainRouterVO> findByNetworkOutsideThePod(long networkId, long podId, State state);
}

View File

@ -46,6 +46,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
protected final SearchBuilder<DomainRouterVO> IdNetworkIdStatesSearch;
protected final SearchBuilder<DomainRouterVO> HostUpSearch;
protected final SearchBuilder<DomainRouterVO> StateNetworkTypeSearch;
protected final SearchBuilder<DomainRouterVO> OutsidePodSearch;
NetworkDaoImpl _networksDao = ComponentLocator.inject(NetworkDaoImpl.class);
protected DomainRouterDaoImpl() {
@ -81,6 +82,12 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
joinStateNetwork.and("guestType", joinStateNetwork.entity().getGuestType(), Op.EQ);
StateNetworkTypeSearch.join("network", joinStateNetwork, joinStateNetwork.entity().getId(), StateNetworkTypeSearch.entity().getNetworkId(), JoinType.INNER);
StateNetworkTypeSearch.done();
OutsidePodSearch = createSearchBuilder();
OutsidePodSearch.and("network", OutsidePodSearch.entity().getNetworkId(), Op.EQ);
OutsidePodSearch.and("podId", OutsidePodSearch.entity().getPodIdToDeployIn(), Op.NEQ);
OutsidePodSearch.and("state", OutsidePodSearch.entity().getState(), Op.EQ);
OutsidePodSearch.done();
}
@ -194,4 +201,14 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
sc.setJoinParameters("network", "guestType", ipType);
return listBy(sc);
}
@Override
public List<DomainRouterVO> findByNetworkOutsideThePod(long networkId, long podId, State state) {
SearchCriteria<DomainRouterVO> sc = OutsidePodSearch.create();
sc.setParameters("network", networkId);
sc.setParameters("podId", podId);
sc.setParameters("state", state);
return listBy(sc);
}
}

View File

@ -5,3 +5,5 @@
ALTER TABLE `cloud`.`account` ADD COLUMN `network_domain` varchar(255);
ALTER TABLE `cloud`.`domain` ADD COLUMN `network_domain` varchar(255);
INSERT IGNORE INTO configuration VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'network.dns.basiczone.updates', 'all', 'This parameter can take 2 values: all (default) and pod. It defines if DHCP/DNS requests have to be send to all dhcp servers in cloudstack, or only to the one in the same pod');