CoreModuleProvider.java 9.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.core.analysis.indicator.annotation.IndicatorTypeListener;
23
import org.apache.skywalking.oap.server.core.analysis.record.annotation.RecordTypeListener;
24
import org.apache.skywalking.oap.server.core.annotation.AnnotationScan;
25 26 27 28
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 已提交
29
import org.apache.skywalking.oap.server.core.register.annotation.InventoryTypeListener;
30 31 32 33
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.*;
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.annotation.StorageAnnotationListener;
39
import org.apache.skywalking.oap.server.core.storage.model.*;
40
import org.apache.skywalking.oap.server.core.storage.ttl.DataTTLKeeperTimer;
41
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
import org.slf4j.*;
47 48 49 50 51 52 53 54 55 56 57

/**
 * @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;
58
    private RemoteClientManager remoteClientManager;
59 60 61 62
    private final AnnotationScan annotationScan;
    private final StorageAnnotationListener storageAnnotationListener;
    private final StreamAnnotationListener streamAnnotationListener;
    private final StreamDataAnnotationContainer streamDataAnnotationContainer;
63
    private final SourceReceiverImpl receiver;
64 65 66 67

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

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

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

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

    @Override public void prepare() throws ServiceNotProvidedException {
        grpcServer = new GRPCServer(moduleConfig.getGRPCHost(), moduleConfig.getGRPCPort());
89 90 91 92 93 94
        if (moduleConfig.getMaxConcurrentCallsPerConnection() > 0) {
            grpcServer.setMaxConcurrentCallsPerConnection(moduleConfig.getMaxConcurrentCallsPerConnection());
        }
        if (moduleConfig.getMaxMessageSize() > 0) {
            grpcServer.setMaxMessageSize(moduleConfig.getMaxMessageSize());
        }
95 96 97 98 99
        grpcServer.initialize();

        jettyServer = new JettyServer(moduleConfig.getRestHost(), moduleConfig.getRestPort(), moduleConfig.getRestContextPath());
        jettyServer.initialize();

100 101
        this.registerServiceImplementation(DownsamplingConfigService.class, new DownsamplingConfigService(moduleConfig.getDownsampling()));

102 103 104
        this.registerServiceImplementation(GRPCHandlerRegister.class, new GRPCHandlerRegisterImpl(grpcServer));
        this.registerServiceImplementation(JettyHandlerRegister.class, new JettyHandlerRegisterImpl(jettyServer));

105 106
        this.registerServiceImplementation(IComponentLibraryCatalogService.class, new ComponentLibraryCatalogService());

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

109
        this.registerServiceImplementation(StreamDataClassGetter.class, streamDataAnnotationContainer);
彭勇升 pengys 已提交
110 111

        this.registerServiceImplementation(RemoteSenderService.class, new RemoteSenderService(getManager()));
112
        this.registerServiceImplementation(IModelGetter.class, storageAnnotationListener);
113
        this.registerServiceImplementation(IModelOverride.class, storageAnnotationListener);
114

115 116 117
        this.registerServiceImplementation(ServiceInventoryCache.class, new ServiceInventoryCache(getManager()));
        this.registerServiceImplementation(IServiceInventoryRegister.class, new ServiceInventoryRegister(getManager()));

118 119 120
        this.registerServiceImplementation(ServiceInstanceInventoryCache.class, new ServiceInstanceInventoryCache(getManager()));
        this.registerServiceImplementation(IServiceInstanceInventoryRegister.class, new ServiceInstanceInventoryRegister(getManager()));

121 122 123
        this.registerServiceImplementation(EndpointInventoryCache.class, new EndpointInventoryCache(getManager()));
        this.registerServiceImplementation(IEndpointInventoryRegister.class, new EndpointInventoryRegister(getManager()));

124 125 126
        this.registerServiceImplementation(NetworkAddressInventoryCache.class, new NetworkAddressInventoryCache(getManager()));
        this.registerServiceImplementation(INetworkAddressInventoryRegister.class, new NetworkAddressInventoryRegister(getManager()));

127
        this.registerServiceImplementation(TopologyQueryService.class, new TopologyQueryService(getManager()));
彭勇升 pengys 已提交
128 129
        this.registerServiceImplementation(MetricQueryService.class, new MetricQueryService(getManager()));
        this.registerServiceImplementation(TraceQueryService.class, new TraceQueryService(getManager()));
130
        this.registerServiceImplementation(MetadataQueryService.class, new MetadataQueryService(getManager()));
131
        this.registerServiceImplementation(AggregationQueryService.class, new AggregationQueryService(getManager()));
132
        this.registerServiceImplementation(AlarmQueryService.class, new AlarmQueryService(getManager()));
133

134 135
        annotationScan.registerListener(storageAnnotationListener);
        annotationScan.registerListener(streamAnnotationListener);
136
        annotationScan.registerListener(new IndicatorTypeListener(getManager()));
彭勇升 pengys 已提交
137
        annotationScan.registerListener(new InventoryTypeListener(getManager()));
138
        annotationScan.registerListener(new RecordTypeListener(getManager()));
139 140 141

        this.remoteClientManager = new RemoteClientManager(getManager());
        this.registerServiceImplementation(RemoteClientManager.class, remoteClientManager);
142 143
    }

彭勇升 pengys 已提交
144 145
    @Override public void start() throws ModuleStartException {
        grpcServer.addHandler(new RemoteServiceHandler(getManager()));
146
        grpcServer.addHandler(new HealthCheckServiceHandler());
147
        remoteClientManager.start();
148

彭勇升 pengys 已提交
149
        try {
150 151
            receiver.scan();

152 153 154
            annotationScan.scan(() -> {
                streamDataAnnotationContainer.generate(streamAnnotationListener.getStreamClasses());
            });
155
        } catch (IOException | IllegalAccessException | InstantiationException e) {
彭勇升 pengys 已提交
156 157
            throw new ModuleStartException(e.getMessage(), e);
        }
158 159
    }

wu-sheng's avatar
Fix CI.  
wu-sheng 已提交
160
    @Override public void notifyAfterCompleted() throws ModuleStartException {
161 162 163 164 165 166 167
        try {
            grpcServer.start();
            jettyServer.start();
        } catch (ServerException e) {
            throw new ModuleStartException(e.getMessage(), e);
        }

168
        RemoteInstance gRPCServerInstance = new RemoteInstance(new Address(moduleConfig.getGRPCHost(), moduleConfig.getGRPCPort(), true));
169
        this.getManager().find(ClusterModule.NAME).provider().getService(ClusterRegister.class).registerRemote(gRPCServerInstance);
170 171

        PersistenceTimer.INSTANCE.start(getManager());
172 173 174

        DataTTLKeeperTimer.INSTANCE.setDataTTL(moduleConfig.getDataTTL());
        DataTTLKeeperTimer.INSTANCE.start(getManager());
175 176

        CacheUpdateTimer.INSTANCE.start(getManager());
177
    }
wu-sheng's avatar
wu-sheng 已提交
178 179 180

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