Open Kilda Java Documentation
CliArguments.java
Go to the documentation of this file.
1 package org.openkilda.wfm;
2 
3 import org.kohsuke.args4j.Argument;
4 import org.kohsuke.args4j.CmdLineException;
5 import org.kohsuke.args4j.CmdLineParser;
6 import org.kohsuke.args4j.Option;
9 
10 import java.io.File;
11 import java.io.FileInputStream;
12 import java.io.IOException;
13 import java.util.Properties;
14 
15 public class CliArguments {
16  @Option(name = "--local", usage = "Do not push topology onto storm server, execute it local.")
17  private Boolean isLocal = false;
18 
19  @Option(name="--name", usage="Set topology name.")
20  protected String topologyName;
21 
22  @Option(name="--local-execution-time", usage="Work time limit, when started in \"local\" execution mode.")
23  protected Integer localExecutionTime;
24 
25  @Argument(metaVar="CONFIG", multiValued=true, usage="Extra configuration file(s) (can accept multiple paths).")
26  private File extraConfiguration[] = {};
27 
28  protected Properties properties;
29 
30  public CliArguments(String[] args) throws CmdLineException, ConfigurationException {
31  CmdLineParser parser = new CmdLineParser(this);
32  parser.parseArgument(args);
33 
34  topologyName = fixTopologyName();
35 
36  loadExtraConfig();
37  }
38 
39  public Boolean getIsLocal() {
40  return isLocal;
41  }
42 
43  public String getTopologyName() {
44  return topologyName;
45  }
46 
47  public Integer getLocalExecutionTime() {
48  return localExecutionTime;
49  }
50 
51  public Properties getProperties() {
52  return properties;
53  }
54 
55  private String fixTopologyName() {
56  String value = getTopologyName();
57  if (value == null) {
58  return null;
59  }
60  if (value.isEmpty()) {
61  return null;
62  }
63  return value;
64  }
65 
66  private void loadExtraConfig() throws ConfigurationException {
67  properties = new Properties();
68  try {
69  properties.load(this.getClass().getResourceAsStream(Topology.TOPOLOGY_PROPERTIES));
70  } catch (IOException e) {
71  throw new ConfigurationException("Unable to load default properties.", e);
72  }
73 
74  for (File path : extraConfiguration) {
75  Properties override = new Properties(properties);
76  try {
77  FileInputStream source = new FileInputStream(path);
78  override.load(source);
79  } catch (IOException e) {
80  throw new ConfigurationException(String.format("Unable to load properties from %s", path), e);
81  }
82 
83  properties = override;
84  }
85  }
86 }
value
Definition: nodes.py:62
name
Definition: setup.py:24
source
Definition: nodes.py:53