Elasticsearch 7.x plugin 만들기

By | 2022년 8월 19일
Table of Contents

Elasticsearch 7.x plugin 만들기

Elasticsearch 소스 다운로드

mkdir /tmp/work
cd /tmp/work
git clone https://github.com/elastic/elasticsearch.git
cd elasticsearch

설치하려는 서버 버전에 맞춰서 checkout 한다.

git checkout 7.15

예제 별도 복사

cp -r plugins/examples/rest-handler ../
cp -r gradle* ../rest-handler/
cd ../rest-handler/

build.gradle

gradle 7.x 버전에서 컴파일되었다.

apply plugin: 'java'
apply plugin: 'maven-publish'

sourceCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'

version = '7.15.1'
jar {
  manifest {
    attributes 'Implementation-Title': 'Example rest handler Plugin',
            'Implementation-Version': archiveVersion
  }
}

repositories {
  mavenCentral()
}

dependencies {
  implementation group: 'commons-collections', name: 'commons-collections', version: '3.2'
  implementation group: 'org.elasticsearch', name: 'elasticsearch', version: version
  implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0'
  implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
  testImplementation group: 'junit', name: 'junit', version: '4.+'
  implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
}

test {
  systemProperties 'property': 'value'
}

publishing {
  repositories {
    flatDir {
      dirs 'repos'
    }
  }
}

task buildPluginZip(type: Zip, dependsOn:[':jar']) {
  archiveBaseName = 'example-rest-handler-plugin'
  classifier = 'plugin'
  from 'build/libs'
  from 'src/main/resources'
}

artifacts {
  archives buildPluginZip
}

[ compileJava, compileTestJava ]*.options*.encoding = 'UTF-8'
[ compileJava, compileTestJava ]*.options*.compilerArgs = ['-Xlint:-options']

plugin-descriptor.properties

classname 은 ExampleRestHandlerPlugin.java 의 패키지명과 일치해야 한다.

mkdir src/main/resources
vi src/main/resources/plugin-descriptor.properties

description=Example rest handler Plugin
version=7.15.1
name=example-rest-handler-plugin
classname=org.elasticsearch.example.resthandler.ExampleRestHandlerPlugin
java.version=1.8
elasticsearch.version=7.15.1

build

./gradlew clean
./gradlew buildPluginZip

ls -al build/distributions/

install plugin

file:/// 와 같이 / 가 3개여야 한다.

./bin/elasticsearch-plugin install file:///home/.../example-rest-handler-plugin-7.15.1-plugin.zip

test

// start elasticsearch
$ ./bin/elasticsearch
$ curl 127.0.0.1:9200/_cat/example

docker 로 elasticsearch 를 실행한 경우

mkdir ../dockerize
cp build/distributions/example-rest-handler-plugin-7.15.1-plugin.zip ../dockerize/
cd ../dockerize

vi Dockerfile
--------------
FROM docker.elastic.co/elasticsearch/elasticsearch:7.15.1

ADD example-rest-handler-plugin-7.15.1-plugin.zip /

RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install --batch file:///example-rest-handler-plugin-7.15.1-plugin.zip
--------------
docker build -t skyer9/elasticsearch-with-plugin:7.15.1 .
docker login
docker push skyer9/elasticsearch-with-plugin:7.15.1

http://localhost:9200/_cat/example 에 접속한다.

답글 남기기