/**
   * Static method that converts the persistence {@link VirtualMachine} object to transfer {@link
   * VirtualMachineDto} object. It also adds REST self-discover {@link RESTLink}s
   *
   * @param vm Input persistence object.
   * @param restBuilder Context-injected {@link RESTLink} builder to create the links.
   * @return the corresponding transfer object.
   * @throws Exception Serialization unhandled exception.
   */
  public static VirtualMachineDto createTransferObject(
      final Integer datacenterId,
      final Integer rackId,
      final Integer machineId,
      final VirtualMachine vm,
      final VirtualAppliance vapp,
      final IRESTBuilder restBuilder)
      throws Exception {
    // TODO: Try with enterprise and user != null
    VirtualMachineDto vmDto =
        ModelTransformer.transportFromPersistence(VirtualMachineDto.class, vm);
    if (vm.getIdType() == 0) {
      vmDto.setIdType(com.abiquo.server.core.cloud.VirtualMachine.NOT_MANAGED);
    } else {
      vmDto.setIdType(com.abiquo.server.core.cloud.VirtualMachine.MANAGED);
    }
    Integer enterpriseId = null;
    Integer userId = null;

    if (vm.getEnterprise() != null) {
      enterpriseId = vm.getEnterprise().getId();
    }
    if (vm.getUser() != null) {
      userId = vm.getUser().getId();
    }
    vmDto.setLinks(
        restBuilder.buildVirtualMachineAdminLinks(
            datacenterId,
            rackId,
            machineId,
            enterpriseId,
            userId,
            vm.getHypervisor().getType(),
            vapp,
            vm.getId()));

    final VirtualMachineTemplate vmtemplate = vm.getVirtualMachineTemplate();
    if (vmtemplate != null) {
      if (vmtemplate.getRepository() != null) {
        vmDto.addLink(
            restBuilder.buildVirtualMachineTemplateLink(
                vmtemplate.getEnterprise().getId(),
                vmtemplate.getRepository().getDatacenter().getId(),
                vmtemplate.getId()));
      } else {
        // imported virtual machines
        vmDto.addLink(
            restBuilder.buildVirtualMachineTemplateLink(
                vmtemplate.getEnterprise().getId(),
                vm.getHypervisor().getMachine().getRack().getDatacenter().getId(),
                vmtemplate.getId()));
      }
    }
    return vmDto;
  }
Пример #2
0
  public static IpPoolManagementDto createTransferObject(
      final IpPoolManagement ip, final IRESTBuilder restBuilder) throws Exception {
    IpPoolManagementDto dto =
        ModelTransformer.transportFromPersistence(IpPoolManagementDto.class, ip);

    // Create the links to the resources where the IP object is assigned to
    dto.addLinks(restBuilder.buildIpRasdLinks(ip));
    dto.addLinks(restBuilder.buildRasdLinks(ip));

    return dto;
  }
Пример #3
0
  @GET
  public IpsPoolManagementDto getIPAddresses(
      @PathParam(VirtualDatacenterResource.VIRTUAL_DATACENTER) final Integer vdcId,
      @PathParam(PrivateNetworkResource.PRIVATE_NETWORK) final Integer vlanId,
      @QueryParam(START_WITH) @DefaultValue("0") @Min(0) final Integer startwith,
      @QueryParam(BY) @DefaultValue("ip") final String orderBy,
      @QueryParam(FILTER) @DefaultValue("") final String filter,
      @QueryParam(LIMIT) @Min(0) @DefaultValue(DEFAULT_PAGE_LENGTH_STRING) final Integer limit,
      @QueryParam(ASC) @DefaultValue("true") final Boolean descOrAsc,
      @QueryParam(ONLYAVAILABLE) @DefaultValue("false") final Boolean available,
      @Context final IRESTBuilder restBuilder)
      throws Exception {

    List<IpPoolManagement> all =
        service.getListIpPoolManagementByVlan(
            vdcId, vlanId, startwith, orderBy, filter, limit, descOrAsc);

    IpsPoolManagementDto ips = new IpsPoolManagementDto();

    for (IpPoolManagement ip : all) {
      ips.add(createTransferObject(ip, restBuilder));
    }

    ips.addLinks(
        restBuilder.buildPaggingLinks(uriInfo.getAbsolutePath().toString(), (PagedList) all));
    ips.setTotalSize(((PagedList) all).getTotalResults());

    return ips;
  }
  public static DatastoreDto createTransferObject(
      Datastore datastore,
      Integer datacenterId,
      Integer rackId,
      Integer machineId,
      IRESTBuilder restBuilder)
      throws Exception {
    DatastoreDto dto = ModelTransformer.transportFromPersistence(DatastoreDto.class, datastore);

    dto.setLinks(restBuilder.buildDatastoreLinks(datacenterId, rackId, machineId, datastore));

    return dto;
  }