Search in sources :

Example 51 with GET

use of javax.ws.rs.GET in project hbase by apache.

the class StorageClusterStatusResource method get.

@GET
@Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(@Context final UriInfo uriInfo) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("GET " + uriInfo.getAbsolutePath());
    }
    servlet.getMetrics().incrementRequests(1);
    try {
        ClusterStatus status = servlet.getAdmin().getClusterStatus();
        StorageClusterStatusModel model = new StorageClusterStatusModel();
        model.setRegions(status.getRegionsCount());
        model.setRequests(status.getRequestsCount());
        model.setAverageLoad(status.getAverageLoad());
        for (ServerName info : status.getServers()) {
            ServerLoad load = status.getLoad(info);
            StorageClusterStatusModel.Node node = model.addLiveNode(info.getHostname() + ":" + Integer.toString(info.getPort()), info.getStartcode(), load.getUsedHeapMB(), load.getMaxHeapMB());
            node.setRequests(load.getNumberOfRequests());
            for (RegionLoad region : load.getRegionsLoad().values()) {
                node.addRegion(region.getName(), region.getStores(), region.getStorefiles(), region.getStorefileSizeMB(), region.getMemStoreSizeMB(), region.getStorefileIndexSizeMB(), region.getReadRequestsCount(), region.getWriteRequestsCount(), region.getRootIndexSizeKB(), region.getTotalStaticIndexSizeKB(), region.getTotalStaticBloomSizeKB(), region.getTotalCompactingKVs(), region.getCurrentCompactedKVs());
            }
        }
        for (ServerName name : status.getDeadServerNames()) {
            model.addDeadNode(name.toString());
        }
        ResponseBuilder response = Response.ok(model);
        response.cacheControl(cacheControl);
        servlet.getMetrics().incrementSucessfulGetRequests(1);
        return response.build();
    } catch (IOException e) {
        servlet.getMetrics().incrementFailedGetRequests(1);
        return Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT).entity("Unavailable" + CRLF).build();
    }
}
Also used : ServerLoad(org.apache.hadoop.hbase.ServerLoad) RegionLoad(org.apache.hadoop.hbase.RegionLoad) ServerName(org.apache.hadoop.hbase.ServerName) StorageClusterStatusModel(org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel) IOException(java.io.IOException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 52 with GET

use of javax.ws.rs.GET in project hbase by apache.

the class TableScanResource method getProtobuf.

@GET
@Produces({ Constants.MIMETYPE_PROTOBUF, Constants.MIMETYPE_PROTOBUF_IETF })
public Response getProtobuf(@Context final UriInfo uriInfo, @PathParam("scanspec") final String scanSpec, @HeaderParam("Accept") final String contentType, @DefaultValue(Integer.MAX_VALUE + "") @QueryParam(Constants.SCAN_LIMIT) int userRequestedLimit, @DefaultValue("") @QueryParam(Constants.SCAN_START_ROW) String startRow, @DefaultValue("") @QueryParam(Constants.SCAN_END_ROW) String endRow, @DefaultValue("column") @QueryParam(Constants.SCAN_COLUMN) List<String> column, @DefaultValue("1") @QueryParam(Constants.SCAN_MAX_VERSIONS) int maxVersions, @DefaultValue("-1") @QueryParam(Constants.SCAN_BATCH_SIZE) int batchSize, @DefaultValue("0") @QueryParam(Constants.SCAN_START_TIME) long startTime, @DefaultValue(Long.MAX_VALUE + "") @QueryParam(Constants.SCAN_END_TIME) long endTime, @DefaultValue("true") @QueryParam(Constants.SCAN_BATCH_SIZE) boolean cacheBlocks) {
    servlet.getMetrics().incrementRequests(1);
    try {
        int fetchSize = this.servlet.getConfiguration().getInt(Constants.SCAN_FETCH_SIZE, 10);
        ProtobufStreamingUtil stream = new ProtobufStreamingUtil(this.results, contentType, userRequestedLimit, fetchSize);
        servlet.getMetrics().incrementSucessfulScanRequests(1);
        ResponseBuilder response = Response.ok(stream);
        response.header("content-type", contentType);
        return response.build();
    } catch (Exception exp) {
        servlet.getMetrics().incrementFailedScanRequests(1);
        processException(exp);
        LOG.warn(exp);
        return null;
    }
}
Also used : ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) IOException(java.io.IOException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 53 with GET

use of javax.ws.rs.GET in project hbase by apache.

the class VersionResource method get.

/**
   * Build a response for a version request.
   * @param context servlet context
   * @param uriInfo (JAX-RS context variable) request URL
   * @return a response for a version request
   */
@GET
@Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(@Context final ServletContext context, @Context final UriInfo uriInfo) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("GET " + uriInfo.getAbsolutePath());
    }
    servlet.getMetrics().incrementRequests(1);
    ResponseBuilder response = Response.ok(new VersionModel(context));
    response.cacheControl(cacheControl);
    servlet.getMetrics().incrementSucessfulGetRequests(1);
    return response.build();
}
Also used : ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) VersionModel(org.apache.hadoop.hbase.rest.model.VersionModel) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 54 with GET

use of javax.ws.rs.GET in project hbase by apache.

the class ExistsResource method get.

