Skip to content

Commit

Permalink
MODE-1474 - Fixed AS7 subsystem support for passing down to the repos…
Browse files Browse the repository at this point in the history
…itory custom <indexing/> attributes. Also, validated that with the current version of Hibernate Search it's possible to use a custom configured analyzer.
  • Loading branch information
Horia Chiorean authored and rhauch committed Dec 5, 2012
1 parent b9c6632 commit e02f7e6
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 153 deletions.
Expand Up @@ -334,6 +334,7 @@
<node-type>custom.cnd</node-type>
</node-types>
<cache-index-storage cache-container="index-cache-container" data-cache-name="index-data"/>
<indexing analyzer-classname="org.apache.lucene.analysis.standard.ClassicAnalyzer"/>
</repository>
</subsystem>
<subsystem xmlns="urn:jboss:domain:jaxrs:1.0"/>
Expand Down
Expand Up @@ -24,7 +24,6 @@
package org.modeshape.jboss.service;

import org.infinispan.manager.CacheContainer;
import org.infinispan.schematic.Schematic;
import org.infinispan.schematic.document.EditableDocument;
import org.modeshape.jcr.RepositoryConfiguration;

Expand All @@ -43,24 +42,26 @@ public class IndexStorage {
this.queryConfig = queryConfig;
}

