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;
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations