Search in sources :

Example 41 with ColumnFormatter

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

the class GetJDBCConfigSourceConfiguration method execute.

@Override
public void execute(AdminCommandContext acc) {
    final ActionReport actionReport = acc.getActionReport();
    final Config targetConfig = targetUtil.getConfig(target);
    if (targetConfig == null) {
        actionReport.setMessage("No such config named: " + target);
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    JDBCConfigSourceConfiguration jdbcConfigSourceConfiguration = targetConfig.getExtensionByType(JDBCConfigSourceConfiguration.class);
    ColumnFormatter columnFormatter = new ColumnFormatter(OUTPUT_HEADERS);
    Object[] outputValues = { jdbcConfigSourceConfiguration.getJndiName(), jdbcConfigSourceConfiguration.getTableName(), jdbcConfigSourceConfiguration.getKeyColumnName(), jdbcConfigSourceConfiguration.getValueColumnName() };
    columnFormatter.addRow(outputValues);
    actionReport.appendMessage(columnFormatter.toString());
    Map<String, Object> extraPropertiesMap = new HashMap<>();
    extraPropertiesMap.put("jndiName", jdbcConfigSourceConfiguration.getJndiName());
    extraPropertiesMap.put("tableName", jdbcConfigSourceConfiguration.getTableName());
    extraPropertiesMap.put("keyColumnName", jdbcConfigSourceConfiguration.getKeyColumnName());
    extraPropertiesMap.put("valueColumnName", jdbcConfigSourceConfiguration.getValueColumnName());
    Properties extraProperties = new Properties();
    extraProperties.put("jdbcConfigSourceConfiguration", extraPropertiesMap);
    actionReport.setExtraProperties(extraProperties);
}
Also used : JDBCConfigSourceConfiguration(fish.payara.nucleus.microprofile.config.spi.JDBCConfigSourceConfiguration) HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 42 with ColumnFormatter

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

the class ListApplicationRefsCommand method execute.

/**
 * Entry point from the framework into the command execution
 * @param context context for the command.
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    final ActionReport subReport = report.addSubActionsReport();
    ColumnFormatter cf = new ColumnFormatter();
    ActionReport.MessagePart part = report.getTopMessagePart();
    int numOfApplications = 0;
    if (!terse && long_opt) {
        String[] headings = new String[] { "NAME", "STATUS" };
        cf = new ColumnFormatter(headings);
    }
    for (ApplicationRef ref : appRefs) {
        Object[] row = new Object[] { ref.getRef() };
        if (!terse && long_opt) {
            row = new Object[] { ref.getRef(), getLongStatus(ref) };
        }
        cf.addRow(row);
        numOfApplications++;
    }
    if (numOfApplications != 0) {
        report.setMessage(cf.toString());
    } else if (!terse) {
        subReport.setMessage(localStrings.getLocalString(DeployCommand.class, "NoSuchAppDeployed", "No applications are deployed to this target {0}.", new Object[] { this.target }));
        part.setMessage(localStrings.getLocalString("list.components.no.elements.to.list", "Nothing to List."));
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : ActionReport(org.glassfish.api.ActionReport) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter) RestEndpoint(org.glassfish.api.admin.RestEndpoint)

Example 43 with ColumnFormatter

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

the class GenericListCommand method execute.

@Override
public void execute(final AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    if (parentBean == null) {
        String msg = LOCAL_STRINGS.getLocalString(GenericCrudCommand.class, "GenericCreateCommand.target_object_not_found", "The CrudResolver {0} could not find the configuration object of type {1} where instances of {2} should be added", resolver.getClass().toString(), parentType, targetType);
        report.failure(LOGGER, msg);
        return;
    }
    // Force longOpt if output option is specified
    if (outputOpts != null) {
        longOpt = true;
    }
    List<ColumnInfo> cols = null;
    ColumnFormatter colfm = null;
    if (longOpt) {
        cols = getColumnInfo(targetType);
        if (!isOutputOptsValid(cols, outputOpts)) {
            String collist = arrayToString(getColumnHeadings(cols));
            String msg = LOCAL_STRINGS.getLocalString(GenericCrudCommand.class, "GenericListCommand.invalidOutputOpts", "Invalid output option. Choose from the following columns: {0}", collist);
            report.failure(LOGGER, msg);
            return;
        }
        cols = filterColumns(cols, outputOpts);
        // sort the columns based on column ordering
        Collections.sort(cols, new Comparator<ColumnInfo>() {

            @Override
            public int compare(ColumnInfo o1, ColumnInfo o2) {
                return Integer.compare(o1.order, o2.order);
            }
        });
        colfm = headerOpt ? new ColumnFormatter(getColumnHeadings(cols)) : new ColumnFormatter();
    }
    List<Map> list = new ArrayList<Map>();
    Properties props = report.getExtraProperties();
    if (props == null) {
        props = new Properties();
        report.setExtraProperties(props);
    }
    try {
        List<ConfigBeanProxy> children = (List<ConfigBeanProxy>) targetMethod.invoke(parentBean);
        for (ConfigBeanProxy child : children) {
            if (name != null && !name.equals(Dom.unwrap(child).getKey())) {
                continue;
            }
            Map<String, String> map = new HashMap<String, String>();
            if (longOpt) {
                String[] data = getColumnData(child, cols);
                colfm.addRow(data);
                for (int i = 0; i < data.length; i++) {
                    map.put(cols.get(i).xmlName, data[i]);
                }
            } else {
                Dom childDom = Dom.unwrap(child);
                String key = childDom.getKey();
                if (key == null) {
                    String msg = LOCAL_STRINGS.getLocalString(GenericCrudCommand.class, "GenericListCommand.element_has_no_key", "The element {0} has no key attribute", targetType);
                    report.failure(LOGGER, msg);
                    return;
                }
                report.addSubActionsReport().setMessage(key);
                map.put("key", key);
            }
            list.add(map);
        }
        if (longOpt) {
            report.appendMessage(colfm.toString());
        }
        if (!list.isEmpty()) {
            props.put(elementName(Dom.unwrap(parentBean).document, parentType, targetType), list);
        }
    } catch (Exception e) {
        String msg = LOCAL_STRINGS.getLocalString(GenericCrudCommand.class, "GenericCrudCommand.method_invocation_exception", "Exception while invoking {0} method : {1}", targetMethod.toString(), e.toString());
        report.failure(LOGGER, msg, e);
    }
}
Also used : ActionReport(org.glassfish.api.ActionReport) InvocationTargetException(java.lang.reflect.InvocationTargetException) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 44 with ColumnFormatter

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

the class ListDomainsCommand method executeCommand.

@Override
protected int executeCommand() throws CommandException, CommandValidationException {
    try {
        File domainsDirFile = ok(domainDirParam) ? new File(domainDirParam) : DomainDirs.getDefaultDomainsDir();
        DomainConfig domainConfig = new DomainConfig(null, domainsDirFile.getAbsolutePath());
        DomainsManager manager = new PEDomainsManager();
        String[] domainsList = manager.listDomains(domainConfig);
        // no prompting for passwords
        programOpts.setInteractive(false);
        if (domainsList.length > 0) {
            if (longOpt) {
                String[] headings = { "DOMAIN", "ADMIN_HOST", "ADMIN_PORT", "RUNNING", "RESTART_REQUIRED" };
                ColumnFormatter cf = header ? new ColumnFormatter(headings) : new ColumnFormatter();
                for (String dn : domainsList) {
                    DomainInfo di = getStatus(dn);
                    cf.addRow(new Object[] { dn, di.adminAddr.getHost(), di.adminAddr.getPort(), di.status, di.restartRequired });
                }
                logger.info(cf.toString());
            } else {
                for (String dn : domainsList) {
                    logger.info(getStatus(dn).statusMsg);
                }
            }
        } else {
            logger.fine(STRINGS.get("NoDomainsToList"));
        }
    } catch (Exception ex) {
        throw new CommandException(ex.getLocalizedMessage());
    }
    return 0;
}
Also used : PEDomainsManager(com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager) DomainsManager(com.sun.enterprise.admin.servermgmt.DomainsManager) File(java.io.File) PEDomainsManager(com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter) IOException(java.io.IOException) DomainException(com.sun.enterprise.admin.servermgmt.DomainException) DomainConfig(com.sun.enterprise.admin.servermgmt.DomainConfig)

Example 45 with ColumnFormatter

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

the class InstanceInfo method format.

// ///////////////////////////////////////////////////////////////////////
// //////  static formatting stuff below   ///////////////////////////////
// ///////////////////////////////////////////////////////////////////////
public static String format(List<InstanceInfo> infos) {
    String[] headings = { NAME, HOST, PORT, PID, CLUSTER, STATE };
    ColumnFormatter cf = new ColumnFormatter(headings);
    for (InstanceInfo info : infos) {
        cf.addRow(new Object[] { info.getName(), info.getHost(), info.getPort(), formatPid(info), info.getDisplayCluster(), info.getDisplayState() });
    }
    return cf.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