Search in sources :

Example 21 with StringRepresentation

use of org.restlet.representation.StringRepresentation in project pinot by linkedin.

the class PinotTenantRestletResource method delete.

@Override
@Delete
public Representation delete() {
    StringRepresentation presentation;
    try {
        final String tenantName = (String) getRequest().getAttributes().get(TENANT_NAME);
        final String type = getReference().getQueryAsForm().getValues("type");
        presentation = deleteTenant(tenantName, type);
    } catch (final Exception e) {
        presentation = exceptionToStringRepresentation(e);
        LOGGER.error("Caught exception while deleting tenant ", e);
        ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_TENANT_DELETE_ERROR, 1L);
        setStatus(Status.SERVER_ERROR_INTERNAL);
    }
    return presentation;
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) JSONException(org.json.JSONException) Delete(org.restlet.resource.Delete)

Example 22 with StringRepresentation

use of org.restlet.representation.StringRepresentation in project helix by apache.

the class WorkflowsResource method get.

@Override
public Representation get() {
    StringRepresentation presentation = null;
    try {
        String clusterName = (String) getRequest().getAttributes().get("clusterName");
        presentation = getHostedEntitiesRepresentation(clusterName);
    } catch (Exception e) {
        String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
        presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);
        LOG.error("", e);
    }
    return presentation;
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) HelixException(org.apache.helix.HelixException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException)

Example 23 with StringRepresentation

use of org.restlet.representation.StringRepresentation in project helix by apache.

the class ZkPathResource method get.

@Override
public Representation get() {
    StringRepresentation presentation = null;
    String zkPath = getZKPath();
    try {
        ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
        ZNRecord result = readZkDataStatAndChild(zkPath, zkClient);
        presentation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(result), MediaType.APPLICATION_JSON);
    } catch (Exception e) {
        String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
        presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);
        LOG.error("Error in read zkPath: " + zkPath, e);
    }
    return presentation;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) StringRepresentation(org.restlet.representation.StringRepresentation) ZNRecord(org.apache.helix.ZNRecord) HelixException(org.apache.helix.HelixException)

Example 24 with StringRepresentation

use of org.restlet.representation.StringRepresentation in project helix by apache.

the class ClusterResource method get.

/**
 * List cluster information
 * <p>
 * Usage: <code> curl http://{host:port}/clusters/{clusterName}
 */
@Override
public Representation get() {
    StringRepresentation presentation = null;
    try {
        String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME);
        presentation = getClusterRepresentation(clusterName);
    } catch (Exception e) {
        String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
        presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);
        LOG.error("Exception in get cluster", e);
    }
    return presentation;
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) HelixException(org.apache.helix.HelixException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException)

Example 25 with StringRepresentation

use of org.restlet.representation.StringRepresentation in project helix by apache.

the class ClustersResource method getClustersRepresentation.

StringRepresentation getClustersRepresentation() throws JsonGenerationException, JsonMappingException, IOException {
    ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
    ClusterSetup setupTool = new ClusterSetup(zkClient);
    List<String> clusters = setupTool.getClusterManagementTool().getClusters();
    ZNRecord clustersRecord = new ZNRecord("Clusters Summary");
    clustersRecord.setListField("clusters", clusters);
    StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(clustersRecord), MediaType.APPLICATION_JSON);
    return representation;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) StringRepresentation(org.restlet.representation.StringRepresentation) ClusterSetup(org.apache.helix.tools.ClusterSetup) ZNRecord(org.apache.helix.ZNRecord)

Aggregations

StringRepresentation (org.restlet.representation.StringRepresentation)130 HttpVerb (com.linkedin.pinot.common.restlet.swagger.HttpVerb)30 Paths (com.linkedin.pinot.common.restlet.swagger.Paths)30 Summary (com.linkedin.pinot.common.restlet.swagger.Summary)30 IOException (java.io.IOException)30 Tags (com.linkedin.pinot.common.restlet.swagger.Tags)29 ZkClient (org.apache.helix.manager.zk.ZkClient)29 JSONObject (org.json.JSONObject)23 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)19 ZNRecord (org.apache.helix.ZNRecord)17 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)17 JSONException (org.json.JSONException)17 Representation (org.restlet.representation.Representation)15 Responses (com.linkedin.pinot.common.restlet.swagger.Responses)14 HelixException (org.apache.helix.HelixException)12 JSONArray (org.json.JSONArray)12 Builder (org.apache.helix.PropertyKey.Builder)11 Get (org.restlet.resource.Get)10 Post (org.restlet.resource.Post)9 ResourceException (org.restlet.resource.ResourceException)9