use of com.yahoo.vespa.orchestrator.Orchestrator in project vespa by vespa-engine.
the class RetiredExpirer method canRemove.
/**
* Checks if the node can be removed:
* if the node is a docker host, it will only be removed if it has no children,
* or all its children are parked or failed
* Otherwise, a removal is allowed if either of these are true:
* - The node has been in state {@link History.Event.Type#retired} for longer than {@link #retiredExpiry}
* - Orchestrator allows it
*/
private boolean canRemove(Node node) {
if (node.type().isDockerHost()) {
return nodeRepository().getChildNodes(node.hostname()).stream().allMatch(child -> child.state() == Node.State.parked || child.state() == Node.State.failed);
}
Optional<Instant> timeOfRetiredEvent = node.history().event(History.Event.Type.retired).map(History.Event::at);
Optional<Instant> retireAfter = timeOfRetiredEvent.map(retiredEvent -> retiredEvent.plus(retiredExpiry));
boolean shouldRetireNowBecauseExpried = retireAfter.map(time -> time.isBefore(clock.instant())).orElse(false);
if (shouldRetireNowBecauseExpried) {
return true;
}
try {
orchestrator.acquirePermissionToRemove(new HostName(node.hostname()));
return true;
} catch (OrchestrationException e) {
log.info("Did not get permission to remove retired " + node + ": " + e.getMessage());
return false;
}
}
use of com.yahoo.vespa.orchestrator.Orchestrator in project vespa by vespa-engine.
the class HostResourceTest method patch_works.
@Test
public void patch_works() throws OrchestrationException {
Orchestrator orchestrator = mock(Orchestrator.class);
HostResource hostResource = new HostResource(orchestrator, uriInfo);
String hostNameString = "hostname";
PatchHostRequest request = new PatchHostRequest();
request.state = "NO_REMARKS";
PatchHostResponse response = hostResource.patch(hostNameString, request);
assertEquals(response.description, "ok");
verify(orchestrator, times(1)).setNodeStatus(new HostName(hostNameString), HostStatus.NO_REMARKS);
}
use of com.yahoo.vespa.orchestrator.Orchestrator in project vespa by vespa-engine.
the class HostResourceTest method getHost_works.
@Test
public void getHost_works() throws Exception {
Orchestrator orchestrator = mock(Orchestrator.class);
HostResource hostResource = new HostResource(orchestrator, uriInfo);
HostName hostName = new HostName("hostname");
UriBuilder baseUriBuilder = mock(UriBuilder.class);
when(uriInfo.getBaseUriBuilder()).thenReturn(baseUriBuilder);
when(baseUriBuilder.path(any(String.class))).thenReturn(baseUriBuilder);
when(baseUriBuilder.path(any(Class.class))).thenReturn(baseUriBuilder);
URI uri = new URI("https://foo.com/bar");
when(baseUriBuilder.build()).thenReturn(uri);
ServiceInstance serviceInstance = new ServiceInstance(new ConfigId("configId"), hostName, ServiceStatus.UP);
ServiceCluster serviceCluster = new ServiceCluster(new ClusterId("clusterId"), new ServiceType("serviceType"), Collections.singleton(serviceInstance));
serviceInstance.setServiceCluster(serviceCluster);
Host host = new Host(hostName, HostStatus.ALLOWED_TO_BE_DOWN, new ApplicationInstanceReference(new TenantId("tenantId"), new ApplicationInstanceId("applicationId")), Collections.singletonList(serviceInstance));
when(orchestrator.getHost(hostName)).thenReturn(host);
GetHostResponse response = hostResource.getHost(hostName.s());
assertEquals("https://foo.com/bar", response.applicationUrl());
assertEquals("hostname", response.hostname());
assertEquals("ALLOWED_TO_BE_DOWN", response.state());
assertEquals(1, response.services().size());
assertEquals("clusterId", response.services().get(0).clusterId);
assertEquals("configId", response.services().get(0).configId);
assertEquals("UP", response.services().get(0).serviceStatus);
assertEquals("serviceType", response.services().get(0).serviceType);
}
use of com.yahoo.vespa.orchestrator.Orchestrator 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);
}
use of com.yahoo.vespa.orchestrator.Orchestrator 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);
}
Aggregations