diff --git a/src/common/codeine/model/Constants.java b/src/common/codeine/model/Constants.java index 731e8d2a..19f81557 100755 --- a/src/common/codeine/model/Constants.java +++ b/src/common/codeine/model/Constants.java @@ -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"; diff --git a/src/web_server/codeine/ServerServletModule.java b/src/web_server/codeine/ServerServletModule.java index 5a505552..f0b3ba29 100755 --- a/src/web_server/codeine/ServerServletModule.java +++ b/src/web_server/codeine/ServerServletModule.java @@ -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; @@ -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)); diff --git a/src/web_server/codeine/servlets/api_servlets/NodesCsvApiServlet.java b/src/web_server/codeine/servlets/api_servlets/NodesCsvApiServlet.java new file mode 100644 index 00000000..0dd19939 --- /dev/null +++ b/src/web_server/codeine/servlets/api_servlets/NodesCsvApiServlet.java @@ -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 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; + } + + +}