@Override
  public long getEntityOwnerId() {

    Volume volume = _entityMgr.findById(Volume.class, getVolumeId());
    if (volume == null) {
      throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
    }

    Account account = _accountService.getAccount(volume.getAccountId());
    // Can create templates for enabled projects/accounts only
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
      Project project = _projectService.findByProjectAccountId(volume.getAccountId());
      if (project.getState() != Project.State.Active) {
        throw new PermissionDeniedException(
            "Can't add resources to the project id="
                + project.getId()
                + " in state="
                + project.getState()
                + " as it's no longer active");
      }
    } else if (account.getState() == Account.State.disabled) {
      throw new PermissionDeniedException("The owner of template is disabled: " + account);
    }

    return volume.getAccountId();
  }
Exemplo n.º 2
0
 @Override
 public long getEntityOwnerId() {
   Volume volume = _responseGenerator.findVolumeById(getId());
   if (volume == null) {
     return Account
         .ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are
                             // tracked
   }
   return volume.getAccountId();
 }
Exemplo n.º 3
0
  @Override
  public void create() throws ResourceAllocationException {

    Volume volume = this._volumeService.allocVolume(this);
    if (volume != null) {
      this.setEntityId(volume.getId());
      this.setEntityUuid(volume.getUuid());
    } else {
      throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create volume");
    }
  }
  @Override
  public String reserveVirtualMachine(
      VMEntityVO vmEntityVO, String plannerToUse, DeploymentPlan planToDeploy, ExcludeList exclude)
      throws InsufficientCapacityException, ResourceUnavailableException {

    // call planner and get the deployDestination.
    // load vm instance and offerings and call virtualMachineManagerImpl
    // FIXME: profile should work on VirtualMachineEntity
    VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
    VirtualMachineProfileImpl<VMInstanceVO> vmProfile =
        new VirtualMachineProfileImpl<VMInstanceVO>(vm);
    DataCenterDeployment plan =
        new DataCenterDeployment(
            vm.getDataCenterId(), vm.getPodIdToDeployIn(), null, null, null, null);
    if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
      plan =
          new DataCenterDeployment(
              planToDeploy.getDataCenterId(),
              planToDeploy.getPodId(),
              planToDeploy.getClusterId(),
              planToDeploy.getHostId(),
              planToDeploy.getPoolId(),
              planToDeploy.getPhysicalNetworkId());
    }

    List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
    if (!vols.isEmpty()) {
      VolumeVO vol = vols.get(0);
      StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
      if (!pool.isInMaintenance()) {
        long rootVolDcId = pool.getDataCenterId();
        Long rootVolPodId = pool.getPodId();
        Long rootVolClusterId = pool.getClusterId();
        if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
          Long clusterIdSpecified = planToDeploy.getClusterId();
          if (clusterIdSpecified != null && rootVolClusterId != null) {
            if (rootVolClusterId.longValue() != clusterIdSpecified.longValue()) {
              // cannot satisfy the plan passed in to the
              // planner
              throw new ResourceUnavailableException(
                  "Root volume is ready in different cluster, Deployment plan provided cannot be satisfied, unable to create a deployment for "
                      + vm,
                  Cluster.class,
                  clusterIdSpecified);
            }
          }
          plan =
              new DataCenterDeployment(
                  planToDeploy.getDataCenterId(),
                  planToDeploy.getPodId(),
                  planToDeploy.getClusterId(),
                  planToDeploy.getHostId(),
                  vol.getPoolId(),
                  null,
                  null);
        } else {
          plan =
              new DataCenterDeployment(
                  rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null, null);
        }
      }
    }

    DeploymentPlanner planner = ComponentContext.getComponent(plannerToUse);
    DeployDestination dest = null;

    if (planner.canHandle(vmProfile, plan, exclude)) {
      dest = planner.plan(vmProfile, plan, exclude);
    }

    if (dest != null) {
      // save destination with VMEntityVO
      VMReservationVO vmReservation =
          new VMReservationVO(
              vm.getId(),
              dest.getDataCenter().getId(),
              dest.getPod().getId(),
              dest.getCluster().getId(),
              dest.getHost().getId());
      Map<Long, Long> volumeReservationMap = new HashMap<Long, Long>();
      for (Volume vo : dest.getStorageForDisks().keySet()) {
        volumeReservationMap.put(vo.getId(), dest.getStorageForDisks().get(vo).getId());
      }
      vmReservation.setVolumeReservation(volumeReservationMap);

      vmEntityVO.setVmReservation(vmReservation);
      _vmEntityDao.persist(vmEntityVO);

      return vmReservation.getUuid();
    } else {
      throw new InsufficientServerCapacityException(
          "Unable to create a deployment for " + vmProfile,
          DataCenter.class,
          plan.getDataCenterId());
    }
  }
 @Override
 public List<VolumeJoinVO> newVolumeView(Volume vol) {
   SearchCriteria<VolumeJoinVO> sc = volIdSearch.create();
   sc.setParameters("id", vol.getId());
   return searchIncludingRemoved(sc, null, null, false);
 }
Exemplo n.º 6
0
 // Copy Constructor
 public VolumeVO(Volume that) {
   this(
       that.getName(),
       that.getDataCenterId(),
       that.getPodId(),
       that.getAccountId(),
       that.getDomainId(),
       that.getInstanceId(),
       that.getFolder(),
       that.getPath(),
       that.getSize(),
       that.getVolumeType());
   this.recreatable = that.isRecreatable();
   this.state = that.getState();
   this.size = that.getSize();
   this.diskOfferingId = that.getDiskOfferingId();
   this.poolId = that.getPoolId();
   this.attached = that.getAttached();
   this.chainInfo = that.getChainInfo();
   this.templateId = that.getTemplateId();
   this.deviceId = that.getDeviceId();
 }
 @Override
 public long getVolumeSizeIncludingHypervisorSnapshotReserve(Volume volume, StoragePool pool) {
   return volume.getSize();
 }
Exemplo n.º 8
0
 // Copy Constructor
 public VolumeVO(Volume that) {
   this(
       that.getName(),
       that.getDataCenterId(),
       that.getPodId(),
       that.getAccountId(),
       that.getDomainId(),
       that.getInstanceId(),
       that.getFolder(),
       that.getPath(),
       that.getSize(),
       that.getMinIops(),
       that.getMaxIops(),
       that.get_iScsiName(),
       that.getVolumeType());
   this.recreatable = that.isRecreatable();
   this.state = that.getState();
   this.size = that.getSize();
   this.minIops = that.getMinIops();
   this.maxIops = that.getMaxIops();
   this._iScsiName = that.get_iScsiName();
   this.diskOfferingId = that.getDiskOfferingId();
   this.poolId = that.getPoolId();
   this.attached = that.getAttached();
   this.chainInfo = that.getChainInfo();
   this.templateId = that.getTemplateId();
   this.deviceId = that.getDeviceId();
   this.format = that.getFormat();
   this.uuid = UUID.randomUUID().toString();
 }