Search in sources :

Example 31 with HostName

use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.

the class ServiceMonitorStub method getAllApplicationInstances.

@Override
public Map<ApplicationInstanceReference, ApplicationInstance> getAllApplicationInstances() {
    // Convert apps information to the response payload to return
    Map<ApplicationInstanceReference, ApplicationInstance> status = new HashMap<>();
    for (Map.Entry<ApplicationId, MockDeployer.ApplicationContext> app : apps.entrySet()) {
        Set<ServiceInstance> serviceInstances = new HashSet<>();
        for (Node node : nodeRepository.getNodes(app.getValue().id(), Node.State.active)) {
            serviceInstances.add(new ServiceInstance(new ConfigId("configid"), new HostName(node.hostname()), getHostStatus(node.hostname())));
        }
        Set<ServiceCluster> serviceClusters = new HashSet<>();
        serviceClusters.add(new ServiceCluster(new ClusterId(app.getValue().clusterContexts().get(0).cluster().id().value()), new ServiceType("serviceType"), serviceInstances));
        TenantId tenantId = new TenantId(app.getKey().tenant().value());
        ApplicationInstanceId applicationInstanceId = new ApplicationInstanceId(app.getKey().application().value());
        status.put(new ApplicationInstanceReference(tenantId, applicationInstanceId), new ApplicationInstance(tenantId, applicationInstanceId, serviceClusters));
    }
    return status;
}
Also used : HashMap(java.util.HashMap) ServiceCluster(com.yahoo.vespa.applicationmodel.ServiceCluster) ClusterId(com.yahoo.vespa.applicationmodel.ClusterId) Node(com.yahoo.vespa.hosted.provision.Node) ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) ApplicationInstanceId(com.yahoo.vespa.applicationmodel.ApplicationInstanceId) TenantId(com.yahoo.vespa.applicationmodel.TenantId) ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) ServiceType(com.yahoo.vespa.applicationmodel.ServiceType) ApplicationInstanceReference(com.yahoo.vespa.applicationmodel.ApplicationInstanceReference) ConfigId(com.yahoo.vespa.applicationmodel.ConfigId) ApplicationId(com.yahoo.config.provision.ApplicationId) HashMap(java.util.HashMap) Map(java.util.Map) HostName(com.yahoo.vespa.applicationmodel.HostName) HashSet(java.util.HashSet)

Example 32 with HostName

use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.

the class OrchestratorImpl method getHost.

@Override
public Host getHost(HostName hostName) throws HostNameNotFoundException {
    ApplicationInstance applicationInstance = getApplicationInstance(hostName);
    List<ServiceInstance> serviceInstances = applicationInstance.serviceClusters().stream().flatMap(cluster -> cluster.serviceInstances().stream()).filter(serviceInstance -> hostName.equals(serviceInstance.hostName())).collect(Collectors.toList());
    HostStatus hostStatus = getNodeStatus(applicationInstance.reference(), hostName);
    return new Host(hostName, hostStatus, applicationInstance.reference(), serviceInstances);
}
Also used : ApplicationId(com.yahoo.config.provision.ApplicationId) Inject(com.google.inject.Inject) HostedVespaClusterPolicy(com.yahoo.vespa.orchestrator.policy.HostedVespaClusterPolicy) HashMap(java.util.HashMap) ClusterControllerClientFactory(com.yahoo.vespa.orchestrator.controller.ClusterControllerClientFactory) ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) ClusterId(com.yahoo.vespa.applicationmodel.ClusterId) ApplicationApi(com.yahoo.vespa.orchestrator.model.ApplicationApi) MutableStatusRegistry(com.yahoo.vespa.orchestrator.status.MutableStatusRegistry) ApplicationApiImpl(com.yahoo.vespa.orchestrator.model.ApplicationApiImpl) BatchHostStateChangeDeniedException(com.yahoo.vespa.orchestrator.policy.BatchHostStateChangeDeniedException) HostName(com.yahoo.vespa.applicationmodel.HostName) HostStateChangeDeniedException(com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException) Map(java.util.Map) LogLevel(com.yahoo.log.LogLevel) ClusterControllerStateResponse(com.yahoo.vespa.orchestrator.controller.ClusterControllerStateResponse) ApplicationInstanceReference(com.yahoo.vespa.applicationmodel.ApplicationInstanceReference) ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) ClusterControllerNodeState(com.yahoo.vespa.orchestrator.controller.ClusterControllerNodeState) StatusService(com.yahoo.vespa.orchestrator.status.StatusService) Policy(com.yahoo.vespa.orchestrator.policy.Policy) OrchestratorConfig(com.yahoo.vespa.orchestrator.config.OrchestratorConfig) ServiceCluster(com.yahoo.vespa.applicationmodel.ServiceCluster) VespaModelUtil(com.yahoo.vespa.orchestrator.model.VespaModelUtil) Set(java.util.Set) IOException(java.io.IOException) Logger(java.util.logging.Logger) ApplicationInstanceStatus(com.yahoo.vespa.orchestrator.status.ApplicationInstanceStatus) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) ClusterControllerClient(com.yahoo.vespa.orchestrator.controller.ClusterControllerClient) List(java.util.List) NodeGroup(com.yahoo.vespa.orchestrator.model.NodeGroup) HostedVespaPolicy(com.yahoo.vespa.orchestrator.policy.HostedVespaPolicy) HostStatus(com.yahoo.vespa.orchestrator.status.HostStatus) ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) HostStatus(com.yahoo.vespa.orchestrator.status.HostStatus)

Example 33 with HostName

use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.

the class OrchestratorImpl method nodeGroupsOrderedForSuspend.

/**
 * PROBLEM
 * Take the example of 2 Docker hosts:
 *  - Docker host 1 has two nodes A1 and B1, belonging to the application with
 *    a globally unique ID A and B, respectively.
 *  - Similarly, Docker host 2 has two nodes running content nodes A2 and B2,
 *    and we assume both A1 and A2 (and B1 and B2) have services within the same service cluster.
 *
 * Suppose both Docker hosts wanting to reboot, and
 *  - Docker host 1 asks to suspend A1 and B1, while
 *  - Docker host 2 asks to suspend B2 and A2.
 *
 * The Orchestrator may allow suspend of A1 and B2, before requesting the suspension of B1 and A2.
 * None of these can be suspended (assuming max 1 suspended content node per content cluster),
 * and so both requests for suspension will fail.
 *
 * Note that it's not a deadlock - both client will fail immediately and resume both A1 and B2 before
 * responding to the client, and if host 1 asks later w/o host 2 asking at the same time,
 * it will be given permission to suspend. However if both hosts were to request in lock-step,
 * there would be starvation. And in general, it would fail requests for suspension more
 * than necessary.
 *
 * SOLUTION
 * The solution we're using is to order the hostnames by the globally unique application instance ID,
 * e.g. hosted-vespa:routing:dev:some-region:default. In the example above, it would guarantee
 * Docker host 2 would ensure ask to suspend B2 before A2. We take care of that ordering here.
 *
 * NodeGroups complicate the above picture a little:  Each A1, A2, B1, and B2 is a NodeGroup that may
 * contain several nodes (on the same Docker host).  But the argument still applies.
 */
private List<NodeGroup> nodeGroupsOrderedForSuspend(List<HostName> hostNames) throws HostNameNotFoundException {
    Map<ApplicationInstanceReference, NodeGroup> nodeGroupMap = new HashMap<>(hostNames.size());
    for (HostName hostName : hostNames) {
        ApplicationInstance application = getApplicationInstance(hostName);
        NodeGroup nodeGroup = nodeGroupMap.get(application.reference());
        if (nodeGroup == null) {
            nodeGroup = new NodeGroup(application);
            nodeGroupMap.put(application.reference(), nodeGroup);
        }
        nodeGroup.addNode(hostName);
    }
    return nodeGroupMap.values().stream().sorted(OrchestratorImpl::compareNodeGroupsForSuspend).collect(Collectors.toList());
}
Also used : ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) HashMap(java.util.HashMap) ApplicationInstanceReference(com.yahoo.vespa.applicationmodel.ApplicationInstanceReference) HostName(com.yahoo.vespa.applicationmodel.HostName) NodeGroup(com.yahoo.vespa.orchestrator.model.NodeGroup)

Example 34 with HostName

use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.

the class ClusterApiImplTest method testNoServices.

