use of com.cloud.exception.OperationTimedoutException in project cloudstack by apache.
the class VirtualMachineManagerImpl method orchestrateReboot.
private void orchestrateReboot(final String vmUuid, final Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
if (_vmSnapshotMgr.hasActiveVMSnapshotTasks(vm.getId())) {
s_logger.error("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks");
throw new CloudRuntimeException("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks");
}
final DataCenter dc = _entityMgr.findById(DataCenter.class, vm.getDataCenterId());
final Host host = _hostDao.findById(vm.getHostId());
if (host == null) {
throw new CloudRuntimeException("Unable to retrieve host with id " + vm.getHostId());
}
final Cluster cluster = _entityMgr.findById(Cluster.class, host.getClusterId());
final Pod pod = _entityMgr.findById(Pod.class, host.getPodId());
final DeployDestination dest = new DeployDestination(dc, pod, cluster, host);
try {
final Commands cmds = new Commands(Command.OnError.Stop);
RebootCommand rebootCmd = new RebootCommand(vm.getInstanceName(), getExecuteInSequence(vm.getHypervisorType()));
VirtualMachineTO vmTo = getVmTO(vm.getId());
checkAndSetEnterSetupMode(vmTo, params);
rebootCmd.setVirtualMachine(vmTo);
cmds.addCommand(rebootCmd);
_agentMgr.send(host.getId(), cmds);
final Answer rebootAnswer = cmds.getAnswer(RebootAnswer.class);
if (rebootAnswer != null && rebootAnswer.getResult()) {
boolean isVmSecurityGroupEnabled = _securityGroupManager.isVmSecurityGroupEnabled(vm.getId());
if (isVmSecurityGroupEnabled && vm.getType() == VirtualMachine.Type.User) {
List<Long> affectedVms = new ArrayList<>();
affectedVms.add(vm.getId());
_securityGroupManager.scheduleRulesetUpdateToHosts(affectedVms, true, null);
}
return;
}
String errorMsg = "Unable to reboot VM " + vm + " on " + dest.getHost() + " due to " + (rebootAnswer == null ? "no reboot response" : rebootAnswer.getDetails());
s_logger.info(errorMsg);
throw new CloudRuntimeException(errorMsg);
} catch (final OperationTimedoutException e) {
s_logger.warn("Unable to send the reboot command to host " + dest.getHost() + " for the vm " + vm + " due to operation timeout", e);
throw new CloudRuntimeException("Failed to reboot the vm on host " + dest.getHost(), e);
}
}
use of com.cloud.exception.OperationTimedoutException in project cloudstack by apache.
the class VirtualMachineManagerImpl method unplugNic.
public boolean unplugNic(final Network network, final NicTO nic, final VirtualMachineTO vm, final ReservationContext context, final DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException {
boolean result = true;
final VMInstanceVO router = _vmDao.findById(vm.getId());
if (router.getState() == State.Running) {
UserVmVO userVm = _userVmDao.findById(vm.getId());
if (userVm != null && userVm.getType() == VirtualMachine.Type.User) {
_userVmService.collectVmNetworkStatistics(userVm);
}
try {
final Commands cmds = new Commands(Command.OnError.Stop);
final UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(nic, vm.getName());
Map<String, Boolean> vlanToPersistenceMap = getVlanToPersistenceMapForVM(vm.getId());
if (MapUtils.isNotEmpty(vlanToPersistenceMap)) {
unplugNicCmd.setVlanToPersistenceMap(vlanToPersistenceMap);
}
cmds.addCommand("unplugnic", unplugNicCmd);
_agentMgr.send(dest.getHost().getId(), cmds);
final UnPlugNicAnswer unplugNicAnswer = cmds.getAnswer(UnPlugNicAnswer.class);
if (unplugNicAnswer == null || !unplugNicAnswer.getResult()) {
s_logger.warn("Unable to unplug nic from router " + router);
result = false;
}
} catch (final OperationTimedoutException e) {
throw new AgentUnavailableException("Unable to unplug nic from rotuer " + router + " from network " + network, dest.getHost().getId(), e);
}
} else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
s_logger.debug("Vm " + router.getInstanceName() + " is in " + router.getState() + ", so not sending unplug nic command to the backend");
} else {
String message = String.format("Unable to apply unplug nic, VM [%s] is not in the right state (\"Running\"). VM state [%s].", router.toString(), router.getState());
s_logger.warn(message);
throw new ResourceUnavailableException(message, DataCenter.class, router.getDataCenterId());
}
return result;
}
use of com.cloud.exception.OperationTimedoutException in project cloudstack by apache.
the class NetworkOrchestrator method setupPersistentNetwork.
private void setupPersistentNetwork(NetworkVO network, NetworkOfferingVO offering, Long dcId) throws AgentUnavailableException, OperationTimedoutException {
List<ClusterVO> clusterVOs = clusterDao.listClustersByDcId(dcId);
List<HostVO> hosts = resourceManager.listAllUpAndEnabledHostsInOneZoneByType(Host.Type.Routing, dcId);
Map<Long, List<Long>> clusterToHostsMap = new HashMap<>();
for (HostVO host : hosts) {
try {
Pair<Boolean, NicTO> networkCfgStateAndDetails = isNtwConfiguredInCluster(host, clusterToHostsMap, network, offering);
if (networkCfgStateAndDetails.first()) {
continue;
}
NicTO to = networkCfgStateAndDetails.second();
SetupPersistentNetworkCommand cmd = new SetupPersistentNetworkCommand(to);
final SetupPersistentNetworkAnswer answer = (SetupPersistentNetworkAnswer) _agentMgr.send(host.getId(), cmd);
if (answer == null) {
s_logger.warn("Unable to get an answer to the SetupPersistentNetworkCommand from agent:" + host.getId());
clusterToHostsMap.get(host.getClusterId()).remove(host.getId());
continue;
}
if (!answer.getResult()) {
s_logger.warn("Unable to setup agent " + host.getId() + " due to " + answer.getDetails());
clusterToHostsMap.get(host.getClusterId()).remove(host.getId());
}
} catch (Exception e) {
s_logger.warn("Failed to connect to host: " + host.getName());
}
}
if (clusterToHostsMap.keySet().size() != clusterVOs.size()) {
s_logger.warn("Hosts on all clusters may not have been configured with network devices.");
}
}
use of com.cloud.exception.OperationTimedoutException in project cloudstack by apache.
the class NetworkOrchestrator method implementNetwork.
@Override
@DB
public Pair<NetworkGuru, NetworkVO> implementNetwork(final long networkId, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
final Pair<NetworkGuru, NetworkVO> implemented = new Pair<NetworkGuru, NetworkVO>(null, null);
NetworkVO network = _networksDao.findById(networkId);
final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
if (isNetworkImplemented(network)) {
s_logger.debug("Network id=" + networkId + " is already implemented");
implemented.set(guru, network);
return implemented;
}
// Acquire lock only when network needs to be implemented
network = _networksDao.acquireInLockTable(networkId, NetworkLockTimeout.value());
if (network == null) {
// see NetworkVO.java
final ConcurrentOperationException ex = new ConcurrentOperationException("Unable to acquire network configuration");
ex.addProxyObject(_entityMgr.findById(Network.class, networkId).getUuid());
throw ex;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Lock is acquired for network id " + networkId + " as a part of network implement");
}
try {
if (isNetworkImplemented(network)) {
s_logger.debug("Network id=" + networkId + " is already implemented");
implemented.set(guru, network);
return implemented;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Asking " + guru.getName() + " to implement " + network);
}
final NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
network.setReservationId(context.getReservationId());
if (isSharedNetworkWithServices(network)) {
network.setState(Network.State.Implementing);
} else {
stateTransitTo(network, Event.ImplementNetwork);
}
final Network result = guru.implement(network, offering, dest, context);
network.setCidr(result.getCidr());
network.setBroadcastUri(result.getBroadcastUri());
network.setGateway(result.getGateway());
network.setMode(result.getMode());
network.setPhysicalNetworkId(result.getPhysicalNetworkId());
_networksDao.update(networkId, network);
// implement network elements and re-apply all the network rules
implementNetworkElementsAndResources(dest, context, network, offering);
long dcId = dest.getDataCenter().getId();
if (networkMeetsPersistenceCriteria(network, offering, false)) {
setupPersistentNetwork(network, offering, dcId);
}
if (isSharedNetworkWithServices(network)) {
network.setState(Network.State.Implemented);
} else {
stateTransitTo(network, Event.OperationSucceeded);
}
network.setRestartRequired(false);
_networksDao.update(network.getId(), network);
implemented.set(guru, network);
return implemented;
} catch (final NoTransitionException e) {
s_logger.error(e.getMessage());
return new Pair<NetworkGuru, NetworkVO>(null, null);
} catch (final CloudRuntimeException | OperationTimedoutException e) {
s_logger.error("Caught exception: " + e.getMessage());
return new Pair<NetworkGuru, NetworkVO>(null, null);
} finally {
if (implemented.first() == null) {
s_logger.debug("Cleaning up because we're unable to implement the network " + network);
try {
if (isSharedNetworkWithServices(network)) {
network.setState(Network.State.Shutdown);
_networksDao.update(networkId, network);
} else {
stateTransitTo(network, Event.OperationFailed);
}
} catch (final NoTransitionException e) {
s_logger.error(e.getMessage());
}
try {
shutdownNetwork(networkId, context, false);
} catch (final Exception e) {
// Don't throw this exception as it would hide the original thrown exception, just log
s_logger.error("Exception caught while shutting down a network as part of a failed implementation", e);
}
}
_networksDao.releaseFromLockTable(networkId);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Lock is released for network id " + networkId + " as a part of network implement");
}
}
}
use of com.cloud.exception.OperationTimedoutException in project cloudstack by apache.
the class LibvirtServerDiscoverer method deleteHost.
@Override
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException {
if (host.getType() != Host.Type.Routing || (host.getHypervisorType() != HypervisorType.KVM && host.getHypervisorType() != HypervisorType.LXC)) {
return null;
}
_resourceMgr.deleteRoutingHost(host, isForced, isForceDeleteStorage);
try {
ShutdownCommand cmd = new ShutdownCommand(ShutdownCommand.DeleteHost, null, !ADD_HOST_ON_SERVICE_RESTART_KVM.value());
agentMgr.send(host.getId(), cmd);
} catch (AgentUnavailableException e) {
s_logger.warn("Sending ShutdownCommand failed: ", e);
} catch (OperationTimedoutException e) {
s_logger.warn("Sending ShutdownCommand failed: ", e);
}
return new DeleteHostAnswer(true);
}
Aggregations