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);
}
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);
}
}
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));
}
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;
}
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());
}
Aggregations