@Test
public void testNoServices() {
    HostName hostName1 = modelUtils.createNode("host1", HostStatus.NO_REMARKS);
    HostName hostName2 = modelUtils.createNode("host2", HostStatus.NO_REMARKS);
    HostName hostName3 = modelUtils.createNode("host3", HostStatus.ALLOWED_TO_BE_DOWN);
    HostName hostName4 = modelUtils.createNode("host4", HostStatus.ALLOWED_TO_BE_DOWN);
    HostName hostName5 = modelUtils.createNode("host5", HostStatus.NO_REMARKS);
    ServiceCluster serviceCluster = modelUtils.createServiceCluster("cluster", new ServiceType("service-type"), Arrays.asList(modelUtils.createServiceInstance("service-1", hostName1, ServiceStatus.UP), modelUtils.createServiceInstance("service-2", hostName2, ServiceStatus.DOWN), modelUtils.createServiceInstance("service-3", hostName3, ServiceStatus.UP), modelUtils.createServiceInstance("service-4", hostName4, ServiceStatus.DOWN), modelUtils.createServiceInstance("service-5", hostName5, ServiceStatus.UP)));
    verifyNoServices(serviceCluster, false, false, hostName1);
    verifyNoServices(serviceCluster, true, false, hostName2);
    verifyNoServices(serviceCluster, true, false, hostName3);
    verifyNoServices(serviceCluster, true, false, hostName4);
    verifyNoServices(serviceCluster, false, false, hostName5);
    verifyNoServices(serviceCluster, false, false, hostName1, hostName2);
    verifyNoServices(serviceCluster, true, false, hostName2, hostName3);
    verifyNoServices(serviceCluster, true, true, hostName2, hostName3, hostName4);
    verifyNoServices(serviceCluster, false, true, hostName1, hostName2, hostName3, hostName4);
}
Also used : ServiceCluster(com.yahoo.vespa.applicationmodel.ServiceCluster) ServiceType(com.yahoo.vespa.applicationmodel.ServiceType) HostName(com.yahoo.vespa.applicationmodel.HostName) Test(org.junit.Test)

Example 35 with HostName

use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.

the class NodeGroupTest method testBasics.

@Test
public void testBasics() {
    ApplicationInstance applicationInstance = new ApplicationInstance(new TenantId("tenant"), new ApplicationInstanceId("application-instance"), new HashSet<>());
    HostName hostName1 = new HostName("host1");
    HostName hostName2 = new HostName("host2");
    HostName hostName3 = new HostName("host3");
    NodeGroup nodeGroup = new NodeGroup(applicationInstance, hostName1, hostName3);
    nodeGroup.addNode(hostName2);
    // hostnames are sorted (for no good reason other than testability due to stability, readability)
    assertEquals(Arrays.asList(hostName1, hostName2, hostName3), nodeGroup.getHostNames());
    assertEquals("host1,host2,host3", nodeGroup.toCommaSeparatedString());
}
Also used : ApplicationInstanceId(com.yahoo.vespa.applicationmodel.ApplicationInstanceId) TenantId(com.yahoo.vespa.applicationmodel.TenantId) ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) HostName(com.yahoo.vespa.applicationmodel.HostName) Test(org.junit.Test)

Aggregations

HostName (com.yahoo.vespa.applicationmodel.HostName)46 Test (org.junit.Test)20 ApplicationInstance (com.yahoo.vespa.applicationmodel.ApplicationInstance)14 ServiceType (com.yahoo.vespa.applicationmodel.ServiceType)13 ServiceCluster (com.yahoo.vespa.applicationmodel.ServiceCluster)9 ServiceInstance (com.yahoo.vespa.applicationmodel.ServiceInstance)9 ClusterId (com.yahoo.vespa.applicationmodel.ClusterId)8 HostStatus (com.yahoo.vespa.orchestrator.status.HostStatus)8 List (java.util.List)8 ApplicationId (com.yahoo.config.provision.ApplicationId)7 ApplicationInstanceReference (com.yahoo.vespa.applicationmodel.ApplicationInstanceReference)7 Orchestrator (com.yahoo.vespa.orchestrator.Orchestrator)7 Collectors (java.util.stream.Collectors)7 ApplicationInstanceId (com.yahoo.vespa.applicationmodel.ApplicationInstanceId)6 ConfigId (com.yahoo.vespa.applicationmodel.ConfigId)6 TenantId (com.yahoo.vespa.applicationmodel.TenantId)6 ServiceStatus (com.yahoo.vespa.applicationmodel.ServiceStatus)5 OrchestrationException (com.yahoo.vespa.orchestrator.OrchestrationException)5 StorageNode (com.yahoo.vespa.orchestrator.model.StorageNode)5 IOException (java.io.IOException)5