mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	Import Remote KVM VM logging improvements (#9284)
This commit is contained in:
		
							parent
							
								
									6a518e29b7
								
							
						
					
					
						commit
						c17aa0d9ad
					
				| @ -203,8 +203,8 @@ public class ImportUnmanagedInstanceCmd extends BaseAsyncCmd { | |||||||
|             for (Map<String, String> entry : (Collection<Map<String, String>>)nicNetworkList.values()) { |             for (Map<String, String> entry : (Collection<Map<String, String>>)nicNetworkList.values()) { | ||||||
|                 String nic = entry.get(VmDetailConstants.NIC); |                 String nic = entry.get(VmDetailConstants.NIC); | ||||||
|                 String networkUuid = entry.get(VmDetailConstants.NETWORK); |                 String networkUuid = entry.get(VmDetailConstants.NETWORK); | ||||||
|                 if (LOGGER.isTraceEnabled()) { |                 if (LOGGER.isDebugEnabled()) { | ||||||
|                     LOGGER.trace(String.format("nic, '%s', goes on net, '%s'", nic, networkUuid)); |                     LOGGER.debug(String.format("nic, '%s', goes on net, '%s'", nic, networkUuid)); | ||||||
|                 } |                 } | ||||||
|                 if (StringUtils.isAnyEmpty(nic, networkUuid) || _entityMgr.findByUuid(Network.class, networkUuid) == null) { |                 if (StringUtils.isAnyEmpty(nic, networkUuid) || _entityMgr.findByUuid(Network.class, networkUuid) == null) { | ||||||
|                     throw new InvalidParameterValueException(String.format("Network ID: %s for NIC ID: %s is invalid", networkUuid, nic)); |                     throw new InvalidParameterValueException(String.format("Network ID: %s for NIC ID: %s is invalid", networkUuid, nic)); | ||||||
| @ -221,8 +221,8 @@ public class ImportUnmanagedInstanceCmd extends BaseAsyncCmd { | |||||||
|             for (Map<String, String> entry : (Collection<Map<String, String>>)nicIpAddressList.values()) { |             for (Map<String, String> entry : (Collection<Map<String, String>>)nicIpAddressList.values()) { | ||||||
|                 String nic = entry.get(VmDetailConstants.NIC); |                 String nic = entry.get(VmDetailConstants.NIC); | ||||||
|                 String ipAddress = StringUtils.defaultIfEmpty(entry.get(VmDetailConstants.IP4_ADDRESS), null); |                 String ipAddress = StringUtils.defaultIfEmpty(entry.get(VmDetailConstants.IP4_ADDRESS), null); | ||||||
|                 if (LOGGER.isTraceEnabled()) { |                 if (LOGGER.isDebugEnabled()) { | ||||||
|                     LOGGER.trace(String.format("nic, '%s', gets ip, '%s'", nic, ipAddress)); |                     LOGGER.debug(String.format("nic, '%s', gets ip, '%s'", nic, ipAddress)); | ||||||
|                 } |                 } | ||||||
|                 if (StringUtils.isEmpty(nic)) { |                 if (StringUtils.isEmpty(nic)) { | ||||||
|                     throw new InvalidParameterValueException(String.format("NIC ID: '%s' is invalid for IP address mapping", nic)); |                     throw new InvalidParameterValueException(String.format("NIC ID: '%s' is invalid for IP address mapping", nic)); | ||||||
|  | |||||||
| @ -17,7 +17,6 @@ | |||||||
| 
 | 
 | ||||||
| package com.cloud.agent.api; | package com.cloud.agent.api; | ||||||
| 
 | 
 | ||||||
| @LogLevel(LogLevel.Log4jLevel.Trace) |  | ||||||
| public class CheckVolumeAnswer extends Answer { | public class CheckVolumeAnswer extends Answer { | ||||||
| 
 | 
 | ||||||
|     private long size; |     private long size; | ||||||
|  | |||||||
| @ -21,7 +21,6 @@ package com.cloud.agent.api; | |||||||
| 
 | 
 | ||||||
| import com.cloud.agent.api.to.StorageFilerTO; | import com.cloud.agent.api.to.StorageFilerTO; | ||||||
| 
 | 
 | ||||||
| @LogLevel(LogLevel.Log4jLevel.Trace) |  | ||||||
| public class CheckVolumeCommand extends Command { | public class CheckVolumeCommand extends Command { | ||||||
| 
 | 
 | ||||||
|     String srcFile; |     String srcFile; | ||||||
|  | |||||||
| @ -17,7 +17,6 @@ | |||||||
| 
 | 
 | ||||||
| package com.cloud.agent.api; | package com.cloud.agent.api; | ||||||
| 
 | 
 | ||||||
| @LogLevel(LogLevel.Log4jLevel.Trace) |  | ||||||
| public class CopyRemoteVolumeAnswer extends Answer { | public class CopyRemoteVolumeAnswer extends Answer { | ||||||
| 
 | 
 | ||||||
|     private String remoteIp; |     private String remoteIp; | ||||||
|  | |||||||
| @ -21,10 +21,10 @@ package com.cloud.agent.api; | |||||||
| 
 | 
 | ||||||
| import com.cloud.agent.api.to.StorageFilerTO; | import com.cloud.agent.api.to.StorageFilerTO; | ||||||
| 
 | 
 | ||||||
| @LogLevel(LogLevel.Log4jLevel.Trace) |  | ||||||
| public class CopyRemoteVolumeCommand extends Command { | public class CopyRemoteVolumeCommand extends Command { | ||||||
|     String remoteIp; |     String remoteIp; | ||||||
|     String username; |     String username; | ||||||
|  |     @LogLevel(LogLevel.Log4jLevel.Off) | ||||||
|     String password; |     String password; | ||||||
|     String srcFile; |     String srcFile; | ||||||
|     String tmpPath; |     String tmpPath; | ||||||
|  | |||||||
| @ -22,10 +22,10 @@ import org.apache.cloudstack.vm.UnmanagedInstanceTO; | |||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
| @LogLevel(LogLevel.Log4jLevel.Trace) |  | ||||||
| public class GetRemoteVmsAnswer extends Answer { | public class GetRemoteVmsAnswer extends Answer { | ||||||
| 
 | 
 | ||||||
|     private String remoteIp; |     private String remoteIp; | ||||||
|  |     @LogLevel(LogLevel.Log4jLevel.Trace) | ||||||
|     private HashMap<String, UnmanagedInstanceTO> unmanagedInstances; |     private HashMap<String, UnmanagedInstanceTO> unmanagedInstances; | ||||||
| 
 | 
 | ||||||
|     List<String> vmNames; |     List<String> vmNames; | ||||||
|  | |||||||
| @ -19,11 +19,11 @@ | |||||||
| 
 | 
 | ||||||
| package com.cloud.agent.api; | package com.cloud.agent.api; | ||||||
| 
 | 
 | ||||||
| @LogLevel(LogLevel.Log4jLevel.Trace) |  | ||||||
| public class GetRemoteVmsCommand extends Command { | public class GetRemoteVmsCommand extends Command { | ||||||
| 
 | 
 | ||||||
|     String remoteIp; |     String remoteIp; | ||||||
|     String username; |     String username; | ||||||
|  |     @LogLevel(LogLevel.Log4jLevel.Off) | ||||||
|     String password; |     String password; | ||||||
| 
 | 
 | ||||||
|     public GetRemoteVmsCommand(String remoteIp, String username, String password) { |     public GetRemoteVmsCommand(String remoteIp, String username, String password) { | ||||||
|  | |||||||
| @ -21,10 +21,10 @@ import java.util.HashMap; | |||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.vm.UnmanagedInstanceTO; | import org.apache.cloudstack.vm.UnmanagedInstanceTO; | ||||||
| 
 | 
 | ||||||
| @LogLevel(LogLevel.Log4jLevel.Trace) |  | ||||||
| public class GetUnmanagedInstancesAnswer extends Answer { | public class GetUnmanagedInstancesAnswer extends Answer { | ||||||
| 
 | 
 | ||||||
|     private String instanceName; |     private String instanceName; | ||||||
|  |     @LogLevel(LogLevel.Log4jLevel.Trace) | ||||||
|     private HashMap<String, UnmanagedInstanceTO> unmanagedInstances; |     private HashMap<String, UnmanagedInstanceTO> unmanagedInstances; | ||||||
| 
 | 
 | ||||||
|     GetUnmanagedInstancesAnswer() { |     GetUnmanagedInstancesAnswer() { | ||||||
|  | |||||||
| @ -28,10 +28,10 @@ import org.apache.commons.collections.CollectionUtils; | |||||||
|  * All managed instances will be filtered while trying to find unmanaged instances. |  * All managed instances will be filtered while trying to find unmanaged instances. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| @LogLevel(LogLevel.Log4jLevel.Trace) |  | ||||||
| public class GetUnmanagedInstancesCommand extends Command { | public class GetUnmanagedInstancesCommand extends Command { | ||||||
| 
 | 
 | ||||||
|     String instanceName; |     String instanceName; | ||||||
|  |     @LogLevel(LogLevel.Log4jLevel.Trace) | ||||||
|     List<String> managedInstancesNames; |     List<String> managedInstancesNames; | ||||||
| 
 | 
 | ||||||
|     public GetUnmanagedInstancesCommand() { |     public GetUnmanagedInstancesCommand() { | ||||||
|  | |||||||
| @ -3771,14 +3771,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public List<String> getAllVmNames(final Connect conn) { |     public List<String> getAllVmNames(final Connect conn) { | ||||||
|         final ArrayList<String> la = new ArrayList<String>(); |         final ArrayList<String> domainNames = new ArrayList<String>(); | ||||||
|         try { |         try { | ||||||
|             final String names[] = conn.listDefinedDomains(); |             final String names[] = conn.listDefinedDomains(); | ||||||
|             for (int i = 0; i < names.length; i++) { |             for (int i = 0; i < names.length; i++) { | ||||||
|                 la.add(names[i]); |                 domainNames.add(names[i]); | ||||||
|             } |             } | ||||||
|         } catch (final LibvirtException e) { |         } catch (final LibvirtException e) { | ||||||
|             s_logger.warn("Failed to list Defined domains", e); |             s_logger.warn("Failed to list defined domains", e); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         int[] ids = null; |         int[] ids = null; | ||||||
| @ -3786,14 +3786,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv | |||||||
|             ids = conn.listDomains(); |             ids = conn.listDomains(); | ||||||
|         } catch (final LibvirtException e) { |         } catch (final LibvirtException e) { | ||||||
|             s_logger.warn("Failed to list domains", e); |             s_logger.warn("Failed to list domains", e); | ||||||
|             return la; |             return domainNames; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         Domain dm = null; |         Domain dm = null; | ||||||
|         for (int i = 0; i < ids.length; i++) { |         for (int i = 0; i < ids.length; i++) { | ||||||
|             try { |             try { | ||||||
|                 dm = conn.domainLookupByID(ids[i]); |                 dm = conn.domainLookupByID(ids[i]); | ||||||
|                 la.add(dm.getName()); |                 domainNames.add(dm.getName()); | ||||||
|             } catch (final LibvirtException e) { |             } catch (final LibvirtException e) { | ||||||
|                 s_logger.warn("Unable to get vms", e); |                 s_logger.warn("Unable to get vms", e); | ||||||
|             } finally { |             } finally { | ||||||
| @ -3807,7 +3807,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return la; |         return domainNames; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private HashMap<String, HostVmStateReportEntry> getHostVmStateReport() { |     private HashMap<String, HostVmStateReportEntry> getHostVmStateReport() { | ||||||
|  | |||||||
| @ -50,36 +50,37 @@ public final class LibvirtGetRemoteVmsCommandWrapper extends CommandWrapper<GetR | |||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public Answer execute(final GetRemoteVmsCommand command, final LibvirtComputingResource libvirtComputingResource) { |     public Answer execute(final GetRemoteVmsCommand command, final LibvirtComputingResource libvirtComputingResource) { | ||||||
|         String hypervisorURI = "qemu+tcp://" + command.getRemoteIp() + "/system"; |         String remoteIp = command.getRemoteIp(); | ||||||
|  |         String hypervisorURI = "qemu+tcp://" + remoteIp + "/system"; | ||||||
|         HashMap<String, UnmanagedInstanceTO> unmanagedInstances = new HashMap<>(); |         HashMap<String, UnmanagedInstanceTO> unmanagedInstances = new HashMap<>(); | ||||||
|         try { |         try { | ||||||
|             Connect conn = LibvirtConnection.getConnection(hypervisorURI); |             Connect conn = LibvirtConnection.getConnection(hypervisorURI); | ||||||
|             final List<String> allVmNames = libvirtComputingResource.getAllVmNames(conn); |             final List<String> allVmNames = libvirtComputingResource.getAllVmNames(conn); | ||||||
|  |             s_logger.info(String.format("Found %d VMs on the remote host %s", allVmNames.size(), remoteIp)); | ||||||
|             for (String name : allVmNames) { |             for (String name : allVmNames) { | ||||||
|                 final Domain domain = libvirtComputingResource.getDomain(conn, name); |                 final Domain domain = libvirtComputingResource.getDomain(conn, name); | ||||||
| 
 |  | ||||||
|                 final DomainInfo.DomainState ps = domain.getInfo().state; |                 final DomainInfo.DomainState ps = domain.getInfo().state; | ||||||
|                 final VirtualMachine.PowerState state = libvirtComputingResource.convertToPowerState(ps); |                 final VirtualMachine.PowerState state = libvirtComputingResource.convertToPowerState(ps); | ||||||
|                 s_logger.debug("VM " + domain.getName() + " - powerstate: " + ps + ", state: " + state.toString()); |                 s_logger.debug(String.format("Remote VM %s - powerstate: %s, state: %s", domain.getName(), ps.toString(), state.toString())); | ||||||
| 
 | 
 | ||||||
|                 if (state == VirtualMachine.PowerState.PowerOff) { |                 if (state == VirtualMachine.PowerState.PowerOff) { | ||||||
|                     try { |                     try { | ||||||
|                         UnmanagedInstanceTO instance = getUnmanagedInstance(libvirtComputingResource, domain, conn); |                         UnmanagedInstanceTO instance = getUnmanagedInstance(libvirtComputingResource, domain, conn); | ||||||
|                         unmanagedInstances.put(instance.getName(), instance); |                         unmanagedInstances.put(instance.getName(), instance); | ||||||
|                     } catch (Exception e) { |                     } catch (Exception e) { | ||||||
|                         s_logger.error("Couldn't fetch VM " + domain.getName() + " details, due to: " + e.getMessage(), e); |                         s_logger.error("Couldn't fetch remote VM " + domain.getName() + " details, due to: " + e.getMessage(), e); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 domain.free(); |                 domain.free(); | ||||||
|             } |             } | ||||||
|             s_logger.debug("Found " + unmanagedInstances.size() + " stopped VMs on host " + command.getRemoteIp()); |             s_logger.debug("Found " + unmanagedInstances.size() + " stopped VMs on remote host " + remoteIp); | ||||||
|             return new GetRemoteVmsAnswer(command, "", unmanagedInstances); |             return new GetRemoteVmsAnswer(command, "", unmanagedInstances); | ||||||
|         } catch (final LibvirtException e) { |         } catch (final LibvirtException e) { | ||||||
|             s_logger.error("Failed to list stopped VMs on remote host " + command.getRemoteIp() + ", due to: " + e.getMessage(), e); |             s_logger.error("Failed to list stopped VMs on remote host " + remoteIp + ", due to: " + e.getMessage(), e); | ||||||
|             if (e.getMessage().toLowerCase().contains("connection refused")) { |             if (e.getMessage().toLowerCase().contains("connection refused")) { | ||||||
|                 return new Answer(command, false, "Unable to connect to remote host " + command.getRemoteIp() + ", please check the libvirtd tcp connectivity and retry"); |                 return new Answer(command, false, "Unable to connect to remote host " + remoteIp + ", please check the libvirtd tcp connectivity and retry"); | ||||||
|             } |             } | ||||||
|             return new Answer(command, false, "Unable to list stopped VMs on remote host " + command.getRemoteIp() + ", due to: " + e.getMessage()); |             return new Answer(command, false, "Unable to list stopped VMs on remote host " + remoteIp + ", due to: " + e.getMessage()); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -105,8 +106,8 @@ public final class LibvirtGetRemoteVmsCommandWrapper extends CommandWrapper<GetR | |||||||
| 
 | 
 | ||||||
|             return instance; |             return instance; | ||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
|             s_logger.debug("Unable to retrieve unmanaged instance info,  due to: " + e.getMessage(), e); |             s_logger.debug("Unable to retrieve remote unmanaged instance info,  due to: " + e.getMessage(), e); | ||||||
|             throw new CloudRuntimeException("Unable to retrieve unmanaged instance info, due to: " + e.getMessage()); |             throw new CloudRuntimeException("Unable to retrieve remote unmanaged instance info, due to: " + e.getMessage()); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -48,7 +48,7 @@ public final class LibvirtGetUnmanagedInstancesCommandWrapper extends CommandWra | |||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public GetUnmanagedInstancesAnswer execute(GetUnmanagedInstancesCommand command, LibvirtComputingResource libvirtComputingResource) { |     public GetUnmanagedInstancesAnswer execute(GetUnmanagedInstancesCommand command, LibvirtComputingResource libvirtComputingResource) { | ||||||
|         LOGGER.info("Fetching unmanaged instance on host"); |         LOGGER.info("Fetching unmanaged instances on host"); | ||||||
| 
 | 
 | ||||||
|         HashMap<String, UnmanagedInstanceTO> unmanagedInstances = new HashMap<>(); |         HashMap<String, UnmanagedInstanceTO> unmanagedInstances = new HashMap<>(); | ||||||
|         try { |         try { | ||||||
|  | |||||||
| @ -800,6 +800,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager { | |||||||
|         } |         } | ||||||
|         int copyTimeoutInSecs = copyTimeout * 60; |         int copyTimeoutInSecs = copyTimeout * 60; | ||||||
|         copyRemoteVolumeCommand.setWait(copyTimeoutInSecs); |         copyRemoteVolumeCommand.setWait(copyTimeoutInSecs); | ||||||
|  |         LOGGER.error(String.format("Initiating copy remote volume %s from %s, timeout %d secs", path, remoteUrl, copyTimeoutInSecs)); | ||||||
|         Answer answer = agentManager.easySend(dest.getHost().getId(), copyRemoteVolumeCommand); |         Answer answer = agentManager.easySend(dest.getHost().getId(), copyRemoteVolumeCommand); | ||||||
|         if (!(answer instanceof CopyRemoteVolumeAnswer)) { |         if (!(answer instanceof CopyRemoteVolumeAnswer)) { | ||||||
|             throw new CloudRuntimeException("Error while copying volume of remote instance: " + answer.getDetails()); |             throw new CloudRuntimeException("Error while copying volume of remote instance: " + answer.getDetails()); | ||||||
| @ -2434,7 +2435,6 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager { | |||||||
|         return defaultNetwork; |         return defaultNetwork; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     //generate unit test |  | ||||||
|     public ListResponse<UnmanagedInstanceResponse> listVmsForImport(ListVmsForImportCmd cmd) { |     public ListResponse<UnmanagedInstanceResponse> listVmsForImport(ListVmsForImportCmd cmd) { | ||||||
|         final Account caller = CallContext.current().getCallingAccount(); |         final Account caller = CallContext.current().getCallingAccount(); | ||||||
|         if (caller.getType() != Account.Type.ADMIN) { |         if (caller.getType() != Account.Type.ADMIN) { | ||||||
| @ -2474,8 +2474,8 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager { | |||||||
|     private HashMap<String, UnmanagedInstanceTO> getRemoteVmsOnKVMHost(long zoneId, String remoteHostUrl, String username, String password) { |     private HashMap<String, UnmanagedInstanceTO> getRemoteVmsOnKVMHost(long zoneId, String remoteHostUrl, String username, String password) { | ||||||
|         //ToDo: add option to list one Vm by name |         //ToDo: add option to list one Vm by name | ||||||
|         List<HostVO> hosts = resourceManager.listAllUpAndEnabledHostsInOneZoneByHypervisor(Hypervisor.HypervisorType.KVM, zoneId); |         List<HostVO> hosts = resourceManager.listAllUpAndEnabledHostsInOneZoneByHypervisor(Hypervisor.HypervisorType.KVM, zoneId); | ||||||
|         if(hosts.size() < 1) { |         if (hosts.size() < 1) { | ||||||
|             throw new CloudRuntimeException("No hosts available for VM import"); |             throw new CloudRuntimeException("No hosts available to list VMs on remote host " + remoteHostUrl); | ||||||
|         } |         } | ||||||
|         HostVO host = hosts.get(0); |         HostVO host = hosts.get(0); | ||||||
|         GetRemoteVmsCommand getRemoteVmsCommand = new GetRemoteVmsCommand(remoteHostUrl, username, password); |         GetRemoteVmsCommand getRemoteVmsCommand = new GetRemoteVmsCommand(remoteHostUrl, username, password); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user