CoreModuleProvider.java 10.5 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.core.analysis.DisableRegister;
23
import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorTypeListener;
24
import org.apache.skywalking.oap.server.core.analysis.record.annotation.RecordTypeListener;
wu-sheng's avatar
wu-sheng 已提交
25
import org.apache.skywalking.oap.server.core.analysis.topn.annotation.TopNTypeListener;
26
import org.apache.skywalking.oap.server.core.annotation.AnnotationScan;
27 28 29 30
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.query.*;
彭勇升 pengys 已提交
31
import org.apache.skywalking.oap.server.core.register.annotation.InventoryTypeListener;
32 33 34 35
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.annotation.*;
import org.apache.skywalking.oap.server.core.remote.client.*;
36
import org.apache.skywalking.oap.server.core.remote.health.HealthCheckServiceHandler;
37 38
import org.apache.skywalking.oap.server.core.server.*;
import org.apache.skywalking.oap.server.core.source.*;
39
import org.apache.skywalking.oap.server.core.storage.PersistenceTimer;
40
import org.apache.skywalking.oap.server.core.storage.annotation.StorageAnnotationListener;
41
import org.apache.skywalking.oap.server.core.storage.model.*;
42
import org.apache.skywalking.oap.server.core.storage.ttl.DataTTLKeeperTimer;
43
import org.apache.skywalking.oap.server.core.worker.*;
44
import org.apache.skywalking.oap.server.library.module.*;
45 46 47
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 已提交
48
import org.apache.skywalking.oap.server.telemetry.TelemetryModule;
49
import org.slf4j.*;
50 51 52 53 54 55 56 57 58 59 60

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

    private static final Logger logger = LoggerFactory.getLogger(CoreModuleProvider.class);

    private final CoreModuleConfig moduleConfig;
    private GRPCServer grpcServer;
    private JettyServer jettyServer;
61
    private RemoteClientManager remoteClientManager;
62 63 64 65
    private final AnnotationScan annotationScan;
    private final StorageAnnotationListener storageAnnotationListener;
    private final StreamAnnotationListener streamAnnotationListener;
    private final StreamDataAnnotationContainer streamDataAnnotationContainer;
66
    private final SourceReceiverImpl receiver;
67 68 69 70

    public CoreModuleProvider() {
        super();
        this.moduleConfig = new CoreModuleConfig();
71 72 73 74
        this.annotationScan = new AnnotationScan();
        this.storageAnnotationListener = new StorageAnnotationListener();
        this.streamAnnotationListener = new StreamAnnotationListener();
        this.streamDataAnnotationContainer = new StreamDataAnnotationContainer();
75
        this.receiver = new SourceReceiverImpl();
76 77 78 79 80 81
    }

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

彭勇升 pengys 已提交
82
    @Override public Class<? extends ModuleDefine> module() {
83 84 85 86 87 88 89
        return CoreModule.class;
    }

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

