Search in sources :

Example 26 with ClusterSpec

use of com.yahoo.config.provision.ClusterSpec 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 27 with ClusterSpec

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

the class NodeFailTester method withProxyApplication.

public static NodeFailTester withProxyApplication() {
    NodeFailTester tester = new NodeFailTester();
    tester.createReadyNodes(16, NodeType.proxy);
    // Create application
    Capacity allProxies = Capacity.fromRequiredNodeType(NodeType.proxy);
    ClusterSpec clusterApp1 = ClusterSpec.request(ClusterSpec.Type.container, ClusterSpec.Id.from("test"), Version.fromString("6.42"), false);
    tester.activate(app1, clusterApp1, allProxies);
    assertEquals(16, tester.nodeRepository.getNodes(NodeType.proxy, Node.State.active).size());
    Map<ApplicationId, MockDeployer.ApplicationContext> apps = new HashMap<>();
    apps.put(app1, new MockDeployer.ApplicationContext(app1, clusterApp1, allProxies, 1));
    tester.deployer = new MockDeployer(tester.provisioner, apps);
    tester.serviceMonitor = new ServiceMonitorStub(apps, tester.nodeRepository);
    tester.metric = new MetricsReporterTest.TestMetric();
    tester.failer = tester.createFailer();
    return tester;
}
Also used : ServiceMonitorStub(com.yahoo.vespa.hosted.provision.testutils.ServiceMonitorStub) Capacity(com.yahoo.config.provision.Capacity) HashMap(java.util.HashMap) ClusterSpec(com.yahoo.config.provision.ClusterSpec) ApplicationId(com.yahoo.config.provision.ApplicationId) MetricsReporterTest(com.yahoo.vespa.hosted.provision.monitoring.MetricsReporterTest) MockDeployer(com.yahoo.vespa.hosted.provision.testutils.MockDeployer)

Example 28 with ClusterSpec

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

the class NodeRetirerTester method deployApp.

void deployApp(String tenantName, String applicationName, int[] flavorIds, int[] numNodes) {
    final ApplicationId applicationId = ApplicationId.from(tenantName, applicationName, "default");
    final List<MockDeployer.ClusterContext> clusterContexts = new ArrayList<>();
    for (int i = 0; i < flavorIds.length; i++) {
        Flavor flavor = flavors.get(flavorIds[i]);
        ClusterSpec cluster = ClusterSpec.request(ClusterSpec.Type.container, ClusterSpec.Id.from("cluster-" + i), Version.fromString("6.99"), false);
        Capacity capacity = Capacity.fromNodeCount(numNodes[i], Optional.of(flavor.name()), false);
        // If the number of node the app wants is divisible by 2, make it into 2 groups, otherwise as 1
        int numGroups = numNodes[i] % 2 == 0 ? 2 : 1;
        clusterContexts.add(new MockDeployer.ClusterContext(applicationId, cluster, capacity, numGroups));
    }
    apps.put(applicationId, new MockDeployer.ApplicationContext(applicationId, clusterContexts));
    deployer.deployFromLocalActive(applicationId, Duration.ZERO).get().activate();
}
Also used : Capacity(com.yahoo.config.provision.Capacity) ArrayList(java.util.ArrayList) ClusterSpec(com.yahoo.config.provision.ClusterSpec) ApplicationId(com.yahoo.config.provision.ApplicationId) Flavor(com.yahoo.config.provision.Flavor) MockDeployer(com.yahoo.vespa.hosted.provision.testutils.MockDeployer)

Example 29 with ClusterSpec

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

the class RetiredExpirerTest method ensure_retired_groups_time_out.

