diff --git a/src/server/src/main/java/io/cassandrareaper/storage/CassandraStorage.java b/src/server/src/main/java/io/cassandrareaper/storage/CassandraStorage.java index 63f2f515a..1f54d5589 100644 --- a/src/server/src/main/java/io/cassandrareaper/storage/CassandraStorage.java +++ b/src/server/src/main/java/io/cassandrareaper/storage/CassandraStorage.java @@ -140,6 +140,7 @@ public RepairUnit load(UUID repairUnitId) throws Exception { /* prepared stmts */ private PreparedStatement insertClusterPrepStmt; + private PreparedStatement updateClusterPrepStmt; private PreparedStatement getClusterPrepStmt; private PreparedStatement deleteClusterPrepStmt; private PreparedStatement insertRepairRunPrepStmt; @@ -323,6 +324,11 @@ private void prepareStatements() { "INSERT INTO cluster(name, partitioner, seed_hosts, properties, state, last_contact)" + " values(?, ?, ?, ?, ?, ?)") .setConsistencyLevel(ConsistencyLevel.QUORUM); + updateClusterPrepStmt = session + .prepare( + "INSERT INTO cluster(name, seed_hosts, state, last_contact)" + + " values(?, ?, ?, ?)") + .setConsistencyLevel(ConsistencyLevel.LOCAL_ONE); getClusterPrepStmt = session .prepare("SELECT * FROM cluster WHERE name = ?") .setConsistencyLevel(ConsistencyLevel.QUORUM) @@ -547,7 +553,18 @@ public boolean addCluster(Cluster cluster) { @Override public boolean updateCluster(Cluster newCluster) { - return addCluster(newCluster); + try { + session.execute( + updateClusterPrepStmt.bind( + newCluster.getName(), + newCluster.getSeedHosts(), + newCluster.getState().name(), + java.sql.Date.valueOf(newCluster.getLastContact()))); + } catch (RuntimeException e) { + LOG.error("Failed updating cluster", e); + throw new IllegalStateException(e); + } + return true; } private boolean addClusterAssertions(Cluster cluster) {