private RayoNode store(RayoNode node) throws DatastoreException { Mutator mutator = Pelops.createMutator(schemaName); for (String platform : node.getPlatforms()) { mutator.writeSubColumns( "nodes", platform, node.getHostname(), mutator.newColumnList( mutator.newColumn("priority", String.valueOf(node.getPriority())), mutator.newColumn("weight", String.valueOf(node.getWeight())), mutator.newColumn("ip", node.getIpAddress()), mutator.newColumn("consecutive-errors", String.valueOf(node.getConsecutiveErrors())), mutator.newColumn("blacklisted", String.valueOf(node.isBlackListed())))); } mutator.writeColumn( "ips", Bytes.fromUTF8(node.getIpAddress()), mutator.newColumn(Bytes.fromUTF8("node"), Bytes.fromUTF8(node.getHostname()))); try { mutator.execute(ConsistencyLevel.ONE); log.debug("Node [%s] stored successfully", node); } catch (Exception e) { log.error(e.getMessage(), e); throw new DatastoreException(String.format("Could not create node [%s]", node)); } return node; }
@Override public RayoNode removeNode(String rayoNode) throws DatastoreException { log.debug("Removing node: [%s]", rayoNode); RayoNode node = getNode(rayoNode); if (node == null) { log.error("Node not found: [%s]", rayoNode); throw new RayoNodeNotFoundException(); } RowDeletor deletor = Pelops.createRowDeletor(schemaName); deletor.deleteRow("ips", node.getIpAddress(), ConsistencyLevel.ONE); Mutator mutator = Pelops.createMutator(schemaName); for (String platform : node.getPlatforms()) { mutator.deleteColumn("nodes", platform, rayoNode); } try { mutator.execute(ConsistencyLevel.ONE); log.debug("Node [%s] deleted successfully", rayoNode); } catch (Exception e) { log.error(e.getMessage(), e); throw new DatastoreException("Could not remove node"); } return node; }