Search in sources :

Example 1 with OperationNotSupportedForUnitException

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));
    }
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) OperationNotSupportedForUnitException(com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.OperationNotSupportedForUnitException) Test(org.junit.Test)

Example 2 with OperationNotSupportedForUnitException

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);
}
Also used : InvalidContentException(com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.InvalidContentException) OperationNotSupportedForUnitException(com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.OperationNotSupportedForUnitException) MissingUnitException(com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.MissingUnitException)

Aggregations

OperationNotSupportedForUnitException (com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.OperationNotSupportedForUnitException)2 InvalidContentException (com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.InvalidContentException)1 MissingUnitException (com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.MissingUnitException)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 Test (org.junit.Test)1