Search in sources :

Example 41 with StringRepresentation

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

the class CurrentStatesResource method getInstanceCurrentStatesRepresentation.

StringRepresentation getInstanceCurrentStatesRepresentation(String clusterName, String instanceName) throws JsonGenerationException, JsonMappingException, IOException {
    ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
    ;
    String instanceSessionId = ClusterRepresentationUtil.getInstanceSessionId(zkClient, clusterName, instanceName);
    String message = ClusterRepresentationUtil.getInstancePropertyNameListAsString(zkClient, clusterName, instanceName, PropertyType.CURRENTSTATES, instanceSessionId, MediaType.APPLICATION_JSON);
    StringRepresentation representation = new StringRepresentation(message, MediaType.APPLICATION_JSON);
    return representation;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) StringRepresentation(org.restlet.representation.StringRepresentation)

Example 42 with StringRepresentation

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

the class ErrorsResource method getInstanceErrorsRepresentation.

StringRepresentation getInstanceErrorsRepresentation(String clusterName, String instanceName) throws JsonGenerationException, JsonMappingException, IOException {
    ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
    ;
    String instanceSessionId = ClusterRepresentationUtil.getInstanceSessionId(zkClient, clusterName, instanceName);
    String message = ClusterRepresentationUtil.getInstancePropertyNameListAsString(zkClient, clusterName, instanceName, PropertyType.CURRENTSTATES, instanceSessionId, MediaType.APPLICATION_JSON);
    StringRepresentation representation = new StringRepresentation(message, MediaType.APPLICATION_JSON);
    return representation;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) StringRepresentation(org.restlet.representation.StringRepresentation)

Example 43 with StringRepresentation

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

the class ExternalViewResource method get.

@Override
public Representation get() {
    StringRepresentation presentation = null;
    try {
        String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME);
        String resourceName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.RESOURCE_NAME);
        presentation = getExternalViewRepresentation(clusterName, resourceName);
    } catch (Exception e) {
        String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
        presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);
        LOG.error("Exception in get externalView", e);
    }
    return presentation;
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException)

Example 44 with StringRepresentation

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

the class ExternalViewResource method getExternalViewRepresentation.

StringRepresentation getExternalViewRepresentation(String clusterName, String resourceName) throws JsonGenerationException, JsonMappingException, IOException {
    Builder keyBuilder = new PropertyKey.Builder(clusterName);
    ZkClient zkclient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.RAW_ZKCLIENT);
    String extViewStr = ResourceUtil.readZkAsBytes(zkclient, keyBuilder.externalView(resourceName));
    StringRepresentation representation = new StringRepresentation(extViewStr, MediaType.APPLICATION_JSON);
    return representation;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) StringRepresentation(org.restlet.representation.StringRepresentation) Builder(org.apache.helix.PropertyKey.Builder)

Example 45 with StringRepresentation

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

the class IdealStateResource method get.

/**
 * Get ideal state
 * <p>
 * Usage:
 * <code>curl http://{host:port}/clusters/{clusterName}/resourceGroups/{resourceName}/idealState
 */
@Override
public Representation get() {
    StringRepresentation presentation = null;
    try {
        String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME);
        String resourceName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.RESOURCE_NAME);
        presentation = getIdealStateRepresentation(clusterName, resourceName);
    } catch (Exception e) {
        String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
        presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);
        LOG.error("Exception in get idealState", 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)

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