Search in sources :

Example 1 with PeerDatabase

use of net.yacy.grid.io.db.PeerDatabase in project yacy_grid_mcp by yacy.

the class Data method init.

// public static Swagger swagger;
public static void init(File serviceData, Map<String, String> cc, boolean localStorage) {
    PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %p %c %x - %m%n");
    logger = Logger.getRootLogger();
    logger.removeAllAppenders();
    logAppender = new LogAppender(layout, 100000);
    logger.addAppender(logAppender);
    logger.addAppender(new ConsoleAppender(layout));
    config = cc;
    /*
        try {
            swagger = new Swagger(new File(new File(approot, "conf"), "swagger.json"));
        } catch (UnsupportedEncodingException | FileNotFoundException e) {
        }
        */
    // swagger.getServlets().forEach(path -> System.out.println(swagger.getServlet(path).toString()));
    gridServicePath = serviceData;
    if (!gridServicePath.exists())
        gridServicePath.mkdirs();
    // create databases
    File dbPath = new File(gridServicePath, "db");
    if (!dbPath.exists())
        dbPath.mkdirs();
    peerDB = new PeerDatabase(dbPath);
    peerJsonDB = new JSONDatabase(peerDB);
    // create broker
    File messagesPath = new File(gridServicePath, "messages");
    if (!messagesPath.exists())
        messagesPath.mkdirs();
    boolean lazy = config.containsKey("grid.broker.lazy") && config.get("grid.broker.lazy").equals("true");
    gridBroker = new GridBroker(lazy, localStorage ? messagesPath : null);
    // create storage
    File assetsPath = new File(gridServicePath, "assets");
    boolean deleteafterread = cc.containsKey("grid.assets.delete") && cc.get("grid.assets.delete").equals("true");
    gridStorage = new GridStorage(deleteafterread, localStorage ? assetsPath : null);
    // create index
    String elasticsearchAddress = config.getOrDefault("grid.elasticsearch.address", "");
    String elasticsearchClusterName = config.getOrDefault("grid.elasticsearch.clusterName", "");
    gridIndex = new GridIndex();
    gridIndex.connectElasticsearch(ElasticIndexFactory.PROTOCOL_PREFIX + elasticsearchAddress + "/" + elasticsearchClusterName);
    // connect outside services
    // first try to connect to the configured MCPs.
    // if that fails, try to make all connections self
    String gridMcpAddressl = config.containsKey("grid.mcp.address") ? config.get("grid.mcp.address") : "";
    String[] gridMcpAddress = gridMcpAddressl.split(",");
    boolean mcpConnected = false;
    for (String address : gridMcpAddress) {
        String host = getHost(address);
        int port = YaCyServices.mcp.getDefaultPort();
        if (address.length() > 0 && Data.gridBroker.connectMCP(host, port) && Data.gridStorage.connectMCP(host, port) && Data.gridIndex.connectMCP(host, port)) {
            Data.logger.info("Connected MCP at " + getHost(address));
            mcpConnected = true;
            break;
        }
    }
    if (!mcpConnected) {
        // try to connect to local services directly
        String[] gridBrokerAddress = (config.containsKey("grid.broker.address") ? config.get("grid.broker.address") : "").split(",");
        for (String address : gridBrokerAddress) {
            if (Data.gridBroker.connectRabbitMQ(getHost(address), getPort(address, "-1"), getUser(address, "anonymous"), getPassword(address, "yacy"))) {
                Data.logger.info("Connected Broker at " + getHost(address));
                break;
            }
        }
        if (!Data.gridBroker.isRabbitMQConnected()) {
            Data.logger.info("Connected to the embedded Broker");
        }
        String[] gridFtpAddress = (config.containsKey("grid.ftp.address") ? config.get("grid.ftp.address") : "").split(",");
        for (String address : gridFtpAddress) {
            if (address.length() > 0 && Data.gridStorage.connectFTP(getHost(address), getPort(address, "2121"), getUser(address, "anonymous"), getPassword(address, "yacy"))) {
                Data.logger.info("Connected Storage at " + getHost(address));
                break;
            }
        }
        if (!Data.gridStorage.isFTPConnected()) {
            Data.logger.info("Connected to the embedded Asset Storage");
        }
    }
    // init boosts from configuration
    Map<String, String> defaultBoosts = Service.readDoubleConfig("boost.properties");
    boostsFactory = new BoostsFactory(defaultBoosts);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) GridBroker(net.yacy.grid.io.messages.GridBroker) GridStorage(net.yacy.grid.io.assets.GridStorage) JSONDatabase(net.yacy.grid.io.db.JSONDatabase) PatternLayout(org.apache.log4j.PatternLayout) GridIndex(net.yacy.grid.io.index.GridIndex) PeerDatabase(net.yacy.grid.io.db.PeerDatabase) BoostsFactory(net.yacy.grid.io.index.BoostsFactory) File(java.io.File)

Aggregations

File (java.io.File)1 GridStorage (net.yacy.grid.io.assets.GridStorage)1 JSONDatabase (net.yacy.grid.io.db.JSONDatabase)1 PeerDatabase (net.yacy.grid.io.db.PeerDatabase)1 BoostsFactory (net.yacy.grid.io.index.BoostsFactory)1 GridIndex (net.yacy.grid.io.index.GridIndex)1 GridBroker (net.yacy.grid.io.messages.GridBroker)1 ConsoleAppender (org.apache.log4j.ConsoleAppender)1 PatternLayout (org.apache.log4j.PatternLayout)1