Skip to content

Commit

Permalink
Send snapshot output while command is running
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Kurait <[email protected]>
  • Loading branch information
AndreKurait committed Jun 20, 2024
1 parent e0ec666 commit c19a155
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
14 changes: 9 additions & 5 deletions CreateSnapshot/src/main/java/com/rfs/CreateSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public static class Args {
@Parameter(names = {"--source-password"}, description = "Optional. The source password; if not provided, will assume no auth on source", required = false)
public String sourcePass = null;

@Parameter(names = {"--source-insecure"}, description = "Allow untrusted SSL certificates for source", required = false)
public boolean sourceInsecure = false;

@Parameter(names = {"--target-host"}, description = "The target host and port (e.g. http://localhost:9200)", required = true)
public String targetHost;

Expand All @@ -49,8 +52,8 @@ public static class Args {
@Parameter(names = {"--target-password"}, description = "Optional. The target password; if not provided, will assume no auth on target", required = false)
public String targetPass = null;

@Parameter(names = {"--insecure"}, description = "Allow untrusted SSL certificates", required = false)
public boolean insecure = false;
@Parameter(names = {"--target-insecure"}, description = "Allow untrusted SSL certificates for target", required = false)
public boolean targetInsecure = false;
}

public static void main(String[] args) throws Exception {
Expand All @@ -70,10 +73,11 @@ public static void main(String[] args) throws Exception {
final String targetHost = arguments.targetHost;
final String targetUser = arguments.targetUser;
final String targetPass = arguments.targetPass;
final boolean insecure = arguments.insecure;
final boolean sourceInsecure = arguments.sourceInsecure;
final boolean targetInsecure = arguments.targetInsecure;

final ConnectionDetails sourceConnection = new ConnectionDetails(sourceHost, sourceUser, sourcePass, insecure);
final ConnectionDetails targetConnection = new ConnectionDetails(targetHost, targetUser, targetPass, insecure);
final ConnectionDetails sourceConnection = new ConnectionDetails(sourceHost, sourceUser, sourcePass, sourceInsecure);
final ConnectionDetails targetConnection = new ConnectionDetails(targetHost, targetUser, targetPass, targetInsecure);

TryHandlePhaseFailure.executeWithTryCatch(() -> {
log.info("Running RfsWorker");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,21 @@ def create(self, *args, **kwargs) -> CommandResult:
"--source-host", self.source_cluster.endpoint,
"--target-host", self.target_cluster.endpoint,
]
if self.source_cluster.allow_insecure or self.target_cluster.allow_insecure:
command.append("--insecure")

if self.source_cluster.allow_insecure:
command.append("--source-insecure")
if self.target_cluster.allow_insecure:
command.append("--target-insecure")

logger.info(f"Creating snapshot with command: {' '.join(command)}")
try:
subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True)
# Pass None to stdout and stderr to not capture output and show in terminal
subprocess.run(command, stdout=None, stderr=None, text=True, check=True)
logger.info(f"Snapshot {self.config['snapshot_name']} created successfully")
return CommandResult(success=True, value=f"Snapshot {self.config['snapshot_name']} created successfully")
except subprocess.CalledProcessError as e:
logger.error(f"Failed to create snapshot: {str(e)}")
return CommandResult(success=False, value=f"Failed to create snapshot: {str(e)} {e.output} {e.stderr}")
return CommandResult(success=False, value=f"Failed to create snapshot: {str(e)}")

def status(self, *args, **kwargs) -> CommandResult:
return CommandResult(success=False, value=f"Command not implemented")

0 comments on commit c19a155

Please sign in to comment.