Skip to content

Commit

Permalink
Move billing to webadmin.
Browse files Browse the repository at this point in the history
This patch updates and combines the previous patches:

http://rb.dcache.org/r/4522/
http://rb.dcache.org/r/4523/

A.  Modifies where the billing plots are produced.

See:

http://rt.dcache.org/Ticket/Display.html?id=7149 
http://rb.dcache.org/r/4507/
http://rb.dcache.org/r/4473/

In the current implementation, the HttpBillingEngine, which is responsible for generating histograms, needs access to the same database as the BillingCell, which processes the door and mover messages.  The above tickets and patches provide work-arounds for this departure from the underlying contract for the "database ls" command.  

While it may be desirable in the future to revise this contract and restructure the code to support shared database mappings, it is a relatively simple modification to bring billing in line with the contract.

This patch eliminates the BillingHistory class and moves the plot generation into the BillingDatabase class; this is activated by an option "generatePlots" which by default it false (and which can only be true if billingToDb=yes).  The HttpResponseEngine (the billingHistory alias) is merely responsible for serving the plot images as an html response.

In the future we will want to change this static production system entirely so that the GET request to the billing plots page dynamically requests the histogram plot.  This can be done by message callbacks to the BillingCell, and so the web application will continue to be isolated from the BillingCell's database.

B.  Migration of billing pages to webadmin (Wicket).

http://rb.dcache.org/r/4208/
http://rb.dcache.org/r/4329/

Combines the above-cited patches into a single revised patch.

The previous code was written prior to the integration of the JettyCell with the HttpServiceCell (http://rb.dcache.org/r/4518) and the relocation of the plotting thread from the web layer to the billing service itself.  This patch accomplishes the same goal within the new framework.

The wicket billing plots page now resides inside webadmin; as a consequence, the billingHistory alias and the corresponding HttpBillingHistoryEngine have been eliminated, as well as the static link to that page from the static index page.

Note that the properties billingToDb and generatePlots control WebAdminInterface's mount of, and the BasicNavigatorPanel's link to, the BillingPlot page (this occurs only when their values are yes/true, respectively); hence the contexts for switching between a static page reporting that plots are not enabled and the actual plots page are no longer necessary and have also been eliminated. Note that this page's index in the BasicNavigatorPanel.properties file must remain the last one (N-1), since it is removed from or appended to the list on this basis.  Hence, any future pages (such as the alarms page), should not occupy the last position.

Three of the links on the main static (Cell Services, Pool Usage and Pool Transfer Queues) have been redirected to their webadmin URLs, but one other (aliased as '/billing'), linked to "Action Log" on the main static page and generated by diskCacheV111.cells.HttpBillingEngine, is still available there; it would be desirable eventually to move this to Wicket as well.

Patch was merged on 06/15/2012 with changes introduced by http://rb.dcache.org/r/4518 (rev) and http://rb.dcache.org/r/4581.  trunk@17337

Patch was updated on 06/21/2012:

This updated version adds necessary changes to httpd.batch which an oversight left out of the preceding version.
The exception-handling in the plot classes has been cleaned up.
We have also eliminated URL references to ajax.google by downloading the referenced jquery file and including it in webapps/js.
There are also numerous cosmetic changes to the plot code, such as eliminating useless auto-generated javadoc comments.
The size of the patch is deceptive; most of the extra length comes from the cosmetic changes and the added jquery files.

RELEASE NOTES:

1.  The billingToDb property still needs to be global, but the properties specific to the database can now live in the service scope.
2.  To turn on plotting, the billing service property generatePlots must be set to true (this is its default value).
3.  Since generatePlots now also controls the presence or absence of a web application page, it (like billingToDb) needs to be global (or at least domain-wide if billing runs in the httpd domain).

Target: trunk
Patch: http://rb.dcache.org/r/4572/
Acked-by: Dmitry
  • Loading branch information
alrossi committed Jun 22, 2012
1 parent 9300be2 commit c14d931
Show file tree
Hide file tree
Showing 36 changed files with 8,666 additions and 1,653 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,121 +0,0 @@
package org.dcache.services.billing.html;

import java.util.List;

import org.dcache.services.billing.plots.BillingHistory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import diskCacheV111.util.HTMLWriter;
import dmg.cells.nucleus.CellNucleus;
import dmg.util.Args;
import dmg.util.HttpException;
import dmg.util.HttpRequest;
import dmg.util.HttpResponseEngine;

/**
* Servlet stand-in {@link org.dcache.services.httpd.HttpServiceCell}. <br><br>
* Constructs dynamic html page with table of plots.
*
* @see BillingHistory
* @author arossi
*/
public final class HttpBillingHistoryEngine extends BillingHistory implements
HttpResponseEngine {

private static final Logger _log = LoggerFactory.getLogger(HttpBillingHistoryEngine.class);
private static final String fileSep = System.getProperty("file.separator");

private static final String THUMBNAIL_W = "120";
private static final String THUMBNAIL_H = "60";

private CellNucleus nucleus;
private final Thread _billingHistory;

/**
* @param nucleus
* @param args
*/
public HttpBillingHistoryEngine(CellNucleus nucleus, String[] args) {
super(new Args(args));
this.nucleus = nucleus;
_billingHistory = nucleus.newThread(this, "billing-history");
}

@Override
public void startup()
{
_billingHistory.start();
}


@Override
public void shutdown()
{
setRunning(false);
_billingHistory.interrupt();
try {
_billingHistory.join();
} catch (InterruptedException e) {
_log.warn("Interrupted while waiting for BillingHistory thread to terminate");
}
close();
}

/*
* (non-Javadoc)
*
* @see dmg.util.HttpResponseEngine#queryUrl(dmg.util.HttpRequest)
*/
@Override
public void queryUrl(HttpRequest request) throws HttpException {
request.printHttpHeader(0);
emit(new HTMLWriter(request.getOutputStream(),
this.nucleus.getDomainContext()));
}

/**
* Constructs the html page.
*
* @param contents
*/
public void emit(HTMLWriter contents) {
contents.addHeader("/styles/common.css", "Billing History Plots");
contents.println("<table align='center'>");
contents.println("<tr>");
contents.println("<th>Plot Type</th>");
contents.println("<th>24-Hour</th>");
contents.println("<th>Weekly</th>");
contents.println("<th>Monthly</th>");
contents.println("<th>Yearly</th>");
contents.println("</tr>");
List<String> type = BillingHistory.getTYPE();
for (int t = 0; t < type.size(); t++) {
printRow(contents, BillingHistory.getTITLE(t), type.get(t));
}
contents.println("</table>");
contents.addFooter(this.getClass().getName());
contents.flush();
}

/**
* Generates row in the table containing link to the image file for plot.
*
* @param contents
* @param title
* @param type
*/
private void printRow(HTMLWriter contents, String title, String type) {
contents.println("<tr>");
contents.println("<td align='right'><i>" + title + "</i></td>");
String prefix = subDir + fileSep + type;
for (String tag : BillingHistory.getEXT()) {
String file = prefix + tag + imgExt;
contents.println("<td><a href='" + file + "'> <img src='" + file
+ "' width=" + THUMBNAIL_W + " height="
+ THUMBNAIL_H
+ "> </a></td>");
}
contents.println("</tr>");
}
}
Loading

0 comments on commit c14d931

Please sign in to comment.