Search in sources :

Example 16 with Module

use of com.sun.enterprise.config.serverbeans.Module in project Payara by payara.

the class FlushInstancesConnectionPool method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    Resources resources = domain.getResources();
    String scope = "";
    if (moduleName != null) {
        if (!poolUtil.isValidModule(applicationName, moduleName, poolName, report)) {
            report.setMessage("Modulename is not that of a valid module: " + moduleName);
            report.setActionExitCode(ActionReport.ExitCode.WARNING);
            return;
        }
        Application application = applications.getApplication(applicationName);
        Module module = application.getModule(moduleName);
        resources = module.getResources();
        scope = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX;
    } else if (applicationName != null) {
        if (!poolUtil.isValidApplication(applicationName, poolName, report)) {
            report.setMessage("ApplicationName is not that of a valid module: " + applicationName);
            report.setActionExitCode(ActionReport.ExitCode.WARNING);
            return;
        }
        Application application = applications.getApplication(applicationName);
        resources = application.getResources();
        scope = ConnectorConstants.JAVA_APP_SCOPE_PREFIX;
    }
    if (!poolUtil.isValidPool(resources, poolName, scope, report)) {
        report.setMessage("Connection Pool is not valid");
        report.setActionExitCode(ActionReport.ExitCode.WARNING);
        return;
    }
    List<Future> instanceFlushes = new ArrayList<>();
    for (Server server : domain.getServers().getServer()) {
        instanceFlushes.add(executor.submit(new Runnable() {

            @Override
            public void run() {
                ActionReport subReport = report.addSubActionsReport();
                try {
                    if (!server.isRunning()) {
                        // skip servers that are stopped
                        return;
                    }
                    String host = server.getAdminHost();
                    int port = server.getAdminPort();
                    ParameterMap map = new ParameterMap();
                    map.add("poolName", poolName);
                    if (applicationName != null) {
                        map.add("appname", applicationName);
                    }
                    if (moduleName != null) {
                        map.add("modulename", moduleName);
                    }
                    if (server.isDas()) {
                        CommandRunner runner = habitat.getService(CommandRunner.class);
                        CommandRunner.CommandInvocation invocation = runner.getCommandInvocation("_flush-connection-pool", subReport, context.getSubject());
                        invocation.parameters(map);
                        invocation.execute();
                    } else {
                        RemoteRestAdminCommand rac = new ServerRemoteRestAdminCommand(habitat, "_flush-connection-pool", host, port, false, "admin", null, LOGGER);
                        rac.executeCommand(map);
                        ActionReport result = rac.getActionReport();
                        subReport.setActionExitCode(result.getActionExitCode());
                        subReport.setMessage(result.getMessage());
                    }
                } catch (CommandException ex) {
                    subReport.failure(Logger.getLogger("CONNECTORS-ADMIN"), ex.getLocalizedMessage(), ex);
                    subReport.appendMessage(server.getName());
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                }
            }
        }));
    }
    for (Future future : instanceFlushes) {
        try {
            future.get();
        } catch (InterruptedException | ExecutionException ex) {
            LOGGER.log(Level.SEVERE, null, ex);
        }
    }
    if (report.hasFailures()) {
        report.setActionExitCode(ActionReport.ExitCode.WARNING);
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) ArrayList(java.util.ArrayList) ParameterMap(org.glassfish.api.admin.ParameterMap) CommandException(org.glassfish.api.admin.CommandException) ActionReport(org.glassfish.api.ActionReport) RestEndpoint(org.glassfish.api.admin.RestEndpoint) Future(java.util.concurrent.Future) Resources(com.sun.enterprise.config.serverbeans.Resources) Module(com.sun.enterprise.config.serverbeans.Module) ExecutionException(java.util.concurrent.ExecutionException) Application(com.sun.enterprise.config.serverbeans.Application) CommandRunner(org.glassfish.api.admin.CommandRunner) RemoteRestAdminCommand(com.sun.enterprise.admin.remote.RemoteRestAdminCommand) ServerRemoteRestAdminCommand(com.sun.enterprise.admin.remote.ServerRemoteRestAdminCommand) ServerRemoteRestAdminCommand(com.sun.enterprise.admin.remote.ServerRemoteRestAdminCommand)

Example 17 with Module

use of com.sun.enterprise.config.serverbeans.Module in project Payara by payara.

the class CreateConnectorWorkSecurityMap method execute.

