Search in sources :

Example 21 with ColumnFormatter

use of com.sun.enterprise.util.ColumnFormatter in project Payara by payara.

the class ListBatchJobSteps method handleJob.

private Map<String, Object> handleJob(StepExecution stepExecution, ColumnFormatter columnFormatter) {
    Map<String, Object> jobInfo = new HashMap<>();
    int stepMetricsIndex = -1;
    StringTokenizer st = new StringTokenizer("", "");
    String[] cfData = new String[getOutputHeaders().length];
    for (int index = 0; index < getOutputHeaders().length; index++) {
        Object data = null;
        switch(getOutputHeaders()[index]) {
            case NAME:
                data = stepExecution.getStepName();
                break;
            case STEP_ID:
                data = stepExecution.getStepExecutionId();
                break;
            case BATCH_STATUS:
                data = stepExecution.getBatchStatus() != null ? stepExecution.getBatchStatus() : "";
                break;
            case EXIT_STATUS:
                data = stepExecution.getExitStatus() != null ? stepExecution.getExitStatus() : "";
                break;
            case START_TIME:
                if (stepExecution.getStartTime() != null) {
                    data = stepExecution.getStartTime().getTime();
                    cfData[index] = stepExecution.getStartTime().toString();
                } else {
                    data = "";
                }
                break;
            case END_TIME:
                if (stepExecution.getEndTime() != null) {
                    data = stepExecution.getEndTime().getTime();
                    cfData[index] = stepExecution.getEndTime().toString();
                } else {
                    data = "";
                }
                break;
            case STEP_METRICS:
                stepMetricsIndex = index;
                Map<String, Long> metricMap = new HashMap<>();
                if (stepExecution.getMetrics() != null) {
                    ColumnFormatter cf = new ColumnFormatter(new String[] { "METRICNAME", "VALUE" });
                    for (Metric metric : stepExecution.getMetrics()) {
                        metricMap.put(metric.getType().name(), metric.getValue());
                        cf.addRow(new Object[] { metric.getType().name(), metric.getValue() });
                    }
                    st = new StringTokenizer(cf.toString(), "\n");
                }
                data = metricMap;
                break;
            default:
                throw new IllegalArgumentException("Unknown header: " + getOutputHeaders()[index]);
        }
        jobInfo.put(getOutputHeaders()[index], data);
        cfData[index] = (stepMetricsIndex != index) ? (cfData[index] == null ? data.toString() : cfData[index]) : (st.hasMoreTokens() ? st.nextToken() : "");
    }
    columnFormatter.addRow(cfData);
    cfData = new String[getOutputHeaders().length];
    for (int i = 0; i < getOutputHeaders().length; i++) cfData[i] = "";
    while (st.hasMoreTokens()) {
        cfData[stepMetricsIndex] = st.nextToken();
        columnFormatter.addRow(cfData);
    }
    return jobInfo;
}
Also used : Metric(javax.batch.runtime.Metric) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 22 with ColumnFormatter

use of com.sun.enterprise.util.ColumnFormatter in project Payara by payara.

the class ListBatchJobSteps method executeCommand.

@Override
protected void executeCommand(AdminCommandContext context, Properties extraProps) throws Exception {
    ColumnFormatter columnFormatter = new ColumnFormatter(getDisplayHeaders());
    List<Map<String, Object>> jobExecutions = new ArrayList<>();
    extraProps.put(LIST_BATCH_JOBS_STEPS, jobExecutions);
    for (StepExecution je : findStepExecutions()) {
        try {
            jobExecutions.add(handleJob(je, columnFormatter));
        } catch (Exception ex) {
            logger.log(Level.WARNING, "Exception while getting jobExecution details: " + ex);
            logger.log(Level.FINE, "Exception while getting jobExecution details ", ex);
        }
    }
    context.getActionReport().setMessage(columnFormatter.toString());
}
Also used : StepExecution(javax.batch.runtime.StepExecution) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter) NoSuchJobExecutionException(javax.batch.operations.NoSuchJobExecutionException) JobSecurityException(javax.batch.operations.JobSecurityException)

Example 23 with ColumnFormatter

use of com.sun.enterprise.util.ColumnFormatter in project Payara by payara.

the class GetDatadogNotifierConfiguration method listConfiguration.

@Override
protected String listConfiguration(DatadogNotifierConfiguration configuration) {
    String[] headers = { "Enabled", "Key" };
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    Object[] values = new Object[2];
    values[0] = configuration.getEnabled();
    values[1] = configuration.getKey();
    columnFormatter.addRow(values);
    return columnFormatter.toString();
}
Also used : ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 24 with ColumnFormatter

use of com.sun.enterprise.util.ColumnFormatter in project Payara by payara.

the class GetEmailNotifierConfiguration method listConfiguration.

@Override
protected String listConfiguration(EmailNotifierConfiguration configuration) {
    String[] headers = { "Enabled", "JNDI Name", "To" };
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    Object[] values = new Object[3];
    values[0] = configuration.getEnabled();
    values[1] = configuration.getJndiName();
    values[2] = configuration.getTo();
    columnFormatter.addRow(values);
    return columnFormatter.toString();
}
Also used : ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 25 with ColumnFormatter

use of com.sun.enterprise.util.ColumnFormatter in project Payara by payara.

the class GetHipchatNotifierConfiguration method listConfiguration.

@Override
protected String listConfiguration(HipchatNotifierConfiguration configuration) {
    String[] headers = { "Enabled", "Room Name", "Token" };
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    Object[] values = new Object[3];
    values[0] = configuration.getEnabled();
    values[1] = configuration.getRoomName();
    values[2] = configuration.getToken();
    columnFormatter.addRow(values);
    return columnFormatter.toString();
}
Also used : ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Aggregations

ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)53 Properties (java.util.Properties)24 HashMap (java.util.HashMap)22 ActionReport (org.glassfish.api.ActionReport)22 Config (com.sun.enterprise.config.serverbeans.Config)21 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)8 ArrayList (java.util.ArrayList)7 PayaraNotifier (fish.payara.internal.notification.PayaraNotifier)5 MonitoringService (com.sun.enterprise.config.serverbeans.MonitoringService)3 AMXConfiguration (fish.payara.admin.amx.config.AMXConfiguration)2 MonitoredAttribute (fish.payara.jmx.monitoring.configuration.MonitoredAttribute)2 MonitoringServiceConfiguration (fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration)2 BaseHealthCheck (fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck)2 NotifierConfigurationType (fish.payara.nucleus.notification.configuration.NotifierConfigurationType)2 LogNotifierConfiguration (fish.payara.nucleus.notification.log.LogNotifierConfiguration)2 BaseNotifierService (fish.payara.nucleus.notification.service.BaseNotifierService)2 File (java.io.File)2 TaggedJobExecution (com.ibm.jbatch.spi.TaggedJobExecution)1 DomainConfig (com.sun.enterprise.admin.servermgmt.DomainConfig)1 DomainException (com.sun.enterprise.admin.servermgmt.DomainException)1