@Test public void testAvailableResources() { MetricValue mv = new MetricValue.Builder().load(50).add(); Set<String> diskSet = ImmutableSet.of("disk1", "disk2"); diskSet.forEach(disk -> DISK_METRICS.forEach(cmt -> testUpdateMetricWithResource(cmt, mv, disk))); Set<String> networkSet = ImmutableSet.of("eth0", "eth1"); networkSet.forEach(network -> NETWORK_METRICS.forEach(cmt -> testUpdateMetricWithResource(cmt, mv, network))); assertThat(monitor.availableResourcesSync(nodeId, Type.DISK), is(diskSet)); assertThat(monitor.availableResourcesSync(nodeId, Type.NETWORK), is(networkSet)); }
@Override public CompletableFuture<Set<String>> availableResources(NodeId nodeId, Type resourceType) { if (clusterService.getLocalNode().id().equals(nodeId)) { Set<String> resources = getLocalAvailableResources(resourceType); return CompletableFuture.completedFuture(resources); } else { return communicationService.sendAndReceive(createResourceRequest(resourceType), CONTROL_RESOURCE, SERIALIZER::encode, SERIALIZER::decode, nodeId); } }
ControlPlaneMonitor implements ControlPlaneMonitorService { @Override public CompletableFuture<Set<String>> availableResources(NodeId nodeId, Type resourceType) { if (clusterService.getLocalNode().id().equals(nodeId)) { Set<String> resources = getLocalAvailableResources(resourceType); return CompletableFuture.completedFuture(resources); } else { return communicationService.sendAndReceive(createResourceRequest(resourceType), CONTROL_RESOURCE, SERIALIZER::encode, SERIALIZER::decode, nodeId); } } }
ControlPlaneMonitor implements ControlPlaneMonitorService { @Override public CompletableFuture<Set<String>> availableResources(NodeId nodeId, Type resourceType) { if (clusterService.getLocalNode().id().equals(nodeId)) { Set<String> resources = getLocalAvailableResources(resourceType); return CompletableFuture.completedFuture(resources); } else { return communicationService.sendAndReceive(createResourceRequest(resourceType), CONTROL_RESOURCE, SERIALIZER::encode, SERIALIZER::decode, nodeId); } }  }
ControlPlaneMonitor implements ControlPlaneMonitorService { @Override public CompletableFuture<Set<String>> availableResources(NodeId nodeId, Type resourceType) { if (clusterService.getLocalNode().id().equals(nodeId)) { Set<String> resources = getLocalAvailableResources(resourceType); return CompletableFuture.completedFuture(resources); } else { return communicationService.sendAndReceive(createResourceRequest(resourceType), CONTROL_RESOURCE, SERIALIZER::encode, SERIALIZER::decode, nodeId); } }  @Activate void activate(); @Deactivate void deactivate(); @Override void updateMetric(ControlMetric cm, int updateIntervalInMinutes,
                             Optional<DeviceId> deviceId); @Override void updateMetric(ControlMetric cm, int updateIntervalInMinutes,
                             String resourceName); @Override CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
                                                          ControlMetricType type,
                                                          Optional<DeviceId> deviceId); @Override CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
                                                          ControlMetricType type,
                                                          String resourceName); @Override CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
                                                          ControlMetricType type,
                                                          int duration, TimeUnit unit,
                                                          Optional<DeviceId> deviceId); @Override CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
                                                          ControlMetricType type,
                                                          int duration, TimeUnit unit,
                                                          String resourceName); @Override CompletableFuture<Set<String>> availableResources(NodeId nodeId,
                                                             Type resourceType); }
ControlPlaneMonitor implements ControlPlaneMonitorService { @Override public CompletableFuture<Set<String>> availableResources(NodeId nodeId, Type resourceType) { if (clusterService.getLocalNode().id().equals(nodeId)) { Set<String> resources = getLocalAvailableResources(resourceType); return CompletableFuture.completedFuture(resources); } else { return communicationService.sendAndReceive(createResourceRequest(resourceType), CONTROL_RESOURCE, SERIALIZER::encode, SERIALIZER::decode, nodeId); } }  @Activate void activate(); @Deactivate void deactivate(); @Override void updateMetric(ControlMetric cm, int updateIntervalInMinutes,
                             Optional<DeviceId> deviceId); @Override void updateMetric(ControlMetric cm, int updateIntervalInMinutes,
                             String resourceName); @Override CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
                                                          ControlMetricType type,
                                                          Optional<DeviceId> deviceId); @Override CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
                                                          ControlMetricType type,
                                                          String resourceName); @Override CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
                                                          ControlMetricType type,
                                                          int duration, TimeUnit unit,
                                                          Optional<DeviceId> deviceId); @Override CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
                                                          ControlMetricType type,
                                                          int duration, TimeUnit unit,
                                                          String resourceName); @Override CompletableFuture<Set<String>> availableResources(NodeId nodeId,
                                                             Type resourceType);  }