Search in sources :

Example 6 with NodeFlavors

use of com.yahoo.config.provision.NodeFlavors in project vespa by vespa-engine.

the class MetricsReporterTest method docker_metrics.

@Test
public void docker_metrics() throws Exception {
    NodeFlavors nodeFlavors = FlavorConfigBuilder.createDummies("host", "docker", "docker2");
    Curator curator = new MockCurator();
    NodeRepository nodeRepository = new NodeRepository(nodeFlavors, curator, Clock.systemUTC(), Zone.defaultZone(), new MockNameResolver().mockAnyLookup(), new DockerImage("docker-registry.domain.tld:8080/dist/vespa"), true);
    // Allow 4 containers
    Set<String> additionalIps = new HashSet<>();
    additionalIps.add("::2");
    additionalIps.add("::3");
    additionalIps.add("::4");
    additionalIps.add("::5");
    Node dockerHost = Node.create("openStackId1", Collections.singleton("::1"), additionalIps, "dockerHost", Optional.empty(), nodeFlavors.getFlavorOrThrow("host"), NodeType.host);
    nodeRepository.addNodes(Collections.singletonList(dockerHost));
    nodeRepository.setDirty("dockerHost", Agent.system, getClass().getSimpleName());
    nodeRepository.setReady("dockerHost", Agent.system, getClass().getSimpleName());
    Node container1 = Node.createDockerNode("openStackId1:1", Collections.singleton("::2"), Collections.emptySet(), "container1", Optional.of("dockerHost"), nodeFlavors.getFlavorOrThrow("docker"), NodeType.tenant);
    container1 = container1.with(allocation(Optional.of("app1")).get());
    nodeRepository.addDockerNodes(Collections.singletonList(container1));
    Node container2 = Node.createDockerNode("openStackId1:2", Collections.singleton("::3"), Collections.emptySet(), "container2", Optional.of("dockerHost"), nodeFlavors.getFlavorOrThrow("docker2"), NodeType.tenant);
    container2 = container2.with(allocation(Optional.of("app2")).get());
    nodeRepository.addDockerNodes(Collections.singletonList(container2));
    Orchestrator orchestrator = mock(Orchestrator.class);
    ServiceMonitor serviceMonitor = mock(ServiceMonitor.class);
    when(orchestrator.getNodeStatus(any())).thenReturn(HostStatus.NO_REMARKS);
    ServiceModel serviceModel = mock(ServiceModel.class);
    when(serviceMonitor.getServiceModelSnapshot()).thenReturn(serviceModel);
    when(serviceModel.getServiceInstancesByHostName()).thenReturn(Collections.emptyMap());
    TestMetric metric = new TestMetric();
    MetricsReporter metricsReporter = new MetricsReporter(nodeRepository, metric, orchestrator, serviceMonitor, Duration.ofMinutes(1), new JobControl(nodeRepository.database()));
    metricsReporter.maintain();
    assertEquals(0L, metric.values.get("hostedVespa.readyHosts"));
    /**
     * Only tenants counts *
     */
    assertEquals(2L, metric.values.get("hostedVespa.reservedHosts"));
    assertEquals(12.0, metric.values.get("hostedVespa.docker.totalCapacityDisk"));
    assertEquals(10.0, metric.values.get("hostedVespa.docker.totalCapacityMem"));
    assertEquals(7.0, metric.values.get("hostedVespa.docker.totalCapacityCpu"));
    assertEquals(6.0, metric.values.get("hostedVespa.docker.freeCapacityDisk"));
    assertEquals(3.0, metric.values.get("hostedVespa.docker.freeCapacityMem"));
    assertEquals(4.0, metric.values.get("hostedVespa.docker.freeCapacityCpu"));
    assertContext(metric, "hostedVespa.docker.freeCapacityFlavor", 1, 0);
    assertContext(metric, "hostedVespa.docker.idealHeadroomFlavor", 0, 0);
    assertContext(metric, "hostedVespa.docker.hostsAvailableFlavor", 1l, 0l);
}
Also used : MockNameResolver(com.yahoo.vespa.hosted.provision.testutils.MockNameResolver) Node(com.yahoo.vespa.hosted.provision.Node) JobControl(com.yahoo.vespa.hosted.provision.maintenance.JobControl) Curator(com.yahoo.vespa.curator.Curator) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Orchestrator(com.yahoo.vespa.orchestrator.Orchestrator) ServiceMonitor(com.yahoo.vespa.service.monitor.ServiceMonitor) NodeFlavors(com.yahoo.config.provision.NodeFlavors) ServiceModel(com.yahoo.vespa.service.monitor.ServiceModel) MetricsReporter(com.yahoo.vespa.hosted.provision.maintenance.MetricsReporter) NodeRepository(com.yahoo.vespa.hosted.provision.NodeRepository) DockerImage(com.yahoo.config.provision.DockerImage) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with NodeFlavors

use of com.yahoo.config.provision.NodeFlavors in project vespa by vespa-engine.

the class NodeRetirerTest method setup.

