use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class VersioningService method handleDisable.
/**
* 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.
* @param subject the Subject on whose behalf to run
*/
public void handleDisable(final String appName, final String target, final ActionReport report, final Subject subject) throws VersioningSyntaxException {
Set<String> versionsToDisable = Collections.EMPTY_SET;
if (DeploymentUtils.isDomainTarget(target)) {
// retrieve the enabled versions on each target in the domain
Map<String, Set<String>> enabledVersions = getEnabledVersionsInReferencedTargets(appName);
if (!enabledVersions.isEmpty()) {
versionsToDisable = enabledVersions.keySet();
}
} else {
// retrieve the currently enabled version of the application
String enabledVersion = getEnabledVersion(appName, target);
if (enabledVersion != null && !enabledVersion.equals(appName)) {
versionsToDisable = new HashSet<String>();
versionsToDisable.add(enabledVersion);
}
}
Iterator<String> it = versionsToDisable.iterator();
while (it.hasNext()) {
String currentVersion = it.next();
// invoke disable if the currently enabled version is not itself
if (currentVersion != null && !currentVersion.equals(appName)) {
final ParameterMap parameters = new ParameterMap();
parameters.add("DEFAULT", currentVersion);
parameters.add("target", target);
ActionReport subReport = report.addSubActionsReport();
CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("disable", subReport, subject);
inv.parameters(parameters).execute();
}
}
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class ExampleDASCommandWithReplication method execute.
@Override
public void execute(AdminCommandContext context) {
// first we work in the DAS in this example just log something
Logger.getLogger(this.getClass().getCanonicalName()).info("This is on the DAS I am going to send message to all nodes " + message);
// work out the servers you want to call.
// The domain config object has methods to find out what servers are available
List<String> domainServers = domain.getAllTargets();
// build your command parameters
ParameterMap params = new ParameterMap();
params.add("message", message);
ClusterOperationUtil.replicateCommand("example-instance-command", FailurePolicy.Ignore, FailurePolicy.Ignore, FailurePolicy.Error, domainServers, context, params, habitat);
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class SetCommand method replicateSetCommand.
private boolean replicateSetCommand(AdminCommandContext context, String targetName, String value) {
// "domain." on the front of the attribute name is optional. So if it is
// there, strip it off.
List<Server> replicationInstances = null;
String tName;
if (targetName.startsWith("domain.")) {
tName = targetName.substring("domain.".length());
if (tName.indexOf('.') == -1) {
// This is a domain-level attribute, replicate to all instances
replicationInstances = targetService.getAllInstances();
}
} else {
tName = targetName;
}
if (replicationInstances == null) {
int dotIdx = tName.indexOf('.');
String firstElementOfName = dotIdx != -1 ? tName.substring(0, dotIdx) : tName;
Integer targetElementLocation = targetLevel.get(firstElementOfName);
if (targetElementLocation == null) {
targetElementLocation = 1;
}
if (targetElementLocation == 0) {
if ("resources".equals(firstElementOfName)) {
replicationInstances = targetService.getAllInstances();
}
if ("applications".equals(firstElementOfName)) {
String appName = getElementFromString(tName, 3);
if (appName == null) {
fail(context, localStrings.getLocalString("admin.set.invalid.appname", "Unable to extract application name from {0}", targetName));
return false;
}
replicationInstances = targetService.getInstances(domain.getAllReferencedTargetsForApplication(appName));
}
} else {
String target = getElementFromString(tName, targetElementLocation);
if (target == null) {
fail(context, localStrings.getLocalString("admin.set.invalid.target", "Unable to extract replication target from {0}", targetName));
return false;
}
replicationInstances = targetService.getInstances(target);
}
}
if (replicationInstances != null && !replicationInstances.isEmpty()) {
ParameterMap params = new ParameterMap();
params.set("DEFAULT", targetName + "=" + value);
ActionReport.ExitCode ret = ClusterOperationUtil.replicateCommand("set", FailurePolicy.Error, FailurePolicy.Warn, FailurePolicy.Ignore, replicationInstances, context, params, habitat);
if (ret.equals(ActionReport.ExitCode.FAILURE)) {
return false;
}
}
return true;
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class DeleteCustomResourceTest method tearDown.
@After
public void tearDown() throws TransactionFailure {
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
Resource target = null;
for (Resource resource : param.getResources()) {
if (resource instanceof CustomResource) {
CustomResource r = (CustomResource) resource;
if (r.getJndiName().equals("sample_custom_resource")) {
target = resource;
break;
}
}
}
if (target != null) {
param.getResources().remove(target);
}
return null;
}
}, resources);
parameters = new ParameterMap();
}
use of org.glassfish.api.admin.ParameterMap in project Payara by payara.
the class ListCustomResourcesTest method deleteCustomResource.
private void deleteCustomResource() {
org.glassfish.resources.admin.cli.DeleteCustomResource deleteCommand = habitat.getService(org.glassfish.resources.admin.cli.DeleteCustomResource.class);
assertTrue(deleteCommand != null);
ParameterMap parameters = new ParameterMap();
parameters.set("jndi_name", "custom_resource1");
cr.getCommandInvocation("delete-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
Aggregations