use of org.glassfish.api.ActionReport in project Payara by payara.
the class ListHazelcastClusterMembersCommand method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport actionReport = context.getActionReport();
// Check if the DAS is in a Hazelcast cluster
if (payaraInstance.isClustered()) {
// Get the instance descriptors of the cluster members
Set<InstanceDescriptor> instances = payaraInstance.getClusteredPayaras();
// Create the table headers
String[] headers = { "Instance Name", "Instance Group", "Instance Type", "Host Name", "HTTP Ports", "HTTPS Ports", "Admin Port", "Hazelcast Port", "Lite Member", "Deployed Applications" };
ColumnFormatter columnFormatter = new ColumnFormatter(headers);
List members = new ArrayList();
Properties extraProps = new Properties();
// list
for (InstanceDescriptor instance : instances) {
if (type != null && type.equals("micro")) {
if (instance.isMicroInstance()) {
populateMembers(members, instance, columnFormatter);
}
} else if (type != null && type.equals("server")) {
if (instance.isPayaraInstance()) {
populateMembers(members, instance, columnFormatter);
}
} else {
populateMembers(members, instance, columnFormatter);
}
}
// Return the instance information as both a String for console output, and in the action report for REST
extraProps.put("members", members);
actionReport.setExtraProperties(extraProps);
actionReport.setMessage(columnFormatter.toString());
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} else {
// If hazelcast is not enabled, just return a String stating as such
Properties extraProps = new Properties();
extraProps.put("members", "Hazelcast is not enabled");
actionReport.setExtraProperties(extraProps);
actionReport.setMessage("Hazelcast is not enabled");
}
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class SendAsadminCommand method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport actionReport = context.getActionReport();
// Check if the DAS is in a Hazelcast cluster
if (payaraMicro.isClustered()) {
// Get the subset of targets if provided, otherwise just get all clustered Micro instances
Map<String, InstanceDescriptor> targetInstanceDescriptors = getTargetInstanceDescriptors(targets);
// Add any explicit targets to our list of target GUIDS
targetInstanceDescriptors.putAll(getExplicitTargetInstanceDescriptors(explicitTargets));
// If no targets have been found, throw an exception and fail out
if (targetInstanceDescriptors.isEmpty()) {
throw new IllegalArgumentException("No targets match!");
}
// Get the command parameters if provided, otherwise initialise to an empty String
if (parameters != null) {
parameters = parseParameters(parameters);
} else {
parameters = new String[] { "" };
}
// Run the asadmin command against the targets (or all instances if no targets given)
Map<String, Future<ClusterCommandResult>> results = payaraMicro.executeClusteredASAdmin(targetInstanceDescriptors.keySet(), command, parameters);
// Check the command results for any failures
if (results != null) {
List<String> successMessages = new ArrayList<>();
List<String> warningMessages = new ArrayList<>();
List<String> failureMessages = new ArrayList<>();
for (Map.Entry<String, Future<ClusterCommandResult>> result : results.entrySet()) {
try {
ClusterCommandResult commandResult = result.getValue().get();
switch(commandResult.getExitStatus()) {
case SUCCESS:
// Only get the success messages if we've asked for them
if (verbose || logOutput) {
// We only want to get the message, not the formatter name or exit code
String rawOutput = commandResult.getOutput();
String[] outputComponents = rawOutput.split(commandResult.getExitStatus().name());
String output = outputComponents.length > 1 ? outputComponents[1] : rawOutput;
// Box the name and add it to the output to help split up the individual responses,
// since the success messages don't inherently provide information about what instance
// the command was run on
String boxedInstanceName = boxInstanceName(output);
successMessages.add("\n" + targetInstanceDescriptors.get(result.getKey()).getInstanceName() + "\n" + boxedInstanceName);
}
break;
case WARNING:
// If one of the commands has not already failed, set the exit code as WARNING
if (actionReport.getActionExitCode() != ExitCode.FAILURE) {
actionReport.setActionExitCode(ExitCode.WARNING);
}
// We only want to get the message, not the formatter name or exit code
failureMessages.add("\n" + targetInstanceDescriptors.get(result.getKey()).getInstanceName() + ":" + processException(commandResult));
break;
case FAILURE:
actionReport.setActionExitCode(ExitCode.FAILURE);
// We only want to get the message, not the formatter name or exit code
failureMessages.add("\n" + targetInstanceDescriptors.get(result.getKey()).getInstanceName() + ":\n" + processException(commandResult));
break;
}
} catch (InterruptedException | ExecutionException ex) {
actionReport.setActionExitCode(ExitCode.FAILURE);
actionReport.failure(Logger.getLogger(SendAsadminCommand.class.getName()), "Ran into an exception during execution: \n", ex);
}
}
switch(actionReport.getActionExitCode()) {
case SUCCESS:
actionReport.setMessage("Command executed successfully");
// Skip if neither verbose or logOutput were selected
if (verbose || logOutput) {
String output = "";
// Combine the success messages into one String
for (String successMessage : successMessages) {
output += "\n" + successMessage;
}
// Only print out the messages if verbose was chosen
if (verbose) {
actionReport.setMessage(output);
}
// Only log the messages if logOutput was chosen
if (logOutput) {
Logger.getLogger(SendAsadminCommand.class.getName()).log(Level.INFO, output);
}
}
break;
case WARNING:
actionReport.setMessage("Command completed with warnings: ");
for (String warningMessage : warningMessages) {
actionReport.appendMessage("\n" + warningMessage);
}
break;
case FAILURE:
actionReport.setMessage("Failures reported: ");
for (String failureMessage : failureMessages) {
actionReport.appendMessage("\n" + failureMessage);
}
break;
}
} else {
actionReport.setMessage("No results returned!");
actionReport.setActionExitCode(ExitCode.FAILURE);
}
} else {
actionReport.setMessage("Hazelcast not enabled");
actionReport.setActionExitCode(ExitCode.FAILURE);
}
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class DisableHTTPLBApplicationCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
Logger logger = context.getLogger();
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
ApplicationRef appRef = domain.getApplicationRefInTarget(name, target);
if (appRef == null) {
String msg = localStrings.getLocalString("AppRefNotDefined", "Application ref [{0}] does not exist in server [{1}]", name, target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
boolean appEnabled = Boolean.valueOf(appRef.getEnabled());
if (appEnabled) {
if (appRef.getLbEnabled().equals("false")) {
String msg = localStrings.getLocalString("AppDisabled", "Application [{0}] is already disabled for [{1}].", name, target);
logger.warning(msg);
report.setMessage(msg);
} else {
try {
updateLbEnabledForApp(name, target, timeout);
} catch (TransactionFailure e) {
String msg = localStrings.getLocalString("FailedToUpdateAttr", "Failed to update lb-enabled attribute for {0}", name);
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
report.setFailureCause(e);
}
}
}
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class DisableHTTPLBServerCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
Logger logger = context.getLogger();
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
LbConfigs lbconfigs = domain.getExtensionByType(LbConfigs.class);
if (lbconfigs == null) {
String msg = localStrings.getLocalString("NoLbConfigsElement", "Empty lb-configs");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
int t = Integer.parseInt(timeout);
if (t < 0) {
String msg = localStrings.getLocalString("InvalidTimeout", "Invalid timeout {0}", timeout);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
if (tgt.isCluster(target)) {
// disable all servers in cluster
updateLBForCluster(report, target, "false", timeout);
} else {
boolean foundTarget = false;
List<LbConfig> lbConfigs = lbconfigs.getLbConfig();
for (LbConfig lc : lbConfigs) {
ServerRef sRef = lc.getRefByRef(ServerRef.class, target);
if (sRef == null) {
// log a warning and continue search
logger.warning(localStrings.getLocalString("InvalidInstance", "Server {0} does not exist in {1}", target, lc.getName()));
} else {
int curTout = Integer.parseInt(sRef.getDisableTimeoutInMinutes());
boolean enabled = sRef.getLbEnabled().equals("true");
if ((enabled == false) && (curTout == t)) {
String msg = localStrings.getLocalString("ServerDisabled", "Server [{0}] is already disabled.", sRef.getRef());
report.setMessage(msg);
return;
}
try {
updateLbEnabled(sRef, "false", timeout);
} catch (TransactionFailure ex) {
String msg = localStrings.getLocalString("FailedToUpdateAttr", "Failed to update lb-enabled attribute for {0}", target);
report.setMessage(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(ex);
return;
}
foundTarget = true;
}
}
// did not find server target
if (!foundTarget) {
ServerRef sRef = getServerRefFromCluster(report, target);
if (sRef == null) {
String msg = localStrings.getLocalString("InvalidServer", "Server {0} does not exist", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
} else {
int curTout = Integer.parseInt(sRef.getDisableTimeoutInMinutes());
boolean enabled = sRef.getLbEnabled().equals("true");
if ((enabled == false) && (curTout == t)) {
String msg = localStrings.getLocalString("ServerDisabled", "Server [{0}] is already disabled.", sRef.getRef());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
try {
updateLbEnabled(sRef, "false", timeout);
} catch (TransactionFailure ex) {
String msg = localStrings.getLocalString("FailedToUpdateAttr", "Failed to update lb-enabled attribute for {0}", target);
report.setMessage(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(ex);
return;
}
}
}
}
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class ExportHttpLbConfig method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
try {
String msg = process(context);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
report.setMessage(msg);
} catch (Throwable t) {
String msg = LbLogUtil.getStringManager().getString("ExportHttpLbConfigFailed", t.getMessage());
LbLogUtil.getLogger().log(Level.WARNING, msg);
if (LbLogUtil.getLogger().isLoggable(Level.FINE)) {
LbLogUtil.getLogger().log(Level.FINE, "Exception when exporting http lb config", t);
}
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(t.getMessage());
report.setFailureCause(t);
}
}
Aggregations