Search in sources :

Example 86 with GenericOptionsParser

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()));
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) ArrayList(java.util.ArrayList) Constants(org.apache.metron.common.Constants) BytesWritable(org.apache.hadoop.io.BytesWritable) Date(java.util.Date) IOException(java.io.IOException) SequenceFile(org.apache.hadoop.io.SequenceFile) PacketInfo(org.apache.metron.pcap.PacketInfo) LongWritable(org.apache.hadoop.io.LongWritable) GenericOptionsParser(org.apache.hadoop.util.GenericOptionsParser)

Example 87 with GenericOptionsParser

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;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException) CredentialShell(org.apache.hadoop.security.alias.CredentialShell) IOException(java.io.IOException) GenericOptionsParser(org.apache.hadoop.util.GenericOptionsParser)

Example 88 with GenericOptionsParser

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) Configuration(org.apache.hadoop.conf.Configuration) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) CredentialShell(org.apache.hadoop.security.alias.CredentialShell) IOException(java.io.IOException) GenericOptionsParser(org.apache.hadoop.util.GenericOptionsParser)

Example 89 with GenericOptionsParser

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;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException) CredentialShell(org.apache.hadoop.security.alias.CredentialShell) IOException(java.io.IOException) GenericOptionsParser(org.apache.hadoop.util.GenericOptionsParser)

Example 90 with GenericOptionsParser

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;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException) CredentialShell(org.apache.hadoop.security.alias.CredentialShell) IOException(java.io.IOException) GenericOptionsParser(org.apache.hadoop.util.GenericOptionsParser)

Aggregations

GenericOptionsParser (org.apache.hadoop.util.GenericOptionsParser)102 Configuration (org.apache.hadoop.conf.Configuration)72 Path (org.apache.hadoop.fs.Path)38 Job (org.apache.hadoop.mapreduce.Job)35 CommandLine (org.apache.commons.cli.CommandLine)18 IOException (java.io.IOException)15 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)11 PosixParser (org.apache.commons.cli.PosixParser)10 FileSystem (org.apache.hadoop.fs.FileSystem)10 HCatSchema (org.apache.hive.hcatalog.data.schema.HCatSchema)10 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)9 ParseException (org.apache.commons.cli.ParseException)7 Test (org.junit.jupiter.api.Test)7 ArrayList (java.util.ArrayList)6 Options (org.apache.commons.cli.Options)6 JobConf (org.apache.hadoop.mapred.JobConf)6 File (java.io.File)5 HashMap (java.util.HashMap)5 YarnUncaughtExceptionHandler (org.apache.hadoop.yarn.YarnUncaughtExceptionHandler)5 TezConfiguration (org.apache.tez.dag.api.TezConfiguration)5