Skip to content

Commit 9569c43

Browse files
Namespace arguments for hoptimator-operator (#23)
* Minor fix in check CLI function * Added and used Apache Commons CLI to support custom namespaces with hoptimator operator * Added Apache commons CLI to libs * Update hoptimator-operator/src/main/java/com/linkedin/hoptimator/operator/HoptimatorOperatorApp.java Co-authored-by: Ryanne Dolan <[email protected]> * Fixed formatting --------- Co-authored-by: Ryanne Dolan <[email protected]>
1 parent 8b44f3b commit 9569c43

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ kubernetesExtendedClient = "io.kubernetes:client-java-extended:16.0.2"
2828
slf4jSimple = "org.slf4j:slf4j-simple:1.7.30"
2929
slf4jApi = "org.slf4j:slf4j-api:1.7.30"
3030
sqlline = "sqlline:sqlline:1.12.0"
31+
commonsCli = 'commons-cli:commons-cli:1.4'
32+

hoptimator-cli/src/main/java/com/linkedin/hoptimator/HoptimatorCliApp.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,16 @@ public void execute(String line, DispatchCallback dispatchCallback) {
360360
}
361361
break;
362362
case "value":
363+
boolean varFound = false;
363364
while (iter.hasNext()) {
364365
if(String.valueOf(iter.next()).contains(value)) {
366+
varFound = true;
365367
break;
366368
}
367369
}
370+
if (varFound) {
371+
break;
372+
}
368373
throw new IllegalArgumentException("Query result did not contain expected value");
369374
}
370375
sqlline.output("PASS");

hoptimator-operator/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ dependencies {
2525
implementation libs.kubernetesClient
2626
implementation libs.kubernetesExtendedClient
2727
implementation libs.slf4jApi
28-
28+
implementation libs.commonsCli
29+
2930
testImplementation libs.junit
3031
testImplementation libs.assertj
3132
}

hoptimator-operator/src/main/java/com/linkedin/hoptimator/operator/HoptimatorOperatorApp.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
import com.linkedin.hoptimator.operator.subscription.SubscriptionReconciler;
1414
import com.linkedin.hoptimator.planner.HoptimatorPlanner;
1515

16+
import org.apache.commons.cli.CommandLine;
17+
import org.apache.commons.cli.CommandLineParser;
18+
import org.apache.commons.cli.DefaultParser;
19+
import org.apache.commons.cli.HelpFormatter;
20+
import org.apache.commons.cli.Option;
21+
import org.apache.commons.cli.Options;
22+
import org.apache.commons.cli.ParseException;
23+
1624
import org.slf4j.Logger;
1725
import org.slf4j.LoggerFactory;
1826

@@ -37,10 +45,34 @@ public HoptimatorOperatorApp(String modelPath, String namespace, Properties prop
3745
}
3846

3947
public static void main(String[] args) throws Exception {
40-
if (args.length != 1) {
48+
if (args.length < 1) {
4149
throw new IllegalArgumentException("Missing model file argument.");
4250
}
43-
new HoptimatorOperatorApp(args[0], "default", new Properties()).run();
51+
52+
Options options = new Options();
53+
54+
Option namespace = new Option("n", "namespace", true, "specified namespace");
55+
namespace.setRequired(false);
56+
options.addOption(namespace);
57+
58+
CommandLineParser parser = new DefaultParser();
59+
HelpFormatter formatter = new HelpFormatter();
60+
CommandLine cmd;
61+
62+
try {
63+
cmd = parser.parse(options, args);
64+
} catch (ParseException e) {
65+
System.out.println(e.getMessage());
66+
formatter.printHelp("utility-name", options);
67+
68+
System.exit(1);
69+
return;
70+
}
71+
72+
String modelFileInput = cmd.getArgs()[0];
73+
String namespaceInput = cmd.getOptionValue("namespace", "default");
74+
75+
new HoptimatorOperatorApp(modelFileInput, namespaceInput, new Properties()).run();
4476
}
4577

4678
public void run() throws Exception {

0 commit comments

Comments
 (0)