Search in sources :

Example 1 with Get

use of org.restlet.resource.Get in project pinot by linkedin.

the class PinotSegmentRestletResource method get.

/**
   * URI Mappings:
   * - "/tables/{tableName}/segments", "tables/{tableName}/segments/":
   *   List all segments in the table.
   *
   * - "/tables/{tableName}/segments/{segmentName}", "/tables/{tableName}/segments/{segmentName}/":
   *   List meta-data for the specified segment.
   *
   * - "/tables/{tableName}/segments/{segmentName}?state={state}",
   *    Change the state of the segment to specified {state} (enable|disable|drop)
   *
   * - "/tables/{tableName}/segments?state={state}"
   *    Change the state of all segments of the table to specified {state} (enable|disable|drop)
   *
   * {@inheritDoc}
   * @see org.restlet.resource.ServerResource#get()
   */
@Override
@Get
public Representation get() {
    StringRepresentation presentation = null;
    try {
        final String tableName = (String) getRequest().getAttributes().get(TABLE_NAME);
        String segmentName = (String) getRequest().getAttributes().get(SEGMENT_NAME);
        if (segmentName != null) {
            segmentName = URLDecoder.decode(segmentName, "UTF-8");
        }
        final String state = getReference().getQueryAsForm().getValues(STATE);
        final String tableType = getReference().getQueryAsForm().getValues(TABLE_TYPE);
        if (tableType != null && !isValidTableType(tableType)) {
            LOGGER.error(INVALID_TABLE_TYPE_ERROR);
            setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation(INVALID_TABLE_TYPE_ERROR);
        }
        if (state != null) {
            if (!isValidState(state)) {
                LOGGER.error(INVALID_STATE_ERROR);
                setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                return new StringRepresentation(INVALID_STATE_ERROR);
            } else {
                if (segmentName != null) {
                    return toggleOneSegmentState(tableName, segmentName, state, tableType);
                } else {
                    return toggleAllSegmentsState(tableName, state, tableType);
                }
            }
        } else if (segmentName != null) {
            return getSegmentMetadataForTable(tableName, segmentName, tableType);
        } else {
            return getAllSegmentsMetadataForTable(tableName, tableType);
        }
    } catch (final Exception e) {
        presentation = new StringRepresentation(e.getMessage() + "\n" + ExceptionUtils.getStackTrace(e));
        LOGGER.error("Caught exception while processing get request", e);
        ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_SEGMENT_GET_ERROR, 1L);
        setStatus(Status.SERVER_ERROR_INTERNAL);
    }
    return presentation;
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) JSONException(org.json.JSONException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Get(org.restlet.resource.Get)

Example 2 with Get

use of org.restlet.resource.Get in project pinot by linkedin.

the class PinotTableRestletResource method get.

/**
   * URI Mappings:
   * - "/tables", "/tables/": List all the tables
   * - "/tables/{tableName}", "/tables/{tableName}/": List config for specified table.
   *
   * - "/tables/{tableName}?state={state}"
   *   Set the state for the specified {tableName} to the specified {state} (enable|disable|drop).
   *
   * - "/tables/{tableName}?type={type}"
   *   List all tables of specified type, type can be one of {offline|realtime}.
   *
   *   Set the state for the specified {tableName} to the specified {state} (enable|disable|drop).
   *   * - "/tables/{tableName}?state={state}&type={type}"
   *
   *   Set the state for the specified {tableName} of specified type to the specified {state} (enable|disable|drop).
   *   Type here is type of the table, one of 'offline|realtime'.
   * {@inheritDoc}
   * @see org.restlet.resource.ServerResource#get()
   */
@Override
@Get
public Representation get() {
    final String tableName = (String) getRequest().getAttributes().get(TABLE_NAME);
    final String state = getReference().getQueryAsForm().getValues(STATE);
    final String tableType = getReference().getQueryAsForm().getValues(TABLE_TYPE);
    if (tableType != null && !isValidTableType(tableType)) {
        LOGGER.error(INVALID_TABLE_TYPE_ERROR);
        setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
        return new StringRepresentation(INVALID_TABLE_TYPE_ERROR);
    }
    if (tableName == null) {
        try {
            return getAllTables();
        } catch (Exception e) {
            LOGGER.error("Caught exception while fetching table ", e);
            ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_GET_ERROR, 1L);
            setStatus(Status.SERVER_ERROR_INTERNAL);
            return PinotSegmentUploadRestletResource.exceptionToStringRepresentation(e);
        }
    }
    try {
        if (state == null) {
            return getTable(tableName, tableType);
        } else if (isValidState(state)) {
            return setTablestate(tableName, tableType, state);
        } else {
            LOGGER.error(INVALID_STATE_ERROR);
            setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation(INVALID_STATE_ERROR);
        }
    } catch (Exception e) {
        LOGGER.error("Caught exception while fetching table ", e);
        ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_GET_ERROR, 1L);
        setStatus(Status.SERVER_ERROR_INTERNAL);
        return PinotSegmentUploadRestletResource.exceptionToStringRepresentation(e);
    }
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JSONException(org.json.JSONException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) Get(org.restlet.resource.Get)