@Test
public void ensure_retired_groups_time_out() {
    createReadyNodes(8, nodeRepository, nodeFlavors);
    createHostNodes(4, nodeRepository, nodeFlavors);
    ApplicationId applicationId = ApplicationId.from(TenantName.from("foo"), ApplicationName.from("bar"), InstanceName.from("fuz"));
    ClusterSpec cluster = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("test"), Version.fromString("6.42"), false);
    activate(applicationId, cluster, 8, 8, provisioner);
    activate(applicationId, cluster, 2, 2, provisioner);
    assertEquals(8, nodeRepository.getNodes(applicationId, Node.State.active).size());
    assertEquals(0, nodeRepository.getNodes(applicationId, Node.State.inactive).size());
    // Cause inactivation of retired nodes
    // Retire period spent
    clock.advance(Duration.ofHours(30));
    MockDeployer deployer = new MockDeployer(provisioner, Collections.singletonMap(applicationId, new MockDeployer.ApplicationContext(applicationId, cluster, Capacity.fromNodeCount(2, Optional.of("default"), false), 1)));
    createRetiredExpirer(deployer).run();
    assertEquals(2, nodeRepository.getNodes(applicationId, Node.State.active).size());
    assertEquals(6, nodeRepository.getNodes(applicationId, Node.State.inactive).size());
    assertEquals(1, deployer.redeployments);
    // inactivated nodes are not retired
    for (Node node : nodeRepository.getNodes(applicationId, Node.State.inactive)) assertFalse(node.allocation().get().membership().retired());
}
Also used : Node(com.yahoo.vespa.hosted.provision.Node) ClusterSpec(com.yahoo.config.provision.ClusterSpec) ApplicationId(com.yahoo.config.provision.ApplicationId) MockDeployer(com.yahoo.vespa.hosted.provision.testutils.MockDeployer) Test(org.junit.Test)

Example 30 with ClusterSpec

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

the class Preparer method prepare.

/**
 * Ensure sufficient nodes are reserved or active for the given application and cluster
 *
 * @return the list of nodes this cluster will have allocated if activated
 */
// Note: This operation may make persisted changes to the set of reserved and inactive nodes,
// but it may not change the set of active nodes, as the active nodes must stay in sync with the
// active config model which is changed on activate
public List<Node> prepare(ApplicationId application, ClusterSpec cluster, NodeSpec requestedNodes, int wantedGroups) {
    List<Node> surplusNodes = findNodesInRemovableGroups(application, cluster, wantedGroups);
    MutableInteger highestIndex = new MutableInteger(findHighestIndex(application, cluster));
    List<Node> acceptedNodes = new ArrayList<>();
    for (int groupIndex = 0; groupIndex < wantedGroups; groupIndex++) {
        ClusterSpec clusterGroup = cluster.with(Optional.of(ClusterSpec.Group.from(groupIndex)));
        List<Node> accepted = groupPreparer.prepare(application, clusterGroup, requestedNodes.fraction(wantedGroups), surplusNodes, highestIndex, spareCount);
        replace(acceptedNodes, accepted);
    }
    moveToActiveGroup(surplusNodes, wantedGroups, cluster.group());
    replace(acceptedNodes, retire(surplusNodes));
    return acceptedNodes;
}
Also used : Node(com.yahoo.vespa.hosted.provision.Node) MutableInteger(com.yahoo.lang.MutableInteger) ArrayList(java.util.ArrayList) ClusterSpec(com.yahoo.config.provision.ClusterSpec)

Aggregations

ClusterSpec (com.yahoo.config.provision.ClusterSpec)32 Node (com.yahoo.vespa.hosted.provision.Node)23 ApplicationId (com.yahoo.config.provision.ApplicationId)20 Test (org.junit.Test)18 Zone (com.yahoo.config.provision.Zone)14 MockDeployer (com.yahoo.vespa.hosted.provision.testutils.MockDeployer)10 HashSet (java.util.HashSet)10 Flavor (com.yahoo.config.provision.Flavor)9 HostSpec (com.yahoo.config.provision.HostSpec)9 Capacity (com.yahoo.config.provision.Capacity)7 ArrayList (java.util.ArrayList)6 Version (com.yahoo.component.Version)5 ClusterMembership (com.yahoo.config.provision.ClusterMembership)5 List (java.util.List)5 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 Environment (com.yahoo.config.provision.Environment)3 NodeType (com.yahoo.config.provision.NodeType)3 RegionName (com.yahoo.config.provision.RegionName)3