// TODO common code replicated in ConnectorWorkSecurityMapManager
/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    if (mapName == null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.noMapName", "No mapname defined for connector work security map."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (raName == null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.noRaName", "No raname defined for connector work security map."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (principalsMap == null && groupsMap == null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.noMap", "No principalsmap or groupsmap defined for connector work security map."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (principalsMap != null && groupsMap != null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.specifyPrincipalsOrGroupsMap", "A work-security-map can have either (any number of) group mapping  " + "or (any number of) principals mapping but not both. Specify" + "--principalsmap or --groupsmap."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // ensure we don't already have one of this name
    if (hasDuplicate(domain.getResources(), report))
        return;
    // TODO ASR : need similar validation while creating app-scoped-resource of w-s-m
    String appName = raName;
    if (!ConnectorsUtil.isStandAloneRA(raName)) {
        appName = ConnectorsUtil.getApplicationNameOfEmbeddedRar(raName);
        Application application = applications.getApplication(appName);
        if (application != null) {
            // embedded RAR
            String resourceAdapterName = ConnectorsUtil.getRarNameFromApplication(raName);
            Module module = application.getModule(resourceAdapterName);
            if (module != null) {
                Resources msr = module.getResources();
                if (msr != null) {
                    if (hasDuplicate(msr, report))
                        return;
                }
            }
        }
    } else {
        // standalone RAR
        Application application = applications.getApplication(appName);
        if (application != null) {
            Resources appScopedResources = application.getResources();
            if (appScopedResources != null) {
                if (hasDuplicate(appScopedResources, report))
                    return;
            }
        }
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                WorkSecurityMap workSecurityMap = param.createChild(WorkSecurityMap.class);
                workSecurityMap.setName(mapName);
                workSecurityMap.setResourceAdapterName(raName);
                if (principalsMap != null) {
                    for (Map.Entry e : principalsMap.entrySet()) {
                        PrincipalMap principalMap = workSecurityMap.createChild(PrincipalMap.class);
                        principalMap.setEisPrincipal((String) e.getKey());
                        principalMap.setMappedPrincipal((String) e.getValue());
                        workSecurityMap.getPrincipalMap().add(principalMap);
                    }
                } else if (groupsMap != null) {
                    for (Map.Entry e : groupsMap.entrySet()) {
                        GroupMap groupMap = workSecurityMap.createChild(GroupMap.class);
                        groupMap.setEisGroup((String) e.getKey());
                        groupMap.setMappedGroup((String) e.getValue());
                        workSecurityMap.getGroupMap().add(groupMap);
                    }
                } else {
                // no mapping
                }
                param.getResources().add(workSecurityMap);
                return workSecurityMap;
            }
        }, domain.getResources());
    } catch (TransactionFailure tfe) {
        Logger.getLogger(CreateConnectorWorkSecurityMap.class.getName()).log(Level.SEVERE, "create-connector-work-security-map failed", tfe);
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.fail", "Unable to create connector work security map {0}.", mapName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PrincipalMap(org.glassfish.connectors.config.PrincipalMap) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) ActionReport(org.glassfish.api.ActionReport) PropertyVetoException(java.beans.PropertyVetoException) GroupMap(org.glassfish.connectors.config.GroupMap) Module(com.sun.enterprise.config.serverbeans.Module) Map(java.util.Map) PrincipalMap(org.glassfish.connectors.config.PrincipalMap) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) GroupMap(org.glassfish.connectors.config.GroupMap)

Example 18 with Module

use of com.sun.enterprise.config.serverbeans.Module in project Payara by payara.

the class AppSpecificConnectorClassLoaderUtil method getModuleScopedResource.

private <T> Resource getModuleScopedResource(String name, String moduleName, Class<T> type, ApplicationInfo appInfo) {
    Resource foundRes = null;
    if (appInfo != null) {
        com.sun.enterprise.config.serverbeans.Application app = appInfo.getTransientAppMetaData(com.sun.enterprise.config.serverbeans.ServerTags.APPLICATION, com.sun.enterprise.config.serverbeans.Application.class);
        Resources resources = null;
        if (app != null) {
            Module module = null;
            List<Module> modules = app.getModule();
            for (Module m : modules) {
                if (ConnectorsUtil.getActualModuleName(m.getName()).equals(moduleName)) {
                    module = m;
                    break;
                }
            }
            if (module != null) {
                resources = appInfo.getTransientAppMetaData(module.getName() + "-resources", Resources.class);
            }
        }
        if (resources != null) {
            boolean bindableResource = BindableResource.class.isAssignableFrom(type);
            boolean poolResource = ResourcePool.class.isAssignableFrom(type);
            boolean workSecurityMap = WorkSecurityMap.class.isAssignableFrom(type);
            boolean rac = ResourceAdapterConfig.class.isAssignableFrom(type);
            Iterator itr = resources.getResources().iterator();
            while (itr.hasNext()) {
                String resourceName = null;
                Resource res = (Resource) itr.next();
                if (bindableResource && res instanceof BindableResource) {
                    resourceName = ((BindableResource) res).getJndiName();
                } else if (poolResource && res instanceof ResourcePool) {
                    resourceName = ((ResourcePool) res).getName();
                } else if (rac && res instanceof ResourceAdapterConfig) {
                    resourceName = ((ResourceAdapterConfig) res).getName();
                } else if (workSecurityMap && res instanceof WorkSecurityMap) {
                    resourceName = ((WorkSecurityMap) res).getName();
                }
                if (resourceName != null) {
                    if (!(resourceName.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX))) {
                        resourceName = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX + resourceName;
                    }
                    if (!(name.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX))) {
                        name = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX + name;
                    }
                    if (name.equals(resourceName)) {
                        foundRes = res;
                        break;
                    }
                }
            }
        }
    }
    return foundRes;
}
Also used : AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) Resource(com.sun.enterprise.config.serverbeans.Resource) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) ResourceAdapterConfig(org.glassfish.connectors.config.ResourceAdapterConfig) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) Iterator(java.util.Iterator) Resources(com.sun.enterprise.config.serverbeans.Resources) Module(com.sun.enterprise.config.serverbeans.Module)

