Skip to content

Commit a21ce17

Browse files
committed
1) More logging during vm cleanup when the vm fails to start
2) Cleanup nic info in the DB during nicRelease
1 parent cfce5e0 commit a21ce17

5 files changed

Lines changed: 25 additions & 108 deletions

File tree

server/src/com/cloud/network/NetworkManagerImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,19 @@ protected Integer applyProfileToNic(NicVO vo, NicProfile profile, Integer device
924924
vo.setState(Nic.State.Allocated);
925925
return deviceId;
926926
}
927+
928+
929+
protected void applyProfileToNicForRelease(NicVO vo, NicProfile profile) {
930+
vo.setGateway(profile.getGateway());
931+
vo.setAddressFormat(profile.getFormat());
932+
vo.setIp4Address(profile.getIp4Address());
933+
vo.setIp6Address(profile.getIp6Address());
934+
vo.setMacAddress(profile.getMacAddress());
935+
vo.setReservationStrategy(profile.getReservationStrategy());
936+
vo.setBroadcastUri(profile.getBroadCastUri());
937+
vo.setIsolationUri(profile.getIsolationUri());
938+
vo.setNetmask(profile.getNetmask());
939+
}
927940

928941
protected NicTO toNicTO(NicVO nic, NicProfile profile, NetworkVO config) {
929942
NicTO to = new NicTO();
@@ -1100,6 +1113,7 @@ public void release(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, boo
11001113
_nicDao.update(nic.getId(), nic);
11011114
NicProfile profile = new NicProfile(nic, network, null, null, null);
11021115
if (concierge.release(profile, vmProfile, nic.getReservationId())) {
1116+
applyProfileToNicForRelease(nic, profile);
11031117
nic.setState(Nic.State.Allocated);
11041118
if (originalState == Nic.State.Reserved) {
11051119
updateNic(nic, network.getId(), -1);

server/src/com/cloud/network/guru/ControlNetworkGuru.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,8 @@ public boolean release(NicProfile nic, VirtualMachineProfile<? extends VirtualMa
143143
}
144144

145145
_dcDao.releaseLinkLocalIpAddress(nic.getId(), reservationId);
146-
nic.setIp4Address(null);
147-
nic.setMacAddress(null);
148-
nic.setNetmask(null);
149-
nic.setFormat(null);
150-
nic.setGateway(null);
146+
147+
nic.deallocate();
151148

152149
return true;
153150
}

server/src/com/cloud/network/guru/PodBasedNetworkGuru.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ public void reserve(NicProfile nic, Network config, VirtualMachineProfile<? exte
9696
nic.setBroadcastType(BroadcastDomainType.Native);
9797
nic.setBroadcastUri(null);
9898
nic.setIsolationUri(null);
99-
nic.setFormat(AddressFormat.Ip4);
10099

101100
s_logger.debug("Allocated a nic " + nic + " for " + vm);
102101
}

server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@
119119
import com.cloud.network.router.VirtualRouter.Role;
120120
import com.cloud.network.rules.FirewallRule;
121121
import com.cloud.network.rules.PortForwardingRule;
122-
import com.cloud.network.rules.PortForwardingRuleVO;
123122
import com.cloud.network.rules.RulesManager;
124123
import com.cloud.network.rules.dao.PortForwardingRulesDao;
125124
import com.cloud.offering.NetworkOffering;
@@ -651,106 +650,6 @@ public Long convertToId(final String vmName) {
651650
return VirtualMachineName.getRouterId(vmName);
652651
}
653652

654-
// @Override
655-
// public HostVO prepareForMigration(final DomainRouterVO router) throws StorageUnavailableException {
656-
// final long routerId = router.getId();
657-
// final boolean mirroredVols = router.isMirroredVols();
658-
// final DataCenterVO dc = _dcDao.findById(router.getDataCenterId());
659-
// final HostPodVO pod = _podDao.findById(router.getPodId());
660-
// final ServiceOfferingVO offering = _serviceOfferingDao.findById(router.getServiceOfferingId());
661-
// StoragePoolVO sp = _storageMgr.getStoragePoolForVm(router.getId());
662-
//
663-
// final List<VolumeVO> vols = _volsDao.findCreatedByInstance(routerId);
664-
//
665-
// final String[] storageIps = new String[2];
666-
// final VolumeVO vol = vols.get(0);
667-
// storageIps[0] = vol.getHostIp();
668-
// if (mirroredVols && (vols.size() == 2)) {
669-
// storageIps[1] = vols.get(1).getHostIp();
670-
// }
671-
//
672-
// final PrepareForMigrationCommand cmd = new PrepareForMigrationCommand(router.getInstanceName(), router.getVnet(), storageIps, vols,
673-
// mirroredVols);
674-
//
675-
// HostVO routingHost = null;
676-
// final HashSet<Host> avoid = new HashSet<Host>();
677-
//
678-
// final HostVO fromHost = _hostDao.findById(router.getHostId());
679-
// if (fromHost.getHypervisorType() != HypervisorType.KVM && fromHost.getClusterId() == null) {
680-
// s_logger.debug("The host is not in a cluster");
681-
// return null;
682-
// }
683-
// avoid.add(fromHost);
684-
//
685-
// while ((routingHost = (HostVO) _agentMgr.findHost(Host.Type.Routing, dc, pod, sp, offering, _template, router, fromHost, avoid)) != null) {
686-
// avoid.add(routingHost);
687-
// if (s_logger.isDebugEnabled()) {
688-
// s_logger.debug("Trying to migrate router to host " + routingHost.getName());
689-
// }
690-
//
691-
// if (!_storageMgr.share(router, vols, routingHost, false)) {
692-
// s_logger.warn("Can not share " + vol.getPath() + " to " + router.getName());
693-
// throw new StorageUnavailableException("Can not share " + vol.getPath() + " to " + router.getName(), sp.getId());
694-
// }
695-
//
696-
// final Answer answer = _agentMgr.easySend(routingHost.getId(), cmd);
697-
// if (answer != null && answer.getResult()) {
698-
// return routingHost;
699-
// }
700-
//
701-
// _storageMgr.unshare(router, vols, routingHost);
702-
// }
703-
//
704-
// return null;
705-
// }
706-
//
707-
// @Override
708-
// public boolean migrate(final DomainRouterVO router, final HostVO host) {
709-
// final HostVO fromHost = _hostDao.findById(router.getHostId());
710-
//
711-
// if (!_itMgr.stateTransitTo(router, VirtualMachine.Event.MigrationRequested, router.getHostId())) {
712-
// s_logger.debug("State for " + router.toString() + " has changed so migration can not take place.");
713-
// return false;
714-
// }
715-
//
716-
// final MigrateCommand cmd = new MigrateCommand(router.getInstanceName(), host.getPrivateIpAddress(), false);
717-
// final Answer answer = _agentMgr.easySend(fromHost.getId(), cmd);
718-
// if (answer == null) {
719-
// return false;
720-
// }
721-
//
722-
// final List<VolumeVO> vols = _volsDao.findCreatedByInstance(router.getId());
723-
// if (vols.size() == 0) {
724-
// return true;
725-
// }
726-
//
727-
// _storageMgr.unshare(router, vols, fromHost);
728-
//
729-
// return true;
730-
// }
731-
//
732-
// @Override
733-
// public boolean completeMigration(final DomainRouterVO router, final HostVO host) throws OperationTimedoutException, AgentUnavailableException {
734-
// final CheckVirtualMachineCommand cvm = new CheckVirtualMachineCommand(router.getInstanceName());
735-
// final CheckVirtualMachineAnswer answer = (CheckVirtualMachineAnswer) _agentMgr.send(host.getId(), cvm);
736-
// if (answer == null || !answer.getResult()) {
737-
// s_logger.debug("Unable to complete migration for " + router.getId());
738-
// _itMgr.stateTransitTo(router, VirtualMachine.Event.AgentReportStopped, null);
739-
// return false;
740-
// }
741-
//
742-
// final State state = answer.getState();
743-
// if (state == State.Stopped) {
744-
// s_logger.warn("Unable to complete migration as we can not detect it on " + host.getId());
745-
// _itMgr.stateTransitTo(router, VirtualMachine.Event.AgentReportStopped, null);
746-
// return false;
747-
// }
748-
//
749-
// _itMgr.stateTransitTo(router, VirtualMachine.Event.OperationSucceeded, host.getId());
750-
//
751-
// return true;
752-
// }
753-
754653
protected class RouterCleanupTask implements Runnable {
755654

756655
public RouterCleanupTask() {

server/src/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,49 +724,57 @@ protected <T extends VMInstanceVO> boolean sendStop(VirtualMachineGuru<T> guru,
724724
protected <T extends VMInstanceVO> boolean cleanup(VirtualMachineGuru<T> guru, VirtualMachineProfile<T> profile, ItWorkVO work, boolean force, User user, Account account) {
725725
T vm = profile.getVirtualMachine();
726726
State state = vm.getState();
727+
s_logger.debug("Cleaning up resources for the vm " + vm + " in " + state + " state");
727728
if (state == State.Starting) {
728729
Step step = work.getStep();
729730
if (step == Step.Start && !force) {
731+
s_logger.warn("Unable to cleanup vm " + vm + "; work state is incorrect: " + step);
730732
return false;
731733
}
732734

733-
734735
if (step == Step.Started || step == Step.Start) {
735736
if (vm.getHostId() != null) {
736737
if (!sendStop(guru, profile, force)) {
738+
s_logger.warn("Failed to stop vm " + vm + " in " + State.Starting + " state as a part of cleanup process");
737739
return false;
738740
}
739741
}
740742
}
741743

742744
if (step != Step.Release && step != Step.Prepare && step != Step.Started && step != Step.Start) {
745+
s_logger.debug("Cleanup is not needed for vm " + vm + "; work state is incorrect: " + step);
743746
return true;
744747
}
745748
} else if (state == State.Stopping) {
746749
if (vm.getHostId() != null) {
747750
if (!sendStop(guru, profile, force)) {
751+
s_logger.warn("Failed to stop vm " + vm + " in " + State.Stopping + " state as a part of cleanup process");
748752
return false;
749753
}
750754
}
751755
} else if (state == State.Migrating) {
752756
if (vm.getHostId() != null) {
753757
if (!sendStop(guru, profile, force)) {
758+
s_logger.warn("Failed to stop vm " + vm + " in " + State.Migrating + " state as a part of cleanup process");
754759
return false;
755760
}
756761
}
757762
if (vm.getLastHostId() != null) {
758763
if (!sendStop(guru, profile, force)) {
764+
s_logger.warn("Failed to stop vm " + vm + " in " + State.Migrating + " state as a part of cleanup process");
759765
return false;
760766
}
761767
}
762768
} else if (state == State.Running) {
763769
if (!sendStop(guru, profile, force)) {
770+
s_logger.warn("Failed to stop vm " + vm + " in " + State.Running + " state as a part of cleanup process");
764771
return false;
765772
}
766773
}
767774

768775
_networkMgr.release(profile, force);
769776
_storageMgr.release(profile);
777+
s_logger.debug("Successfully cleanued up resources for the vm " + vm + " in " + state + " state");
770778
return true;
771779
}
772780

0 commit comments

Comments
 (0)