Example 3 with Get

use of org.restlet.resource.Get in project pinot by linkedin.

the class PinotTenantRestletResource method get.

/**
   * URI Mappings:
   * "/tenants", "/tenants/": List all the tenants in the cluster.
   * "/tenants/{tenantName}", "/tenants/{tenantName}/": List all instances for the tenant.
   * "/tenants/{tenantName}?state={state}":
   * - Set the state for the specified tenant to the specified value, one of {enable|disable|drop}.
   *
   * {@inheritDoc}
   * @see org.restlet.resource.ServerResource#get()
   */
@Override
@Get
public Representation get() {
    StringRepresentation presentation = null;
    try {
        final String tenantName = (String) getRequest().getAttributes().get(TENANT_NAME);
        final String state = getReference().getQueryAsForm().getValues(STATE);
        ;
        final String type = getReference().getQueryAsForm().getValues(TABLE_TYPE);
        if (tenantName == null) {
            presentation = getAllTenants(type);
        } else if (state == null) {
            presentation = getTenant(tenantName, type);
        } else {
            if (isValidState(state)) {
                presentation = toggleTenantState(tenantName, state, type);
            } else {
                LOGGER.error(INVALID_STATE_ERROR);
                setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                return new StringRepresentation(INVALID_STATE_ERROR);
            }
        }
    } catch (final Exception e) {
        presentation = exceptionToStringRepresentation(e);
        ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_TENANT_GET_ERROR, 1L);
        setStatus(Status.SERVER_ERROR_INTERNAL);
        LOGGER.error("Caught exception while fetching tenant ", e);
        setStatus(Status.SERVER_ERROR_INTERNAL);
    }
    return presentation;
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) JSONException(org.json.JSONException) Get(org.restlet.resource.Get)

Example 4 with Get

use of org.restlet.resource.Get in project OpenAM by OpenRock.

the class EndSession method endSession.

/**
     * Handles GET requests to the OpenId Connect end session endpoint for ending OpenId Connect user sessions.
     *
     * @return The OpenId Connect token of the session that has ended.
     * @throws OAuth2RestletException If an error occurs whilst ending the users session.
     */
@Get
public Representation endSession() throws OAuth2RestletException {
    final OAuth2Request request = requestFactory.create(getRequest());
    final String idToken = request.getParameter(OAuth2Constants.Params.END_SESSION_ID_TOKEN_HINT);
    final String redirectUri = request.getParameter(OAuth2Constants.Params.POST_LOGOUT_REDIRECT_URI);
    try {
        openIDConnectEndSession.endSession(idToken);
        if (StringUtils.isNotEmpty(redirectUri)) {
            return handleRedirect(request, idToken, redirectUri);
        }
    } catch (OAuth2Exception e) {
        throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), null);
    }
    return null;
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) OAuth2RestletException(org.forgerock.oauth2.restlet.OAuth2RestletException) OAuth2Exception(org.forgerock.oauth2.core.exceptions.OAuth2Exception) Get(org.restlet.resource.Get)

Example 5 with Get

use of org.restlet.resource.Get in project pinot by linkedin.

the class SwaggerResource method get.

