/*** * Validate this configuration if the supplied changes were made to this. Note that this does <i>not</i> actually change this * configuration. * * @param changes the proposed changes to this configuration's underlying document; never null * @return the validation results; never null * @see #edit() * @see #validate() */ public Problems validate( Changes changes ) { // Create a copy of this configuration ... Editor copy = edit(); copy.apply(changes); RepositoryConfiguration updated = new RepositoryConfiguration(copy.unwrap(), this.getName()); return updated.validate(); }
/*** * Validate this configuration if the supplied changes were made to this. Note that this does <i>not</i> actually change this * configuration. * * @param changes the proposed changes to this configuration's underlying document; never null * @return the validation results; never null * @see #edit() * @see #validate() */ public Problems validate( Changes changes ) { // Create a copy of this configuration ... Editor copy = edit(); copy.apply(changes); RepositoryConfiguration updated = new RepositoryConfiguration(copy.unwrap(), this.getName()); return updated.validate(); }
Editor copy = oldConfiguration.edit(); ConfigurationChange configChanges = new ConfigurationChange(); copy.apply(changes, configChanges);
Editor copy = oldConfiguration.edit(); ConfigurationChange configChanges = new ConfigurationChange(); copy.apply(changes, configChanges);
Editor configEditor = repositoryConfig.edit(); EditableDocument externalSources = configEditor.getOrCreateDocument(RepositoryConfiguration.FieldName.EXTERNAL_SOURCES);
Editor editor = config.edit();
Editor editor = repositoryConfig.edit();
Editor editor = config.edit();
/** * Make sure that a workspace with the supplied name exists. * * @param workspaceName the name of the workspace; may not be null */ protected void predefineWorkspace( RepositoryConfiguration configuration, String workspaceName ) { assertThat(workspaceName, is(notNullValue())); // Edit the configuration ... Editor editor = configuration.edit(); EditableDocument workspaces = editor.getOrCreateDocument("workspaces"); EditableArray predefined = workspaces.getOrCreateArray("predefined"); predefined.addStringIfAbsent(workspaceName); // And apply the changes ... Changes changes = editor.getChanges(); if (changes.isEmpty()) return; try { repository.apply(changes); } catch (Exception e) { e.printStackTrace(); throw new AssertionFailedError("Unexpected error while predefining the \"" + workspaceName + "\" workspace:" + e.getMessage()); } }
Editor editor = repository.getConfiguration().edit(); EditableDocument sequencing = editor.getDocument(FieldName.SEQUENCING); EditableDocument sequencers = sequencing.getDocument(FieldName.SEQUENCERS);
/** * Immediately change and apply the specified persistence field to the repository configuration * * @param defn the attribute definition for the value; may not be null * @param newValue the new string value * @throws RepositoryException if there is a problem obtaining the repository configuration or applying the change * @throws OperationFailedException if there is a problem obtaining the raw value from the supplied model node */ public void changePersistenceField(MappedAttributeDefinition defn, ModelNode newValue) throws RepositoryException, OperationFailedException { ModeShapeEngine engine = getEngine(); String repositoryName = repositoryName(); // Get a snapshot of the current configuration ... RepositoryConfiguration config = engine.getRepositoryConfiguration(repositoryName); // Now start to make changes ... Editor editor = config.edit(); EditableDocument persistence = editor.getOrCreateDocument(FieldName.STORAGE).getOrCreateDocument(FieldName.PERSISTENCE); // Change the field ... String fieldName = defn.getFieldName(); // Get the raw value from the model node ... Object rawValue = defn.getTypedValue(newValue); // And update the field ... persistence.set(fieldName, rawValue); // Get and apply the changes to the current configuration. Note that the 'update' call asynchronously // updates the configuration, and returns a Future<JcrRepository> that we could use if we wanted to // wait for the changes to take place. But we don't want/need to wait, so we'll not use the Future ... Changes changes = editor.getChanges(); engine.update(repositoryName, changes); }
/** * Immediately change and apply the specified field in the current repository configuration to the new value. * * @param defn the attribute definition for the value; may not be null * @param newValue the new string value * @throws RepositoryException if there is a problem obtaining the repository configuration or applying the change * @throws OperationFailedException if there is a problem obtaining the raw value from the supplied model node */ public void changeField( MappedAttributeDefinition defn, ModelNode newValue ) throws RepositoryException, OperationFailedException { ModeShapeEngine engine = getEngine(); String repositoryName = repositoryName(); // Get a snapshot of the current configuration ... RepositoryConfiguration config = engine.getRepositoryConfiguration(repositoryName); // Now start to make changes ... Editor editor = config.edit(); // Find the Document containing the field ... EditableDocument fieldContainer = editor; for (String fieldName : defn.getPathToContainerOfField()) { fieldContainer = editor.getOrCreateDocument(fieldName); } // Get the raw value from the model node ... Object rawValue = defn.getTypedValue(newValue); // Change the field ... String fieldName = defn.getFieldName(); fieldContainer.set(fieldName, rawValue); // Apply the changes to the current configuration ... Changes changes = editor.getChanges(); engine.update(repositoryName, changes); }
Editor editor = config.edit();
Editor editor = repositoryConfig.edit(); editor.getOrCreateDocument(FieldName.STORAGE).setDocument(FieldName.PERSISTENCE, config);
@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)); }
@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)); }
Editor editor = repository.getConfiguration().edit(); EditableDocument externalSources = editor.getDocument(FieldName.EXTERNAL_SOURCES); externalSources.set("files", files.unwrap());
@Test @FixFor( {"MODE-2575", "MODE-2635"} ) public void shouldSuccessfullyValidateMongoBinaryStorageConfiguration() throws Exception { RepositoryConfiguration config = assertValid("config/mongo-binary-storage-full-config.json"); Document storageDoc = config.getDocument().getDocument(FieldName.STORAGE).getDocument(FieldName.BINARY_STORAGE); assertEquals(Arrays.asList("192.1.68.1.1:90", "143.22.33.123:120"), storageDoc.get(FieldName.HOST_ADDRESSES)); RepositoryConfiguration.BinaryStorage storage = config.getBinaryStorage(); assertEquals(RepositoryConfiguration.FieldValue.BINARY_STORAGE_TYPE_MONGO, storage.getType()); assertTrue(storage.getBinaryStore() instanceof MongodbBinaryStore); // remove host and port, check that the config is still valid Editor editor = config.edit(); EditableDocument storageDocEditable = editor.getDocument(FieldName.STORAGE).getDocument(FieldName.BINARY_STORAGE); storageDocEditable.remove(FieldName.HOST); storageDocEditable.remove(FieldName.PORT); RepositoryConfiguration configWithoutHostPort = new RepositoryConfiguration(editor.unwrap(), "mongo-config-1"); assertValid(configWithoutHostPort); // remove host addresses as well and check that what remains is not valid storageDocEditable.remove(FieldName.HOST_ADDRESSES); RepositoryConfiguration invalidConfig = new RepositoryConfiguration(editor.unwrap(), "mongo-config-2"); try { invalidConfig.getBinaryStorage().getBinaryStore(); fail("Should not allow a Mongo binary storage without host, port and host addresses"); } catch (IllegalArgumentException e) { //expected } }
@Test @FixFor( "MODE-2583 ") public void shouldNotUseIndexesWhichHaveBeenRemovedFromConfiguration() throws Exception { // clean the indexes TestingUtil.waitUntilFolderCleanedUp("target/startup_test_indexes"); RepositoryConfiguration configuration = startRunStop(this::addNodeAndAssertIndexUsed, "config/repo-config-persistent-local-indexes.json"); MutableDocument configDoc = configuration.edit().asMutableDocument(); configDoc.remove(RepositoryConfiguration.FieldName.INDEXES); TestingUtil.waitUntilFolderCleanedUp("target/startup_test_indexes"); startRunStop(repository -> { JcrSession session = repository.login(); // force a re-index of the entire workspace session.getWorkspace().reindex(); //then check that still only 1 node is returned String sql = "select [jcr:path] from [nt:unstructured] where [jcr:name] = 'testRoot'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); ValidateQuery.validateQuery().rowCount(1).useNoIndexes().validate(query, query.execute()); session.logout(); }, new RepositoryConfiguration(configDoc, "updated_config")); }
}, "config/repo-config-persistent-predefined-ws.json"); final Editor editor = config.edit(); EditableArray predefinedWs = editor.getDocument(RepositoryConfiguration.FieldName.WORKSPACES) .getArray(RepositoryConfiguration.FieldName.PREDEFINED);