io.cattle.platform.core.model.Volume类的使用及代码示例

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

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

Volume介绍

[英]This class is generated by jOOQ.
[中]这个类是由jOOQ生成的。

代码示例

代码示例来源:origin: rancher/cattle

setId(from.getId());
setName(from.getName());
setAccountId(from.getAccountId());
setKind(from.getKind());
setUuid(from.getUuid());
setDescription(from.getDescription());
setState(from.getState());
setCreated(from.getCreated());
setRemoved(from.getRemoved());
setRemoveTime(from.getRemoveTime());
setData(from.getData());
setPhysicalSizeMb(from.getPhysicalSizeMb());
setVirtualSizeMb(from.getVirtualSizeMb());
setDeviceNumber(from.getDeviceNumber());
setFormat(from.getFormat());
setAllocationState(from.getAllocationState());
setAttachedState(from.getAttachedState());
setInstanceId(from.getInstanceId());
setImageId(from.getImageId());
setZoneId(from.getZoneId());
setUri(from.getUri());
setExternalId(from.getExternalId());
setAccessMode(from.getAccessMode());
setHostId(from.getHostId());
setDeploymentUnitId(from.getDeploymentUnitId());
setStackId(from.getStackId());
setVolumeTemplateId(from.getVolumeTemplateId());
setStorageDriverId(from.getStorageDriverId());
setSizeMb(from.getSizeMb());

代码示例来源:origin: rancher/cattle

@Override
  public HandlerResult handle(ProcessState state, ProcessInstance process) {
    Volume volume = (Volume)state.getResource();
    if (volume.getImageId() != null || StringUtils.isEmpty(volume.getName())) {
      return null;
    }

    Map<Object, Object> data = new HashMap<>();
    String externalId = volume.getExternalId();
    if (StringUtils.isEmpty(externalId)) {
      externalId = volume.getName();
    }
    data.put("externalId", VolumeUtils.externalId(externalId));
    return new HandlerResult(data);
  }
}

代码示例来源:origin: rancher/cattle

protected void storage(Instance instance) {
  List<Volume> volumes = getObjectManager().children(instance, Volume.class);
  for (Volume volume : volumes) {
    if (volume.getRemoved() == null && !volume.getState().equals(CommonStatesConstants.REMOVED)) {
      deactivate(volume, null);
    }
  }
}

代码示例来源:origin: rancher/cattle

@Override
protected Long getId(Object obj) {
  if (obj instanceof Volume) {
    return ((Volume) obj).getId();
  }
  return null;
}

代码示例来源:origin: rancher/cattle

