Search in sources :

Example 51 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project exhibitor by soabase.

the class ClusterResource method makeRemoteRequest.

private String makeRemoteRequest(String methodName, String hostname, boolean responseIsJson, Callable<String> proc, Object... values) throws Exception {
    String remoteResponse;
    String errorMessage;
    if (hostname.equals("localhost") || hostname.equals(context.getExhibitor().getThisJVMHostname())) {
        remoteResponse = proc.call();
        errorMessage = "";
    } else {
        try {
            RemoteInstanceRequest request = new RemoteInstanceRequest(context.getExhibitor(), hostname);
            RemoteInstanceRequest.Result result = request.makeRequest(context.getExhibitor().getRemoteInstanceRequestClient(), methodName, values);
            remoteResponse = result.remoteResponse;
            errorMessage = result.errorMessage;
        } catch (Exception e) {
            remoteResponse = "{}";
            errorMessage = e.getMessage();
            if (errorMessage == null) {
                errorMessage = "Unknown";
            }
        }
    }
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode node = JsonNodeFactory.instance.objectNode();
    if (responseIsJson) {
        node.put("response", mapper.readTree(mapper.getJsonFactory().createJsonParser(remoteResponse)));
    } else {
        node.put("response", remoteResponse);
    }
    node.put("errorMessage", errorMessage);
    node.put("success", errorMessage.length() == 0);
    return JsonUtil.writeValueAsString(node);
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) RemoteInstanceRequest(com.netflix.exhibitor.core.automanage.RemoteInstanceRequest) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 52 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project exhibitor by soabase.

the class ClusterResource method getClusterAsJson.

@Path("list")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getClusterAsJson() throws Exception {
    InstanceConfig config = context.getExhibitor().getConfigManager().getConfig();
    ObjectNode node = JsonNodeFactory.instance.objectNode();
    ArrayNode serversNode = JsonNodeFactory.instance.arrayNode();
    ServerList serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
    for (ServerSpec spec : serverList.getSpecs()) {
        serversNode.add(spec.getHostname());
    }
    node.put("servers", serversNode);
    node.put("port", config.getInt(IntConfigs.CLIENT_PORT));
    return JsonUtil.writeValueAsString(node);
}
Also used : ServerSpec(com.netflix.exhibitor.core.state.ServerSpec) InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) ObjectNode(org.codehaus.jackson.node.ObjectNode) ServerList(com.netflix.exhibitor.core.state.ServerList) ArrayNode(org.codehaus.jackson.node.ArrayNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 53 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project modules.playframework.org by playframework.

the class FeaturedModules method delete.

public static Result delete() {
    Map<String, String[]> postParams = request().body().asFormUrlEncoded();
    String[] ids = postParams.get("id");
    Result result;
    if (ids.length != 1) {
        result = badRequest("A featured module must be defined");
    } else {
        FeaturedModule featuredModule = FeaturedModule.FIND.byId(Long.parseLong(ids[0]));
        featuredModule.delete();
        ObjectNode node = Json.newObject();
        node.put("id", featuredModule.id);
        result = ok(node);
    }
    return result;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) FeaturedModule(models.FeaturedModule) Result(play.mvc.Result)

Example 54 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project pinot by linkedin.

the class IngraphMetricConfigResource method viewMetricConfig.

@GET
@Path("/list")
@Produces(MediaType.APPLICATION_JSON)
public String viewMetricConfig(@NotNull @QueryParam("dashboardName") String dashboardName, @DefaultValue("0") @QueryParam("jtStartIndex") int jtStartIndex, @DefaultValue("100") @QueryParam("jtPageSize") int jtPageSize) {
    List<IngraphMetricConfigDTO> ingraphMetricConfigDTOs = ingraphMetricConfigDao.findByDashboard(dashboardName);
    List<IngraphMetricConfigDTO> subList = Utils.sublist(ingraphMetricConfigDTOs, jtStartIndex, jtPageSize);
    ObjectNode rootNode = JsonResponseUtil.buildResponseJSON(subList);
    return rootNode.toString();
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) IngraphMetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.IngraphMetricConfigDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 55 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project pinot by linkedin.

the class MetricConfigResource method viewMetricConfig.

@GET
@Path("/list")
@Produces(MediaType.APPLICATION_JSON)
public String viewMetricConfig(@NotNull @QueryParam("dataset") String dataset, @DefaultValue("0") @QueryParam("jtStartIndex") int jtStartIndex, @DefaultValue("100") @QueryParam("jtPageSize") int jtPageSize) {
    Map<String, Object> filters = new HashMap<>();
    filters.put("dataset", dataset);
    List<MetricConfigDTO> metricConfigDTOs = metricConfigDao.findByParams(filters);
    List<MetricConfigDTO> subList = Utils.sublist(metricConfigDTOs, jtStartIndex, jtPageSize);
    ObjectNode rootNode = JsonResponseUtil.buildResponseJSON(subList);
    return rootNode.toString();
}
Also used : MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) ObjectNode(org.codehaus.jackson.node.ObjectNode) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ObjectNode (org.codehaus.jackson.node.ObjectNode)97 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)29 ArrayNode (org.codehaus.jackson.node.ArrayNode)29 JsonNode (org.codehaus.jackson.JsonNode)22 GET (javax.ws.rs.GET)21 Path (javax.ws.rs.Path)18 Test (org.junit.Test)16 Produces (javax.ws.rs.Produces)12 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 IOException (java.io.IOException)8 StringWriter (java.io.StringWriter)5 JsonFactory (org.codehaus.jackson.JsonFactory)5 HelixDataAccessor (org.apache.helix.HelixDataAccessor)4 Span (org.apache.stanbol.enhancer.nlp.model.Span)4 DatasetImpl (org.eol.globi.service.DatasetImpl)4 Date (java.util.Date)3 TaskDriver (org.apache.helix.task.TaskDriver)3 WorkflowConfig (org.apache.helix.task.WorkflowConfig)3