blob: 6c2c080e6e4c7b1d42329f01259a9739fef67704 (
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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.configchange;
import com.yahoo.config.model.api.ConfigChangeAction;
import com.yahoo.config.model.api.ServiceInfo;
import java.util.*;
/**
* Represents all actions to restart services in order to handle a config change.
*
* @author geirst
* @since 5.44
*/
public class RestartActions {
public static class Entry {
private final String clusterName;
private final String clusterType;
private final String serviceType;
private final Set<ServiceInfo> services = new LinkedHashSet<>();
private final Set<String> messages = new TreeSet<>();
private Entry addService(ServiceInfo service) {
services.add(service);
return this;
}
private Entry addMessage(String message) {
messages.add(message);
return this;
}
private Entry(String clusterName, String clusterType, String serviceType) {
this.clusterName = clusterName;
this.clusterType = clusterType;
this.serviceType = serviceType;
}
public String getClusterName() {
return clusterName;
}
public String getClusterType() {
return clusterType;
}
public String getServiceType() {
return serviceType;
}
public Set<ServiceInfo> getServices() {
return services;
}
public Set<String> getMessages() {
return messages;
}
}
private Entry addEntry(ServiceInfo service) {
String clusterName = service.getProperty("clustername").orElse("");
String clusterType = service.getProperty("clustertype").orElse("");
String entryId = clusterType + "." + clusterName + "." + service.getServiceType();
Entry entry = actions.get(entryId);
if (entry == null) {
entry = new Entry(clusterName, clusterType, service.getServiceType());
actions.put(entryId, entry);
}
return entry;
}
private final Map<String, Entry> actions = new TreeMap<>();
public RestartActions() {
}
public RestartActions(List<ConfigChangeAction> actions) {
for (ConfigChangeAction action : actions) {
if (action.getType().equals(ConfigChangeAction.Type.RESTART)) {
for (ServiceInfo service : action.getServices()) {
addEntry(service).
addService(service).
addMessage(action.getMessage());
}
}
}
}
public List<Entry> getEntries() {
return new ArrayList<>(actions.values());
}
}
|