Search in sources :

Example 6 with RestException

use of org.apache.metron.rest.RestException in project metron by apache.

the class GrokServiceImpl method validateGrokStatement.

@Override
public GrokValidation validateGrokStatement(GrokValidation grokValidation) throws RestException {
    Map<String, Object> results;
    try {
        if (grokValidation.getPatternLabel() == null) {
            throw new RestException("Pattern label is required");
        }
        if (Strings.isEmpty(grokValidation.getStatement())) {
            throw new RestException("Grok statement is required");
        }
        Grok grok = new Grok();
        grok.addPatternFromReader(new InputStreamReader(getClass().getResourceAsStream("/patterns/common")));
        grok.addPatternFromReader(new StringReader(grokValidation.getStatement()));
        String grokPattern = "%{" + grokValidation.getPatternLabel() + "}";
        grok.compile(grokPattern);
        Match gm = grok.match(grokValidation.getSampleData());
        gm.captures();
        results = gm.toMap();
        results.remove(grokValidation.getPatternLabel());
    } catch (Exception e) {
        throw new RestException(e);
    }
    grokValidation.setResults(results);
    return grokValidation;
}
Also used : InputStreamReader(java.io.InputStreamReader) Grok(oi.thekraken.grok.api.Grok) RestException(org.apache.metron.rest.RestException) StringReader(java.io.StringReader) RestException(org.apache.metron.rest.RestException) Match(oi.thekraken.grok.api.Match)

Example 7 with RestException

use of org.apache.metron.rest.RestException in project metron by apache.

the class HdfsServiceImpl method write.

@Override
public void write(Path path, byte[] contents, String userMode, String groupMode, String otherMode) throws RestException {
    FSDataOutputStream fsDataOutputStream;
    try {
        FsPermission permission = null;
        boolean setPermissions = false;
        if (StringUtils.isNotEmpty(userMode) && StringUtils.isNotEmpty(groupMode) && StringUtils.isNotEmpty(otherMode)) {
            // invalid actions will return null
            FsAction userAction = FsAction.getFsAction(userMode);
            FsAction groupAction = FsAction.getFsAction(groupMode);
            FsAction otherAction = FsAction.getFsAction(otherMode);
            if (userAction == null || groupAction == null || otherAction == null) {
                throw new RestException(String.format("Invalid permission set: user[%s] " + "group[%s] other[%s]", userAction, groupAction, otherAction));
            }
            permission = new FsPermission(userAction, groupAction, otherAction);
            setPermissions = true;
        }
        fsDataOutputStream = FileSystem.get(configuration).create(path, true);
        fsDataOutputStream.write(contents);
        fsDataOutputStream.close();
        if (setPermissions) {
            FileSystem.get(configuration).setPermission(path, permission);
        }
    } catch (IOException e) {
        throw new RestException(e);
    }
}
Also used : FsAction(org.apache.hadoop.fs.permission.FsAction) RestException(org.apache.metron.rest.RestException) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) FsPermission(org.apache.hadoop.fs.permission.FsPermission) IOException(java.io.IOException)

Example 8 with RestException

use of org.apache.metron.rest.RestException in project metron by apache.

the class SearchServiceImpl method getColumnMetadata.

@Override
public Map<String, FieldType> getColumnMetadata(List<String> indices) throws RestException {
    try {
        if (indices == null || indices.isEmpty()) {
            indices = getDefaultIndices();
            // metaalerts should be included by default in column metadata requests
            indices.add(METAALERT_TYPE);
            LOG.debug(String.format("No indices provided for getColumnMetadata.  Using default indices: %s", String.join(",", indices)));
        }
        return dao.getColumnMetadata(indices);
    } catch (IOException ioe) {
        throw new RestException(ioe.getMessage(), ioe);
    }
}
Also used : RestException(org.apache.metron.rest.RestException) IOException(java.io.IOException)

Example 9 with RestException

use of org.apache.metron.rest.RestException in project metron by apache.

the class StormCLIWrapper method stormClientVersionInstalled.

protected String stormClientVersionInstalled() throws RestException {
    String stormClientVersionInstalled = "Storm client is not installed";
    ProcessBuilder pb = getProcessBuilder("storm", "version");
    pb.redirectErrorStream(true);
    Process p;
    try {
        p = pb.start();
    } catch (IOException e) {
        throw new RestException(e);
    }
    BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
    List<String> lines = reader.lines().collect(toList());
    lines.forEach(System.out::println);
    if (lines.size() > 1) {
        stormClientVersionInstalled = lines.get(1).replaceFirst("Storm ", "");
    }
    return stormClientVersionInstalled;
}
Also used : InputStreamReader(java.io.InputStreamReader) RestException(org.apache.metron.rest.RestException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 10 with RestException

use of org.apache.metron.rest.RestException in project metron by apache.

the class StormCLIWrapper method runCommand.

protected int runCommand(String[] command) throws RestException {
    ProcessBuilder pb = getProcessBuilder(command);
    pb.inheritIO();
    LOG.debug("Running command: cmd={}", String.join(" ", command));
    Process process;
    try {
        process = pb.start();
        process.waitFor();
    } catch (Exception e) {
        throw new RestException(e);
    }
    int exitValue = process.exitValue();
    LOG.debug("Command completed: cmd={}, exit={}", String.join(" ", command), exitValue);
    return exitValue;
}
Also used : RestException(org.apache.metron.rest.RestException) IOException(java.io.IOException) RestException(org.apache.metron.rest.RestException)

Aggregations

RestException (org.apache.metron.rest.RestException)10 IOException (java.io.IOException)4 InputStreamReader (java.io.InputStreamReader)2 HTableProvider (org.apache.metron.hbase.HTableProvider)2 Bean (org.springframework.context.annotation.Bean)2 BufferedReader (java.io.BufferedReader)1 StringReader (java.io.StringReader)1 Grok (oi.thekraken.grok.api.Grok)1 Match (oi.thekraken.grok.api.Match)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 Path (org.apache.hadoop.fs.Path)1 FsAction (org.apache.hadoop.fs.permission.FsAction)1 FsPermission (org.apache.hadoop.fs.permission.FsPermission)1 EnrichmentConfigurations (org.apache.metron.common.configuration.EnrichmentConfigurations)1 UserSettingsClient (org.apache.metron.hbase.client.UserSettingsClient)1 AccessConfig (org.apache.metron.indexing.dao.AccessConfig)1 IndexDao (org.apache.metron.indexing.dao.IndexDao)1 MetaAlertDao (org.apache.metron.indexing.dao.MetaAlertDao)1 InvalidSearchException (org.apache.metron.indexing.dao.search.InvalidSearchException)1 KeeperException (org.apache.zookeeper.KeeperException)1