@Get
@Override
public Representation get() {
    try {
        // Info
        JSONObject info = new JSONObject();
        info.put("title", "Pinot Controller");
        info.put("version", "0.1");
        // Paths
        JSONObject paths = new JSONObject();
        Router router = PinotRestletApplication.getRouter();
        RouteList routeList = router.getRoutes();
        for (Route route : routeList) {
            if (route instanceof TemplateRoute) {
                TemplateRoute templateRoute = (TemplateRoute) route;
                JSONObject pathObject = new JSONObject();
                String routePath = templateRoute.getTemplate().getPattern();
                // Check which methods are present
                Restlet routeTarget = templateRoute.getNext();
                if (routeTarget instanceof Finder) {
                    Finder finder = (Finder) routeTarget;
                    generateSwaggerForFinder(pathObject, routePath, finder);
                } else if (routeTarget instanceof Filter) {
                    do {
                        Filter filter = (Filter) routeTarget;
                        routeTarget = filter.getNext();
                    } while (routeTarget instanceof Filter);
                    if (routeTarget instanceof Finder) {
                        Finder finder = (Finder) routeTarget;
                        generateSwaggerForFinder(pathObject, routePath, finder);
                    }
                }
                if (pathObject.keys().hasNext()) {
                    paths.put(routePath, pathObject);
                }
            }
        }
        // Tags
        JSONArray tags = new JSONArray();
        addTag(tags, "tenant", "Tenant-related operations");
        addTag(tags, "instance", "Instance-related operations");
        addTag(tags, "table", "Table-related operations");
        addTag(tags, "segment", "Segment-related operations");
        addTag(tags, "schema", "Schema-related operations");
        addTag(tags, "version", "Version-related operations");
        // Swagger
        JSONObject swagger = new JSONObject();
        swagger.put("swagger", "2.0");
        swagger.put("info", info);
        swagger.put("paths", paths);
        swagger.put("tags", tags);
        StringRepresentation representation = new StringRepresentation(swagger.toString());
        // Set up CORS
        Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers");
        if (responseHeaders == null) {
            responseHeaders = new Series(Header.class);
            getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
        }
        responseHeaders.add(new Header("Access-Control-Allow-Origin", "*"));
        return representation;
    } catch (JSONException e) {
        return new StringRepresentation(e.toString());
    }
}
Also used : Restlet(org.restlet.Restlet) TemplateRoute(org.restlet.routing.TemplateRoute) Finder(org.restlet.resource.Finder) JSONArray(org.json.JSONArray) Router(org.restlet.routing.Router) JSONException(org.json.JSONException) RouteList(org.restlet.util.RouteList) Series(org.restlet.util.Series) JSONObject(org.json.JSONObject) Header(org.restlet.engine.header.Header) Filter(org.restlet.routing.Filter) StringRepresentation(org.restlet.representation.StringRepresentation) Route(org.restlet.routing.Route) TemplateRoute(org.restlet.routing.TemplateRoute) Get(org.restlet.resource.Get)

Aggregations

Get (org.restlet.resource.Get)14 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)6 OAuth2Exception (org.forgerock.oauth2.core.exceptions.OAuth2Exception)6 StringRepresentation (org.restlet.representation.StringRepresentation)5 JsonValue (org.forgerock.json.JsonValue)4 OAuth2RestletException (org.forgerock.oauth2.restlet.OAuth2RestletException)4 JSONException (org.json.JSONException)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)2 TableType (com.linkedin.pinot.common.utils.CommonConstants.Helix.TableType)1 IOException (java.io.IOException)1 URI (java.net.URI)1 JsonParseException (org.codehaus.jackson.JsonParseException)1 JsonProcessingException (org.codehaus.jackson.JsonProcessingException)1 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)1 AuthorizationToken (org.forgerock.oauth2.core.AuthorizationToken)1 InvalidClientException (org.forgerock.oauth2.core.exceptions.InvalidClientException)1 RedirectUriMismatchException (org.forgerock.oauth2.core.exceptions.RedirectUriMismatchException)1 ResourceOwnerAuthenticationRequired (org.forgerock.oauth2.core.exceptions.ResourceOwnerAuthenticationRequired)1 ResourceOwnerConsentRequired (org.forgerock.oauth2.core.exceptions.ResourceOwnerConsentRequired)1