Search in sources :

Example 11 with GlusterServerHook

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook in project ovirt-engine by oVirt.

the class ClusterGlusterHookListModel method resolveConflicts.

private void resolveConflicts() {
    if (getWindow() != null) {
        return;
    }
    final GlusterHookEntity hookEntity = getSelectedItem();
    if (hookEntity == null) {
        return;
    }
    final GlusterHookResolveConflictsModel conflictsModel = new GlusterHookResolveConflictsModel();
    conflictsModel.setTitle(ConstantsManager.getInstance().getConstants().resolveConflictsGlusterHookTitle());
    conflictsModel.setHelpTag(HelpTag.gluster_hook_resolve_conflicts);
    // $NON-NLS-1$
    conflictsModel.setHashName("gluster_hook_resolve_conflicts");
    hookEntity.setServerHooks(new ArrayList<GlusterServerHook>());
    conflictsModel.setGlusterHookEntity(hookEntity);
    setWindow(conflictsModel);
    conflictsModel.startProgress();
    AsyncDataProvider.getInstance().getGlusterHook(new AsyncQuery<>(returnValue -> {
        List<GlusterServerHook> serverHooks = returnValue.getServerHooks();
        hookEntity.setServerHooks(serverHooks);
        ArrayList<EntityModel<GlusterServerHook>> serverHookModels = new ArrayList<>();
        GlusterServerHook engineCopy = new GlusterServerHook();
        engineCopy.setHookId(hookEntity.getId());
        // $NON-NLS-1$
        engineCopy.setServerName("Engine (Master)");
        engineCopy.setStatus(hookEntity.getStatus());
        engineCopy.setContentType(hookEntity.getContentType());
        engineCopy.setChecksum(hookEntity.getChecksum());
        EntityModel<GlusterServerHook> engineCopyModel = new EntityModel<>(engineCopy);
        serverHookModels.add(engineCopyModel);
        for (GlusterServerHook serverHook : serverHooks) {
            serverHookModels.add(new EntityModel<>(serverHook));
        }
        conflictsModel.getHookSources().setItems(serverHookModels);
        conflictsModel.getHookSources().setSelectedItem(engineCopyModel);
        ArrayList<GlusterServerHook> serverHooksWithEngine = new ArrayList<>(serverHooks);
        serverHooksWithEngine.add(0, engineCopy);
        conflictsModel.getServerHooksList().setItems(serverHooksWithEngine);
        conflictsModel.getServerHooksList().setSelectedItem(engineCopy);
        conflictsModel.stopProgress();
        // $NON-NLS-1$
        UICommand command = UICommand.createDefaultOkUiCommand("OnResolveConflicts", ClusterGlusterHookListModel.this);
        conflictsModel.getCommands().add(command);
        // $NON-NLS-1$
        command = new UICommand("Cancel", ClusterGlusterHookListModel.this);
        command.setTitle(ConstantsManager.getInstance().getConstants().close());
        command.setIsCancel(true);
        conflictsModel.getCommands().add(command);
    }), hookEntity.getId(), true);
}
Also used : GlusterHookManageParameters(org.ovirt.engine.core.common.action.gluster.GlusterHookManageParameters) GlusterHookEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity) GlusterHookStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookStatus) Guid(org.ovirt.engine.core.compat.Guid) GlusterHookContentType(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookContentType) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) ApplicationMode(org.ovirt.engine.core.common.mode.ApplicationMode) SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ActionType(org.ovirt.engine.core.common.action.ActionType) Frontend(org.ovirt.engine.ui.frontend.Frontend) List(java.util.List) GlusterHookParameters(org.ovirt.engine.core.common.action.gluster.GlusterHookParameters) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) GlusterClusterParameters(org.ovirt.engine.core.common.action.gluster.GlusterClusterParameters) GlusterHookEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity) GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ArrayList(java.util.ArrayList) List(java.util.List) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand)

Example 12 with GlusterServerHook

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook 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 13 with GlusterServerHook

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook in project ovirt-engine by oVirt.

the class GlusterHooksDaoTest method testGetServerHooks.

@Test
public void testGetServerHooks() {
    GlusterServerHook serverHook1 = getGlusterServerHook(FixturesTool.VDS_GLUSTER_SERVER2, GlusterHookStatus.ENABLED, GlusterHookContentType.TEXT, CHECKSUM_HOOK1_SERVER1);
    GlusterServerHook serverHook2 = getGlusterServerHook(FixturesTool.GLUSTER_BRICK_SERVER1, GlusterHookStatus.MISSING, null, null);
    List<GlusterServerHook> serverHooks = dao.getGlusterServerHooks(FixturesTool.HOOK_ID);
    assertNotNull(serverHooks);
    assertEquals(2, serverHooks.size());
    assertTrue(serverHooks.contains(serverHook1));
    assertTrue(serverHooks.contains(serverHook2));
}
Also used : GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) Test(org.junit.Test)

Example 14 with GlusterServerHook

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook in project ovirt-engine by oVirt.

the class GlusterHooksDaoTest method getGlusterServerHook.

private GlusterServerHook getGlusterServerHook(Guid serverId, GlusterHookStatus status, GlusterHookContentType contentType, String checksum) {
    GlusterServerHook serverHook = new GlusterServerHook();
    serverHook.setHookId(FixturesTool.HOOK_ID);
    serverHook.setServerId(serverId);
    serverHook.setStatus(status);
    serverHook.setContentType(contentType);
    serverHook.setChecksum(checksum);
    return serverHook;
}
Also used : GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook)

Example 15 with GlusterServerHook

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook in project ovirt-engine by oVirt.

the class GlusterHooksDaoTest method testUpdateGlusterServerHookStatus.

@Test
public void testUpdateGlusterServerHookStatus() {
    GlusterServerHook serverhookExisting = dao.getGlusterServerHook(FixturesTool.HOOK_ID, FixturesTool.VDS_GLUSTER_SERVER2);
    assertEquals(GlusterHookStatus.ENABLED, serverhookExisting.getStatus());
    dao.updateGlusterServerHookStatus(FixturesTool.HOOK_ID, FixturesTool.VDS_GLUSTER_SERVER2, GlusterHookStatus.DISABLED);
    GlusterServerHook serverhookUpdated = dao.getGlusterServerHook(FixturesTool.HOOK_ID, FixturesTool.VDS_GLUSTER_SERVER2);
    assertNotNull(serverhookUpdated);
    assertEquals(GlusterHookStatus.DISABLED, serverhookUpdated.getStatus());
}
Also used : GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) Test(org.junit.Test)

Aggregations

GlusterServerHook (org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook)22 GlusterHookEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 VDS (org.ovirt.engine.core.common.businessentities.VDS)5 Guid (org.ovirt.engine.core.compat.Guid)5 GlusterHookContentType (org.ovirt.engine.core.common.businessentities.gluster.GlusterHookContentType)4 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)4 List (java.util.List)3 Callable (java.util.concurrent.Callable)3 GlusterHookStatus (org.ovirt.engine.core.common.businessentities.gluster.GlusterHookStatus)3 GlusterHookVDSParameters (org.ovirt.engine.core.common.vdscommands.gluster.GlusterHookVDSParameters)3 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)3 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)2 ActionType (org.ovirt.engine.core.common.action.ActionType)2 GlusterClusterParameters (org.ovirt.engine.core.common.action.gluster.GlusterClusterParameters)2