SnapshotService { public void clearSnapshotClusterWide(String snapshotName, String clusterName) throws ReaperException { try { Cluster cluster = context.storage.getCluster(clusterName); List<String> liveNodes = clusterFacade.getLiveNodes(cluster); List<Callable<Node>> clearSnapshotTasks = liveNodes .stream() .map(host -> Node.builder().withCluster(cluster).withHostname(host).build()) .map(node -> clearSnapshotTask(snapshotName, node)) .collect(Collectors.toList()); List<Future<Node>> futures = executor.invokeAll(clearSnapshotTasks); for (Future<Node> future : futures) { future.get(); } context.storage.deleteSnapshot(Snapshot.builder().withClusterName(clusterName).withName(snapshotName).build()); } catch (ExecutionException e) { LOG.error("Failed clearing {} snapshot for cluster {}", snapshotName, clusterName, e); } catch (InterruptedException e) { LOG.error("Interrupted clearing {} snapshot for cluster {}", snapshotName, clusterName, e); throw new ReaperException(e); } } private  SnapshotService(AppContext context, ExecutorService executor, Supplier<ClusterFacade> clusterFacadeSupplier); static SnapshotService create(AppContext context, ExecutorService executor); Pair<Node, String> takeSnapshot(String snapshotName, Node host, String... keyspaces); List<Pair<Node, String>> takeSnapshotClusterWide(
      String snapshotName,
      String clusterName,
      String owner,
      String cause,
      String... keyspace); Map<String, List<Snapshot>> listSnapshotsGroupedByName(Node host); List<Snapshot> listSnapshots(Node host); Map<String, Map<String, List<Snapshot>>> listSnapshotsClusterWide(String clusterName); void clearSnapshot(String snapshotName, Node host); void clearSnapshotClusterWide(String snapshotName, String clusterName); String formatSnapshotName(String snapshotName); static final String SNAPSHOT_PREFIX; }
@Test public void testClearSnapshotClusterWide() throws InterruptedException, ReaperException, ClassNotFoundException, IOException { JmxProxy proxy = (JmxProxy) mock(Class.forName("io.cassandrareaper.jmx.JmxProxyImpl")); StorageServiceMBean storageMBean = Mockito.mock(StorageServiceMBean.class); JmxProxyTest.mockGetStorageServiceMBean(proxy, storageMBean); AppContext cxt = new AppContext(); cxt.config = TestRepairConfiguration.defaultConfig(); cxt.jmxConnectionFactory = mock(JmxConnectionFactory.class); when(cxt.jmxConnectionFactory.connectAny(any(Collection.class))).thenReturn(proxy); ClusterFacade clusterFacadeSpy = Mockito.spy(ClusterFacade.create(cxt)); Mockito.doReturn(Arrays.asList("127.0.0.1", "127.0.0.2")).when(clusterFacadeSpy).getLiveNodes(any()); Mockito.doReturn(Arrays.asList("127.0.0.1", "127.0.0.2")) .when(clusterFacadeSpy) .getLiveNodes(any(), any()); cxt.storage = mock(IStorage.class); Cluster cluster = Cluster.builder() .withName("testCluster") .withPartitioner("murmur3") .withSeedHosts(ImmutableSet.of("127.0.0.1")) .build(); when(cxt.storage.getCluster(anyString())).thenReturn(cluster); SnapshotService .create(cxt, SNAPSHOT_MANAGER_EXECUTOR, () -> clusterFacadeSpy) .clearSnapshotClusterWide("snapshot", "testCluster"); verify(storageMBean, times(2)).clearSnapshot("snapshot"); }