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);
}
}
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);
}
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;
}
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;
}
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);
}
}
Aggregations