CoreModuleProvider.java 7.6 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
import org.apache.skywalking.oap.server.core.cache.*;
彭勇升 pengys 已提交
26
import org.apache.skywalking.oap.server.core.cluster.*;
27
import org.apache.skywalking.oap.server.core.config.*;
彭勇升 pengys 已提交
28
import org.apache.skywalking.oap.server.core.query.*;
彭勇升 pengys 已提交
29
import org.apache.skywalking.oap.server.core.register.annotation.InventoryTypeListener;
30
import org.apache.skywalking.oap.server.core.register.service.*;
彭勇升 pengys 已提交
31
import org.apache.skywalking.oap.server.core.remote.*;
32
import org.apache.skywalking.oap.server.core.remote.annotation.*;
彭勇升 pengys 已提交
33 34
import org.apache.skywalking.oap.server.core.remote.client.RemoteClientManager;
import org.apache.skywalking.oap.server.core.server.*;
35
import org.apache.skywalking.oap.server.core.source.*;
36
import org.apache.skywalking.oap.server.core.storage.PersistenceTimer;
37 38
import org.apache.skywalking.oap.server.core.storage.annotation.StorageAnnotationListener;
import org.apache.skywalking.oap.server.core.storage.model.IModelGetter;
彭勇升 pengys 已提交
39
import org.apache.skywalking.oap.server.library.module.*;
40 41 42
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;
彭勇升 pengys 已提交
43
import org.slf4j.*;
44 45 46 47 48 49 50 51 52 53 54

/**
 * @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;
55
    private RemoteClientManager remoteClientManager;
56 57 58 59
    private final AnnotationScan annotationScan;
    private final StorageAnnotationListener storageAnnotationListener;
    private final StreamAnnotationListener streamAnnotationListener;
    private final StreamDataAnnotationContainer streamDataAnnotationContainer;
60 61 62 63

    public CoreModuleProvider() {
        super();
        this.moduleConfig = new CoreModuleConfig();
64 65 66 67
        this.annotationScan = new AnnotationScan();
        this.storageAnnotationListener = new StorageAnnotationListener();
        this.streamAnnotationListener = new StreamAnnotationListener();
        this.streamDataAnnotationContainer = new StreamDataAnnotationContainer();
68 69 70 71 72 73
    }

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

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

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

    @Override public void prepare() throws ServiceNotProvidedException {
        grpcServer = new GRPCServer(moduleConfig.getGRPCHost(), moduleConfig.getGRPCPort());
        grpcServer.initialize();

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

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

92 93
        this.registerServiceImplementation(IComponentLibraryCatalogService.class, new ComponentLibraryCatalogService());

94
        this.registerServiceImplementation(SourceReceiver.class, new SourceReceiverImpl());
彭勇升 pengys 已提交
95

96
        this.registerServiceImplementation(StreamDataClassGetter.class, streamDataAnnotationContainer);
彭勇升 pengys 已提交
97 98

        this.registerServiceImplementation(RemoteSenderService.class, new RemoteSenderService(getManager()));
99 100
        this.registerServiceImplementation(IModelGetter.class, storageAnnotationListener);

101 102 103
        this.registerServiceImplementation(ServiceInventoryCache.class, new ServiceInventoryCache(getManager()));
        this.registerServiceImplementation(IServiceInventoryRegister.class, new ServiceInventoryRegister(getManager()));

104 105 106
        this.registerServiceImplementation(ServiceInstanceInventoryCache.class, new ServiceInstanceInventoryCache(getManager()));
        this.registerServiceImplementation(IServiceInstanceInventoryRegister.class, new ServiceInstanceInventoryRegister(getManager()));

107 108 109
        this.registerServiceImplementation(EndpointInventoryCache.class, new EndpointInventoryCache(getManager()));
        this.registerServiceImplementation(IEndpointInventoryRegister.class, new EndpointInventoryRegister(getManager()));

110 111 112
        this.registerServiceImplementation(NetworkAddressInventoryCache.class, new NetworkAddressInventoryCache(getManager()));
        this.registerServiceImplementation(INetworkAddressInventoryRegister.class, new NetworkAddressInventoryRegister(getManager()));

113
        this.registerServiceImplementation(TopologyQueryService.class, new TopologyQueryService(getManager()));
彭勇升 pengys 已提交
114 115
        this.registerServiceImplementation(MetricQueryService.class, new MetricQueryService(getManager()));
        this.registerServiceImplementation(TraceQueryService.class, new TraceQueryService(getManager()));
116

117 118
        annotationScan.registerListener(storageAnnotationListener);
        annotationScan.registerListener(streamAnnotationListener);
119
        annotationScan.registerListener(new IndicatorTypeListener(getManager()));
彭勇升 pengys 已提交
120
        annotationScan.registerListener(new InventoryTypeListener(getManager()));
121
        annotationScan.registerListener(new RecordTypeListener(getManager()));
122 123 124

        this.remoteClientManager = new RemoteClientManager(getManager());
        this.registerServiceImplementation(RemoteClientManager.class, remoteClientManager);
125 126
    }

彭勇升 pengys 已提交
127 128
    @Override public void start() throws ModuleStartException {
        grpcServer.addHandler(new RemoteServiceHandler(getManager()));
129
        remoteClientManager.start();
130

彭勇升 pengys 已提交
131
        try {
132 133 134
            annotationScan.scan(() -> {
                streamDataAnnotationContainer.generate(streamAnnotationListener.getStreamClasses());
            });
135
        } catch (IOException e) {
彭勇升 pengys 已提交
136 137
            throw new ModuleStartException(e.getMessage(), e);
        }
138 139
    }

wu-sheng's avatar
Fix CI.  
wu-sheng 已提交
140
    @Override public void notifyAfterCompleted() throws ModuleStartException {
141 142 143 144 145 146 147
        try {
            grpcServer.start();
            jettyServer.start();
        } catch (ServerException e) {
            throw new ModuleStartException(e.getMessage(), e);
        }

彭勇升 pengys 已提交
148
        RemoteInstance gRPCServerInstance = new RemoteInstance(moduleConfig.getGRPCHost(), moduleConfig.getGRPCPort(), true);
149
        this.getManager().find(ClusterModule.NAME).getService(ClusterRegister.class).registerRemote(gRPCServerInstance);
150 151

        PersistenceTimer.INSTANCE.start(getManager());
152
    }
wu-sheng's avatar
wu-sheng 已提交
153 154 155 156 157

    @Override
    public String[] requiredModules() {
        return new String[0];
    }
158
}