stack.getId(), VOLUME.DEPLOYMENT_UNIT_ID, unit.getId());
    for (Volume vol : volumes) {
      if (vol.getName().startsWith(name)) {
        volume = vol;
        break;
              stack.getId());
      for (Volume testVolume : volumes) {
        if (testVolume.getDeploymentUnitId() == null) {
          continue;
        boolean invalidHost = VolumeConstants.ACCESS_MODE_SINGLE_HOST_RW.equalsIgnoreCase(testVolume.getAccessMode())
            && testVolume.getHostId() != null
            && !hostIdsToDeploy.contains(testVolume.getHostId());
        if (invalidHost) {
          continue;
            context.objectManager.loadResource(io.cattle.platform.core.model.DeploymentUnit.class, testVolume.getDeploymentUnitId());
        if (unit.getServiceIndex().equals(testUnit.getServiceIndex()) &&
            testUnit.getServiceId() != null && testUnit.getServiceId().equals(unit.getServiceId())) {
volumeMounts.put(volumePath, volume.getId());
internalVolumes.add(volumeName);

代码示例来源:origin: rancher/cattle

@Override
public HandlerResult handle(ProcessState state, ProcessInstance process) {
  Volume volume = (Volume) state.getResource();
  String driver = DataAccessor.fieldString(volume, VolumeConstants.FIELD_VOLUME_DRIVER);
  Long driverId = volume.getStorageDriverId();
  Integer deviceNum = volume.getDeviceNumber();
  StorageDriver storageDriver = objectManager.loadResource(StorageDriver.class, driverId);
  if (storageDriver == null && StringUtils.isNotBlank(driver)) {
    storageDriver = objectManager.findAny(StorageDriver.class,
        STORAGE_DRIVER.ACCOUNT_ID, volume.getAccountId(),
        STORAGE_DRIVER.REMOVED, null,
        STORAGE_DRIVER.NAME, driver);
  }
  if (storageDriver != null) {
    driver = storageDriver.getName();
    driverId = storageDriver.getId();
    deviceNum = -1;
  }
  HandlerResult result = new HandlerResult(VolumeConstants.FIELD_VOLUME_DRIVER, driver,
      VOLUME.DEVICE_NUMBER, deviceNum,
      VOLUME.STORAGE_DRIVER_ID, driverId);
  Long hostId = volume.getHostId();
  if (storageDriver != null && hostId != null) {
    if (storagePoolDao.associateVolumeToPool(volume.getId(), storageDriver.getId(), hostId) != null) {
      result.withShouldContinue(false)
      .withChainProcessName(objectProcessManager.getStandardProcessName(StandardProcess.DEACTIVATE, volume));
    }
  }
  return result;
}

代码示例来源:origin: rancher/cattle

List<Volume> volumes = InstanceHelpers.extractVolumesFromMounts(instance, objectManager);
for (Volume v : volumes) {
  if (VolumeConstants.ACCESS_MODE_SINGLE_HOST_RW.equals(v.getAccessMode())) {
    Long hostID = null;
    Object hostIdObject = DataAccessor.fromDataFieldOf(v).withKey(VolumeConstants.FIELD_LAST_ALLOCATED_HOST_ID).get();
      hostID = Long.parseLong(hostIdObject.toString());
    Set<Long> hostIds = allocatorDao.findHostsWithVolumeInUse(v.getId());
    boolean hardConstraint = false;
    if (hostIds.size() == 0) {
      Host host = objectManager.loadResource(Host.class, hostID);
      String hostName = DataAccessor.fieldString(host, HostConstants.FIELD_HOSTNAME);
      constraints.add(new VolumeAccessModeSingleHostConstraint(hostID, v.getId(), v.getName(), hostName, hardConstraint, idFormatter));
  } else if (VolumeConstants.ACCESS_MODE_SINGLE_INSTANCE_RW.equals(v.getAccessMode())) {
    List<Long> currentlyUsedBy = allocatorDao.getInstancesWithVolumeMounted(v.getId(), instance.getId());
    if (currentlyUsedBy.size() > 0) {
      constraints.add(new VolumeAccessModeSingleInstanceConstraint(v.getName(), v.getId(), v.getAccessMode(), currentlyUsedBy, idFormatter));

代码示例来源:origin: rancher/cattle

String driver = DataAccessor.fieldString(v, VolumeConstants.FIELD_VOLUME_DRIVER);
if (StringUtils.isNotEmpty(driver) && !VolumeConstants.LOCAL_DRIVER.equals(driver)) {
  List<? extends StoragePool> pools = storagePoolDao.findStoragePoolByDriverName(v.getAccountId(), driver);
  if (pools.size() == 0) {
    continue;
  if (StringUtils.isNotEmpty(accessMode) && StringUtils.isEmpty(v.getAccessMode()) && !accessMode.equals(v.getAccessMode())) {
    lockManager.lock(new InstanceVolumeAccessModeLock(v.getId()), new LockCallbackNoReturn() {
      @Override
      public void doWithLockNoResult() {

代码示例来源:origin: rancher/cattle

Object d = data.get(VolumeConstants.FIELD_VOLUME_DRIVER);
String driver = d != null ? d.toString() : null;
Long driverId = volume.getStorageDriverId();
StorageDriver storageDriver = objectManager.loadResource(StorageDriver.class, driverId);
      VOLUME.NAME, volume.getName(),
      VOLUME.REMOVED, null,
      VOLUME.STORAGE_DRIVER_ID, storageDriver.getId());
if (volume.getSizeMb() != null) {
  if (storageDriver == null && StringUtils.isNotBlank(driver)) {
    storageDriver = objectManager.findAny(StorageDriver.class,

代码示例来源:origin: rancher/cattle

@Override
public HandlerResult handle(ProcessState state, ProcessInstance process) {
  Volume volume = (Volume)state.getResource();
  deallocate(volume, state.getData());
  boolean maps = false;
  boolean mounts = false;
  for (VolumeStoragePoolMap map : mapDao.findToRemove(VolumeStoragePoolMap.class, Volume.class, volume.getId())) {
    maps = true;
    deactivateThenScheduleRemove(map, null);
  }
  for (Mount mount : mapDao.findToRemove(Mount.class, Volume.class, volume.getId())) {
    mounts = true;
    deactivateThenRemove(mount, null);
  }
  Image image = objectManager.loadResource(Image.class, volume.getImageId());
  if (image != null) {
    remove(image, null);
  }
  if (maps && !mounts && volume.getHostId() != null) {
    /* HostId != null means this volume was created from a host, but no mounts also means it won't be deleted,
     * so we delete.
     */
    return super.handle(state, process);
  }
  return new HandlerResult();
}

代码示例来源:origin: rancher/cattle

private void deleteVolumes(Instance instance, ProcessState state) {
  Object b = DataAccessor.fieldMap(instance, FIELD_LABELS).get(SystemLabels.LABEL_VOLUME_CLEANUP_STRATEGY);
  String behavior = b != null ? b.toString() : VOLUME_CLEANUP_STRATEGY_UNNAMED;
  Set<? extends Volume> volumes = volumeDao.findNonremovedVolumesWithNoOtherMounts(instance.getId());
  for (Volume v : volumes) {
    String volumeBehavior = migrateVolume(instance, v, behavior);
    if (VOLUME_CLEANUP_STRATEGY_NONE.equals(volumeBehavior)
        || (!VOLUME_CLEANUP_STRATEGY_UNNAMED.equals(volumeBehavior) && !VOLUME_CLEANUP_STRATEGY_ALL.equals(volumeBehavior))) {
      continue;
    }
    if (VOLUME_CLEANUP_STRATEGY_UNNAMED.equals(volumeBehavior) &&
        ((StringUtils.length(v.getName()) != 64 || !StringUtils.isAlphanumeric(v.getName()))) && !StringUtils.startsWith(v.getName(), "/")) {
      continue;
    }
    if (CommonStatesConstants.ACTIVE.equals(v.getState()) || CommonStatesConstants.ACTIVATING.equals(v.getState())) {
      objectProcessManager.scheduleStandardProcess(StandardProcess.DEACTIVATE, v,
          ProcessUtils.chainInData(state.getData(), VolumeConstants.PROCESS_DEACTIVATE, VolumeConstants.PROCESS_REMOVE));
    } else {
      objectProcessManager.scheduleStandardProcess(StandardProcess.REMOVE, v, state.getData());
    }
  }
}

代码示例来源:origin: rancher/cattle

name = v.getName();
if (!VolumeConstants.ACCESS_MODE_SINGLE_INSTANCE_RW.equals(v.getAccessMode())) {
  objectManager.setFields(v, VOLUME.ACCESS_MODE, VolumeConstants.ACCESS_MODE_SINGLE_INSTANCE_RW);

代码示例来源:origin: rancher/cattle

locks.add(new AllocateConstraintLock(AllocateConstraintLock.Type.VOLUME, v.getId().toString()));
StorageDriver driver = objectManager.loadResource(StorageDriver.class, volume.getStorageDriverId());
if (driver != null) {
  String accessMode = DataAccessor.fieldString(driver, StorageDriverConstants.FIELD_VOLUME_ACCESS_MODE);
  if (VolumeConstants.ACCESS_MODE_SINGLE_HOST_RW.equals(accessMode) || VolumeConstants.ACCESS_MODE_SINGLE_INSTANCE_RW.equals(accessMode)) {
    locks.add(new AllocateConstraintLock(AllocateConstraintLock.Type.VOLUME, volume.getId().toString()));

代码示例来源:origin: rancher/cattle

if (CommonStatesConstants.REQUESTED.equals(volume.getState())) {
  action = "Created";
  objectProcessManager.scheduleStandardProcess(StandardProcess.CREATE, volume, state.getData());
  action = "Using existing";
log.debug("{} volume [{}] in storage pool [{}].", action, volume.getId(), pool.getId());
log.info("Volme mount created. Volume id [{}], instance id [{}], mount id [{}]", volume.getId(), instance.getId(), mount.getId());
objectProcessManager.scheduleStandardProcess(StandardProcess.CREATE, mount, null);

代码示例来源:origin: rancher/cattle

@Override
  public Object perform(String name, Object obj, ApiRequest request) {
    if (!(obj instanceof Volume)) {
      return null;
    }
    Volume volume = (Volume)obj;
    Snapshot snapshot = objectManager.newRecord(Snapshot.class);
    snapshot.setKind(SnapshotConstants.TYPE);
    snapshot.setAccountId(volume.getAccountId());
    snapshot.setVolumeId(volume.getId());

    String snapshotName = DataAccessor.fromMap(request.getRequestObject()).withKey("name").as(String.class);
    if (StringUtils.isNotBlank(snapshotName)) {
      snapshot.setName(snapshotName);
    }

    snapshot = objectManager.create(snapshot);
    processManager.scheduleStandardProcess(StandardProcess.CREATE, snapshot, null);
    return objectManager.reload(snapshot);
  }
}

代码示例来源:origin: rancher/cattle

void updateVolumeHostInfo(AllocationAttempt attempt, AllocationCandidate candidate, Long newHost) {
  List<Object> storageDriverIds = new ArrayList<>();
  for (Volume v : attempt.getVolumes()) {
    if (v.getStorageDriverId() != null) {
      storageDriverIds.add(v.getStorageDriverId());
    StorageDriver d = v.getStorageDriverId() != null ? storageDrivers.get(v.getStorageDriverId()) : null;
    if (d != null && StorageDriverConstants.SCOPE_LOCAL.equals(DataAccessor.fieldString(d, StorageDriverConstants.FIELD_SCOPE))) {
      persist = true;
      getAllocatedHostUuidProp(v).set(candidate.getHostUuid());
    if (VolumeConstants.ACCESS_MODE_SINGLE_HOST_RW.equals(v.getAccessMode())) {
      persist = true;
      DataAccessor.fromDataFieldOf(v).withKey(VolumeConstants.FIELD_LAST_ALLOCATED_HOST_ID).set(newHost);

代码示例来源:origin: rancher/cattle

restrictToUnmanagedPool = true;
  if (StringUtils.isNotEmpty(driver) && !VolumeConstants.LOCAL_DRIVER.equals(driver)) {
    List<? extends StoragePool> pools = storagePoolDao.findStoragePoolByDriverName(volume.getAccountId(), driver);
    if (pools.size() > 0) {
      Set<Long> poolIds = new HashSet<>();
  Instance instance = objectManager.loadResource(Instance.class, volume.getInstanceId());
  if (instance != null) {
    Host host = allocatorDao.getHost(instance);
if (restrictToUnmanagedPool || volume.getImageId() != null) {
  constraints.add(new UnmanagedStoragePoolKindConstraint(volume));

代码示例来源:origin: rancher/cattle

private List<String> processManagedVolumes(Instance instance) {
  List<String> dataVolumes = DataAccessor.fieldStringList(instance, InstanceConstants.FIELD_DATA_VOLUMES);
  if (dataVolumes == null) {
    dataVolumes = new ArrayList<String>();
  }
  Map<String, Object> dataVolumeMounts = DataAccessor.fieldMap(instance, InstanceConstants.FIELD_DATA_VOLUME_MOUNTS);
  if (dataVolumeMounts == null) {
    return dataVolumes;
  }
  for (Map.Entry<String, Object> mountedVols : dataVolumeMounts.entrySet()) {
    Long volId = ((Number) mountedVols.getValue()).longValue();
    Volume vol = objectManager.loadResource(Volume.class, volId);
    if (vol != null) {
      String volDescriptor = vol.getName() + ":" + mountedVols.getKey().trim();
      if (!dataVolumes.contains(volDescriptor)) {
        dataVolumes.add(volDescriptor);
      }
    }
  }
  return dataVolumes;
}

代码示例来源:origin: rancher/cattle

@Override
  protected void doRun() throws Exception {
    log.warn("Removing invalid volume [{}]", ObjectUtils.toStringWrapper(vol));
    if (VolumeConstants.STATE_DETACHED.equals(vol.getState())) {
      processManager.scheduleStandardProcessAsync(StandardProcess.REMOVE, vol, null);
    } else {
      processManager.scheduleStandardChainedProcessAsync(StandardProcess.DEACTIVATE, StandardProcess.REMOVE, vol, null);
    }
  }
});

代码示例来源:origin: rancher/cattle

protected void populateVolume(Map<String, Object> instanceMetadata, Instance instance, Volume volume) {
  if (volume == null) {
    return;
  }
  Integer deviceNumber = volume.getDeviceNumber();
  if (deviceNumber == null) {
    return;
  }
  char index = (char) ('a' + deviceNumber.intValue());
  if (deviceNumber == 0) {
    setNestedValue(instanceMetadata, String.format("/dev/sd%s", index), "block-device-mapping", "ami");
    setNestedValue(instanceMetadata, String.format("/dev/sd%s1", index), "block-device-mapping", "root");
  } else {
    setNestedValue(instanceMetadata, "sd" + index, "block-device-mapping", "ebs" + (deviceNumber + 1));
  }
  // TODO do something about swap and ephemeral
}

相关文章