Search in sources :

Example 1 with RepositoryConfiguration

use of org.modeshape.jcr.RepositoryConfiguration in project kylo by Teradata.

the class ModeShapeEngineConfig method metadataRepoConfig.

@Bean
public RepositoryConfiguration metadataRepoConfig() throws IOException {
    // for variable substitution in the ModeShape json config.
    for (String prop : CONFIG_PROPS) {
        if (this.environment.containsProperty(prop)) {
            System.setProperty(prop, this.environment.getProperty(prop));
        }
    }
    File dir = DEFAULT_INDEX_DIR;
    if (this.environment.containsProperty(INDEX_DIR_PROP)) {
        String idxPath = this.environment.getProperty(INDEX_DIR_PROP);
        dir = new File(idxPath);
    }
    try {
        // Create index directory if necessary.
        dir.mkdirs();
    } catch (Exception e) {
        log.error("Failed to verify Modeshape index directory in property: {}", INDEX_DIR_PROP, e);
        throw new IllegalStateException("Failed to verify Modeshape index directory in property: " + INDEX_DIR_PROP, e);
    }
    ClassPathResource res = new ClassPathResource("/metadata-repository.json");
    final AtomicReference<RepositoryConfiguration> config = new AtomicReference<>(RepositoryConfiguration.read(res.getURL()));
    repositoryIndexConfiguration.ifPresent(idxConfig -> {
        RepositoryConfiguration updatedConfigWithIndexes = idxConfig.build();
        EditableDocument original = config.get().edit();
        EditableDocument added = updatedConfigWithIndexes.edit();
        original.merge(added);
        RepositoryConfiguration updatedConfig = new RepositoryConfiguration(original, config.get().getName());
        log.debug("Original ModeShape configuration: {}", config.toString());
        log.debug("ModeShape indexing configuration: {}", updatedConfigWithIndexes.toString());
        log.debug("Updated ModeShape configuration: {}", updatedConfig.toString());
        config.set(updatedConfig);
        log.info("ModeShape indexing configured");
    });
    Problems problems = config.get().validate();
    if (problems.hasErrors()) {
        log.error("Problems with the ModeShape repository configuration: \n{}", problems);
        throw new RuntimeException("Problems with the ModeShape repository configuration: " + problems);
    }
    return config.get();
}
Also used : Problems(org.modeshape.common.collection.Problems) EditableDocument(org.modeshape.schematic.document.EditableDocument) AtomicReference(java.util.concurrent.atomic.AtomicReference) RepositoryConfiguration(org.modeshape.jcr.RepositoryConfiguration) File(java.io.File) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) Bean(org.springframework.context.annotation.Bean)

Example 2 with RepositoryConfiguration

use of org.modeshape.jcr.RepositoryConfiguration in project kylo by Teradata.

the class ElasticSearchRestModeShapeConfigurationService method build.

@Override
public RepositoryConfiguration build() {
    RepositoryConfiguration repositoryConfiguration;
    final String EMPTY_CONFIG = "{}";
    final String KYLO_CATEGORIES = "kylo-categories";
    final String KYLO_FEEDS = "kylo-feeds";
    final String INDEXES = "indexes";
    final String INDEX_PROVIDERS = "indexProviders";
    try {
        repositoryConfiguration = RepositoryConfiguration.read(EMPTY_CONFIG);
    } catch (ParsingException | FileNotFoundException e) {
        e.printStackTrace();
        return null;
    }
    Editor editor = repositoryConfiguration.edit();
    EditableDocument indexesDocument = editor.getOrCreateDocument(INDEXES);
    EditableDocument categoriesIndexDocument = indexesDocument.getOrCreateDocument(KYLO_CATEGORIES);
    EditableDocument feedsIndexDocument = indexesDocument.getOrCreateDocument(KYLO_FEEDS);
    categoriesIndexDocument.putAll(getCategoriesIndexConfiguration());
    feedsIndexDocument.putAll(getFeedsIndexConfiguration());
    EditableDocument indexProvidersDocument = editor.getOrCreateDocument(INDEX_PROVIDERS);
    EditableDocument elasticSearchIndexProviderDocument = indexProvidersDocument.getOrCreateDocument(ELASTIC_SEARCH);
    elasticSearchIndexProviderDocument.putAll(getElasticSearchIndexProviderConfiguration());
    repositoryConfiguration = new RepositoryConfiguration(editor, repositoryConfiguration.getName());
    return repositoryConfiguration;
}
Also used : EditableDocument(org.modeshape.schematic.document.EditableDocument) ParsingException(org.modeshape.schematic.document.ParsingException) FileNotFoundException(java.io.FileNotFoundException) RepositoryConfiguration(org.modeshape.jcr.RepositoryConfiguration) Editor(org.modeshape.schematic.document.Editor)

