Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/src/com/cloud/vm/VirtualMachineProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static class Param {
public static final Param VmSshPubKey = new Param("VmSshPubKey");
public static final Param ControlNic = new Param("ControlNic");
public static final Param ReProgramGuestNetworks = new Param("RestartNetwork");
public static final Param RollingRestart = new Param("RollingRestart");
public static final Param PxeSeverType = new Param("PxeSeverType");
public static final Param HaTag = new Param("HaTag");
public static final Param HaOperation = new Param("HaOperation");
Expand Down Expand Up @@ -173,4 +174,6 @@ public boolean equals(Object obj) {

Float getMemoryOvercommitRatio();

boolean isRollingRestart();

}
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ public Float getMemoryOvercommitRatio() {
return memoryOvercommitRatio;
}

@Override
public boolean isRollingRestart() {
return Boolean.TRUE.equals(getParameter(VirtualMachineProfile.Param.RollingRestart));
}

@Override
public List<String[]> getVmData() {
return vmData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupVspCommand;
import com.cloud.agent.api.element.ApplyAclRuleVspCommand;
Expand Down Expand Up @@ -289,14 +290,41 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
VspDhcpDomainOption vspDhcpOptions = _nuageVspEntityBuilder.buildNetworkDhcpOption(network, offering);
HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(network.getPhysicalNetworkId());
ImplementVspCommand cmd = new ImplementVspCommand(vspNetwork, ingressFirewallRules, egressFirewallRules, floatingIpUuids, vspDhcpOptions);
send(cmd, network);

return true;
}

private void send(Command cmd, Network network)
throws ResourceUnavailableException {
send(cmd, network.getPhysicalNetworkId(), Network.class, network);
}

private void send(Command cmd, Vpc vpc)
throws ResourceUnavailableException {
send(cmd, getPhysicalNetworkId(vpc.getZoneId()), Vpc.class, vpc);
}


private <R extends InternalIdentity> void send(Command cmd, long physicalNetworkId, Class<R> resourceClass,
R resource)
throws ResourceUnavailableException {
HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(physicalNetworkId);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ImplementVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
throw new ResourceUnavailableException(answer.getDetails(), Network.class, network.getId());
if (isFailure(answer)) {
s_logger.error(cmd.getClass().getName() + " for " + resourceClass.getName() + " " + resource.getId() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if (hasFailureDetails(answer)) {
throw new ResourceUnavailableException(answer.getDetails(), resourceClass, resource.getId());
}
}
return true;
}

private boolean hasFailureDetails(Answer answer) {
return (null != answer) && (null != answer.getDetails());
}

private boolean isFailure(Answer answer) {
return answer == null || !answer.getResult();
}

private boolean applyACLRulesForVpc(Network network, NetworkOffering offering) throws ResourceUnavailableException {
Expand Down Expand Up @@ -358,15 +386,9 @@ public boolean shutdown(Network network, ReservationContext context, boolean cle
NetworkOfferingVO networkOfferingVO = _ntwkOfferingDao.findById(network.getNetworkOfferingId());
VspDhcpDomainOption vspDhcpOptions = _nuageVspEntityBuilder.buildNetworkDhcpOption(network, networkOfferingVO);
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network);
HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(network.getPhysicalNetworkId());

ShutDownVspCommand cmd = new ShutDownVspCommand(vspNetwork, vspDhcpOptions);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ShutDownVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
throw new ResourceUnavailableException(answer.getDetails(), Network.class, network.getId());
}
}
send(cmd, network);
}
return true;
}
Expand Down Expand Up @@ -501,14 +523,17 @@ public boolean removeDhcpSupportForSubnet(Network network) throws ResourceUnavai

@Override
public boolean setExtraDhcpOptions(Network network, long nicId, Map<Integer, String> dhcpOptions) {
if (network.isRollingRestart()) {
return true;
}

VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network);
HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(network.getPhysicalNetworkId());
NicVO nic = _nicDao.findById(nicId);

ExtraDhcpOptionsVspCommand extraDhcpOptionsVspCommand = new ExtraDhcpOptionsVspCommand(vspNetwork, nic.getUuid(), dhcpOptions);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), extraDhcpOptionsVspCommand);

if (answer == null || !answer.getResult()) {
if (isFailure(answer)) {
s_logger.error("[setExtraDhcpOptions] setting extra DHCP options for nic " + nic.getUuid() + " failed.");
return false;
}
Expand Down Expand Up @@ -539,15 +564,9 @@ public boolean applyStaticNats(Network config, List<? extends StaticNat> rules)
}

VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(config);
HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(config.getPhysicalNetworkId());
ApplyStaticNatVspCommand cmd = new ApplyStaticNatVspCommand(vspNetwork, vspStaticNatDetails);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ApplyStaticNatNuageVspCommand for network " + config.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
throw new ResourceUnavailableException(answer.getDetails(), Network.class, config.getId());
}
}
send(cmd,
config);

return true;
}
Expand Down Expand Up @@ -611,16 +630,10 @@ public VspAclRule apply(@Nullable InternalIdentity input) {
}
});

HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(network.getPhysicalNetworkId());
VspAclRule.ACLType vspAclType = isNetworkAcl ? VspAclRule.ACLType.NetworkACL : VspAclRule.ACLType.Firewall;
ApplyAclRuleVspCommand cmd = new ApplyAclRuleVspCommand(vspAclType, vspNetwork, vspAclRules, networkReset);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ApplyAclRuleNuageVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
throw new ResourceUnavailableException(answer.getDetails(), Network.class, network.getId());
}
}
send(cmd,
network);
return true;
}

Expand Down Expand Up @@ -686,7 +699,6 @@ public String apply(@Nullable DomainRouterVO input) {
});

Domain vpcDomain = _domainDao.findById(vpc.getDomainId());
HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(getPhysicalNetworkId(vpc.getZoneId()));

String preConfiguredDomainTemplateName;
VpcDetailVO domainTemplateNameDetail = _vpcDetailsDao.findDetail(vpc.getId(), NuageVspManager.nuageDomainTemplateDetailName);
Expand All @@ -710,14 +722,7 @@ public String apply(@Nullable DomainRouterVO input) {
}

ShutDownVpcVspCommand cmd = new ShutDownVpcVspCommand(vpcDomain.getUuid(), vpc.getUuid(), preConfiguredDomainTemplateName, domainRouterUuids, vpcDetails);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ShutDownVpcVspCommand for VPC " + vpc.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
throw new ResourceUnavailableException(answer.getDetails(), Vpc.class, vpc.getId());
}
return false;
}
send(cmd, vpc);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.dao.PhysicalNetworkVO;
import com.cloud.network.manager.NuageVspManager;
import com.cloud.network.router.VirtualRouter;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
Expand All @@ -94,13 +95,15 @@
import com.cloud.utils.db.DB;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.Ip;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.VMInstanceDao;

