HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2019-06-12 1b447b3f85bab7c66a857e740748156cca70f831
first pillar
1 files added
3 files modified
130 ■■■■■ changed files
hsarback/conf/WEB-INF/dev-web.xml 10 ●●●●● patch | view | raw | blame | history
hsarback/conf/WEB-INF/prod-web.xml 10 ●●●●● patch | view | raw | blame | history
hsarback/conf/WEB-INF/test-web.xml 20 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/pillar/JsonPillarServlet.java 90 ●●●●● patch | view | raw | blame | history
hsarback/conf/WEB-INF/dev-web.xml
@@ -37,12 +37,22 @@
        </init-param>
    </servlet>
    <servlet>
        <servlet-name>PillarServlet</servlet-name>
        <servlet-class>de.hsadmin.pillar.JsonPillarServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Queue Status Servlet</servlet-name>
        <url-pattern>/queueStatus</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>PillarServlet</servlet-name>
        <url-pattern>/pillar</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Queue PacTasks Servlet</servlet-name>
        <url-pattern>/queuePacTasks</url-pattern>
    </servlet-mapping>
hsarback/conf/WEB-INF/prod-web.xml
@@ -39,11 +39,21 @@
        </init-param>
    </servlet>
    <servlet>
        <servlet-name>PillarServlet</servlet-name>
        <servlet-class>de.hsadmin.pillar.JsonPillarServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Queue Status Servlet</servlet-name>
        <url-pattern>/queueStatus</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>PillarServlet</servlet-name>
        <url-pattern>/pillar</url-pattern>
    </servlet-mapping>
    <!--
    <servlet-mapping>
        <servlet-name>Queue PacTasks Servlet</servlet-name>
hsarback/conf/WEB-INF/test-web.xml
@@ -37,9 +37,19 @@
        </init-param>
    </servlet>
    <servlet>
        <servlet-name>PillarServlet</servlet-name>
        <servlet-class>de.hsadmin.pillar.JsonPillarServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Queue Status Servlet</servlet-name>
        <url-pattern>/queueStatus</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>PillarServlet</servlet-name>
        <url-pattern>/pillar</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
@@ -96,14 +106,4 @@
        <res-sharing-scope>Shareable</res-sharing-scope>
    </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>
hsarback/src/de/hsadmin/pillar/JsonPillarServlet.java
New 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();
    }
}