Ejemplo n.º 1
0
  /**
   * Returns the list of volumes as if they were fetched from glusterfs. Changes from existing
   * volumes are:<br>
   * - existingDistVol not fetched (means it was removed from gluster cli, and should be removed
   * from db<br>
   * - option 'auth.allow' removed from the existingReplVol<br>
   * - new option 'auth.reject' added to existingReplVol<br>
   * - value of option 'nfs.disable' changed from 'off' ot 'on' in existingReplVol<br>
   * - new volume test-new-vol fetched from gluster (means it was added from gluster cli, and should
   * be added to db<br>
   */
  private Map<Guid, GlusterVolumeEntity> getFetchedVolumesList() {
    Map<Guid, GlusterVolumeEntity> volumes = new HashMap<>();

    GlusterVolumeEntity fetchedReplVol = createReplVol();
    fetchedReplVol.removeOption(OPTION_AUTH_ALLOW); // option removed
    fetchedReplVol.setOption(OPTION_AUTH_REJECT, AUTH_REJECT_IP); // added
    fetchedReplVol.setOption(OPTION_NFS_DISABLE, OPTION_VALUE_ON); // changed

    // brick changes
    removedBrickIds.add(
        GlusterCoreUtil.findBrick(existingReplVol.getBricks(), SERVER_ID_1, REPL_BRICK_R1D1)
            .getId());
    removedBrickIds.add(
        GlusterCoreUtil.findBrick(existingReplVol.getBricks(), SERVER_ID_1, REPL_BRICK_R2D1)
            .getId());

    GlusterBrickEntity brickToReplace =
        GlusterCoreUtil.findBrick(fetchedReplVol.getBricks(), SERVER_ID_1, REPL_BRICK_R1D1);
    replaceBrick(brickToReplace, SERVER_ID_1, REPL_BRICK_R1D1_NEW);

    brickToReplace =
        GlusterCoreUtil.findBrick(fetchedReplVol.getBricks(), SERVER_ID_1, REPL_BRICK_R2D1);
    replaceBrick(brickToReplace, SERVER_ID_1, REPL_BRICK_R2D1_NEW);
    volumes.put(fetchedReplVol.getId(), fetchedReplVol);

    // add a new volume
    newVolume = getNewVolume();
    volumes.put(newVolume.getId(), newVolume);

    return volumes;
  }
 private void setVolumeType(GlusterVolumeEntity createdVolume) {
   if (createdVolume.getVolumeType() == GlusterVolumeType.REPLICATE
       && createdVolume.getBricks().size() > createdVolume.getReplicaCount()) {
     createdVolume.setVolumeType(GlusterVolumeType.DISTRIBUTED_REPLICATE);
   } else if (createdVolume.getVolumeType() == GlusterVolumeType.DISTRIBUTED_REPLICATE
       && createdVolume.getBricks().size() == createdVolume.getReplicaCount()) {
     createdVolume.setVolumeType(GlusterVolumeType.REPLICATE);
   } else if (createdVolume.getVolumeType() == GlusterVolumeType.STRIPE
       && createdVolume.getBricks().size() > createdVolume.getStripeCount()) {
     createdVolume.setVolumeType(GlusterVolumeType.DISTRIBUTED_STRIPE);
   } else if (createdVolume.getVolumeType() == GlusterVolumeType.DISTRIBUTED_STRIPE
       && createdVolume.getBricks().size() == createdVolume.getStripeCount()) {
     createdVolume.setVolumeType(GlusterVolumeType.STRIPE);
   }
 }
