Search in sources :

Example 1 with GlusterHookContentType

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterHookContentType 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)

Aggregations

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