Example 19 with Module

use of com.sun.enterprise.config.serverbeans.Module in project Payara by payara.

the class ListResources method isValidModule.

private boolean isValidModule(String appName, String moduleName) {
    Application app = applications.getApplication(appName);
    Module module = app.getModule(moduleName);
    return module != null;
}
Also used : Module(com.sun.enterprise.config.serverbeans.Module)

Example 20 with Module

use of com.sun.enterprise.config.serverbeans.Module in project Payara by payara.

the class PingConnectionPool method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    boolean status = false;
    Resources resources = domain.getResources();
    String scope = "";
    if (moduleName != null) {
        if (!poolUtil.isValidModule(applicationName, moduleName, poolName, report)) {
            return;
        }
        Application application = applications.getApplication(applicationName);
        Module module = application.getModule(moduleName);
        resources = module.getResources();
        scope = "java:module/";
    } else if (applicationName != null) {
        if (!poolUtil.isValidApplication(applicationName, poolName, report)) {
            return;
        }
        Application application = applications.getApplication(applicationName);
        resources = application.getResources();
        scope = "java:app/";
    }
    if (!poolUtil.isValidPool(resources, poolName, scope, report)) {
        return;
    }
    PoolInfo poolInfo = new PoolInfo(poolName, applicationName, moduleName);
    try {
        status = connRuntime.pingConnectionPool(poolInfo);
        if (status) {
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        } else {
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(localStrings.getLocalString("ping.connection.pool.fail", "Ping Connection Pool for {0} Failed", poolInfo));
        }
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("ping.connection.pool.fail", "Ping Connection Pool for {0} Failed", poolInfo));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ActionReport(org.glassfish.api.ActionReport) Module(com.sun.enterprise.config.serverbeans.Module)

Aggregations

Module (com.sun.enterprise.config.serverbeans.Module)42 Application (com.sun.enterprise.config.serverbeans.Application)11 ActionReport (org.glassfish.api.ActionReport)9 PropertyVetoException (java.beans.PropertyVetoException)5 Engine (com.sun.enterprise.config.serverbeans.Engine)3 Resource (com.sun.enterprise.config.serverbeans.Resource)3 Resources (com.sun.enterprise.config.serverbeans.Resources)3 ArrayList (java.util.ArrayList)3 Property (org.jvnet.hk2.config.types.Property)3 Server (com.sun.enterprise.config.serverbeans.Server)2 ConnectorApplication (com.sun.enterprise.connectors.module.ConnectorApplication)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)2 WorkSecurityMap (org.glassfish.connectors.config.WorkSecurityMap)2 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)2 Resource (org.glassfish.resources.api.Resource)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 RemoteRestAdminCommand (com.sun.enterprise.admin.remote.RemoteRestAdminCommand)1 ServerRemoteRestAdminCommand (com.sun.enterprise.admin.remote.ServerRemoteRestAdminCommand)1