Class NodesSetupService

  • All Implemented Interfaces:
    org.apache.sling.event.jobs.consumer.JobConsumer

    public class NodesSetupService
    extends Object
    implements org.apache.sling.event.jobs.consumer.JobConsumer
    Ensures orderly removal of obsolete (e.g. Composum Core V1) bundles / configurations and replacing / updating new Composum Nore bundles and replacing the content in "/libs/composum/nodes". The service registers itself as a job (to be executed after the bundle is active) for this. The process is as follows:
    1. Remove all obsolete and to be replaced bundles / configurations from "/libs/composum/nodes/install"
    2. Moves all bundles in "/libs/composum/nodes.setup/upload" to "/libs/composum/nodes/install" to be picked up by the OSGI installer and then removes "/libs/composum/nodes.setup/upload"
    3. Replaces the content of "/libs/composum/nodes" with the content of "/libs/composum/nodes.setup"
    4. Installs the composum-nodes-jslibs-package again to make sure it wasn't trashed by a bundle removal
    5. Removes the bundle containing this and it's LoginAdminWhitelist configuration (even if something previous failed).
    It's sensible to check whether there were any errors logged after this (search for "Composum Nodes setup").
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.apache.sling.event.jobs.consumer.JobConsumer

        org.apache.sling.event.jobs.consumer.JobConsumer.AsyncHandler, org.apache.sling.event.jobs.consumer.JobConsumer.JobResult
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void activate​(org.osgi.framework.BundleContext bundleContext)  
      protected org.apache.jackrabbit.vault.fs.io.ImportOptions createPackageImportOptions()  
      protected void deactivate()  
      protected void installPackage​(@NotNull javax.jcr.Session session, @NotNull String packagePath, @NotNull Pattern... subpckgPatterns)
      (re-)install a package or subpackage if subpackages are specified
      protected boolean isInstallArtifact​(@NotNull String name)  
      protected void moveAcl​(javax.jcr.Node src, javax.jcr.Node target, boolean isSubnode)
      This moves any ACL restrictions from the subnodes of src to the nodes of target.
      org.apache.sling.event.jobs.consumer.JobConsumer.JobResult process​(org.apache.sling.event.jobs.Job job)  
      protected void removeInstallArtifacts​(@NotNull javax.jcr.Session session)
      the final removal of the install artifacts (setup-bundle and the related configuration)
      protected boolean removeNodesBundles​(@NotNull javax.jcr.Session session)  
      protected void removeNodesContent​(@NotNull javax.jcr.Session session)
      remove the Nodes modules content resources to prepare a clean install
      protected boolean removeUploadedBundles​(@NotNull javax.jcr.Session session)
      removes all matching artifacts in the bundle install repository folder (removes bundle files uploaded before)
      protected void setupNodesBundlesAndContent​(@NotNull javax.jcr.Session session)
      setup new Nodes bundles and content installed in the setup folder during package install
      protected boolean uninstallBundles()
      uninstalls all bundles matching to the unistall pattern list (removes bundles installed before)
      protected void wait​(int seconds)  
    • Field Detail

      • NODES_BUNDLES_PATH

        public static final String NODES_BUNDLES_PATH
        "/libs/composum/nodes/install" - the path where artefacts to install are put for automatical installation and from where obsolete / replaced bundles are deleted.
        See Also:
        Constant Field Values
      • SETUP_BUNDLES_PATH

        public static final String SETUP_BUNDLES_PATH
        "/libs/composum/nodes.setup/upload" a place the sling package puts the new bundles temporarily, to be moved by this service.
        See Also:
        Constant Field Values
      • VERSION_PATTERN

        public static final Pattern VERSION_PATTERN
      • INSTALL_ARTIFACTS

        public static final Pattern[] INSTALL_ARTIFACTS
        Matches the artifacts belonging to this setup bundle, which have to be removed later (used only for installation).
      • BUNDLES_TO_UNINSTALL

        public static final Pattern[] BUNDLES_TO_UNINSTALL
        Matches the old (Composum Core) bundles to be removed and the new (Composum Nodes) bundles to be replaced.
      • jobManager

        protected org.apache.sling.event.jobs.JobManager jobManager
    • Constructor Detail

      • NodesSetupService

        public NodesSetupService()
    • Method Detail

      • activate

        protected void activate​(org.osgi.framework.BundleContext bundleContext)
      • deactivate

        protected void deactivate()
      • process

        public org.apache.sling.event.jobs.consumer.JobConsumer.JobResult process​(org.apache.sling.event.jobs.Job job)
        Specified by:
        process in interface org.apache.sling.event.jobs.consumer.JobConsumer
      • removeNodesBundles

        protected boolean removeNodesBundles​(@NotNull
                                             @NotNull javax.jcr.Session session)
                                      throws javax.jcr.RepositoryException
        Throws:
        javax.jcr.RepositoryException
      • setupNodesBundlesAndContent

        protected void setupNodesBundlesAndContent​(@NotNull
                                                   @NotNull javax.jcr.Session session)
                                            throws javax.jcr.RepositoryException,
                                                   org.apache.jackrabbit.vault.packaging.PackageException,
                                                   IOException
        setup new Nodes bundles and content installed in the setup folder during package install
        Parameters:
        session - the JCR session of the executed setup job
        Throws:
        javax.jcr.RepositoryException - ...
        org.apache.jackrabbit.vault.packaging.PackageException
        IOException
      • moveAcl

        protected void moveAcl​(javax.jcr.Node src,
                               javax.jcr.Node target,
                               boolean isSubnode)
                        throws javax.jcr.RepositoryException
        This moves any ACL restrictions from the subnodes of src to the nodes of target. This violates the constraints for the src since the rep:policy nodes are removed, but src will be deleted, anyway.
        Throws:
        javax.jcr.RepositoryException
      • installPackage

        protected void installPackage​(@NotNull
                                      @NotNull javax.jcr.Session session,
                                      @NotNull
                                      @NotNull String packagePath,
                                      @NotNull
                                      @NotNull Pattern... subpckgPatterns)
                               throws javax.jcr.RepositoryException,
                                      org.apache.jackrabbit.vault.packaging.PackageException,
                                      IOException
        (re-)install a package or subpackage if subpackages are specified
        Parameters:
        session - the current session
        packagePath - the relative path of the package to install
        subpckgPatterns - a set of subpackage name patterns, each matching subpackage will be installed
        Throws:
        javax.jcr.RepositoryException
        org.apache.jackrabbit.vault.packaging.PackageException
        IOException
      • createPackageImportOptions

        protected org.apache.jackrabbit.vault.fs.io.ImportOptions createPackageImportOptions()
      • removeNodesContent

        protected void removeNodesContent​(@NotNull
                                          @NotNull javax.jcr.Session session)
                                   throws javax.jcr.RepositoryException
        remove the Nodes modules content resources to prepare a clean install
        Throws:
        javax.jcr.RepositoryException
      • removeUploadedBundles

        protected boolean removeUploadedBundles​(@NotNull
                                                @NotNull javax.jcr.Session session)
        removes all matching artifacts in the bundle install repository folder (removes bundle files uploaded before)
        Returns:
        true if at least one artifact has been removed
      • uninstallBundles

        protected boolean uninstallBundles()
        uninstalls all bundles matching to the unistall pattern list (removes bundles installed before)
        Returns:
        true if at least one bundle has been uninstalled
      • isInstallArtifact

        protected boolean isInstallArtifact​(@NotNull
                                            @NotNull String name)
        Returns:
        'true' if the name references an artifact od the setup itself
      • removeInstallArtifacts

        protected void removeInstallArtifacts​(@NotNull
                                              @NotNull javax.jcr.Session session)
                                       throws javax.jcr.RepositoryException
        the final removal of the install artifacts (setup-bundle and the related configuration)
        Throws:
        javax.jcr.RepositoryException
      • wait

        protected void wait​(int seconds)