@Override
  protected boolean canDoAction() {
    if (!super.canDoAction()) {
      return false;
    }

    VDSGroup cluster = getVdsGroup();
    if (cluster == null) {
      addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_CLUSTER_IS_NOT_VALID);
      return false;
    }

    if (!cluster.supportsGlusterService()) {
      addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_CLUSTER_DOES_NOT_SUPPORT_GLUSTER);
      return false;
    }

    if (volumeNameExists(volume.getName())) {
      addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_GLUSTER_VOLUME_NAME_ALREADY_EXISTS);
      addCanDoActionMessage(String.format("$volumeName %1$s", volume.getName()));
      return false;
    }

    return validateBricks(volume);
  }
  @SuppressWarnings("unchecked")
  private void setupMocks() throws Exception {
    logUtil = spy(GlusterAuditLogUtil.getInstance());
    glusterManager.setLogUtil(logUtil);
    mockDaos();

    doReturn(glusterUtil).when(glusterManager).getGlusterUtil();
    doReturn(existingServer1).when(glusterUtil).getUpServer(any(Guid.class));
    doReturn(existingServer1).when(glusterUtil).getRandomUpServer(any(Guid.class));

    doNothing().when(logUtil).logServerMessage(any(VDS.class), any(AuditLogType.class));
    doNothing()
        .when(logUtil)
        .logVolumeMessage(any(GlusterVolumeEntity.class), any(AuditLogType.class));
    doNothing()
        .when(logUtil)
        .logAuditMessage(
            any(Guid.class),
            any(GlusterVolumeEntity.class),
            any(VDS.class),
            any(AuditLogType.class),
            any(HashMap.class));
    doNothing()
        .when(logUtil)
        .logAuditMessage(
            any(Guid.class),
            any(GlusterVolumeEntity.class),
            any(VDS.class),
            any(AuditLogType.class),
            any(Guid.class),
            any(String.class));
    doReturn(getFetchedServersList()).when(glusterManager).fetchServers(any(VDS.class));
    doReturn(getFetchedVolumesList()).when(glusterManager).fetchVolumes(any(VDS.class));
    doReturn(getVolumeAdvancedDetails(existingDistVol))
        .when(glusterManager)
        .getVolumeAdvancedDetails(existingServer1, CLUSTER_ID, existingDistVol.getName());
    doReturn(getVolumeAdvancedDetails(existingReplVol))
        .when(glusterManager)
        .getVolumeAdvancedDetails(existingServer1, CLUSTER_ID, existingReplVol.getName());
    doReturn(new VDSReturnValue())
        .when(glusterManager)
        .runVdsCommand(eq(VDSCommandType.RemoveVds), argThat(isRemovedServer()));
    doReturn(mockVdcReturn())
        .when(backend)
        .runInternalAction(
            any(VdcActionType.class),
            any(VdcActionParametersBase.class),
            any(CommandContext.class));

    doNothing().when(glusterManager).acquireLock(CLUSTER_ID);
    doNothing().when(glusterManager).releaseLock(CLUSTER_ID);
    doReturn(glusterUtil).when(glusterManager).getGlusterUtil();
  }
  private void verifyMocksForHeavyWeight() {
    InOrder inOrder = inOrder(clusterDao, glusterUtil, volumeDao, glusterManager, brickDao);

    // all clusters fetched from db
    inOrder.verify(clusterDao, times(1)).getAll();

    VerificationMode mode = times(1);

    // get the UP server from cluster
    inOrder.verify(glusterUtil, mode).getRandomUpServer(CLUSTER_ID);

    // get volumes of the cluster
    inOrder.verify(volumeDao, mode).getByClusterId(CLUSTER_ID);

    // acquire lock on the cluster
    inOrder.verify(glusterManager, mode).acquireLock(CLUSTER_ID);

    // get volume advance details
    inOrder
        .verify(glusterManager, mode)
        .getVolumeAdvancedDetails(existingServer1, CLUSTER_ID, existingDistVol.getName());

    // Update capacity info
    inOrder
        .verify(volumeDao, mode)
        .updateVolumeCapacityInfo(getVolumeAdvancedDetails(existingDistVol).getCapacityInfo());
    // release lock on the cluster
    inOrder.verify(glusterManager, mode).releaseLock(CLUSTER_ID);

    // acquire lock on the cluster for repl volume
    inOrder.verify(glusterManager, mode).acquireLock(CLUSTER_ID);

    // get volume advance details of repl volume
    inOrder
        .verify(glusterManager, mode)
        .getVolumeAdvancedDetails(existingServer1, CLUSTER_ID, existingReplVol.getName());

    // Add Capacity Info
    inOrder
        .verify(volumeDao, mode)
        .addVolumeCapacityInfo(getVolumeAdvancedDetails(existingReplVol).getCapacityInfo());

    // Add Capacity Info
    inOrder.verify(brickDao, mode).addBrickProperties(any(List.class));

    // update brick status
    inOrder.verify(brickDao, mode).updateBrickStatuses(argThat(hasBricksWithChangedStatus()));

    // release lock on the cluster
    inOrder.verify(glusterManager, mode).releaseLock(CLUSTER_ID);
  }
  /*
   * (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());
  }