Search in sources :

Example 1 with GlusterServerHook

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

the class ClusterGlusterHookListModel method onResolveConflicts.

/*
     * If there are multiple types of conflicts found for a hook and the user choose to resolve them. The conflicts will
     * be resolved in the following order 1)Content Conflict, 2)Status Conflict, 3)Missing Conflict
     *
     * If any conflict resolution is failed the next one will not be executed
     */
private void onResolveConflicts() {
    final GlusterHookResolveConflictsModel resolveConflictsModel = (GlusterHookResolveConflictsModel) getWindow();
    if (resolveConflictsModel == null) {
        return;
    }
    if (!resolveConflictsModel.isAnyResolveActionSelected()) {
        resolveConflictsModel.setMessage(ConstantsManager.getInstance().getConstants().noResolveActionSelectedGlusterHook());
        return;
    }
    resolveConflictsModel.startProgress();
    GlusterHookEntity hookEntity = resolveConflictsModel.getGlusterHookEntity();
    ArrayList<ActionType> actionTypes = new ArrayList<>();
    ArrayList<ActionParametersBase> parameters = new ArrayList<>();
    ArrayList<IFrontendActionAsyncCallback> callbacks = new ArrayList<>();
    if (resolveConflictsModel.getResolveContentConflict().getEntity()) {
        actionTypes.add(ActionType.UpdateGlusterHook);
        GlusterServerHook serverHook = resolveConflictsModel.getServerHooksList().getSelectedItem();
        Guid serverId = (serverHook == null) ? null : serverHook.getServerId();
        parameters.add(new GlusterHookManageParameters(hookEntity.getId(), serverId));
        IFrontendActionAsyncCallback callback = result -> {
            if (result.getReturnValue().getSucceeded()) {
                resolveConflictsModel.getResolveContentConflict().setEntity(Boolean.FALSE);
                resolveConflictsModel.getResolveContentConflict().setIsChangeable(Boolean.FALSE);
            }
        };
        callbacks.add(callback);
    }
    if (resolveConflictsModel.getResolveStatusConflict().getEntity()) {
        boolean isEnable = resolveConflictsModel.getResolveStatusConflictEnable().getEntity();
        actionTypes.add(isEnable ? ActionType.EnableGlusterHook : ActionType.DisableGlusterHook);
        parameters.add(new GlusterHookParameters(hookEntity.getId()));
        IFrontendActionAsyncCallback callback = result -> {
            if (result.getReturnValue().getSucceeded()) {
                resolveConflictsModel.getResolveStatusConflict().setEntity(Boolean.FALSE);
                resolveConflictsModel.getResolveStatusConflict().setIsChangeable(Boolean.FALSE);
            }
        };
        callbacks.add(callback);
    }
    if (resolveConflictsModel.getResolveMissingConflict().getEntity()) {
        boolean isAdd = resolveConflictsModel.getResolveMissingConflictCopy().getEntity();
        actionTypes.add(isAdd ? ActionType.AddGlusterHook : ActionType.RemoveGlusterHook);
        parameters.add(new GlusterHookManageParameters(hookEntity.getId()));
        IFrontendActionAsyncCallback callback = result -> {
            if (result.getReturnValue().getSucceeded()) {
                resolveConflictsModel.getResolveMissingConflict().setEntity(Boolean.FALSE);
                resolveConflictsModel.getResolveMissingConflict().setIsChangeable(Boolean.FALSE);
            }
        };
        callbacks.add(callback);
    }
    IFrontendActionAsyncCallback onFinishCallback = result -> {
        if (result.getReturnValue().getSucceeded()) {
            resolveConflictsModel.stopProgress();
            cancel();
            syncSearch();
        }
    };
    IFrontendActionAsyncCallback failureCallback = result -> resolveConflictsModel.stopProgress();
    // Replacing the last callback with onFinishCallback, as we just want to close the dialog and execute the search
    if (callbacks.size() > 0) {
        callbacks.remove(callbacks.size() - 1);
        callbacks.add(onFinishCallback);
        Frontend.getInstance().runMultipleActions(actionTypes, parameters, callbacks, failureCallback, null);
    }
}
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) GlusterHookParameters(org.ovirt.engine.core.common.action.gluster.GlusterHookParameters) ActionType(org.ovirt.engine.core.common.action.ActionType) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) GlusterHookManageParameters(org.ovirt.engine.core.common.action.gluster.GlusterHookManageParameters) GlusterHookEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook)

Example 2 with GlusterServerHook

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

the class GlusterHookResolveConflictsModel method onSelectedHookSourceChanged.

