Search in sources :

Example 36 with ColumnFormatter

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

the class ListBatchJobs method executeCommand.

@Override
protected void executeCommand(AdminCommandContext context, Properties extraProps) throws Exception {
    String dataSourceName = batchRuntimeHelper.getDataSourceLookupName();
    InitialContext ctx = new InitialContext();
    Object object = ctx.lookup(dataSourceName);
    // check whether the referenced JNDI entry is a DataSource
    if (object instanceof DataSource) {
        dataSource = DataSource.class.cast(object);
        String prefix = batchRuntimeConfiguration.getTablePrefix();
        String suffix = batchRuntimeConfiguration.getTableSuffix();
        createTables();
        jobInstanceTableKey = prefix + "JOBINSTANCEDATA" + suffix;
        if (checkIfTableExists(jobInstanceTableKey)) {
            queryToGetUniqueJobNames = "SELECT DISTINCT name FROM " + jobInstanceTableKey;
            ColumnFormatter columnFormatter = new ColumnFormatter(getDisplayHeaders());
            if (isSimpleMode()) {
                setToSimpleMode(extraProps, columnFormatter);
            } else {
                setToLongMode(extraProps, columnFormatter);
            }
            context.getActionReport().setMessage(columnFormatter.toString());
        } else {
            context.getActionReport().failure(logger, jobInstanceTableKey + " table doesn't exists");
        }
    }
}
Also used : InitialContext(javax.naming.InitialContext) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter) DataSource(javax.sql.DataSource)

Example 37 with ColumnFormatter

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

the class ListBatchRuntimeConfiguration method executeCommand.

@Override
protected void executeCommand(AdminCommandContext context, Properties extraProps) {
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config named: " + target);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    BatchRuntimeConfiguration batchRuntimeConfiguration = config.getExtensionByType(BatchRuntimeConfiguration.class);
    Map<String, Object> map = new HashMap<>();
    map.put(DATA_SOURCE_NAME, batchRuntimeConfiguration.getDataSourceLookupName());
    map.put(EXECUTOR_SERVICE_NAME, batchRuntimeConfiguration.getExecutorServiceLookupName());
    map.put(SCHEMA_NAME, batchRuntimeConfiguration.getSchemaName());
    map.put(TABLE_PREFIX, batchRuntimeConfiguration.getTablePrefix());
    map.put(TABLE_SUFFIX, batchRuntimeConfiguration.getTableSuffix());
    extraProps.put("listBatchRuntimeConfiguration", map);
    ColumnFormatter columnFormatter = new ColumnFormatter(getDisplayHeaders());
    Object[] data = new Object[getOutputHeaders().length];
    for (int index = 0; index < getOutputHeaders().length; index++) {
        switch(getOutputHeaders()[index]) {
            case DATA_SOURCE_NAME:
                String val = batchRuntimeConfiguration.getDataSourceLookupName();
                data[index] = (val == null || val.trim().length() == 0) ? BatchRuntimeHelper.getDefaultDataSourceLookupNameForTarget(target) : val;
                break;
            case EXECUTOR_SERVICE_NAME:
                data[index] = batchRuntimeConfiguration.getExecutorServiceLookupName();
                break;
            case SCHEMA_NAME:
                data[index] = batchRuntimeConfiguration.getSchemaName();
                break;
            case TABLE_PREFIX:
                data[index] = batchRuntimeConfiguration.getTablePrefix();
                break;
            case TABLE_SUFFIX:
                data[index] = batchRuntimeConfiguration.getTableSuffix();
                break;
            default:
                throw new IllegalArgumentException("Unknown header: " + getOutputHeaders()[index]);
        }
    }
    columnFormatter.addRow(data);
    context.getActionReport().setMessage(columnFormatter.toString());
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config) BatchRuntimeConfiguration(org.glassfish.batch.spi.impl.BatchRuntimeConfiguration) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 38 with ColumnFormatter

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

