Search in sources :

Example 1 with GlusterHookVDSParameters

use of org.ovirt.engine.core.common.vdscommands.gluster.GlusterHookVDSParameters 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 2 with GlusterHookVDSParameters

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

the class RemoveGlusterHookCommand method executeCommand.

@Override
protected void executeCommand() {
    entity = getGlusterHook();
    addCustomValue(GlusterConstants.HOOK_NAME, entity.getName());
    List<Callable<Pair<VDS, VDSReturnValue>>> taskList = new ArrayList<>();
    for (final VDS server : getServersInCluster()) {
        taskList.add(() -> {
            VDSReturnValue returnValue;
            returnValue = runVdsCommand(VDSCommandType.RemoveGlusterHook, new GlusterHookVDSParameters(server.getId(), entity.getGlusterCommand(), entity.getStage(), entity.getName()));
            return new Pair<>(server, returnValue);
        });
    }
    if (!taskList.isEmpty()) {
        List<Pair<VDS, VDSReturnValue>> pairResults = ThreadPoolUtil.invokeAll(taskList);
        for (Pair<VDS, VDSReturnValue> pairResult : pairResults) {
            VDSReturnValue retValue = pairResult.getSecond();
            if (!retValue.getSucceeded()) {
                errors.add(retValue.getVdsError().getMessage());
            }
        }
    }
    if (errors.size() > 0) {
        setSucceeded(false);
        errorType = AuditLogType.GLUSTER_HOOK_REMOVE_FAILED;
        handleVdsErrors(getAuditLogTypeValue(), errors);
        addCustomValue(GlusterConstants.FAILURE_MESSAGE, StringUtils.join(errors, System.lineSeparator()));
    } else {
        setSucceeded(true);
    }
    if (getSucceeded()) {
        entity.removeMissingConflict();
        glusterHooksDao.remove(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 3 with GlusterHookVDSParameters

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

the class GetGlusterHookContentQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    GlusterHookEntity hook = glusterHooksDao.getById(getParameters().getGlusterHookId());
    String content = "";
    if (getParameters().getGlusterServerId() == null) {
        if (hook.getContentType().equals(GlusterHookContentType.TEXT)) {
            content = glusterHooksDao.getGlusterHookContent(getParameters().getGlusterHookId());
        }
    } else {
        GlusterServerHook serverHook = glusterHooksDao.getGlusterServerHook(hook.getId(), getParameters().getGlusterServerId());
        if (serverHook != null && serverHook.getContentType() == GlusterHookContentType.TEXT) {
            VDSReturnValue returnValue = runVdsCommand(VDSCommandType.GetGlusterHookContent, new GlusterHookVDSParameters(getParameters().getGlusterServerId(), hook.getGlusterCommand(), hook.getStage(), hook.getName()));
            if (returnValue.getSucceeded()) {
                content = (String) returnValue.getReturnValue();
            }
        }
    }
    content = StringUtils.newStringUtf8(Base64.decodeBase64(content));
    getQueryReturnValue().setReturnValue(content);
}
Also used : GlusterHookEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity) GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) GlusterHookVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.GlusterHookVDSParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 4 with GlusterHookVDSParameters

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

the class UpdateGlusterHookCommand method executeCommand.

