Search in sources :

Example 6 with VDSReturnValue

use of org.ovirt.engine.core.common.vdscommands.VDSReturnValue in project ovirt-engine by oVirt.

the class GlusterHookStatusChangeCommand method executeCommand.

@Override
protected void executeCommand() {
    entity = getGlusterHook();
    addCustomValue(GlusterConstants.HOOK_NAME, entity.getName());
    if (getAllUpServers().size() < clusterUtils.getServerCount(getGlusterHook().getClusterId())) {
        errors.add(EngineMessage.CLUSTER_ALL_SERVERS_NOT_UP.toString());
    }
    List<Callable<Pair<VDS, VDSReturnValue>>> taskList = new ArrayList<>();
    for (final VDS upServer : getAllUpServers()) {
        taskList.add(() -> {
            VDSReturnValue returnValue = runVdsCommand(getStatusChangeVDSCommand(), new GlusterHookVDSParameters(upServer.getId(), entity.getGlusterCommand(), entity.getStage(), entity.getName()));
            return new Pair<>(upServer, returnValue);
        });
    }
    boolean atLeastOneSuccess = false;
    List<Pair<VDS, VDSReturnValue>> pairResults = ThreadPoolUtil.invokeAll(taskList);
    for (Pair<VDS, VDSReturnValue> pairResult : pairResults) {
        VDSReturnValue retValue = pairResult.getSecond();
        if (retValue.getSucceeded()) {
            atLeastOneSuccess = true;
            // update status in database
            updateServerHookStatusInDb(getGlusterHook().getId(), pairResult.getFirst().getId(), getNewStatus());
        } else {
            errors.add(retValue.getVdsError().getMessage());
        }
    }
    setSucceeded(atLeastOneSuccess);
    if (errors.size() > 0) {
        // conflict in status
        entity.addStatusConflict();
        handleVdsErrors(getAuditLogTypeValue(), errors);
        addCustomValue(GlusterConstants.FAILURE_MESSAGE, StringUtils.join(errors, System.lineSeparator()));
    }
    // The intention was to enable/disable hook. So we update the entity with new status if command succeeded
    if (getSucceeded()) {
        entity.setStatus(getNewStatus());
        // no longer conflicts as all hooks have same status
        entity.removeStatusConflict();
        updateHookInDb(entity);
        if (entity.getConflictStatus() == 0) {
            // all conflicts have been resolved, remove server hooks
            glusterHooksDao.removeGlusterServerHooks(entity.getId());
        }
    }
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) ArrayList(java.util.ArrayList) GlusterHookVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.GlusterHookVDSParameters) Callable(java.util.concurrent.Callable) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 7 with VDSReturnValue

use of org.ovirt.engine.core.common.vdscommands.VDSReturnValue in project ovirt-engine by oVirt.

the class GlusterHookSyncJob method saveHookContent.

private void saveHookContent(List<Callable<Pair<GlusterHookEntity, VDSReturnValue>>> contentTasksList) {
    if (contentTasksList.isEmpty()) {
        return;
    }
    List<Pair<GlusterHookEntity, VDSReturnValue>> pairResults = ThreadPoolUtil.invokeAll(contentTasksList);
    for (Pair<GlusterHookEntity, VDSReturnValue> pairResult : pairResults) {
        final GlusterHookEntity hook = pairResult.getFirst();
        if (!pairResult.getSecond().getSucceeded()) {
            log.info("Failed to get content of hook '{}' with error: {}", hook.getHookKey(), pairResult.getSecond().getVdsError().getMessage());
            logMessage(hook.getClusterId(), hook.getHookKey(), AuditLogType.GLUSTER_HOOK_GETCONTENT_FAILED);
            continue;
        }
        final String content = (String) pairResult.getSecond().getReturnValue();
        hooksDao.updateGlusterHookContent(hook.getId(), hook.getChecksum(), content);
    }
}
Also used : GlusterHookEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity) Pair(org.ovirt.engine.core.common.utils.Pair) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 8 with VDSReturnValue

use of org.ovirt.engine.core.common.vdscommands.VDSReturnValue in project ovirt-engine by oVirt.

