3 Replies Latest reply on Jan 9, 2013 10:48 AM by Randall Hauch

    Issues with binary storage.

    Gurpreet Singh Newbie

      Hi - I am new to ModeShape and Java. My intention is to develop a distributed file server application which will server clients over WebDav and through URL. The files will be replicated to other sever in different geographies. In am currently testing the Binary file store example and could not able to create a persistent store.

       

      I see that the Binary store is unable to create a store and using the temp directory of windows. I know if the infinispan-configuration.xml is configured properly, it will end up creating a temp store. I couldn't figure out where I am going wrong. Here are resource files. Also, please help me with the approach I should take for my use case.

       

       

      /*
       * To change this template, choose Tools | Templates
       * and open the template in the editor.
       */
       import java.net.URL;
       import javax.jcr.Node;
       import javax.jcr.Repository;
       import javax.jcr.RepositoryException;
       import javax.jcr.Session;
       import org.modeshape.common.collection.Problems;
       import org.modeshape.jcr.ModeShapeEngine;
       import org.modeshape.jcr.RepositoryConfiguration;
      
      /**
       *
       * @author test
       */
      public class ModeShapeTest1 {
      
          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              // Create and start the engine ...
              ModeShapeEngine engine = new ModeShapeEngine();
              engine.start();
      
              // Load the configuration for a repository via the classloader (can also use path to a file)...
              Repository repository = null;
              String repositoryName = null;
              try {
                  URL url = ModeShapeTest1.class.getClassLoader().getResource("my-repository-config.json");
                  System.out.println(url);
                  RepositoryConfiguration config = RepositoryConfiguration.read(url);
                  System.out.println("Cache Config : "+ config.getStoreName());
                  Long lng = config.getBinaryStorage().getMinimumBinarySizeInBytes();
                  System.out.println(lng);
                  
                  // We could change the name of the repository programmatically ...
                  // config = config.withName("Some Other Repository");
      
                  // Verify the configuration for the repository ...
                  
                  Problems problems = config.validate();
                  if (problems.hasErrors()) {
       System.err.println("Problems starting the engine.");
                      System.err.println(problems);
                      System.exit(-1);
                      
                  }
      
                  // Deploy the repository ...
                  repository = engine.deploy(config);
                  repositoryName = config.getName();
                  
                  System.out.println(repositoryName + " Storage : " + config.getStoreName());
              } catch (Throwable e) {
                  e.printStackTrace();
                  System.exit(-1);
                  return;
              }
      
              Session session = null;
              try {
                  // Get the repository
                  repository = engine.getRepository(repositoryName);
                   
                  // Create a session ...
                  
                  session = repository.login("default");
                  
                 // Get the root node ...
                  Node root = session.getRootNode();
                  assert root != null;
                  
                  session.save();
                              
                  root.addNode("MyNode1");
                  
       
                  System.out.println("Found the root node in the \"" + session.getWorkspace().getName() + "\" workspace");
                  
              } catch (RepositoryException e) {
                  e.printStackTrace();
              } finally {
                  if (session != null) session.logout();
                  System.out.println("Shutting down engine ...");
                  try {
                      engine.shutdown().get();
       System.out.println("Success!");
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
          }
      
          }
      }
      
      

       

      --------------------------------
      my-repository-config.json
      --------------------------------
      {
          "name" : "Data-Repository",
          "workspaces" : {
              "predefined" : ["otherWorkspace"],
              "default" : "default",
              "allowCreation" : true
          },
          "security" : {
              "anonymous" : {
                  "roles" : ["readonly","readwrite","admin"],
                  "useOnFailedLogin" : false
              }
          },
        "storage" : {
              "cacheConfiguration" : "Configuration.xml",
              "cacheName" : "DataRepository",
              "binaryStorage" : {
                  "type" : "file",
                  "directory" : "store",
       "minimumBinarySizeInBytes" : 512
                  }
        }
      }
      

       

      ---------------------------------------
      infinispan-configuration.xml
      ---------------------------------------
      <?xml version="1.0" encoding="UTF-8"?>
      <infinispan
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd"
       xmlns="urn:infinispan:config:5.1">
      
          <global/>
      
          <namedCache name="DataRepository">
              <transaction
                      transactionManagerLookupClass ="org.infinispan.transaction.lookup.DummyTransactionManagerLookup"
                      transactionMode ="TRANSACTIONAL"
                      lockingMode ="OPTIMISTIC"/>
              <loaders
                      passivation ="false"
                      shared ="false"
                      preload ="false">
                  <loader
                          class ="org.infinispan.loaders.file.FileCacheStore"
                          fetchPersistentState ="false"
                          purgeOnStartup ="false">
                      <properties>
                          <property name ="location" value="store"/>
                      </properties>
                  </loader>
              </loaders>
          </namedCache>
      </infinispan>
      
      

       

      -------------------
      Output Logs
      ------------------
      
      run:
      file:/C:/Documents%20and%20Settings/test/My%20Documents/NetBeansProjects/ModeShapeTest1/build/classes/my-repository-config.json
      Cache Config : DataRepository //I see its picking up values from JSON file
      512
      Data-Repository Storage : DataRepository
      Jan 9, 2013 5:33:13 PM org.modeshape.jcr.ModeShape <clinit>
      INFO: Initializing ModeShape version 3.0.1.Final
      Jan 9, 2013 5:33:13 PM org.modeshape.jcr.value.binary.TransientBinaryStore newTempDirectory
      INFO: ModeShape is using the following directory for transient storage of binary values: C:\DOCUME~1\test\LOCALS~1\Temp
      Jan 9, 2013 5:33:14 PM org.infinispan.factories.GlobalComponentRegistry start
      INFO: ISPN000128: Infinispan version: Infinispan 'Brahma' 5.1.2.FINAL
      Jan 9, 2013 5:33:17 PM org.hibernate.search.Version <clinit>
      INFO: HSEARCH000034: Hibernate Search 4.1.1.Final
      Jan 9, 2013 5:33:17 PM org.hibernate.annotations.common.Version <clinit>
      INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
      Jan 9, 2013 5:33:18 PM org.hibernate.search.indexes.serialization.avro.impl.AvroSerializationProvider <init>
      INFO: HSEARCH000079: Serialization protocol version 1.0
      
      Found the root node in the "default" workspace
      Shutting down engine ...
      Success!
      BUILD SUCCESSFUL (total time: 8 seconds)
      
      
        • 1. Re: Issues with binary storage.
          Randall Hauch Master

          Those two "transient" binary store messages have been problematic because they don't necessarily refer to the repository's binary store; the TransientBinaryStore is a singleton that is initialized statically and therefore always initialized.

           

          I noticed that your code isn't actually setting a BINARY value on a node in the repository. I'd suggest trying that, and I think the repository is lazily creating the directory for the binary store.

           

          I'll log a JIRA to correct the logging, but please let us know if you're still having problems.

           

          BTW, I think you have an error in your JSON configuration file.

           

           

          --------------------------------
          my-repository-config.json
          --------------------------------
          {
              "name" : "Data-Repository",
              "workspaces" : {
                  "predefined" : ["otherWorkspace"],
                  "default" : "default",
                  "allowCreation" : true
              },
              "security" : {
                  "anonymous" : {
                      "roles" : ["readonly","readwrite","admin"],
                      "useOnFailedLogin" : false
                  }
              },
            "storage" : {
                  "cacheConfiguration" : "Configuration.xml",
                  "cacheName" : "DataRepository",
                  "binaryStorage" : {
                      "type" : "file",
                      "directory" : "store",
           "minimumBinarySizeInBytes" : 512
                      }
            }
          }
          

           

           

          The "storage.cacheConfiguration" field has a value of "Configuration.xml". This should point to the Infinispan configuration file, which you've described as being named "infinispan-configuration.xml".

          • 2. Re: Issues with binary storage.
            Gurpreet Singh Newbie

            Thanks Randall - However I have the infinispan configuration as 'Configuration.xml' in my version of JSON, so its not the issues. I forgot to update the JSON when posting it. Could you please help me with the code to store BINARY value on a node or maybe point me to an example.

            • 3. Re: Issues with binary storage.
              Randall Hauch Master

              Sure. Here's a simple example of creating an 'nt:file' node that represents a file containing the text "something":

               

                      Node root = session.getRootNode();

                      Node projectNode = root.addNode("myFolder", "nt:folder");

                      Node fileNode = projectNode.addNode("fileNode", "nt:file");

                      Node contentNode = fileNode.addNode("jcr:content", "nt:resource");

                      Binary binaryValue = session.getValueFactory().createBinary(new ByteArrayInputStream("something".getBytes()));

                      contentNode.setProperty("jcr:data", binaryValue);

                      contentNode.setProperty("jcr:lastModified", Calendar.getInstance());

                      contentNode.setProperty("jcr:mimeType", "application/octet-stream"); // or as appropriate for your file


              Normally you'd create the Binary value using the "createBinary(InputStream)" method and supply a real InputStream.

               

              Our WebDAV implementation works with such 'nt:file' nodes and exposes them as files. Same with 'nt:folder' nodes (which are simpler). For some information about storing files and folders inside JCR, see our documentation and this blog post.