@Override
protected void executeCommand() {
    // check source to copy hook from - if engine copy or server copy
    final boolean copyfromEngine = getParameters().getSourceServerId() == null;
    entity = getGlusterHook();
    addCustomValue(GlusterConstants.HOOK_NAME, entity.getName());
    final String hookContent;
    final String hookChecksum;
    final GlusterHookContentType hookContentType;
    if (copyfromEngine) {
        hookContent = entity.getContent();
        hookChecksum = entity.getChecksum();
        hookContentType = entity.getContentType();
    } else {
        // use a server's copy
        GlusterServerHook sourceServerHook = glusterHooksDao.getGlusterServerHook(entity.getId(), getParameters().getSourceServerId());
        VDSReturnValue retValue = runVdsCommand(VDSCommandType.GetGlusterHookContent, new GlusterHookVDSParameters(getParameters().getSourceServerId(), entity.getGlusterCommand(), entity.getStage(), entity.getName()));
        if (!retValue.getSucceeded()) {
            // throw exception as we cannot continue without content
            log.error("Failed to get content from server with id '{}': {}", getParameters().getSourceServerId(), retValue.getExceptionString());
            throw new EngineException(retValue.getVdsError().getCode(), retValue.getVdsError().getMessage());
        }
        hookContent = (String) retValue.getReturnValue();
        hookChecksum = sourceServerHook.getChecksum();
        hookContentType = sourceServerHook.getContentType();
    }
    List<Callable<Pair<Guid, VDSReturnValue>>> taskList = new ArrayList<>();
    List<Guid> serverIdsToUpdate = new ArrayList<>();
    if (copyfromEngine) {
        for (final GlusterServerHook serverHook : getContentConflictServerHooks()) {
            serverIdsToUpdate.add(serverHook.getServerId());
        }
    } else {
        // need to be updated with hook content
        for (final VDS server : glusterUtil.getAllUpServers(entity.getClusterId())) {
            if (!server.getId().equals(getParameters().getSourceServerId())) {
                serverIdsToUpdate.add(server.getId());
            }
        }
    }
    for (final Guid serverId : serverIdsToUpdate) {
        taskList.add(() -> {
            VDSReturnValue returnValue;
            returnValue = runVdsCommand(VDSCommandType.UpdateGlusterHook, new GlusterHookVDSParameters(serverId, entity.getGlusterCommand(), entity.getStage(), entity.getName(), hookContent, hookChecksum));
            return new Pair<>(serverId, returnValue);
        });
    }
    setSucceeded(true);
    if (!taskList.isEmpty()) {
        List<Pair<Guid, VDSReturnValue>> pairResults = ThreadPoolUtil.invokeAll(taskList);
        for (Pair<Guid, VDSReturnValue> pairResult : pairResults) {
            VDSReturnValue retValue = pairResult.getSecond();
            if (!retValue.getSucceeded()) {
                errors.add(retValue.getVdsError().getMessage());
            }
        }
    } else {
        setSucceeded(false);
    }
    if (errors.size() > 0) {
        setSucceeded(false);
        errorType = AuditLogType.GLUSTER_HOOK_UPDATE_FAILED;
        handleVdsErrors(getAuditLogTypeValue(), errors);
        addCustomValue(GlusterConstants.FAILURE_MESSAGE, StringUtils.join(errors, System.lineSeparator()));
    }
    if (getSucceeded() && !copyfromEngine) {
        // update server's content copy
        entity.setChecksum(hookChecksum);
        entity.setContent(hookContent);
        entity.setContentType(hookContentType);
    }
    if (getSucceeded()) {
        entity.removeContentConflict();
        updateGlusterHook(entity);
    }
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) EngineException(org.ovirt.engine.core.common.errors.EngineException) ArrayList(java.util.ArrayList) GlusterHookContentType(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookContentType) Guid(org.ovirt.engine.core.compat.Guid) Callable(java.util.concurrent.Callable) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) GlusterHookVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.GlusterHookVDSParameters) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 5 with GlusterHookVDSParameters

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

the class AddGlusterHookCommand method executeCommand.

@Override
protected void executeCommand() {
    entity = getGlusterHook();
    addCustomValue(GlusterConstants.HOOK_NAME, entity.getName());
    final boolean hookEnabled = entity.getStatus() == GlusterHookStatus.ENABLED;
    List<Callable<Pair<GlusterServerHook, VDSReturnValue>>> taskList = new ArrayList<>();
    for (final GlusterServerHook serverHook : getMissingServerHooks()) {
        taskList.add(() -> {
            VDSReturnValue returnValue;
            returnValue = runVdsCommand(VDSCommandType.AddGlusterHook, new GlusterHookVDSParameters(serverHook.getServerId(), entity.getGlusterCommand(), entity.getStage(), entity.getName(), entity.getContent(), entity.getChecksum(), hookEnabled));
            return new Pair<>(serverHook, returnValue);
        });
    }
    if (!taskList.isEmpty()) {
        List<Pair<GlusterServerHook, VDSReturnValue>> pairResults = ThreadPoolUtil.invokeAll(taskList);
        for (Pair<GlusterServerHook, VDSReturnValue> pairResult : pairResults) {
            VDSReturnValue retValue = pairResult.getSecond();
            if (!retValue.getSucceeded()) {
                errors.add(retValue.getVdsError().getMessage());
            } else {
                // hook added successfully, so remove from gluster server hooks table
                glusterHooksDao.removeGlusterServerHook(pairResult.getFirst().getHookId(), pairResult.getFirst().getServerId());
            }
        }
    }
    if (errors.size() > 0) {
        setSucceeded(false);
        errorType = AuditLogType.GLUSTER_HOOK_ADD_FAILED;
        handleVdsErrors(getAuditLogTypeValue(), errors);
        addCustomValue(GlusterConstants.FAILURE_MESSAGE, StringUtils.join(errors, System.lineSeparator()));
    } else {
        setSucceeded(true);
    }
    if (getSucceeded()) {
        entity.removeMissingConflict();
        updateGlusterHook(entity);
    }
}
Also used : GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) 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)

Aggregations

VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)5 GlusterHookVDSParameters (org.ovirt.engine.core.common.vdscommands.gluster.GlusterHookVDSParameters)5 ArrayList (java.util.ArrayList)4 Callable (java.util.concurrent.Callable)4 Pair (org.ovirt.engine.core.common.utils.Pair)4 VDS (org.ovirt.engine.core.common.businessentities.VDS)3 GlusterServerHook (org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook)3 GlusterHookContentType (org.ovirt.engine.core.common.businessentities.gluster.GlusterHookContentType)1 GlusterHookEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1 Guid (org.ovirt.engine.core.compat.Guid)1