Search in sources :

Example 31 with SuppressForbidden

use of org.opensearch.common.SuppressForbidden in project OpenSearch by opensearch-project.

the class BenchmarkMain method main.

@SuppressForbidden(reason = "system out is ok for a command line tool")
public static void main(String[] args) throws Exception {
    String type = args[0];
    AbstractBenchmark<?> benchmark = null;
    if ("rest".equals(type)) {
        benchmark = new RestClientBenchmark();
    } else {
        System.err.println("Unknown client type [" + type + "]");
        System.exit(1);
    }
    benchmark.run(Arrays.copyOfRange(args, 1, args.length));
}
Also used : RestClientBenchmark(org.opensearch.client.benchmark.rest.RestClientBenchmark) SuppressForbidden(org.opensearch.common.SuppressForbidden)

Example 32 with SuppressForbidden

use of org.opensearch.common.SuppressForbidden in project OpenSearch by opensearch-project.

the class BenchmarkRunner method run.

@SuppressForbidden(reason = "system out is ok for a command line tool")
public void run() {
    SampleRecorder recorder = new SampleRecorder(iterations);
    System.out.printf("Running %s with %d warmup iterations and %d iterations.%n", task.getClass().getSimpleName(), warmupIterations, iterations);
    try {
        task.setUp(recorder);
        task.run();
        task.tearDown();
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        return;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    List<Sample> samples = recorder.getSamples();
    final List<Metrics> summaryMetrics = MetricsCalculator.calculate(samples);
    if (summaryMetrics.isEmpty()) {
        System.out.println("No results.");
    }
    for (Metrics metrics : summaryMetrics) {
        String throughput = String.format(Locale.ROOT, "Throughput [ops/s]: %f", metrics.throughput);
        String serviceTimes = String.format(Locale.ROOT, "Service time [ms]: p50 = %f, p90 = %f, p95 = %f, p99 = %f, p99.9 = %f, p99.99 = %f", metrics.serviceTimeP50, metrics.serviceTimeP90, metrics.serviceTimeP95, metrics.serviceTimeP99, metrics.serviceTimeP999, metrics.serviceTimeP9999);
        String latencies = String.format(Locale.ROOT, "Latency [ms]:      p50 = %f, p90 = %f, p95 = %f, p99 = %f, p99.9 = %f, p99.99 = %f", metrics.latencyP50, metrics.latencyP90, metrics.latencyP95, metrics.latencyP99, metrics.latencyP999, metrics.latencyP9999);
        int lineLength = Math.max(serviceTimes.length(), latencies.length());
        System.out.println(repeat(lineLength, '-'));
        System.out.println(throughput);
        System.out.println(serviceTimes);
        System.out.println(latencies);
        System.out.printf("success count = %d, error count = %d%n", metrics.successCount, metrics.errorCount);
        System.out.println(repeat(lineLength, '-'));
    }
}
Also used : Metrics(org.opensearch.client.benchmark.metrics.Metrics) Sample(org.opensearch.client.benchmark.metrics.Sample) SampleRecorder(org.opensearch.client.benchmark.metrics.SampleRecorder) SuppressForbidden(org.opensearch.common.SuppressForbidden)

Example 33 with SuppressForbidden

use of org.opensearch.common.SuppressForbidden in project OpenSearch by opensearch-project.

the class TikaImpl method getRestrictedPermissions.

// compute some minimal permissions for parsers. they only get r/w access to the java temp directory,
// the ability to load some resources from JARs, and read sysprops
@SuppressForbidden(reason = "adds access to tmp directory")
static PermissionCollection getRestrictedPermissions() {
    Permissions perms = new Permissions();
    // property/env access needed for parsing
    perms.add(new PropertyPermission("*", "read"));
    perms.add(new RuntimePermission("getenv.TIKA_CONFIG"));
    try {
        // add permissions for resource access:
        // classpath
        addReadPermissions(perms, JarHell.parseClassPath());
        // plugin jars
        if (TikaImpl.class.getClassLoader() instanceof URLClassLoader) {
            URL[] urls = ((URLClassLoader) TikaImpl.class.getClassLoader()).getURLs();
            Set<URL> set = new LinkedHashSet<>(Arrays.asList(urls));
            if (set.size() != urls.length) {
                throw new AssertionError("duplicate jars: " + Arrays.toString(urls));
            }
            addReadPermissions(perms, set);
        }
        // jvm's java.io.tmpdir (needs read/write)
        FilePermissionUtils.addDirectoryPath(perms, "java.io.tmpdir", PathUtils.get(System.getProperty("java.io.tmpdir")), "read,readlink,write,delete", false);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    // current hacks needed for POI/PDFbox issues:
    perms.add(new SecurityPermission("putProviderProperty.BC"));
    perms.add(new SecurityPermission("insertProvider"));
    perms.add(new ReflectPermission("suppressAccessChecks"));
    perms.add(new RuntimePermission("accessClassInPackage.sun.java2d.cmm.kcms"));
    // xmlbeans, use by POI, needs to get the context classloader
    perms.add(new RuntimePermission("getClassLoader"));
    perms.setReadOnly();
    return perms;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PropertyPermission(java.util.PropertyPermission) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) URL(java.net.URL) URLClassLoader(java.net.URLClassLoader) Permissions(java.security.Permissions) ReflectPermission(java.lang.reflect.ReflectPermission) SecurityPermission(java.security.SecurityPermission) SuppressForbidden(org.opensearch.common.SuppressForbidden)

Example 34 with SuppressForbidden

use of org.opensearch.common.SuppressForbidden in project OpenSearch by opensearch-project.

the class EvilOpenSearchCliTests method testPathHome.

@SuppressForbidden(reason = "manipulates system properties for testing")
public void testPathHome() throws Exception {
    final String pathHome = System.getProperty("opensearch.path.home");
    final String value = randomAlphaOfLength(16);
    System.setProperty("opensearch.path.home", value);
    runTest(ExitCodes.OK, true, (output, error) -> {
    }, (foreground, pidFile, quiet, esSettings) -> {
        Settings settings = esSettings.settings();
        assertThat(settings.keySet(), hasSize(2));
        assertThat(settings.get("path.home"), equalTo(PathUtils.get(System.getProperty("user.dir")).resolve(value).toString()));
        // added by env initialization
        assertThat(settings.keySet(), hasItem("path.logs"));
    });
    System.clearProperty("opensearch.path.home");
    final String commandLineValue = randomAlphaOfLength(16);
    runTest(ExitCodes.OK, true, (output, error) -> {
    }, (foreground, pidFile, quiet, esSettings) -> {
        Settings settings = esSettings.settings();
        assertThat(settings.keySet(), hasSize(2));
        assertThat(settings.get("path.home"), equalTo(PathUtils.get(System.getProperty("user.dir")).resolve(commandLineValue).toString()));
        // added by env initialization
        assertThat(settings.keySet(), hasItem("path.logs"));
    }, "-Epath.home=" + commandLineValue);
    if (pathHome != null)
        System.setProperty("opensearch.path.home", pathHome);
    else
        System.clearProperty("opensearch.path.home");
}
Also used : Settings(org.opensearch.common.settings.Settings) SuppressForbidden(org.opensearch.common.SuppressForbidden)

Example 35 with SuppressForbidden

use of org.opensearch.common.SuppressForbidden in project OpenSearch by opensearch-project.

the class OpenSearchPolicyUnitTests method testDataPathPermissionIsChecked.

@SuppressForbidden(reason = "to create FilePermission object")
public void testDataPathPermissionIsChecked() {
    assumeTrue("test cannot run with security manager", System.getSecurityManager() == null);
    final PermissionCollection dataPathPermission = new Permissions();
    dataPathPermission.add(new FilePermission("/home/opensearch/data/-", "read"));
    final OpenSearchPolicy policy = new OpenSearchPolicy(Collections.emptyMap(), new Permissions(), Collections.emptyMap(), true, dataPathPermission);
    assertTrue(policy.implies(new ProtectionDomain(new CodeSource(null, (Certificate[]) null), new Permissions()), new FilePermission("/home/opensearch/data/index/file.si", "read")));
}
Also used : PermissionCollection(java.security.PermissionCollection) ProtectionDomain(java.security.ProtectionDomain) Permissions(java.security.Permissions) CodeSource(java.security.CodeSource) FilePermission(java.io.FilePermission) SuppressForbidden(org.opensearch.common.SuppressForbidden)

Aggregations

SuppressForbidden (org.opensearch.common.SuppressForbidden)42 URL (java.net.URL)17 Path (java.nio.file.Path)13 IOException (java.io.IOException)12 FilePermission (java.io.FilePermission)8 HttpURLConnection (java.net.HttpURLConnection)6 Settings (org.opensearch.common.settings.Settings)6 File (java.io.File)5 Permissions (java.security.Permissions)5 HashMap (java.util.HashMap)5 URLConnection (java.net.URLConnection)4 ProtectionDomain (java.security.ProtectionDomain)4 ArrayList (java.util.ArrayList)4 LinkedHashSet (java.util.LinkedHashSet)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 InputStream (java.io.InputStream)3 CodeSource (java.security.CodeSource)3 PermissionCollection (java.security.PermissionCollection)3 Policy (java.security.Policy)3 HashSet (java.util.HashSet)3