mirror of https://github.com/apache/cloudstack.git
1) More logging during vm cleanup when the vm fails to start
2) Cleanup nic info in the DB during nicRelease
This commit is contained in:
parent
cfce5e023c
commit
a21ce17c09
|
|
@ -924,6 +924,19 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
vo.setState(Nic.State.Allocated);
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
|
||||
protected void applyProfileToNicForRelease(NicVO vo, NicProfile profile) {
|
||||
vo.setGateway(profile.getGateway());
|
||||
vo.setAddressFormat(profile.getFormat());
|
||||
vo.setIp4Address(profile.getIp4Address());
|
||||
vo.setIp6Address(profile.getIp6Address());
|
||||
vo.setMacAddress(profile.getMacAddress());
|
||||
vo.setReservationStrategy(profile.getReservationStrategy());
|
||||
vo.setBroadcastUri(profile.getBroadCastUri());
|
||||
vo.setIsolationUri(profile.getIsolationUri());
|
||||
vo.setNetmask(profile.getNetmask());
|
||||
}
|
||||
|
||||
protected NicTO toNicTO(NicVO nic, NicProfile profile, NetworkVO config) {
|
||||
NicTO to = new NicTO();
|
||||
|
|
@ -1100,6 +1113,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
_nicDao.update(nic.getId(), nic);
|
||||
NicProfile profile = new NicProfile(nic, network, null, null, null);
|
||||
if (concierge.release(profile, vmProfile, nic.getReservationId())) {
|
||||
applyProfileToNicForRelease(nic, profile);
|
||||
nic.setState(Nic.State.Allocated);
|
||||
if (originalState == Nic.State.Reserved) {
|
||||
updateNic(nic, network.getId(), -1);
|
||||
|
|
|
|||
|
|
@ -143,11 +143,8 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
|
|||
}
|
||||
|
||||
_dcDao.releaseLinkLocalIpAddress(nic.getId(), reservationId);
|
||||
nic.setIp4Address(null);
|
||||
nic.setMacAddress(null);
|
||||
nic.setNetmask(null);
|
||||
nic.setFormat(null);
|
||||
nic.setGateway(null);
|
||||
|
||||
nic.deallocate();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,6 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
nic.setBroadcastType(BroadcastDomainType.Native);
|
||||
nic.setBroadcastUri(null);
|
||||
nic.setIsolationUri(null);
|
||||
nic.setFormat(AddressFormat.Ip4);
|
||||
|
||||
s_logger.debug("Allocated a nic " + nic + " for " + vm);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,6 @@ import com.cloud.network.ovs.OvsTunnelManager;
|
|||
import com.cloud.network.router.VirtualRouter.Role;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.rules.PortForwardingRule;
|
||||
import com.cloud.network.rules.PortForwardingRuleVO;
|
||||
import com.cloud.network.rules.RulesManager;
|
||||
import com.cloud.network.rules.dao.PortForwardingRulesDao;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
|
|
@ -651,106 +650,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
return VirtualMachineName.getRouterId(vmName);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public HostVO prepareForMigration(final DomainRouterVO router) throws StorageUnavailableException {
|
||||
// final long routerId = router.getId();
|
||||
// final boolean mirroredVols = router.isMirroredVols();
|
||||
// final DataCenterVO dc = _dcDao.findById(router.getDataCenterId());
|
||||
// final HostPodVO pod = _podDao.findById(router.getPodId());
|
||||
// final ServiceOfferingVO offering = _serviceOfferingDao.findById(router.getServiceOfferingId());
|
||||
// StoragePoolVO sp = _storageMgr.getStoragePoolForVm(router.getId());
|
||||
//
|
||||
// final List<VolumeVO> vols = _volsDao.findCreatedByInstance(routerId);
|
||||
//
|
||||
// final String[] storageIps = new String[2];
|
||||
// final VolumeVO vol = vols.get(0);
|
||||
// storageIps[0] = vol.getHostIp();
|
||||
// if (mirroredVols && (vols.size() == 2)) {
|
||||
// storageIps[1] = vols.get(1).getHostIp();
|
||||
// }
|
||||
//
|
||||
// final PrepareForMigrationCommand cmd = new PrepareForMigrationCommand(router.getInstanceName(), router.getVnet(), storageIps, vols,
|
||||
// mirroredVols);
|
||||
//
|
||||
// HostVO routingHost = null;
|
||||
// final HashSet<Host> avoid = new HashSet<Host>();
|
||||
//
|
||||
// final HostVO fromHost = _hostDao.findById(router.getHostId());
|
||||
// if (fromHost.getHypervisorType() != HypervisorType.KVM && fromHost.getClusterId() == null) {
|
||||
// s_logger.debug("The host is not in a cluster");
|
||||
// return null;
|
||||
// }
|
||||
// avoid.add(fromHost);
|
||||
//
|
||||
// while ((routingHost = (HostVO) _agentMgr.findHost(Host.Type.Routing, dc, pod, sp, offering, _template, router, fromHost, avoid)) != null) {
|
||||
// avoid.add(routingHost);
|
||||
// if (s_logger.isDebugEnabled()) {
|
||||
// s_logger.debug("Trying to migrate router to host " + routingHost.getName());
|
||||
// }
|
||||
//
|
||||
// if (!_storageMgr.share(router, vols, routingHost, false)) {
|
||||
// s_logger.warn("Can not share " + vol.getPath() + " to " + router.getName());
|
||||
// throw new StorageUnavailableException("Can not share " + vol.getPath() + " to " + router.getName(), sp.getId());
|
||||
// }
|
||||
//
|
||||
// final Answer answer = _agentMgr.easySend(routingHost.getId(), cmd);
|
||||
// if (answer != null && answer.getResult()) {
|
||||
// return routingHost;
|
||||
// }
|
||||
//
|
||||
// _storageMgr.unshare(router, vols, routingHost);
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean migrate(final DomainRouterVO router, final HostVO host) {
|
||||
// final HostVO fromHost = _hostDao.findById(router.getHostId());
|
||||
//
|
||||
// if (!_itMgr.stateTransitTo(router, VirtualMachine.Event.MigrationRequested, router.getHostId())) {
|
||||
// s_logger.debug("State for " + router.toString() + " has changed so migration can not take place.");
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// final MigrateCommand cmd = new MigrateCommand(router.getInstanceName(), host.getPrivateIpAddress(), false);
|
||||
// final Answer answer = _agentMgr.easySend(fromHost.getId(), cmd);
|
||||
// if (answer == null) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// final List<VolumeVO> vols = _volsDao.findCreatedByInstance(router.getId());
|
||||
// if (vols.size() == 0) {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// _storageMgr.unshare(router, vols, fromHost);
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean completeMigration(final DomainRouterVO router, final HostVO host) throws OperationTimedoutException, AgentUnavailableException {
|
||||
// final CheckVirtualMachineCommand cvm = new CheckVirtualMachineCommand(router.getInstanceName());
|
||||
// final CheckVirtualMachineAnswer answer = (CheckVirtualMachineAnswer) _agentMgr.send(host.getId(), cvm);
|
||||
// if (answer == null || !answer.getResult()) {
|
||||
// s_logger.debug("Unable to complete migration for " + router.getId());
|
||||
// _itMgr.stateTransitTo(router, VirtualMachine.Event.AgentReportStopped, null);
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// final State state = answer.getState();
|
||||
// if (state == State.Stopped) {
|
||||
// s_logger.warn("Unable to complete migration as we can not detect it on " + host.getId());
|
||||
// _itMgr.stateTransitTo(router, VirtualMachine.Event.AgentReportStopped, null);
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// _itMgr.stateTransitTo(router, VirtualMachine.Event.OperationSucceeded, host.getId());
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
|
||||
protected class RouterCleanupTask implements Runnable {
|
||||
|
||||
public RouterCleanupTask() {
|
||||
|
|
|
|||
|
|
@ -724,49 +724,57 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, StateLi
|
|||
protected <T extends VMInstanceVO> boolean cleanup(VirtualMachineGuru<T> guru, VirtualMachineProfile<T> profile, ItWorkVO work, boolean force, User user, Account account) {
|
||||
T vm = profile.getVirtualMachine();
|
||||
State state = vm.getState();
|
||||
s_logger.debug("Cleaning up resources for the vm " + vm + " in " + state + " state");
|
||||
if (state == State.Starting) {
|
||||
Step step = work.getStep();
|
||||
if (step == Step.Start && !force) {
|
||||
s_logger.warn("Unable to cleanup vm " + vm + "; work state is incorrect: " + step);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (step == Step.Started || step == Step.Start) {
|
||||
if (vm.getHostId() != null) {
|
||||
if (!sendStop(guru, profile, force)) {
|
||||
s_logger.warn("Failed to stop vm " + vm + " in " + State.Starting + " state as a part of cleanup process");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (step != Step.Release && step != Step.Prepare && step != Step.Started && step != Step.Start) {
|
||||
s_logger.debug("Cleanup is not needed for vm " + vm + "; work state is incorrect: " + step);
|
||||
return true;
|
||||
}
|
||||
} else if (state == State.Stopping) {
|
||||
if (vm.getHostId() != null) {
|
||||
if (!sendStop(guru, profile, force)) {
|
||||
s_logger.warn("Failed to stop vm " + vm + " in " + State.Stopping + " state as a part of cleanup process");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (state == State.Migrating) {
|
||||
if (vm.getHostId() != null) {
|
||||
if (!sendStop(guru, profile, force)) {
|
||||
s_logger.warn("Failed to stop vm " + vm + " in " + State.Migrating + " state as a part of cleanup process");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (vm.getLastHostId() != null) {
|
||||
if (!sendStop(guru, profile, force)) {
|
||||
s_logger.warn("Failed to stop vm " + vm + " in " + State.Migrating + " state as a part of cleanup process");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (state == State.Running) {
|
||||
if (!sendStop(guru, profile, force)) {
|
||||
s_logger.warn("Failed to stop vm " + vm + " in " + State.Running + " state as a part of cleanup process");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
_networkMgr.release(profile, force);
|
||||
_storageMgr.release(profile);
|
||||
s_logger.debug("Successfully cleanued up resources for the vm " + vm + " in " + state + " state");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue