Return-Path: X-Original-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5DE44DA07 for ; Thu, 21 Feb 2013 08:52:23 +0000 (UTC) Received: (qmail 23650 invoked by uid 500); 21 Feb 2013 08:52:23 -0000 Delivered-To: apmail-jackrabbit-oak-commits-archive@jackrabbit.apache.org Received: (qmail 23614 invoked by uid 500); 21 Feb 2013 08:52:23 -0000 Mailing-List: contact oak-commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-dev@jackrabbit.apache.org Delivered-To: mailing list oak-commits@jackrabbit.apache.org Received: (qmail 23595 invoked by uid 99); 21 Feb 2013 08:52:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Feb 2013 08:52:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,NORMAL_HTTP_TO_IP,WEIRD_PORT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Feb 2013 08:52:19 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D6B7E2388C06; Thu, 21 Feb 2013 08:51:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1448550 [6/6] - in /jackrabbit/oak/trunk: ./ oak-parent/ oak-solr-core/ oak-solr-core/src/ oak-solr-core/src/main/ oak-solr-core/src/main/java/ oak-solr-core/src/main/java/org/ oak-solr-core/src/main/java/org/apache/ oak-solr-core/src/main... Date: Thu, 21 Feb 2013 08:51:32 -0000 To: oak-commits@jackrabbit.apache.org From: tommaso@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130221085136.D6B7E2388C06@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: jackrabbit/oak/trunk/oak-solr-remote/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/http/RemoteSolrServerProvider.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-remote/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/http/RemoteSolrServerProvider.java?rev=1448550&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-solr-remote/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/http/RemoteSolrServerProvider.java (added) +++ jackrabbit/oak/trunk/oak-solr-remote/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/http/RemoteSolrServerProvider.java Thu Feb 21 08:51:30 2013 @@ -0,0 +1,117 @@ +/* + * 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.jackrabbit.oak.plugins.index.solr.http; + +import java.io.IOException; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Property; +import org.apache.felix.scr.annotations.Service; +import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrUtils; +import org.apache.jackrabbit.oak.plugins.index.solr.SolrServerProvider; +import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.impl.CloudSolrServer; +import org.apache.solr.client.solrj.impl.HttpSolrServer; +import org.osgi.service.component.ComponentContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * {@link SolrServerProvider} for remote Solr installations. + */ +@Component(metatype = true, immediate = true) +@Service(SolrServerProvider.class) +public class RemoteSolrServerProvider implements SolrServerProvider { + + private final Logger log = LoggerFactory.getLogger(RemoteSolrServerProvider.class); + + private static final String DEFAULT_COLLECTION = "oak"; + + @Property(value = "http://127.0.0.1:8983/solr") + private static final String SOLR_HTTP_URL = "solr.http.url"; + + @Property(value = "localhost:9983") + private static final String SOLR_ZK_HOST = "solr.zk.host"; + + private SolrServer solrServer; + private String solrHttpUrl; + private String solrZkHost; + + @Activate + protected void activate(ComponentContext componentContext) throws Exception { + solrHttpUrl = String.valueOf(componentContext.getProperties().get(SOLR_HTTP_URL)); + solrZkHost = String.valueOf(componentContext.getProperties().get(SOLR_ZK_HOST)); + } + + @Deactivate + protected void deactivate() throws Exception { + solrHttpUrl = null; + solrZkHost = null; + if (solrServer != null) { + solrServer.shutdown(); + solrServer = null; + } + } + + + @Override + public SolrServer getSolrServer() throws Exception { + if (solrServer == null) { + try { + solrServer = initializeWithCloudSolrServer(); + } catch (Exception e) { + log.warn("unable to initialize default SolrCloud client"); + try { + solrServer = initializeWithExistingHttpServer(); + } catch (Exception e1) { + log.warn("unable to initialize default Solr HTTP client"); + } + } + if (solrServer == null) { + throw new IOException("could not connect to any HTTP Solr server"); + } + } + return solrServer; + } + + private SolrServer initializeWithExistingHttpServer() throws IOException, SolrServerException { + // try basic Solr HTTP client + HttpSolrServer httpSolrServer = new HttpSolrServer(solrHttpUrl); + if (OakSolrUtils.checkServerAlive(httpSolrServer)) { + // TODO : check if oak collection exists, otherwise create it + return httpSolrServer; + } else { + throw new IOException("the found HTTP Solr server is not alive"); + } + + } + + private SolrServer initializeWithCloudSolrServer() throws IOException, SolrServerException { + // try SolrCloud client + CloudSolrServer cloudSolrServer = new CloudSolrServer(solrZkHost); + cloudSolrServer.setDefaultCollection(DEFAULT_COLLECTION); + if (OakSolrUtils.checkServerAlive(cloudSolrServer)) { + // TODO : check if oak collection exists, otherwise create it + return cloudSolrServer; + } else { + throw new IOException("the found SolrCloud server is not alive"); + } + } +} Propchange: jackrabbit/oak/trunk/oak-solr-remote/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/http/RemoteSolrServerProvider.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: jackrabbit/oak/trunk/pom.xml URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/pom.xml?rev=1448550&r1=1448549&r2=1448550&view=diff ============================================================================== --- jackrabbit/oak/trunk/pom.xml (original) +++ jackrabbit/oak/trunk/pom.xml Thu Feb 21 08:51:30 2013 @@ -47,6 +47,9 @@ oak-sling oak-http oak-lucene + oak-solr-core + oak-solr-remote + oak-solr-embedded oak-run oak-it oak-mk-perf