001/*
002 * Copyright (C) 2014 Jörg Prante
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.xbib.elasticsearch.plugin.jdbc.river;
017
018import org.elasticsearch.action.ActionModule;
019import org.elasticsearch.common.inject.Inject;
020import org.elasticsearch.common.inject.Module;
021import org.elasticsearch.common.settings.Settings;
022import org.elasticsearch.plugins.AbstractPlugin;
023import org.elasticsearch.rest.RestModule;
024import org.elasticsearch.river.RiversModule;
025import org.xbib.elasticsearch.action.plugin.jdbc.run.RunRiverAction;
026import org.xbib.elasticsearch.action.plugin.jdbc.run.TransportRunRiverAction;
027import org.xbib.elasticsearch.action.plugin.jdbc.state.delete.DeleteRiverStateAction;
028import org.xbib.elasticsearch.action.plugin.jdbc.state.delete.TransportDeleteRiverStateAction;
029import org.xbib.elasticsearch.action.plugin.jdbc.state.get.GetRiverStateAction;
030import org.xbib.elasticsearch.action.plugin.jdbc.state.get.TransportGetRiverStateAction;
031import org.xbib.elasticsearch.action.plugin.jdbc.state.post.PostRiverStateAction;
032import org.xbib.elasticsearch.action.plugin.jdbc.state.post.TransportPostRiverStateAction;
033import org.xbib.elasticsearch.action.plugin.jdbc.state.put.PutRiverStateAction;
034import org.xbib.elasticsearch.action.plugin.jdbc.state.put.TransportPutRiverStateAction;
035import org.xbib.elasticsearch.plugin.jdbc.state.RiverStateModule;
036import org.xbib.elasticsearch.rest.action.river.jdbc.RestRunRiverAction;
037import org.xbib.elasticsearch.rest.action.river.jdbc.RestRiverStateAction;
038
039import java.util.Collection;
040
041import static org.elasticsearch.common.collect.Lists.newArrayList;
042
043public class JDBCRiverPlugin extends AbstractPlugin {
044
045    private final Settings settings;
046
047    @Inject
048    public JDBCRiverPlugin(Settings settings) {
049        this.settings = settings;
050    }
051
052    @Override
053    public String name() {
054        return "jdbc-"
055                + Build.getInstance().getVersion() + "-"
056                + Build.getInstance().getShortHash();
057    }
058
059    @Override
060    public String description() {
061        return "JDBC plugin";
062    }
063
064    @Override
065    public Collection<Class<? extends Module>> modules() {
066        Collection<Class<? extends Module>> modules = newArrayList();
067        // if we are in feeder node mode, we skip initiating the server-side only river state module
068        if (!"feeder".equals(settings.get("name"))) {
069            modules.add(RiverStateModule.class);
070        }
071        return modules;
072    }
073
074    public void onModule(RiversModule module) {
075        module.registerRiver("jdbc", JDBCRiverModule.class);
076    }
077
078    public void onModule(ActionModule module) {
079        module.registerAction(DeleteRiverStateAction.INSTANCE, TransportDeleteRiverStateAction.class);
080        module.registerAction(PutRiverStateAction.INSTANCE, TransportPutRiverStateAction.class);
081        module.registerAction(PostRiverStateAction.INSTANCE, TransportPostRiverStateAction.class);
082        module.registerAction(GetRiverStateAction.INSTANCE, TransportGetRiverStateAction.class);
083        module.registerAction(RunRiverAction.INSTANCE, TransportRunRiverAction.class);
084    }
085
086    public void onModule(RestModule module) {
087        module.addRestAction(RestRunRiverAction.class);
088        module.addRestAction(RestRiverStateAction.class);
089    }
090
091}