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;
  }
Exemplo n.º 2
0
  @PUT
  @Path("action/allocate")
  public synchronized VirtualMachineDto allocate(
      @PathParam(VirtualApplianceResource.VIRTUAL_APPLIANCE) Integer virtualApplianceId,
      @PathParam(VirtualMachineResource.VIRTUAL_MACHINE) Integer virtualMachineId,
      String forceEnterpriseLimitsStr,
      @Context IRESTBuilder restBuilder)
      throws Exception {

    Boolean forceEnterpriseLimits = Boolean.parseBoolean(forceEnterpriseLimitsStr);
    // get user form the authentication layer
    // User user = userService.getCurrentUser();

    VirtualMachine vmachine =
        service.allocateVirtualMachine(virtualMachineId, virtualApplianceId, forceEnterpriseLimits);

    service.updateVirtualMachineUse(virtualApplianceId, vmachine);

    return ModelTransformer.transportFromPersistence(VirtualMachineDto.class, vmachine);
  }
Exemplo n.º 3
0
  @Transactional(propagation = Propagation.REQUIRED)
  public DatacenterDto addDatacenter(final DatacenterDto dto) throws Exception {
    if (repo.existsAnyDatacenterWithName(dto.getName())) {
      addConflictErrors(APIError.DATACENTER_DUPLICATED_NAME);
      flushErrors();
    }

    // Create the public network before the datacenter
    // This network will store all the public VLANs of the datacenter.
    Network network = new Network(UUID.randomUUID().toString());
    repo.insertNetwork(network);

    Datacenter datacenter = new Datacenter(dto.getName(), dto.getLocation());
    isValidDatacenter(datacenter);
    datacenter.setNetwork(network);
    repo.insert(datacenter);

    DatacenterDto responseDto =
        ModelTransformer.transportFromPersistence(DatacenterDto.class, datacenter);

    // Add the default tiers
    for (int i = 1; i <= 4; i++) {
      Tier tier = new Tier("Default Tier " + i, "Description of the default tier " + i, datacenter);
      repo.insertTier(tier);
    }

    // Add the Remote Services in database in case are informed in the request
    if (dto.getRemoteServices() != null) {
      RemoteServicesDto responseRemoteService = new RemoteServicesDto();
      for (RemoteServiceDto rsd : dto.getRemoteServices().getCollection()) {
        RemoteServiceDto rsDto = infrastructureService.addRemoteService(rsd, datacenter.getId());
        responseRemoteService.add(rsDto);
      }
      responseDto.setRemoteServices(responseRemoteService);
    }

    return responseDto;
  }