import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Dictionary;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import org.argeo.util.naming.AttributesDictionary;
import org.argeo.util.naming.LdifParser;
import org.argeo.util.naming.LdifWriter;
-import org.eclipse.equinox.http.jetty.JettyConfigurator;
-import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
/** Manages the LDIF-based deployment configuration. */
public class DeployConfig implements ConfigurationListener {
+ private final static LdapName USER_ADMIN_BASE_DN;
+ static {
+ try {
+ USER_ADMIN_BASE_DN = new LdapName(
+ CmsConstants.OU + "=" + CmsConstants.NODE_USER_ADMIN_PID + "," + CmsConstants.DEPLOY_BASEDN);
+ } catch (InvalidNameException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
private final CmsLog log = CmsLog.getLog(getClass());
// private final BundleContext bc = FrameworkUtil.getBundle(getClass()).getBundleContext();
private ConfigurationAdmin configurationAdmin;
- public DeployConfig() {
-// this.dataModels = dataModels;
- // ConfigurationAdmin configurationAdmin =
-// // bc.getService(bc.getServiceReference(ConfigurationAdmin.class));
-// try {
-// if (!isInitialized()) { // first init
-// isFirstInit = true;
-// firstInit();
-// }
-// this.configurationAdmin = configurationAdmin;
-//// init(configurationAdmin, isClean, isFirstInit);
-// } catch (IOException e) {
-// throw new RuntimeException("Could not init deploy configs", e);
-// }
- // FIXME check race conditions during initialization
- // bc.registerService(ConfigurationListener.class, this, null);
- }
-
private void firstInit() throws IOException {
log.info("## FIRST INIT ##");
Files.createDirectories(deployConfigPath.getParent());
}
// http server
-// Dictionary<String, Object> webServerConfig = InitUtils
-// .getHttpServerConfig(getProps(KernelConstants.JETTY_FACTORY_PID, NodeConstants.DEFAULT));
-// if (!webServerConfig.isEmpty()) {
-// // TODO check for other customizers
+ Dictionary<String, Object> webServerConfig = InitUtils
+ .getHttpServerConfig(getProps(KernelConstants.JETTY_FACTORY_PID, CmsConstants.DEFAULT));
+ if (!webServerConfig.isEmpty()) {
+ // TODO check for other customizers
// webServerConfig.put("customizer.class", "org.argeo.equinox.jetty.CmsJettyCustomizer");
-// putFactoryDeployConfig(KernelConstants.JETTY_FACTORY_PID, webServerConfig);
-// }
- LdapName defaultHttpServiceDn = serviceDn(KernelConstants.JETTY_FACTORY_PID, CmsConstants.DEFAULT);
- if (deployConfigs.containsKey(defaultHttpServiceDn)) {
- // remove old default configs since we have now to start Jetty servlet bridge
- // indirectly
- deployConfigs.remove(defaultHttpServiceDn);
+ putFactoryDeployConfig(KernelConstants.JETTY_FACTORY_PID, webServerConfig);
}
+// LdapName defaultHttpServiceDn = serviceDn(KernelConstants.JETTY_FACTORY_PID, CmsConstants.DEFAULT);
+// if (deployConfigs.containsKey(defaultHttpServiceDn)) {
+// // remove old default configs since we have now to start Jetty servlet bridge
+// // indirectly
+// deployConfigs.remove(defaultHttpServiceDn);
+// }
// SAVE
save();
//
- // Explicitly configures Jetty so that the default server is not started by the
- // activator of the Equinox Jetty bundle.
- Dictionary<String, Object> webServerConfig = InitUtils
- .getHttpServerConfig(getProps(KernelConstants.JETTY_FACTORY_PID, CmsConstants.DEFAULT));
-// if (!webServerConfig.isEmpty()) {
-// webServerConfig.put("customizer.class", KernelConstants.CMS_JETTY_CUSTOMIZER_CLASS);
-//
-// // TODO centralise with Jetty extender
-// Object webSocketEnabled = webServerConfig.get(InternalHttpConstants.WEBSOCKET_ENABLED);
-// if (webSocketEnabled != null && webSocketEnabled.toString().equals("true")) {
-// bc.registerService(ServerEndpointConfig.Configurator.class, new CmsWebSocketConfigurator(), null);
-// webServerConfig.put(InternalHttpConstants.WEBSOCKET_ENABLED, "true");
-// }
-// }
+// Dictionary<String, Object> webServerConfig = InitUtils
+// .getHttpServerConfig(getProps(KernelConstants.JETTY_FACTORY_PID, CmsConstants.DEFAULT));
+ }
- int tryCount = 60;
+ public void start() {
try {
- tryGettyJetty: while (tryCount > 0) {
- try {
- JettyConfigurator.startServer(KernelConstants.DEFAULT_JETTY_SERVER, webServerConfig);
- // Explicitly starts Jetty OSGi HTTP bundle, so that it gets triggered if OSGi
- // configuration is not cleaned
- FrameworkUtil.getBundle(JettyConfigurator.class).start();
- break tryGettyJetty;
- } catch (IllegalStateException e) {
- // Jetty may not be ready
- try {
- Thread.sleep(1000);
- } catch (Exception e1) {
- // silent
- }
- tryCount--;
- }
+ if (!isInitialized()) { // first init
+ isFirstInit = true;
+ firstInit();
}
- } catch (Exception e) {
- log.error("Cannot start default Jetty server with config " + webServerConfig, e);
- }
-
- }
- public void init() throws IOException {
- if (!isInitialized()) { // first init
- isFirstInit = true;
- firstInit();
- }
-
- boolean isClean;
- try {
- Configuration[] confs = configurationAdmin
- .listConfigurations("(service.factoryPid=" + CmsConstants.NODE_USER_ADMIN_PID + ")");
- isClean = confs == null || confs.length == 0;
- } catch (Exception e) {
- throw new IllegalStateException("Cannot analyse clean state", e);
- }
+ boolean isClean = true;
+ if (configurationAdmin != null)
+ try {
+ Configuration[] confs = configurationAdmin
+ .listConfigurations("(service.factoryPid=" + CmsConstants.NODE_USER_ADMIN_PID + ")");
+ isClean = confs == null || confs.length == 0;
+ } catch (Exception e) {
+ throw new IllegalStateException("Cannot analyse clean state", e);
+ }
- try (InputStream in = Files.newInputStream(deployConfigPath)) {
- deployConfigs = new LdifParser().read(in);
- }
- if (isClean) {
- if (log.isDebugEnabled())
- log.debug("Clean state, loading from framework properties...");
- setFromFrameworkProperties(isFirstInit);
- loadConfigs();
+ try (InputStream in = Files.newInputStream(deployConfigPath)) {
+ deployConfigs = new LdifParser().read(in);
+ }
+ if (isClean) {
+ if (log.isDebugEnabled())
+ log.debug("Clean state, loading from framework properties...");
+ setFromFrameworkProperties(isFirstInit);
+ if (configurationAdmin != null)
+ loadConfigs();
+ }
+ // TODO check consistency if not clean
+ } catch (IOException e) {
+ throw new RuntimeException("Cannot load deploy configuration", e);
}
- // TODO check consistency if not clean
}
- public void destroy() {
+ public void stop() {
}
}
+ public Set<Dictionary<String, Object>> getUserDirectoryConfigs() {
+ Set<Dictionary<String, Object>> res = new HashSet<>();
+ for (LdapName dn : deployConfigs.keySet()) {
+ if (dn.endsWith(USER_ADMIN_BASE_DN)) {
+ Attributes attributes = deployConfigs.get(dn);
+ res.add(new AttributesDictionary(attributes));
+ }
+ }
+ return res;
+ }
+
@Override
public void configurationEvent(ConfigurationEvent event) {
try {
}
public boolean hasDomain() {
+ // FIXME lookup deploy configs directly
+ if (configurationAdmin == null)
+ return false;
+
Configuration[] configs;
try {
configs = configurationAdmin