use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class CreateSsl method addSslToJMXConnector.
private void addSslToJMXConnector(Config config, ActionReport report) {
AdminService adminService = config.getAdminService();
// ensure we have the specified listener
JmxConnector jmxConnector = null;
for (JmxConnector jmxConn : adminService.getJmxConnector()) {
if (jmxConn.getName().equals(listenerId)) {
jmxConnector = jmxConn;
}
}
if (jmxConnector == null) {
report.setMessage(localStrings.getLocalString("create.ssl.jmx.notfound", "JMX Connector named {0} to which this ssl element is " + "being added does not exist.", listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (jmxConnector.getSsl() != null) {
report.setMessage(localStrings.getLocalString("create.ssl.jmx.alreadyExists", "IIOP Listener named {0} to which this ssl element is " + "being added already has an ssl element.", listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<JmxConnector>() {
@Override
public Object run(JmxConnector param) throws PropertyVetoException, TransactionFailure {
Ssl newSsl = param.createChild(Ssl.class);
populateSslElement(newSsl);
param.setSsl(newSsl);
return newSsl;
}
}, jmxConnector);
} catch (TransactionFailure e) {
reportError(report, e);
}
reportSuccess(report);
}
use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class DeleteSsl 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) {
ActionReport report = context.getActionReport();
Target targetUtil = habitat.getService(Target.class);
Config newConfig = targetUtil.getConfig(target);
if (newConfig != null) {
config = newConfig;
}
if (!type.equals("iiop-service")) {
if (listenerId == null) {
report.setMessage(localStrings.getLocalString("create.ssl.listenerid.missing", "Listener id needs to be specified"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
try {
SslConfigHandler sslConfigHandler = habitat.getService(SslConfigHandler.class, type);
if (sslConfigHandler != null) {
sslConfigHandler.delete(this, report);
} else if ("jmx-connector".equals(type)) {
JmxConnector jmxConnector = null;
for (JmxConnector listener : config.getAdminService().getJmxConnector()) {
if (listener.getName().equals(listenerId)) {
jmxConnector = listener;
}
}
if (jmxConnector == null) {
report.setMessage(localStrings.getLocalString("delete.ssl.jmx.connector.notfound", "Iiop Listener named {0} not found", listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (jmxConnector.getSsl() == null) {
report.setMessage(localStrings.getLocalString("delete.ssl.element.doesnotexist", "Ssl element does " + "not exist for Listener named {0}", listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
ConfigSupport.apply(new SingleConfigCode<JmxConnector>() {
public Object run(JmxConnector param) throws PropertyVetoException {
param.setSsl(null);
return null;
}
}, jmxConnector);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
} catch (TransactionFailure e) {
reportError(report, e);
}
}
use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class ProtocolSslConfigHandler method delete.
@Override
public void delete(final DeleteSsl command, final ActionReport report) {
try {
NetworkConfig networkConfig = command.config.getNetworkConfig();
final Protocol protocol = networkConfig.findProtocol(command.listenerId);
if (protocol != null) {
ConfigSupport.apply(new SingleConfigCode<Protocol>() {
public Object run(Protocol param) {
param.setSecurityEnabled("false");
param.setSsl(null);
return null;
}
}, protocol);
}
} catch (TransactionFailure transactionFailure) {
command.reportError(report, transactionFailure);
}
}
use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class SetConfigOrdinal method execute.
@Override
public void execute(AdminCommandContext context) {
Config configVal = targetUtil.getConfig(target);
MicroprofileConfigConfiguration serviceConfig = configVal.getExtensionByType(MicroprofileConfigConfiguration.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<MicroprofileConfigConfiguration>() {
@Override
public Object run(MicroprofileConfigConfiguration config) {
switch(source) {
case "domain":
{
config.setDomainOrdinality(Integer.toString(ordinal));
break;
}
case "config":
{
config.setConfigOrdinality(Integer.toString(ordinal));
break;
}
case "server":
{
config.setServerOrdinality(Integer.toString(ordinal));
break;
}
case "application":
{
config.setApplicationOrdinality(Integer.toString(ordinal));
break;
}
case "module":
{
config.setModuleOrdinality(Integer.toString(ordinal));
break;
}
case "cluster":
{
config.setClusterOrdinality(Integer.toString(ordinal));
break;
}
case "jndi":
{
config.setJNDIOrdinality(Integer.toString(ordinal));
break;
}
case "secrets":
{
config.setSecretDirOrdinality(Integer.toString(ordinal));
break;
}
}
return null;
}
}, serviceConfig);
} catch (TransactionFailure ex) {
// set failure
context.getActionReport().failure(Logger.getLogger(SetConfigOrdinal.class.getName()), "Failed to update message", ex);
}
} else {
context.getActionReport().failure(Logger.getLogger(SetConfigOrdinal.class.getName()), "No configuration with name " + target);
}
}
use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class ConfigConfigSource method setValue.
public boolean setValue(final String propertyName, final String propertyValue) throws TransactionFailure {
boolean success = false;
Config config = domainConfiguration.getConfigs().getConfigByName(configurationName);
if (config != null) {
Property p = config.getProperty(PROPERTY_PREFIX + propertyName);
if (p == null) {
ConfigSupport.apply(new SingleConfigCode<Config>() {
@Override
public Object run(Config config) throws TransactionFailure, PropertyVetoException {
Property prop = config.createChild(Property.class);
prop.setName(PROPERTY_PREFIX + propertyName);
prop.setValue(propertyValue);
config.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);
}
success = true;
}
return success;
}
Aggregations