use of org.apache.hadoop.util.GenericOptionsParser in project metron by apache.
the class PcapInspector method main.
public static void main(String... argv) throws IOException {
Configuration conf = new Configuration();
String[] otherArgs = new GenericOptionsParser(conf, argv).getRemainingArgs();
CommandLine cli = InspectorOptions.parse(new PosixParser(), otherArgs);
Path inputPath = new Path(InspectorOptions.INPUT.get(cli));
int n = -1;
if (InspectorOptions.NUM.has(cli)) {
n = Integer.parseInt(InspectorOptions.NUM.get(cli));
}
SequenceFile.Reader reader = new SequenceFile.Reader(new Configuration(), SequenceFile.Reader.file(inputPath));
LongWritable key = new LongWritable();
BytesWritable value = new BytesWritable();
for (int i = 0; (n < 0 || i < n) && reader.next(key, value); ++i) {
long millis = Long.divideUnsigned(key.get(), 1000000);
String ts = DATE_FORMAT.format(new Date(millis));
try {
for (PacketInfo pi : PcapHelper.toPacketInfo(value.copyBytes())) {
Map<String, Object> result = PcapHelper.packetToFields(pi);
List<String> fieldResults = new ArrayList<String>() {
{
add("TS: " + ts);
}
};
for (Constants.Fields field : Constants.Fields.values()) {
if (result.containsKey(field.getName())) {
fieldResults.add(field.getName() + ": " + result.get(field.getName()));
}
}
System.out.println(Joiner.on(",").join(fieldResults));
}
} catch (Exception e) {
System.out.println(String.format("Error: malformed packet #=%s, ts=%s, error msg=%s", i + 1, ts, e.getMessage()));
}
}
}
use of org.apache.hadoop.util.GenericOptionsParser in project ranger by apache.
the class buildks method deleteCredential.
public int deleteCredential(String[] args, boolean isSilentMode) {
int returnCode = -1;
try {
if (args != null && args.length == 4) {
// for non-interactive, insert argument "-f" if needed
if (isSilentMode && isCredentialShellInteractiveEnabled()) {
String[] updatedArgs = new String[5];
updatedArgs[0] = args[0];
updatedArgs[1] = args[1];
updatedArgs[2] = "-f";
updatedArgs[3] = args[2];
updatedArgs[4] = args[3];
args = updatedArgs;
}
// display command which need to be executed or entered
displayCommand(args);
} else {
return returnCode;
}
CredentialShell cs = new CredentialShell();
Configuration conf = new Configuration();
// parse argument
GenericOptionsParser parser = new GenericOptionsParser(conf, args);
// set the configuration back, so that Tool can configure itself
cs.setConf(conf);
// get valid and remaining argument
String[] toolArgs = parser.getRemainingArgs();
// execute command in CredentialShell
// String[] finalArgs = Arrays.copyOfRange(toolArgs, 0, 6);
returnCode = cs.run(toolArgs);
// if response code is zero then success else failure
// System.out.println("Response Code:"+returnCode);
} catch (IOException ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
return returnCode;
}
use of org.apache.hadoop.util.GenericOptionsParser in project ranger by apache.
the class buildks method createCredentialFromUserInput.
public int createCredentialFromUserInput() {
int returnCode = -1;
try {
String[] args = null;
String command = null;
String alias = null;
String valueOption = null;
String credential = null;
String providerOption = null;
String providerPath = null;
String storeTypeOption = null;
String storeType = null;
// below code can ask user to input if command line input fails
System.out.println("Enter Alias Name:");
BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
alias = bufferRead.readLine();
System.out.println("Enter password:");
credential = bufferRead.readLine();
System.out.println("Enter .jceks output file name with path:");
providerPath = bufferRead.readLine();
if (providerPath != null && !providerPath.trim().isEmpty() && (!providerPath.startsWith("localjceks://file") && !providerPath.startsWith("jceks://file") && !providerPath.startsWith("localbcfks://file") && !providerPath.startsWith("bcfks://file"))) {
if (providerPath.startsWith("/")) {
providerPath = "jceks://file" + providerPath;
} else {
providerPath = "jceks://file/" + providerPath;
}
}
command = "create";
valueOption = "-value";
providerOption = "-provider";
if (!isValidCreateCommand(command, alias, valueOption, credential, providerOption, providerPath, storeTypeOption, storeType)) {
return returnCode;
}
args = new String[6];
args[0] = command;
args[1] = alias;
args[2] = valueOption;
args[3] = credential;
args[4] = providerOption;
args[5] = providerPath;
CredentialShell cs = new CredentialShell();
Configuration conf = new Configuration();
// parse argument
GenericOptionsParser parser = new GenericOptionsParser(conf, args);
// set the configuration back, so that Tool can configure itself
cs.setConf(conf);
// get valid and remaining argument
String[] toolArgs = parser.getRemainingArgs();
// execute command in CredentialShell
returnCode = cs.run(toolArgs);
// if response code is zero then success else failure
// System.out.println("Response Code:"+returnCode);
} catch (IOException ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
return returnCode;
}
use of org.apache.hadoop.util.GenericOptionsParser in project ranger by apache.
the class buildks method listCredential.
public int listCredential(String[] args) {
int returnCode = -1;
String command = null;
String providerOption = null;
String providerPath = null;
String storeType = KeyStore.getDefaultType();
try {
if (args != null && args.length == 3) {
command = args[0];
providerOption = args[1];
providerPath = args[2];
if (!isValidListCommand(command, providerOption, providerPath, storeType)) {
return returnCode;
}
// display command which need to be executed or entered
displayCommand(args);
} else {
return returnCode;
}
CredentialShell cs = new CredentialShell();
Configuration conf = new Configuration();
// parse argument
GenericOptionsParser parser = new GenericOptionsParser(conf, args);
// set the configuration back, so that Tool can configure itself
cs.setConf(conf);
// get valid and remaining argument
String[] toolArgs = parser.getRemainingArgs();
// execute command in CredentialShell
returnCode = cs.run(toolArgs);
// if response code is zero then success else failure
// System.out.println("Response Code:"+returnCode);
} catch (IOException ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
return returnCode;
}
use of org.apache.hadoop.util.GenericOptionsParser in project ranger by apache.
the class buildks method createKeyStore.
public int createKeyStore(String[] args) {
int returnCode = -1;
try {
String command = null;
String alias = null;
String valueOption = null;
String credential = null;
String providerOption = null;
String providerPath = null;
String storeTypeOption = "storeType";
String storeType = KeyStore.getDefaultType();
if (args != null && (args.length == 6 || args.length == 8)) {
command = args[0];
alias = args[1];
valueOption = args[2];
credential = args[3];
providerOption = args[4];
providerPath = args[5];
if (args.length == 8) {
storeTypeOption = args[6];
storeType = args[7];
}
if (!isValidCreateCommand(command, alias, valueOption, credential, providerOption, providerPath, storeTypeOption, storeType)) {
return returnCode;
}
displayCommand(args);
} else {
return returnCode;
}
CredentialShell cs = new CredentialShell();
Configuration conf = new Configuration();
// parse argument
GenericOptionsParser parser = new GenericOptionsParser(conf, args);
// set the configuration back, so that Tool can configure itself
cs.setConf(conf);
// get valid and remaining argument
String[] toolArgs = parser.getRemainingArgs();
// execute command in CredentialShell
// int i = 0;
// for(String s : toolArgs) {
// System.out.println("TooArgs [" + i + "] = [" + s + "]");
// i++;
// }
String[] finalArgs = Arrays.copyOfRange(toolArgs, 0, 6);
returnCode = cs.run(finalArgs);
// if response code is zero then success else failure
} catch (IOException ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
return returnCode;
}
Aggregations