first pillar

This commit is contained in:
Peter Hormanns 2019-06-12 14:02:41 +02:00
parent 76f1df397b
commit 1b447b3f85
4 changed files with 120 additions and 10 deletions

View File

@ -37,11 +37,21 @@
</init-param> </init-param>
</servlet> </servlet>
<servlet>
<servlet-name>PillarServlet</servlet-name>
<servlet-class>de.hsadmin.pillar.JsonPillarServlet</servlet-class>
</servlet>
<servlet-mapping> <servlet-mapping>
<servlet-name>Queue Status Servlet</servlet-name> <servlet-name>Queue Status Servlet</servlet-name>
<url-pattern>/queueStatus</url-pattern> <url-pattern>/queueStatus</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet-mapping>
<servlet-name>PillarServlet</servlet-name>
<url-pattern>/pillar</url-pattern>
</servlet-mapping>
<servlet-mapping> <servlet-mapping>
<servlet-name>Queue PacTasks Servlet</servlet-name> <servlet-name>Queue PacTasks Servlet</servlet-name>
<url-pattern>/queuePacTasks</url-pattern> <url-pattern>/queuePacTasks</url-pattern>

View File

@ -39,11 +39,21 @@
</init-param> </init-param>
</servlet> </servlet>
<servlet>
<servlet-name>PillarServlet</servlet-name>
<servlet-class>de.hsadmin.pillar.JsonPillarServlet</servlet-class>
</servlet>
<servlet-mapping> <servlet-mapping>
<servlet-name>Queue Status Servlet</servlet-name> <servlet-name>Queue Status Servlet</servlet-name>
<url-pattern>/queueStatus</url-pattern> <url-pattern>/queueStatus</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet-mapping>
<servlet-name>PillarServlet</servlet-name>
<url-pattern>/pillar</url-pattern>
</servlet-mapping>
<!-- <!--
<servlet-mapping> <servlet-mapping>
<servlet-name>Queue PacTasks Servlet</servlet-name> <servlet-name>Queue PacTasks Servlet</servlet-name>

View File

@ -37,11 +37,21 @@
</init-param> </init-param>
</servlet> </servlet>
<servlet>
<servlet-name>PillarServlet</servlet-name>
<servlet-class>de.hsadmin.pillar.JsonPillarServlet</servlet-class>
</servlet>
<servlet-mapping> <servlet-mapping>
<servlet-name>Queue Status Servlet</servlet-name> <servlet-name>Queue Status Servlet</servlet-name>
<url-pattern>/queueStatus</url-pattern> <url-pattern>/queueStatus</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet-mapping>
<servlet-name>PillarServlet</servlet-name>
<url-pattern>/pillar</url-pattern>
</servlet-mapping>
<servlet-mapping> <servlet-mapping>
<servlet-name>XmlRpcServlet</servlet-name> <servlet-name>XmlRpcServlet</servlet-name>
<url-pattern>/xmlrpc/*</url-pattern> <url-pattern>/xmlrpc/*</url-pattern>
@ -96,14 +106,4 @@
<res-sharing-scope>Shareable</res-sharing-scope> <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref> </resource-ref>
<security-constraint>
<web-resource-collection>
<web-resource-name>Hostsharing Administrative Area</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
</web-app> </web-app>

View File

@ -0,0 +1,90 @@
package de.hsadmin.pillar;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.core.qserv.ProcessorException;
import de.hsadmin.mods.pac.Hive;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.pac.PacComponent;
public class JsonPillarServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final Transaction transaction = new Transaction("pilalr");
final EntityManager em = transaction.getEntityManager();
final String hiveFqdn = req.getParameter("hive");
String hiveName = "";
if (hiveFqdn != null && hiveFqdn.length() == 19 && hiveFqdn.endsWith(".hostsharing.net") && hiveFqdn.startsWith("h")) {
hiveName = hiveFqdn.substring(0, 3);
} else {
throw new ServletException("error in hive parameter");
}
final Query hiveQuery = em.createQuery("SELECT h FROM Hives h WHERE h.name = :hive");
hiveQuery.setParameter("hive", hiveName);
final Object hiveResult = hiveQuery.getSingleResult();
final Hive hive = (Hive) hiveResult;
final Query pacsQuery = em.createQuery("SELECT p FROM Pacs p WHERE p.hive.name = :hive AND p.basepac.name = 'PAC/WEB'");
pacsQuery.setParameter("hive", hiveName);
final List<?> pacsResult = pacsQuery.getResultList();
resp.setContentType("text/plain");
final PrintWriter writer = resp.getWriter();
writer.println("{");
writer.println(" \"hivename\": \"" + hive.getHiveName() + "\"");
writer.println(" \"hiveipv4\": \"" + hive.getInetAddr().getInet4Addr() + "\"");
try {
writer.println(" \"hiveipv6\": \"" + hive.getInetAddr().getInet6Addr() + "\"");
} catch (ProcessorException e) {
// dont care
}
writer.println(" \"pacs\": [");
final Iterator<?> pacsIterator = pacsResult.iterator();
boolean firstLoop = true;
while (pacsIterator.hasNext()) {
final Object result = pacsIterator.next();
final Pac pac = (Pac) result;
if (firstLoop) {
firstLoop = false;
writer.println(" {");
} else {
writer.println(" , {");
}
writer.println(" \"pac\": \"" + pac.getName() + "\"");
writer.println(" , \"ipv4\": \"" + pac.getCurINetAddr().getInet4Addr() + "\"");
try {
writer.println(" , \"ipv6\": \"" + pac.getCurINetAddr().getInet6Addr() + "\"");
} catch (ProcessorException e) {
// dont care
}
final PacComponent pacQuota = pac.getPacComponent("QUOTA");
if (pacQuota != null) {
int quota = pacQuota.getQuantity();
writer.println(" , \"quota\": \"" + quota + "\"");
}
final PacComponent pacOffice = pac.getPacComponent("OFFICE");
if (pacOffice != null) {
int office = pacOffice.getQuantity();
writer.println(" , \"office\": \"" + office + "\"");
}
writer.println(" }");
}
writer.println(" ]");
writer.println("}");
writer.close();
em.close();
}
}