com.cloud.storage.Volume.getAccountId()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中com.cloud.storage.Volume.getAccountId()方法的一些代码示例,展示了Volume.getAccountId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Volume.getAccountId()方法的具体详情如下:
包路径:com.cloud.storage.Volume
类名称:Volume
方法名:getAccountId

Volume.getAccountId介绍

暂无

代码示例

代码示例来源:origin: apache/cloudstack

private void updateResourceCount(Volume volume, Boolean displayVolume) {
  // Update only when the flag has changed.
  if (displayVolume != null && displayVolume != volume.isDisplayVolume()) {
    _resourceLimitMgr.changeResourceCount(volume.getAccountId(), ResourceType.volume, displayVolume);
    _resourceLimitMgr.changeResourceCount(volume.getAccountId(), ResourceType.primary_storage, displayVolume, new Long(volume.getSize()));
  }
}

代码示例来源:origin: apache/cloudstack

@Override
public long getEntityOwnerId() {
  Volume volume = _entityMgr.findById(Volume.class, getId());
  if (volume != null) {
    return volume.getAccountId();
  }
  return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
}

代码示例来源:origin: apache/cloudstack

@Override
public long getEntityOwnerId() {
  Volume volume = _entityMgr.findById(Volume.class, getId());
  if (volume != null) {
    return volume.getAccountId();
  }
  // invalid id, parent this command to SYSTEM so ERROR events are tracked
  return Account.ACCOUNT_ID_SYSTEM;
}

代码示例来源:origin: apache/cloudstack

@Override
public long getEntityOwnerId() {
  Volume volume = _entityMgr.findById(Volume.class, getVolumeId());
  if (volume != null) {
    return volume.getAccountId();
  }
  return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
}

代码示例来源:origin: apache/cloudstack

@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();
}

代码示例来源:origin: apache/cloudstack

@Override
public long getEntityOwnerId() {
  Volume volume = _responseGenerator.findVolumeById(getId());
  if (volume == null) {
    throw new InvalidParameterValueException("Invalid volume id was provided");
  }
  return volume.getAccountId();
}

代码示例来源:origin: apache/cloudstack

@Override
public long getEntityOwnerId() {
  Volume volume = _entityMgr.findById(Volume.class, getEntityId());
  if (volume == null) {
      throw new InvalidParameterValueException("Unable to find volume by id=" + id);
  }
  Account account = _accountService.getAccount(volume.getAccountId());
  //Can resize volumes 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  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 volume " + id + "  is disabled: " + account);
  }
  return volume.getAccountId();
}

代码示例来源:origin: apache/cloudstack

@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();
}

代码示例来源:origin: apache/cloudstack

private void saveUsageEvent(Volume volume, Boolean displayVolume) {
  // Update only when the flag has changed  &&  only when volume in a non-destroyed state.
  if ((displayVolume != null && displayVolume != volume.isDisplayVolume()) && !isVolumeDestroyed(volume)) {
    if (displayVolume) {
      // flag turned 1 equivalent to freshly created volume
      UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), volume.getDiskOfferingId(),
          volume.getTemplateId(), volume.getSize(), Volume.class.getName(), volume.getUuid());
    } else {
      // flag turned 0 equivalent to deleting a volume
      UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), Volume.class.getName(),
          volume.getUuid());
    }
  }
}

代码示例来源:origin: apache/cloudstack

@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) {
      PermissionDeniedException ex =
        new PermissionDeniedException("Can't add resources to the specified project id in state=" + project.getState() + " as it's no longer active");
      ex.addProxyObject(project.getUuid(), "projectId");
      throw ex;
    }
  } else if (account.getState() == Account.State.disabled) {
    throw new PermissionDeniedException("The owner of template is disabled: " + account);
  }
  return volume.getAccountId();
}

代码示例来源:origin: apache/cloudstack

@Override
public long getEntityOwnerId() {
  SnapshotPolicy policy = _entityMgr.findById(SnapshotPolicy.class, getId());
  if (policy == null) {
    throw new InvalidParameterValueException("Invalid snapshot policy id was provided");
  }
  Volume volume = _responseGenerator.findVolumeById(policy.getVolumeId());
  if (volume == null) {
    throw new InvalidParameterValueException("Snapshot policy's volume id doesnt exist");
  }else{
    return volume.getAccountId();
  }
}

代码示例来源:origin: apache/cloudstack

@Override
public void destroyVolume(Volume volume) {
  try {
    // Mark volume as removed if volume has not been created on primary
    if (volume.getState() == Volume.State.Allocated) {
      _volsDao.remove(volume.getId());
      stateTransitTo(volume, Volume.Event.DestroyRequested);
    } else {
      volService.destroyVolume(volume.getId());
    }
    // FIXME - All this is boiler plate code and should be done as part of state transition. This shouldn't be part of orchestrator.
    // publish usage event for the volume
    UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), Volume.class.getName(),
        volume.getUuid(), volume.isDisplayVolume());
    _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume, volume.isDisplay());
    _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.isDisplay(), new Long(volume.getSize()));
  } catch (Exception e) {
    s_logger.debug("Failed to destroy volume" + volume.getId(), e);
    throw new CloudRuntimeException("Failed to destroy volume" + volume.getId(), e);
  }
}

