예제 #1
0
  @POST
  @Produces(MediaType.APPLICATION_JSON)
  public Response addNode(Node node) {
    Response response = null;
    try {
      org.nikhil.webapp.nodeadmin.entity.Node newNode = getJPANodeFromJSONNode(node);
      nodeOperation.addNode(newNode);
      response =
          NodeAdminUtils.buildStandardRESTHTTPResponse(
              201, "Node " + node.getName() + " Added Successfully", null, null);

    } catch (Exception e) {
      e.printStackTrace();
      response =
          NodeAdminUtils.buildStandardRESTHTTPResponse(500, "Server Error Adding Node", null, null);
    }
    return response;
  }
예제 #2
0
 @GET
 @Produces(MediaType.APPLICATION_JSON)
 @Path("{nodeName}/stop")
 public Response stop(@PathParam("nodeName") String nodeName) {
   Response response = null;
   try {
     nodeOperation.reStartNode(nodeName);
     response =
         NodeAdminUtils.buildStandardRESTHTTPResponse(
             200, "Node " + nodeName + " Stopped Successfully", null, null);
   } catch (Exception e) {
     e.printStackTrace();
     response =
         NodeAdminUtils.buildStandardRESTHTTPResponse(
             500, "Server Error Stopping the Node " + nodeName, null, null);
   }
   return response;
 }
예제 #3
0
 @GET
 @Produces(MediaType.APPLICATION_JSON)
 @Path("{nodeName}/status")
 public Response getStatus(@PathParam("nodeName") String nodeName) {
   Response response = null;
   try {
     org.nikhil.webapp.nodeadmin.entity.Node fetchedNode = nodeOperation.getNode(nodeName);
     String status = nodeOperation.getNodeStatus(nodeName, true);
     Object jsonObj = NodeAdminUtils.createObjectFromRawData("status", status, null);
     response =
         NodeAdminUtils.buildStandardRESTHTTPResponse(
             200, "Node " + nodeName + " Status Retrieved Successfully", status, null);
   } catch (Exception e) {
     e.printStackTrace();
     response =
         NodeAdminUtils.buildStandardRESTHTTPResponse(
             500, "Server Error getting the status of the Node " + nodeName, null, null);
   }
   return response;
 }
예제 #4
0
  @DELETE
  @Produces(MediaType.APPLICATION_JSON)
  @Path("/{nodeName}")
  public Response deleteNode(@PathParam("nodeName") String nodeName) {
    Response response = null;
    try {
      nodeOperation.deleteNode(nodeName);
      response =
          NodeAdminUtils.buildStandardRESTHTTPResponse(
              200, "Node " + nodeName + " Deleted Successfully", null, null);

    } catch (Exception e) {
      e.printStackTrace();
      response =
          NodeAdminUtils.buildStandardRESTHTTPResponse(
              500, "Server Error Deleting Node", null, null);
    }

    return response;
  }
예제 #5
0
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public Response getNodes() {
    Response response = null;

    try {
      List<Node> flattenedNodeList = new ArrayList<>();
      List<org.nikhil.webapp.nodeadmin.entity.Node> list = nodeOperation.listNodes();
      for (org.nikhil.webapp.nodeadmin.entity.Node node : list) {
        flattenedNodeList.add(getNodeJSONFromNodeEntity(node));
      }
      response =
          NodeAdminUtils.buildStandardRESTHTTPResponseForCollection(
              200, "Node List Retrieved Successfully", flattenedNodeList, null);
    } catch (Exception e) {
      e.printStackTrace();
      response =
          NodeAdminUtils.buildStandardRESTHTTPResponse(
              500, "Server Error Retrieving Node List", null, null);
    }
    return response;
  }
예제 #6
0
 @GET
 @Produces(MediaType.APPLICATION_JSON)
 @Path("/{nodeName}")
 public Response getANode(@PathParam("nodeName") String nodeName) {
   Response response = null;
   try {
     org.nikhil.webapp.nodeadmin.entity.Node fetchedNode = nodeOperation.getNode(nodeName);
     if (fetchedNode == null) {
       response = NodeAdminUtils.buildStandardRESTHTTPResponse(404, "No Such Node", null, null);
     } else {
       Node flattenedNode = getNodeJSONFromNodeEntity(fetchedNode);
       response =
           NodeAdminUtils.buildStandardRESTHTTPResponse(
               200, "Node Retrieved Successfully", flattenedNode, null);
     }
   } catch (Exception e) {
     e.printStackTrace();
     response =
         NodeAdminUtils.buildStandardRESTHTTPResponse(
             500, "Server Error Retrieving Node " + nodeName, null, null);
   }
   return response;
 }