com.splout.db.qnode.rest.AdminServlet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of splout-server Show documentation
Show all versions of splout-server Show documentation
Splout SQL is a read only, horizontally scalable and
partitioned SQL database that plays well with Hadoop.
package com.splout.db.qnode.rest;
/*
* #%L
* Splout SQL Server
* %%
* Copyright (C) 2012 Datasalt Systems S.L.
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
* #L%
*/
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.splout.db.common.JSONSerDe;
import com.splout.db.qnode.IQNodeHandler;
@SuppressWarnings("serial")
public class AdminServlet extends BaseServlet {
public final static String ACTION_DNODE_STATUS = "dnodestatus";
public final static String ACTION_ALL_TABLESPACE_VERSIONS = "alltablespaceversions";
public final static String ACTION_TABLESPACE_INFO = "tablespaceinfo";
public final static String ACTION_TABLESPACES = "tablespaces";
public final static String ACTION_DNODE_LIST = "dnodelist";
public final static String ACTION_OVERVIEW = "overview";
public AdminServlet(IQNodeHandler qNodeHandler) {
super(qNodeHandler);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
String action = req.getParameter("action");
String response = null;
try {
if(action.equals(ACTION_DNODE_STATUS)) {
String dnode = req.getParameter("dnode");
response = JSONSerDe.ser(qNodeHandler.dnodeStatus(dnode));
} else if(action.equals(ACTION_ALL_TABLESPACE_VERSIONS)) {
String tablespace = req.getParameter("tablespace");
response = JSONSerDe.ser(qNodeHandler.allTablespaceVersions(tablespace));
} else if(action.equals(ACTION_TABLESPACE_INFO)) {
String tablespace = req.getParameter("tablespace");
response = JSONSerDe.ser(qNodeHandler.tablespace(tablespace));
} else if(action.equals(ACTION_TABLESPACES)) {
response = JSONSerDe.ser(qNodeHandler.tablespaces());
} else if(action.equals(ACTION_DNODE_LIST)) {
response = JSONSerDe.ser(qNodeHandler.getDNodeList());
} else if(action.equals(ACTION_OVERVIEW)) {
response = JSONSerDe.ser(qNodeHandler.overview());
} else {
throw new ServletException("Unknown action: " + action);
}
resp.getWriter().append(response);
} catch(Exception e) {
log.error(e);
throw new ServletException(e);
}
}
}