コード例 #1
0
ファイル: VmsMonitoring.java プロジェクト: nirs/ovirt-engine
  /**
   * Actually process the VM device update in DB.
   *
   * @param vm
   */
  private void processVmDevices(Map vm) {
    if (vm == null || vm.get(VdsProperties.vm_guid) == null) {
      log.error("Received NULL VM or VM id when processing VM devices, abort.");
      return;
    }

    Guid vmId = new Guid((String) vm.get(VdsProperties.vm_guid));
    Set<Guid> processedDevices = new HashSet<Guid>();
    List<VmDevice> devices = getDbFacade().getVmDeviceDao().getVmDeviceByVmId(vmId);
    Map<VmDeviceId, VmDevice> deviceMap = Entities.businessEntitiesById(devices);

    for (Object o : (Object[]) vm.get(VdsProperties.Devices)) {
      Map device = (Map<String, Object>) o;
      if (device.get(VdsProperties.Address) == null) {
        logDeviceInformation(vmId, device);
        continue;
      }

      Guid deviceId = getDeviceId(device);
      VmDevice vmDevice = deviceMap.get(new VmDeviceId(deviceId, vmId));
      String logicalName = null;
      if (deviceId != null
          && FeatureSupported.reportedDisksLogicalNames(
              getVdsManager().getGroupCompatibilityVersion())
          && VmDeviceType.DISK.getName().equals(device.get(VdsProperties.Device))) {
        try {
          logicalName =
              getDeviceLogicalName((Map<?, ?>) vm.get(VdsProperties.GuestDiskMapping), deviceId);
        } catch (Exception e) {
          log.error(
              "error while getting device name when processing, vm '{}', device info '{}' with exception, skipping '{}'",
              vmId,
              device,
              e.getMessage());
          log.error("Exception", e);
        }
      }

      if (deviceId == null || vmDevice == null) {
        deviceId = addNewVmDevice(vmId, device, logicalName);
      } else {
        vmDevice.setIsPlugged(Boolean.TRUE);
        vmDevice.setAddress(((Map<String, String>) device.get(VdsProperties.Address)).toString());
        vmDevice.setAlias(StringUtils.defaultString((String) device.get(VdsProperties.Alias)));
        vmDevice.setLogicalName(logicalName);
        addVmDeviceToList(vmDevice);
      }

      processedDevices.add(deviceId);
    }

    handleRemovedDevices(vmId, processedDevices, devices);
  }
  @Override
  protected void executeQueryCommand() {
    List<VmTemplate> vmTemplateList =
        getDbFacade().getVmTemplateDao().getAllForNetwork(getParameters().getId());
    List<VmNetworkInterface> vmNetworkInterfaceList =
        getDbFacade()
            .getVmNetworkInterfaceDao()
            .getAllForTemplatesByNetwork(getParameters().getId());

    final Map<Guid, VmTemplate> vmTemplatesById = Entities.businessEntitiesById(vmTemplateList);

    List<PairQueryable<VmNetworkInterface, VmTemplate>> vmInterfaceVmPairs =
        new ArrayList<PairQueryable<VmNetworkInterface, VmTemplate>>();
    for (VmNetworkInterface vmNetworkInterface : vmNetworkInterfaceList) {
      vmInterfaceVmPairs.add(
          new PairQueryable<VmNetworkInterface, VmTemplate>(
              vmNetworkInterface, vmTemplatesById.get(vmNetworkInterface.getVmTemplateId())));
    }

    getQueryReturnValue().setReturnValue(vmInterfaceVmPairs);
  }