use of com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.OperationNotSupportedForUnitException in project vespa by vespa-engine.
the class SetNodeStateTest method testWrongUnit.
@Test
public void testWrongUnit() throws Exception {
setUp(true);
String wrongUnitMessage = "State can only be set at cluster or node level";
try {
restAPI.setUnitState(new SetUnitStateRequestImpl("").setNewState("user", "down", "testing"));
assertTrue(false);
} catch (OperationNotSupportedForUnitException e) {
assertTrue(e.getMessage(), e.getMessage().contains(wrongUnitMessage));
}
try {
restAPI.setUnitState(new SetUnitStateRequestImpl("music/distributor").setNewState("user", "down", "testing"));
assertTrue(false);
} catch (OperationNotSupportedForUnitException e) {
assertTrue(e.getMessage(), e.getMessage().contains(wrongUnitMessage));
}
try {
restAPI.setUnitState(new SetUnitStateRequestImpl("music/storage/1/0").setNewState("user", "down", "testing"));
assertTrue(false);
} catch (OperationNotSupportedForUnitException e) {
assertTrue(e.getMessage(), e.getMessage().contains(wrongUnitMessage));
}
}
use of com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.OperationNotSupportedForUnitException 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);
}
Aggregations