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