protected final void completeRestore(RestoreOptions options) throws ExecutionException, Exception { if (getState() == State.RESTORING) { logger.debug("Shutting down '{0}' after content has been restored", getName()); doShutdown(false); logger.debug("Starting '{0}' after content has been restored", getName()); start(); logger.debug("Started '{0}' after content has been restored; beginning indexing of content", getName()); if (options.reindexContentOnFinish()) { // Reindex all content ... queryManager().cleanAndReindex(false); logger.debug("Completed reindexing all content in '{0}' after restore.", getName()); } } }
/** * Get the immutable configuration for the repository with the supplied name. * * @param repositoryName the name of the deployed repository * @return the repository configuration; never null * @throws IllegalArgumentException if the repository name is null, blank or invalid * @throws NoSuchRepositoryException if there is no repository with the specified name * @throws IllegalStateException if this engine is not {@link #getState() running} */ public final RepositoryConfiguration getRepositoryConfiguration( String repositoryName ) throws NoSuchRepositoryException { return getRepository(repositoryName).getConfiguration(); }
/** * @see org.jboss.msc.value.Value#getValue() */ @Override public RepositoryMonitor getValue() throws IllegalStateException, IllegalArgumentException { try { return this.repoInjector.getValue().getRepositoryStatistics(); } catch (Exception e) { // nothing to do } return RepositoryMonitor.EMPTY_MONITOR; }
protected final void prepareToRestore() throws RepositoryException { logger.debug("Preparing to restore '{0}' repository; setting state to RESTORING", getName()); if (getState() == State.RESTORING) { throw new RepositoryException(JcrI18n.repositoryIsCurrentlyBeingRestored.text(getName())); } state.set(State.RESTORING); }
public static void killRepository( JcrRepository repository ) { if (repository == null || repository.getState() != State.RUNNING) return; try { // Rollback any open transactions ... killTransaction(repository.runningState().txnManager()); // First shut down the repository ... repository.doShutdown(false); } catch (Throwable t) { log.error(t, JcrI18n.errorKillingRepository, repository.getName(), t.getMessage()); } }
@Test @FixFor( "MODE-2056" ) public void shouldReturnActiveSessions() throws Exception { shutdownDefaultRepository(); RepositoryConfiguration config = new RepositoryConfiguration("repoName", new TestingEnvironment()); repository = new JcrRepository(config); assertEquals(0, repository.getActiveSessionsCount()); repository.start(); JcrSession session1 = repository.login(); JcrSession session2 = repository.login(); assertEquals(2, repository.getActiveSessionsCount()); session2.logout(); assertEquals(1, repository.getActiveSessionsCount()); session1.logout(); assertEquals(0, repository.getActiveSessionsCount()); repository.login(); repository.shutdown().get(); assertEquals(0, repository.getActiveSessionsCount()); }
@Before public void beforeEach() throws Exception { config = new RepositoryConfiguration("repoName").with(new TestingEnvironment()); repository = new JcrRepository(config); repository.start(); context = repository.runningState().context(); repoTypeManager = repository.nodeTypeManager(); session = repository.login(); }
protected void startRepository() throws Exception { RepositoryConfiguration repositoryConfiguration = createRepositoryConfiguration(REPO_NAME); repositoryConfiguration = repositoryConfiguration.with(new TestingEnvironment()); repository = new JcrRepository(repositoryConfiguration); repository.start(); session = repository.login(); }
@Override public void reindexSince( long timestamp ) throws RepositoryException { // First check permissions ... session.checkPermission(workspaceName, Path.ROOT_PATH, ModeShapePermissions.INDEX_WORKSPACE); // then if the journal is available JcrRepository.RunningState runningState = repository().runningState(); if (runningState.journal() == null) { throw new RepositoryException(JcrI18n.cannotReindexJournalNotEnabled.text(timestamp, repository().getName())); } runningState.queryManager().reindexSince(this, timestamp); }
@FixFor("MODE-1137") @Test public void shouldExportContentWithUnicodeCharactersAsSystemView() throws Exception { Node unicode = session.getRootNode().addNode("unicodeContent"); Node desc = unicode.addNode("descriptionNode"); desc.setProperty("ex1", "étudiant (student)"); desc.setProperty("ex2", "où (where)"); desc.setProperty("ex3", "forêt (forest)"); desc.setProperty("ex4", "naïve (naïve)"); desc.setProperty("ex5", "garçon (boy)"); desc.setProperty("ex6", "multi\nline\nvalue"); desc.setProperty("ex7", "prop \"value\" with quotes"); desc.setProperty("ex7", "values with \n various \t\n : characters"); session.save(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); session.exportSystemView("/unicodeContent", baos, false, false); baos.close(); predefineWorkspace(repository.getConfiguration(), "workspace2"); InputStream istream = new ByteArrayInputStream(baos.toByteArray()); Session session2 = repository.login("workspace2"); session2.getWorkspace().importXML("/", istream, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW); Node desc2 = session2.getNode("/unicodeContent/descriptionNode"); assertSameProperties(desc, desc2); }
@Override protected String createConnectionUrl( JcrRepository repository ) throws Exception { return LocalJcrDriver.JNDI_URL_PREFIX + "jcr/local?repositoryName=" + repository.getName(); } }
@Before public void beforeEach() throws Exception { config = new RepositoryConfiguration("repoName").with(new TestingEnvironment()); repository = new JcrRepository(config); repository.start(); SessionCache systemCache = repository.createSystemSession(repository.runningState().context(), false); system = new SystemContent(systemCache); }
public void shouldAddPredefinedWorkspacesOnRestartViaConfigUpdate() throws Exception { RepositoryConfiguration config = startRunStop(repository -> { JcrSession session = repository.login("default"); session.logout(); session = repository.login("ws1"); session.getWorkspace().createWorkspace("ws2"); session.logout(); session = repository.login("ws2"); session.logout(); }, "config/repo-config-persistent-predefined-ws.json"); predefinedWs.add("ws4"); JcrRepository repository = new JcrRepository(new RepositoryConfiguration(editor.asMutableDocument(), "updated_config")); repository.start(); try { repository.apply(editor.getChanges()); JcrSession session = repository.login("default"); session.logout(); session = repository.login("ws1"); session.logout(); session = repository.login("ws2"); session.logout(); session = repository.login("ws3"); session.logout(); session = repository.login("ws4"); session.logout(); } finally {
@Override public Session call() throws Exception { return repository.login(); } });
@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)); }
public static JcrRepository startRepositoryWithConfig( String configFile ) throws Exception { URL configUrl = TestingUtil.class.getClassLoader().getResource(configFile); RepositoryConfiguration config = RepositoryConfiguration.read(configUrl).with(new TestingEnvironment()); JcrRepository repository = null; repository = new JcrRepository(config); repository.start(); return repository; }
JcrSession session = repository.login(); session.getRootNode().addNode("testNode"); session.save(); SessionCache systemSession = repository.createSystemSession(repository.runningState().context(), false); SystemContent systemContent = new SystemContent(systemSession); MutableCachedNode systemNode = systemContent.mutableSystemNode(); SessionCache systemSession = repository.createSystemSession(repository.runningState().context(), false); SystemContent systemContent = new SystemContent(systemSession); MutableCachedNode systemNode = systemContent.mutableSystemNode(); JcrSession session = repository.login(); AccessControlManager acm = session.getAccessControlManager(); SessionCache systemSession = repository.createSystemSession(repository.runningState().context(), true); SystemContent systemContent = new SystemContent(systemSession); CachedNode systemNode = systemContent.systemNode(); assertEquals(0, Long.valueOf(aclCountProp.getFirstValue().toString()).longValue()); assertFalse(repository.runningState().repositoryCache().isAccessControlEnabled()); }, config);
LinkedList<JcrSession> sessions = new LinkedList<JcrSession>(); for (int i = 0; i != 5; ++i) { JcrSession session1 = repository.login(); assertThat(session1.getRootNode(), is(notNullValue())); sessions.addFirst(session1); Thread.sleep(1000L); History history = repository.getRepositoryStatistics().getHistory(ValueMetric.SESSION_COUNT, Window.PREVIOUS_60_SECONDS); Statistics[] stats = history.getStats(); assertThat(stats.length, is(12)); System.out.println(history); DurationActivity[] lifetimes = repository.getRepositoryStatistics().getLongestRunning(DurationMetric.SESSION_LIFETIME); System.out.println("Session lifetimes: "); for (DurationActivity activity : lifetimes) {
RepositoryConfiguration config = repository.getConfiguration(); Problems problems = config.validate(changes); repository.setConfigurationProblems(problems); if (problems.hasErrors()) { throw new ConfigurationException(problems, JcrI18n.repositoryConfigurationIsNotValid.text(repositoryName, repository.apply(changes); } catch (Exception e) { throw new ConfigurationException(problems, JcrI18n.repositoryConfigurationIsNotValid.text(repositoryName,
protected void validateCrossWorkspaceAction( String srcWorkspace ) throws RepositoryException { CheckArg.isNotEmpty(srcWorkspace, "srcWorkspace"); session.checkLive(); session.checkWorkspacePermission(srcWorkspace, ModeShapePermissions.READ); session.checkWorkspacePermission(getName(), ModeShapePermissions.READ); JcrRepository repository = repository(); if (!repository.hasWorkspace(srcWorkspace)) { throw new NoSuchWorkspaceException(JcrI18n.workspaceNameIsInvalid.text(repository.getName(), srcWorkspace)); } }