use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.
the class ListJdbcResourcesTest method testExecuteSuccessListNoBob.
/**
* Test of execute method, of class ListJdbcResource.
* delete-jdbc-resource bob
* list-jdbc-resources
*/
@Test
public void testExecuteSuccessListNoBob() {
// Create JDBC Resource bob
assertTrue(resources != null);
// Get an instance of the CreateJdbcResource command
createCommand = habitat.getService(CreateJdbcResource.class);
assertTrue(createCommand != null);
parameters.add("connectionpoolid", "DerbyPool");
parameters.add("DEFAULT", "bob2");
context = new AdminCommandContextImpl(LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Delete JDBC Resource bob
// assertTrue(resources!=null);
// Get an instance of the CreateJdbcResource command
deleteCommand = habitat.getService(DeleteJdbcResource.class);
assertTrue(deleteCommand != null);
parameters = new ParameterMap();
parameters.add("DEFAULT", "bob2");
cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// List JDBC Resources and check if bob is in the list
// Get an instance of the ListJdbcResources command
listCommand = habitat.getService(ListJdbcResources.class);
parameters = new ParameterMap();
context = new AdminCommandContextImpl(LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
int numResources = 0;
for (Resource resource : resources.getResources()) {
if (resource instanceof JdbcResource) {
numResources = numResources + 1;
}
}
assertEquals(numResources, list.size());
List<String> listStr = new java.util.ArrayList();
for (MessagePart mp : list) {
listStr.add(mp.getMessage());
}
assertFalse(listStr.contains("bob2"));
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.
the class CLIUtil method getRemoteCommands.
/**
* Get the list of commands from the remote server.
*
* @return the commands as a String array, sorted
*/
public static String[] getRemoteCommands(CLIContainer container, ProgramOptions po, Environment env) throws CommandException, CommandValidationException {
/*
* In order to eliminate all local command names from the list
* of remote commands, we collect the local command names into
* a Set that we check later when collecting remote command
* names.
*/
Set<String> localnames = container.getLocalCommandsNames();
/*
* Now get the list of remote commands.
*/
po.removeDetach();
RemoteCLICommand cmd = new RemoteCLICommand("list-commands", po, env);
ActionReport report = cmd.executeAndReturnActionReport("list-commands");
List<MessagePart> children = report.getTopMessagePart().getChildren();
List<String> rcmds = new ArrayList<String>(children.size());
for (ActionReport.MessagePart msg : children) {
if (!localnames.contains(msg.getMessage())) {
rcmds.add(msg.getMessage());
}
}
Collections.sort(rcmds);
String[] remoteCommands = rcmds.toArray(new String[rcmds.size()]);
Arrays.sort(remoteCommands);
return remoteCommands;
}
use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.
the class ListJobsCommand method display.
public void display(Collection<JobInfo> jobInfoList, AdminCommandContext context) {
report = context.getActionReport();
int longestName = TITLE_NAME.length();
int longestJobId = TITLE_JOBID.length();
int longestTime = TITLE_TIME.length();
int longestState = TITLE_STATE.length();
int longestUser = TITLE_USER.length();
int longestExitCode = TITLE_EXITCODE.length();
for (JobInfo job : jobInfoList) {
int jobId = job.jobId.length();
int time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(job.commandExecutionDate).length();
int name = job.jobName.length();
int state = job.state.length();
int user;
if (job.user != null) {
user = job.user.length();
} else {
user = DEFAULT_USER_STRING.length();
}
int exitCode = job.exitCode.length();
if (name > longestName)
longestName = name;
if (time > longestTime)
longestTime = time;
if (jobId > longestJobId)
longestJobId = jobId;
if (state > longestState)
longestState = state;
if (user > longestUser)
longestUser = user;
if (exitCode > longestExitCode)
longestExitCode = exitCode;
}
if (jobInfoList.size() < 1) {
report.setMessage(TITLE_NONE);
}
longestName += 2;
longestJobId += 2;
longestState += 2;
longestTime += 2;
longestUser += 2;
longestExitCode += 2;
String formattedLine = "%-" + longestName + "s %-" + longestJobId + "s %-" + longestTime + "s %-" + longestState + "s %-" + longestExitCode + "s %-" + longestUser + "s";
// no linefeed at the end!!!
boolean first = true;
MessagePart topMsg = report.getTopMessagePart();
Properties properties = report.getExtraProperties();
if (properties == null) {
properties = new Properties();
report.setExtraProperties(properties);
}
Collection<Map<String, Object>> details = new ArrayList<Map<String, Object>>();
properties.put("jobs", details);
for (JobInfo info : jobInfoList) {
if (first) {
topMsg.setMessage(String.format(formattedLine, TITLE_NAME, TITLE_JOBID, TITLE_TIME, TITLE_STATE, TITLE_EXITCODE, TITLE_USER));
first = false;
}
MessagePart msg = topMsg.addChild();
msg.setMessage(String.format(formattedLine, info.jobName, info.jobId, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(info.commandExecutionDate), info.state, info.exitCode, info.user));
Map<String, Object> detail = new HashMap<String, Object>();
details.add(detail);
detail.put(NAME, info.jobName);
detail.put(ID, info.jobId);
detail.put(DATE, new Date(info.commandExecutionDate));
if (info.commandCompletionDate == 0)
// for a running job
detail.put(COMPLETION_DATE, " ");
else
// for a completed job
detail.put(COMPLETION_DATE, new Date(info.commandCompletionDate));
detail.put(STATE, info.state);
detail.put(CODE, info.exitCode);
detail.put(MESSAGE, info.message);
detail.put(USER, info.user);
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.
the class LocationsCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
report.setMessage(env.getInstanceRoot().getAbsolutePath().replace('\\', '/'));
MessagePart mp = report.getTopMessagePart();
mp.addProperty("Base-Root", StartupContextUtil.getInstallRoot(env.getStartupContext()).getAbsolutePath());
mp.addProperty("Domain-Root", env.getDomainRoot().getAbsolutePath());
mp.addProperty("Instance-Root", env.getInstanceRoot().getAbsolutePath());
mp.addProperty("Config-Dir", env.getConfigDirPath().getAbsolutePath());
mp.addProperty("Uptime", "" + getUptime());
mp.addProperty("Pid", "" + ProcessUtils.getPid());
mp.addProperty("Restart-Required", "" + ucl.serverRequiresRestart());
}
use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.
the class ListJdbcResourcesTest method testExecuteFailInvalidOption.
/**
* Test of execute method, of class ListJdbcResource.
* list-jdbc-resources --invalid invalid
*/
@Ignore
@Test
public void testExecuteFailInvalidOption() {
listCommand = habitat.getService(ListJdbcResources.class);
parameters.add("invalid", "invalid");
context = new AdminCommandContextImpl(LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
assertEquals(1, list.size());
for (MessagePart mp : list) {
assertEquals("Usage: list-jdbc-resources ", mp.getMessage());
}
// Check the exit code is FAILURE
assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
}
Aggregations