blob: 293814045625d3a0922c370f9d08b2c37ad4bbff (
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
|
// 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.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.config.model.application.provider.Bundle;
import com.yahoo.config.application.ConfigDefinitionDir;
import com.yahoo.io.IOUtils;
import com.yahoo.log.LogLevel;
import com.yahoo.vespa.defaults.Defaults;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Config server db is the maintainer of the serverdb directory containing def files and the file system sessions.
* See also {@link com.yahoo.vespa.config.server.deploy.TenantFileSystemDirs} which maintains directories per tenant.
*
* @author lulf
* @since 5.1
*/
public class ConfigServerDB {
private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(ConfigServerDB.class.getName());
private final File serverDB;
private final ConfigserverConfig configserverConfig;
public ConfigServerDB(ConfigserverConfig configserverConfig) {
this.configserverConfig = configserverConfig;
this.serverDB = new File(Defaults.getDefaults().underVespaHome(configserverConfig.configServerDBDir()));
create();
try {
initialize(configserverConfig.configModelPluginDir());
} catch (IllegalArgumentException e) {
log.log(LogLevel.ERROR, "Error initializing serverdb: " + e.getMessage());
} catch (IOException e) {
throw new RuntimeException("Unable to initialize server db", e);
}
}
public static ConfigServerDB createTestConfigServerDb(String dir) {
return new ConfigServerDB(new ConfigserverConfig(new ConfigserverConfig.Builder().configServerDBDir(dir)));
}
public File dest() { return new File(serverDB, "configs"); }
public File classes() { return new File(serverDB, "classes"); }
public File vespaapps() { return new File(serverDB, "vespaapps"); }
public File serverdefs() { return new File(serverDB, "serverdefs"); }
/**
* Creates all the config server db's dirs that are global.
*/
public void create() {
cr(dest());
cr(classes());
cr(vespaapps());
cr(serverdefs());
}
public static void cr(File d) {
if (d.exists()) {
if (!d.isDirectory()) {
throw new IllegalArgumentException(d.getAbsolutePath() + " exists, but isn't a directory.");
}
} else {
if (!d.mkdirs()) {
throw new IllegalArgumentException("Couldn't create " + d.getAbsolutePath());
}
}
}
private void initialize(List<String> pluginDirectories) throws IOException {
IOUtils.recursiveDeleteDir(serverdefs());
IOUtils.copyDirectory(classes(), serverdefs());
ConfigDefinitionDir configDefinitionDir = new ConfigDefinitionDir(serverdefs());
ArrayList<Bundle> bundles = new ArrayList<>();
for (String pluginDirectory : pluginDirectories) {
bundles.addAll(Bundle.getBundles(new File(pluginDirectory)));
}
log.log(LogLevel.DEBUG, "Found " + bundles.size() + " bundles");
List<Bundle> addedBundles = new ArrayList<>();
for (Bundle bundle : bundles) {
log.log(LogLevel.DEBUG, "Bundle in " + bundle.getFile().getAbsolutePath() + " appears to contain " + bundle.getDefEntries().size() + " entries");
configDefinitionDir.addConfigDefinitionsFromBundle(bundle, addedBundles);
addedBundles.add(bundle);
}
}
public ConfigserverConfig getConfigserverConfig() {
return configserverConfig;
}
}
|