package org.argeo.cms.internal.kernel;
-import static org.argeo.node.DataModelNamespace.CMS_DATA_MODEL_NAMESPACE;
+import static org.argeo.api.DataModelNamespace.CMS_DATA_MODEL_NAMESPACE;
import java.io.File;
+import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.management.ManagementFactory;
import org.apache.jackrabbit.commons.cnd.CndImporter;
import org.apache.jackrabbit.core.RepositoryContext;
import org.apache.jackrabbit.core.RepositoryImpl;
+import org.argeo.api.DataModelNamespace;
+import org.argeo.api.NodeConstants;
+import org.argeo.api.NodeDeployment;
+import org.argeo.api.NodeState;
+import org.argeo.api.security.CryptoKeyring;
+import org.argeo.api.security.Keyring;
import org.argeo.cms.ArgeoNames;
import org.argeo.cms.CmsException;
import org.argeo.jcr.JcrUtils;
-import org.argeo.node.DataModelNamespace;
-import org.argeo.node.NodeConstants;
-import org.argeo.node.NodeDeployment;
-import org.argeo.node.NodeState;
-import org.argeo.node.security.CryptoKeyring;
-import org.argeo.node.security.Keyring;
import org.argeo.osgi.useradmin.UserAdminConf;
import org.argeo.util.LangUtils;
import org.eclipse.equinox.http.jetty.JettyConfigurator;
import org.osgi.service.useradmin.UserAdmin;
import org.osgi.util.tracker.ServiceTracker;
+/** Implementation of a CMS deployment. */
public class CmsDeployment implements NodeDeployment {
- // private final static String LEGACY_JCR_REPOSITORY_ALIAS =
- // "argeo.jcr.repository.alias";
-
private final Log log = LogFactory.getLog(getClass());
private final BundleContext bc = FrameworkUtil.getBundle(getClass()).getBundleContext();
private DataModels dataModels;
private DeployConfig deployConfig;
- private HomeRepository homeRepository;
private Long availableSince;
- private final boolean cleanState;
+// private final boolean cleanState;
private NodeHttp nodeHttp;
private boolean httpAvailable = false;
public CmsDeployment() {
- ServiceReference<NodeState> nodeStateSr = bc.getServiceReference(NodeState.class);
- if (nodeStateSr == null)
- throw new CmsException("No node state available");
+// ServiceReference<NodeState> nodeStateSr = bc.getServiceReference(NodeState.class);
+// if (nodeStateSr == null)
+// throw new CmsException("No node state available");
- NodeState nodeState = bc.getService(nodeStateSr);
- cleanState = nodeState.isClean();
+// NodeState nodeState = bc.getService(nodeStateSr);
+// cleanState = nodeState.isClean();
- nodeHttp = new NodeHttp(cleanState);
+ nodeHttp = new NodeHttp();
dataModels = new DataModels(bc);
initTrackers();
}
@Override
public ConfigurationAdmin addingService(ServiceReference<ConfigurationAdmin> reference) {
ConfigurationAdmin configurationAdmin = bc.getService(reference);
- deployConfig = new DeployConfig(configurationAdmin, dataModels, cleanState);
+ boolean isClean;
+ try {
+ Configuration[] confs = configurationAdmin
+ .listConfigurations("(service.factoryPid=" + NodeConstants.NODE_USER_ADMIN_PID + ")");
+ isClean = confs == null || confs.length == 0;
+ } catch (Exception e) {
+ throw new CmsException("Cannot analize clean state", e);
+ }
+ deployConfig = new DeployConfig(configurationAdmin, dataModels, isClean);
httpExpected = deployConfig.getProps(KernelConstants.JETTY_FACTORY_PID, "default") != null;
try {
- // Configuration[] configs = configurationAdmin
- // .listConfigurations("(service.factoryPid=" +
- // NodeConstants.NODE_REPOS_FACTORY_PID + ")");
- // for (Configuration config : configs) {
- // Object cn = config.getProperties().get(NodeConstants.CN);
- // if (log.isDebugEnabled())
- // log.debug("Standalone repo cn: " + cn);
- // }
Configuration[] configs = configurationAdmin
.listConfigurations("(service.factoryPid=" + NodeConstants.NODE_USER_ADMIN_PID + ")");
}
// home
- prepareDataModel(NodeConstants.NODE, deployedNodeRepository);
+ prepareDataModel(NodeConstants.NODE_REPOSITORY, deployedNodeRepository);
}
private void prepareHomeRepository(RepositoryImpl deployedRepository) {
JcrUtils.logoutQuietly(adminSession);
}
- Hashtable<String, String> regProps = new Hashtable<String, String>();
- regProps.put(NodeConstants.CN, NodeConstants.HOME);
- // regProps.put(LEGACY_JCR_REPOSITORY_ALIAS, NodeConstants.HOME);
- homeRepository = new HomeRepository(deployedRepository, false);
- // register
- bc.registerService(Repository.class, homeRepository, regProps);
+ // Publish home with the highest service ranking
+ Hashtable<String, Object> regProps = new Hashtable<>();
+ regProps.put(NodeConstants.CN, NodeConstants.EGO_REPOSITORY);
+ regProps.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
+ Repository egoRepository = new EgoRepository(deployedRepository, false);
+ bc.registerService(Repository.class, egoRepository, regProps);
// Keyring only if Argeo extensions are available
if (argeoDataModelExtensionsAvailable) {
@Override
public CallbackHandler addingService(ServiceReference<CallbackHandler> reference) {
- NodeKeyRing nodeKeyring = new NodeKeyRing(homeRepository);
+ NodeKeyRing nodeKeyring = new NodeKeyRing(egoRepository);
CallbackHandler callbackHandler = bc.getService(reference);
nodeKeyring.setDefaultCallbackHandler(callbackHandler);
bc.registerService(LangUtils.names(Keyring.class, CryptoKeyring.class, ManagedService.class),
BundleWiring wiring = bundle.adapt(BundleWiring.class);
if (wiring == null)
continue bundles;
- if (NodeConstants.NODE.equals(cn))// process all data models
+ if (NodeConstants.NODE_REPOSITORY.equals(cn))// process all data models
processWiring(cn, adminSession, wiring, processed, false);
else {
List<BundleCapability> capabilities = wiring.getCapabilities(CMS_DATA_MODEL_NAMESPACE);
boolean publishLocalRepo;
if (isStandalone && name.equals(cn))// includes the node itself
publishLocalRepo = true;
- else if (!isStandalone && cn.equals(NodeConstants.NODE))
+ else if (!isStandalone && cn.equals(NodeConstants.NODE_REPOSITORY))
publishLocalRepo = true;
else
publishLocalRepo = false;
private void publishLocalRepo(String dataModelName, Repository repository) {
Hashtable<String, Object> properties = new Hashtable<>();
- // properties.put(LEGACY_JCR_REPOSITORY_ALIAS, name);
properties.put(NodeConstants.CN, dataModelName);
- if (dataModelName.equals(NodeConstants.NODE))
- properties.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
LocalRepository localRepository;
String[] classes;
if (repository instanceof RepositoryImpl) {
RepositoryContext repoContext = bc.getService(reference);
String cn = (String) reference.getProperty(NodeConstants.CN);
if (cn != null) {
- if (cn.equals(NodeConstants.NODE)) {
+ if (cn.equals(NodeConstants.NODE_REPOSITORY)) {
prepareNodeRepository(repoContext.getRepository());
// TODO separate home repository
prepareHomeRepository(repoContext.getRepository());