Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions connectors/appsearch/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<!--
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.
-->

<project name="appsearch" default="all">

<property environment="env"/>
<condition property="mcf-dist" value="${env.MCFDISTPATH}">
<isset property="env.MCFDISTPATH"/>
</condition>
<property name="abs-dist" location="../../dist"/>
<condition property="mcf-dist" value="${abs-dist}">
<not>
<isset property="env.MCFDISTPATH"/>
</not>
</condition>

<import file="${mcf-dist}/connector-build.xml"/>

<property name="elasticsearch.version" value="1.0.1"/>

<target name="download-dependencies">

<mkdir dir="build/download"/>
<get src="http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${elasticsearch.version}.tar.gz"
dest="build/download/elasticsearch.tar.gz"/>
<gunzip src="build/download/elasticsearch.tar.gz"/>
<untar src="build/download/elasticsearch.tar" dest="test-materials"/>

<!-- download and install the attachment plugin -->
<mkdir dir="test-materials/elasticsearch-${elasticsearch.version}/plugins"/>

<get src="https://github.com/elasticsearch/elasticsearch-mapper-attachments/archive/v2.0.0.RC1.zip"
dest="test-materials/elasticsearch-${elasticsearch.version}/plugins/mapper-attachments.zip"/>

<unzip src="test-materials/elasticsearch-${elasticsearch.version}/plugins/mapper-attachments.zip" dest="test-materials/elasticsearch-${elasticsearch.version}/plugins/mapper-attachments"/>

<chmod dir="test-materials/elasticsearch-${elasticsearch.version}" perm="ugo+rxw">
<fileset dir="**/*"/>
</chmod>
<chmod file="test-materials/elasticsearch-${elasticsearch.version}/bin/plugin" perm="ugo+rx"/>
<chmod file="test-materials/elasticsearch-${elasticsearch.version}/bin/elasticsearch" perm="ugo+rx"/>
<chmod file="test-materials/elasticsearch-${elasticsearch.version}/bin/elasticsearch.in.sh" perm="ugo+rx"/>

</target>

<target name="download-cleanup">
<delete>
<fileset dir="test-materials" excludes="README*.txt"/>
</delete>
</target>

<target name="integration">
<mkdir dir="dist/integration/elasticsearch"/>
<copy todir="dist/integration/elasticsearch">
<fileset dir="../../lib/elasticsearch"/>
</copy>
<mkdir dir="dist/integration/elasticsearch-1.5"/>
<copy todir="dist/integration/elasticsearch-1.5">
<fileset dir="../../lib/elasticsearch-1.5"/>
</copy>
</target>

<target name="calculate-testcode-condition">
<available file="test-materials/elasticsearch-${elasticsearch.version}" property="tests-present"/>
</target>

<target name="pretest-warn" depends="calculate-testcode-condition" unless="tests-present">
<echo message="Need ElasticSearch download in order to compile tests - run ant make-deps"/>
</target>

<path id="connector-test-classpath">
<path refid="mcf-connector-build.connector-test-classpath"/>
<fileset dir="test-materials/elasticsearch-${elasticsearch.version}">
<include name="lib/*.jar"/>
<include name="plugins/mapper-attachments/*.jar"/>
</fileset>
</path>

<target name="deliver-connector" depends="mcf-connector-build.deliver-connector">
<antcall target="general-add-output-connector">
<param name="connector-label" value="AppSearch"/>
<param name="connector-class" value="com.mcplusa.manifoldcf.agents.output.appsearch.AppSearchConnector"/>
</antcall>
</target>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* 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 com.mcplusa.manifoldcf.agents.output.appsearch;

import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.HttpClient;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.SocketTimeoutException;
import java.util.Locale;

import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
import org.apache.manifoldcf.agents.interfaces.ServiceInterruption;
import org.apache.manifoldcf.crawler.system.Logging;

public class AppSearchAction extends AppSearchConnection {

public enum CommandEnum {
_optimize, _refresh, _stats, _forcemerge, _none;
}

public AppSearchAction(HttpClient client, AppSearchConfig config)
throws ManifoldCFException {
super(config, client);
}

public void executeGET(CommandEnum cmd, boolean checkConnection)
throws ManifoldCFException, ServiceInterruption {
String command = cmd.toString();
if (cmd.equals(CommandEnum._none)) {
command = "";
}

StringBuffer url = getApiUrl(command);
HttpGet method = new HttpGet(url.toString());
call(method);
String error = checkJson(jsonException);
if (getResult() == Result.OK && error == null) {
return;
}
setResult("JSONERROR", Result.ERROR, error);
Logging.connectors.warn("AppSearch: Commit failed: " + getResponse());
}

public void executePOST(CommandEnum cmd, boolean checkConnection) throws ManifoldCFException, ServiceInterruption {
String command = cmd.toString();
if (cmd.equals(CommandEnum._none)) {
command = "";
}

StringBuffer url = getApiUrl(command);
HttpPost method = new HttpPost(url.toString());
call(method);
String error = checkJson(jsonException);
if (getResult() == Result.OK && error == null) {
return;
}
setResult("JSONERROR", Result.ERROR, error);
Logging.connectors.warn("AppSearch: Commit failed: " + getResponse());
}

@Override
protected void handleIOException(IOException e) throws ManifoldCFException, ServiceInterruption {
if (e instanceof InterruptedIOException && !(e instanceof SocketTimeoutException)) {
throw new ManifoldCFException(e.getMessage(), ManifoldCFException.INTERRUPTED);
}
setResult(e.getClass().getSimpleName().toUpperCase(Locale.ROOT), Result.ERROR, e.getMessage());
long currentTime = System.currentTimeMillis();

throw new ServiceInterruption("IO exception: " + e.getMessage(), e,
currentTime + 60000L,
currentTime + 1L * 60L * 60000L,
1, false);
}

}
Loading