use of org.jvnet.hk2.config in project Payara by payara.
the class DeleteHttpRedirect 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;
}
Protocol protocolToBeRemoved = null;
ActionReport report = context.getActionReport();
NetworkConfig networkConfig = config.getNetworkConfig();
Protocols protocols = networkConfig.getProtocols();
try {
for (Protocol protocol : protocols.getProtocol()) {
if (protocolName.equalsIgnoreCase(protocol.getName())) {
protocolToBeRemoved = protocol;
}
}
if (protocolToBeRemoved == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_HTTP_NOTEXISTS), protocolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// check if the protocol whose http to be deleted is being used by
// any network listener, then do not delete it.
List<NetworkListener> nwlsnrList = protocolToBeRemoved.findNetworkListeners();
for (NetworkListener nwlsnr : nwlsnrList) {
if (protocolToBeRemoved.getName().equals(nwlsnr.getProtocol())) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_PROTOCOL_BEING_USED), protocolName, nwlsnr.getName()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
ConfigSupport.apply(new SingleConfigCode<Protocol>() {
public Object run(Protocol param) {
param.setHttpRedirect(null);
return null;
}
}, protocolToBeRemoved);
} catch (TransactionFailure e) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_HTTP_FAIL), protocolName) + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.jvnet.hk2.config in project Payara by payara.
the class DeleteProtocolFinder method execute.
@Override
public void execute(AdminCommandContext context) {
Target targetUtil = services.getService(Target.class);
Config newConfig = targetUtil.getConfig(target);
if (newConfig != null) {
config = newConfig;
}
report = context.getActionReport();
try {
final Protocols protocols = config.getNetworkConfig().getProtocols();
final Protocol protocol = protocols.findProtocol(protocolName);
validate(protocol, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, protocolName);
PortUnification pu = getPortUnification(protocol);
ConfigSupport.apply(new ConfigCode() {
@Override
public Object run(ConfigBeanProxy... params) {
final Protocol prot = (Protocol) params[0];
final PortUnification portUnification = (PortUnification) params[1];
final List<ProtocolFinder> oldList = portUnification.getProtocolFinder();
List<ProtocolFinder> newList = new ArrayList<ProtocolFinder>();
for (final ProtocolFinder finder : oldList) {
if (!name.equals(finder.getName())) {
newList.add(finder);
}
}
if (oldList.size() == newList.size()) {
throw new RuntimeException(String.format("No finder named %s found for protocol %s", name, protocolName));
}
if (newList.isEmpty()) {
prot.setPortUnification(null);
} else {
portUnification.setProtocolFinder(newList);
}
return null;
}
}, protocol, pu);
cleanPortUnification(pu);
} catch (ValidationFailureException e) {
return;
} catch (Exception e) {
e.printStackTrace();
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_FAIL), name, e.getMessage() == null ? "No reason given" : e.getMessage()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
}
use of org.jvnet.hk2.config in project Payara by payara.
the class DeleteVirtualServer 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) {
Target targetUtil = services.getService(Target.class);
Config newConfig = targetUtil.getConfig(target);
if (newConfig != null) {
config = newConfig;
}
ActionReport report = context.getActionReport();
httpService = config.getHttpService();
networkConfig = config.getNetworkConfig();
if (!exists()) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_VIRTUAL_SERVER_NOT_EXISTS), vsid));
report.setActionExitCode(ExitCode.FAILURE);
return;
}
// reference check
String referencedBy = getReferencingListener();
if (referencedBy != null && referencedBy.length() != 0) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_VIRTUAL_SERVER_REFERENCED), vsid, referencedBy));
report.setActionExitCode(ExitCode.FAILURE);
return;
}
try {
// we need to determine which deployed applications reference this virtual-server
List<ApplicationRef> appRefs = new ArrayList<ApplicationRef>();
for (ApplicationRef appRef : server.getApplicationRef()) {
if (appRef.getVirtualServers() != null && appRef.getVirtualServers().contains(vsid)) {
appRefs.add(appRef);
}
}
// transfer into the array of arguments
ConfigBeanProxy[] proxies = new ConfigBeanProxy[appRefs.size() + 1];
proxies[0] = httpService;
for (int i = 0; i < appRefs.size(); i++) {
proxies[i + 1] = appRefs.get(i);
}
ConfigSupport.apply(new ConfigUpdate(vsid), proxies);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (TransactionFailure e) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_VIRTUAL_SERVER_FAIL), vsid));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
use of org.jvnet.hk2.config in project Payara by payara.
the class SetMetricsConfigurationCommand method execute.
@Override
public void execute(AdminCommandContext adminCommandContext) {
Config targetConfig = targetUtil.getConfig(target);
MetricsServiceConfiguration metricsConfiguration = targetConfig.getExtensionByType(MetricsServiceConfiguration.class);
try {
ConfigSupport.apply(metricsConfigurationProxy -> {
if (enabled != null) {
metricsConfigurationProxy.setEnabled(String.valueOf(enabled));
}
if (secure != null) {
metricsConfigurationProxy.setSecure(String.valueOf(secure));
}
return metricsConfigurationProxy;
}, metricsConfiguration);
} catch (TransactionFailure ex) {
adminCommandContext.getActionReport().failure(LOGGER, "Failed to update Metrics configuration", ex);
}
}
use of org.jvnet.hk2.config in project Payara by payara.
the class SetMonitoringConfiguration method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport actionReport = context.getActionReport();
Config config = targetUtil.getConfig(target);
final MonitoringService service = serviceLocator.getService(MonitoringService.class);
if (service == null) {
actionReport.appendMessage("Could not find a monitoring service.");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
monitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
try {
ConfigSupport.apply(new SingleConfigCode<MonitoringServiceConfiguration>() {
@Override
public Object run(final MonitoringServiceConfiguration monitoringConfigProxy) throws PropertyVetoException, TransactionFailure {
updateConfiguration(monitoringConfigProxy);
updateAttributes(monitoringConfigProxy, actionReport);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return monitoringConfigProxy;
}
}, monitoringConfig);
if (dynamic) {
enableOnTarget(actionReport, context, enabled);
}
} catch (TransactionFailure ex) {
Logger.getLogger(SetMonitoringConfiguration.class.getName()).log(Level.WARNING, "Exception during command " + "set-monitoring-configuration: " + ex.getCause().getMessage());
actionReport.setMessage(ex.getCause().getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
Aggregations