@Mapping(
      from = DiskSnapshot.class,
      to = org.ovirt.engine.core.common.businessentities.storage.Disk.class)
  public static org.ovirt.engine.core.common.businessentities.storage.Disk map(
      DiskSnapshot diskSnapshot,
      org.ovirt.engine.core.common.businessentities.storage.Disk template) {
    DiskImage engineDisk = (DiskImage) DiskMapper.map(diskSnapshot, template);

    engineDisk.setImageId(GuidUtils.asGuid(diskSnapshot.getId()));

    if (diskSnapshot.isSetDisk()) {
      engineDisk.setId(GuidUtils.asGuid(diskSnapshot.getDisk().getId()));
    }

    return engineDisk;
  }
 /**
  * A session is not a business-entity in the engine and does not have an ID. This method generates
  * an ID for the session object, based on its attributes.
  */
 private void setSessionId(Session session) {
   String idString = session.getUser().getName();
   if (session.isSetIp() && session.getIp().isSetAddress()) {
     idString += session.getIp().getAddress();
   }
   if (session.isSetProtocol()) {
     idString += session.getProtocol();
   }
   session.setId(GuidUtils.generateGuidUsingMd5(idString).toString());
 }
Example #3
0
  @Mapping(from = QoS.class, to = QosBase.class)
  public static QosBase map(QoS model, QosBase template) {
    QosBase entity = null;
    if (template != null) {
      entity = template;
    }
    QosType qosType =
        model.getType() != null
            ? QosType.valueOf(model.getType().toUpperCase())
            : entity != null
                ? QosType.valueOf(entity.getQosType().toString().toUpperCase())
                : QosType.STORAGE;
    switch (qosType) {
      case STORAGE:
        if (entity == null) {
          entity = new StorageQos();
        }
        if (model.isSetMaxThroughput()) {
          ((StorageQos) entity)
              .setMaxThroughput(IntegerMapper.mapMinusOneToNull(model.getMaxThroughput()));
        }
        if (model.isSetMaxReadThroughput()) {
          ((StorageQos) entity)
              .setMaxReadThroughput(IntegerMapper.mapMinusOneToNull(model.getMaxReadThroughput()));
        }
        if (model.isSetMaxWriteThroughput()) {
          ((StorageQos) entity)
              .setMaxWriteThroughput(
                  IntegerMapper.mapMinusOneToNull(model.getMaxWriteThroughput()));
        }
        if (model.isSetMaxIops()) {
          ((StorageQos) entity).setMaxIops(IntegerMapper.mapMinusOneToNull(model.getMaxIops()));
        }
        if (model.isSetMaxReadIops()) {
          ((StorageQos) entity)
              .setMaxReadIops(IntegerMapper.mapMinusOneToNull(model.getMaxReadIops()));
        }
        if (model.isSetMaxWriteIops()) {
          ((StorageQos) entity)
              .setMaxWriteIops(IntegerMapper.mapMinusOneToNull(model.getMaxWriteIops()));
        }
        break;
      case CPU:
        if (entity == null) {
          entity = new CpuQos();
        }
        if (model.isSetCpuLimit()) {
          ((CpuQos) entity).setCpuLimit(IntegerMapper.mapMinusOneToNull(model.getCpuLimit()));
        }
        break;
      case NETWORK:
        if (entity == null) {
          entity = new NetworkQoS();
        }
        if (model.isSetInboundAverage()) {
          ((NetworkQoS) entity)
              .setInboundAverage(IntegerMapper.mapMinusOneToNull(model.getInboundAverage()));
        }
        if (model.isSetInboundPeak()) {
          ((NetworkQoS) entity)
              .setInboundPeak(IntegerMapper.mapMinusOneToNull(model.getInboundPeak()));
        }
        if (model.isSetInboundBurst()) {
          ((NetworkQoS) entity)
              .setInboundBurst(IntegerMapper.mapMinusOneToNull(model.getInboundBurst()));
        }
        if (model.isSetOutboundAverage()) {
          ((NetworkQoS) entity)
              .setOutboundAverage(IntegerMapper.mapMinusOneToNull(model.getOutboundAverage()));
        }
        if (model.isSetOutboundPeak()) {
          ((NetworkQoS) entity)
              .setOutboundPeak(IntegerMapper.mapMinusOneToNull(model.getOutboundPeak()));
        }
        if (model.isSetOutboundBurst()) {
          ((NetworkQoS) entity)
              .setOutboundBurst(IntegerMapper.mapMinusOneToNull(model.getOutboundBurst()));
        }
        break;
      default:
        break;
    }

    if (model.isSetId()) {
      entity.setId(GuidUtils.asGuid(model.getId()));
    }
    if (model.isSetName()) {
      entity.setName(model.getName());
    }
    if (model.isSetDataCenter() && model.getDataCenter().isSetId()) {
      entity.setStoragePoolId(GuidUtils.asGuid(model.getDataCenter().getId()));
    }
    if (model.isSetDescription()) {
      entity.setDescription(model.getDescription());
    }

    return entity;
  }