You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2011/07/08 16:50:37 UTC
svn commit: r1144346 - in /incubator/stanbol/trunk/commons/solr: ./
src/main/java/org/apache/stanbol/commons/solr/impl/install/
src/main/resources/OSGI-INF/metatype/ src/test/ src/test/java/
src/test/java/org/ src/test/java/org/apache/ src/test/java/or...
Author: rwesten
Date: Fri Jul 8 14:50:36 2011
New Revision: 1144346
URL: http://svn.apache.org/viewvc?rev=1144346&view=rev
Log:
STANBOL-257: 2nd try to commit this. Has overlooked that there where still some ".svn" directories origination from the original location within the SolrYard bundle
Added:
incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexInstallTask.java (with props)
incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexInstallerConstants.java (with props)
incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexRemoveTask.java (with props)
incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/SolrIndexInstaller.java (with props)
incubator/stanbol/trunk/commons/solr/src/main/resources/OSGI-INF/metatype/metatype.properties (with props)
incubator/stanbol/trunk/commons/solr/src/test/
incubator/stanbol/trunk/commons/solr/src/test/java/
incubator/stanbol/trunk/commons/solr/src/test/java/org/
incubator/stanbol/trunk/commons/solr/src/test/java/org/apache/
incubator/stanbol/trunk/commons/solr/src/test/java/org/apache/stanbol/
incubator/stanbol/trunk/commons/solr/src/test/java/org/apache/stanbol/commons/
incubator/stanbol/trunk/commons/solr/src/test/java/org/apache/stanbol/commons/solr/
incubator/stanbol/trunk/commons/solr/src/test/java/org/apache/stanbol/commons/solr/SolrDirectoryManagerTest.java (with props)
incubator/stanbol/trunk/commons/solr/src/test/resources/
incubator/stanbol/trunk/commons/solr/src/test/resources/solr/
incubator/stanbol/trunk/commons/solr/src/test/resources/solr/core/
incubator/stanbol/trunk/commons/solr/src/test/resources/solr/core/test.solrindex.zip (with props)
Modified:
incubator/stanbol/trunk/commons/solr/ (props changed)
Propchange: incubator/stanbol/trunk/commons/solr/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Jul 8 14:50:36 2011
@@ -0,0 +1,7 @@
+.classpath
+
+.project
+
+.settings
+
+target
Added: incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexInstallTask.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexInstallTask.java?rev=1144346&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexInstallTask.java (added)
+++ incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexInstallTask.java Fri Jul 8 14:50:36 2011
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.commons.solr.impl.install;
+
+import static org.apache.stanbol.commons.solr.impl.install.IndexInstallerConstants.PROPERTY_ARCHIVE_FORMAT;
+import static org.apache.stanbol.commons.solr.impl.install.IndexInstallerConstants.PROPERTY_INDEX_ARCHIVE;
+import static org.apache.stanbol.commons.solr.impl.install.IndexInstallerConstants.PROPERTY_INDEX_NAME;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.io.IOUtils;
+import org.apache.sling.installer.api.tasks.InstallTask;
+import org.apache.sling.installer.api.tasks.InstallationContext;
+import org.apache.sling.installer.api.tasks.ResourceState;
+import org.apache.sling.installer.api.tasks.TaskResourceGroup;
+import org.apache.stanbol.commons.solr.SolrDirectoryManager;
+import org.apache.stanbol.commons.solr.utils.ConfigUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class IndexInstallTask extends InstallTask {
+
+ private static final Logger log = LoggerFactory.getLogger(IndexInstallTask.class);
+ /**
+ * use 19 because the config install uses 20 and the files MUST be installed before the config triggering
+ * the initialisation of the services.
+ */
+ private static final String CONFIG_INSTALL_ORDER = "19-";
+
+ private final SolrDirectoryManager solrDirectoryManager;
+
+ public IndexInstallTask(TaskResourceGroup trg, SolrDirectoryManager solrDirectoryManager) {
+ super(trg);
+ this.solrDirectoryManager = solrDirectoryManager;
+ }
+
+ @Override
+ public void execute(InstallationContext ctx) {
+ String indexName = (String) getResource().getAttribute(PROPERTY_INDEX_NAME);
+ Map<String,File> existingIndexes = solrDirectoryManager.getManagedIndices();
+ if (existingIndexes.containsKey(indexName)) {
+ // an Index with that name already exists -> ignore
+ ctx.log(
+ "Unable to install the Index with the name \"%s\" becuase an index with that name is already managed by the the SolrYard "
+ + "(resource %s | location of the existing index %s)!", indexName, getResource()
+ .getURL(), existingIndexes.get(indexName));
+ setFinishedState(ResourceState.IGNORED);
+ } else { // this index does not exist
+ String archiveFormat = (String) getResource().getAttribute(PROPERTY_ARCHIVE_FORMAT);
+ InputStream is = null;
+ try {
+ is = getResource().getInputStream();
+ if ("properties".equals(archiveFormat)) {
+ InputStreamReader reader = new InputStreamReader(is, "UTF-8");
+ Properties props = new Properties();
+ try {
+ props.load(reader);
+ } finally {
+ IOUtils.closeQuietly(reader);
+ }
+ String indexPath = props.getProperty(PROPERTY_INDEX_ARCHIVE);
+ if (indexPath == null) {
+ indexPath = indexName + '.' + ConfigUtils.SOLR_INDEX_ARCHIVE_EXTENSION;
+ log.info("Property \""
+ + PROPERTY_INDEX_ARCHIVE
+ + "\" not present within the SolrIndex references file. Will use the default name \""
+ + indexPath + "\"");
+ }
+ solrDirectoryManager.createSolrDirectory(indexName, indexPath, props);
+ setFinishedState(ResourceState.INSTALLED);
+ } else {
+ ArchiveInputStream ais = null;
+ try {
+ ais = ConfigUtils.getArchiveInputStream(archiveFormat, is);
+ solrDirectoryManager.createSolrIndex(indexName, ais);
+ // we are done ... set the state to installed!
+ setFinishedState(ResourceState.INSTALLED);
+ } finally {
+ IOUtils.closeQuietly(ais);
+ }
+ }
+ // now we can copy the core!
+ } catch (Exception e) {
+ String message = String
+ .format(
+ "Unable to install SolrIndexArchive for index name \"%s\"! (resource=%s, arviceFormat=%s)",
+ indexName, getResource().getURL(), archiveFormat);
+ log.error(message, e);
+ ctx.log("%s! Reason: %s", message, e.getMessage());
+ setFinishedState(ResourceState.IGNORED);
+ } finally {
+ IOUtils.closeQuietly(is);
+ }
+
+ }
+
+ }
+
+ @Override
+ public String getSortKey() {
+ return CONFIG_INSTALL_ORDER + getResource().getPriority() + "-" + getResource().getEntityId();
+ }
+
+}
Propchange: incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexInstallTask.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexInstallerConstants.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexInstallerConstants.java?rev=1144346&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexInstallerConstants.java (added)
+++ incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexInstallerConstants.java Fri Jul 8 14:50:36 2011
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.commons.solr.impl.install;
+
+/**
+ * Constants and static configuration used by the {@link SolrIndexInstaller}
+ *
+ * @author Rupert Westenthaler
+ *
+ */
+public final class IndexInstallerConstants {
+ private IndexInstallerConstants() { /* do not create instances */}
+
+ /**
+ * The schema used for transformed resources.
+ */
+ public static final String SOLR_INDEX_ARCHIVE_RESOURCE_TYPE = "solrarchive";
+
+ private static final String PROPERTY_PREFIX = "org.apache.stanbol.yard.solr.installer.";
+ /**
+ * The key used to configure the name of the Index-Archive The default name is
+ * \"<indexName>.solrarchive\".
+ */
+ public static final String PROPERTY_INDEX_ARCHIVE = "Index-Archive";
+
+ /**
+ * The key used for the name of the index
+ */
+ public static final String PROPERTY_INDEX_NAME = PROPERTY_PREFIX + "index.name";
+ /**
+ * The key used for the type of the archive
+ */
+ public static final String PROPERTY_ARCHIVE_FORMAT = PROPERTY_PREFIX + "archive.format";
+
+}
Propchange: incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexInstallerConstants.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexRemoveTask.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexRemoveTask.java?rev=1144346&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexRemoveTask.java (added)
+++ incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexRemoveTask.java Fri Jul 8 14:50:36 2011
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.commons.solr.impl.install;
+
+import org.apache.sling.installer.api.tasks.InstallTask;
+import org.apache.sling.installer.api.tasks.InstallationContext;
+import org.apache.sling.installer.api.tasks.TaskResourceGroup;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.core.CoreContainer;
+import org.apache.stanbol.commons.solr.SolrDirectoryManager;
+
+/**
+ * TODO: To remove a SolrIndex one would need first to close the SolrCore or shutdown the SolrContainer. This
+ * is currently not possible be cause the current architecture was not intended to support that.
+ * <p>
+ * To implement this one would need access to the CoreContainer with the core running on top of the Core to
+ * remove. Than one would need to call {@link CoreContainer#remove(String)} with the core and
+ * {@link CoreContainer#persist()} to remove the core also from the solr.xml. After that one can remove the
+ * files from the disk.
+ * <p>
+ * This would still have the problem that other components using an {@link EmbeddedSolrServer} that is based
+ * on this core would not be notified about such a change.
+ *
+ * @author Rupert Westenthaler
+ *
+ */
+public class IndexRemoveTask extends InstallTask {
+ /**
+ * Use 11 because the RemoveConfiguration uses 10 and we need to ensure that the files are removed after
+ * the services are shut down.
+ */
+ private static final String CONFIG_INSTALL_ORDER = "11-";
+
+ public IndexRemoveTask(TaskResourceGroup trg, SolrDirectoryManager solrDirectoryManager) {
+ super(trg);
+ }
+
+ @Override
+ public void execute(InstallationContext ctx) {
+ throw new UnsupportedOperationException("TODO: Not yet implemented :(");
+ }
+
+ @Override
+ public String getSortKey() {
+ return CONFIG_INSTALL_ORDER + getResource().getEntityId();
+ }
+
+}
Propchange: incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/IndexRemoveTask.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/SolrIndexInstaller.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/SolrIndexInstaller.java?rev=1144346&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/SolrIndexInstaller.java (added)
+++ incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/SolrIndexInstaller.java Fri Jul 8 14:50:36 2011
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.commons.solr.impl.install;
+
+import static org.apache.stanbol.commons.solr.impl.install.IndexInstallerConstants.PROPERTY_ARCHIVE_FORMAT;
+import static org.apache.stanbol.commons.solr.impl.install.IndexInstallerConstants.PROPERTY_INDEX_NAME;
+import static org.apache.stanbol.commons.solr.impl.install.IndexInstallerConstants.SOLR_INDEX_ARCHIVE_RESOURCE_TYPE;
+import static org.apache.stanbol.commons.solr.utils.ConfigUtils.SOLR_INDEX_ARCHIVE_EXTENSION;
+import static org.apache.stanbol.commons.solr.utils.ConfigUtils.SUPPORTED_SOLR_ARCHIVE_FORMAT;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.felix.scr.annotations.Services;
+import org.apache.sling.installer.api.InstallableResource;
+import org.apache.sling.installer.api.tasks.InstallTask;
+import org.apache.sling.installer.api.tasks.InstallTaskFactory;
+import org.apache.sling.installer.api.tasks.RegisteredResource;
+import org.apache.sling.installer.api.tasks.ResourceState;
+import org.apache.sling.installer.api.tasks.ResourceTransformer;
+import org.apache.sling.installer.api.tasks.TaskResource;
+import org.apache.sling.installer.api.tasks.TaskResourceGroup;
+import org.apache.sling.installer.api.tasks.TransformationResult;
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.stanbol.commons.solr.SolrDirectoryManager;
+import org.apache.stanbol.commons.solr.SolrServerProviderManager;
+import org.osgi.framework.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The main class implementing the two core interfaces of the Apache Sling Installer framework.
+ * <p>
+ * The {@link ResourceTransformer} is needed to check if installed files actually SolrIndexes. Currently this
+ * check is done by checking if <code>'.'+{@link IndexInstallerConstants#SOLR_INDEX_ARCHIVE_EXTENSION}</code>
+ * is contained in the filename. In addition it is checked of the archive type is hinted by the Filename. If
+ * not than ".zip" (works also for ".jar") is assumed. Note also that for ".gz" and ".bz2" it is assumed that
+ * ".tar" is used. File names such as "<indexName>.
+ * {@value IndexInstallerConstants#SOLR_INDEX_ARCHIVE_EXTENSION} [.<archiveType>]" are used by this
+ * implementation
+ * <p>
+ * The {@link InstallTaskFactory} interface is needed to create the actual install and remove task for
+ * transformed resources. Based on the requested activity instances of {@link IndexInstallTask} or
+ * {@link IndexRemoveTask} are created.
+ * <p>
+ * This implementation uses a {@link Constants#SERVICE_RANKING} of 100. This ensures that the this
+ * implementation is called before any {@link ResourceTransformer} directly part of the Apache Sling Installer
+ * framework. If {@link #transform(RegisteredResource)} returns <code>null</code> the Sling Installer
+ * framework will call the next registered {@link ResourceTransformer} instance. By returning a
+ * {@link TransformationResult} no further {@link ResourceTransformer} will be called.
+ * <p>
+ *
+ * TODO: This package should move to an own bundle supporting Sling Install capabilities for Solr. Even the
+ * current version only on the {@link SolrDirectoryManager}. The reason why it is still inside the SolrYard
+ * Bundle is that the remove functionality would also need to stop currently running SolrServers. this is
+ * currently not possible with the current architecture because {@link SolrServer} instances returned by the
+ * {@link SolrServerProviderManager} are no OSGI components.
+ *
+ *
+ * @author Rupert Westenthaler
+ *
+ */
+@Component(immediate = true)
+@Services(value = {@Service(value = InstallTaskFactory.class), @Service(value = ResourceTransformer.class)})
+@Property(name = Constants.SERVICE_RANKING, intValue = 100)
+// we need to be in front of the Sling Components
+public class SolrIndexInstaller implements InstallTaskFactory, ResourceTransformer {
+
+ private static final Logger log = LoggerFactory.getLogger(SolrIndexInstaller.class);
+
+ /**
+ * This service manages the SolrIndex Directory of the SolrYard. It is needed by the
+ * {@link IndexInstallTask} and {@link IndexRemoveTask} to do there work.
+ */
+ @Reference
+ private SolrDirectoryManager solrDirectoryManager;
+
+ public InstallTask createTask(TaskResourceGroup taskResourceGroup) {
+ TaskResource toActivate = taskResourceGroup.getActiveResource();
+ if (SOLR_INDEX_ARCHIVE_RESOURCE_TYPE.equals(toActivate.getType())) {
+ if (toActivate.getState() == ResourceState.UNINSTALL) {
+ return new IndexRemoveTask(taskResourceGroup, solrDirectoryManager);
+ } else {
+ return new IndexInstallTask(taskResourceGroup, solrDirectoryManager);
+ }
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public TransformationResult[] transform(RegisteredResource registeredResource) {
+ if (InstallableResource.TYPE_FILE.equals(registeredResource.getType())) {
+ return checkIndex(registeredResource);
+ } else { // this processes only files
+ return null;
+ }
+ }
+
+ /**
+ * Checks if the installed resource is an Solr Index Archive
+ *
+ * @param registeredResource
+ * the registered resource parsed by the Apache Sling installer framework
+ * @return the transformed resource or <code>null</code> if the parsed resource is not an Solr Index
+ * Archive.
+ */
+ private TransformationResult[] checkIndex(RegisteredResource registeredResource) {
+ // the URL is <schema>:<filePath>
+ // where the schema is the provider that registered the resource
+ Map<String,Object> properties = new HashMap<String,Object>();
+ String filePath = registeredResource.getURL().substring(
+ registeredResource.getURL().lastIndexOf(':') + 1);
+ // get the name of the index
+ String indexName = FilenameUtils.getBaseName(filePath);
+ // only the String until the first '.' -> multiple endings (e.g. slrindex.zip) expected
+ indexName = indexName.indexOf('.') > 0 ? indexName.substring(0, indexName.indexOf('.')) : indexName;
+ properties.put(PROPERTY_INDEX_NAME, indexName);
+ // now convert to lover case to ease the tests for file endings
+ filePath = filePath.toLowerCase();
+ if (!filePath.contains('.' + SOLR_INDEX_ARCHIVE_EXTENSION)) {
+ // not an solr index archive
+ return null; // -> can not transform
+ }
+ String extension = FilenameUtils.getExtension(filePath);
+ String archiveFormat = SUPPORTED_SOLR_ARCHIVE_FORMAT.get(extension);
+ if (archiveFormat == null) {
+ log.error("Unable to process Solr Index Archive from Resource " + registeredResource.getURL()
+ + "because of unsupported archive format \"" + extension + "\" (supported are "
+ + SUPPORTED_SOLR_ARCHIVE_FORMAT.keySet() + ")");
+ return null;
+ } else {
+ properties.put(PROPERTY_ARCHIVE_FORMAT, archiveFormat);
+ }
+
+ TransformationResult tr = new TransformationResult();
+ // try {
+ // tr.setInputStream(registeredResource.getInputStream());
+ // } catch (IOException e) {
+ // log.error(String.format("Unable to transform RegisteredResource %s with type %s and scheme %s",
+ // registeredResource.getURL(), registeredResource.getType(), registeredResource.getScheme()),e);
+ // return null;
+ // }
+ tr.setId(indexName + '.' + SOLR_INDEX_ARCHIVE_EXTENSION + '.' + archiveFormat);
+ tr.setAttributes(properties);
+ tr.setResourceType(SOLR_INDEX_ARCHIVE_RESOURCE_TYPE);
+ return new TransformationResult[] {tr};
+ }
+}
Propchange: incubator/stanbol/trunk/commons/solr/src/main/java/org/apache/stanbol/commons/solr/impl/install/SolrIndexInstaller.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/commons/solr/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1144346&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/solr/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ incubator/stanbol/trunk/commons/solr/src/main/resources/OSGI-INF/metatype/metatype.properties Fri Jul 8 14:50:36 2011
@@ -0,0 +1,7 @@
+
+#Properties defined by the org.apache.stanbol.entityhub.yard.solr.embedded.EmbeddedSolrPorovider
+org.apache.stanbol.entityhub.yard.solr.impl.DefaultSolrDirectoryManager.name=Apache Stanbol Entityhub Yard: Solr Directory Manager
+org.apache.stanbol.entityhub.yard.solr.impl.DefaultSolrDirectoryManager.description=Manages the Solr Indices used by the SolrYard in cases where no absolute path or an http URL is configured as SolrServer location.
+
+org.apache.stanbol.entityhub.yard.solr.embedded.solrDataDir.name=Managed Index Location
+org.apache.stanbol.entityhub.yard.solr.embedded.solrDataDir.description=The path to the directory used to store the managed Solr Indices. The user directory is used to resolve relative paths. Property substitution is supported. (e.g. ${user.home}/.stanbol/indices will create the managed indices within the "/.stanbol/indices" relative to the home directory of the user).
\ No newline at end of file
Propchange: incubator/stanbol/trunk/commons/solr/src/main/resources/OSGI-INF/metatype/metatype.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/commons/solr/src/test/java/org/apache/stanbol/commons/solr/SolrDirectoryManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/src/test/java/org/apache/stanbol/commons/solr/SolrDirectoryManagerTest.java?rev=1144346&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/solr/src/test/java/org/apache/stanbol/commons/solr/SolrDirectoryManagerTest.java (added)
+++ incubator/stanbol/trunk/commons/solr/src/test/java/org/apache/stanbol/commons/solr/SolrDirectoryManagerTest.java Fri Jul 8 14:50:36 2011
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.commons.solr;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.ServiceLoader;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.apache.stanbol.commons.solr.SolrDirectoryManager;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SolrDirectoryManagerTest {
+
+ private static final Logger log = LoggerFactory.getLogger(SolrDirectoryManagerTest.class);
+
+ public static final String TEST_SOLR_CONFIG_NAME = "test";
+ public static final String TEST_YARD_ID = "testYard";
+ public static final String TEST_SOLR_CORE_NAME = "test";
+ protected static final String TEST_INDEX_REL_PATH = File.separatorChar + "target" + File.separatorChar
+ + SolrDirectoryManager.DEFAULT_SOLR_DATA_DIR;
+
+ private static SolrDirectoryManager solrDirectoryManager;
+
+ private static File expectedManagedDirectory;
+ private static Collection<String> expectedIndexNames = Arrays.asList("entityhub", "cache");
+
+ @BeforeClass
+ public static void init() throws IOException {
+ // set to "${basedir}/some/rel/path" to test if property substitution works!
+ String prefix = System.getProperty("basedir") == null ? "." : "${basedir}";
+ String resolvedPrefix = System.getProperty("basedir") == null ? "." : System.getProperty("basedir");
+ String solrServerDir = prefix + TEST_INDEX_REL_PATH;
+ log.info("configured directory: " + solrServerDir);
+ System.setProperty(SolrDirectoryManager.MANAGED_SOLR_DIR_PROPERTY, solrServerDir);
+ // store the expected managed directory for later testing
+ expectedManagedDirectory = new File(resolvedPrefix, TEST_INDEX_REL_PATH);
+ log.info("expected managed directory: " + expectedManagedDirectory);
+ // create the SolrDirectoryManager used for the tests
+ Iterator<SolrDirectoryManager> providerIt = ServiceLoader.load(SolrDirectoryManager.class,
+ SolrDirectoryManager.class.getClassLoader()).iterator();
+ if (providerIt.hasNext()) {
+ solrDirectoryManager = providerIt.next();
+ } else {
+ throw new IllegalStateException("Unable to instantiate "
+ + SolrDirectoryManager.class.getSimpleName()
+ + " service by using " + ServiceLoader.class.getName() + "!");
+ }
+ //setup the entityhub and the cache index (as it would be done by the Entityhub)
+ //to test this initialisation
+ solrDirectoryManager.createSolrDirectory("entityhub", TEST_SOLR_CONFIG_NAME, null);
+ //for the cahce we use the default configuration
+ solrDirectoryManager.createSolrDirectory("cache", TEST_SOLR_CONFIG_NAME, null);
+ }
+
+ @Test
+ public void testManagedDirectoryInitialisation() {
+ // the managed directory must be set based on the
+ expectedManagedDirectory.equals(solrDirectoryManager.getManagedDirectory());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testNullIndexName() {
+ solrDirectoryManager.getSolrIndexDirectory(null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testEmptyIndexName() {
+ solrDirectoryManager.getSolrIndexDirectory("");
+ }
+
+ @Test
+ public void testGetManagedIndexes() {
+ Set<String> expected = new HashSet<String>(expectedIndexNames);
+ for (Entry<String,File> index : solrDirectoryManager.getManagedIndices().entrySet()) {
+ expected.remove(index.getKey());
+ // test that the index dir is the expected location
+ File expectedLocation = new File(expectedManagedDirectory, index.getKey());
+ assertEquals(expectedLocation, index.getValue());
+ }
+ // test that the expected indexes where returned
+ assertTrue(expected.isEmpty());
+ }
+
+ @Test
+ public void testIsManagedIndex() {
+ for (String name : expectedIndexNames) {
+ assertTrue(solrDirectoryManager.isManagedIndex(name));
+ }
+ assertFalse(solrDirectoryManager.isManagedIndex("notAnIndex" + System.currentTimeMillis()));
+ }
+
+ @Test
+ public void testDefaultIndexInitialisation() throws IOException {
+ // this is actually tested already by the initialisation of the
+ // SolrYardTest ...
+ String indexName = "testIndexInitialisation_" + System.currentTimeMillis();
+ File indexDir = solrDirectoryManager.createSolrDirectory(indexName,
+ TEST_SOLR_CONFIG_NAME, null);
+ assertEquals(new File(expectedManagedDirectory, indexName), indexDir);
+ assertTrue(indexDir.isDirectory());
+ }
+}
Propchange: incubator/stanbol/trunk/commons/solr/src/test/java/org/apache/stanbol/commons/solr/SolrDirectoryManagerTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/commons/solr/src/test/resources/solr/core/test.solrindex.zip
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/src/test/resources/solr/core/test.solrindex.zip?rev=1144346&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/stanbol/trunk/commons/solr/src/test/resources/solr/core/test.solrindex.zip
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream