/** * Deploy a new repository with the given configuration. This method will fail if this engine already contains a repository * with the specified name. * * @param repositoryConfiguration the configuration for the repository * @return the deployed repository instance, which must be {@link #startRepository(String) started} before it can be used; * never null * @throws ConfigurationException if the configuration is not valid * @throws RepositoryException if there is already a deployed repository with the specified name, or if there is a problem * deploying the repository * @throws IllegalArgumentException if the configuration is null * @see #deploy(RepositoryConfiguration) * @see #update(String, Changes) * @see #undeploy(String) */ public JcrRepository deploy( final RepositoryConfiguration repositoryConfiguration ) throws ConfigurationException, RepositoryException { return deploy(repositoryConfiguration, null); }
/** * Deploy a new repository with the given configuration. This method will fail if this engine already contains a repository * with the specified name. * * @param repositoryConfiguration the configuration for the repository * @return the deployed repository instance, which must be {@link #startRepository(String) started} before it can be used; * never null * @throws ConfigurationException if the configuration is not valid * @throws RepositoryException if there is already a deployed repository with the specified name, or if there is a problem * deploying the repository * @throws IllegalArgumentException if the configuration is null * @see #deploy(RepositoryConfiguration) * @see #update(String, Changes) * @see #undeploy(String) */ public JcrRepository deploy( final RepositoryConfiguration repositoryConfiguration ) throws ConfigurationException, RepositoryException { return deploy(repositoryConfiguration, null); }
@Override public Repository getRepository(Map parameters) throws RepositoryException { String name = (String) parameters.get(org.modeshape.jcr.api.RepositoryFactory.REPOSITORY_NAME); logger.info("Accessing repository " + name); Map defaultParameters = getRepositoryConfiguration(name); defaultParameters.putAll(parameters); if (!engine.getRepositoryNames().contains(name)) { try { File configurationFile = new File(new File(applicationConfiguration.getBaseDir(), "conf"), (String) defaultParameters.get(org.modeshape.jcr.api.RepositoryFactory.URL)); engine.deploy(RepositoryConfiguration.read(configurationFile)); } catch (ParsingException e) { logger.error(e.getMessage(), e); } catch (FileNotFoundException e) { logger.error(e.getMessage(), e); } } return engine.getRepository(name); }
@Bean(name = "metadataJcrRepository") public Repository metadataJcrRepository(@Qualifier("springApplicationContext")SpringApplicationContext springApplicationContext) throws Exception { JcrRepository repo = modeShapeEngine(springApplicationContext).deploy(metadataRepoConfig()); try { Problems problems = repo.getStartupProblems(); if (problems.hasErrors()) { log.error("Problems starting the metadata ModeShape repository: {} \n{}", repo.getName(), problems); throw new RuntimeException("Problems starting the ModeShape metadata repository: " + problems); } } catch (NullPointerException e) { // This gets thrown sometimes when attempting to retrieve the startup problems. It looks // like it is probably a ModeShape bug that can happen even when the repo starts successfully. // Just log a warning about it and proceed as if everything is fine. log.warn("Retrieved a NullPointerException when attempting to check for startup errors - this is likely a ModeShape bug and can usually be ignored"); } return repo; } }
/** * Generate a JCR repository from the given configuration * */ @PostConstruct public void buildRepository() { try { LOGGER.info("Using repo config (classpath): {}", repositoryConfiguration.getURL()); getPropertiesLoader().loadSystemProperties(); final RepositoryConfiguration config = RepositoryConfiguration.read(repositoryConfiguration.getURL()); repository = modeShapeEngine.deploy(config); // next line ensures that repository starts before the factory is used. final org.modeshape.common.collection.Problems problems = repository.getStartupProblems(); for (final org.modeshape.common.collection.Problem p : problems) { LOGGER.error("ModeShape Start Problem: {}", p.getMessageString()); // TODO determine problems that should be runtime errors } } catch (final Exception e) { throw new RepositoryRuntimeException(e); } }
private Repository deployRepository( String uri ) throws ResourceException { if (engine == null) { engine = ra.getEngine(); if (engine == null) { throw new ResourceException("Engine not started by resource adapter!"); } } // load configuration RepositoryConfiguration config = null; try { URL url = isAbsolutePath(uri) ? getClass().getClassLoader().getResource(uri) : new URL(uri); config = RepositoryConfiguration.read(url); } catch (Exception e) { throw new ResourceException(e); } // check configuration Problems problems = config.validate(); if (problems.hasErrors()) { throw new ResourceException(problems.toString()); } try { return engine.deploy(config); } catch (RepositoryException e) { throw new ResourceException(e); } }
@Test public void shouldDeployRepositoryConfiguration() throws Exception { engine.start(); JcrRepository repository = engine.deploy(config); assertThat(repository, is(notNullValue())); assertThat(repository, is(notNullValue())); }
protected void startEngineAndDeployRepositoryAndLogIn() throws Exception { print("starting engine"); engine.start(); assertThat(engine.getState(), is(State.RUNNING)); print("deploying repository"); repository = engine.deploy(config); session = repository.login(); assertThat(session.getRootNode(), is(notNullValue())); }
@Test public void shouldNotAutomaticallyStartDeployedRepositories() throws Exception { engine.start(); JcrRepository repository = engine.deploy(config); String name = repository.getName(); assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); engine.startRepository(name).get(); // blocks assertThat(engine.getRepositoryState(name), is(State.RUNNING)); engine.shutdownRepository(name).get(); // blocks assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); }
protected JcrRepository repository( Map<?, ?> parameters, String repositoryURL ) throws RepositoryException { String repositoryName = repositoryNameFrom(repositoryURL, parameters); JcrRepository repository = lookForAlreadyDeployedRepositoryKey(repositoryURL); if (repository != null) { return repository; } RepositoryConfiguration configuration = loadRepositoryConfigurationFrom(repositoryURL); repository = lookForAlreadyDeployedRepositoryName(configuration.getName()); if (repository != null) { return StringUtil.isBlank(repositoryName) || configuration.getName().equalsIgnoreCase(repositoryName) ? repository : null; } // Now deploy the new repository ... try { repository = ENGINE.deploy(configuration); repository.start(); // The name might not match the configuration's name ... if (StringUtil.isBlank(repositoryName) || repository.getName().equals(repositoryName)) { return repository; } LOG.warn(JcrI18n.repositoryNotFound, repositoryName, repositoryURL, parameters); return null; } catch (RepositoryException re) { throw re; } catch (Exception e) { throw new RepositoryException(e); } }
@Test( expected = ConfigurationException.class ) public void shouldFailToDeployRepositoryConfigurationWithoutName() throws Throwable { config = new RepositoryConfiguration(); // without a name! assertThat(config.validate().hasErrors(), is(true)); engine.start(); engine.deploy(config); }
protected JcrRepository repository( Map<?, ?> parameters, String repositoryURL ) throws RepositoryException { String repositoryName = repositoryNameFrom(repositoryURL, parameters); JcrRepository repository = lookForAlreadyDeployedRepositoryKey(repositoryURL); if (repository != null) { return repository; } RepositoryConfiguration configuration = loadRepositoryConfigurationFrom(repositoryURL); repository = lookForAlreadyDeployedRepositoryName(configuration.getName()); if (repository != null) { return StringUtil.isBlank(repositoryName) || configuration.getName().equalsIgnoreCase(repositoryName) ? repository : null; } // Now deploy the new repository ... try { repository = ENGINE.deploy(configuration); repository.start(); // The name might not match the configuration's name ... if (StringUtil.isBlank(repositoryName) || repository.getName().equals(repositoryName)) { return repository; } LOG.warn(JcrI18n.repositoryNotFound, repositoryName, repositoryURL, parameters); return null; } catch (RepositoryException re) { throw re; } catch (Exception e) { throw new RepositoryException(e); } }
@Test public void shouldAutomaticallyStartRepositoryUponLogin() throws Exception { engine.start(); JcrRepository repository = engine.deploy(config); String name = repository.getName(); assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); assertThat(repository.getState(), is(State.NOT_RUNNING)); for (int i = 0; i != 4; ++i) { javax.jcr.Session session = repository.login(); assertThat(repository.getState(), is(State.RUNNING)); session.logout(); } assertThat(engine.getRepositoryState(name), is(State.RUNNING)); engine.shutdownRepository(name).get(); // blocks assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); }
@Test public void shouldStartRepositoryUsingLocalEnvironmentWithDefaultPersistenceConfiguration() throws Exception { // Create the repository configuration ... String configFilePath = "config/repo-config-inmemory-no-persistence.json"; InputStream configFileStream = getClass().getClassLoader().getResourceAsStream(configFilePath); RepositoryConfiguration repositoryConfiguration = RepositoryConfiguration.read(configFileStream, "doesn't matter"); LocalEnvironment environment = new LocalEnvironment(); repositoryConfiguration = repositoryConfiguration.with(environment); // Start the engine and repository ... ModeShapeEngine engine = new ModeShapeEngine(); engine.start(); try { JcrRepository repository = engine.deploy(repositoryConfiguration); Session session = repository.login(); Node root = session.getRootNode(); root.addNode("Library", "nt:folder"); session.save(); session.logout(); session = repository.login(); Node library = session.getNode("/Library"); assertThat(library, is(notNullValue())); assertThat(library.getPrimaryNodeType().getName(), is("nt:folder")); session.logout(); } finally { engine.shutdown().get(); environment.shutdown(); } }
@Test public void shouldAllowConcurrentLoginWhileRequiringAutoStartOfRepository() throws Exception { engine.start(); final JcrRepository repository = engine.deploy(config); String name = repository.getName(); assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING));
engine.start(); config = RepositoryConfiguration.read(configUrl).with(environment); JcrRepository repository = engine.deploy(config);
@Test public void shouldAllowUpdatingRepositoryConfigurationWhileNotRunning() throws Exception { engine.start(); JcrRepository repository = engine.deploy(config); String name = repository.getName(); assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); assertThat(config.getBinaryStorage().getMinimumBinarySizeInBytes(), is(Default.MINIMUM_BINARY_SIZE_IN_BYTES)); // Change the configuration ... long newLargeValueSizeInBytes = Default.MINIMUM_BINARY_SIZE_IN_BYTES * 2; Editor editor = repository.getConfiguration().edit(); EditableDocument binaryStorage = editor.getOrCreateDocument(FieldName.STORAGE) .getOrCreateDocument(FieldName.BINARY_STORAGE); binaryStorage.setNumber(FieldName.MINIMUM_BINARY_SIZE_IN_BYTES, newLargeValueSizeInBytes); Changes changes = editor.getChanges(); // Apply the changes to the deployed repository ... engine.update(name, changes).get(); // blocks assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); RepositoryConfiguration newConfig = engine.getRepository(name).getConfiguration(); assertThat(newConfig.getBinaryStorage().getMinimumBinarySizeInBytes(), is(newLargeValueSizeInBytes)); }
@Test public void shouldAllowUpdatingRepositoryConfigurationWhileRunning() throws Exception { engine.start(); JcrRepository repository = engine.deploy(config); String name = repository.getName(); assertThat(engine.getRepositoryState(name), is(State.NOT_RUNNING)); engine.startRepository(name).get(); // blocks assertThat(engine.getRepositoryState(name), is(State.RUNNING)); long defaultLargeValueSize = Default.MINIMUM_BINARY_SIZE_IN_BYTES; assertThat(config.getBinaryStorage().getMinimumBinarySizeInBytes(), is(defaultLargeValueSize)); assertThat(repository.repositoryCache().largeValueSizeInBytes(), is(defaultLargeValueSize)); // Change the configuration. We'll do something simple, like changing the large value size ... long newLargeValueSizeInBytes = defaultLargeValueSize * 2L; Editor editor = repository.getConfiguration().edit(); EditableDocument binaryStorage = editor.getOrCreateDocument(FieldName.STORAGE) .getOrCreateDocument(FieldName.BINARY_STORAGE); binaryStorage.setNumber(FieldName.MINIMUM_BINARY_SIZE_IN_BYTES, newLargeValueSizeInBytes); Changes changes = editor.getChanges(); // Apply the changes to the deployed repository ... engine.update(name, changes).get(); // blocks assertThat(engine.getRepositoryState(name), is(State.RUNNING)); // Verify the running repository and its configuraiton are using the new value ... RepositoryConfiguration newConfig = engine.getRepository(name).getConfiguration(); assertThat(newConfig.getBinaryStorage().getMinimumBinarySizeInBytes(), is(newLargeValueSizeInBytes)); assertThat(repository.repositoryCache().largeValueSizeInBytes(), is(newLargeValueSizeInBytes)); }
engine.deploy(updatedConfiguration.with(this)); } catch (Exception e) { throw new StartException(e);
engine.start(); config = RepositoryConfiguration.read(configUrl).with(environment); JcrRepository repository = engine.deploy(config);