Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ansible runner cleanup #547

Merged
merged 1 commit into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import org.ovirt.engine.core.bll.tasks.interfaces.CommandCallback;
import org.ovirt.engine.core.common.AuditLogType;
import org.ovirt.engine.core.common.action.AnsibleCommandParameters;
import org.ovirt.engine.core.common.utils.ansible.AnsibleReturnCode;
import org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue;
import org.ovirt.engine.core.common.utils.ansible.AnsibleRunnerClient;
import org.ovirt.engine.core.common.utils.ansible.AnsibleRunnerLogger;
import org.ovirt.engine.core.compat.CommandStatus;
Expand Down Expand Up @@ -59,8 +57,6 @@ public void doPolling(Guid cmdId, List<Guid> childCmdIds) {
}
};

AnsibleReturnValue ret = new AnsibleReturnValue(AnsibleReturnCode.ERROR);
ret.setLogFile(runnerClient.getLogger().getLogFile());
michalskrivanek marked this conversation as resolved.
Show resolved Hide resolved
int totalEvents;
// Get the current status of the playbook:
AnsibleRunnerClient.PlaybookStatus playbookStatus = runnerClient.getPlaybookStatus(playUuid);
Expand All @@ -72,13 +68,12 @@ public void doPolling(Guid cmdId, List<Guid> childCmdIds) {
if (msg.equalsIgnoreCase("running") || msg.equalsIgnoreCase("successful")
&& command.getParameters().getLastEventId() < totalEvents) {
command.getParameters().setLastEventId(runnerClient.processEvents(
playUuid, command.getParameters().getLastEventId(), fn, msg, ret.getLogFile()));
playUuid, command.getParameters().getLastEventId(), fn));
return;
} else if (msg.equalsIgnoreCase("successful")) {
log.info("Playbook (Play uuid = {}, command = {}) has completed!",
command.getParameters().getPlayUuid(), command.getActionType().name());
// Exit the processing if playbook finished:
ret.setAnsibleReturnCode(AnsibleReturnCode.OK);
command.setSucceeded(true);
command.setCommandStatus(CommandStatus.SUCCEEDED);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ public AnsibleReturnValue runCommand(AnsibleCommandConfig commandConfig, int tim
AnsibleReturnValue ret = new AnsibleReturnValue(AnsibleReturnCode.ERROR);

String playUuid = null;
String msg = "";
AnsibleRunnerClient runnerClient = null;
try {
runnerClient = ansibleClientFactory.create(commandConfig);
Expand Down Expand Up @@ -182,7 +181,7 @@ public AnsibleReturnValue runCommand(AnsibleCommandConfig commandConfig, int tim
} finally {
// Make sure all events are proccessed even in case of failure:
if (playUuid != null && runnerClient != null && !async) {
runnerClient.processEvents(playUuid, ret.getLastEventId(), fn, msg, ret.getLogFile());
runnerClient.processEvents(playUuid, ret.getLastEventId(), fn);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -64,7 +63,7 @@ public AnsibleReturnValue artifactHandler(UUID uuid, int lastEventID, int timeou
int executionTime = 0;
setReturnValue(uuid);
while (!playHasEnded(uuid.toString(), lastEventID)) {
lastEventID = processEvents(uuid.toString(), lastEventID, fn, "", Paths.get(""));
lastEventID = processEvents(uuid.toString(), lastEventID, fn);
if (lastEventID == -1) {
return returnValue;
}
Expand Down Expand Up @@ -108,9 +107,7 @@ public String getJobEventsDir(String playUuid) {

public int processEvents(String playUuid,
int lastEventId,
BiConsumer<String, String> fn,
String msg,
Path logFile) {
BiConsumer<String, String> fn) {
String jobEvents = getJobEventsDir(playUuid);
while(true){
// get next event
Expand Down