use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class SetPayaraExecutorServiceConfigurationCommand method execute.
@Override
public void execute(AdminCommandContext acc) {
Config configVal = targetUtil.getConfig(target);
PayaraExecutorServiceConfiguration payaraExecutorServiceConfiguration = configVal.getExtensionByType(PayaraExecutorServiceConfiguration.class);
if (payaraExecutorServiceConfiguration != null) {
try {
ConfigSupport.apply((PayaraExecutorServiceConfiguration config) -> {
if (threadPoolExecutorCorePoolSize != null) {
config.setThreadPoolExecutorCorePoolSize(threadPoolExecutorCorePoolSize);
}
if (threadPoolExecutorMaxPoolSize != null) {
config.setThreadPoolExecutorMaxPoolSize(threadPoolExecutorMaxPoolSize);
}
if (threadPoolExecutorKeepAliveTime != null) {
config.setThreadPoolExecutorKeepAliveTime(threadPoolExecutorKeepAliveTime);
}
if (threadPoolExecutorKeepAliveTimeUnit != null) {
config.setThreadPoolExecutorKeepAliveTimeUnit(threadPoolExecutorKeepAliveTimeUnit.toUpperCase());
}
if (threadPoolExecutorQueueSize != null) {
config.setThreadPoolExecutorQueueSize(threadPoolExecutorQueueSize);
}
if (scheduledThreadPoolExecutorCorePoolSize != null) {
config.setScheduledThreadPoolExecutorCorePoolSize(scheduledThreadPoolExecutorCorePoolSize);
}
return null;
}, payaraExecutorServiceConfiguration);
} catch (TransactionFailure ex) {
acc.getActionReport().failure(Logger.getLogger(SetPayaraExecutorServiceConfigurationCommand.class.getName()), "Failed to set executor service configuration", ex);
}
}
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class SetExampleServiceMessage method execute.
@Override
public void execute(AdminCommandContext context) {
// obtain the correct configuration
Config configVal = targetUtil.getConfig(target);
ExampleServiceConfiguration serviceConfig = configVal.getExtensionByType(ExampleServiceConfiguration.class);
if (serviceConfig != null) {
try {
// to perform a transaction on the domain.xml you need to use this construct
// see https://github.com/hk2-project/hk2/blob/master/hk2-configuration/persistence/hk2-xml-dom/hk2-config/src/main/java/org/jvnet/hk2/config/ConfigSupport.java
ConfigSupport.apply(new SingleConfigCode<ExampleServiceConfiguration>() {
@Override
public Object run(ExampleServiceConfiguration config) {
config.setMessage(message);
return null;
}
}, serviceConfig);
} catch (TransactionFailure ex) {
// set failure
context.getActionReport().failure(Logger.getLogger(SetExampleServiceMessage.class.getName()), "Failed to update message", ex);
}
}
// was targetted explicitly via the following code
if (server.isDas()) {
// you would need to do this if you now want to manipulate the service based on the command parameters
if (targetUtil.getConfig(target).isDas()) {
// this command was also targetted at the DAS
service.doSomethingDirectly("Set message command was targetted at the DAS");
// as below you can now directly manipulate the service as needed
}
} else {
// if you are not the DAS then impoicitly this command was targeted to this instance
service.doSomethingDirectly("Set config command targeted at the instance");
// you can now directly manipulate the service remember though
// if it is a config listener it has already been notified of the config change
// however if it is not a config listener you can manipulate the service now
}
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class CreateSecurityService method execute.
/**
* Execute the create-security-service admin command.
*/
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
// Setup the service type and configuration handler
if (AUTHENTICATION.equalsIgnoreCase(serviceType)) {
clazzServiceType = AuthenticationService.class;
serviceConfigHandler = new AuthenticationConfigHandler();
} else {
report.setMessage("Invalid security service type specified: " + serviceType);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// Add service configuration to the security configurations
// TODO - Add validation logic required for base service configuration
SecurityConfiguration config = null;
try {
config = (SecurityConfiguration) ConfigSupport.apply(new SingleConfigCode<SecurityConfigurations>() {
@Override
public Object run(SecurityConfigurations param) throws PropertyVetoException, TransactionFailure {
SecurityConfiguration svcConfig = param.createChild(clazzServiceType);
svcConfig.setName(serviceName);
svcConfig.setDefault(enableDefault.toString());
param.getSecurityServices().add(svcConfig);
return svcConfig;
}
}, secConfigs);
} catch (TransactionFailure transactionFailure) {
report.setMessage("Unable to create security service: " + transactionFailure.getMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(transactionFailure);
return;
}
// TODO - Add validation logic required for specific service configuration
if ((config != null) && (configuration != null) && (!configuration.isEmpty())) {
serviceConfigHandler.setupConfiguration(report, config);
}
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class SecurityConfigUpgradeService method postConstruct.
@Override
public void postConstruct() {
if (domain.getExtensionByType(SecurityConfigurations.class) != null) {
/*
* The domain already contains a security-configurations setting,
* so for now that's sufficient to conclude we don't need to upgrade.
*/
logger.log(Level.INFO, "SecurityConfigUpgradeService bypassing - security-configurations already present");
return;
}
Transaction t = null;
try {
t = new Transaction();
final Domain domain_w = t.enroll(domain);
/*
* Create the security configurations element and add it to the domain.
*/
final SecurityConfigurations sc_w = domain_w.createChild(SecurityConfigurations.class);
domain_w.getExtensions().add(sc_w);
/*
* Create and add the authentication service.
*/
final AuthenticationService as_w = addAuthenticationService(sc_w);
/*
* Next, add the two providers and their children.
*/
addAdmRealmProvider(as_w);
addFileRealmProvider(as_w);
/**
* Next add the authorization service
*/
final AuthorizationService authorizationService = addAuthorizationService(sc_w);
/**
* Next add the authorization service provider
*/
addSimpleAuthorizationProvider(authorizationService);
t.commit();
logger.log(Level.INFO, "SecurityConfigUpgradeService successfully completed the upgrade");
} catch (Exception ex) {
if (t != null) {
t.rollback();
}
logger.log(Level.SEVERE, null, ex);
}
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class StuckThreadsConfigurer method execute.
@Override
public void execute(AdminCommandContext context) {
Config config = targetUtil.getConfig(target);
StuckThreadsHealthCheck service = habitat.getService(StuckThreadsHealthCheck.class);
final ActionReport actionReport = context.getActionReport();
if (service == null) {
actionReport.appendMessage(strings.getLocalString("healthcheck.stuckthreads.configure.status.error", "Stuck Threads Checker Service could not be found"));
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
HealthCheckServiceConfiguration healthCheckServiceConfiguration = config.getExtensionByType(HealthCheckServiceConfiguration.class);
StuckThreadsChecker stuckThreadConfiguration = healthCheckServiceConfiguration.getCheckerByType(StuckThreadsChecker.class);
if (stuckThreadConfiguration == null) {
ConfigSupport.apply(new SingleConfigCode<HealthCheckServiceConfiguration>() {
@Override
public Object run(final HealthCheckServiceConfiguration healthCheckServiceConfigurationProxy) throws PropertyVetoException, TransactionFailure {
StuckThreadsChecker checkerProxy = healthCheckServiceConfigurationProxy.createChild(StuckThreadsChecker.class);
applyValues(checkerProxy);
healthCheckServiceConfigurationProxy.getCheckerList().add(checkerProxy);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return healthCheckServiceConfigurationProxy;
}
}, healthCheckServiceConfiguration);
} else {
ConfigSupport.apply(new SingleConfigCode<StuckThreadsChecker>() {
@Override
public Object run(final StuckThreadsChecker hoggingThreadConfigurationProxy) throws PropertyVetoException, TransactionFailure {
applyValues(hoggingThreadConfigurationProxy);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return hoggingThreadConfigurationProxy;
}
}, stuckThreadConfiguration);
}
if (dynamic) {
if (server.isDas()) {
if (targetUtil.getConfig(target).isDas()) {
StuckThreadsChecker checkerByType = healthCheckServiceConfiguration.getCheckerByType(StuckThreadsChecker.class);
service.setOptions(service.constructOptions(checkerByType));
healthCheckService.registerCheck(checkerByType.getName(), service);
healthCheckService.reboot();
}
} else {
// it implicitly targetted to us as we are not the DAS
// restart the service
StuckThreadsChecker checkerByType = healthCheckServiceConfiguration.getCheckerByType(StuckThreadsChecker.class);
service.setOptions(service.constructOptions(stuckThreadConfiguration));
healthCheckService.registerCheck(checkerByType.getName(), service);
healthCheckService.reboot();
}
}
} catch (TransactionFailure ex) {
logger.log(Level.WARNING, "Exception during command ", ex);
actionReport.setMessage(ex.getCause().getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
Aggregations