@Override public void run() { ci.execute(); if (responseQueue != null) { responseQueue.add(this); } }
@Override public void run() { ci.execute(); if (responseQueue != null) { responseQueue.add(this); } }
private void validateInstanceDirUnique(ActionReport report, AdminCommandContext context) { CommandInvocation listInstances = cr.getCommandInvocation("list-instances", report, context.getSubject()); ParameterMap map = new ParameterMap(); map.add("whichTarget", theNode.getName()); listInstances.parameters(map); listInstances.execute(); Properties pro = listInstances.report().getExtraProperties(); if (pro != null){ List<HashMap> instanceList = (List<HashMap>) pro.get("instanceList"); if (instanceList == null) return; for (HashMap instanceMap : instanceList) { final File nodeDirFile = (nodeDir != null ? new File(nodeDir) : defaultLocalNodeDirFile()); File instanceDir = new File(new File(nodeDirFile.toString(), theNode.getName()), instance); String instanceName = (String)instanceMap.get("name"); File instanceListDir = new File(new File(nodeDirFile.toString(), theNode.getName()), instance); if (instance.equalsIgnoreCase(instanceName) && instanceDir.equals(instanceListDir)) { String msg = Strings.get("Instance.duplicateInstanceDir", instance, instanceName); logger.warning(msg); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setMessage(msg); return; } } } }
@Override public void execute(AdminCommandContext context) { ActionReport report = context.getActionReport(); Logger logger = context.logger; Node node = nodes.getNode(name); if (node == null) { //no node to delete nothing to do here String msg = Strings.get("noSuchNode", name); logger.warning(msg); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setMessage(msg); return; } if (!(node.getType().equals("CONFIG") )){ //no node to delete nothing to do here String msg = Strings.get("notConfigNodeType", name); logger.warning(msg); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setMessage(msg); return; } CommandInvocation ci = cr.getCommandInvocation("_delete-node", report); ParameterMap map = new ParameterMap(); map.add("DEFAULT", name); ci.parameters(map); ci.execute(); }
/** * Runs a command from somewhere OTHER THAN an already-running, * previously-authorized command. * <p> * If a command is already running then it should have a valid Subject and * that Subject must be used in running a nested command. This * method uses the internal system admin identity to authorize the command to be run and * this should never be done if a user has authenticated to the system * and is running a separate, already-authorized command. This method * is, therefore, used from some embedded functionality. * * @param command * @param args * @return * @throws CommandException */ /* package */ ActionReport executeCommand(String command, String... args) throws CommandException { ParameterMap commandParams = getParameters(command, args); final ActionReport actionReport = createActionReport(); org.glassfish.api.admin.CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation(command, actionReport, embeddedSystemAdministrator.getSubject(),false); inv.parameters(commandParams).execute(); return actionReport; }
@Override public void execute(AdminCommandContext context) { ActionReport report = context.getActionReport(); Logger logger = context.getLogger(); Node node = nodes.getNode(name); if (node == null) { //no node to delete nothing to do here String msg = Strings.get("noSuchNode", name); logger.warning(msg); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setMessage(msg); return; } if (!(node.getType().equals("CONFIG") )){ //no node to delete nothing to do here String msg = Strings.get("notConfigNodeType", name); logger.warning(msg); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setMessage(msg); return; } CommandInvocation ci = cr.getCommandInvocation("_delete-node", report, context.getSubject()); ParameterMap map = new ParameterMap(); map.add("DEFAULT", name); ci.parameters(map); ci.execute(); }
/** * Executes the command. * * @param context information */ public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); if (!validateParameters(name, report)) { return; } final ParameterMap paramMap; final ParameterMapExtractor extractor = new ParameterMapExtractor(this); try { paramMap = extractor.extract(excludedDeployCommandParamNames); } catch (IllegalArgumentException ex) { throw new RuntimeException(ex); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); } paramMap.set("force", String.valueOf(true)); CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("deploy", report); inv.parameters(paramMap).inbound(context.getInboundPayload()).outbound(context.getOutboundPayload()).execute(); }
private void reloadApp(AppReloadInfo appInfo) throws IOException { logger.fine("[Reloader] Reloading " + appInfo.getApplication().getName()); /* * Prepare a deploy command and invoke it, taking advantage of the * DeployCommand's logic to deal with redeploying an existing app. * * Note that the redeployinplace internal option tells the undeploy * command (which is invoked by the deploy command) to preserve the * existing directory, even if the configuration does not indicate that * the app is directory-deployed. * */ CommandRunnerImpl commandRunner = habitat.getService(CommandRunnerImpl.class); ParameterMap deployParam = new ParameterMap(); deployParam.set(DeploymentProperties.FORCE, Boolean.TRUE.toString()); deployParam.set(DeploymentProperties.PATH, appInfo.getApplicationDirectory().getCanonicalPath()); deployParam.set(DeploymentProperties.NAME, appInfo.getApplication().getName()); deployParam.set(DeploymentProperties.KEEP_REPOSITORY_DIRECTORY, "true"); commandRunner.getCommandInvocation("deploy", new XMLActionReporter(), kernelSubject).parameters(deployParam).execute(); appInfo.recordLoad(); }
/** * Disable the enabled version of the application if it exists. This method * is used in versioning context. * * @param appName application's name * @param target an option supply from admin command, it's retained for * compatibility with other releases * @param report ActionReport, report object to send back to client. */ public void handleDisable(final String appName, final String target, final ActionReport report) throws VersioningDeploymentSyntaxException { // retrieve the currently enabled version of the application String enabledVersion = getEnabledVersion(appName, target); // invoke disable if the currently enabled version is not itself if (enabledVersion != null && !enabledVersion.equals(appName)) { final ParameterMap parameters = new ParameterMap(); parameters.add("DEFAULT", enabledVersion); parameters.add("target", target); ActionReport subReport = report.addSubActionsReport(); CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("disable", subReport); inv.parameters(parameters).execute(); } }
private void displayAppScopedResources(String applicationName, ActionReport report, ActionReport.MessagePart part) { Application application = null; List<Application> applications = domain.getApplicationsInTarget(target); for (Application app : applications) { if (app.getName().equals(applicationName)) { application = app; } } if (application != null) { ActionReport subReport = report.addSubActionsReport(); CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("_list-resources", subReport); final ParameterMap parameters = new ParameterMap(); parameters.add("appname", application.getName()); inv.parameters(parameters).execute(); ActionReport.MessagePart subPart = subReport.getTopMessagePart(); for (ActionReport.MessagePart cp: subPart.getChildren()) { ActionReport.MessagePart resourcesChildPart = part.addChild(); resourcesChildPart.setMessage(cp.getMessage()); } } }
private void shutdown() { CommandRunner runner = commandRunnerProvider.get(); if (runner!=null) { final ParameterMap params = new ParameterMap(); // By default we don't want to shutdown forcefully, as that will cause the VM to exit and that's not // a very good behavior for a code known to be embedded in other processes. final boolean noForcedShutdown = Boolean.parseBoolean(context.getArguments().getProperty( com.sun.enterprise.glassfish.bootstrap.Constants.NO_FORCED_SHUTDOWN, "true")); if (noForcedShutdown) { params.set("force", "false"); } final InternalSystemAdministrator kernelIdentity = locator.getService(InternalSystemAdministrator.class); if (env.isDas()) { runner.getCommandInvocation("stop-domain", new DoNothingActionReporter(), kernelIdentity.getSubject()).parameters(params).execute(); } else { runner.getCommandInvocation("_stop-instance", new DoNothingActionReporter(), kernelIdentity.getSubject()).parameters(params).execute(); } } }
public CommandExecution execute(String commandName, CommandParameters params) { ParameterMap props = params.getOptions(); if (params.getOperands().size() > 0) { for (String op : params.getOperands()) props.add("DEFAULT", op); } final ActionReport report = new PlainTextActionReporter(); CommandExecution ce = new CommandExecution() { public ActionReport getActionReport() { return report; } public ActionReport.ExitCode getExitCode() { return report.getActionExitCode(); } public String getMessage() { return report.getMessage(); } }; runner.getCommandInvocation(commandName, report, kernelIdentity.getSubject()).parameters(props).execute(); return ce; }
@Override public void execute(AdminCommandContext context) { ActionReport report = context.getActionReport(); if (name == null) name = nodehost; if (nodes.getNode(name) != null) { //already created nothing to do here return; } CommandInvocation ci = cr.getCommandInvocation("_create-node", report, context.getSubject()); ParameterMap map = new ParameterMap(); map.add("DEFAULT", name); map.add(NodeUtils.PARAM_NODEDIR, nodedir); map.add(NodeUtils.PARAM_INSTALLDIR, installdir); map.add(NodeUtils.PARAM_NODEHOST, nodehost); map.add(NodeUtils.PARAM_TYPE,"CONFIG"); ci.parameters(map); ci.execute(); }
public boolean executeAdminCommand(ActionReport report, String commandName, String operand, String... parameters) { ParameterMap params = new ParameterMap(); if (operand!=null) { params.add("DEFAULT", operand); } for (int i=0;i<parameters.length;) { String key = parameters[i++]; String value=null; if (i<parameters.length) { value = parameters[i++]; } params.add(key, value); } CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation(commandName, report); inv.parameters(params); inv.execute(); return (report.getActionExitCode()==ActionReport.ExitCode.SUCCESS); }
@Override public void execute(AdminCommandContext context) { ActionReport report = context.getActionReport(); if (name == null) name = nodehost.toString(); if (nodes.getNode(name) != null) { //already created nothing to do here return; } CommandInvocation ci = cr.getCommandInvocation("_create-node", report); ParameterMap map = new ParameterMap(); map.add("DEFAULT", name); map.add(NodeUtils.PARAM_NODEDIR, nodedir); map.add(NodeUtils.PARAM_INSTALLDIR, installdir); map.add(NodeUtils.PARAM_NODEHOST, nodehost); map.add(NodeUtils.PARAM_TYPE,"CONFIG"); ci.parameters(map); ci.execute(); }
private void displaySubComponents(String appName, ActionReport report, ActionReport.MessagePart part) { ActionReport subReport = report.addSubActionsReport(); CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("list-sub-components", subReport); final ParameterMap parameters = new ParameterMap(); parameters.add("DEFAULT", appName); parameters.add("terse", "true"); parameters.add("resources", resources.toString()); inv.parameters(parameters).execute(); ActionReport.MessagePart subPart = subReport.getTopMessagePart(); for (ActionReport.MessagePart childPart: subPart.getChildren()) { ActionReport.MessagePart actualChildPart = part.addChild(); actualChildPart.setMessage(" " + childPart.getMessage()); for(ActionReport.MessagePart grandChildPart : childPart.getChildren()){ actualChildPart.addChild().setMessage(grandChildPart.getMessage()); } } }
public boolean executeAdminCommand(ActionReport report, String commandName, String operand, String... parameters) { ParameterMap params = new ParameterMap(); if (operand!=null) { params.add("DEFAULT", operand); } for (int i=0;i<parameters.length;) { String key = parameters[i++]; String value=null; if (i<parameters.length) { value = parameters[i++]; } params.add(key, value); } CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation(commandName, report); inv.parameters(params); inv.execute(); return (report.getActionExitCode()==ActionReport.ExitCode.SUCCESS); }
/* package */ ActionReport executeCommand(String command, String... args) throws CommandException { ParameterMap commandParams = getParameters(command, args); final ActionReport actionReport = createActionReport(); org.glassfish.api.admin.CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation(command, actionReport); inv.parameters(commandParams).execute(); return actionReport; }
void deleteJMSResource(ActionReport subReport, String tmpJMSResource, final Subject subject) { ParameterMap aoAttrList = new ParameterMap(); aoAttrList.set("DEFAULT", tmpJMSResource); //aoAttrList.set("target", target); commandRunner.getCommandInvocation("delete-jms-resource", subReport, subject).parameters(aoAttrList).execute(); } }
private ActionReport executeInternalCommand(AdminCommandContext context, String targetInstanceName) { String commandName = getCommandName(); ParameterMap params = new ParameterMap(); params.add("target", targetInstanceName); fillParameterMap(params); CommandRunner runner = serviceLocator.getService(CommandRunner.class); ActionReport subReport = context.getActionReport().addSubActionsReport(); CommandRunner.CommandInvocation inv = runner.getCommandInvocation(commandName, subReport, context.getSubject()); inv.parameters(params); inv.execute(); return subReport; }