Search in sources :

Example 21 with CommandRunner

use of org.glassfish.api.admin.CommandRunner in project Payara by payara.

the class ResourceUtil method getParamMetaData.

/**
 * Constructs and returns the parameter meta-data.
 *
 * @param commandName the command associated with the resource method
 * @param commandParamsToSkip the command parameters for which not to
 * include the meta-data.
 * @param habitat the habitat
 * @return Collection the meta-data for the parameter of the resource
 * method.
 */
public static Collection<CommandModel.ParamModel> getParamMetaData(String commandName, Collection<String> commandParamsToSkip, ServiceLocator habitat) {
    CommandModel cm = habitat.<CommandRunner>getService(CommandRunner.class).getModel(commandName, RestLogging.restLogger);
    Collection<String> parameterNames = cm.getParametersNames();
    ArrayList<CommandModel.ParamModel> metaData = new ArrayList<CommandModel.ParamModel>();
    CommandModel.ParamModel paramModel;
    for (String name : parameterNames) {
        paramModel = cm.getModelFor(name);
        String parameterName = (paramModel.getParam().primary()) ? "id" : paramModel.getName();
        if (!commandParamsToSkip.contains(parameterName)) {
            metaData.add(paramModel);
        }
    }
    return metaData;
}
Also used : ArrayList(java.util.ArrayList) CommandModel(org.glassfish.api.admin.CommandModel) CommandRunner(org.glassfish.api.admin.CommandRunner)

Example 22 with CommandRunner

use of org.glassfish.api.admin.CommandRunner in project Payara by payara.

the class PayaraServerNameGenerator method getAllNamesInUse.

private static List<String> getAllNamesInUse(AdminCommandContext context) {
    List<String> namesInUse = new ArrayList<>();
    CommandRunner commandRunner = Globals.getDefaultBaseServiceLocator().getService(CommandRunner.class);
    namesInUse.addAll(getInstanceNames(new DoNothingActionReporter(), context, commandRunner));
    namesInUse.addAll(getNodeNames(new DoNothingActionReporter(), context, commandRunner));
    namesInUse.addAll(getClusterNames(new DoNothingActionReporter(), context, commandRunner));
    namesInUse.addAll(getDeploymentGroupNames(new DoNothingActionReporter(), context, commandRunner));
    namesInUse.addAll(getConfigNames(new DoNothingActionReporter(), context, commandRunner));
    return namesInUse;
}
Also used : ArrayList(java.util.ArrayList) CommandRunner(org.glassfish.api.admin.CommandRunner) DoNothingActionReporter(com.sun.enterprise.admin.report.DoNothingActionReporter)

Example 23 with CommandRunner

use of org.glassfish.api.admin.CommandRunner in project Payara by payara.

the class PayaraServerNameGenerator method getDeploymentGroupNames.

private static List<String> getDeploymentGroupNames(ActionReport report, AdminCommandContext context, CommandRunner commandRunner) {
    List<String> deploymentGroupNames = new ArrayList<>();
    CommandRunner.CommandInvocation listDeploymentGroupsCommand = commandRunner.getCommandInvocation("list-deployment-groups", report, context.getSubject());
    listDeploymentGroupsCommand.execute();
    Properties extraProperties = listDeploymentGroupsCommand.report().getExtraProperties();
    if (extraProperties != null) {
        deploymentGroupNames.addAll((List<String>) extraProperties.get("listOfDeploymentGroups"));
    }
    return deploymentGroupNames;
}
Also used : ArrayList(java.util.ArrayList) Properties(java.util.Properties) CommandRunner(org.glassfish.api.admin.CommandRunner)

Example 24 with CommandRunner

use of org.glassfish.api.admin.CommandRunner in project Payara by payara.

the class PayaraServerNameGenerator method getClusterNames.

private static List<String> getClusterNames(ActionReport report, AdminCommandContext context, CommandRunner commandRunner) {
    List<String> clusterNames = new ArrayList<>();
    CommandRunner.CommandInvocation listClustersCommand = commandRunner.getCommandInvocation("list-clusters", report, context.getSubject());
    listClustersCommand.execute();
    Properties extraProperties = listClustersCommand.report().getExtraProperties();
    if (extraProperties != null) {
        clusterNames.addAll((Set<String>) extraProperties.get("clusterNames"));
    }
    return clusterNames;
}
Also used : ArrayList(java.util.ArrayList) Properties(java.util.Properties) CommandRunner(org.glassfish.api.admin.CommandRunner)

Example 25 with CommandRunner

use of org.glassfish.api.admin.CommandRunner in project Payara by payara.

the class PayaraServerNameGenerator method getInstanceNames.

private static List<String> getInstanceNames(ActionReport report, AdminCommandContext context, CommandRunner commandRunner) {
    List<String> instanceNames = new ArrayList<>();
    CommandRunner.CommandInvocation listInstancesCommand = commandRunner.getCommandInvocation("list-instances", report, context.getSubject());
    ParameterMap commandParameters = new ParameterMap();
    commandParameters.add("nostatus", "true");
    listInstancesCommand.parameters(commandParameters);
    listInstancesCommand.execute();
    Properties extraProperties = listInstancesCommand.report().getExtraProperties();
    if (extraProperties != null) {
        List<Map<String, String>> instanceList = (List<Map<String, String>>) extraProperties.get("instanceList");
        for (Map<String, String> instanceMap : instanceList) {
            instanceNames.add(instanceMap.get("name"));
        }
    }
    return instanceNames;
}
Also used : ArrayList(java.util.ArrayList) ParameterMap(org.glassfish.api.admin.ParameterMap) ArrayList(java.util.ArrayList) List(java.util.List) Properties(java.util.Properties) CommandRunner(org.glassfish.api.admin.CommandRunner) ParameterMap(org.glassfish.api.admin.ParameterMap) Map(java.util.Map)

Aggregations

CommandRunner (org.glassfish.api.admin.CommandRunner)26 ParameterMap (org.glassfish.api.admin.ParameterMap)14 ActionReport (org.glassfish.api.ActionReport)12 ArrayList (java.util.ArrayList)8 Properties (java.util.Properties)5 RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)4 IOException (java.io.IOException)3 RemoteRestAdminCommand (com.sun.enterprise.admin.remote.RemoteRestAdminCommand)2 Server (com.sun.enterprise.config.serverbeans.Server)2 File (java.io.File)2 AdminCommand (org.glassfish.api.admin.AdminCommand)2 CommandException (org.glassfish.api.admin.CommandException)2 CommandModel (org.glassfish.api.admin.CommandModel)2 CommandInvocation (org.glassfish.api.admin.CommandRunner.CommandInvocation)2 InternalSystemAdministrator (org.glassfish.internal.api.InternalSystemAdministrator)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 ServerRemoteRestAdminCommand (com.sun.enterprise.admin.remote.ServerRemoteRestAdminCommand)1 DoNothingActionReporter (com.sun.enterprise.admin.report.DoNothingActionReporter)1 PlainTextActionReporter (com.sun.enterprise.admin.report.PlainTextActionReporter)1 Application (com.sun.enterprise.config.serverbeans.Application)1