Search in sources :

Example 66 with ParameterMap

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();
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) CommandRunner(org.glassfish.api.admin.CommandRunner)

Example 67 with ParameterMap

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);
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap)

Example 68 with ParameterMap

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;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport)

Example 69 with ParameterMap

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();
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) CustomResource(org.glassfish.resources.config.CustomResource) CustomResource(org.glassfish.resources.config.CustomResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ParameterMap(org.glassfish.api.admin.ParameterMap) After(org.junit.After)

Example 70 with 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());
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap)

Aggregations

ParameterMap (org.glassfish.api.admin.ParameterMap)149 ActionReport (org.glassfish.api.ActionReport)68 CommandRunner (org.glassfish.api.admin.CommandRunner)37 Test (org.junit.Test)25 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)24 Map (java.util.Map)20 PropsFileActionReporter (com.sun.enterprise.v3.common.PropsFileActionReporter)19 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)18 List (java.util.List)16 ArrayList (java.util.ArrayList)15 CommandRunner (org.glassfish.embeddable.CommandRunner)15 IOException (java.io.IOException)14 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)13 Before (org.junit.Before)13 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)13 CommandException (org.glassfish.api.admin.CommandException)12 File (java.io.File)11 MessagePart (org.glassfish.api.ActionReport.MessagePart)11 Resource (com.sun.enterprise.config.serverbeans.Resource)10 Logger (java.util.logging.Logger)9