Search in sources :

Example 6 with NodeRepository

use of com.yahoo.vespa.hosted.provision.NodeRepository in project vespa by vespa-engine.

the class IdentityDocumentGeneratorTest method generates_valid_identity_document.

@Test
public void generates_valid_identity_document() throws Exception {
    String hostname = "x.y.com";
    ApplicationId appid = ApplicationId.from(TenantName.from("tenant"), ApplicationName.from("application"), InstanceName.from("default"));
    Allocation allocation = new Allocation(appid, ClusterMembership.from("container/default/0/0", Version.fromString("1.2.3")), Generation.inital(), false);
    Node n = Node.create("ostkid", ImmutableSet.of("127.0.0.1"), new HashSet<>(), hostname, Optional.empty(), new MockNodeFlavors().getFlavorOrThrow("default"), NodeType.tenant).with(allocation);
    NodeRepository nodeRepository = mock(NodeRepository.class);
    when(nodeRepository.getNode(eq(hostname))).thenReturn(Optional.of(n));
    AutoGeneratedKeyProvider keyProvider = new AutoGeneratedKeyProvider();
    String dnsSuffix = "vespa.dns.suffix";
    AthenzProviderServiceConfig config = getAthenzProviderConfig("domain", "service", dnsSuffix, ZONE);
    IdentityDocumentGenerator identityDocumentGenerator = new IdentityDocumentGenerator(config, nodeRepository, ZONE, keyProvider);
    SignedIdentityDocument signedIdentityDocument = identityDocumentGenerator.generateSignedIdentityDocument(hostname);
    // Verify attributes
    assertEquals(hostname, signedIdentityDocument.identityDocument.instanceHostname);
    String environment = "dev";
    String region = "us-north-1";
    String expectedZoneDnsSuffix = environment + "-" + region + "." + dnsSuffix;
    assertEquals(expectedZoneDnsSuffix, signedIdentityDocument.dnsSuffix);
    ProviderUniqueId expectedProviderUniqueId = new ProviderUniqueId("tenant", "application", environment, region, "default", "default", 0);
    assertEquals(expectedProviderUniqueId, signedIdentityDocument.identityDocument.providerUniqueId);
    // Validate signature
    assertTrue("Message", InstanceValidator.isSignatureValid(keyProvider.getPublicKey(0), signedIdentityDocument.rawIdentityDocument, signedIdentityDocument.signature));
}
Also used : MockNodeFlavors(com.yahoo.vespa.hosted.provision.testutils.MockNodeFlavors) Allocation(com.yahoo.vespa.hosted.provision.node.Allocation) Node(com.yahoo.vespa.hosted.provision.Node) NodeRepository(com.yahoo.vespa.hosted.provision.NodeRepository) AutoGeneratedKeyProvider(com.yahoo.vespa.hosted.athenz.instanceproviderservice.AutoGeneratedKeyProvider) AthenzProviderServiceConfig(com.yahoo.vespa.hosted.athenz.instanceproviderservice.config.AthenzProviderServiceConfig) ApplicationId(com.yahoo.config.provision.ApplicationId) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with NodeRepository

use of com.yahoo.vespa.hosted.provision.NodeRepository in project vespa by vespa-engine.

the class ReservationExpirerTest method ensure_reservation_times_out.

@Test
public void ensure_reservation_times_out() {
    ManualClock clock = new ManualClock();
    NodeFlavors flavors = FlavorConfigBuilder.createDummies("default");
    NodeRepository nodeRepository = new NodeRepository(flavors, curator, clock, Zone.defaultZone(), new MockNameResolver().mockAnyLookup(), new DockerImage("docker-registry.domain.tld:8080/dist/vespa"), true);
    NodeRepositoryProvisioner provisioner = new NodeRepositoryProvisioner(nodeRepository, flavors, Zone.defaultZone());
    List<Node> nodes = new ArrayList<>(2);
    nodes.add(nodeRepository.createNode(UUID.randomUUID().toString(), UUID.randomUUID().toString(), Optional.empty(), flavors.getFlavorOrThrow("default"), NodeType.tenant));
    nodes.add(nodeRepository.createNode(UUID.randomUUID().toString(), UUID.randomUUID().toString(), Optional.empty(), flavors.getFlavorOrThrow("default"), NodeType.tenant));
    nodes.add(nodeRepository.createNode(UUID.randomUUID().toString(), UUID.randomUUID().toString(), Optional.empty(), flavors.getFlavorOrThrow("default"), NodeType.host));
    nodes = nodeRepository.addNodes(nodes);
    nodes = nodeRepository.setDirty(nodes, Agent.system, getClass().getSimpleName());
    // Reserve 2 nodes
    assertEquals(2, nodeRepository.getNodes(NodeType.tenant, Node.State.dirty).size());
    nodeRepository.setReady(nodes, Agent.system, getClass().getSimpleName());
    ApplicationId applicationId = new ApplicationId.Builder().tenant("foo").applicationName("bar").instanceName("fuz").build();
    ClusterSpec cluster = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("test"), Version.fromString("6.42"), false);
    provisioner.prepare(applicationId, cluster, Capacity.fromNodeCount(2), 1, null);
    assertEquals(2, nodeRepository.getNodes(NodeType.tenant, Node.State.reserved).size());
    // Reservation times out
    // Reserved but not used time out
    clock.advance(Duration.ofMinutes(14));
    new ReservationExpirer(nodeRepository, clock, Duration.ofMinutes(10), new JobControl(nodeRepository.database())).run();
    // Assert nothing is reserved
    assertEquals(0, nodeRepository.getNodes(NodeType.tenant, Node.State.reserved).size());
    List<Node> dirty = nodeRepository.getNodes(NodeType.tenant, Node.State.dirty);
    assertEquals(2, dirty.size());
    assertFalse(dirty.get(0).allocation().isPresent());
    assertFalse(dirty.get(1).allocation().isPresent());
}
Also used : MockNameResolver(com.yahoo.vespa.hosted.provision.testutils.MockNameResolver) Node(com.yahoo.vespa.hosted.provision.Node) FlavorConfigBuilder(com.yahoo.vespa.hosted.provision.provisioning.FlavorConfigBuilder) NodeRepositoryProvisioner(com.yahoo.vespa.hosted.provision.provisioning.NodeRepositoryProvisioner) ArrayList(java.util.ArrayList) ClusterSpec(com.yahoo.config.provision.ClusterSpec) ManualClock(com.yahoo.test.ManualClock) NodeFlavors(com.yahoo.config.provision.NodeFlavors) NodeRepository(com.yahoo.vespa.hosted.provision.NodeRepository) DockerImage(com.yahoo.config.provision.DockerImage) ApplicationId(com.yahoo.config.provision.ApplicationId) Test(org.junit.Test)

Example 8 with NodeRepository

use of com.yahoo.vespa.hosted.provision.NodeRepository in project vespa by vespa-engine.

the class PeriodicApplicationMaintainerTest method before.

@Before
public void before() {
    Curator curator = new MockCurator();
    Zone zone = new Zone(Environment.prod, RegionName.from("us-east"));
    this.nodeRepository = new NodeRepository(nodeFlavors, curator, new ManualClock(), zone, new MockNameResolver().mockAnyLookup(), new DockerImage("docker-registry.domain.tld:8080/dist/vespa"), true);
    this.fixture = new Fixture(zone, nodeRepository, nodeFlavors, curator);
}
Also used : ManualClock(com.yahoo.test.ManualClock) MockNameResolver(com.yahoo.vespa.hosted.provision.testutils.MockNameResolver) Zone(com.yahoo.config.provision.Zone) NodeRepository(com.yahoo.vespa.hosted.provision.NodeRepository) Curator(com.yahoo.vespa.curator.Curator) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) DockerImage(com.yahoo.config.provision.DockerImage) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Before(org.junit.Before)

