Search in sources :

Example 1 with OutStream

use of org.folio.rest.tools.utils.OutStream in project raml-module-builder by folio-org.

the class AdminAPI method getAdminCacheHitRates.

@Override
public void getAdminCacheHitRates(Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    try {
        PostgresClient.getInstance(vertxContext.owner()).select("SELECT sum(heap_blks_read) as heap_read, sum(heap_blks_hit)  as heap_hit," + " (sum(heap_blks_hit) - sum(heap_blks_read)) / sum(heap_blks_hit) as ratio " + "FROM pg_statio_user_tables;", reply -> {
            if (reply.succeeded()) {
                OutStream stream = new OutStream();
                stream.setData(reply.result().getRows());
                asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminCacheHitRatesResponse.withJsonOK(stream)));
            } else {
                log.error(reply.cause().getMessage(), reply.cause());
                asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
            }
        });
    } catch (Exception e) {
        log.error(e.getMessage());
        asyncResultHandler.handle(io.vertx.core.Future.failedFuture(e.getMessage()));
    }
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream)

Example 2 with OutStream

use of org.folio.rest.tools.utils.OutStream in project raml-module-builder by folio-org.

the class AdminAPI method getAdminTableIndexUsage.

@Override
public void getAdminTableIndexUsage(Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    PostgresClient.getInstance(vertxContext.owner()).select("SELECT relname, 100 * idx_scan / (seq_scan + idx_scan) percent_of_times_index_used, n_live_tup rows_in_table " + "FROM pg_stat_user_tables " + "ORDER BY n_live_tup DESC;", reply -> {
        if (reply.succeeded()) {
            OutStream stream = new OutStream();
            stream.setData(reply.result().getRows());
            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminTableIndexUsageResponse.withJsonOK(stream)));
        } else {
            log.error(reply.cause().getMessage(), reply.cause());
            asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
        }
    });
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream)

Example 3 with OutStream

use of org.folio.rest.tools.utils.OutStream in project raml-module-builder by folio-org.

the class AdminAPI method putAdminLoglevel.

@Validate
@Override
public void putAdminLoglevel(Level level, String javaPackage, java.util.Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    try {
        JsonObject updatedLoggers = LogUtil.updateLogConfiguration(javaPackage, level.name());
        OutStream os = new OutStream();
        os.setData(updatedLoggers);
        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutAdminLoglevelResponse.withJsonOK(os)));
    } catch (Exception e) {
        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutAdminLoglevelResponse.withPlainInternalServerError("ERROR" + e.getMessage())));
        log.error(e.getMessage(), e);
    }
}
Also used : JsonObject(io.vertx.core.json.JsonObject) OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Example 4 with OutStream

use of org.folio.rest.tools.utils.OutStream in project raml-module-builder by folio-org.

the class AdminAPI method getAdminPostgresTableAccessStats.

@Validate
@Override
public void getAdminPostgresTableAccessStats(Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    PostgresClient.getInstance(vertxContext.owner()).select("SELECT schemaname,relname,seq_scan,idx_scan,cast(idx_scan " + "AS numeric) / (idx_scan + seq_scan) AS idx_scan_pct " + "FROM pg_stat_user_tables WHERE (idx_scan + seq_scan)>0 " + "ORDER BY idx_scan_pct;", reply -> {
        if (reply.succeeded()) {
            OutStream stream = new OutStream();
            stream.setData(reply.result().getRows());
            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminPostgresTableAccessStatsResponse.withJsonOK(stream)));
        } else {
            log.error(reply.cause().getMessage(), reply.cause());
            asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
        }
    });
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Example 5 with OutStream

use of org.folio.rest.tools.utils.OutStream in project raml-module-builder by folio-org.

the class AdminAPI method getAdminPostgresActiveSessions.

@Validate
@Override
public void getAdminPostgresActiveSessions(String dbname, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    PostgresClient.getInstance(vertxContext.owner(), "public").select("SELECT pid , usename, " + "application_name, client_addr, client_hostname, " + "query, state from pg_stat_activity where datname='" + dbname + "'", reply -> {
        if (reply.succeeded()) {
            OutStream stream = new OutStream();
            stream.setData(reply.result().getRows());
            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminPostgresActiveSessionsResponse.withJsonOK(stream)));
        } else {
            log.error(reply.cause().getMessage(), reply.cause());
            asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
        }
    });
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Aggregations

OutStream (org.folio.rest.tools.utils.OutStream)40 Validate (org.folio.rest.annotations.Validate)26 FieldException (org.z3950.zing.cql.cql2pgjson.FieldException)13 CQLParseException (org.z3950.zing.cql.CQLParseException)8 PostgresClient (org.folio.rest.persist.PostgresClient)7 List (java.util.List)5 JsonObject (io.vertx.core.json.JsonObject)4 Response (javax.ws.rs.core.Response)4 CQLWrapper (org.folio.rest.persist.cql.CQLWrapper)4 Map (java.util.Map)3 Limit (org.folio.rest.persist.Criteria.Limit)3 Offset (org.folio.rest.persist.Criteria.Offset)3 TenantTool (org.folio.rest.tools.utils.TenantTool)3 CQL2PgJSON (org.z3950.zing.cql.cql2pgjson.CQL2PgJSON)3 io.vertx.core (io.vertx.core)2 AsyncResult (io.vertx.core.AsyncResult)2 JsonArray (io.vertx.core.json.JsonArray)2 Logger (io.vertx.core.logging.Logger)2 LoggerFactory (io.vertx.core.logging.LoggerFactory)2 InputStream (java.io.InputStream)2