Search in sources :

Example 1 with ServiceModel

use of com.yahoo.vespa.service.monitor.ServiceModel in project vespa by vespa-engine.

the class ModelGeneratorTest method toApplicationModel.

@Test
public void toApplicationModel() throws Exception {
    SuperModel superModel = ExampleModel.createExampleSuperModelWithOneRpcPort(HOSTNAME, PORT);
    ModelGenerator modelGenerator = new ModelGenerator();
    Zone zone = new Zone(Environment.from(ENVIRONMENT), RegionName.from(REGION));
    List<String> configServerHosts = Collections.emptyList();
    SlobrokMonitorManagerImpl slobrokMonitorManager = mock(SlobrokMonitorManagerImpl.class);
    when(slobrokMonitorManager.getStatus(any(), any(), any(), any())).thenReturn(ServiceStatus.UP);
    ServiceModel serviceModel = modelGenerator.toServiceModel(superModel, zone, configServerHosts, slobrokMonitorManager);
    Map<ApplicationInstanceReference, ApplicationInstance> applicationInstances = serviceModel.getAllApplicationInstances();
    assertEquals(1, applicationInstances.size());
    verifyOtherApplication(applicationInstances.values().iterator().next());
}
Also used : ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) ServiceModel(com.yahoo.vespa.service.monitor.ServiceModel) SuperModel(com.yahoo.config.model.api.SuperModel) Zone(com.yahoo.config.provision.Zone) ApplicationInstanceReference(com.yahoo.vespa.applicationmodel.ApplicationInstanceReference) Test(org.junit.Test)

Example 2 with ServiceModel

use of com.yahoo.vespa.service.monitor.ServiceModel in project vespa by vespa-engine.

the class ModelGeneratorTest method toApplicationModelWithConfigServerApplication.

@Test
public void toApplicationModelWithConfigServerApplication() throws Exception {
    SuperModel superModel = ExampleModel.createExampleSuperModelWithOneRpcPort(HOSTNAME, PORT);
    ModelGenerator modelGenerator = new ModelGenerator();
    Zone zone = new Zone(Environment.from(ENVIRONMENT), RegionName.from(REGION));
    List<String> configServerHosts = Stream.of("cfg1", "cfg2", "cfg3").collect(Collectors.toList());
    SlobrokMonitorManagerImpl slobrokMonitorManager = mock(SlobrokMonitorManagerImpl.class);
    when(slobrokMonitorManager.getStatus(any(), any(), any(), any())).thenReturn(ServiceStatus.UP);
    ServiceModel serviceModel = modelGenerator.toServiceModel(superModel, zone, configServerHosts, slobrokMonitorManager);
    Map<ApplicationInstanceReference, ApplicationInstance> applicationInstances = serviceModel.getAllApplicationInstances();
    assertEquals(2, applicationInstances.size());
    Iterator<Map.Entry<ApplicationInstanceReference, ApplicationInstance>> iterator = applicationInstances.entrySet().iterator();
    ApplicationInstance applicationInstance1 = iterator.next().getValue();
    ApplicationInstance applicationInstance2 = iterator.next().getValue();
    if (applicationInstance1.applicationInstanceId().equals(ConfigServerApplication.APPLICATION_INSTANCE_ID)) {
        verifyConfigServerApplication(applicationInstance1);
        verifyOtherApplication(applicationInstance2);
    } else {
        verifyConfigServerApplication(applicationInstance2);
        verifyOtherApplication(applicationInstance1);
    }
}
Also used : ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) ServiceModel(com.yahoo.vespa.service.monitor.ServiceModel) SuperModel(com.yahoo.config.model.api.SuperModel) Zone(com.yahoo.config.provision.Zone) ApplicationInstanceReference(com.yahoo.vespa.applicationmodel.ApplicationInstanceReference) Test(org.junit.Test)

Example 3 with ServiceModel

use of com.yahoo.vespa.service.monitor.ServiceModel in project vespa by vespa-engine.

the class SuperModelListenerImplTest method sanityCheck.

@Test
public void sanityCheck() {
    SlobrokMonitorManagerImpl slobrokMonitorManager = mock(SlobrokMonitorManagerImpl.class);
    ServiceMonitorMetrics metrics = mock(ServiceMonitorMetrics.class);
    ModelGenerator modelGenerator = mock(ModelGenerator.class);
    Zone zone = mock(Zone.class);
    List<String> configServers = new ArrayList<>();
    SuperModelListenerImpl listener = new SuperModelListenerImpl(slobrokMonitorManager, metrics, modelGenerator, zone, configServers);
    SuperModelProvider superModelProvider = mock(SuperModelProvider.class);
    SuperModel superModel = mock(SuperModel.class);
    when(superModelProvider.snapshot(listener)).thenReturn(superModel);
    ApplicationInfo application1 = mock(ApplicationInfo.class);
    ApplicationInfo application2 = mock(ApplicationInfo.class);
    List<ApplicationInfo> applications = Stream.of(application1, application2).collect(Collectors.toList());
    when(superModel.getAllApplicationInfos()).thenReturn(applications);
    listener.start(superModelProvider);
    verify(slobrokMonitorManager).applicationActivated(superModel, application1);
    verify(slobrokMonitorManager).applicationActivated(superModel, application2);
    ServiceModel serviceModel = listener.get();
    verify(modelGenerator).toServiceModel(superModel, zone, configServers, slobrokMonitorManager);
}
Also used : Zone(com.yahoo.config.provision.Zone) SuperModel(com.yahoo.config.model.api.SuperModel) ArrayList(java.util.ArrayList) ApplicationInfo(com.yahoo.config.model.api.ApplicationInfo) SuperModelProvider(com.yahoo.config.model.api.SuperModelProvider) ServiceModel(com.yahoo.vespa.service.monitor.ServiceModel) Test(org.junit.Test)

Example 4 with ServiceModel

use of com.yahoo.vespa.service.monitor.ServiceModel in project vespa by vespa-engine.

the class MetricsReporterTest method test_registered_metric.

@Test
public void test_registered_metric() throws Exception {
    NodeFlavors nodeFlavors = FlavorConfigBuilder.createDummies("default");
    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);
    Node node = nodeRepository.createNode("openStackId", "hostname", Optional.empty(), nodeFlavors.getFlavorOrThrow("default"), NodeType.tenant);
    nodeRepository.addNodes(Collections.singletonList(node));
    Node hostNode = nodeRepository.createNode("openStackId2", "parent", Optional.empty(), nodeFlavors.getFlavorOrThrow("default"), NodeType.proxy);
    nodeRepository.addNodes(Collections.singletonList(hostNode));
    Map<String, Number> expectedMetrics = new HashMap<>();
    expectedMetrics.put("hostedVespa.provisionedHosts", 1L);
    expectedMetrics.put("hostedVespa.parkedHosts", 0L);
    expectedMetrics.put("hostedVespa.readyHosts", 0L);
    expectedMetrics.put("hostedVespa.reservedHosts", 0L);
    expectedMetrics.put("hostedVespa.activeHosts", 0L);
    expectedMetrics.put("hostedVespa.inactiveHosts", 0L);
    expectedMetrics.put("hostedVespa.dirtyHosts", 0L);
    expectedMetrics.put("hostedVespa.failedHosts", 0L);
    expectedMetrics.put("hostedVespa.docker.totalCapacityDisk", 0.0);
    expectedMetrics.put("hostedVespa.docker.totalCapacityMem", 0.0);
    expectedMetrics.put("hostedVespa.docker.totalCapacityCpu", 0.0);
    expectedMetrics.put("hostedVespa.docker.freeCapacityDisk", 0.0);
    expectedMetrics.put("hostedVespa.docker.freeCapacityMem", 0.0);
    expectedMetrics.put("hostedVespa.docker.freeCapacityCpu", 0.0);
    expectedMetrics.put("wantedRebootGeneration", 0L);
    expectedMetrics.put("currentRebootGeneration", 0L);
    expectedMetrics.put("wantToReboot", 0);
    expectedMetrics.put("wantToRetire", 0);
    expectedMetrics.put("wantToDeprovision", 0);
    expectedMetrics.put("hardwareFailure", 0);
    expectedMetrics.put("hardwareDivergence", 0);
    expectedMetrics.put("allowedToBeDown", 0);
    expectedMetrics.put("numberOfServices", 0L);
    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(expectedMetrics, metric.values);
}
Also used : MockNameResolver(com.yahoo.vespa.hosted.provision.testutils.MockNameResolver) HashMap(java.util.HashMap) 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) Test(org.junit.Test)

