public static void auditMlcpFinish(Configuration conf, String jobName, 
            Counters counters) throws IOException {
        boolean success = false;
        if (!conf.getBoolean(ConfigConstants.CONF_AUDIT_MLCPFINISH_ENABLED, false)) {
            return;
        }
        
        StringBuilder auditBuf = new StringBuilder();
        auditBuf.append("job=");
        auditBuf.append(jobName);
        
        if (counters.countCounters() > 0) {
            auditBuf.append(";");
            Iterator<CounterGroup> groupIt = counters.iterator();
            int groupCounter = 0;
            while (groupIt.hasNext()) {
                CounterGroup group = groupIt.next();
                if (groupCounter != 0) {
                    auditBuf.append("; ");
                } else {
                    auditBuf.append(" ");
                }
                
                auditBuf.append('(');
                auditBuf.append(group.getDisplayName());
                auditBuf.append(") ");

                Iterator<Counter> counterIt = group.iterator();
                int counterCount = 0;
                while (counterIt.hasNext()) {
                    if (counterCount != 0) {
                        auditBuf.append(", ");
                    }
                    Counter counter = counterIt.next();                    
                    auditBuf.append(counter.getDisplayName());
                    auditBuf.append('=');
                    auditBuf.append(counter.getValue());
                    counterCount++;
                }
                groupCounter++;
            }
            success = true;
        }
        
        String ruleCounter = conf.get(ConfigConstants.CONF_AUDIT_MLCPFINISH_MESSAGE);
        if (ruleCounter != null) {
            auditBuf.append("; ");
            auditBuf.append(ruleCounter);
        }
        String auditMessage = auditBuf.toString();
        
        auditBuf = new StringBuilder();
        auditBuf.append("xquery version \"1.0-ml\";\n");
        auditBuf.append("declare variable $success as xs:boolean external;\n");
        auditBuf.append("xdmp:audit(\"");
        auditBuf.append(ConfigConstants.AUDIT_MLCPFINISH_CODE);
        auditBuf.append("\",\"");
        auditBuf.append(auditMessage);
        auditBuf.append("\", ");
        auditBuf.append("xdmp:get-current-user(), $success)");
        String auditQueryStr = auditBuf.toString();
        
        Session auditSession = null;
        ContentSource auditCs = null;
        try {
            auditCs = InternalUtilities.getInputContentSource(conf);
            auditSession = auditCs.newSession();
            RequestOptions options = new RequestOptions();
            options.setCacheResult(false);

            AdhocQuery auditQuery = auditSession.newAdhocQuery(auditQueryStr);
            auditQuery.setOptions(options);
            auditQuery.setNewVariable("success", ValueType.XS_BOOLEAN, 
                    new Boolean(success));
            auditSession.submitRequest(auditQuery);
        } catch (XccConfigException e) {
            LOG.error(e);
            throw new IOException(e);
        } catch (URISyntaxException e) {
            LOG.error(e);
            throw new IOException(e);
        } catch (RequestException e) {
            LOG.error(e);
            LOG.error("Query: " + auditQueryStr);
            throw new IOException(e);
        }
    }
public static void auditMlcpFinish ( Configuration conf , String jobName , Counters counters ) throws IOException { boolean success = false ; if ( ! conf . getBoolean ( ConfigConstants . CONF_AUDIT_MLCPFINISH_ENABLED , false ) ) { return ; } StringBuilder auditBuf = new StringBuilder ( ) ; auditBuf . append ( "job=" ) ; auditBuf . append ( jobName ) ; if ( counters . countCounters ( ) > 0 ) { auditBuf . append ( ";" ) ; Iterator < CounterGroup > groupIt = counters . iterator ( ) ; int groupCounter = 0 ; while ( groupIt . hasNext ( ) ) { CounterGroup group = groupIt . next ( ) ; if ( groupCounter != 0 ) { auditBuf . append ( "; " ) ; } else { auditBuf . append ( " " ) ; } auditBuf . append ( '(' ) ; auditBuf . append ( group . getDisplayName ( ) ) ; auditBuf . append ( ") " ) ; Iterator < Counter > counterIt = group . iterator ( ) ; int counterCount = 0 ; while ( counterIt . hasNext ( ) ) { if ( counterCount != 0 ) { auditBuf . append ( ", " ) ; } Counter counter = counterIt . next ( ) ; auditBuf . append ( counter . getDisplayName ( ) ) ; auditBuf . append ( '=' ) ; auditBuf . append ( counter . getValue ( ) ) ; counterCount ++ ; } groupCounter ++ ; } success = true ; } String ruleCounter = conf . get ( ConfigConstants . CONF_AUDIT_MLCPFINISH_MESSAGE ) ; if ( ruleCounter != null ) { auditBuf . append ( "; " ) ; auditBuf . append ( ruleCounter ) ; } String auditMessage = auditBuf . toString ( ) ; auditBuf = new StringBuilder ( ) ; auditBuf . append ( "xquery version \"1.0-ml\";\n" ) ; auditBuf . append ( "declare variable $success as xs:boolean external;\n" ) ; auditBuf . append ( "xdmp:audit(\"" ) ; auditBuf . append ( ConfigConstants . AUDIT_MLCPFINISH_CODE ) ; auditBuf . append ( "\",\"" ) ; auditBuf . append ( auditMessage ) ; auditBuf . append ( "\", " ) ; auditBuf . append ( "xdmp:get-current-user(), $success)" ) ; String auditQueryStr = auditBuf . toString ( ) ; Session auditSession = null ; ContentSource auditCs = null ; try { auditCs = InternalUtilities . getInputContentSource ( conf ) ; auditSession = auditCs . newSession ( ) ; RequestOptions options = new RequestOptions ( ) ; options . setCacheResult ( false ) ; AdhocQuery auditQuery = auditSession . newAdhocQuery ( auditQueryStr ) ; auditQuery . setOptions ( options ) ; auditQuery . setNewVariable ( "success" , ValueType . XS_BOOLEAN , new Boolean ( success ) ) ; auditSession . submitRequest ( auditQuery ) ; } catch ( XccConfigException e ) { LOG . error ( e ) ; throw new IOException ( e ) ; } catch ( URISyntaxException e ) { LOG . error ( e ) ; throw new IOException ( e ) ; } catch ( RequestException e ) { LOG . error ( e ) ; LOG . error ( "Query: " + auditQueryStr ) ; throw new IOException ( e ) ; } }
@param job
@param counters
@throws IOException