-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
993 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
common/src/main/java/io/brokerqe/claire/LocalExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright Strimzi and Broker QE authors. | ||
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). | ||
*/ | ||
package io.brokerqe.claire; | ||
|
||
import io.brokerqe.claire.exception.ClaireNotImplementedException; | ||
import io.brokerqe.claire.executor.Executor; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.time.Duration; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.function.Consumer; | ||
|
||
|
||
public class LocalExecutor implements Executor { | ||
|
||
private String commandDataOutput; | ||
private int exitCode; | ||
@Override | ||
public Object executeCommand(String... cmd) { | ||
return executeCommand(Duration.ofSeconds(60).toSeconds(), cmd); | ||
} | ||
|
||
@Override | ||
public Object executeCommand(long maxExecMs, String... cmd) { | ||
ProcessBuilder builder = new ProcessBuilder(cmd); | ||
builder.directory(new File(System.getProperty("user.home"))); | ||
try { | ||
Process process = builder.start(); | ||
StreamGobbler streamGobbler = new StreamGobbler(process.getInputStream(), System.out::println); | ||
streamGobbler.run(); | ||
|
||
ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
executor.submit(streamGobbler); | ||
exitCode = process.waitFor(); | ||
executor.shutdown(); | ||
commandDataOutput = streamGobbler.toString(); | ||
} catch (IOException | InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
return exitCode; | ||
} | ||
|
||
@Override | ||
public void execBackgroundCommand(String... cmd) { | ||
throw new ClaireNotImplementedException("Not implemented yet"); | ||
} | ||
|
||
@Override | ||
public boolean isBackgroundCommandFinished() { | ||
throw new ClaireNotImplementedException("Not implemented yet"); | ||
} | ||
|
||
@Override | ||
public String getBackgroundCommandData(int waitTime) { | ||
throw new ClaireNotImplementedException("Not implemented yet"); | ||
} | ||
|
||
@Override | ||
public String getCommandData(long timeout) { | ||
return commandDataOutput; | ||
} | ||
} | ||
|
||
class StreamGobbler implements Runnable { | ||
private InputStream inputStream; | ||
private Consumer<String> consumer; | ||
|
||
public StreamGobbler(InputStream inputStream, Consumer<String> consumer) { | ||
this.inputStream = inputStream; | ||
this.consumer = consumer; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
new BufferedReader(new InputStreamReader(inputStream)).lines().forEach(consumer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
common/src/main/java/io/brokerqe/claire/clients/Protocol.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Broker QE authors. | ||
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). | ||
*/ | ||
package io.brokerqe.claire.clients; | ||
|
||
public enum Protocol { | ||
AMQP, | ||
AMQPS, | ||
CORE, | ||
CORES | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.