@Before
public void setup() {
    doAnswer(invoke -> {
        boolean shouldRetire = ((Node) invoke.getArguments()[0]).ipAddresses().equals(Collections.singleton("::1"));
        return shouldRetire ? Optional.of("Some reason") : Optional.empty();
    }).when(policy).shouldRetire(any(Node.class));
    when(policy.isActive()).thenReturn(true);
    NodeFlavors nodeFlavors = NodeRetirerTester.makeFlavors(5);
    tester = new NodeRetirerTester(nodeFlavors);
    retirer = spy(tester.makeNodeRetirer(policy));
    tester.createReadyNodesByFlavor(21, 42, 27, 15, 8);
    tester.deployApp("vespa", "calendar", new int[] { 3 }, new int[] { 7 });
    tester.deployApp("vespa", "notes", new int[] { 0 }, new int[] { 3 });
    tester.deployApp("sports", "results", new int[] { 0 }, new int[] { 6 });
    tester.deployApp("search", "images", new int[] { 3 }, new int[] { 4 });
    tester.deployApp("search", "videos", new int[] { 2 }, new int[] { 2 });
    tester.deployApp("tester", "my-app", new int[] { 1, 2 }, new int[] { 4, 6 });
}
Also used : NodeFlavors(com.yahoo.config.provision.NodeFlavors) Node(com.yahoo.vespa.hosted.provision.Node) Before(org.junit.Before)

Example 8 with NodeFlavors

use of com.yahoo.config.provision.NodeFlavors in project vespa by vespa-engine.

the class NodePrioritizer method findHeadroomHosts.

/**
 * Headroom hosts are the host with the least but sufficient capacity for the requested headroom.
 *
 * If not enough headroom - the headroom violating hosts are the once that are closest to fulfill
 * a headroom request.
 */
private static Map<Node, ResourceCapacity> findHeadroomHosts(List<Node> nodes, Set<Node> spareNodes, NodeFlavors flavors) {
    DockerHostCapacity capacity = new DockerHostCapacity(nodes);
    Map<Node, ResourceCapacity> headroomHosts = new HashMap<>();
    List<Node> hostsSortedOnLeastCapacity = nodes.stream().filter(n -> !spareNodes.contains(n)).filter(node -> node.type().equals(NodeType.host)).filter(dockerHost -> dockerHost.state().equals(Node.State.active)).filter(dockerHost -> capacity.freeIPs(dockerHost) > 0).sorted((a, b) -> capacity.compareWithoutInactive(b, a)).collect(Collectors.toList());
    // For all flavors with ideal headroom - find which hosts this headroom should be allocated to
    for (Flavor flavor : flavors.getFlavors().stream().filter(f -> f.getIdealHeadroom() > 0).collect(Collectors.toList())) {
        Set<Node> tempHeadroom = new HashSet<>();
        Set<Node> notEnoughCapacity = new HashSet<>();
        ResourceCapacity headroomCapacity = ResourceCapacity.of(flavor);
        // Select hosts that has available capacity for both headroom and for new allocations
        for (Node host : hostsSortedOnLeastCapacity) {
            if (headroomHosts.containsKey(host))
                continue;
            if (capacity.hasCapacityWhenRetiredAndInactiveNodesAreGone(host, headroomCapacity)) {
                headroomHosts.put(host, headroomCapacity);
                tempHeadroom.add(host);
            } else {
                notEnoughCapacity.add(host);
            }
            if (tempHeadroom.size() == flavor.getIdealHeadroom()) {
                break;
            }
        }
        // Now check if we have enough headroom - if not choose the nodes that almost has it
        if (tempHeadroom.size() < flavor.getIdealHeadroom()) {
            List<Node> violations = notEnoughCapacity.stream().sorted((a, b) -> capacity.compare(b, a)).limit(flavor.getIdealHeadroom() - tempHeadroom.size()).collect(Collectors.toList());
            for (Node hostViolatingHeadrom : violations) {
                headroomHosts.put(hostViolatingHeadrom, headroomCapacity);
            }
        }
    }
    return headroomHosts;
}
Also used : NodeFlavors(com.yahoo.config.provision.NodeFlavors) Arrays(java.util.Arrays) ApplicationId(com.yahoo.config.provision.ApplicationId) NodeType(com.yahoo.config.provision.NodeType) ClusterSpec(com.yahoo.config.provision.ClusterSpec) Set(java.util.Set) HashMap(java.util.HashMap) Node(com.yahoo.vespa.hosted.provision.Node) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) NameResolver(com.yahoo.vespa.hosted.provision.persistence.NameResolver) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Flavor(com.yahoo.config.provision.Flavor) Map(java.util.Map) LogLevel(com.yahoo.log.LogLevel) Optional(java.util.Optional) NodeList(com.yahoo.vespa.hosted.provision.NodeList) Collections(java.util.Collections) HashMap(java.util.HashMap) Node(com.yahoo.vespa.hosted.provision.Node) Flavor(com.yahoo.config.provision.Flavor) HashSet(java.util.HashSet)

Aggregations

NodeFlavors (com.yahoo.config.provision.NodeFlavors)8 Node (com.yahoo.vespa.hosted.provision.Node)5 Test (org.junit.Test)4 ApplicationId (com.yahoo.config.provision.ApplicationId)3 DockerImage (com.yahoo.config.provision.DockerImage)3 MockCurator (com.yahoo.vespa.curator.mock.MockCurator)3 NodeRepository (com.yahoo.vespa.hosted.provision.NodeRepository)3 MockNameResolver (com.yahoo.vespa.hosted.provision.testutils.MockNameResolver)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Before (org.junit.Before)3 ClusterSpec (com.yahoo.config.provision.ClusterSpec)2 Flavor (com.yahoo.config.provision.Flavor)2 Curator (com.yahoo.vespa.curator.Curator)2 JobControl (com.yahoo.vespa.hosted.provision.maintenance.JobControl)2 MetricsReporter (com.yahoo.vespa.hosted.provision.maintenance.MetricsReporter)2 Orchestrator (com.yahoo.vespa.orchestrator.Orchestrator)2 ServiceModel (com.yahoo.vespa.service.monitor.ServiceModel)2 ServiceMonitor (com.yahoo.vespa.service.monitor.ServiceMonitor)2 HashMap (java.util.HashMap)2