Package org.restlet.representation

Examples of org.restlet.representation.StringRepresentation


    List<String> models = setupTool.getClusterManagementTool().getStateModelDefs(clusterName);

    ZNRecord modelDefinitions = new ZNRecord("modelDefinitions");
    modelDefinitions.setListField("models", models);

    StringRepresentation representation =
        new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(modelDefinitions),
            MediaType.APPLICATION_JSON);

    return representation;
  }
View Full Code Here


    setNegotiated(false);
  }

  @Override
  public Representation get() {
    StringRepresentation presentation = null;
    try {
      presentation = getInstanceRepresentation();
    } catch (Exception e) {
      String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
      presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);

      LOG.error("", e);
    }
    return presentation;
  }
View Full Code Here

    String message =
        ClusterRepresentationUtil.getClusterPropertyAsString(zkClient, clusterName,
            MediaType.APPLICATION_JSON, keyBuilder.instanceConfig(instanceName));

    StringRepresentation representation =
        new StringRepresentation(message, MediaType.APPLICATION_JSON);

    return representation;
  }
View Full Code Here

    return (String) getRequest().getAttributes().get(key);
  }

  @Override
  public Representation get() {
    StringRepresentation representation = null;
    String clusterName = getValue("clusterName");
    String constraintTypeStr = getValue("constraintType").toUpperCase();
    String constraintId = getValue("constraintId");

    try {
      ConstraintType constraintType = ConstraintType.valueOf(constraintTypeStr);
      ZkClient zkClient =
          (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
      // ClusterSetup setupTool = new ClusterSetup(zkClient);
      HelixAdmin admin = new ZKHelixAdmin(zkClient); // setupTool.getClusterManagementTool();

      ZNRecord record = admin.getConstraints(clusterName, constraintType).getRecord();
      if (constraintId == null) {
        // get all message constraints
        representation =
            new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record),
                MediaType.APPLICATION_JSON);
      } else {
        // get a specific constraint
        Map<String, String> constraint = record.getMapField(constraintId);
        if (constraint == null) {
          representation =
              new StringRepresentation("No constraint of type: " + constraintType
                  + " associated with id: " + constraintId, MediaType.APPLICATION_JSON);
        } else {
          ZNRecord subRecord = new ZNRecord(record.getId());
          subRecord.setMapField(constraintId, constraint);
          representation =
              new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(subRecord),
                  MediaType.APPLICATION_JSON);
        }
      }
    } catch (IllegalArgumentException e) {
      representation =
          new StringRepresentation("constraint-type: " + constraintTypeStr + " not recognized.",
              MediaType.APPLICATION_JSON);
    } catch (Exception e) {
      String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
      representation = new StringRepresentation(error, MediaType.APPLICATION_JSON);
      LOG.error("", e);
    }

    return representation;
  }
View Full Code Here

    setNegotiated(false);
  }

  @Override
  public Representation get() {
    StringRepresentation presentation = null;
    try {
      presentation = getSchedulerTasksRepresentation();
    }

    catch (Exception e) {
      String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
      presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);

      LOG.error("", e);
    }
    return presentation;
  }
View Full Code Here

        ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
    LiveInstance liveInstance =
        accessor.getProperty(accessor.keyBuilder().liveInstance(instanceName));
    String sessionId = liveInstance.getSessionId();

    StringRepresentation representation = new StringRepresentation("");// (ClusterRepresentationUtil.ObjectToJson(instanceConfigs),
                                                                       // MediaType.APPLICATION_JSON);

    return representation;
  }
View Full Code Here

    boolean paused = (accessor.getProperty(keyBuilder.pause()) == null ? false : true);
    record.setSimpleField(PropertyType.PAUSE.toString(), "" + paused);

    String retVal = ClusterRepresentationUtil.ZNRecordToJson(record);
    StringRepresentation representation =
        new StringRepresentation(retVal, MediaType.APPLICATION_JSON);

    return representation;
  }
View Full Code Here

    return representation;
  }

  @Override
  public Representation get() {
    StringRepresentation presentation = null;
    try {
      String clusterName = (String) getRequest().getAttributes().get("clusterName");
      presentation = getControllerRepresentation(clusterName);
    } catch (Exception e) {
      String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
      presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);
      e.printStackTrace();
    }
    return presentation;
  }
View Full Code Here

    setNegotiated(false);
  }

  @Override
  public Representation get() {
    StringRepresentation presentation = null;
    try {
      String clusterName = (String) getRequest().getAttributes().get("clusterName");
      String instanceName = (String) getRequest().getAttributes().get("instanceName");
      presentation = getInstanceErrorsRepresentation(clusterName, instanceName);
    } catch (Exception e) {
      String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
      presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);

      LOG.error("", e);
    }
    return presentation;
  }
View Full Code Here

    String message =
        ClusterRepresentationUtil
            .getInstancePropertyNameListAsString(zkClient, clusterName, instanceName,
                PropertyType.CURRENTSTATES, instanceSessionId, MediaType.APPLICATION_JSON);

    StringRepresentation representation =
        new StringRepresentation(message, MediaType.APPLICATION_JSON);

    return representation;
  }
View Full Code Here

TOP

Related Classes of org.restlet.representation.StringRepresentation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.