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