@Test public void testResolver() { assertThat(agentOperations.getInstanceGroups()).isNotNull(); assertThat(agentOperations.getInstanceGroups()).isNotEmpty(); AgentInstanceGroup agentInstanceGroup = agentOperations.getInstanceGroups().get(0); List<AgentInstance> agentInstances = agentOperations.getAgentInstances(agentInstanceGroup.getId()); assertThat(agentInstances).isNotNull(); assertThat(agentInstances).isNotEmpty(); String k8sNodeId = agentInstances.get(0).getId(); V1Node k8sNode = TestDataFactory.newNode(k8sNodeId); addNodeTaint(k8sNode, KubeConstants.TAINT_SCHEDULER, KubeConstants.TAINT_SCHEDULER_VALUE_FENZO, KubeConstants.TAINT_EFFECT_NO_EXECUTE); addNodeCondition(k8sNode, "CorrectableMemoryFailure", "True"); AgentManagementNodeDataResolver resolver = new AgentManagementNodeDataResolver(agentOperations, agentDataReplicator, instance -> true, relocationConfiguration, TestDataFactory.mockKubeApiFacade(k8sNode)); Map<String, Node> resolved = resolver.resolve(); int expectedCount = agentOperations.findAgentInstances(pair -> true).stream().mapToInt(p -> p.getRight().size()).sum(); assertThat(resolved).hasSize(expectedCount); String instanceId = CollectionsExt.first(resolved.keySet()); assertThat(resolver.resolve().get(instanceId).isRelocationRequired()).isFalse(); assertThat(resolver.resolve().get(instanceId).isRelocationRequiredImmediately()).isFalse(); assertThat(resolver.resolve().get(instanceId).isRelocationNotAllowed()).isFalse(); assertThat(resolver.resolve().get(instanceId).isInBadCondition()).isFalse(); relocationConnectorStubs.addInstanceAttribute(instanceId, RelocationAttributes.RELOCATION_REQUIRED, "true"); assertThat(resolver.resolve().get(instanceId).isRelocationRequired()).isTrue(); assertThat(resolver.resolve().get(instanceId).isRelocationRequiredImmediately()).isFalse(); assertThat(resolver.resolve().get(instanceId).isRelocationNotAllowed()).isFalse(); assertThat(resolver.resolve().get(instanceId).isInBadCondition()).isFalse(); relocationConnectorStubs.addInstanceAttribute(instanceId, RelocationAttributes.RELOCATION_REQUIRED_IMMEDIATELY, "true"); assertThat(resolver.resolve().get(instanceId).isRelocationRequiredImmediately()).isTrue(); assertThat(resolver.resolve().get(instanceId).isRelocationNotAllowed()).isFalse(); assertThat(resolver.resolve().get(instanceId).isInBadCondition()).isFalse(); relocationConnectorStubs.addInstanceAttribute(instanceId, RelocationAttributes.RELOCATION_NOT_ALLOWED, "true"); assertThat(resolver.resolve().get(instanceId).isRelocationNotAllowed()).isTrue(); assertThat(resolver.resolve().get(instanceId).isInBadCondition()).isFalse(); assertThat(resolver.resolve().get(k8sNodeId).isInBadCondition()).isTrue(); }
@Override public Map<String, Node> resolve() { List<Pair<AgentInstanceGroup, List<AgentInstance>>> all = agentOperations.findAgentInstances(pair -> fenzoNodeFilter.test(pair.getRight()) ); Map<String, Node> result = new HashMap<>(); all.forEach(pair -> { AgentInstanceGroup serverGroup = pair.getLeft(); List<AgentInstance> instances = pair.getRight(); instances.forEach(instance -> result.put(instance.getId(), toNode(serverGroup, instance))); }); return result; }
AgentManagementNodeDataResolver implements NodeDataResolver { @Override public Map<String, Node> resolve() { List<Pair<AgentInstanceGroup, List<AgentInstance>>> all = agentOperations.findAgentInstances(pair -> fenzoNodeFilter.test(pair.getRight()) ); Map<String, Node> result = new HashMap<>(); all.forEach(pair -> { AgentInstanceGroup serverGroup = pair.getLeft(); List<AgentInstance> instances = pair.getRight(); instances.forEach(instance -> result.put(instance.getId(), toNode(serverGroup, instance))); }); return result; } }
AgentManagementNodeDataResolver implements NodeDataResolver { @Override public Map<String, Node> resolve() { List<Pair<AgentInstanceGroup, List<AgentInstance>>> all = agentOperations.findAgentInstances(pair -> fenzoNodeFilter.test(pair.getRight()) ); Map<String, Node> result = new HashMap<>(); all.forEach(pair -> { AgentInstanceGroup serverGroup = pair.getLeft(); List<AgentInstance> instances = pair.getRight(); instances.forEach(instance -> result.put(instance.getId(), toNode(serverGroup, instance))); }); return result; } AgentManagementNodeDataResolver(ReadOnlyAgentOperations agentOperations,
                                           AgentDataReplicator agentDataReplicator,
                                           Predicate<AgentInstance> fenzoNodeFilter,
                                           RelocationConfiguration relocationConfiguration,
                                           KubeApiFacade kubeApiFacade); }
AgentManagementNodeDataResolver implements NodeDataResolver { @Override public Map<String, Node> resolve() { List<Pair<AgentInstanceGroup, List<AgentInstance>>> all = agentOperations.findAgentInstances(pair -> fenzoNodeFilter.test(pair.getRight()) ); Map<String, Node> result = new HashMap<>(); all.forEach(pair -> { AgentInstanceGroup serverGroup = pair.getLeft(); List<AgentInstance> instances = pair.getRight(); instances.forEach(instance -> result.put(instance.getId(), toNode(serverGroup, instance))); }); return result; } AgentManagementNodeDataResolver(ReadOnlyAgentOperations agentOperations,
                                           AgentDataReplicator agentDataReplicator,
                                           Predicate<AgentInstance> fenzoNodeFilter,
                                           RelocationConfiguration relocationConfiguration,
                                           KubeApiFacade kubeApiFacade); @Override Map<String, Node> resolve(); @Override long getStalenessMs(); }
AgentManagementNodeDataResolver implements NodeDataResolver { @Override public Map<String, Node> resolve() { List<Pair<AgentInstanceGroup, List<AgentInstance>>> all = agentOperations.findAgentInstances(pair -> fenzoNodeFilter.test(pair.getRight()) ); Map<String, Node> result = new HashMap<>(); all.forEach(pair -> { AgentInstanceGroup serverGroup = pair.getLeft(); List<AgentInstance> instances = pair.getRight(); instances.forEach(instance -> result.put(instance.getId(), toNode(serverGroup, instance))); }); return result; } AgentManagementNodeDataResolver(ReadOnlyAgentOperations agentOperations,
                                           AgentDataReplicator agentDataReplicator,
                                           Predicate<AgentInstance> fenzoNodeFilter,
                                           RelocationConfiguration relocationConfiguration,
                                           KubeApiFacade kubeApiFacade); @Override Map<String, Node> resolve(); @Override long getStalenessMs();  }