代码示例来源:origin: apache/cloudstack

@Override
public long getEntityOwnerId() {
  Long volumeId = getId();
  if (volumeId != null) {
    Volume volume = _responseGenerator.findVolumeById(volumeId);
    if (volume != null) {
      return volume.getAccountId();
    }
  } else if (getVirtualMachineId() != null) {
    UserVm vm = _responseGenerator.findUserVmById(getVirtualMachineId());
    if (vm != null) {
      return vm.getAccountId();
    }
  }
  // invalid id, parent this command to SYSTEM so ERROR events are tracked
  return Account.ACCOUNT_ID_SYSTEM;
}

代码示例来源:origin: apache/cloudstack

@Override
public boolean postStateTransitionEvent(StateMachine2.Transition<State, Event> transition, Volume vol, boolean status, Object opaque) {
 pubishOnEventBus(transition.getEvent().name(), "postStateTransitionEvent", vol, transition.getCurrentState(), transition.getToState());
 if(transition.isImpacted(StateMachine2.Transition.Impact.USAGE)) {
  Long instanceId = vol.getInstanceId();
  VMInstanceVO vmInstanceVO = null;
  if(instanceId != null) {
   vmInstanceVO = _vmInstanceDao.findById(instanceId);
  }
  if(instanceId == null || vmInstanceVO.getType() == VirtualMachine.Type.User) {
   if (transition.getToState() == State.Ready) {
    if (transition.getCurrentState() == State.Resizing) {
     // Log usage event for volumes belonging user VM's only
     UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_RESIZE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(),
         vol.getDiskOfferingId(), vol.getTemplateId(), vol.getSize(), Volume.class.getName(), vol.getUuid());
    } else {
     UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), vol.getDiskOfferingId(), null, vol.getSize(),
         Volume.class.getName(), vol.getUuid(), vol.isDisplayVolume());
    }
   } else if (transition.getToState() == State.Destroy && vol.getVolumeType() != Volume.Type.ROOT) { //Do not Publish Usage Event for ROOT Disk as it would have been published already while destroying a VM
    UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(),
        Volume.class.getName(), vol.getUuid(), vol.isDisplayVolume());
   } else if (transition.getToState() == State.Uploaded) {
    //Currently we are not capturing Usage for Secondary Storage so Usage for this operation will be captured when it is moved to primary storage
   }
  }
 }
 return true;
}

代码示例来源:origin: apache/cloudstack

@DB
@Override
public VolumeInfo createVolumeFromSnapshot(Volume volume, Snapshot snapshot, UserVm vm) throws StorageUnavailableException {
  Account account = _entityMgr.findById(Account.class, volume.getAccountId());

代码示例来源:origin: apache/cloudstack

that.getDataCenterId(),
that.getPodId(),
that.getAccountId(),
that.getDomainId(),
that.getInstanceId(),

代码示例来源:origin: apache/cloudstack

public VolumeVO allocateDuplicateVolumeVO(Volume oldVol, Long templateId) {
  VolumeVO newVol = new VolumeVO(oldVol.getVolumeType(), oldVol.getName(), oldVol.getDataCenterId(), oldVol.getDomainId(), oldVol.getAccountId(), oldVol.getDiskOfferingId(),
      oldVol.getProvisioningType(), oldVol.getSize(), oldVol.getMinIops(), oldVol.getMaxIops(), oldVol.get_iScsiName());
  if (templateId != null) {
    newVol.setTemplateId(templateId);
  } else {
    newVol.setTemplateId(oldVol.getTemplateId());
  }
  newVol.setDeviceId(oldVol.getDeviceId());
  newVol.setInstanceId(oldVol.getInstanceId());
  newVol.setRecreatable(oldVol.isRecreatable());
  newVol.setFormat(oldVol.getFormat());
  return _volsDao.persist(newVol);
}

代码示例来源:origin: apache/cloudstack

_resourceLimitMgr.incrementResourceCount(newVol.getAccountId(), ResourceType.volume, newVol.isDisplay());
_resourceLimitMgr.incrementResourceCount(newVol.getAccountId(), ResourceType.primary_storage, newVol.isDisplay(), new Long(newVol.getSize()));
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, newVol.getAccountId(), newVol.getDataCenterId(), newVol.getId(), newVol.getName(), newVol.getDiskOfferingId(), template.getId(), newVol.getSize());
_usageEventDao.persist(usageEvent);

相关文章