Ejemplo n.º 3
0
  private GlusterVolumeAdvancedDetails getVolumeAdvancedDetails(GlusterVolumeEntity volume) {
    GlusterVolumeAdvancedDetails volDetails = new GlusterVolumeAdvancedDetails();
    GlusterVolumeSizeInfo capacityInfo = new GlusterVolumeSizeInfo();
    capacityInfo.setVolumeId(volume.getId());
    capacityInfo.setTotalSize(600000L);
    capacityInfo.setFreeSize(200000L);
    capacityInfo.setUsedSize(400000L);
    volDetails.setCapacityInfo(capacityInfo);

    List<BrickDetails> brickDetailsList = new ArrayList<>();
    for (GlusterBrickEntity brick : volume.getBricks()) {
      BrickDetails brickDetails = new BrickDetails();
      BrickProperties properties = new BrickProperties();
      properties.setBrickId(brick.getId());
      brickDetails.setBrickProperties(properties);
      properties.setStatus(brick.getStatus());
      if (volume == existingReplVol) {
        if (brick.getServerId().equals(SERVER_ID_1)
            && (brick.getBrickDirectory().equals(REPL_BRICK_R1D1)
                || brick.getBrickDirectory().equals(REPL_BRICK_R2D1))) {
          properties.setStatus(GlusterStatus.DOWN);
          bricksWithChangedStatus.add(brick);
        }
      }
      brickDetailsList.add(brickDetails);
    }
    volDetails.setBrickDetails(brickDetailsList);

    return volDetails;
  }
  /**
   * Validates the the number of bricks against the replica count or stripe count based on volume
   * type
   *
   * @param volume
   * @return
   */
  private boolean validateBricks(GlusterVolumeEntity volume) {
    List<GlusterBrickEntity> bricks = volume.getBricks();
    if (bricks.isEmpty()) {
      addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_BRICKS_REQUIRED);
      return false;
    }

    int brickCount = bricks.size();
    int replicaCount = volume.getReplicaCount();
    int stripeCount = volume.getStripeCount();

    switch (volume.getVolumeType()) {
      case REPLICATE:
        if (replicaCount < 2) {
          addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_REPLICA_COUNT_MIN_2);
          return false;
        }

        if (brickCount != replicaCount) {
          addCanDoActionMessage(
              VdcBllMessages.ACTION_TYPE_FAILED_INVALID_BRICK_COUNT_FOR_REPLICATE);
          return false;
        }
        break;
      case DISTRIBUTED_REPLICATE:
        if (replicaCount < 2) {
          addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_REPLICA_COUNT_MIN_2);
          return false;
        }
        if (brickCount < replicaCount || Math.IEEEremainder(brickCount, replicaCount) != 0) {
          addCanDoActionMessage(
              VdcBllMessages.ACTION_TYPE_FAILED_INVALID_BRICK_COUNT_FOR_DISTRIBUTED_REPLICATE);
          return false;
        }
        break;
      case STRIPE:
        if (stripeCount < 4) {
          addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_STRIPE_COUNT_MIN_4);
          return false;
        }
        if (brickCount != stripeCount) {
          addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_INVALID_BRICK_COUNT_FOR_STRIPE);
          return false;
        }
        break;
      case DISTRIBUTED_STRIPE:
        if (stripeCount < 4) {
          addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_STRIPE_COUNT_MIN_4);
          return false;
        }
        if (brickCount < stripeCount || Math.IEEEremainder(brickCount, stripeCount) != 0) {
          addCanDoActionMessage(
              VdcBllMessages.ACTION_TYPE_FAILED_INVALID_BRICK_COUNT_FOR_DISTRIBUTED_STRIPE);
          return false;
        }
        break;
    }

    return updateBrickServerNames(bricks, true);
  }
  /*
   * (non-Javadoc)
   *
   * @see org.ovirt.engine.core.bll.CommandBase#executeCommand()
   */
  @Override
  protected void executeCommand() {
    // set the gluster volume name for audit purpose
    setGlusterVolumeName(volume.getName());

    if (volume.getTransportTypes() == null || volume.getTransportTypes().isEmpty()) {
      volume.addTransportType(TransportType.TCP);
    }

    // GLUSTER access protocol is enabled by default
    volume.addAccessProtocol(AccessProtocol.GLUSTER);
    if (!volume.getAccessProtocols().contains(AccessProtocol.NFS)) {
      volume.disableNFS();
    }

    VDSReturnValue returnValue =
        runVdsCommand(
            VDSCommandType.CreateGlusterVolume,
            new CreateGlusterVolumeVDSParameters(upServer.getId(), volume));
    setSucceeded(returnValue.getSucceeded());

    if (!getSucceeded()) {
      handleVdsError(
          AuditLogType.GLUSTER_VOLUME_CREATE_FAILED, returnValue.getVdsError().getMessage());
      return;
    }

    // Volume created successfully. Insert it to database.
    GlusterVolumeEntity createdVolume = (GlusterVolumeEntity) returnValue.getReturnValue();
    setVolumeType(createdVolume);
    setBrickOrder(createdVolume.getBricks());
    addVolumeToDb(createdVolume);

    // set all options of the volume
    setVolumeOptions(createdVolume);

    getReturnValue().setActionReturnValue(createdVolume.getId());
  }