use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.
the class CreateProtocolFinder 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();
final Protocols protocols = config.getNetworkConfig().getProtocols();
final Protocol protocol = protocols.findProtocol(protocolName);
final Protocol target = protocols.findProtocol(targetName);
try {
validate(protocol, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, protocolName);
validate(target, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, targetName);
final Class<?> finderClass = Thread.currentThread().getContextClassLoader().loadClass(classname);
if (!org.glassfish.grizzly.portunif.ProtocolFinder.class.isAssignableFrom(finderClass)) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PORTUNIF_FAIL_NOTFINDER), name, classname));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
PortUnification unif = (PortUnification) ConfigSupport.apply(new SingleConfigCode<Protocol>() {
@Override
public Object run(Protocol param) throws PropertyVetoException, TransactionFailure {
PortUnification pu = param.getPortUnification();
if (pu == null) {
pu = param.createChild(PortUnification.class);
param.setPortUnification(pu);
}
return pu;
}
}, protocol);
ConfigSupport.apply(new SingleConfigCode<PortUnification>() {
@Override
public Object run(PortUnification param) throws PropertyVetoException, TransactionFailure {
final List<ProtocolFinder> list = param.getProtocolFinder();
for (ProtocolFinder finder : list) {
if (name.equals(finder.getName())) {
throw new TransactionFailure(String.format("A protocol finder named %s already exists.", name));
}
}
final ProtocolFinder finder = param.createChild(ProtocolFinder.class);
finder.setName(name);
finder.setProtocol(targetName);
finder.setClassname(classname);
list.add(finder);
return null;
}
}, unif);
} catch (ValidationFailureException e) {
return;
} catch (Exception e) {
e.printStackTrace();
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PORTUNIF_FAIL), name, e.getMessage() == null ? "No reason given" : e.getMessage()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
}
use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.
the class CreateVirtualServer 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) {
Target targetUtil = services.getService(Target.class);
Config newConfig = targetUtil.getConfig(target);
if (newConfig != null) {
config = newConfig;
}
final ActionReport report = context.getActionReport();
if (networkListeners != null && httpListeners != null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_VIRTUAL_SERVER_BOTH_HTTP_NETWORK), virtualServerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// use the listener parameter provided by the user.
if (networkListeners == null) {
networkListeners = httpListeners;
}
HttpService httpService = config.getHttpService();
// ensure we don't already have one of this name
for (VirtualServer virtualServer : httpService.getVirtualServer()) {
if (virtualServer.getId().equals(virtualServerId)) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_VIRTUAL_SERVER_DUPLICATE), virtualServerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
try {
ConfigSupport.apply(new SingleConfigCode<HttpService>() {
public Object run(HttpService param) throws PropertyVetoException, TransactionFailure {
// default
String docroot = "${com.sun.aas.instanceRoot}/docroot";
// default
String accessLog = "${com.sun.aas.instanceRoot}/logs/access";
VirtualServer newVirtualServer = param.createChild(VirtualServer.class);
newVirtualServer.setId(virtualServerId);
newVirtualServer.setHosts(hosts);
newVirtualServer.setNetworkListeners(networkListeners);
newVirtualServer.setDefaultWebModule(defaultWebModule);
newVirtualServer.setState(state);
newVirtualServer.setLogFile(logFile);
// values if the properties have not been specified.
if (properties != null) {
for (Map.Entry entry : properties.entrySet()) {
String pn = (String) entry.getKey();
String pv = (String) entry.getValue();
if ("docroot".equals(pn)) {
docroot = pv;
} else if ("accesslog".equals(pn)) {
accessLog = pv;
} else {
Property property = newVirtualServer.createChild(Property.class);
property.setName(pn);
property.setValue(pv);
newVirtualServer.getProperty().add(property);
}
}
}
newVirtualServer.setDocroot(docroot);
newVirtualServer.setAccessLog(accessLog);
param.getVirtualServer().add(newVirtualServer);
return newVirtualServer;
}
}, httpService);
} catch (TransactionFailure e) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_VIRTUAL_SERVER_FAIL), virtualServerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.
the class DeleteTransport 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) {
Target targetUtil = services.getService(Target.class);
Config newConfig = targetUtil.getConfig(target);
if (newConfig != null) {
config = newConfig;
}
ActionReport report = context.getActionReport();
NetworkConfig networkConfig = config.getNetworkConfig();
Transports transports = networkConfig.getTransports();
try {
for (Transport transport : transports.getTransport()) {
if (transportName.equalsIgnoreCase(transport.getName())) {
transportToBeRemoved = transport;
}
}
if (transportToBeRemoved == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_TRANSPORT_NOT_EXISTS), transportName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// check if the transport to be deleted is being used by
// any network listener
List<NetworkListener> nwlsnrList = transportToBeRemoved.findNetworkListeners();
for (NetworkListener nwlsnr : nwlsnrList) {
if (transportToBeRemoved.getName().equals(nwlsnr.getTransport())) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_TRANSPORT_BEINGUSED), transportName, nwlsnr.getName()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
ConfigSupport.apply(new SingleConfigCode<Transports>() {
public Object run(Transports param) {
param.getTransport().remove(transportToBeRemoved);
return transportToBeRemoved;
}
}, transports);
} catch (TransactionFailure e) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_TRANSPORT_FAIL), transportName) + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.
the class GetHttpListener method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
// Check that a configuration can be found
if (targetUtil.getConfig(target) == null) {
report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_CONFIG), target));
return;
}
Config config = targetUtil.getConfig(target);
// Check that a matching listener can be found
List<NetworkListener> listeners = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
Optional<NetworkListener> optionalListener = listeners.stream().filter(listener -> listener.getName().equals(listenerName)).findFirst();
if (!optionalListener.isPresent()) {
report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_NETWORK_LISTENER), listenerName, target));
return;
}
NetworkListener listener = optionalListener.get();
// Write message body
report.appendMessage(String.format("Name: %s\n", listener.getName()));
report.appendMessage(String.format("Enabled: %s\n", listener.getEnabled()));
report.appendMessage(String.format("Port: %s\n", listener.getPort()));
report.appendMessage(String.format("Address: %s\n", listener.getAddress()));
report.appendMessage(String.format("Protocol: %s\n", listener.getProtocol()));
if (verbose) {
report.appendMessage(String.format("Transport: %s\n", listener.getTransport()));
report.appendMessage(String.format("Type: %s\n", listener.getType()));
report.appendMessage(String.format("Thread Pool: %s\n", listener.getThreadPool()));
report.appendMessage(String.format("JK Enabled: %s\n", listener.getJkEnabled()));
report.appendMessage(String.format("JK Configuration File: %s\n", listener.getJkConfigurationFile()));
}
// Write the variables as properties
Properties properties = new Properties();
properties.put("name", listener.getName());
properties.put("enabled", listener.getEnabled());
properties.put("port", listener.getPort());
properties.put("address", listener.getAddress());
properties.put("protocol", listener.getProtocol());
properties.put("transport", listener.getTransport());
properties.put("type", listener.getType());
properties.put("threadPool", listener.getThreadPool());
properties.put("jkEnabled", listener.getJkEnabled());
properties.put("jkConfigurationFile", listener.getJkConfigurationFile());
report.setExtraProperties(properties);
}
use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.
the class ListNetworkListeners 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;
}
final ActionReport report = context.getActionReport();
List<NetworkListener> list = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
for (NetworkListener networkListener : list) {
report.getTopMessagePart().addChild().setMessage(networkListener.getName());
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Aggregations