CoreModuleProvider.java 10.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
 *
 */

package org.apache.skywalking.oap.server.core;

21
import java.io.IOException;
22
import org.apache.skywalking.oap.server.configuration.api.ConfigurationModule;
23 24
import org.apache.skywalking.oap.server.core.analysis.*;
import org.apache.skywalking.oap.server.core.analysis.worker.MetricsStreamProcessor;
25
import org.apache.skywalking.oap.server.core.annotation.AnnotationScan;
26 27 28 29 30 31 32 33
import org.apache.skywalking.oap.server.core.cache.*;
import org.apache.skywalking.oap.server.core.cluster.*;
import org.apache.skywalking.oap.server.core.config.*;
import org.apache.skywalking.oap.server.core.oal.rt.*;
import org.apache.skywalking.oap.server.core.query.*;
import org.apache.skywalking.oap.server.core.register.service.*;
import org.apache.skywalking.oap.server.core.remote.*;
import org.apache.skywalking.oap.server.core.remote.client.*;
34
import org.apache.skywalking.oap.server.core.remote.health.HealthCheckServiceHandler;
35 36
import org.apache.skywalking.oap.server.core.server.*;
import org.apache.skywalking.oap.server.core.source.*;
37
import org.apache.skywalking.oap.server.core.storage.PersistenceTimer;
38
import org.apache.skywalking.oap.server.core.storage.model.*;
39
import org.apache.skywalking.oap.server.core.storage.ttl.DataTTLKeeperTimer;
40 41
import org.apache.skywalking.oap.server.core.worker.*;
import org.apache.skywalking.oap.server.library.module.*;
42 43 44
import org.apache.skywalking.oap.server.library.server.ServerException;
import org.apache.skywalking.oap.server.library.server.grpc.GRPCServer;
import org.apache.skywalking.oap.server.library.server.jetty.JettyServer;
wu-sheng's avatar
wu-sheng 已提交
45
import org.apache.skywalking.oap.server.telemetry.TelemetryModule;
46 47 48 49 50 51 52 53 54

/**
 * @author peng-yongsheng
 */
public class CoreModuleProvider extends ModuleProvider {

    private final CoreModuleConfig moduleConfig;
    private GRPCServer grpcServer;
    private JettyServer jettyServer;
55
    private RemoteClientManager remoteClientManager;
56
    private final AnnotationScan annotationScan;
57
    private final StorageModels storageModels;
58
    private final SourceReceiverImpl receiver;
wu-sheng's avatar
wu-sheng 已提交
59
    private OALEngine oalEngine;
60 61 62 63

    public CoreModuleProvider() {
        super();
        this.moduleConfig = new CoreModuleConfig();
64
        this.annotationScan = new AnnotationScan();
65
        this.storageModels = new StorageModels();
66
        this.receiver = new SourceReceiverImpl();
67 68 69 70 71 72
    }

    @Override public String name() {
        return "default";
    }

彭勇升 pengys 已提交
73
    @Override public Class<? extends ModuleDefine> module() {
74 75 76 77 78 79 80
        return CoreModule.class;
    }

