RealNodeRepository implements NodeRepository { @Override public void setNodeState(String hostName, NodeState nodeState) { String state = nodeState.name(); NodeMessageResponse response = configServerApi.put( "/nodes/v2/state/" + state + "/" + hostName, Optional.empty(), NodeMessageResponse.class); logger.info(response.message); if (Strings.isNullOrEmpty(response.errorCode)) return; throw new NodeRepositoryException("Failed to set node state: " + response.message + " " + response.errorCode); } RealNodeRepository(ConfigServerApi configServerApi); @Override void addNodes(List<AddNode> nodes); @Override List<NodeSpec> getNodes(String baseHostName); @Override Optional<NodeSpec> getOptionalNode(String hostName); @Override Map<String, Acl> getAcls(String hostName); @Override void updateNodeAttributes(String hostName, NodeAttributes nodeAttributes); @Override void setNodeState(String hostName, NodeState nodeState); static NodeRepositoryNode nodeRepositoryNodeFromNodeAttributes(NodeAttributes nodeAttributes);  }
@Test public void testMarkAsReady() { nodeRepositoryApi.setNodeState("host5.yahoo.com", NodeState.dirty); nodeRepositoryApi.setNodeState("host5.yahoo.com", NodeState.ready); try { nodeRepositoryApi.setNodeState("host4.yahoo.com", NodeState.ready); fail("Should not be allowed to be marked ready as it is not registered as provisioned, dirty, failed or parked"); } catch (RuntimeException ignored) { } try { nodeRepositoryApi.setNodeState("host101.yahoo.com", NodeState.ready); fail("Expected failure because host101 does not exist"); } catch (RuntimeException ignored) { } }