public class NuageVspGuestNetworkGuru extends GuestNetworkGuru implements NetworkGuruAdditionalFunctions {
Expand Down Expand Up @@ -134,6 +137,8 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru implements Networ
DataCenterDetailsDao _dcDetailsDao;
@Inject
VlanDetailsDao _vlanDetailsDao;
@Inject
private DomainRouterDao _routerDao;

public NuageVspGuestNetworkGuru() {
super();
Expand Down Expand Up @@ -528,29 +533,34 @@ public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, D
nic.setBroadcastUri(network.getBroadcastUri());
nic.setIsolationUri(network.getBroadcastUri());

//NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
//that we create in VSP
NicVO nicFromDb = _nicDao.findById(nic.getId());
IPAddressVO staticNatIp = _ipAddressDao.findByVmIdAndNetworkId(network.getId(), vm.getId());
VspVm vspVm = _nuageVspEntityBuilder.buildVspVm(vm.getVirtualMachine(), network);
VspNic vspNic = _nuageVspEntityBuilder.buildVspNic(nicFromDb.getUuid(), nic);
VspStaticNat vspStaticNat = null;
if (staticNatIp != null) {
VlanVO staticNatVlan = _vlanDao.findById(staticNatIp.getVlanId());
vspStaticNat = _nuageVspEntityBuilder.buildVspStaticNat(null, staticNatIp, staticNatVlan, vspNic);
}

boolean defaultHasDns = getDefaultHasDns(networkHasDnsCache, nicFromDb);
VspDhcpVMOption dhcpOption = _nuageVspEntityBuilder.buildVmDhcpOption(nicFromDb, defaultHasDns, networkHasDns);
ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand(vspNetwork, vspVm, vspNic, vspStaticNat, dhcpOption);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (vm.isRollingRestart()) {
((NetworkVO)network).setRollingRestart(true);
} else {
//NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
//that we create in VSP
NicVO nicFromDb = _nicDao.findById(nic.getId());
IPAddressVO staticNatIp = _ipAddressDao.findByVmIdAndNetworkId(network.getId(), vm.getId());
VspNic vspNic = _nuageVspEntityBuilder.buildVspNic(nicFromDb.getUuid(), nic);
VspStaticNat vspStaticNat = null;
if (staticNatIp != null) {
VlanVO staticNatVlan = _vlanDao.findById(staticNatIp.getVlanId());
vspStaticNat = _nuageVspEntityBuilder.buildVspStaticNat(null, staticNatIp, staticNatVlan, vspNic);
}

if (answer == null || !answer.getResult()) {
s_logger.error("ReserveVmInterfaceNuageVspCommand failed for NIC " + nic.getId() + " attached to VM " + vm.getId() + " in network " + network.getId());
if ((null != answer) && (null != answer.getDetails())) {
s_logger.error(answer.getDetails());
boolean defaultHasDns = getDefaultHasDns(networkHasDnsCache, nicFromDb);
VspDhcpVMOption dhcpOption = _nuageVspEntityBuilder.buildVmDhcpOption(nicFromDb, defaultHasDns, networkHasDns);
ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand(vspNetwork, vspVm, vspNic, vspStaticNat, dhcpOption);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);

if (answer == null || !answer.getResult()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use BooleanUtils here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null check is on answer, not on answer.getResult().

s_logger.error("ReserveVmInterfaceNuageVspCommand failed for NIC " + nic.getId() + " attached to VM " + vm.getId() + " in network " + network.getId());
if ((null != answer) && (null != answer.getDetails())) {
s_logger.error(answer.getDetails());
}
throw new InsufficientVirtualNetworkCapacityException("Failed to reserve VM in Nuage VSP.", Network.class, network.getId());
}
throw new InsufficientVirtualNetworkCapacityException("Failed to reserve VM in Nuage VSP.", Network.class, network.getId());
}

if (vspVm.getDomainRouter() == Boolean.TRUE) {
Expand Down Expand Up @@ -695,15 +705,18 @@ public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm
}

try {
final VirtualMachine virtualMachine = vm.getVirtualMachine();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Handling deallocate() call back, which is called when a VM is destroyed or interface is removed, " + "to delete VM Interface with IP "
+ nic.getIPv4Address() + " from a VM " + vm.getInstanceName() + " with state " + vm.getVirtualMachine().getState());
+ nic.getIPv4Address() + " from a VM " + vm.getInstanceName() + " with state " + virtualMachine
.getState());
}

NicVO nicFromDb = _nicDao.findById(nic.getId());

VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(vm.getVirtualMachine().getDomainId(), network);
VspVm vspVm = _nuageVspEntityBuilder.buildVspVm(vm.getVirtualMachine(), network);
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(virtualMachine
.getDomainId(), network);
VspVm vspVm = _nuageVspEntityBuilder.buildVspVm(virtualMachine, network);
VspNic vspNic = _nuageVspEntityBuilder.buildVspNic(nicFromDb.getUuid(), nic);
HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(network.getPhysicalNetworkId());

Expand All @@ -723,6 +736,32 @@ public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm
} else {
super.deallocate(network, nic, vm);
}

if (virtualMachine.getType() == VirtualMachine.Type.DomainRouter) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you extract this blob to a method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to go into creating methods for checking enum values?
I'm not in favor of creating that kind of method in this class,
so it should go either in VirtualMachine or in VirtualMachine.Type

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure @rafaelweingartner means the entire if block and not the enum check, @fmaximus

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spot on. I was referring to the IF body, and not to the IF condition. We really need shorter methods and more unit tests.

final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), VirtualRouter.Role.VIRTUAL_ROUTER);
final DomainRouterVO otherRouter = routers.stream()
.filter(r -> r.getId() != vm.getId())
.findFirst()
.orElse(null);

if (otherRouter != null) {
nicFromDb = _nicDao.findByNtwkIdAndInstanceId(network.getId(), otherRouter.getId());
vspVm = _nuageVspEntityBuilder.buildVspVm(otherRouter, network);
vspNic = _nuageVspEntityBuilder.buildVspNic(nicFromDb);

VspDhcpVMOption dhcpOption = _nuageVspEntityBuilder.buildVmDhcpOption(nicFromDb, false, false);
ReserveVmInterfaceVspCommand reserveCmd = new ReserveVmInterfaceVspCommand(vspNetwork, vspVm, vspNic, null, dhcpOption);

answer = _agentMgr.easySend(nuageVspHost.getId(), reserveCmd);
if (answer == null || !answer.getResult()) {
s_logger.error("DeallocateVmNuageVspCommand for VM " + vm.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
s_logger.error(answer.getDetails());
}
}
}

}
} finally {
if (network != null && lockedNetwork) {
_networkDao.releaseFromLockTable(network.getId());
Expand Down
Loading