blob: 0e20410ce7715f7802bd412b7291edd36cf34b81 (
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core;
import com.yahoo.vdslib.state.ClusterState;
import com.yahoo.vespa.clustercontroller.core.listeners.NodeAddedOrRemovedListener;
import com.yahoo.vespa.clustercontroller.core.listeners.NodeStateOrHostInfoChangeHandler;
public abstract class RemoteClusterControllerTask {
public static class Context {
public ContentCluster cluster;
public ClusterState currentState;
public MasterInterface masterInfo;
public NodeStateOrHostInfoChangeHandler nodeStateOrHostInfoChangeHandler;
public NodeAddedOrRemovedListener nodeAddedOrRemovedListener;
}
private final Object monitor = new Object();
private boolean completed = false;
public abstract void doRemoteFleetControllerTask(Context context);
/**
* If the task should _not_ be considered complete before a cluster state
* version representing the changes made by the task has been ACKed by
* all distributors.
*
* Note that if a task performs an idempotent state change (e.g. setting maintenance
* mode on a node already in maintenance mode), the task may be considered complete
* immediately if its effective changes have already been ACKed.
*/
public boolean hasVersionAckDependency() { return false; }
/**
* If the task response has been deferred due to hasVersionAckDependency(),
* handleLeadershipLost() will be invoked on the task if the cluster controller
* discovers it has lost leadership in the time between task execution and
* deferred response send time.
*
* This method will also be invoked if the controller is signalled to shut down
* before the dependent cluster version has been published.
*/
public void handleLeadershipLost() {}
public boolean isCompleted() {
synchronized (monitor) {
return completed;
}
}
/** This is called by the fleet controller. */
public void notifyCompleted() {
synchronized (monitor) {
completed = true;
monitor.notifyAll();
}
}
public void waitForCompletion() {
synchronized (monitor) {
while (!completed) {
try{
monitor.wait();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
}
|