Example 9 with NodeRepository

use of com.yahoo.vespa.hosted.provision.NodeRepository 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 10 with NodeRepository

use of com.yahoo.vespa.hosted.provision.NodeRepository in project vespa by vespa-engine.

the class OperatorChangeApplicationMaintainerTest method test_application_maintenance.

@Test
public void test_application_maintenance() throws InterruptedException {
    ManualClock clock = new ManualClock();
    Curator curator = new MockCurator();
    Zone zone = new Zone(Environment.prod, RegionName.from("us-east"));
    this.nodeRepository = new NodeRepository(nodeFlavors, curator, clock, zone, new MockNameResolver().mockAnyLookup(), new DockerImage("docker-registry.domain.tld:8080/dist/vespa"), true);
    this.fixture = new Fixture(zone, nodeRepository, nodeFlavors, curator);
    createReadyNodes(15, nodeRepository, nodeFlavors);
    createHostNodes(2, nodeRepository, nodeFlavors);
    // Create applications
    fixture.activate();
    OperatorChangeApplicationMaintainer maintainer = new OperatorChangeApplicationMaintainer(fixture.deployer, nodeRepository, clock, Duration.ofMinutes(1), new JobControl(nodeRepository.database()));
    clock.advance(Duration.ofMinutes(2));
    maintainer.maintain();
    assertEquals("No changes -> no redeployments", 0, fixture.deployer.redeployments);
    nodeRepository.fail(nodeRepository.getNodes(fixture.app1).get(3).hostname(), Agent.system, "Failing to unit test");
    clock.advance(Duration.ofMinutes(2));
    maintainer.maintain();
    assertEquals("System change -> no redeployments", 0, fixture.deployer.redeployments);
    clock.advance(Duration.ofSeconds(1));
    nodeRepository.fail(nodeRepository.getNodes(fixture.app2).get(4).hostname(), Agent.operator, "Manual node failing");
    clock.advance(Duration.ofMinutes(2));
    maintainer.maintain();
    assertEquals("Operator change -> redeployment", 1, fixture.deployer.redeployments);
    clock.advance(Duration.ofMinutes(2));
    maintainer.maintain();
    assertEquals("No further operator changes -> no (new) redeployments", 1, fixture.deployer.redeployments);
}
Also used : ManualClock(com.yahoo.test.ManualClock) MockNameResolver(com.yahoo.vespa.hosted.provision.testutils.MockNameResolver) Zone(com.yahoo.config.provision.Zone) NodeRepository(com.yahoo.vespa.hosted.provision.NodeRepository) Curator(com.yahoo.vespa.curator.Curator) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) DockerImage(com.yahoo.config.provision.DockerImage) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Test(org.junit.Test)

Aggregations

NodeRepository (com.yahoo.vespa.hosted.provision.NodeRepository)13 Node (com.yahoo.vespa.hosted.provision.Node)11 ApplicationId (com.yahoo.config.provision.ApplicationId)8 Duration (java.time.Duration)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Deployer (com.yahoo.config.provision.Deployer)6 NodeType (com.yahoo.config.provision.NodeType)6 Orchestrator (com.yahoo.vespa.orchestrator.Orchestrator)6 Map (java.util.Map)6 Optional (java.util.Optional)6 Deployment (com.yahoo.config.provision.Deployment)5 DockerImage (com.yahoo.config.provision.DockerImage)5 MockNameResolver (com.yahoo.vespa.hosted.provision.testutils.MockNameResolver)5 HashMap (java.util.HashMap)5 Curator (com.yahoo.vespa.curator.Curator)4 MockCurator (com.yahoo.vespa.curator.mock.MockCurator)4 Agent (com.yahoo.vespa.hosted.provision.node.Agent)4 ServiceMonitor (com.yahoo.vespa.service.monitor.ServiceMonitor)4 Test (org.junit.Test)4