Example 5 with ServiceModel

use of com.yahoo.vespa.service.monitor.ServiceModel in project vespa by vespa-engine.

the class ModelGenerator method toServiceModel.

/**
 * Create service model based primarily on super model.
 *
 * If the configServerhosts is non-empty, a config server application is added.
 */
ServiceModel toServiceModel(SuperModel superModel, Zone zone, List<String> configServerHosts, ServiceStatusProvider serviceStatusProvider) {
    Map<ApplicationInstanceReference, ApplicationInstance> applicationInstances = new HashMap<>();
    for (ApplicationInfo applicationInfo : superModel.getAllApplicationInfos()) {
        ApplicationInstance applicationInstance = toApplicationInstance(applicationInfo, zone, serviceStatusProvider);
        applicationInstances.put(applicationInstance.reference(), applicationInstance);
    }
    // The config server is part of the service model (but not super model)
    if (!configServerHosts.isEmpty()) {
        ConfigServerApplication configServerApplication = new ConfigServerApplication();
        ApplicationInstance configServerApplicationInstance = configServerApplication.toApplicationInstance(configServerHosts);
        applicationInstances.put(configServerApplicationInstance.reference(), configServerApplicationInstance);
    }
    return new ServiceModel(applicationInstances);
}
Also used : ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) HashMap(java.util.HashMap) ServiceModel(com.yahoo.vespa.service.monitor.ServiceModel) ApplicationInfo(com.yahoo.config.model.api.ApplicationInfo) ApplicationInstanceReference(com.yahoo.vespa.applicationmodel.ApplicationInstanceReference)

Aggregations

ServiceModel (com.yahoo.vespa.service.monitor.ServiceModel)7 Test (org.junit.Test)6 SuperModel (com.yahoo.config.model.api.SuperModel)3 Zone (com.yahoo.config.provision.Zone)3 ApplicationInstance (com.yahoo.vespa.applicationmodel.ApplicationInstance)3 ApplicationInstanceReference (com.yahoo.vespa.applicationmodel.ApplicationInstanceReference)3 ApplicationInfo (com.yahoo.config.model.api.ApplicationInfo)2 DockerImage (com.yahoo.config.provision.DockerImage)2 NodeFlavors (com.yahoo.config.provision.NodeFlavors)2 Curator (com.yahoo.vespa.curator.Curator)2 MockCurator (com.yahoo.vespa.curator.mock.MockCurator)2 Node (com.yahoo.vespa.hosted.provision.Node)2 NodeRepository (com.yahoo.vespa.hosted.provision.NodeRepository)2 JobControl (com.yahoo.vespa.hosted.provision.maintenance.JobControl)2 MetricsReporter (com.yahoo.vespa.hosted.provision.maintenance.MetricsReporter)2 MockNameResolver (com.yahoo.vespa.hosted.provision.testutils.MockNameResolver)2 Orchestrator (com.yahoo.vespa.orchestrator.Orchestrator)2 ServiceMonitor (com.yahoo.vespa.service.monitor.ServiceMonitor)2 HashMap (java.util.HashMap)2 SuperModelProvider (com.yahoo.config.model.api.SuperModelProvider)1