Example 3 with RepositoryConfiguration

use of org.modeshape.jcr.RepositoryConfiguration in project kylo by Teradata.

the class ElasticSearchModeShapeConfigurationService method build.

@Override
public RepositoryConfiguration build() {
    RepositoryConfiguration repositoryConfiguration;
    final String EMPTY_CONFIG = "{}";
    final String KYLO_CATEGORIES = "kylo-categories";
    final String KYLO_FEEDS = "kylo-feeds";
    final String INDEXES = "indexes";
    final String INDEX_PROVIDERS = "indexProviders";
    try {
        repositoryConfiguration = RepositoryConfiguration.read(EMPTY_CONFIG);
    } catch (ParsingException | FileNotFoundException e) {
        log.error("Error loading the repository configuration", e);
        return null;
    }
    Editor editor = repositoryConfiguration.edit();
    EditableDocument indexesDocument = editor.getOrCreateDocument(INDEXES);
    EditableDocument categoriesIndexDocument = indexesDocument.getOrCreateDocument(KYLO_CATEGORIES);
    EditableDocument feedsIndexDocument = indexesDocument.getOrCreateDocument(KYLO_FEEDS);
    categoriesIndexDocument.putAll(getCategoriesIndexConfiguration());
    feedsIndexDocument.putAll(getFeedsIndexConfiguration());
    EditableDocument indexProvidersDocument = editor.getOrCreateDocument(INDEX_PROVIDERS);
    EditableDocument elasticSearchIndexProviderDocument = indexProvidersDocument.getOrCreateDocument(ELASTIC_SEARCH);
    elasticSearchIndexProviderDocument.putAll(getElasticSearchIndexProviderConfiguration());
    repositoryConfiguration = new RepositoryConfiguration(editor, repositoryConfiguration.getName());
    return repositoryConfiguration;
}
Also used : EditableDocument(org.modeshape.schematic.document.EditableDocument) ParsingException(org.modeshape.schematic.document.ParsingException) FileNotFoundException(java.io.FileNotFoundException) RepositoryConfiguration(org.modeshape.jcr.RepositoryConfiguration) Editor(org.modeshape.schematic.document.Editor)

Example 4 with RepositoryConfiguration

use of org.modeshape.jcr.RepositoryConfiguration in project kylo by Teradata.

the class SolrSearchModeShapeConfigurationService method build.

@Override
public RepositoryConfiguration build() {
    RepositoryConfiguration repositoryConfiguration;
    final String EMPTY_CONFIG = "{}";
    final String KYLO_CATEGORIES_METADATA = "kylo-categories-metadata";
    final String KYLO_FEEDS_METADATA = "kylo-feeds-metadata";
    final String INDEXES = "indexes";
    final String INDEX_PROVIDERS = "indexProviders";
    try {
        repositoryConfiguration = RepositoryConfiguration.read(EMPTY_CONFIG);
    } catch (ParsingException | FileNotFoundException e) {
        e.printStackTrace();
        repositoryConfiguration = new RepositoryConfiguration();
    }
    Editor editor = repositoryConfiguration.edit();
    EditableDocument indexesDocument = editor.getOrCreateDocument(INDEXES);
    EditableDocument categoriesIndexDocument = indexesDocument.getOrCreateDocument(KYLO_CATEGORIES_METADATA);
    EditableDocument feedsIndexDocument = indexesDocument.getOrCreateDocument(KYLO_FEEDS_METADATA);
    categoriesIndexDocument.putAll(getCategoriesIndexConfiguration());
    feedsIndexDocument.putAll(getFeedsIndexConfiguration());
    EditableDocument indexProvidersDocument = editor.getOrCreateDocument(INDEX_PROVIDERS);
    EditableDocument localNamedIndexProviderDocument = indexProvidersDocument.getOrCreateDocument(LUCENE);
    localNamedIndexProviderDocument.putAll(getLuceneIndexProviderConfiguration());
    repositoryConfiguration = new RepositoryConfiguration(editor, repositoryConfiguration.getName());
    return repositoryConfiguration;
}
Also used : EditableDocument(org.modeshape.schematic.document.EditableDocument) ParsingException(org.modeshape.schematic.document.ParsingException) FileNotFoundException(java.io.FileNotFoundException) RepositoryConfiguration(org.modeshape.jcr.RepositoryConfiguration) Editor(org.modeshape.schematic.document.Editor)

