use of org.restlet.representation.StringRepresentation 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.representation.StringRepresentation in project pinot by linkedin.
the class PinotTenantRestletResource method post.
/*
* For tenant creation
*/
@Override
@Post("json")
public Representation post(Representation entity) {
StringRepresentation presentation;
try {
final Tenant tenant = _objectMapper.readValue(entity.getText(), Tenant.class);
presentation = createTenant(tenant);
} catch (final Exception e) {
presentation = exceptionToStringRepresentation(e);
LOGGER.error("Caught exception while creating tenant ", e);
ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_TENANT_CREATE_ERROR, 1L);
setStatus(Status.SERVER_ERROR_INTERNAL);
}
return presentation;
}
use of org.restlet.representation.StringRepresentation 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.representation.StringRepresentation in project pinot by linkedin.
the class PinotTenantRestletResource method put.
/*
* For tenant update
*/
@Override
@Put("json")
public Representation put(Representation entity) {
StringRepresentation presentation;
try {
final Tenant tenant = _objectMapper.readValue(ByteStreams.toByteArray(entity.getStream()), Tenant.class);
presentation = updateTenant(tenant);
} catch (final Exception e) {
presentation = exceptionToStringRepresentation(e);
LOGGER.error("Caught exception while updating tenant ", e);
ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_TENANT_UPDATE_ERROR, 1L);
setStatus(Status.SERVER_ERROR_INTERNAL);
}
return presentation;
}
use of org.restlet.representation.StringRepresentation in project pinot by linkedin.
the class PinotTenantRestletResource method toggleTenantState.
@HttpVerb("get")
@Summary("Enable, disable or drop a tenant")
@Tags({ "tenant" })
@Paths({ "/tenants/{tenantName}", "/tenants/{tenantName}/" })
private StringRepresentation toggleTenantState(@Parameter(name = "tenantName", in = "path", description = "The tenant name") String tenantName, @Parameter(name = "state", in = "query", description = "state to set for the tenant {enable|disable|drop}") String state, @Parameter(name = "type", in = "query", description = "The type of tenant, either SERVER or BROKER or NULL") String type) throws JSONException {
Set<String> serverInstances = new HashSet<String>();
Set<String> brokerInstances = new HashSet<String>();
JSONObject instanceResult = new JSONObject();
if ((type == null) || type.equalsIgnoreCase("server")) {
serverInstances = _pinotHelixResourceManager.getAllInstancesForServerTenant(tenantName);
}
if ((type == null) || type.equalsIgnoreCase("broker")) {
brokerInstances = _pinotHelixResourceManager.getAllInstancesForBrokerTenant(tenantName);
}
Set<String> allInstances = new HashSet<String>(serverInstances);
allInstances.addAll(brokerInstances);
if (StateType.DROP.name().equalsIgnoreCase(state)) {
if (!allInstances.isEmpty()) {
setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("Error: Tenant " + tenantName + " has live instances, cannot be dropped.");
}
_pinotHelixResourceManager.deleteBrokerTenantFor(tenantName);
_pinotHelixResourceManager.deleteOfflineServerTenantFor(tenantName);
_pinotHelixResourceManager.deleteRealtimeServerTenantFor(tenantName);
return new StringRepresentation("Dropped tenant " + tenantName + " successfully.");
}
boolean enable = StateType.ENABLE.name().equalsIgnoreCase(state) ? true : false;
for (String instance : allInstances) {
if (enable) {
instanceResult.put(instance, _pinotHelixResourceManager.enableInstance(instance));
} else {
instanceResult.put(instance, _pinotHelixResourceManager.disableInstance(instance));
}
}
return new StringRepresentation(instanceResult.toString(), MediaType.APPLICATION_JSON);
}
Aggregations