the class CommitRemoveGlusterVolumeBricksCommand method executeCommand.

@Override
protected void executeCommand() {
    GlusterVolumeEntity volume = getGlusterVolume();
    VDSReturnValue returnValue = runVdsCommand(VDSCommandType.CommitRemoveGlusterVolumeBricks, new GlusterVolumeRemoveBricksVDSParameters(getUpServer().getId(), volume.getName(), getParameters().getBricks()));
    setSucceeded(returnValue.getSucceeded());
    if (!getSucceeded()) {
        handleVdsError(AuditLogType.GLUSTER_VOLUME_REMOVE_BRICKS_COMMIT_FAILED, returnValue.getVdsError().getMessage());
        return;
    }
    addCustomValue(GlusterConstants.NO_OF_BRICKS, String.valueOf(getParameters().getBricks().size()));
    endStepJobCommitted();
    glusterDBUtils.removeBricksFromVolumeInDb(volume, getParameters().getBricks(), getParameters().getReplicaCount());
    glusterVolumeDao.updateVolumeTask(volume.getId(), null);
    releaseVolumeLock();
    getReturnValue().setActionReturnValue(returnValue.getReturnValue());
}
Also used : GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) GlusterVolumeRemoveBricksVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeRemoveBricksVDSParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 9 with VDSReturnValue

use of org.ovirt.engine.core.common.vdscommands.VDSReturnValue in project ovirt-engine by oVirt.

the class CreateGlusterVolumeCommand method executeCommand.

/*
     * (non-Javadoc)
     *
     * @see org.ovirt.engine.core.bll.CommandBase#executeCommand()
     */
@Override
protected void executeCommand() {
    // set the gluster volume name for audit purpose
    setGlusterVolumeName(getVolume().getName());
    if (getVolume().getTransportTypes() == null || getVolume().getTransportTypes().isEmpty()) {
        getVolume().addTransportType(TransportType.TCP);
    }
    // GLUSTER access protocol is enabled by default
    getVolume().addAccessProtocol(AccessProtocol.GLUSTER);
    if (!getVolume().getAccessProtocols().contains(AccessProtocol.NFS)) {
        getVolume().disableNFS();
    }
    if (getVolume().getAccessProtocols().contains(AccessProtocol.CIFS)) {
        getVolume().enableCifs();
    }
    VDSReturnValue returnValue = runVdsCommand(VDSCommandType.CreateGlusterVolume, new CreateGlusterVolumeVDSParameters(upServer.getId(), getVolume(), upServer.getClusterCompatibilityVersion(), getParameters().isForce()));
    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());
    if (createdVolume.getIsArbiter()) {
        setArbiterFlag(createdVolume);
    }
    addVolumeToDb(createdVolume);
    // If we log successful volume creation at the end of this command,
    // the messages from SetGlusterVolumeOptionCommand appear first,
    // making it look like options were set before volume was created.
    // Hence we explicitly log the volume creation before setting the options.
    auditLogDirector.log(this, AuditLogType.GLUSTER_VOLUME_CREATE);
    // And don't log it at the end
    setCommandShouldBeLogged(false);
    // set all options of the volume
    setVolumeOptions(createdVolume);
    getReturnValue().setActionReturnValue(createdVolume.getId());
}
Also used : GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) CreateGlusterVolumeVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.CreateGlusterVolumeVDSParameters)

Example 10 with VDSReturnValue

use of org.ovirt.engine.core.common.vdscommands.VDSReturnValue in project ovirt-engine by oVirt.

the class CreateGlusterVolumeGeoRepSessionCommand method executeCommand.

