Search in sources :

Example 31 with ColumnFormatter

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

the class GetLogNotifierConfiguration method listConfiguration.

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

Example 32 with ColumnFormatter

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

the class GetEventbusNotifierConfiguration method listConfiguration.

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

Example 33 with ColumnFormatter

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

the class ListManager method list.

/**
 * Find all backup zip files in a domain and return a String
 * summarizing information about the backup.
 * The summary is shorter if the "terse" option is true.
 * @return a String summary
 * @throws BackupException if there is a fatal error
 */
public String list() throws BackupException {
    StringBuilder sb = new StringBuilder();
    String[] headings = { BACKUP, USER, DATE, FILENAME };
    List<Integer> badPropsList = null;
    ColumnFormatter cf = null;
    boolean itemInRow = false;
    TreeSet<Status> statusSet = new TreeSet<Status>(new FileNameComparator());
    // If a backup config was not provided then look for all zips
    // including those in the backup config directories.
    // If a backup config was provided then only look for zips in
    // that backup config directory.
    findZips(request.backupConfig == null);
    badPropsList = new ArrayList<Integer>();
    // it is GUARANTEED that the length > 0
    for (int i = 0; i < zips.length; i++) {
        Status status = new Status();
        if (!status.loadProps(zips[i]))
            badPropsList.add(Integer.valueOf(i));
        else {
            // XXX: if (request.terse)  How indicate no headers?
            statusSet.add(status);
            itemInRow = true;
        }
    }
    if (itemInRow) {
        for (Status status : statusSet) {
            if (request.verbose) {
                File f = null;
                try {
                    f = new File(status.getBackupPath());
                } catch (NullPointerException e) {
                }
                if (f != null) {
                    sb.append(status.read(f, request.terse));
                    sb.append("\n\n");
                }
            } else {
                String filename = status.getFileName();
                if (cf == null) {
                    cf = new ColumnFormatter(headings);
                }
                if (filename == null)
                    filename = strings.get("backup-list.unavailable");
                cf.addRow(new Object[] { status.getBackupConfigName(), status.getUserName(), status.getTimeStamp(), filename });
            }
        }
    }
    if (cf != null)
        sb.append(cf.toString());
    // there was nothing to list.
    if (!itemInRow && !request.terse)
        sb.append("\n" + strings.get("backup-list.nothing"));
    // List any zips that had bad props.
    if (badPropsList != null && !badPropsList.isEmpty()) {
        sb.append("\n\n");
        sb.append(strings.get("backup-list.bad-props"));
        for (Integer iInt : badPropsList) {
            sb.append("\n");
            sb.append(zips[iInt.intValue()]);
        }
    }
    return sb.toString();
}
Also used : TreeSet(java.util.TreeSet) File(java.io.File) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 34 with ColumnFormatter

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

