use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class SetNetworkListenerConfiguration method shutdownChange.
private void shutdownChange() {
List<UnprocessedChangeEvent> processed = new ArrayList<>();
for (UnprocessedChangeEvents unchangedEvents : ucl.getUnprocessedChangeEvents()) {
for (UnprocessedChangeEvent unprocessedEvent : unchangedEvents.getUnprocessed()) {
PropertyChangeEvent event = unprocessedEvent.getEvent();
if (event.getSource().getClass().equals(this.getClass()) && event.getPropertyName().equals("port")) {
SetNetworkListenerConfiguration oldConfig = (SetNetworkListenerConfiguration) event.getSource();
NetworkListeners listeners = oldConfig.confign.getNetworkListeners();
for (NetworkListener listener : listeners.getNetworkListener()) {
if (listener.getName().equals(oldConfig.listenerName)) {
try {
ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {
@Override
public Object run(final NetworkListener listenerProxy) throws PropertyVetoException, TransactionFailure {
listenerProxy.setPort((event.getNewValue().toString()));
return null;
}
}, listener);
} catch (TransactionFailure ex) {
Logger.getLogger(SetNetworkListenerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
} finally {
processed.add(unprocessedEvent);
}
}
}
}
}
}
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class CreateHttpRedirect method execute.
// ----------------------------------------------- Methods from AdminCommand
@Override
public void execute(AdminCommandContext context) {
Target targetUtil = services.getService(Target.class);
Config newConfig = targetUtil.getConfig(target);
if (newConfig != null) {
config = newConfig;
}
final ActionReport report = context.getActionReport();
// check for duplicates
Protocols protocols = config.getNetworkConfig().getProtocols();
Protocol protocol = null;
for (Protocol p : protocols.getProtocol()) {
if (protocolName.equals(p.getName())) {
protocol = p;
}
}
if (protocol == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND), protocolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (protocol.getHttpRedirect() != null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_REDIRECT_FAIL_DUPLICATE), protocolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<Protocol>() {
public Object run(Protocol param) throws TransactionFailure {
HttpRedirect httpRedirect = param.createChild(HttpRedirect.class);
httpRedirect.setPort(port);
httpRedirect.setSecure(secure);
param.setHttpRedirect(httpRedirect);
return httpRedirect;
}
}, protocol);
} catch (TransactionFailure e) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_REDIRECT_FAIL), protocolName) + (e.getMessage() == null ? "No reason given." : e.getMessage()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class SetRequestTracingConfiguration 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 RequestTracingServiceConfiguration requestTracingServiceConfiguration = config.getExtensionByType(RequestTracingServiceConfiguration.class);
if (requestTracingServiceConfiguration != null) {
final Set<String> notifierNames = NotifierUtils.getNotifierNames(serviceLocator);
try {
ConfigSupport.apply(new SingleConfigCode<RequestTracingServiceConfiguration>() {
@Override
public Object run(final RequestTracingServiceConfiguration proxy) throws PropertyVetoException, TransactionFailure {
boolean warn = false;
if (enabled != null) {
proxy.enabled(enabled.toString());
}
if (sampleRate != null) {
proxy.setSampleRate(sampleRate);
}
if (adaptiveSamplingEnabled != null) {
proxy.setAdaptiveSamplingEnabled(adaptiveSamplingEnabled.toString());
}
if (adaptiveSamplingTargetCount != null) {
proxy.setAdaptiveSamplingTargetCount(adaptiveSamplingTargetCount);
}
if (adaptiveSamplingTimeValue != null) {
proxy.setAdaptiveSamplingTimeValue(adaptiveSamplingTimeValue.toString());
}
if (adaptiveSamplingTimeUnit != null) {
proxy.setAdaptiveSamplingTimeUnit(adaptiveSamplingTimeUnit);
}
if (applicationsOnlyEnabled != null) {
proxy.setApplicationsOnlyEnabled(applicationsOnlyEnabled.toString());
}
if (thresholdValue != null) {
proxy.setThresholdValue(thresholdValue);
}
if (thresholdUnit != null) {
proxy.setThresholdUnit(thresholdUnit);
}
if (sampleRateFirstEnabled != null) {
proxy.setSampleRateFirstEnabled(sampleRateFirstEnabled.toString());
}
if (traceStoreSize != null) {
warn = !traceStoreSize.toString().equals(proxy.getTraceStoreSize());
proxy.setTraceStoreSize(traceStoreSize.toString());
}
if (traceStoreTimeout != null) {
warn = !traceStoreTimeout.equals(proxy.getTraceStoreTimeout());
proxy.setTraceStoreTimeout(traceStoreTimeout);
}
if (reservoirSamplingEnabled != null) {
proxy.setReservoirSamplingEnabled(reservoirSamplingEnabled.toString());
}
if (historicTraceStoreEnabled != null) {
proxy.setHistoricTraceStoreEnabled(historicTraceStoreEnabled.toString());
}
if (historicTraceStoreSize != null) {
warn = !historicTraceStoreSize.toString().equals(proxy.getHistoricTraceStoreSize());
proxy.setHistoricTraceStoreSize(historicTraceStoreSize.toString());
}
if (historicTraceStoreTimeout != null) {
warn = !historicTraceStoreTimeout.equals(proxy.getHistoricTraceStoreTimeout());
proxy.setHistoricTraceStoreTimeout(historicTraceStoreTimeout);
}
List<String> notifiers = proxy.getNotifierList();
if (enableNotifiers != null) {
for (String notifier : enableNotifiers) {
if (notifierNames.contains(notifier)) {
if (!notifiers.contains(notifier)) {
notifiers.add(notifier);
}
} else {
throw new PropertyVetoException("Unrecognised notifier " + notifier, new PropertyChangeEvent(proxy, "notifiers", notifiers, notifiers));
}
}
}
if (disableNotifiers != null) {
for (String notifier : disableNotifiers) {
if (notifierNames.contains(notifier)) {
notifiers.remove(notifier);
} else {
throw new PropertyVetoException("Unrecognised notifier " + notifier, new PropertyChangeEvent(proxy, "notifiers", notifiers, notifiers));
}
}
}
if (setNotifiers != null) {
notifiers.clear();
for (String notifier : setNotifiers) {
if (notifierNames.contains(notifier)) {
if (!notifiers.contains(notifier)) {
notifiers.add(notifier);
}
} else {
throw new PropertyVetoException("Unrecognised notifier " + notifier, new PropertyChangeEvent(proxy, "notifiers", notifiers, notifiers));
}
}
}
actionReport.setActionExitCode(ExitCode.SUCCESS);
if (warn) {
actionReport.setMessage(STRINGS.get("requesttracing.configure.store.size.warning"));
}
return proxy;
}
}, requestTracingServiceConfiguration);
} catch (TransactionFailure ex) {
actionReport.failure(logger, ex.getCause().getMessage());
return;
}
}
if (dynamic) {
if (server.isDas()) {
if (targetUtil.getConfig(target).isDas()) {
configureDynamically(actionReport);
}
} else {
configureDynamically(actionReport);
}
}
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class HealthCheckConfigurer 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 HealthCheckServiceConfiguration healthCheckServiceConfiguration = config.getExtensionByType(HealthCheckServiceConfiguration.class);
if (healthCheckServiceConfiguration != null) {
try {
final Set<String> notifierNames = NotifierUtils.getNotifierNames(serviceLocator);
ConfigSupport.apply(new SingleConfigCode<HealthCheckServiceConfiguration>() {
@Override
public Object run(final HealthCheckServiceConfiguration proxy) throws PropertyVetoException, TransactionFailure {
if (enabled != null) {
proxy.enabled(enabled.toString());
}
if (historicalTraceEnabled != null) {
proxy.setHistoricalTraceEnabled(historicalTraceEnabled.toString());
}
if (historicalTraceStoreSize != null) {
proxy.setHistoricalTraceStoreSize(historicalTraceStoreSize.toString());
}
if (historicalTraceStoreTimeout != null) {
proxy.setHistoricalTraceStoreTimeout(historicalTraceStoreTimeout.toString());
}
List<String> notifiers = proxy.getNotifierList();
if (enableNotifiers != null) {
for (String notifier : enableNotifiers) {
if (notifierNames.contains(notifier)) {
notifiers.add(notifier);
} else {
throw new PropertyVetoException("Unrecognised notifier " + notifier, new PropertyChangeEvent(proxy, "notifiers", notifiers, notifiers));
}
}
}
if (disableNotifiers != null) {
for (String notifier : disableNotifiers) {
if (notifierNames.contains(notifier)) {
notifiers.remove(notifier);
} else {
throw new PropertyVetoException("Unrecognised notifier " + notifier, new PropertyChangeEvent(proxy, "notifiers", notifiers, notifiers));
}
}
}
if (setNotifiers != null) {
notifiers.clear();
for (String notifier : setNotifiers) {
if (notifierNames.contains(notifier)) {
if (!notifiers.contains(notifier)) {
notifiers.add(notifier);
}
} else {
throw new PropertyVetoException("Unrecognised notifier " + notifier, new PropertyChangeEvent(proxy, "notifiers", notifiers, notifiers));
}
}
}
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return proxy;
}
}, healthCheckServiceConfiguration);
} catch (TransactionFailure ex) {
logger.log(Level.WARNING, "Exception during command ", ex);
actionReport.setMessage(ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
if (dynamic) {
if (server.isDas()) {
if (targetUtil.getConfig(target).isDas()) {
configureDynamically();
}
} else {
// apply as not the DAS so implicitly it is for us
configureDynamically();
}
}
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class ServerConfigSource method setValue.
public boolean setValue(final String propertyName, final String propertyValue) throws TransactionFailure {
boolean result = false;
Server config = domainConfiguration.getServerNamed(configurationName);
if (config != null) {
Property p = config.getProperty(PROPERTY_PREFIX + propertyName);
if (p == null) {
ConfigSupport.apply(new SingleConfigCode<Server>() {
@Override
public Object run(Server configuration) throws TransactionFailure, PropertyVetoException {
Property prop = configuration.createChild(Property.class);
prop.setName(PROPERTY_PREFIX + propertyName);
prop.setValue(propertyValue);
configuration.getProperty().add(prop);
return null;
}
}, config);
} else {
ConfigSupport.apply(new SingleConfigCode<Property>() {
@Override
public Object run(Property config) throws TransactionFailure, PropertyVetoException {
config.setValue(propertyValue);
return null;
}
}, p);
}
result = true;
}
return result;
}
Aggregations