public void prepare()

in oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/StorageModuleElasticsearchProvider.java [148:285]


    public void prepare() throws ServiceNotProvidedException {
        this.registerServiceImplementation(StorageBuilderFactory.class, new StorageBuilderFactory.Default());

        if (StringUtil.isEmpty(config.getNamespace())) {
            config.setNamespace("sw");
        } else {
            config.setNamespace(config.getNamespace().toLowerCase());
        }
        if (config.getDayStep() > 1) {
            TimeSeriesUtils.setDAY_STEP(config.getDayStep());
            TimeSeriesUtils.setSUPER_DATASET_DAY_STEP(config.getDayStep());
        }
        if (config.getSuperDatasetDayStep() > 0) {
            TimeSeriesUtils.setSUPER_DATASET_DAY_STEP(config.getSuperDatasetDayStep());
        }

        if (!StringUtil.isEmpty(config.getSecretsManagementFile())) {
            MultipleFilesChangeMonitor monitor = new MultipleFilesChangeMonitor(
                10, readableContents -> {
                final byte[] secretsFileContent = readableContents.get(0);
                if (secretsFileContent == null) {
                    return;
                }
                Properties secrets = new Properties();
                secrets.load(new ByteArrayInputStream(secretsFileContent));
                config.setUser(secrets.getProperty("user", null));
                config.setPassword(secrets.getProperty("password", null));
                config.setTrustStorePass(secrets.getProperty("trustStorePass", null));

                if (elasticSearchClient == null) {
                    // In the startup process, we just need to change the username/password
                } else {
                    // The client has connected, updates the config and connects again.
                    elasticSearchClient.setUser(config.getUser());
                    elasticSearchClient.setPassword(config.getPassword());
                    elasticSearchClient.setTrustStorePass(config.getTrustStorePass());
                    elasticSearchClient.connect();
                }
            }, config.getSecretsManagementFile(), config.getTrustStorePath());
            /*
             * By leveraging the sync update check feature when startup.
             */
            monitor.start();
        }

        elasticSearchClient = new ElasticSearchClient(
            config.getClusterNodes(), config.getProtocol(), config.getTrustStorePath(), config
            .getTrustStorePass(), config.getUser(), config.getPassword(),
            indexNameConverter(config.getNamespace()), config.getConnectTimeout(),
            config.getSocketTimeout(), config.getResponseTimeout(),
            config.getNumHttpClientThread()
        );
        modelInstaller = new StorageEsInstaller(elasticSearchClient, getManager(), config);

        this.registerServiceImplementation(
            IBatchDAO.class,
            new BatchProcessEsDAO(elasticSearchClient, config.getBulkActions(), config
                .getFlushInterval(), config.getConcurrentRequests(), config.getBatchOfBytes())
        );
        this.registerServiceImplementation(StorageDAO.class, new StorageEsDAO(elasticSearchClient));
        this.registerServiceImplementation(
            IHistoryDeleteDAO.class, new HistoryDeleteEsDAO(elasticSearchClient));
        this.registerServiceImplementation(
            INetworkAddressAliasDAO.class, new NetworkAddressAliasEsDAO(elasticSearchClient, config));
        this.registerServiceImplementation(ITopologyQueryDAO.class, new TopologyQueryEsDAO(elasticSearchClient));
        this.registerServiceImplementation(IMetricsQueryDAO.class, new MetricsQueryEsDAO(elasticSearchClient));
        this.registerServiceImplementation(
            ITraceQueryDAO.class, new TraceQueryEsDAO(elasticSearchClient, config.getSegmentQueryMaxSize()));
        this.registerServiceImplementation(IBrowserLogQueryDAO.class, new BrowserLogQueryEsDAO(elasticSearchClient));
        this.registerServiceImplementation(
            IMetadataQueryDAO.class, new MetadataQueryEsDAO(elasticSearchClient, config));
        this.registerServiceImplementation(IAggregationQueryDAO.class, new AggregationQueryEsDAO(elasticSearchClient));
        this.registerServiceImplementation(IAlarmQueryDAO.class, new AlarmQueryEsDAO(elasticSearchClient));
        this.registerServiceImplementation(IRecordsQueryDAO.class, new RecordsQueryEsDAO(elasticSearchClient));
        this.registerServiceImplementation(ILogQueryDAO.class, new LogQueryEsDAO(elasticSearchClient));
        this.registerServiceImplementation(
            IProfileTaskQueryDAO.class, new ProfileTaskQueryEsDAO(elasticSearchClient, config
                .getProfileTaskQueryMaxSize()));
        this.registerServiceImplementation(
            IProfileTaskLogQueryDAO.class, new ProfileTaskLogEsDAO(elasticSearchClient, config
                .getProfileTaskQueryMaxSize()));
        this.registerServiceImplementation(
            IProfileThreadSnapshotQueryDAO.class, new ProfileThreadSnapshotQueryEsDAO(elasticSearchClient, config
                .getProfileTaskQueryMaxSize()));
        this.registerServiceImplementation(
            UITemplateManagementDAO.class, new UITemplateManagementEsDAO(elasticSearchClient, new UITemplate.Builder()));
        this.registerServiceImplementation(
            UIMenuManagementDAO.class, new UIMenuManagementEsDAO(elasticSearchClient, new UIMenu.Builder()));

        this.registerServiceImplementation(IEventQueryDAO.class, new ESEventQueryDAO(elasticSearchClient));

        this.registerServiceImplementation(
            IEBPFProfilingTaskDAO.class,
            new EBPFProfilingTaskEsDAO(elasticSearchClient, config)
        );
        this.registerServiceImplementation(
            IEBPFProfilingScheduleDAO.class,
            new EBPFProfilingScheduleEsDAO(elasticSearchClient, config)
        );
        this.registerServiceImplementation(
            IEBPFProfilingDataDAO.class,
            new EBPFProfilingDataEsDAO(elasticSearchClient, config)
        );
        this.registerServiceImplementation(
            IContinuousProfilingPolicyDAO.class,
            new ContinuousProfilingPolicyEsDAO(elasticSearchClient, new ContinuousProfilingPolicy.Builder())
        );
        this.registerServiceImplementation(
            IServiceLabelDAO.class,
            new ServiceLabelEsDAO(elasticSearchClient, config)
        );
        this.registerServiceImplementation(
            ITagAutoCompleteQueryDAO.class, new TagAutoCompleteQueryDAO(elasticSearchClient));
        this.registerServiceImplementation(
            IZipkinQueryDAO.class, new ZipkinQueryEsDAO(elasticSearchClient));
        this.registerServiceImplementation(
            ISpanAttachedEventQueryDAO.class, new SpanAttachedEventEsDAO(elasticSearchClient, config));

        this.registerServiceImplementation(
                IAsyncProfilerTaskQueryDAO.class,
                new AsyncProfilerTaskQueryEsDAO(elasticSearchClient, config.getAsyncProfilerTaskQueryMaxSize())
        );
        this.registerServiceImplementation(
                IAsyncProfilerTaskLogQueryDAO.class,
                new AsyncProfilerTaskLogQueryEsDAO(elasticSearchClient, config.getAsyncProfilerTaskQueryMaxSize())
        );
        this.registerServiceImplementation(
                IJFRDataQueryDAO.class,
                new JFRDataQueryEsDAO(elasticSearchClient)
        );
        this.registerServiceImplementation(
            StorageTTLStatusQuery.class,
            new DefaultStorageTTLStatusQuery()
        );
        IndexController.INSTANCE.setLogicSharding(config.isLogicSharding());
        IndexController.INSTANCE.setEnableCustomRouting(config.isEnableCustomRouting());
        this.registerServiceImplementation(IHierarchyQueryDAO.class, new HierarchyQueryEsDAO(elasticSearchClient, config));
    }