1 2 Previous Next 18 Replies Latest reply on Feb 12, 2013 12:44 PM by Ivan Vasyliev

    Modeshape 3.1.1 and federation

    Ivan Vasyliev Newbie

      I'm exploring federation in modeshape 3.x and cant get it working so far (see my fork from modeshape-examples here https://github.com/vasilievip/modeshape-examples/commits/federation2)

      Here is the issue I see:

       

      {code}

                  session = repository.login("default");

                   Node root = session.getRootNode();

                  Node fed = root.getNode("federation"); <-- Node under federation

                  Node folder = fed.addNode("Folder" + rnd.nextInt(), "nt:folder");

                  Node file = fed.addNode("File" + rnd.nextInt(), "nt:file");

                  session.save();

      {code}

       

      {code}

      javax.jcr.nodetype.ConstraintViolationException: The values for the '{http://www.jcp.org/jcr/1.0}content' property on node '/federation/File1481898856' no longer satisfy the type and/or constraints on the 'jcr:content' property definition on the 'nt:file' node type definition

                at org.modeshape.jcr.JcrSession$JcrPreSave.process(JcrSession.java:1811)

                at org.modeshape.jcr.cache.document.WritableSessionCache.save(WritableSessionCache.java:501)

                at org.modeshape.jcr.JcrSession.save(JcrSession.java:978)

                at org.modeshape.example.filesystem.ModeShapeExample.main(ModeShapeExample.java:73)

                at org.modeshape.example.embedded.ModeShapeExampleTest.shouldRunApplication(ModeShapeExampleTest.java:35)

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

                at java.lang.reflect.Method.invoke(Method.java:601)

                at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)

                at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

                at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)

                at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)

                at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)

                at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)

                at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)

                at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)

                at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)

                at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)

                at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)

                at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)

                at org.junit.runners.ParentRunner.run(ParentRunner.java:300)

                at org.junit.runner.JUnitCore.run(JUnitCore.java:157)

                at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)

                at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)

                at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

                at java.lang.reflect.Method.invoke(Method.java:601)

                at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

      {code}

       

      Please advise

        • 1. Re: Modeshape 3.1.1 and federation
          Randall Hauch Master

          Your code is not correct and would not work even in a non-federated repository. The problem is that the "nt:file" node is not complete. (See our documentation for information about how to store files and folders inside JCR.)

           

           

          The "nt:file" node type is defined as this:

           

          [nt:file] > nt:hierarchyNode
            + jcr:content (nt:base) primary mandatory
          

           

          where

           

          [mix:created] mixin
            - jcr:created (date) protected  
            - jcr:createdBy (string) protected
          
          [nt:hierarchyNode] > mix:created abstract 
          

           

          This means that a node that has a primary type of "nt:file" is only valid if it has a mandatory child node called "jcr:content" that itself is valid. The file system connector expects this child node to be a "nt:resource" subclass. But your code is not creating this child node, and thus the "nt:file" node is not valid, and the exception is actually perfectly correct.

           

          Your code would work if it were changed to be something like the following:

           

          session = repository.login("default");
          Node root = session.getRootNode();
          Node fed = root.getNode("federation"); <-- Node under federation
          Node folder = fed.addNode("Folder" + rnd.nextInt(), "nt:folder");
          Node file = fed.addNode("File" + rnd.nextInt(), "nt:file"); 
          Node content = file.addNode("jcr:content", "nt:resource");
          Binary binary = session.getValueFactory().createBinary(...);
          content.setProperty("jcr:data",binary); 
          session.save();
          
          • 2. Re: Modeshape 3.1.1 and federation
            Ivan Vasyliev Newbie

            I was looking at 2.x filesystem connector:

            https://github.com/vasilievip/modeshape/blob/2.x/extensions/modeshape-connector-filesystem/src/test/java/org/modeshape/connector/filesystem/FileSystemConnectorWritableTest.java#L157

             

            And it was handling this I assume:

             

                @Test

                public void shouldBeAbleToCreateFileWithNoContent() {

                    graph.create("/testEmptyFile").with(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FILE).orReplace().and();

             

             

                    File newFile = new File(testWorkspaceRoot, "testEmptyFile");

                    assertThat(newFile.exists(), is(true));

                    assertThat(newFile.isFile(), is(true));

                }

            • 3. Re: Modeshape 3.1.1 and federation
              Ivan Vasyliev Newbie

              I've got strange error message when I'm trying to work with federated node via CMIS (see my code here  https://github.com/vasilievip/modeshape-examples/tree/modeshape-cmis-federation/modeshape-cmis-federation ):

               

               

              org.modeshape.jcr.cache.NodeNotFoundInParentException: Cannot locate child node: 94dd693eaa9871//testFolder within parent: 94dd693eaa9871/

              at org.modeshape.jcr.cache.document.LazyCachedNode.parentReferenceToSelf(LazyCachedNode.java:214)

              at org.modeshape.jcr.cache.document.LazyCachedNode.getSegment(LazyCachedNode.java:252)

              at org.modeshape.jcr.cache.document.LazyCachedNode.getPath(LazyCachedNode.java:261)

              at org.modeshape.jcr.AbstractJcrNode.path(AbstractJcrNode.java:233)

              at org.modeshape.jcr.JcrNode.getPath(JcrNode.java:81)

              at org.apache.chemistry.opencmis.jcr.PathManager.isRoot(PathManager.java:74)

              at org.apache.chemistry.opencmis.jcr.JcrNode.isRoot(JcrNode.java:162)

              at org.apache.chemistry.opencmis.jcr.JcrFolder.getObjectId(JcrFolder.java:246)

              at org.apache.chemistry.opencmis.jcr.JcrNode.getId(JcrNode.java:143)

              at org.apache.chemistry.opencmis.jcr.JcrRepository.createFolder(JcrRepository.java:294)

              at org.apache.chemistry.opencmis.jcr.JcrService.createFolder(JcrService.java:202)

              at org.apache.chemistry.opencmis.server.support.CmisServiceWrapper.createFolder(CmisServiceWrapper.java:750)

              at org.apache.chemistry.opencmis.server.impl.webservices.ObjectService.createFolder(ObjectService.java:130)

               

              Not federated node works fine, please advise

               

              PS: It assumes fix for https://issues.jboss.org/browse/MODE-1789 in place

              • 4. Re: Modeshape 3.1.1 and federation
                Randall Hauch Master

                Are you federating nodes underneath the root? If so, can you try federating nodes under a child of the root?

                • 5. Re: Modeshape 3.1.1 and federation
                  Ivan Vasyliev Newbie

                  Yes, I have initial content file which creates "federation" folder, so projections looks as afollowing:

                   

                   

                   

                  {
                      "name" : "FederatedRepository",
                      "jndiName" : "",
                      "workspaces" : {
                          "default" : "default",
                          "allowCreation" : true,
                          "initialContent" : {
                              "default" : "myInitialContent.xml",
                          }
                      },
                      "security" : {
                          "anonymous" : {
                              "roles" : ["readonly","readwrite","admin"],
                              "useOnFailedLogin" : false
                          }
                      },
                      "storage" : {
                          "cacheName" : "persistentRepository",
                          "cacheConfiguration" : "infinispan-federation-persistent.xml"
                      },
                      "externalSources" : {
                          "file-source" : {
                                 "classname" : "org.modeshape.connector.filesystem.FileSystemConnector",
                              "directoryPath" : "target/classes",
                              "extraPropertiesStorage" : "json",
                              "projections" : [
                                   "default:/federation => /",
                              ]
                          }
                      }
                  }

                   

                   

                  <?xml version="1.0" encoding="UTF-8"?>
                  <jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0">
                      <federation jcr:mixinTypes="mix:created, mix:lastModified" jcr:primaryType="nt:folder"/>
                  </jcr:root>

                  • 6. Re: Modeshape 3.1.1 and federation
                    Ivan Vasyliev Newbie

                    There is also strange 2 nodes I see via CMIS browser:

                    - First is mounted via external sources "federation" proxy with incorrect ID (contains "/" character)

                    - Second is actual folder created via initialContext.xml

                     

                    I assume the behaviour should be as in linux filesystem: when you mount device under some path, it becames not available until "unmount" operation.

                     

                     

                    !Selection_003.png!

                    • 7. Re: Modeshape 3.1.1 and federation
                      Randall Hauch Master

                      At this point it's hard to tell what is a CMIS issue and what is a federation issue. Can you replicate this just using Java and JCR? Ideally, a test case that replicates the problem would be immeasurably helpful to us.

                      • 8. Re: Modeshape 3.1.1 and federation
                        Ivan Vasyliev Newbie

                        Randall Hauch wrote:

                         

                        Can you replicate this just using Java and JCR? Ideally, a test case that replicates the problem would be immeasurably helpful to us.

                        Sure, but looks like w/o CMIS all works fine. Will look into with debugger and provide my findings

                        Regarding https://issues.jboss.org/browse/MODE-1772

                        I need control over new nodes but I need to know object type to create ID. In my use case - external repository API provides functions to create folders and documents and I need to distinguish which object is going to be created to create to generate ID.

                        So code below must know information about node (nt:file or nt:folder or sub-types of them)

                         

                        {code}public String newDocumentKey( String parentKey,  Name documentName );{code}

                         

                        Should I submit new issue or reopen existing?

                        • 9. Re: Modeshape 3.1.1 and federation
                          Ivan Vasyliev Newbie


                          Randall Hauch wrote:

                           

                          At this point it's hard to tell what is a CMIS issue and what is a federation issue. Can you replicate this just using Java and JCR? Ideally, a test case that replicates the problem would be immeasurably helpful to us.

                           

                          This is not a CMIS issue.  After startup of the engine the code below

                          {code}

                                      System.out.println("******************");

                                      Node root1 = session.getNode("/");

                                      NodeIterator it = root1.getNodes();

                                      while (it.hasNext()){

                                          Node node = (Node)it.next();

                                          System.out.println(node.getName()+" => "+node.getIdentifier());

                                      }

                           

                                      System.out.println("******************");

                          {code}

                           

                          Results into:

                           

                          {code}

                          ******************

                          federation => 94dd693eaa9871/

                          jcr:system => 9db8771317f1e7jcr:system

                          federation => 4feed675-bbfe-49a5-af07-83952b778bb2

                          ******************

                          {code}

                           

                           

                          My config here:

                          https://github.com/vasilievip/modeshape-examples/tree/federation2/modeshape-filesystem-store-example

                           

                          This is actual federation, but ID is wrong

                          federation => 94dd693eaa9871/

                           

                          This is imported node:

                          federation => 4feed675-bbfe-49a5-af07-83952b778bb2

                           

                          I'm working on testcase

                          • 10. Re: Modeshape 3.1.1 and federation
                            Ivan Vasyliev Newbie

                            I figured out the issue: new node in federation does change its ID after save

                             

                            {code}

                             

                            Node root = session.getNode("/fs");

                            Node folder1 = root.addNode("test", "nt:folder");

                            System.out.println(folder1.getIdentifier());

                            session.save();

                            Node folder2 = root.getNode("test");

                            System.out.println(folder2.getIdentifier());

                            {code}

                             

                             

                            Result:

                            {quote}

                             

                            94dd693eaa9871//test

                            94dd693eaa9871/test

                            {quote}

                             

                             

                             

                            Randall, is this an issue which needs to be logged to modeshape jira or this works as expected? I assume apache chemistry is going to get fix from me soon.

                            • 11. Re: Modeshape 3.1.1 and federation
                              Horia Chiorean Master

                              The extra "/" may be related to a bug in the FileSystemConnector that was already fixed in 3.1.2.SNAPSHOT.

                               

                              Could you pls try with the latest SNAPSHOT ? Thanks.

                               

                              Or, could you update/point me to the code you're running in this example and I can try it locally.

                              • 12. Re: Modeshape 3.1.1 and federation
                                Randall Hauch Master

                                Randall, is this an issue which needs to be logged to modeshape jira or this works as expected?

                                Just because the ID happens to be changing doesn't mean that ModeShape can deal with it. IMO, it's a bug that may have already been fixed (see Horia's previous comment), or it might be a problem in the federation logic or in the connector. (BTW, is this the file systm connector or a custom connector?) References to such nodes will be broken upon save, since the references will point to the original ID (not the post-save ID).

                                 

                                 

                                I assume apache chemistry is going to get fix from me soon.

                                I'm not sure what this means. Are you writing/using a CMIS connector? (Please remember that we're dealing with lots of different people doing different things, and we can't always keep all the details separate. We really try, but sometimes being a little be clearer helps us out a lot.)

                                • 14. Re: Modeshape 3.1.1 and federation
                                  Horia Chiorean Master

                                  This is a valid FileSystemConnector bug and is caused by the implementation of the newDocumentId() method by the FSConnector, in the case when the root folder of the connector is "/".

                                   

                                  Please open a JIRA issue for the FileSystemConnector. Thanks

                                  1 2 Previous Next