Exemplo n.º 1
0
  @Override
  public HandlerResult handle(ProcessState state, ProcessInstance process) {
    Volume volume = (Volume) state.getResource();

    deallocate(volume, state.getData());

    for (VolumeStoragePoolMap map :
        mapDao.findToRemove(VolumeStoragePoolMap.class, Volume.class, volume.getId())) {
      try {
        objectProcessManager.scheduleStandardProcess(
            StandardProcess.DEACTIVATE,
            map,
            ProcessUtils.chainInData(
                state.getData(), "volumestoragepoolmap.deactivate", "volumestoragepoolmap.remove"));
      } catch (ProcessCancelException e) {
        objectProcessManager.scheduleStandardProcess(StandardProcess.REMOVE, map, null);
      }
    }

    for (Mount mount : mapDao.findToRemove(Mount.class, Volume.class, volume.getId())) {
      try {
        objectProcessManager.scheduleStandardProcess(
            StandardProcess.DEACTIVATE,
            mount,
            ProcessUtils.chainInData(state.getData(), "mount.deactivate", "mount.remove"));
      } catch (ProcessCancelException e) {
        objectProcessManager.scheduleStandardProcess(StandardProcess.REMOVE, mount, null);
      }
    }

    return new HandlerResult();
  }
Exemplo n.º 2
0
  @Override
  public boolean isVolumeInstanceImageKind(long volumeId, String kind) {
    Volume volume = objectManager.loadResource(Volume.class, volumeId);
    Long instanceId = volume.getInstanceId();

    return instanceId == null ? false : isInstanceImageKind(instanceId, kind);
  }
Exemplo n.º 3
0
  @Override
  public HandlerResult handle(ProcessState state, ProcessInstance process) {
    final Instance instance = (Instance) state.getResource();

    List<Volume> volumes = InstanceHelpers.extractVolumesFromMounts(instance, objectManager);
    for (final Volume v : volumes) {
      String driver = DataAccessor.fieldString(v, VolumeConstants.FIELD_VOLUME_DRIVER);
      if (StringUtils.isNotEmpty(driver) && !VolumeConstants.LOCAL_DRIVER.equals(driver)) {
        StoragePool sp = storagePoolDao.findStoragePoolByDriverName(v.getAccountId(), driver);
        if (sp == null) {
          continue;
        }
        final String accessMode = sp.getVolumeAccessMode();
        if (StringUtils.isNotEmpty(accessMode)
            && StringUtils.isEmpty(v.getAccessMode())
            && !accessMode.equals(v.getAccessMode())) {
          lockManager.lock(
              new InstanceVolumeAccessModeLock(v.getId()),
              new LockCallbackNoReturn() {
                @Override
                public void doWithLockNoResult() {
                  objectManager.setFields(v, VOLUME.ACCESS_MODE, accessMode);
                }
              });
        }
      }
    }

    return null;
  }
Exemplo n.º 4
0
 @Override
 public List<? extends StoragePool> getAssociatedPools(Volume volume) {
   return create()
       .select(STORAGE_POOL.fields())
       .from(STORAGE_POOL)
       .join(VOLUME_STORAGE_POOL_MAP)
       .on(VOLUME_STORAGE_POOL_MAP.STORAGE_POOL_ID.eq(STORAGE_POOL.ID))
       .where(
           VOLUME_STORAGE_POOL_MAP
               .REMOVED
               .isNull()
               .and(VOLUME_STORAGE_POOL_MAP.VOLUME_ID.eq(volume.getId())))
       .fetchInto(StoragePoolRecord.class);
 }
Exemplo n.º 5
0
  @Override
  public boolean recordCandidate(AllocationAttempt attempt, AllocationCandidate candidate) {
    Long newHost = candidate.getHost();
    if (newHost != null) {
      for (Instance instance : attempt.getInstances()) {
        log.info("Associating instance [{}] to host [{}]", instance.getId(), newHost);
        objectManager.create(
            InstanceHostMap.class,
            INSTANCE_HOST_MAP.HOST_ID,
            newHost,
            INSTANCE_HOST_MAP.INSTANCE_ID,
            instance.getId());

        modifyDisk(newHost, instance, true);

        List<Volume> vols = InstanceHelpers.extractVolumesFromMounts(instance, objectManager);
        for (Volume v : vols) {
          if (VolumeConstants.ACCESS_MODE_SINGLE_HOST_RW.equals(v.getAccessMode())) {
            objectManager.setFields(v, VOLUME.HOST_ID, newHost);
          }
        }
      }
    }

    Map<Long, Set<Long>> existingPools = attempt.getPoolIds();
    Map<Long, Set<Long>> newPools = candidate.getPools();

    if (!existingPools.keySet().equals(newPools.keySet())) {
      throw new IllegalStateException(
          String.format(
              "Volumes don't match. currently %s, new %s",
              existingPools.keySet(), newPools.keySet()));
    }

    for (Map.Entry<Long, Set<Long>> entry : newPools.entrySet()) {
      long volumeId = entry.getKey();
      Set<Long> existingPoolsForVol = existingPools.get(entry.getKey());
      Set<Long> newPoolsForVol = entry.getValue();
      if (existingPoolsForVol == null || existingPoolsForVol.size() == 0) {
        for (long poolId : newPoolsForVol) {
          log.info("Associating volume [{}] to storage pool [{}]", volumeId, poolId);
          objectManager.create(
              VolumeStoragePoolMap.class,
              VOLUME_STORAGE_POOL_MAP.VOLUME_ID,
              volumeId,
              VOLUME_STORAGE_POOL_MAP.STORAGE_POOL_ID,
              poolId);
        }
      } else if (!existingPoolsForVol.equals(newPoolsForVol)) {
        throw new IllegalStateException(
            String.format(
                "Can not move volume %s, currently: %s, new: %s",
                volumeId, existingPools, newPools));
      }
    }

    for (Nic nic : attempt.getNics()) {
      Long subnetId = candidate.getSubnetIds().get(nic.getId());

      if (subnetId == null
          || (nic.getSubnetId() != null && subnetId.longValue() == nic.getSubnetId())) {
        continue;
      }

      log.info("Associating nic [{}] to subnet [{}]", nic.getId(), subnetId);
      int i =
          create().update(NIC).set(NIC.SUBNET_ID, subnetId).where(NIC.ID.eq(nic.getId())).execute();

      if (i != 1) {
        throw new IllegalStateException(
            "Expected to update nic id ["
                + nic.getId()
                + "] with subnet ["
                + subnetId
                + "] but update ["
                + i
                + "] rows");
      }
    }

    return true;
  }