@GET
@Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF, MIMETYPE_BINARY })
public Response get(@Context final UriInfo uriInfo) {
    try {
        if (!tableResource.exists()) {
            return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF).build();
        }
    } catch (IOException e) {
        return Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT).entity("Unavailable" + CRLF).build();
    }
    ResponseBuilder response = Response.ok();
    response.cacheControl(cacheControl);
    return response.build();
}
Also used : IOException(java.io.IOException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 55 with GET

use of javax.ws.rs.GET in project zeppelin by apache.

the class SecurityRestApi method getUserList.

/**
   * Get userlist
   * Returns list of all user from available realms
   *
   * @return 200 response
   */
@GET
@Path("userlist/{searchText}")
public Response getUserList(@PathParam("searchText") final String searchText) {
    List<String> usersList = new ArrayList<>();
    List<String> rolesList = new ArrayList<>();
    try {
        GetUserList getUserListObj = new GetUserList();
        Collection realmsList = SecurityUtils.getRealmsList();
        if (realmsList != null) {
            for (Iterator<Realm> iterator = realmsList.iterator(); iterator.hasNext(); ) {
                Realm realm = iterator.next();
                String name = realm.getClass().getName();
                if (LOG.isDebugEnabled()) {
                    LOG.debug("RealmClass.getName: " + name);
                }
                if (name.equals("org.apache.shiro.realm.text.IniRealm")) {
                    usersList.addAll(getUserListObj.getUserList((IniRealm) realm));
                    rolesList.addAll(getUserListObj.getRolesList((IniRealm) realm));
                } else if (name.equals("org.apache.zeppelin.realm.LdapGroupRealm")) {
                    usersList.addAll(getUserListObj.getUserList((JndiLdapRealm) realm, searchText));
                } else if (name.equals("org.apache.zeppelin.realm.LdapRealm")) {
                    usersList.addAll(getUserListObj.getUserList((LdapRealm) realm, searchText));
                    rolesList.addAll(getUserListObj.getRolesList((LdapRealm) realm));
                } else if (name.equals("org.apache.zeppelin.realm.ActiveDirectoryGroupRealm")) {
                    usersList.addAll(getUserListObj.getUserList((ActiveDirectoryGroupRealm) realm, searchText));
                } else if (name.equals("org.apache.shiro.realm.jdbc.JdbcRealm")) {
                    usersList.addAll(getUserListObj.getUserList((JdbcRealm) realm));
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Exception in retrieving Users from realms ", e);
    }
    List<String> autoSuggestUserList = new ArrayList<>();
    List<String> autoSuggestRoleList = new ArrayList<>();
    Collections.sort(usersList);
    Collections.sort(rolesList);
    Collections.sort(usersList, new Comparator<String>() {

        @Override
        public int compare(String o1, String o2) {
            if (o1.matches(searchText + "(.*)") && o2.matches(searchText + "(.*)")) {
                return 0;
            } else if (o1.matches(searchText + "(.*)")) {
                return -1;
            }
            return 0;
        }
    });
    int maxLength = 0;
    for (String user : usersList) {
        if (StringUtils.containsIgnoreCase(user, searchText)) {
            autoSuggestUserList.add(user);
            maxLength++;
        }
        if (maxLength == 5) {
            break;
        }
    }
    for (String role : rolesList) {
        if (StringUtils.containsIgnoreCase(role, searchText)) {
            autoSuggestRoleList.add(role);
        }
    }
    Map<String, List> returnListMap = new HashMap<>();
    returnListMap.put("users", autoSuggestUserList);
    returnListMap.put("roles", autoSuggestRoleList);
    return new JsonResponse<>(Response.Status.OK, "", returnListMap).build();
}
Also used : IniRealm(org.apache.shiro.realm.text.IniRealm) JdbcRealm(org.apache.shiro.realm.jdbc.JdbcRealm) LdapRealm(org.apache.zeppelin.realm.LdapRealm) JndiLdapRealm(org.apache.shiro.realm.ldap.JndiLdapRealm) IniRealm(org.apache.shiro.realm.text.IniRealm) LdapRealm(org.apache.zeppelin.realm.LdapRealm) Realm(org.apache.shiro.realm.Realm) ActiveDirectoryGroupRealm(org.apache.zeppelin.realm.ActiveDirectoryGroupRealm) JdbcRealm(org.apache.shiro.realm.jdbc.JdbcRealm) JndiLdapRealm(org.apache.shiro.realm.ldap.JndiLdapRealm) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

GET (javax.ws.rs.GET)1140 Path (javax.ws.rs.Path)902 Produces (javax.ws.rs.Produces)734 ApiOperation (io.swagger.annotations.ApiOperation)230 ApiResponses (io.swagger.annotations.ApiResponses)163 IOException (java.io.IOException)139 Response (javax.ws.rs.core.Response)116 WebApplicationException (javax.ws.rs.WebApplicationException)113 Timed (com.codahale.metrics.annotation.Timed)103 ArrayList (java.util.ArrayList)100 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)91 List (java.util.List)83 Map (java.util.Map)80 HashMap (java.util.HashMap)78 URI (java.net.URI)70 TimedResource (org.killbill.commons.metrics.TimedResource)58 TenantContext (org.killbill.billing.util.callcontext.TenantContext)57 ApiResponse (io.swagger.annotations.ApiResponse)52 NotFoundException (org.apache.hadoop.yarn.webapp.NotFoundException)39 Consumes (javax.ws.rs.Consumes)36