Skip to content

Commit

Permalink
issue #161 - adding server code
Browse files Browse the repository at this point in the history
  • Loading branch information
oshai committed May 10, 2015
1 parent a6cae33 commit d0b67eb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/common/codeine/model/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class Constants

public static final String PROJECT_NODES_CONTEXT = "/project-nodes";
public static final String PROJECT_NODES_ALIASES_CONTEXT = "/project-nodes-aliases";
public static final String PROJECT_NODES_CSV_CONTEXT = "/csv-nodes";
public static final String PROJECT_STATUS_CONTEXT = "/project-status";
public static final String NODE_STATUS_CONTEXT = "/node-status";
public static final String MONITOR_STATUS_CONTEXT = "/monitor-status";
Expand Down
2 changes: 2 additions & 0 deletions src/web_server/codeine/ServerServletModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import codeine.servlets.api_servlets.CommandHistoryApiServlet;
import codeine.servlets.api_servlets.MonitorsStatisticsApiServlet;
import codeine.servlets.api_servlets.NodesCommandApiServlet;
import codeine.servlets.api_servlets.NodesCsvApiServlet;
import codeine.servlets.api_servlets.PrepareForShutdownApiServlet;
import codeine.servlets.api_servlets.ProjectStatusApiServlet;
import codeine.servlets.api_servlets.ProjectTagsApiServlet;
Expand Down Expand Up @@ -59,6 +60,7 @@ protected void configureServlets()
serveApi(ProjectTagsApiServlet.class, (Constants.PROJECT_TAGS_CONTEXT));
serveApi(ProjectsListApiServlet.class, (Constants.PROJECTS_LIST_CONTEXT));
serveApi(NodesCommandApiServlet.class, (Constants.COMMAND_NODES_CONTEXT));
serveApi(NodesCsvApiServlet.class, (Constants.PROJECT_NODES_CSV_CONTEXT));
serveApi(CodeineConfigurationApiServlet.class, (Constants.GLOBAL_CONFIGURATION_CONTEXT));
serveApi(UpdateDbApiServlet.class, (Constants.PUSH_PROJECTS_TO_DB_CONTEXT));
serveApi(CodeineExperimentalConfigurationApiServlet.class, (Constants.EXPERIMENTAL_CONFIGURATION_CONTEXT));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package codeine.servlets.api_servlets;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import codeine.api.NodeGetter;
import codeine.api.NodeWithMonitorsInfo;
import codeine.model.Constants;
import codeine.servlet.AbstractApiServlet;

import com.google.inject.Inject;

public class NodesCsvApiServlet extends AbstractApiServlet {
private static final Logger log = Logger.getLogger(NodesCsvApiServlet.class);
private static final long serialVersionUID = 1L;

@Inject private NodeGetter nodeGetter;

@Override
protected boolean checkPermissions(HttpServletRequest request) {
return canReadProject(request);
}

@Override
protected void myGet(HttpServletRequest request, HttpServletResponse response) {
log.info("myGet");
String project = getProjectName(request);
List<NodeWithMonitorsInfo> nodes = nodeGetter.getNodes(project);
response.setContentType("text/csv");
PrintWriter writer = getWriter(response);
writer.println("name,alias");
for (NodeWithMonitorsInfo n : nodes) {
writer.println(n.name() + "," + n.alias());
}
}

private String getProjectName(HttpServletRequest request) {
String projectName = getParameter(request, Constants.UrlParameters.PROJECT_NAME);
return projectName;
}


}

0 comments on commit d0b67eb

Please sign in to comment.