Example 5 with RepositoryConfiguration

use of org.modeshape.jcr.RepositoryConfiguration in project kylo by Teradata.

the class JcrNotebooksApp method main.

public static void main(String... args) throws RepositoryException, IOException {
    ModeShapeEngine engine = new ModeShapeEngine();
    engine.start();
    Repository repository = null;
    String repositoryName = null;
    URL url = JcrNotebooksApp.class.getClassLoader().getResource("sandbox/notebook-test-repository.json");
    RepositoryConfiguration config = RepositoryConfiguration.read(url);
    // 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();
    Session session = null;
    JcrTools tools = new JcrTools();
    tools.setDebug(true);
    // get the repository
    repository = engine.getRepository(repositoryName);
    Project p;
    session = repository.login("default");
    // Create the '/files' node that is an 'nt:folder' ...
    Node root = session.getRootNode();
    /*
        Node filesNode = root.addNode("notebooks", "nt:folder");

        InputStream stream =
            new BufferedInputStream(new FileInputStream("/Users/th186036/filesystemconnector/hello.txt"));

        // Create an 'nt:file' node at the supplied path ...
        Node fileNode = filesNode.addNode("hello.txt", "nt:file");

        // Upload the file to that node ...
        Node contentNode = fileNode.addNode("jcr:content", "nt:resource");
        Binary binary = session.getValueFactory().createBinary(stream);
        contentNode.setProperty("jcr:data", binary);

        session.save();
        */
    session = repository.login("default");
    Node project = JcrUtil.getOrCreateNode(root, "Project1", JcrProject.NODE_TYPE);
    List<Node> nodes = JcrUtil.getNodesOfType(root, JcrProject.NODE_TYPE);
    logger.debug("Node list {}", nodes);
    // List<JcrEntity> fileNodes = JcrUtil.getChildrenMatchingNodeType(root, JcrProject.NODE_TYPE, JcrEntity.class, null);
    // logger.debug("Node list {}", nodes );
    logger.debug("Modeshape subgraph");
    tools.printSubgraph(root);
    if (session != null) {
        session.logout();
    }
    logger.info("Shutting down engine ...");
    try {
        engine.shutdown().get();
        logger.info("Success!");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Node(javax.jcr.Node) ModeShapeEngine(org.modeshape.jcr.ModeShapeEngine) URL(java.net.URL) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) Problems(org.modeshape.common.collection.Problems) JcrProject(com.thinkbiganalytics.metadata.modeshape.project.JcrProject) Project(com.thinkbiganalytics.metadata.api.project.Project) Repository(org.modeshape.jcr.api.Repository) RepositoryConfiguration(org.modeshape.jcr.RepositoryConfiguration) JcrTools(org.modeshape.jcr.api.JcrTools) Session(org.modeshape.jcr.api.Session)

Aggregations

RepositoryConfiguration (org.modeshape.jcr.RepositoryConfiguration)5 EditableDocument (org.modeshape.schematic.document.EditableDocument)4 FileNotFoundException (java.io.FileNotFoundException)3 Editor (org.modeshape.schematic.document.Editor)3 ParsingException (org.modeshape.schematic.document.ParsingException)3 IOException (java.io.IOException)2 Problems (org.modeshape.common.collection.Problems)2 Project (com.thinkbiganalytics.metadata.api.project.Project)1 JcrProject (com.thinkbiganalytics.metadata.modeshape.project.JcrProject)1 File (java.io.File)1 URL (java.net.URL)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 ModeShapeEngine (org.modeshape.jcr.ModeShapeEngine)1 JcrTools (org.modeshape.jcr.api.JcrTools)1 Repository (org.modeshape.jcr.api.Repository)1 Session (org.modeshape.jcr.api.Session)1 Bean (org.springframework.context.annotation.Bean)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1