wu-sheng's avatar
wu-sheng 已提交
90 91 92
    @Override public void prepare() throws ServiceNotProvidedException, ModuleStartException {
        AnnotationScan scopeScan = new AnnotationScan();
        scopeScan.registerListener(new DefaultScopeDefine.Listener());
93
        scopeScan.registerListener(DisableRegister.INSTANCE);
wu-sheng's avatar
wu-sheng 已提交
94
        scopeScan.registerListener(new DisableRegister.SingleDisableScanListener());
wu-sheng's avatar
wu-sheng 已提交
95 96 97 98 99 100
        try {
            scopeScan.scan(null);
        } catch (IOException e) {
            throw new ModuleStartException(e.getMessage(), e);
        }

101
        grpcServer = new GRPCServer(moduleConfig.getGRPCHost(), moduleConfig.getGRPCPort());
102 103 104 105 106 107
        if (moduleConfig.getMaxConcurrentCallsPerConnection() > 0) {
            grpcServer.setMaxConcurrentCallsPerConnection(moduleConfig.getMaxConcurrentCallsPerConnection());
        }
        if (moduleConfig.getMaxMessageSize() > 0) {
            grpcServer.setMaxMessageSize(moduleConfig.getMaxMessageSize());
        }
108 109
        grpcServer.initialize();

110
        jettyServer = new JettyServer(moduleConfig.getRestHost(), moduleConfig.getRestPort(), moduleConfig.getRestContextPath(), moduleConfig.getJettySelectors());
111 112
        jettyServer.initialize();

113
        this.registerServiceImplementation(ConfigService.class, new ConfigService(moduleConfig));
114 115
        this.registerServiceImplementation(DownsamplingConfigService.class, new DownsamplingConfigService(moduleConfig.getDownsampling()));

116 117 118
        this.registerServiceImplementation(GRPCHandlerRegister.class, new GRPCHandlerRegisterImpl(grpcServer));
        this.registerServiceImplementation(JettyHandlerRegister.class, new JettyHandlerRegisterImpl(jettyServer));

119 120
        this.registerServiceImplementation(IComponentLibraryCatalogService.class, new ComponentLibraryCatalogService());

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

123
        this.registerServiceImplementation(StreamDataClassGetter.class, streamDataAnnotationContainer);
彭勇升 pengys 已提交
124

125 126 127 128
        WorkerInstancesService instancesService = new WorkerInstancesService();
        this.registerServiceImplementation(IWorkerInstanceGetter.class, instancesService);
        this.registerServiceImplementation(IWorkerInstanceSetter.class, instancesService);

彭勇升 pengys 已提交
129
        this.registerServiceImplementation(RemoteSenderService.class, new RemoteSenderService(getManager()));
130
        this.registerServiceImplementation(IModelGetter.class, storageAnnotationListener);
131
        this.registerServiceImplementation(IModelOverride.class, storageAnnotationListener);
132

133 134 135
        this.registerServiceImplementation(ServiceInventoryCache.class, new ServiceInventoryCache(getManager()));
        this.registerServiceImplementation(IServiceInventoryRegister.class, new ServiceInventoryRegister(getManager()));

136 137 138
        this.registerServiceImplementation(ServiceInstanceInventoryCache.class, new ServiceInstanceInventoryCache(getManager()));
        this.registerServiceImplementation(IServiceInstanceInventoryRegister.class, new ServiceInstanceInventoryRegister(getManager()));

139 140 141
        this.registerServiceImplementation(EndpointInventoryCache.class, new EndpointInventoryCache(getManager()));
        this.registerServiceImplementation(IEndpointInventoryRegister.class, new EndpointInventoryRegister(getManager()));

142 143 144
        this.registerServiceImplementation(NetworkAddressInventoryCache.class, new NetworkAddressInventoryCache(getManager()));
        this.registerServiceImplementation(INetworkAddressInventoryRegister.class, new NetworkAddressInventoryRegister(getManager()));

145
        this.registerServiceImplementation(TopologyQueryService.class, new TopologyQueryService(getManager()));
彭勇升 pengys 已提交
146 147
        this.registerServiceImplementation(MetricQueryService.class, new MetricQueryService(getManager()));
        this.registerServiceImplementation(TraceQueryService.class, new TraceQueryService(getManager()));
148
        this.registerServiceImplementation(MetadataQueryService.class, new MetadataQueryService(getManager()));
149
        this.registerServiceImplementation(AggregationQueryService.class, new AggregationQueryService(getManager()));
150
        this.registerServiceImplementation(AlarmQueryService.class, new AlarmQueryService(getManager()));
wu-sheng's avatar
wu-sheng 已提交
151
        this.registerServiceImplementation(TopNRecordsQueryService.class, new TopNRecordsQueryService(getManager()));
152

153 154
        annotationScan.registerListener(storageAnnotationListener);
        annotationScan.registerListener(streamAnnotationListener);
155
        annotationScan.registerListener(new IndicatorTypeListener(getManager()));
彭勇升 pengys 已提交
156
        annotationScan.registerListener(new InventoryTypeListener(getManager()));
157
        annotationScan.registerListener(new RecordTypeListener(getManager()));
wu-sheng's avatar
wu-sheng 已提交
158
        annotationScan.registerListener(new TopNTypeListener(getManager()));
159 160 161

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

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

彭勇升 pengys 已提交
169
        try {
170 171
            receiver.scan();

172 173 174
            annotationScan.scan(() -> {
                streamDataAnnotationContainer.generate(streamAnnotationListener.getStreamClasses());
            });
175
        } catch (IOException | IllegalAccessException | InstantiationException e) {
彭勇升 pengys 已提交
176 177
            throw new ModuleStartException(e.getMessage(), e);
        }
178 179
    }

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

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

        PersistenceTimer.INSTANCE.start(getManager());
194 195 196

        DataTTLKeeperTimer.INSTANCE.setDataTTL(moduleConfig.getDataTTL());
        DataTTLKeeperTimer.INSTANCE.start(getManager());
197 198

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

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