use of org.jvnet.hk2.config in project Payara by payara.
the class GetMonitoringConfiguration method execute.
/**
* Method that is invoked when the asadmin command is performed.
* Pretty prints the Monitoring Service Configuration values.
* @param context
*/
@Override
public void execute(AdminCommandContext context) {
Config config = targetUtil.getConfig(target);
if (config == null) {
context.getActionReport().setMessage("No such config name: " + targetUtil);
context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
ActionReport actionReport = context.getActionReport();
ActionReport notifiersReport = actionReport.addSubActionsReport();
ActionReport attributeReport = actionReport.addSubActionsReport();
ColumnFormatter attributeColumnFormatter = new ColumnFormatter(ATTRIBUTE_HEADERS);
ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(NOTIFIER_HEADERS);
MonitoringServiceConfiguration monitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
List<ServiceHandle<BaseNotifierService>> allNotifierServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class);
actionReport.appendMessage("Monitoring Service Configuration is enabled? " + prettyBool(Boolean.valueOf(monitoringConfig.getEnabled())) + "\n");
actionReport.appendMessage("Monitoring Service Configuration has AMX enabled? " + prettyBool(Boolean.valueOf(monitoringConfig.getAmx())) + "\n");
actionReport.appendMessage("Monitoring Service Configuration log frequency? " + monitoringConfig.getLogFrequency() + " " + monitoringConfig.getLogFrequencyUnit());
actionReport.appendMessage(StringUtils.EOL);
Map<String, Object> map = new HashMap<>();
Properties extraProps = new Properties();
map.put("enabled", monitoringConfig.getEnabled());
map.put("amx", monitoringConfig.getAmx());
map.put("logfrequency", monitoringConfig.getLogFrequency());
map.put("logfrequencyunit", monitoringConfig.getLogFrequencyUnit());
extraProps.put("jmxmonitoringConfiguration", map);
List<Map<String, String>> monitoredAttributes = new ArrayList<>();
for (MonitoredAttribute monitoredBean : monitoringConfig.getMonitoredAttributes()) {
Object[] values = new Object[3];
values[0] = monitoredBean.getObjectName();
values[1] = monitoredBean.getAttributeName();
values[2] = monitoredBean.getDescription();
Map<String, String> monitoredAttribute = new HashMap<>();
monitoredAttribute.put(monitoredBean.getObjectName(), monitoredBean.getAttributeName());
monitoredAttributes.add(monitoredAttribute);
attributeColumnFormatter.addRow(values);
}
// Cannot change key in line below - required for admingui propertyDescTable.inc
extraProps.put("monitored-beans", monitoredAttributes);
actionReport.setExtraProperties(extraProps);
if (!monitoringConfig.getNotifierList().isEmpty()) {
List<Class<Notifier>> notifierClassList = Lists.transform(monitoringConfig.getNotifierList(), new Function<Notifier, Class<Notifier>>() {
@Override
public Class<Notifier> apply(Notifier input) {
return resolveNotifierClass(input);
}
});
Properties notifierProps = new Properties();
for (ServiceHandle<BaseNotifierService> serviceHandle : allNotifierServiceHandles) {
Notifier notifier = monitoringConfig.getNotifierByType(serviceHandle.getService().getNotifierType());
if (notifier != null) {
ConfigView view = ConfigSupport.getImpl(notifier);
NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
if (notifierClassList.contains(view.<Notifier>getProxyType())) {
Object[] values = new Object[2];
values[0] = annotation.type();
values[1] = notifier.getEnabled();
notifiersColumnFormatter.addRow(values);
Map<String, Object> mapNotifiers = new HashMap<>(2);
mapNotifiers.put("notifierName", values[0]);
mapNotifiers.put("notifierEnabled", values[1]);
notifierProps.put("notifierList" + annotation.type(), mapNotifiers);
}
}
actionReport.getExtraProperties().putAll(notifierProps);
}
}
notifiersReport.setMessage(notifiersColumnFormatter.toString());
notifiersReport.appendMessage(StringUtils.EOL);
attributeReport.setMessage(attributeColumnFormatter.toString());
attributeReport.appendMessage(StringUtils.EOL);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.jvnet.hk2.config in project Payara by payara.
the class BaseMonitoringNotifierConfigurer method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport actionReport = context.getActionReport();
Properties extraProperties = actionReport.getExtraProperties();
if (extraProperties == null) {
extraProperties = new Properties();
actionReport.setExtraProperties(extraProperties);
}
Config config = targetUtil.getConfig(target);
final MonitoringServiceConfiguration configuration = config.getExtensionByType(MonitoringServiceConfiguration.class);
ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
notifierClass = (Class<C>) genericSuperclass.getActualTypeArguments()[0];
C c = configuration.getNotifierByType(notifierClass);
try {
if (c == null) {
ConfigSupport.apply(new SingleConfigCode<MonitoringServiceConfiguration>() {
@Override
public Object run(final MonitoringServiceConfiguration configurationProxy) throws PropertyVetoException, TransactionFailure {
C c = configurationProxy.createChild(notifierClass);
applyValues(c);
configurationProxy.getNotifierList().add(c);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return configurationProxy;
}
}, configuration);
} else {
ConfigSupport.apply(new SingleConfigCode<C>() {
@Override
public Object run(C cProxy) throws PropertyVetoException, TransactionFailure {
applyValues(cProxy);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return cProxy;
}
}, c);
}
if (dynamic) {
if (server.isDas()) {
if (targetUtil.getConfig(target).isDas()) {
configureDynamically();
}
} else {
configureDynamically();
}
}
} catch (TransactionFailure ex) {
logger.log(Level.WARNING, "Exception during command ", ex);
actionReport.setMessage(ex.getCause().getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
use of org.jvnet.hk2.config in project Payara by payara.
the class GMSAdapterImpl method readGMSConfigProps.
private void readGMSConfigProps(Properties configProps) {
configProps.put(MEMBERTYPE_STRING, isDas ? SPECTATOR : CORE);
for (ServiceProviderConfigurationKeys key : ServiceProviderConfigurationKeys.values()) {
String keyName = key.toString();
try {
switch(key) {
case MULTICASTADDRESS:
if (cluster != null) {
String value = cluster.getGmsMulticastAddress();
if (value != null) {
configProps.put(keyName, value);
}
}
break;
case MULTICASTPORT:
if (cluster != null) {
String value = cluster.getGmsMulticastPort();
if (value != null) {
configProps.put(keyName, value);
}
}
break;
case FAILURE_DETECTION_TIMEOUT:
if (clusterConfig != null) {
String value = clusterConfig.getGroupManagementService().getFailureDetection().getHeartbeatFrequencyInMillis();
if (value != null) {
configProps.put(keyName, value);
}
}
break;
case FAILURE_DETECTION_RETRIES:
if (clusterConfig != null) {
String value = clusterConfig.getGroupManagementService().getFailureDetection().getMaxMissedHeartbeats();
if (value != null) {
configProps.put(keyName, value);
}
}
break;
case FAILURE_VERIFICATION_TIMEOUT:
if (clusterConfig != null) {
String value = clusterConfig.getGroupManagementService().getFailureDetection().getVerifyFailureWaittimeInMillis();
if (value != null) {
configProps.put(keyName, value);
}
}
break;
case DISCOVERY_TIMEOUT:
if (clusterConfig != null) {
String value = clusterConfig.getGroupManagementService().getGroupDiscoveryTimeoutInMillis();
if (value != null) {
configProps.put(keyName, value);
}
}
break;
case IS_BOOTSTRAPPING_NODE:
configProps.put(keyName, isDas ? Boolean.TRUE.toString() : Boolean.FALSE.toString());
break;
case BIND_INTERFACE_ADDRESS:
if (cluster != null) {
String value = cluster.getGmsBindInterfaceAddress();
if (value != null) {
value = value.trim();
}
if (value != null && value.length() > 1 && value.charAt(0) != '$') {
// Only supported IPv4 address in gf v2.
if (NetworkUtility.isBindAddressValid(value)) {
configProps.put(keyName, value);
} else {
GMS_LOGGER.log(LogLevel.SEVERE, GMS_BIND_INT_ADDRESS_INVALID, value);
}
}
}
break;
case FAILURE_DETECTION_TCP_RETRANSMIT_TIMEOUT:
if (clusterConfig != null) {
String value = clusterConfig.getGroupManagementService().getFailureDetection().getVerifyFailureConnectTimeoutInMillis();
if (value != null) {
configProps.put(keyName, value);
}
}
break;
case MULTICAST_POOLSIZE:
case INCOMING_MESSAGE_QUEUE_SIZE:
// case MAX_MESSAGE_LENGTH: todo uncomment with shoal-gms.jar with this defined is promoted.
case FAILURE_DETECTION_TCP_RETRANSMIT_PORT:
if (clusterConfig != null) {
Property prop = clusterConfig.getGroupManagementService().getProperty(keyName);
if (prop == null) {
if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
GMS_LOGGER.log(LogLevel.FINE, String.format("No config property found for %s", keyName));
}
break;
}
String value = prop.getValue().trim();
if (value != null) {
configProps.put(keyName, value);
}
/*
int positiveint = 0;
try {
positiveint = Integer.getInteger(value);
} catch (Throwable t) {}
// todo
if (positiveint > 0) {
configProps.put(keyName, positiveint);
} // todo else log event that invalid value was provided.
*/
}
break;
// Must place here or they will get flagged as not handled.
case LOOPBACK:
case VIRTUAL_MULTICAST_URI_LIST:
break;
default:
if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
GMS_LOGGER.log(LogLevel.FINE, String.format("service provider key %s ignored", keyName));
}
break;
}
/* end switch over ServiceProviderConfigurationKeys enum */
} catch (Throwable t) {
GMS_LOGGER.log(LogLevel.WARNING, GMS_EXCEPTION_PROCESSING_CONFIG, t.getLocalizedMessage());
}
}
/* end for loop over ServiceProviderConfigurationKeys */
// check for Grizzly transport specific properties in GroupManagementService property list and then cluster property list.
// cluster property is more specific than group-mangement-service, so allow cluster property to override group-management-service proeprty
// if a GrizzlyConfigConstant property is in both list.
List<Property> props = null;
if (clusterConfig != null) {
props = clusterConfig.getGroupManagementService().getProperty();
for (Property prop : props) {
String name = prop.getName().trim();
String value = prop.getValue().trim();
if (name == null || value == null) {
continue;
}
if (GMS_LOGGER.isLoggable(LogLevel.CONFIG)) {
GMS_LOGGER.log(LogLevel.CONFIG, "processing group-management-service property name=" + name + " value= " + value);
}
if (value.startsWith("${")) {
if (GMS_LOGGER.isLoggable(LogLevel.CONFIG)) {
GMS_LOGGER.log(LogLevel.CONFIG, "skipping group-management-service property name=" + name + " since value is unresolved symbolic token=" + value);
}
} else {
if (GMS_LOGGER.isLoggable(LogLevel.CONFIG)) {
GMS_LOGGER.log(LogLevel.CONFIG, "processing group-management-service property name=" + name + " value= " + value);
}
if (name.startsWith(GMS_PROPERTY_PREFIX)) {
name = name.replaceFirst(GMS_PROPERTY_PREFIX_REGEXP, "");
}
configProps.put(name, value);
if (!validateGMSProperty(name)) {
GMS_LOGGER.log(LogLevel.WARNING, GMS_EXCEPTION_IGNORING_PROPERTY, new Object[] { name, value, "" });
}
}
}
}
if (cluster != null) {
props = cluster.getProperty();
for (Property prop : props) {
String name = prop.getName().trim();
String value = prop.getValue().trim();
if (name == null || value == null) {
continue;
}
if (GMS_LOGGER.isLoggable(LogLevel.CONFIG)) {
GMS_LOGGER.log(LogLevel.CONFIG, "processing cluster property name=" + name + " value= " + value);
}
if (value.startsWith("${")) {
if (GMS_LOGGER.isLoggable(LogLevel.CONFIG)) {
GMS_LOGGER.log(LogLevel.CONFIG, "skipping cluster property name=" + name + " since value is unresolved symbolic token=" + value);
}
} else {
if (name.startsWith(GMS_PROPERTY_PREFIX)) {
name = name.replaceFirst(GMS_PROPERTY_PREFIX_REGEXP, "");
}
// impossible to register handlers in a regular app before gms starts up.
if (name.compareTo("ALIVEANDREADY_LOGGING") == 0) {
aliveAndReadyLoggingEnabled = Boolean.parseBoolean(value);
} else if (name.compareTo("LISTENER_PORT") == 0) {
// special case mapping. Glassfish Cluster property GMS_LISTENER_PORT maps to Grizzly Config Constants TCPSTARTPORT and TCPENDPORT.
configProps.put(GrizzlyConfigConstants.TCPSTARTPORT.toString(), value);
configProps.put(GrizzlyConfigConstants.TCPENDPORT.toString(), value);
} else if (name.compareTo("TEST_FAILURE_RECOVERY") == 0) {
testFailureRecoveryHandler = Boolean.parseBoolean(value);
} else if (ServiceProviderConfigurationKeys.DISCOVERY_URI_LIST.name().equals(name) && "generate".equals(value)) {
value = generateDiscoveryUriList();
configProps.put(name, value);
} else {
// handle normal case. one to one mapping.
configProps.put(name, value);
GMS_LOGGER.log(LogLevel.CONFIG, "processing cluster property name=" + name + " value= " + value);
if (!validateGMSProperty(name)) {
GMS_LOGGER.log(LogLevel.WARNING, GMS_EXCEPTION_CLUSTER_PROPERTY_ERROR, new Object[] { name, value, "" });
}
}
}
}
}
}
use of org.jvnet.hk2.config in project Payara by payara.
the class SetMPHealthCheckConfiguration method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport actionReport = context.getActionReport();
Subject subject = context.getSubject();
Config targetConfig = targetUtil.getConfig(target);
MicroprofileHealthCheckConfiguration config = targetConfig.getExtensionByType(MicroprofileHealthCheckConfiguration.class);
if (Boolean.TRUE.equals(securityEnabled) || Boolean.parseBoolean(config.getSecurityEnabled())) {
ActionReport checkUserReport = actionReport.addSubActionsReport();
ActionReport createUserReport = actionReport.addSubActionsReport();
if (!defaultMicroprofileUserExists(checkUserReport, subject) && !checkUserReport.hasFailures()) {
createDefaultMicroprofileUser(createUserReport, subject);
}
if (checkUserReport.hasFailures() || createUserReport.hasFailures()) {
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
try {
ConfigSupport.apply(configProxy -> {
if (enabled != null) {
configProxy.setEnabled(enabled.toString());
}
if (endpoint != null) {
configProxy.setEndpoint(endpoint);
}
if (virtualServers != null) {
configProxy.setVirtualServers(virtualServers);
}
if (securityEnabled != null) {
configProxy.setSecurityEnabled(securityEnabled.toString());
}
if (roles != null) {
configProxy.setRoles(roles);
}
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return configProxy;
}, config);
actionReport.setMessage("Restart server for change to take effect");
} catch (TransactionFailure ex) {
actionReport.failure(LOGGER, "Failed to update HealthCheck configuration", ex);
}
// If everything has passed, scrap the subaction reports as we don't want to print them out
if (!actionReport.hasFailures() && !actionReport.hasWarnings()) {
actionReport.getSubActionsReport().clear();
}
}
use of org.jvnet.hk2.config in project Payara by payara.
the class TransactionServiceConfigListener method postConstruct.
@Override
public void postConstruct() {
// Listen to monitoring level changes
Config c = habitat.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
ts = c.getExtensionByType(TransactionService.class);
ModuleMonitoringLevels mml = c.getMonitoringService().getModuleMonitoringLevels();
((ObservableBean) ConfigSupport.getImpl(mml)).addListener(this);
}
Aggregations