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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.orchestrator.policy;
import com.yahoo.vespa.applicationmodel.ApplicationInstance;
import com.yahoo.vespa.applicationmodel.HostName;
import com.yahoo.vespa.orchestrator.OrchestratorContext;
import com.yahoo.vespa.orchestrator.controller.ClusterControllerClientFactory;
import com.yahoo.vespa.orchestrator.controller.ClusterControllerNodeState;
import com.yahoo.vespa.orchestrator.model.ApplicationApi;
import com.yahoo.vespa.orchestrator.model.ApplicationApiImpl;
import com.yahoo.vespa.orchestrator.model.ClusterApi;
import com.yahoo.vespa.orchestrator.model.NodeGroup;
import com.yahoo.vespa.orchestrator.model.StorageNode;
import com.yahoo.vespa.orchestrator.status.ApplicationInstanceStatus;
import com.yahoo.vespa.orchestrator.status.HostStatus;
import com.yahoo.vespa.orchestrator.status.MutableStatusRegistry;
import java.util.logging.Logger;
/**
* @author oyving
*/
public class HostedVespaPolicy implements Policy {
public static final String APPLICATION_SUSPENDED_CONSTRAINT = "application-suspended";
public static final String ENOUGH_SERVICES_UP_CONSTRAINT = "enough-services-up";
public static final String SET_NODE_STATE_CONSTRAINT = "controller-set-node-state";
public static final String CLUSTER_CONTROLLER_AVAILABLE_CONSTRAINT = "controller-available";
public static final String DEADLINE_CONSTRAINT = "deadline";
private static final Logger log = Logger.getLogger(HostedVespaPolicy.class.getName());
private final HostedVespaClusterPolicy clusterPolicy;
private final ClusterControllerClientFactory clusterControllerClientFactory;
public HostedVespaPolicy(HostedVespaClusterPolicy clusterPolicy, ClusterControllerClientFactory clusterControllerClientFactory) {
this.clusterPolicy = clusterPolicy;
this.clusterControllerClientFactory = clusterControllerClientFactory;
}
@Override
public void grantSuspensionRequest(OrchestratorContext context, ApplicationApi application)
throws HostStateChangeDeniedException {
// Apply per-cluster policy
for (ClusterApi cluster : application.getClusters()) {
clusterPolicy.verifyGroupGoingDownIsFine(cluster);
}
// Ask Cluster Controller to set UP storage nodes in maintenance.
// These storage nodes are guaranteed to be NO_REMARKS
for (StorageNode storageNode : application.getUpStorageNodesInGroupInClusterOrder()) {
storageNode.setNodeState(context, ClusterControllerNodeState.MAINTENANCE);
}
// Ensure all nodes in the group are marked as allowed to be down
for (HostName hostName : application.getNodesInGroupWithStatus(HostStatus.NO_REMARKS)) {
application.setHostState(context, hostName, HostStatus.ALLOWED_TO_BE_DOWN);
}
}
@Override
public void releaseSuspensionGrant(OrchestratorContext context, ApplicationApi application)
throws HostStateChangeDeniedException {
// Always defer to Cluster Controller whether it's OK to resume storage node
for (StorageNode storageNode : application.getStorageNodesAllowedToBeDownInGroupInReverseClusterOrder()) {
storageNode.setNodeState(context, ClusterControllerNodeState.UP);
}
for (HostName hostName : application.getNodesInGroupWithStatus(HostStatus.ALLOWED_TO_BE_DOWN)) {
application.setHostState(context, hostName, HostStatus.NO_REMARKS);
}
}
@Override
public void acquirePermissionToRemove(OrchestratorContext context, ApplicationApi applicationApi)
throws HostStateChangeDeniedException {
ApplicationInstanceStatus applicationStatus = applicationApi.getApplicationStatus();
if (applicationStatus == ApplicationInstanceStatus.ALLOWED_TO_BE_DOWN) {
throw new HostStateChangeDeniedException(
applicationApi.getNodeGroup(),
HostedVespaPolicy.APPLICATION_SUSPENDED_CONSTRAINT,
"Unable to test availability constraints as the application " +
applicationApi.applicationId() + " is allowed to be down");
}
// Apply per-cluster policy
for (ClusterApi cluster : applicationApi.getClusters()) {
clusterPolicy.verifyGroupGoingDownPermanentlyIsFine(cluster);
}
// Ask Cluster Controller to set storage nodes to DOWN.
// These storage nodes are guaranteed to be NO_REMARKS
for (StorageNode storageNode : applicationApi.getStorageNodesInGroupInClusterOrder()) {
storageNode.setNodeState(context, ClusterControllerNodeState.DOWN);
}
// Ensure all nodes in the group are marked as allowed to be down
for (HostName hostName : applicationApi.getNodesInGroupWithStatus(HostStatus.NO_REMARKS)) {
applicationApi.setHostState(context, hostName, HostStatus.ALLOWED_TO_BE_DOWN);
}
}
// TODO: Remove later - currently used for backward compatibility testing
@Override
public void releaseSuspensionGrant(
OrchestratorContext context,
ApplicationInstance applicationInstance,
HostName hostName,
MutableStatusRegistry hostStatusService) throws HostStateChangeDeniedException {
NodeGroup nodeGroup = new NodeGroup(applicationInstance, hostName);
ApplicationApi applicationApi = new ApplicationApiImpl(nodeGroup, hostStatusService, clusterControllerClientFactory);
releaseSuspensionGrant(context, applicationApi);
}
}
|