use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class DeleteJavaMailResource method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the paramter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
// ensure we already have this resource
if (!isResourceExists(domain.getResources(), jndiName)) {
report.setMessage(localStrings.getLocalString("delete.mail.resource.notfound", "A Mail resource named {0} does not exist.", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (environment.isDas()) {
if ("domain".equals(target)) {
if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
report.setMessage(localStrings.getLocalString("delete.mail.resource.resource-ref.exist", "mail-resource [ {0} ] is referenced in an" + "instance/cluster target, Use delete-resource-ref on appropriate target", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
} else {
if (!resourceUtil.isResourceRefInTarget(jndiName, target)) {
report.setMessage(localStrings.getLocalString("delete.mail.resource.no.resource-ref", "mail-resource [ {0} ] is not referenced in target [ {1} ]", jndiName, target));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) {
report.setMessage(localStrings.getLocalString("delete.mail.resource.multiple.resource-refs", "mail-resource [ {0} ] is referenced in multiple " + "instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
try {
// delete resource-ref
resourceUtil.deleteResourceRef(jndiName, target);
// delete java-mail-resource
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
MailResource resource = (MailResource) ResourceUtil.getBindableResourceByName(domain.getResources(), jndiName);
return param.getResources().remove(resource);
}
}, domain.getResources());
report.setMessage(localStrings.getLocalString("delete.mail.resource.success", "Mail resource {0} deleted", jndiName));
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (TransactionFailure tfe) {
report.setMessage(localStrings.getLocalString("delete.mail.resource.failed", "Unable to delete mail resource {0}", jndiName) + " " + tfe.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
}
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class ConfigTest method testDomTx.
// @Test
public void testDomTx() {
SimpleConnector sc = habitat.getService(SimpleConnector.class);
EjbContainerAvailability ejb = sc.getEjbContainerAvailability();
Dom ejbDom = Dom.unwrap(ejb);
assert (ejbDom.getHabitat() != null);
String avEnabled = ejb.getAvailabilityEnabled();
try {
ConfigSupport.apply(new SingleConfigCode<EjbContainerAvailability>() {
@Override
public Object run(EjbContainerAvailability param) throws PropertyVetoException, TransactionFailure {
param.setSfsbHaPersistenceType("coherence");
param.setSfsbCheckpointEnabled("**MUST BE**");
return null;
}
}, ejb);
// printEjb("AFTER CHANGES", ejb);
assert (ejb.getSfsbHaPersistenceType().equals("coherence") && ejb.getSfsbCheckpointEnabled().equals("**MUST BE**") && ejb.getAvailabilityEnabled().equals(avEnabled));
} catch (Exception e) {
e.printStackTrace();
assert (false);
}
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class SetConfigCacheDuration method execute.
@Override
public void execute(AdminCommandContext context) {
Config configVal = targetUtil.getConfig(target);
MicroprofileConfigConfiguration serviceConfig = configVal.getExtensionByType(MicroprofileConfigConfiguration.class);
if (serviceConfig != null) {
try {
ConfigSupport.apply(new SingleConfigCode<MicroprofileConfigConfiguration>() {
@Override
public Object run(MicroprofileConfigConfiguration config) {
config.setCacheDurationSeconds(Integer.toString(durationInSeconds));
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.SingleConfigCode 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;
}
case PASSWORD:
{
config.setPasswordOrdinality(Integer.toString(ordinal));
break;
}
case JDBC:
{
config.setJdbcOrdinality(Integer.toString(ordinal));
break;
}
case CLOUD:
{
config.setCloudOrdinality(Integer.toString(ordinal));
break;
}
case LDAP:
{
config.setLdapOrdinality(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.SingleConfigCode 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