private void onSelectedHookSourceChanged() {
    EntityModel<GlusterServerHook> selectedItem = getHookSources().getSelectedItem();
    if (selectedItem == null) {
        return;
    }
    GlusterServerHook selectedServer = selectedItem.getEntity();
    getServerHooksList().setSelectedItem(selectedServer);
    if (selectedServer.getStatus() == GlusterHookStatus.MISSING) {
        getContentModel().getContent().setEntity(null);
        getContentModel().getStatus().setEntity(null);
        getContentModel().getMd5Checksum().setEntity(null);
        return;
    }
    getContentModel().getStatus().setEntity(selectedServer.getStatus());
    getContentModel().getMd5Checksum().setEntity(selectedServer.getChecksum());
    if (selectedServer.getContentType() == GlusterHookContentType.TEXT) {
        startProgress();
        AsyncDataProvider.getInstance().getGlusterHookContent(new AsyncQuery<>(content -> {
            getContentModel().getContent().setEntity(content);
            stopProgress();
        }), getGlusterHookEntity().getId(), selectedServer.getServerId());
    } else {
        getContentModel().getContent().setEntity(null);
    }
}
Also used : GlusterHookEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity) GlusterHookStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookStatus) GlusterHookContentType(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookContentType) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) Model(org.ovirt.engine.ui.uicommonweb.models.Model) GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook)

Example 3 with GlusterServerHook

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

the class GlusterHookMapper method map.

@Mapping(from = GlusterHookEntity.class, to = GlusterHook.class)
public static GlusterHook map(GlusterHookEntity entity, GlusterHook hook) {
    GlusterHook model = hook != null ? hook : new GlusterHook();
    if (entity.getId() != null) {
        model.setId(entity.getId().toString());
    }
    if (entity.getClusterId() != null) {
        model.setCluster(new Cluster());
        model.getCluster().setId(entity.getClusterId().toString());
    }
    if (entity.getHookKey() != null) {
        model.setName(entity.getHookKey());
    }
    if (entity.getGlusterCommand() != null) {
        model.setGlusterCommand(entity.getGlusterCommand());
    }
    if (entity.getStage() != null) {
        model.setStage(map(entity.getStage(), null));
    }
    if (entity.getStatus() != null) {
        model.setStatus(mapHookStatus(entity.getStatus()));
    }
    if (entity.getContentType() != null) {
        model.setContentType(map(entity.getContentType(), null));
    }
    if (entity.getChecksum() != null) {
        model.setChecksum(entity.getChecksum());
    }
    if (entity.getContent() != null) {
        model.setContent(entity.getContent());
    }
    if (entity.getConflictStatus() != null) {
        model.setConflictStatus(entity.getConflictStatus());
        model.setConflicts(mapConflicts(entity));
    }
    if (entity.getServerHooks() != null && !entity.getServerHooks().isEmpty()) {
        model.setServerHooks(new GlusterServerHooks());
        for (GlusterServerHook serverHookEntity : entity.getServerHooks()) {
            model.getServerHooks().getGlusterServerHooks().add(map(serverHookEntity));
        }
    }
    return model;
}
Also used : GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) Cluster(org.ovirt.engine.api.model.Cluster) GlusterServerHooks(org.ovirt.engine.api.model.GlusterServerHooks) GlusterHook(org.ovirt.engine.api.model.GlusterHook)

Example 4 with GlusterServerHook

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

the class UpdateGlusterHookCommand method validate.

@Override
protected boolean validate() {
    if (!super.validate()) {
        return false;
    }
    if (getContentConflictServerHooks().isEmpty()) {
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_GLUSTER_HOOK_NO_CONFLICT_SERVERS);
        return false;
    }
    for (GlusterServerHook serverHook : getContentConflictServerHooks()) {
        VDS vds = vdsDao.get(serverHook.getServerId());
        if (vds == null || vds.getStatus() != VDSStatus.Up) {
            String vdsName = vds != null ? vds.getName() : GlusterConstants.NO_SERVER;
            setVdsName(vdsName);
            addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_SERVER_STATUS_NOT_UP);
            addValidationMessage(String.format("$%1$s %2$s", "VdsName", vdsName));
            return false;
        }
    }
    return true;
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook)

Example 5 with GlusterServerHook

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

the class AddGlusterHookCommandTest method getHookEntityWithMissing.

private GlusterHookEntity getHookEntityWithMissing() {
    GlusterHookEntity hook = getHookEntity();
    List<GlusterServerHook> serverHooks = new ArrayList<>();
    serverHooks.add(getGlusterServerHook(0, GlusterHookStatus.MISSING));
    serverHooks.add(getGlusterServerHook(1, GlusterHookStatus.MISSING));
    serverHooks.add(getGlusterServerHook(2, GlusterHookStatus.MISSING));
    hook.setServerHooks(serverHooks);
    return hook;
}
Also used : GlusterHookEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity) GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) ArrayList(java.util.ArrayList)

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