use of org.restlet.representation.StringRepresentation in project helix by apache.
the class JobQueuesResource method get.
/**
* List all job queues
* <p>
* Usage: <code>curl http://{host:port}/clusters/{clusterName}/jobQueues
*/
@Override
public Representation get() {
StringRepresentation presentation = null;
try {
String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME);
presentation = getHostedEntitiesRepresentation(clusterName);
} catch (Exception e) {
String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);
LOG.error("Fail to get all job queues", e);
}
return presentation;
}
use of org.restlet.representation.StringRepresentation in project helix by apache.
the class JobResource method getHostedEntitiesRepresentation.
StringRepresentation getHostedEntitiesRepresentation(String clusterName, String jobQueueName, String jobName) throws Exception {
ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
HelixDataAccessor accessor = ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
// Get job queue config
String namespacedJobName = TaskUtil.getNamespacedJobName(jobQueueName, jobName);
HelixProperty jobConfig = accessor.getProperty(keyBuilder.resourceConfig(namespacedJobName));
TaskDriver taskDriver = new TaskDriver(zkClient, clusterName);
// Get job queue context
JobContext ctx = taskDriver.getJobContext(namespacedJobName);
// Create the result
ZNRecord hostedEntitiesRecord = new ZNRecord(namespacedJobName);
if (jobConfig != null) {
hostedEntitiesRecord.merge(jobConfig.getRecord());
}
if (ctx != null) {
hostedEntitiesRecord.merge(ctx.getRecord());
}
StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(hostedEntitiesRecord), MediaType.APPLICATION_JSON);
return representation;
}
use of org.restlet.representation.StringRepresentation in project helix by apache.
the class JobResource method delete.
@Override
public Representation delete() {
StringRepresentation representation = null;
String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME);
String jobQueueName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.JOB_QUEUE);
String jobName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.JOB);
ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
TaskDriver driver = new TaskDriver(zkClient, clusterName);
try {
driver.deleteJob(jobQueueName, jobName);
getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
} catch (Exception e) {
String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
representation = new StringRepresentation(error, MediaType.APPLICATION_JSON);
LOG.error("Fail to delete job: " + jobName, e);
}
return representation;
}
use of org.restlet.representation.StringRepresentation in project helix by apache.
the class SchedulerTasksResource method getSchedulerTasksRepresentation.
StringRepresentation getSchedulerTasksRepresentation() throws JsonGenerationException, JsonMappingException, IOException {
String clusterName = (String) getRequest().getAttributes().get("clusterName");
String instanceName = (String) getRequest().getAttributes().get("instanceName");
ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
ClusterSetup setupTool = new ClusterSetup(zkClient);
List<String> instances = setupTool.getClusterManagementTool().getInstancesInCluster(clusterName);
HelixDataAccessor accessor = ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
LiveInstance liveInstance = accessor.getProperty(accessor.keyBuilder().liveInstance(instanceName));
String sessionId = liveInstance.getSessionId();
// (ClusterRepresentationUtil.ObjectToJson(instanceConfigs),
StringRepresentation representation = new StringRepresentation("");
return representation;
}
use of org.restlet.representation.StringRepresentation in project helix by apache.
the class StateModelResource method getStateModelRepresentation.
StringRepresentation getStateModelRepresentation(String clusterName, String modelName) throws JsonGenerationException, JsonMappingException, IOException {
Builder keyBuilder = new PropertyKey.Builder(clusterName);
ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
String message = ClusterRepresentationUtil.getClusterPropertyAsString(zkClient, clusterName, keyBuilder.stateModelDef(modelName), MediaType.APPLICATION_JSON);
StringRepresentation representation = new StringRepresentation(message, MediaType.APPLICATION_JSON);
return representation;
}
Aggregations