static IndexStorage defaultStorage(String repositoryName, String dataDirPath) {
EditableDocument query = Schematic.newDocument();
void setDefaultValues( String dataDirPath ) {
queryConfig.set(RepositoryConfiguration.FieldName.REBUILD_UPON_STARTUP, RepositoryConfiguration.QueryRebuild.IF_MISSING.toString().toLowerCase());

EditableDocument indexing = query.getOrCreateDocument(RepositoryConfiguration.FieldName.INDEXING);
EditableDocument indexStorage = query.getOrCreateDocument(RepositoryConfiguration.FieldName.INDEX_STORAGE);
EditableDocument indexing = queryConfig.getOrCreateDocument(RepositoryConfiguration.FieldName.INDEXING);
EditableDocument backend = indexing.getOrCreateDocument(RepositoryConfiguration.FieldName.INDEXING_BACKEND);
query.set(RepositoryConfiguration.FieldName.REBUILD_UPON_STARTUP, RepositoryConfiguration.QueryRebuild.IF_MISSING.toString().toLowerCase());
backend.set(RepositoryConfiguration.FieldName.TYPE, RepositoryConfiguration.FieldValue.INDEXING_BACKEND_TYPE_LUCENE);

EditableDocument indexStorage = queryConfig.getOrCreateDocument(RepositoryConfiguration.FieldName.INDEX_STORAGE);
indexStorage.set(RepositoryConfiguration.FieldName.TYPE, RepositoryConfiguration.FieldValue.INDEX_STORAGE_FILESYSTEM);
indexStorage.set(RepositoryConfiguration.FieldName.INDEX_STORAGE_LOCATION, dataDirPath + "/" + repositoryName + "/indexes");
indexStorage.set(RepositoryConfiguration.FieldName.INDEX_STORAGE_LOCATION, dataDirPath + "/indexes");
}

return new IndexStorage(query);
boolean useDefaultValues() {
return !queryConfig.containsField(RepositoryConfiguration.FieldName.INDEX_STORAGE);
}

/**
* @return the repository's query configuration
*/
EditableDocument getQueryConfiguration() {
public EditableDocument getQueryConfiguration() {
return queryConfig;
}

Expand Down
Expand Up @@ -39,16 +39,8 @@ public class IndexStorageService implements Service<IndexStorage> {
private final InjectedValue<CacheContainer> cacheContainerInjectedValue = new InjectedValue<CacheContainer>();

private final IndexStorage indexStorage;
private final String repositoryName;

public IndexStorageService( String repositoryName ) {
this.indexStorage = null;
this.repositoryName = repositoryName;
}

public IndexStorageService( String repositoryName,
EditableDocument queryConfig ) {
this.repositoryName = repositoryName;
public IndexStorageService( EditableDocument queryConfig ) {
this.indexStorage = new IndexStorage(queryConfig);
}

Expand Down Expand Up @@ -97,10 +89,12 @@ public InjectedValue<CacheContainer> getCacheContainerInjectedValue() {

@Override
public IndexStorage getValue() throws IllegalStateException, IllegalArgumentException {
IndexStorage result = indexStorage == null ? IndexStorage.defaultStorage(this.repositoryName, dataDirectoryPathInjector
.getValue()) : indexStorage;
result.setCacheContainer(cacheContainerInjectedValue.getOptionalValue());
return result;
if (indexStorage.useDefaultValues()) {
//use optional value because this service is dynamically queried from AbstractAddIndexStorage
indexStorage.setDefaultValues(dataDirectoryPathInjector.getOptionalValue());
}
indexStorage.setCacheContainer(cacheContainerInjectedValue.getOptionalValue());
return indexStorage;
}

@Override
Expand Down
Expand Up @@ -23,9 +23,7 @@
*/
package org.modeshape.jboss.subsystem;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import java.util.List;
import org.infinispan.schematic.Schematic;
import org.infinispan.schematic.document.EditableDocument;
import org.jboss.as.controller.AbstractAddStepHandler;
import org.jboss.as.controller.AttributeDefinition;
Expand All @@ -42,6 +40,7 @@
import org.modeshape.jboss.service.IndexStorageService;
import org.modeshape.jcr.RepositoryConfiguration.FieldName;
import org.modeshape.jcr.RepositoryConfiguration.FieldValue;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;

public abstract class AbstractAddIndexStorage extends AbstractAddStepHandler {

Expand Down Expand Up @@ -73,37 +72,37 @@ protected void performRuntime( final OperationContext context,
final ModelNode address = operation.require(OP_ADDR);
final PathAddress pathAddress = PathAddress.pathAddress(address);
final String repositoryName = pathAddress.getElement(1).getValue();
// final String storageName = pathAddress.getLastElement().getValue();

// Get the type of the storage (this is required) ...
// final String storageType = storage.get(ModelKeys.INDEX_STORAGE_TYPE).asString();

// Build the 'query' document (except for the extractors) ...
EditableDocument query = Schematic.newDocument();
String rebuild = ModelAttributes.REBUILD_INDEXES_UPON_STARTUP.resolveModelAttribute(context, storage).asString().toLowerCase();
query.set(FieldName.REBUILD_UPON_STARTUP, rebuild);
ServiceName indexStorageServiceName = ModeShapeServiceNames.indexStorageServiceName(repositoryName);

//get the default service registered by "AddRepository
IndexStorageService existingService = (IndexStorageService)context.getServiceRegistry(false).getService(indexStorageServiceName).getService();
//get the query instance from the existing service, so that any indexing attributes set via "AddRepository" are not lost
EditableDocument query = existingService.getValue().getQueryConfiguration();
if (!query.containsField(FieldName.REBUILD_UPON_STARTUP)) {
String rebuild = ModelAttributes.REBUILD_INDEXES_UPON_STARTUP.resolveModelAttribute(context, storage).asString().toLowerCase();
query.set(FieldName.REBUILD_UPON_STARTUP, rebuild);
}

// Build the 'query/indexing' nested document ...
EditableDocument indexing = query.getOrCreateDocument(FieldName.INDEXING);
writeIndexingConfiguration(context, storage, indexing);

// Build the 'query/indexingStorage' nested document ...
EditableDocument indexStorage = query.getOrCreateDocument(FieldName.INDEX_STORAGE);
// Build the 'query/indexingStorage' nested document from scratch
EditableDocument indexStorage = query.setDocument(FieldName.INDEX_STORAGE);
writeIndexStorageConfiguration(context, storage, indexStorage);

// Build the 'query/indexing/backend' nested document ...
EditableDocument backend = indexing.getOrCreateDocument(FieldName.INDEXING_BACKEND);
writeIndexingBackendConfiguration(context, storage, backend);

IndexStorageService service = new IndexStorageService(repositoryName, query);
ServiceName serviceName = ModeShapeServiceNames.indexStorageServiceName(repositoryName);
ServiceBuilder<IndexStorage> indexBuilder = target.addService(serviceName, service);
IndexStorageService service = new IndexStorageService(query);
ServiceBuilder<IndexStorage> indexBuilder = target.addService(indexStorageServiceName, service);
indexBuilder.setInitialMode(ServiceController.Mode.ACTIVE);

addControllersAndDependencies(repositoryName, service, newControllers, indexBuilder, target);

//A default index service should've already been added by AddRepository, so we remove it here
context.removeService(serviceName);
//remove the default service added by "AddRepository"
context.removeService(indexStorageServiceName);
newControllers.add(indexBuilder.install());
}

Expand Down

0 comments on commit e02f7e6

Please sign in to comment.