use of com.sun.enterprise.config.serverbeans.VirtualServer 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.VirtualServer in project Payara by payara.
the class ListVirtualServers 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();
List<VirtualServer> list = config.getHttpService().getVirtualServer();
for (VirtualServer virtualServer : list) {
report.getTopMessagePart().addChild().setMessage(virtualServer.getId());
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of com.sun.enterprise.config.serverbeans.VirtualServer in project Payara by payara.
the class HttpServiceStatsProviderBootstrap method postConstruct.
public void postConstruct() {
if (config == null) {
Object[] params = { VirtualServerInfoStatsProvider.class.getName(), HttpServiceStatsProvider.class.getName(), "http service", "virtual server" };
logger.log(Level.SEVERE, LogFacade.UNABLE_TO_REGISTER_STATS_PROVIDERS, params);
throw new ConfigurationException(rb.getString(LogFacade.NULL_CONFIG));
}
HttpService httpService = config.getHttpService();
for (VirtualServer vs : httpService.getVirtualServer()) {
StatsProviderManager.register("http-service", PluginPoint.SERVER, "http-service/" + vs.getId(), new VirtualServerInfoStatsProvider(vs));
StatsProviderManager.register("http-service", PluginPoint.SERVER, "http-service/" + vs.getId() + "/request", new HttpServiceStatsProvider(vs.getId(), vs.getNetworkListeners(), config.getNetworkConfig()));
}
}
use of com.sun.enterprise.config.serverbeans.VirtualServer in project Payara by payara.
the class WebConfigListener method changed.
/**
* Handles HttpService change events
* @param events the PropertyChangeEvent
*/
@Override
public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
return ConfigSupport.sortAndDispatch(events, new Changed() {
@Override
public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tClass, T t) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, LogFacade.CHANGE_INVOKED, new Object[] { type, tClass, t });
}
try {
if (tClass == HttpService.class) {
container.updateHttpService((HttpService) t);
} else if (tClass == NetworkListener.class) {
if (type == TYPE.ADD) {
container.addConnector((NetworkListener) t, httpService, true);
} else if (type == TYPE.REMOVE) {
container.deleteConnector((NetworkListener) t);
} else if (type == TYPE.CHANGE) {
container.updateConnector((NetworkListener) t, httpService);
}
} else if (tClass == VirtualServer.class) {
if (type == TYPE.ADD) {
container.createHost((VirtualServer) t, httpService, null);
container.loadDefaultWebModule((VirtualServer) t);
} else if (type == TYPE.REMOVE) {
container.deleteHost(httpService);
} else if (type == TYPE.CHANGE) {
container.updateHost((VirtualServer) t);
}
} else if (tClass == AccessLog.class) {
container.updateAccessLog(httpService);
} else if (tClass == ManagerProperties.class) {
return new NotProcessed("ManagerProperties requires restart");
} else if (tClass == WebContainerAvailability.class || tClass == AvailabilityService.class) {
// container.updateHttpService handles SingleSignOn valve configuration
container.updateHttpService(httpService);
} else if (tClass == NetworkListeners.class) {
// skip updates
} else if (tClass == Property.class) {
ConfigBeanProxy config = ((Property) t).getParent();
if (config instanceof HttpService) {
container.updateHttpService((HttpService) config);
} else if (config instanceof VirtualServer) {
container.updateHost((VirtualServer) config);
} else if (config instanceof NetworkListener) {
container.updateConnector((NetworkListener) config, httpService);
} else {
container.updateHttpService(httpService);
}
} else if (tClass == SystemProperty.class) {
if (((SystemProperty) t).getName().endsWith("LISTENER_PORT")) {
for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
if (listener.getPort().equals(((SystemProperty) t).getValue())) {
container.updateConnector(listener, httpService);
}
}
}
} else if (tClass == JavaConfig.class) {
JavaConfig jc = (JavaConfig) t;
final List<String> jvmOptions = new ArrayList<String>(jc.getJvmOptions());
for (String jvmOption : jvmOptions) {
if (jvmOption.startsWith("-DjvmRoute=")) {
container.updateJvmRoute(httpService, jvmOption);
}
}
} else {
// Ignore other unrelated events
}
} catch (LifecycleException le) {
logger.log(Level.SEVERE, LogFacade.EXCEPTION_WEB_CONFIG, le);
}
return null;
}
}, logger);
}
use of com.sun.enterprise.config.serverbeans.VirtualServer in project Payara by payara.
the class ExistingConfigurationTest method setupServer.
@Test
public void setupServer() throws Exception {
Server server = null;
System.out.println("setup started with gf installation " + System.getProperty("basedir"));
File f = new File(System.getProperty("basedir"));
f = new File(f, "target");
f = new File(f, "dependency");
f = new File(f, "glassfish4");
f = new File(f, "glassfish");
if (f.exists()) {
System.out.println("Using gf at " + f.getAbsolutePath());
} else {
System.out.println("GlassFish not found at " + f.getAbsolutePath());
Assert.assertTrue(f.exists());
}
try {
EmbeddedFileSystem.Builder efsb = new EmbeddedFileSystem.Builder();
efsb.installRoot(f, false);
// find the domain root.
f = new File(f, "domains");
f = new File(f, "domain1");
f = new File(f, "config");
f = new File(f, "domain.xml");
Assert.assertTrue(f.exists());
efsb.configurationFile(f);
Server.Builder builder = new Server.Builder("inplanted");
builder.embeddedFileSystem(efsb.build());
server = builder.build();
ServiceLocator habitat = server.getHabitat();
Collection<VirtualServer> vss = habitat.getAllServices(VirtualServer.class);
Assert.assertTrue(vss.size() > 0);
for (VirtualServer vs : vss) {
System.out.println("Virtual Server " + vs.getId());
}
Collection<NetworkListener> nls = habitat.getAllServices(NetworkListener.class);
for (NetworkListener nl : nls) {
System.out.println("Network listener " + nl.getPort());
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
if (server != null) {
server.stop();
}
}
}
Aggregations