the class ListBatchJobExecutions 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_EXECUTIONS, jobExecutions);
    if (executionId != null) {
        JobOperator jobOperator = getJobOperatorFromBatchRuntime();
        JobExecution je = jobOperator.getJobExecution(Long.parseLong(executionId));
        if (instanceId != null) {
            JobInstance ji = jobOperator.getJobInstance(Long.parseLong(executionId));
            if (ji.getInstanceId() != Long.parseLong(instanceId)) {
                throw new RuntimeException("executionid " + executionId + " is not associated with the specified instanceid (" + instanceId + ")" + "; did you mean " + ji.getInstanceId() + " ?");
            }
        }
        try {
            if (glassFishBatchSecurityHelper.isVisibleToThisInstance(((TaggedJobExecution) je).getTagName()))
                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);
        }
    } else if (instanceId != null) {
        for (JobExecution je : getJobExecutionForInstance(Long.parseLong(instanceId))) {
            try {
                if (glassFishBatchSecurityHelper.isVisibleToThisInstance(((TaggedJobExecution) je).getTagName()))
                    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);
            }
        }
    } else {
        JobOperator jobOperator = getJobOperatorFromBatchRuntime();
        Set<String> jobNames = jobOperator.getJobNames();
        if (jobNames != null) {
            for (String jn : jobOperator.getJobNames()) {
                List<JobInstance> exe = jobOperator.getJobInstances(jn, 0, Integer.MAX_VALUE - 1);
                if (exe != null) {
                    for (JobInstance ji : exe) {
                        for (JobExecution je : jobOperator.getJobExecutions(ji)) {
                            try {
                                if (glassFishBatchSecurityHelper.isVisibleToThisInstance(((TaggedJobExecution) je).getTagName()))
                                    jobExecutions.add(handleJob(jobOperator.getJobExecution(je.getExecutionId()), columnFormatter));
                            } catch (Exception ex) {
                                logger.log(Level.WARNING, "Exception while getting jobExecution details: " + ex);
                                logger.log(Level.FINE, "Exception while getting jobExecution details: ", ex);
                            }
                        }
                    }
                }
            }
        }
    }
    if (jobExecutions.size() > 0) {
        context.getActionReport().setMessage(columnFormatter.toString());
    } else {
        throw new RuntimeException("No Job Executions found");
    }
}
Also used : JobInstance(javax.batch.runtime.JobInstance) TaggedJobExecution(com.ibm.jbatch.spi.TaggedJobExecution) JobExecution(javax.batch.runtime.JobExecution) TaggedJobExecution(com.ibm.jbatch.spi.TaggedJobExecution) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 35 with ColumnFormatter

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

the class ListBatchJobExecutions method handleJob.

private Map<String, Object> handleJob(JobExecution je, ColumnFormatter columnFormatter) throws JobSecurityException, NoSuchJobExecutionException {
    Map<String, Object> jobInfo = new HashMap<>();
    int jobParamIndex = -1;
    StringTokenizer st = new StringTokenizer("", "");
    String[] cfData = new String[getOutputHeaders().length];
    JobOperator jobOperator = AbstractListCommand.getJobOperatorFromBatchRuntime();
    for (int index = 0; index < getOutputHeaders().length; index++) {
        Object data = null;
        switch(getOutputHeaders()[index]) {
            case JOB_NAME:
                data = " " + je.getJobName();
                break;
            case EXECUTION_ID:
                data = "" + je.getExecutionId();
                break;
            case BATCH_STATUS:
                data = je.getBatchStatus() != null ? je.getBatchStatus() : "";
                break;
            case EXIT_STATUS:
                data = je.getExitStatus() != null ? je.getExitStatus() : "";
                break;
            case START_TIME:
                if (je.getStartTime() != null) {
                    data = je.getStartTime().getTime();
                    cfData[index] = je.getStartTime().toString();
                } else {
                    data = "";
                }
                break;
            case END_TIME:
                if (je.getEndTime() != null) {
                    data = je.getEndTime().getTime();
                    cfData[index] = je.getEndTime().toString();
                } else {
                    data = "";
                }
                break;
            case JOB_PARAMETERS:
                data = je.getJobParameters() == null ? new Properties() : je.getJobParameters();
                jobParamIndex = index;
                ColumnFormatter cf = new ColumnFormatter(new String[] { "KEY", "VALUE" });
                for (Map.Entry e : ((Properties) data).entrySet()) cf.addRow(new String[] { e.getKey().toString(), e.getValue().toString() });
                st = new StringTokenizer(cf.toString(), "\n");
                break;
            case STEP_COUNT:
                long exeId = executionId == null ? je.getExecutionId() : Long.parseLong(executionId);
                data = jobOperator.getStepExecutions(exeId) == null ? 0 : jobOperator.getStepExecutions(exeId).size();
                break;
            default:
                throw new IllegalArgumentException("Unknown header: " + getOutputHeaders()[index]);
        }
        jobInfo.put(getOutputHeaders()[index], data);
        cfData[index] = (jobParamIndex != 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[jobParamIndex] = st.nextToken();
        columnFormatter.addRow(cfData);
    }
    return jobInfo;
}
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