5 Replies Latest reply on Apr 26, 2017 10:22 AM by dharrison

    Custom CNDs and Indexes

    dharrison

      Hello,

       

      I have a number of Compact Node Type Definitions (CNDs) and need to create Indexes on them, (some on multiple properties). I would like to avoid the need to restart modeshape upon adding a new index.

       

      My ModeShape app starts up with the REST API services.  Aferwards, I add the CNDs to the modeshape instance via REST API.

       

      However, if I define my indexes on the CNDs in the repository-configuration.json file, Modeshape fails to start the initial time because the referenced CNDs (by the indexes) do not exist at the 1st time that ModeShape instance creates it's database tables.

       

      What is the best way to handle this?

       

      * Can I put CNDs in a directory and have all CND files read and loaded from it?  Then, automatically have some Indexes created based on a similar technique?

      * Add the CNDs via REST API,  then dynamically add the Indexes via JCR IndexManager?

      * Other ways?

       

      FYI, I will also likely be using JGroups for High availability. So, I like the idea of using it to also propagate updates to CNDs and Indexes.

       

      Thanks for your ideas and advice.

       

      Best,

      David

        • 1. Re: Custom CNDs and Indexes
          hchiorean

          If you're planning on clustering, ModeShape 5 only works with a shared database model. In other words, all repository cluster nodes must share the same database. This also means that as long as CNDs have been stored into the database they should be visible across all nodes. JGroups is only used to invalidate the local cluster node in-memory caches when each node performs session.save() operations.

           

          Regarding CNDs and index definitions, as you point out, the prerequisite for index definitions to work is that the data types for which they are defined are stored in the repository first.

           

          The options I can think of are:

          a) if you know all your CNDs up front (which normally should be the case once your model is "stable") then you can configure the repository to load the CND file up front (via the configuration) and also define all the index definitions in the repository configuration file. In other words, you define everything up front.

          b) if you need the ability to add/change CNDs at runtime, then you must do the same with the index definitions. This means currently (see the next point) that you write some code against a repository instance and use the org.modeshape.jcr.api.index.IndexManager API (from the modeshape-api package) to do this. You can add the CNDs either via the REST API or directly using the org.modeshape.jcr.api.nodetype.NodeTypeManager API, but you only have 1 way atm to dynamically register indexes

          c) enhance the ModeShape REST API (or have your own custom REST Service on top of a ModeShape repository) to be able to register indexes using the above mentioned API.

          • 2. Re: Custom CNDs and Indexes
            dharrison

            hchiorean If I were to enhance the ModeShape REST API, I adhered to the coding standards of the ModeShape community, etc, is this a enhancement you would include in the modeshape codebase?

             

            I'm thinking I need

            • POST - Register/Create an Index,  reusing the same JSON format as used in defining an index in the respository configuration JSON.
            • GET - Get definition of one or more indices
            • DELETE - Remove an index

            Possibly

            • PUT - Replace definition of an index,  which would most likely just unregister the index and register it again under the new definition

             

            Thanks very much!

             

            David

            • 3. Re: Custom CNDs and Indexes
              hchiorean

              hchiorean If I were to enhance the ModeShape REST API, I adhered to the coding standards of the ModeShape community, etc, is this a enhancement you would include in the modeshape codebase?

              Of course, we're more than happy to include such an enhancement, especially since I think it would make a nice addition to the REST service.

               

              Regarding the implementation:

              - I would probably name the method "indexes" or something similar and URL segment /repositoryName/indexes

              - I can think of 2  GET methods: GET repository/indexes which returns all configured indexes (from the repo config) and GET /repository/indexes/<indexName> which returns an array for all the indexes named <indexName> (note that it's possible for the same index name to be used across multiple providers)

              - POST/ DELETE /repositoryName/indexes/<indexName> would take the body as a JSON resembling the "index" section from the repository configuration and would create or delete an index for a particular provider (based on the provider attribute from the JSON body)

              - PUT is a bit tricky since there's no direct API support for updating an index definition. So if you want to implement this you would have to do a unregister/register combination behind the scenes

               

              These are just ideas, you're free to implement these in whichever way is most useful for your use case. If you're interested in contributing this feature, please log a JIRA so we can track it. Thanks.

              1 of 1 people found this helpful
              • 4. Re: Custom CNDs and Indexes
                dharrison
                • 5. Re: Custom CNDs and Indexes
                  dharrison

                  While my employer has a legal policy discussion on open source contributions, I'm trying the route of loading all CND and indexes from files , at startup time. If that doesn't suffice, I'll proceed with the rest enhancement and hope for go ahead to contribute