@Override
protected void executeCommand() {
    boolean rootSession = getParameters().getUserName().equalsIgnoreCase("root");
    boolean succeeded = true;
    Set<Guid> remoteServerIds = getServerIds(remoteServersSet);
    Guid slaveHostId = getParameters().getSlaveHostId();
    if (!rootSession) {
        ActionReturnValue completeMountBrokerSetupOnSlaveInternalAction = backend.runInternalAction(ActionType.SetupGlusterGeoRepMountBrokerInternal, new SetUpMountBrokerParameters(vdsDao.get(slaveHostId).getClusterId(), new HashSet<>(Collections.singletonList(getParameters().getSlaveHostId())), getParameters().getSlaveVolumeName(), getParameters().getUserName(), getParameters().getUserGroup()));
        succeeded = evaluateReturnValue(AuditLogType.GLUSTER_GEOREP_SETUP_MOUNT_BROKER_FAILED, completeMountBrokerSetupOnSlaveInternalAction);
        remoteServerIds.remove(slaveHostId);
        if (succeeded) {
            auditLogDirector.log(this, AuditLogType.GLUSTER_SETUP_GEOREP_MOUNT_BROKER);
            if (!remoteServerIds.isEmpty()) {
                ActionReturnValue mountBrokerPartialSetupInternalAction = backend.runInternalAction(ActionType.SetupGlusterGeoRepMountBrokerInternal, new SetUpMountBrokerParameters(vdsDao.get(slaveHostId).getClusterId(), remoteServerIds, getParameters().getSlaveVolumeName(), getParameters().getUserName()));
                succeeded = evaluateReturnValue(AuditLogType.GLUSTER_GEOREP_SETUP_MOUNT_BROKER_FAILED, mountBrokerPartialSetupInternalAction);
                if (succeeded) {
                    auditLogDirector.log(this, AuditLogType.GLUSTER_SETUP_GEOREP_MOUNT_BROKER);
                }
            }
        }
    }
    if (succeeded) {
        remoteServerIds.add(slaveHostId);
        ActionReturnValue setUpPasswordLessSSHinternalAction = runInternalAction(ActionType.SetUpPasswordLessSSHInternal, new SetUpPasswordLessSSHParameters(upServer.getClusterId(), remoteServerIds, getParameters().getUserName()));
        succeeded = evaluateReturnValue(errorType, setUpPasswordLessSSHinternalAction);
        if (succeeded) {
            auditLogDirector.log(this, AuditLogType.SET_UP_PASSWORDLESS_SSH);
            VDSReturnValue createVdsReturnValue = runVdsCommand(VDSCommandType.CreateGlusterVolumeGeoRepSession, new GlusterVolumeGeoRepSessionVDSParameters(upServer.getId(), getGlusterVolumeName(), vdsDao.get(slaveHostId).getHostName(), getParameters().getSlaveVolumeName(), getParameters().getUserName(), getParameters().isForce()));
            succeeded = evaluateReturnValue(AuditLogType.GLUSTER_GEOREP_SESSION_CREATE_FAILED, createVdsReturnValue);
            if (succeeded) {
                glusterGeoRepSyncJob.refreshGeoRepDataForVolume(getGlusterVolume());
            }
        }
    }
    setSucceeded(succeeded);
}
Also used : SetUpMountBrokerParameters(org.ovirt.engine.core.common.action.gluster.SetUpMountBrokerParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) GlusterVolumeGeoRepSessionVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeGeoRepSessionVDSParameters) Guid(org.ovirt.engine.core.compat.Guid) SetUpPasswordLessSSHParameters(org.ovirt.engine.core.common.action.gluster.SetUpPasswordLessSSHParameters) HashSet(java.util.HashSet) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Aggregations

VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)250 Guid (org.ovirt.engine.core.compat.Guid)65 ArrayList (java.util.ArrayList)43 VDS (org.ovirt.engine.core.common.businessentities.VDS)29 EngineException (org.ovirt.engine.core.common.errors.EngineException)29 Pair (org.ovirt.engine.core.common.utils.Pair)26 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)23 List (java.util.List)16 Test (org.junit.Test)15 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)15 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)15 VdsIdVDSCommandParametersBase (org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase)15 HashMap (java.util.HashMap)13 VDSError (org.ovirt.engine.core.common.errors.VDSError)13 Map (java.util.Map)11 Callable (java.util.concurrent.Callable)11 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)11 StoragePoolIsoMap (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap)11 EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)9 GlusterGeoRepSession (org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession)8