    @Override public ModuleConfig createConfigBeanIfAbsent() {
        return moduleConfig;
    }

wu-sheng's avatar
wu-sheng 已提交
81
    @Override public void prepare() throws ServiceNotProvidedException, ModuleStartException {
82
        StreamAnnotationListener streamAnnotationListener = new StreamAnnotationListener(getManager());
wu-sheng's avatar
wu-sheng 已提交
83

wu-sheng's avatar
wu-sheng 已提交
84 85 86
        AnnotationScan scopeScan = new AnnotationScan();
        scopeScan.registerListener(new DefaultScopeDefine.Listener());
        try {
wu-sheng's avatar
wu-sheng 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
            scopeScan.scan();

            oalEngine = OALEngineLoader.get();
            oalEngine.setStreamListener(streamAnnotationListener);
            oalEngine.setDispatcherListener(receiver.getDispatcherManager());
            oalEngine.start(getClass().getClassLoader());
        } catch (Exception e) {
            throw new ModuleStartException(e.getMessage(), e);
        }

        AnnotationScan oalDisable = new AnnotationScan();
        oalDisable.registerListener(DisableRegister.INSTANCE);
        oalDisable.registerListener(new DisableRegister.SingleDisableScanListener());
        try {
            oalDisable.scan();
wu-sheng's avatar
wu-sheng 已提交
102 103 104 105
        } catch (IOException e) {
            throw new ModuleStartException(e.getMessage(), e);
        }

106
        grpcServer = new GRPCServer(moduleConfig.getGRPCHost(), moduleConfig.getGRPCPort());
107 108 109 110 111 112
        if (moduleConfig.getMaxConcurrentCallsPerConnection() > 0) {
            grpcServer.setMaxConcurrentCallsPerConnection(moduleConfig.getMaxConcurrentCallsPerConnection());
        }
        if (moduleConfig.getMaxMessageSize() > 0) {
            grpcServer.setMaxMessageSize(moduleConfig.getMaxMessageSize());
        }
113 114
        grpcServer.initialize();

115
        jettyServer = new JettyServer(moduleConfig.getRestHost(), moduleConfig.getRestPort(), moduleConfig.getRestContextPath(), moduleConfig.getJettySelectors());
116 117
        jettyServer.initialize();

118
        this.registerServiceImplementation(ConfigService.class, new ConfigService(moduleConfig));
119 120
        this.registerServiceImplementation(DownsamplingConfigService.class, new DownsamplingConfigService(moduleConfig.getDownsampling()));

121 122 123
        this.registerServiceImplementation(GRPCHandlerRegister.class, new GRPCHandlerRegisterImpl(grpcServer));
        this.registerServiceImplementation(JettyHandlerRegister.class, new JettyHandlerRegisterImpl(jettyServer));

124 125
        this.registerServiceImplementation(IComponentLibraryCatalogService.class, new ComponentLibraryCatalogService());

126
        this.registerServiceImplementation(SourceReceiver.class, receiver);
彭勇升 pengys 已提交
127

128 129 130 131
        WorkerInstancesService instancesService = new WorkerInstancesService();
        this.registerServiceImplementation(IWorkerInstanceGetter.class, instancesService);
        this.registerServiceImplementation(IWorkerInstanceSetter.class, instancesService);

彭勇升 pengys 已提交
132
        this.registerServiceImplementation(RemoteSenderService.class, new RemoteSenderService(getManager()));
133 134 135
        this.registerServiceImplementation(IModelSetter.class, storageModels);
        this.registerServiceImplementation(IModelGetter.class, storageModels);
        this.registerServiceImplementation(IModelOverride.class, storageModels);
136

137 138 139
        this.registerServiceImplementation(ServiceInventoryCache.class, new ServiceInventoryCache(getManager()));
        this.registerServiceImplementation(IServiceInventoryRegister.class, new ServiceInventoryRegister(getManager()));

140 141 142
        this.registerServiceImplementation(ServiceInstanceInventoryCache.class, new ServiceInstanceInventoryCache(getManager()));
        this.registerServiceImplementation(IServiceInstanceInventoryRegister.class, new ServiceInstanceInventoryRegister(getManager()));

143 144 145
        this.registerServiceImplementation(EndpointInventoryCache.class, new EndpointInventoryCache(getManager()));
        this.registerServiceImplementation(IEndpointInventoryRegister.class, new EndpointInventoryRegister(getManager()));

146 147 148
        this.registerServiceImplementation(NetworkAddressInventoryCache.class, new NetworkAddressInventoryCache(getManager()));
        this.registerServiceImplementation(INetworkAddressInventoryRegister.class, new NetworkAddressInventoryRegister(getManager()));

149
        this.registerServiceImplementation(TopologyQueryService.class, new TopologyQueryService(getManager()));
彭勇升 pengys 已提交
150 151
        this.registerServiceImplementation(MetricQueryService.class, new MetricQueryService(getManager()));
        this.registerServiceImplementation(TraceQueryService.class, new TraceQueryService(getManager()));
152
        this.registerServiceImplementation(LogQueryService.class, new LogQueryService(getManager()));
153
        this.registerServiceImplementation(MetadataQueryService.class, new MetadataQueryService(getManager()));
154
        this.registerServiceImplementation(AggregationQueryService.class, new AggregationQueryService(getManager()));
155
        this.registerServiceImplementation(AlarmQueryService.class, new AlarmQueryService(getManager()));
wu-sheng's avatar
wu-sheng 已提交
156
        this.registerServiceImplementation(TopNRecordsQueryService.class, new TopNRecordsQueryService(getManager()));
157

wu-sheng's avatar
wu-sheng 已提交
158
        annotationScan.registerListener(streamAnnotationListener);
159 160 161

        this.remoteClientManager = new RemoteClientManager(getManager());
        this.registerServiceImplementation(RemoteClientManager.class, remoteClientManager);
162 163

        MetricsStreamProcessor.getInstance().setEnableDatabaseSession(moduleConfig.isEnableDatabaseSession());
164 165
    }

彭勇升 pengys 已提交
166 167
    @Override public void start() throws ModuleStartException {
        grpcServer.addHandler(new RemoteServiceHandler(getManager()));
168
        grpcServer.addHandler(new HealthCheckServiceHandler());
169
        remoteClientManager.start();
170

彭勇升 pengys 已提交
171
        try {
172
            receiver.scan();
wu-sheng's avatar
wu-sheng 已提交
173 174 175
            annotationScan.scan();

            oalEngine.notifyAllListeners();
176
        } catch (IOException | IllegalAccessException | InstantiationException e) {
彭勇升 pengys 已提交
177 178
            throw new ModuleStartException(e.getMessage(), e);
        }
179 180
    }

wu-sheng's avatar
Fix CI.  
wu-sheng 已提交
181
    @Override public void notifyAfterCompleted() throws ModuleStartException {
182 183 184 185 186 187 188
        try {
            grpcServer.start();
            jettyServer.start();
        } catch (ServerException e) {
            throw new ModuleStartException(e.getMessage(), e);
        }

189
        if (CoreModuleConfig.Role.Mixed.name().equalsIgnoreCase(moduleConfig.getRole()) || CoreModuleConfig.Role.Aggregator.name().equalsIgnoreCase(moduleConfig.getRole())) {
190 191 192
            RemoteInstance gRPCServerInstance = new RemoteInstance(new Address(moduleConfig.getGRPCHost(), moduleConfig.getGRPCPort(), true));
            this.getManager().find(ClusterModule.NAME).provider().getService(ClusterRegister.class).registerRemote(gRPCServerInstance);
        }
193

194
        PersistenceTimer.INSTANCE.start(getManager(), moduleConfig);
195

196 197 198
        if (moduleConfig.isEnableDataKeeperExecutor()) {
            DataTTLKeeperTimer.INSTANCE.start(getManager());
        }
199 200

        CacheUpdateTimer.INSTANCE.start(getManager());
201
    }
wu-sheng's avatar
wu-sheng 已提交
202 203 204

    @Override
    public String[] requiredModules() {
205
        return new String[] {TelemetryModule.NAME, ConfigurationModule.NAME};
wu-sheng's avatar
wu-sheng 已提交
206
    }
207
}