the class GetMPHealthCheckConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    Config targetConfig = targetUtil.getConfig(target);
    if (targetConfig == null) {
        context.getActionReport().setMessage("No such config name: " + targetUtil);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    MicroprofileHealthCheckConfiguration healthCheckConfiguration = targetConfig.getExtensionByType(MicroprofileHealthCheckConfiguration.class);
    ColumnFormatter columnFormatter = new ColumnFormatter(OUTPUT_HEADERS);
    Object[] outputValues = { healthCheckConfiguration.getEnabled(), healthCheckConfiguration.getEndpoint(), healthCheckConfiguration.getVirtualServers(), healthCheckConfiguration.getSecurityEnabled(), healthCheckConfiguration.getRoles() };
    columnFormatter.addRow(outputValues);
    context.getActionReport().appendMessage(columnFormatter.toString());
    Map<String, Object> extraPropertiesMap = new HashMap<>();
    extraPropertiesMap.put("enabled", healthCheckConfiguration.getEnabled());
    extraPropertiesMap.put("endpoint", healthCheckConfiguration.getEndpoint());
    extraPropertiesMap.put("virtualServers", healthCheckConfiguration.getVirtualServers());
    extraPropertiesMap.put("securityenabled", healthCheckConfiguration.getSecurityEnabled());
    extraPropertiesMap.put("roles", healthCheckConfiguration.getRoles());
    Properties extraProperties = new Properties();
    extraProperties.put("microprofileHealthCheckConfiguration", extraPropertiesMap);
    context.getActionReport().setExtraProperties(extraProperties);
}
Also used : HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) MicroprofileHealthCheckConfiguration(fish.payara.microprofile.healthcheck.config.MicroprofileHealthCheckConfiguration) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 39 with ColumnFormatter

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

the class ListRequestTraces method generateReport.

private void generateReport(ActionReport actionReport) {
    RequestTracingExecutionOptions executionOptions = service.getExecutionOptions();
    if (first == null) {
        first = executionOptions.getTraceStoreSize();
    }
    RequestTraceStoreInterface eventStore;
    if (historicTraces == null || historicTraces) {
        eventStore = service.getHistoricRequestTraceStore();
    } else {
        eventStore = service.getRequestTraceStore();
    }
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    Properties extrasProps = new Properties();
    List<Map<String, String>> tracesList = new ArrayList<>();
    Collection<RequestTrace> traces = eventStore.getTraces(first);
    for (RequestTrace requestTrace : traces) {
        Map<String, String> messages = new LinkedHashMap<>();
        Object[] values = new Object[3];
        values[0] = requestTrace.getStartTime();
        values[1] = requestTrace.getElapsedTime();
        values[2] = requestTrace.toString();
        messages.put("occuringTime", values[0].toString());
        messages.put("elapsedTime", values[1].toString());
        messages.put("message", (String) values[2]);
        tracesList.add(messages);
        columnFormatter.addRow(values);
    }
    actionReport.setMessage(columnFormatter.toString());
    extrasProps.put("traces", tracesList);
    actionReport.setExtraProperties(extrasProps);
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : RequestTrace(fish.payara.notification.requesttracing.RequestTrace) RequestTraceStoreInterface(fish.payara.nucleus.requesttracing.store.RequestTraceStoreInterface) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter) RequestTracingExecutionOptions(fish.payara.nucleus.requesttracing.domain.execoptions.RequestTracingExecutionOptions)

Example 40 with ColumnFormatter

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

the class ListHistoricHealthChecks method generateReport.

private void generateReport(ActionReport actionReport) {
    if (first == null) {
        first = service.getHistoricalTraceStoreSize();
    }
    HistoricHealthCheckEvent[] traces = eventStore.getTraces(first);
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    Properties extrasProps = new Properties();
    List historic = new ArrayList<>();
    if (traces != null) {
        for (HistoricHealthCheckEvent historicHealthCheckEvent : traces) {
            LinkedHashMap<String, String> messages = new LinkedHashMap<String, String>();
            Object[] values = new Object[2];
            values[0] = new Date(historicHealthCheckEvent.getOccurringTime());
            values[1] = constructMessage(historicHealthCheckEvent);
            messages.put("dateTime", values[0].toString());
            messages.put("message", (String) values[1]);
            historic.add(messages);
            columnFormatter.addRow(values);
        }
    }
    actionReport.setMessage(columnFormatter.toString());
    extrasProps.put("historicmessages", historic);
    actionReport.setExtraProperties(extrasProps);
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : HistoricHealthCheckEvent(fish.payara.nucleus.healthcheck.HistoricHealthCheckEvent) 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