use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class IiopSslConfigHandler method create.
@Override
public void create(final CreateSsl command, ActionReport report) {
IiopService iiopService = command.config.getExtensionByType(IiopService.class);
// ensure we have the specified listener
IiopListener iiopListener = null;
for (IiopListener listener : iiopService.getIiopListener()) {
if (listener.getId().equals(command.listenerId)) {
iiopListener = listener;
}
}
if (iiopListener == null) {
report.setMessage(localStrings.getLocalString("create.ssl.iiop.notfound", "IIOP Listener named {0} to which this ssl element is " + "being added does not exist.", command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (iiopListener.getSsl() != null) {
report.setMessage(localStrings.getLocalString("create.ssl.iiop.alreadyExists", "IIOP Listener named {0} to which this ssl element is " + "being added already has an ssl element.", command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<IiopListener>() {
public Object run(IiopListener param) throws PropertyVetoException, TransactionFailure {
Ssl newSsl = param.createChild(Ssl.class);
command.populateSslElement(newSsl);
param.setSsl(newSsl);
return newSsl;
}
}, iiopListener);
} catch (TransactionFailure e) {
command.reportError(report, e);
}
command.reportSuccess(report);
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class IiopSslConfigHandler method delete.
@Override
public void delete(DeleteSsl command, ActionReport report) {
IiopService iiopService = command.config.getExtensionByType(IiopService.class);
IiopListener iiopListener = null;
for (IiopListener listener : iiopService.getIiopListener()) {
if (listener.getId().equals(command.listenerId)) {
iiopListener = listener;
}
}
if (iiopListener == null) {
report.setMessage(localStrings.getLocalString("delete.ssl.iiop.listener.notfound", "Iiop Listener named {0} not found", command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (iiopListener.getSsl() == null) {
report.setMessage(localStrings.getLocalString("delete.ssl.element.doesnotexist", "Ssl element does " + "not exist for Listener named {0}", command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<IiopListener>() {
public Object run(IiopListener param) throws PropertyVetoException {
param.setSsl(null);
return null;
}
}, iiopListener);
} catch (TransactionFailure e) {
command.reportError(report, e);
}
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class IiopServiceSslConfigHandler method create.
@Override
public void create(final CreateSsl command, ActionReport report) {
IiopService iiopSvc = command.config.getExtensionByType(IiopService.class);
if (iiopSvc.getSslClientConfig() != null) {
report.setMessage(localStrings.getLocalString("create.ssl.iiopsvc.alreadyExists", "IIOP Service " + "already has been configured with SSL configuration."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<IiopService>() {
public Object run(IiopService param) throws PropertyVetoException, TransactionFailure {
SslClientConfig newSslClientCfg = param.createChild(SslClientConfig.class);
Ssl newSsl = newSslClientCfg.createChild(Ssl.class);
command.populateSslElement(newSsl);
newSslClientCfg.setSsl(newSsl);
param.setSslClientConfig(newSslClientCfg);
return newSsl;
}
}, iiopSvc);
} catch (TransactionFailure e) {
command.reportError(report, e);
}
command.reportSuccess(report);
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class DeleteJndiResource 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 (!doesResourceExist(domain.getResources(), jndiName)) {
report.setMessage(localStrings.getLocalString("delete.jndi.resource.notfound", "A jndi 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.jndi.resource.resource-ref.exist", "external-jndi-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.jndi.resource.no.resource-ref", "external-jndi-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.jndi.resource.multiple.resource-refs", "external-jndi-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 external-jndi-resource
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
ExternalJndiResource resource = (ExternalJndiResource) domain.getResources().getResourceByName(ExternalJndiResource.class, jndiName);
if (resource.getJndiName().equals(jndiName)) {
return param.getResources().remove(resource);
}
return null;
}
}, domain.getResources());
report.setMessage(localStrings.getLocalString("" + "delete.jndi.resource.success", "Jndi resource {0} deleted.", jndiName));
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (TransactionFailure tfe) {
report.setMessage(localStrings.getLocalString("" + "delete.jndi.resource.fail", "Unable to delete jndi 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 DeleteCustomResource 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 (domain.getResources().getResourceByName(CustomResource.class, jndiName) == null) {
report.setMessage(localStrings.getLocalString("delete.custom.resource.notfound", "A custom 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.custom.resource.resource-ref.exist", "custom-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.custom.resource.no.resource-ref", "custom-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.custom.resource.multiple.resource-refs", "custom-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 custom-resource
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
CustomResource resource = (CustomResource) domain.getResources().getResourceByName(CustomResource.class, jndiName);
if (resource != null && resource.getJndiName().equals(jndiName)) {
return param.getResources().remove(resource);
}
return null;
}
}, domain.getResources());
report.setMessage(localStrings.getLocalString("delete.custom.resource.success", "Custom resource {0} deleted", jndiName));
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (TransactionFailure tfe) {
report.setMessage(localStrings.getLocalString("delete.custom.resource.fail", "Unable to delete custom resource {0}", jndiName) + " " + tfe.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
}
}
Aggregations