Search in sources :

Example 1 with Instance

use of com.linkedin.pinot.controller.api.pojos.Instance in project pinot by linkedin.

the class PinotInstanceRestletResource method post.

@Override
@Post("json")
public Representation post(Representation entity) {
    StringRepresentation presentation;
    try {
        final String instanceName = (String) getRequest().getAttributes().get(INSTANCE_NAME);
        if (instanceName == null) {
            // This is a request to create an instance
            try {
                final Instance instance = mapper.readValue(ByteStreams.toByteArray(entity.getStream()), Instance.class);
                presentation = addInstance(instance);
            } catch (final Exception e) {
                presentation = new StringRepresentation(e.getMessage() + "\n" + ExceptionUtils.getStackTrace(e));
                LOGGER.error("Caught exception while processing post request", e);
                ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_INTERNAL_ERROR, 1L);
                setStatus(Status.SERVER_ERROR_INTERNAL);
            }
        } else {
            // This is a request to toggle the state of an instance
            if (_pinotHelixResourceManager.instanceExists(instanceName)) {
                final String state = getRequest().getEntityAsText().trim();
                if (isValidState(state)) {
                    presentation = toggleInstanceState(instanceName, state);
                } else {
                    LOGGER.error(INVALID_STATE_ERROR);
                    setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                    return new StringRepresentation(INVALID_STATE_ERROR);
                }
            } else {
                setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                presentation = new StringRepresentation("Error: Instance " + instanceName + " not found.");
            }
        }
    } catch (final Exception e) {
        presentation = new StringRepresentation(e.getMessage() + "\n" + ExceptionUtils.getStackTrace(e));
        LOGGER.error("Caught exception while processing post request", e);
        ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_INSTANCE_POST_ERROR, 1L);
        setStatus(Status.SERVER_ERROR_INTERNAL);
    }
    return presentation;
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) Instance(com.linkedin.pinot.controller.api.pojos.Instance) JSONException(org.json.JSONException) Post(org.restlet.resource.Post)

Aggregations

Instance (com.linkedin.pinot.controller.api.pojos.Instance)1 JSONException (org.json.JSONException)1 StringRepresentation (org.restlet.representation.StringRepresentation)1 Post (org.restlet.resource.Post)1