summaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server/InjectedGlobalComponentRegistry.java
blob: 9badd19009fa00333562223e992208c44614b2b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server;

import com.google.inject.Inject;
import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.concurrent.StripedExecutor;
import com.yahoo.concurrent.ThreadFactoryFactory;
import com.yahoo.config.model.api.ConfigDefinitionRepo;
import com.yahoo.config.provision.Provisioner;
import com.yahoo.config.provision.TenantName;
import com.yahoo.config.provision.Zone;
import com.yahoo.container.jdisc.secretstore.SecretStore;
import com.yahoo.vespa.config.server.application.PermanentApplicationPackage;
import com.yahoo.vespa.config.server.host.HostRegistries;
import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry;
import com.yahoo.vespa.config.server.monitoring.Metrics;
import com.yahoo.vespa.config.server.provision.HostProvisionerProvider;
import com.yahoo.vespa.config.server.rpc.RpcServer;
import com.yahoo.vespa.config.server.session.SessionPreparer;
import com.yahoo.vespa.config.server.tenant.TenantListener;
import com.yahoo.vespa.config.server.tenant.TenantRepository;
import com.yahoo.vespa.config.server.zookeeper.ConfigCurator;
import com.yahoo.vespa.curator.Curator;
import com.yahoo.vespa.flags.FlagSource;

import java.time.Clock;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Registry containing all the "static"/"global" components in a config server in one place.
 *
 * @author Ulf Lilleengen
 */
public class InjectedGlobalComponentRegistry implements GlobalComponentRegistry {

    private final Curator curator;
    private final ConfigCurator configCurator;
    private final Metrics metrics;
    private final ModelFactoryRegistry modelFactoryRegistry;
    private final SessionPreparer sessionPreparer;
    private final RpcServer rpcServer;
    private final ConfigserverConfig configserverConfig;
    private final ConfigDefinitionRepo staticConfigDefinitionRepo;
    private final PermanentApplicationPackage permanentApplicationPackage;
    private final HostRegistries hostRegistries;
    private final Optional<Provisioner> hostProvisioner;
    private final Zone zone;
    private final ConfigServerDB configServerDB;
    private final FlagSource flagSource;
    private final SecretStore secretStore;
    private final StripedExecutor<TenantName> zkWatcherExecutor;
    private final ExecutorService zkCacheExecutor;

    @SuppressWarnings("WeakerAccess")
    @Inject
    public InjectedGlobalComponentRegistry(Curator curator,
                                           ConfigCurator configCurator,
                                           Metrics metrics,
                                           ModelFactoryRegistry modelFactoryRegistry,
                                           SessionPreparer sessionPreparer,
                                           RpcServer rpcServer,
                                           ConfigserverConfig configserverConfig,
                                           SuperModelGenerationCounter superModelGenerationCounter,
                                           ConfigDefinitionRepo staticConfigDefinitionRepo,
                                           PermanentApplicationPackage permanentApplicationPackage,
                                           HostRegistries hostRegistries,
                                           HostProvisionerProvider hostProvisionerProvider,
                                           Zone zone,
                                           ConfigServerDB configServerDB,
                                           FlagSource flagSource,
                                           SecretStore secretStore) {
        this.curator = curator;
        this.configCurator = configCurator;
        this.metrics = metrics;
        this.modelFactoryRegistry = modelFactoryRegistry;
        this.sessionPreparer = sessionPreparer;
        this.rpcServer = rpcServer;
        this.configserverConfig = configserverConfig;
        this.staticConfigDefinitionRepo = staticConfigDefinitionRepo;
        this.permanentApplicationPackage = permanentApplicationPackage;
        this.hostRegistries = hostRegistries;
        this.hostProvisioner = hostProvisionerProvider.getHostProvisioner();
        this.zone = zone;
        this.configServerDB = configServerDB;
        this.flagSource = flagSource;
        this.secretStore = secretStore;
        this.zkWatcherExecutor = new StripedExecutor<>();
        this.zkCacheExecutor = Executors.newFixedThreadPool(1, ThreadFactoryFactory.getThreadFactory(TenantRepository.class.getName()));
    }

    @Override
    public Curator getCurator() { return curator; }
    @Override
    public ConfigCurator getConfigCurator() { return configCurator; }
    @Override
    public Metrics getMetrics() { return metrics; }
    @Override
    public SessionPreparer getSessionPreparer() { return sessionPreparer; }
    @Override
    public ConfigserverConfig getConfigserverConfig() { return configserverConfig; }
    @Override
    public TenantListener getTenantListener() { return rpcServer; }
    @Override
    public ReloadListener getReloadListener() { return rpcServer; }
    @Override
    public ConfigDefinitionRepo getStaticConfigDefinitionRepo() { return staticConfigDefinitionRepo; }
    @Override
    public PermanentApplicationPackage getPermanentApplicationPackage() { return permanentApplicationPackage; }
    @Override
    public HostRegistries getHostRegistries() { return hostRegistries; }
    @Override
    public ModelFactoryRegistry getModelFactoryRegistry() { return modelFactoryRegistry; }

    @Override
    public Optional<Provisioner> getHostProvisioner() {
        return hostProvisioner;
    }

    @Override
    public Zone getZone() {
        return zone;
    }

    @Override
    public Clock getClock() {return  Clock.systemUTC();}

    @Override
    public ConfigServerDB getConfigServerDB() { return configServerDB; }

    @Override
    public StripedExecutor<TenantName> getZkWatcherExecutor() {
        return zkWatcherExecutor;
    }

    @Override
    public FlagSource getFlagSource() { return flagSource; }

    @Override
    public ExecutorService getZkCacheExecutor() {
        return zkCacheExecutor;
    }

    @Override
    public SecretStore getSecretStore() {
        return secretStore;
    }
}