use of com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.MissingUnitException in project vespa by vespa-engine.
the class DummyStateApi method setUnitState.
@Override
public SetResponse setUnitState(SetUnitStateRequest request) throws StateRestApiException {
checkForInducedException();
String[] path = request.getUnitPath();
if (path.length != 2) {
throw new OperationNotSupportedForUnitException(path, "You can only set states on nodes");
}
DummyBackend.Node n = null;
DummyBackend.Cluster c = backend.getClusters().get(path[0]);
if (c != null) {
n = c.nodes.get(path[1]);
}
if (n == null)
throw new MissingUnitException(path, 2);
Map<String, UnitState> newState = request.getNewState();
if (newState.size() != 1 || !newState.containsKey("current")) {
throw new InvalidContentException("Only state of type 'current' is allowed to be set.");
}
n.state = newState.get("current").getId();
n.reason = newState.get("current").getReason();
String reason = String.format("DummyStateAPI %s call", request.getResponseWait().getName());
return new SetResponse(reason, true);
}
use of com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.MissingUnitException in project vespa by vespa-engine.
the class UnitPathResolver method visit.
public Request<? extends T> visit(String[] path, Visitor<T> visitor) throws StateRestApiException {
if (path.length == 0) {
return visitor.visitGlobal();
}
RemoteClusterControllerTaskScheduler fc = fleetControllers.get(path[0]);
if (fc == null)
throw new MissingUnitException(path, 0);
Id.Cluster cluster = new Id.Cluster(path[0]);
if (path.length == 1) {
return visitor.visitCluster(cluster);
}
Id.Service service;
try {
service = new Id.Service(cluster, NodeType.get(path[1]));
} catch (IllegalArgumentException e) {
throw new MissingUnitException(path, 1);
}
if (path.length == 2) {
return visitor.visitService(service);
}
Id.Node node;
try {
node = new Id.Node(service, Integer.valueOf(path[2]));
} catch (NumberFormatException e) {
throw new MissingUnitException(path, 2);
}
if (path.length == 3) {
return visitor.visitNode(node);
}
Id.Partition partition;
try {
partition = new Id.Partition(node, Integer.valueOf(path[3]));
} catch (NumberFormatException e) {
throw new MissingUnitException(path, 3);
}
if (path.length == 4) {
return visitor.visitPartition(partition);
}
throw new MissingUnitException(path, 4);
}
use of com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.MissingUnitException in project vespa by vespa-engine.
the class DummyStateApi method getState.
@Override
public UnitResponse getState(UnitStateRequest request) throws StateRestApiException {
checkForInducedException();
String[] path = request.getUnitPath();
if (path.length == 0) {
return getClusterList(request.getRecursiveLevels());
}
final DummyBackend.Cluster c = backend.getClusters().get(path[0]);
if (c == null)
throw new MissingUnitException(path, 0);
if (path.length == 1) {
return getClusterState(c, request.getRecursiveLevels());
}
final DummyBackend.Node n = c.nodes.get(path[1]);
if (n == null)
throw new MissingUnitException(path, 1);
if (path.length == 2) {
return getNodeState(n);
}
throw new MissingUnitException(path, 3);
}
Aggregations