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