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);
}
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);
}
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);
}
}
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;
}
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();
}
Aggregations