StorageElasticSearchModuleDefine.java 2.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright 2017, OpenSkywalking Organization All rights reserved.
 *
 * Licensed 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 repository: https://github.com/OpenSkywalking/skywalking
 */

19 20
package org.skywalking.apm.collector.storage.elasticsearch;

P
pengys5 已提交
21
import java.util.List;
22 23
import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.skywalking.apm.collector.core.client.Client;
P
pengys5 已提交
24
import org.skywalking.apm.collector.core.framework.DefineException;
25
import org.skywalking.apm.collector.core.module.ModuleConfigParser;
26
import org.skywalking.apm.collector.core.storage.StorageInstaller;
27 28
import org.skywalking.apm.collector.storage.StorageModuleDefine;
import org.skywalking.apm.collector.storage.StorageModuleGroupDefine;
P
pengys5 已提交
29
import org.skywalking.apm.collector.storage.dao.DAOContainer;
P
pengys5 已提交
30 31
import org.skywalking.apm.collector.storage.elasticsearch.dao.EsDAO;
import org.skywalking.apm.collector.storage.elasticsearch.dao.EsDAODefineLoader;
32
import org.skywalking.apm.collector.storage.elasticsearch.define.ElasticSearchStorageInstaller;
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

/**
 * @author pengys5
 */
public class StorageElasticSearchModuleDefine extends StorageModuleDefine {

    public static final String MODULE_NAME = "elasticsearch";

    @Override protected String group() {
        return StorageModuleGroupDefine.GROUP_NAME;
    }

    @Override public String name() {
        return MODULE_NAME;
    }

49 50 51 52
    @Override public final boolean defaultModule() {
        return false;
    }

53 54 55 56
    @Override protected ModuleConfigParser configParser() {
        return new StorageElasticSearchConfigParser();
    }

P
pengys5 已提交
57
    @Override protected Client createClient() {
58 59
        return new ElasticSearchClient(StorageElasticSearchConfig.CLUSTER_NAME, StorageElasticSearchConfig.CLUSTER_TRANSPORT_SNIFFER, StorageElasticSearchConfig.CLUSTER_NODES);
    }
60 61 62 63

    @Override public StorageInstaller storageInstaller() {
        return new ElasticSearchStorageInstaller();
    }
P
pengys5 已提交
64 65 66 67 68 69

    @Override public void injectClientIntoDAO(Client client) throws DefineException {
        EsDAODefineLoader loader = new EsDAODefineLoader();
        List<EsDAO> esDAOs = loader.load();
        esDAOs.forEach(esDAO -> {
            esDAO.setClient((ElasticSearchClient)client);
P
pengys5 已提交
70 71
            String interFaceName = esDAO.getClass().getInterfaces()[0].getName();
            DAOContainer.INSTANCE.put(interFaceName, esDAO);
P
pengys5 已提交
72 73
        });
    }
74
}