summaryrefslogtreecommitdiffstats
path: root/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/ServiceMonitorImpl.java
blob: 3468644169da39d800e3ca3c84f9ddcdb10a70d4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.service.monitor;

import com.google.inject.Inject;
import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.config.model.api.SuperModelProvider;
import com.yahoo.config.provision.Zone;
import com.yahoo.vespa.applicationmodel.ApplicationInstance;
import com.yahoo.vespa.applicationmodel.ApplicationInstanceReference;

import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import java.util.stream.Collectors;

public class ServiceMonitorImpl implements ServiceMonitor {
    private static final Logger logger = Logger.getLogger(ServiceMonitorImpl.class.getName());

    private final Zone zone;
    private final List<String> configServerHostnames;
    private final SlobrokMonitor2 slobrokMonitor = new SlobrokMonitor2();
    private final SuperModelListenerImpl superModelListener =
            new SuperModelListenerImpl(slobrokMonitor);

    @Inject
    public ServiceMonitorImpl(SuperModelProvider superModelProvider,
                              ConfigserverConfig configserverConfig) {
        this.zone = superModelProvider.getZone();
        this.configServerHostnames = configserverConfig.zookeeperserver().stream()
                .map(server -> server.hostname())
                .collect(Collectors.toList());
        superModelListener.start(superModelProvider);
    }

    @Override
    public Map<ApplicationInstanceReference,
            ApplicationInstance<ServiceMonitorStatus>> queryStatusOfAllApplicationInstances() {
        // If we ever need to optimize this method, then consider reusing ServiceModel snapshots
        // for up to X ms.
        ServiceModel serviceModel =
                superModelListener.createServiceModelSnapshot(zone, configServerHostnames);
        return serviceModel.getAllApplicationInstances();
    }
}