use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class WebSslConfigHandler method create.
@Override
public void create(final CreateSsl command, ActionReport report) {
NetworkConfig netConfig = command.config.getNetworkConfig();
// ensure we have the specified listener
NetworkListener listener = netConfig.getNetworkListener(command.listenerId);
Protocol httpProtocol;
try {
if (listener == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_SSL_HTTP_NOT_FOUND), command.listenerId));
httpProtocol = command.findOrCreateProtocol(command.listenerId);
} else {
httpProtocol = listener.findHttpProtocol();
Ssl ssl = httpProtocol.getSsl();
if (ssl != null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_SSL_HTTP_ALREADY_EXISTS), command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
ConfigSupport.apply(new SingleConfigCode<Protocol>() {
public Object run(Protocol param) throws TransactionFailure {
Ssl newSsl = param.createChild(Ssl.class);
command.populateSslElement(newSsl);
param.setSsl(newSsl);
return newSsl;
}
}, httpProtocol);
} catch (TransactionFailure e) {
command.reportError(report, e);
}
command.reportSuccess(report);
}
use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class SetEnvironmentWarningConfigurationCommand method execute.
@Override
public void execute(AdminCommandContext acc) {
Config config = targetUtil.getConfig(target);
ActionReport actionReport = acc.getActionReport();
EnvironmentWarningConfiguration environmentWarningConfiguration = config.getExtensionByType(EnvironmentWarningConfiguration.class);
if (environmentWarningConfiguration != null) {
try {
ConfigSupport.apply(new SingleConfigCode<EnvironmentWarningConfiguration>() {
@Override
public Object run(EnvironmentWarningConfiguration config) throws PropertyVetoException {
if (enabled != null) {
config.setEnabled(enabled);
}
if (message != null) {
config.setMessage(message);
}
if (backgroundColour != null) {
if (backgroundColour.matches("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$")) {
config.setBackgroundColour(backgroundColour);
} else {
throw new PropertyVetoException("Invalid data for background colour, must be a hex value.", new PropertyChangeEvent(config, "backgroundColour", config.getBackgroundColour(), backgroundColour));
}
}
if (textColour != null) {
if (textColour.matches("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$")) {
config.setTextColour(textColour);
} else {
throw new PropertyVetoException("Invalid data for text colour, must be a hex value.", new PropertyChangeEvent(config, "textColour", config.getTextColour(), textColour));
}
}
return null;
}
}, environmentWarningConfiguration);
} catch (TransactionFailure ex) {
// Set failure
actionReport.failure(Logger.getLogger(SetEnvironmentWarningConfigurationCommand.class.getName()), "Failed to update configuration", ex);
}
}
}
use of org.jvnet.hk2.config.TransactionFailure 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.TransactionFailure in project Payara by payara.
the class RestMonitoringLoader method createAndRegisterApplication.
/**
* Create the system application entry and register the application
* @throws Exception
*/
private void createAndRegisterApplication() throws Exception {
LOGGER.log(Level.FINE, "Registering the Rest Monitoring Application...");
// Create the system application entry and application-ref in the config
ConfigCode code = new ConfigCode() {
@Override
public Object run(ConfigBeanProxy... proxies) throws PropertyVetoException, TransactionFailure {
// Create the system application
SystemApplications systemApplications = (SystemApplications) proxies[0];
Application application = systemApplications.createChild(Application.class);
// Check if the application name is valid, generating a new one if it isn't
checkAndResolveApplicationName(systemApplications);
systemApplications.getModules().add(application);
application.setName(applicationName);
application.setEnabled(Boolean.TRUE.toString());
application.setObjectType("system-admin");
application.setDirectoryDeployed("true");
application.setContextRoot(contextRoot);
try {
application.setLocation("${com.sun.aas.installRootURI}/lib/install/applications/" + RestMonitoringService.DEFAULT_REST_MONITORING_APP_NAME);
} catch (Exception me) {
throw new RuntimeException(me);
}
// Set the engine types
Module singleModule = application.createChild(Module.class);
application.getModule().add(singleModule);
singleModule.setName(applicationName);
Engine webEngine = singleModule.createChild(Engine.class);
webEngine.setSniffer("web");
Engine weldEngine = singleModule.createChild(Engine.class);
weldEngine.setSniffer("weld");
Engine securityEngine = singleModule.createChild(Engine.class);
securityEngine.setSniffer("security");
singleModule.getEngines().add(webEngine);
singleModule.getEngines().add(weldEngine);
singleModule.getEngines().add(securityEngine);
// Create the application-ref
Server s = (Server) proxies[1];
List<ApplicationRef> arefs = s.getApplicationRef();
ApplicationRef aref = s.createChild(ApplicationRef.class);
aref.setRef(application.getName());
aref.setEnabled(Boolean.TRUE.toString());
aref.setVirtualServers(getVirtualServerListAsString());
arefs.add(aref);
return true;
}
};
Server server = domain.getServerNamed(serverEnv.getInstanceName());
ConfigSupport.apply(code, domain.getSystemApplications(), server);
LOGGER.log(Level.FINE, "Rest Monitoring Application Registered.");
}
use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class RestMonitoringLoader method registerApplication.
private void registerApplication() throws Exception {
LOGGER.log(Level.FINE, "Registering the Rest Monitoring Application...");
// Create the application-ref entry in the domain.xml
ConfigCode code = new ConfigCode() {
@Override
public Object run(ConfigBeanProxy... proxies) throws PropertyVetoException, TransactionFailure {
// Get the system application config
SystemApplications systemApplications = (SystemApplications) proxies[0];
Application application = null;
for (Application systemApplication : systemApplications.getApplications()) {
if (systemApplication.getName().equals(applicationName)) {
application = systemApplication;
break;
}
}
if (application == null) {
throw new IllegalStateException("The Rest Monitoring application has no system app entry!");
}
// Create the application-ref
Server s = (Server) proxies[1];
List<ApplicationRef> arefs = s.getApplicationRef();
ApplicationRef aref = s.createChild(ApplicationRef.class);
aref.setRef(application.getName());
aref.setEnabled(Boolean.TRUE.toString());
aref.setVirtualServers(getVirtualServerListAsString());
arefs.add(aref);
return true;
}
};
Server server = domain.getServerNamed(serverEnv.getInstanceName());
ConfigSupport.apply(code, domain.getSystemApplications(), server);
// Update the adapter state
LOGGER.log(Level.FINE, "Rest Monitoring Application Registered.");
}
Aggregations