Search in sources :

Example 6 with ServiceInstance

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

the class ApplicationApiImpl method getServiceClustersInGroup.

private static Set<ServiceCluster> getServiceClustersInGroup(NodeGroup nodeGroup) {
    ApplicationInstance applicationInstance = nodeGroup.getApplication();
    Set<ServiceCluster> serviceClustersInGroup = new HashSet<>();
    for (ServiceCluster cluster : applicationInstance.serviceClusters()) {
        for (ServiceInstance instance : cluster.serviceInstances()) {
            if (nodeGroup.contains(instance.hostName())) {
                serviceClustersInGroup.add(cluster);
                break;
            }
        }
    }
    return serviceClustersInGroup;
}
Also used : OrchestratorUtil.getHostsUsedByApplicationInstance(com.yahoo.vespa.orchestrator.OrchestratorUtil.getHostsUsedByApplicationInstance) ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) ServiceCluster(com.yahoo.vespa.applicationmodel.ServiceCluster) ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) HashSet(java.util.HashSet)

Example 7 with ServiceInstance

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

the class ModelGenerator method toApplicationInstance.

ApplicationInstance toApplicationInstance(ApplicationInfo applicationInfo, Zone zone, ServiceStatusProvider serviceStatusProvider) {
    Map<ServiceClusterKey, Set<ServiceInstance>> groupedServiceInstances = new HashMap<>();
    for (HostInfo host : applicationInfo.getModel().getHosts()) {
        HostName hostName = new HostName(host.getHostname());
        for (ServiceInfo serviceInfo : host.getServices()) {
            ServiceClusterKey serviceClusterKey = toServiceClusterKey(serviceInfo);
            ServiceInstance serviceInstance = toServiceInstance(applicationInfo.getApplicationId(), serviceClusterKey.clusterId(), serviceInfo, hostName, serviceStatusProvider);
            if (!groupedServiceInstances.containsKey(serviceClusterKey)) {
                groupedServiceInstances.put(serviceClusterKey, new HashSet<>());
            }
            groupedServiceInstances.get(serviceClusterKey).add(serviceInstance);
        }
    }
    Set<ServiceCluster> serviceClusters = groupedServiceInstances.entrySet().stream().map(entry -> new ServiceCluster(entry.getKey().clusterId(), entry.getKey().serviceType(), entry.getValue())).collect(Collectors.toSet());
    ApplicationInstance applicationInstance = new ApplicationInstance(new TenantId(applicationInfo.getApplicationId().tenant().toString()), toApplicationInstanceId(applicationInfo, zone), serviceClusters);
    // Fill back-references
    for (ServiceCluster serviceCluster : applicationInstance.serviceClusters()) {
        serviceCluster.setApplicationInstance(applicationInstance);
        for (ServiceInstance serviceInstance : serviceCluster.serviceInstances()) {
            serviceInstance.setServiceCluster(serviceCluster);
        }
    }
    return applicationInstance;
}
Also used : ApplicationId(com.yahoo.config.provision.ApplicationId) HostInfo(com.yahoo.config.model.api.HostInfo) HashMap(java.util.HashMap) ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) ClusterId(com.yahoo.vespa.applicationmodel.ClusterId) ServiceStatus(com.yahoo.vespa.applicationmodel.ServiceStatus) HashSet(java.util.HashSet) HostName(com.yahoo.vespa.applicationmodel.HostName) Map(java.util.Map) SuperModel(com.yahoo.config.model.api.SuperModel) ServiceStatusProvider(com.yahoo.vespa.service.monitor.ServiceStatusProvider) ApplicationInstanceReference(com.yahoo.vespa.applicationmodel.ApplicationInstanceReference) ApplicationInfo(com.yahoo.config.model.api.ApplicationInfo) ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) ConfigId(com.yahoo.vespa.applicationmodel.ConfigId) ServiceCluster(com.yahoo.vespa.applicationmodel.ServiceCluster) Set(java.util.Set) TenantId(com.yahoo.vespa.applicationmodel.TenantId) Collectors(java.util.stream.Collectors) ServiceModel(com.yahoo.vespa.service.monitor.ServiceModel) ServiceClusterKey(com.yahoo.vespa.applicationmodel.ServiceClusterKey) ServiceType(com.yahoo.vespa.applicationmodel.ServiceType) List(java.util.List) ApplicationInstanceId(com.yahoo.vespa.applicationmodel.ApplicationInstanceId) Zone(com.yahoo.config.provision.Zone) ServiceInfo(com.yahoo.config.model.api.ServiceInfo) HashSet(java.util.HashSet) Set(java.util.Set) ServiceClusterKey(com.yahoo.vespa.applicationmodel.ServiceClusterKey) HashMap(java.util.HashMap) ServiceCluster(com.yahoo.vespa.applicationmodel.ServiceCluster) ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) ServiceInfo(com.yahoo.config.model.api.ServiceInfo) TenantId(com.yahoo.vespa.applicationmodel.TenantId) ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) HostInfo(com.yahoo.config.model.api.HostInfo) HostName(com.yahoo.vespa.applicationmodel.HostName)

Example 8 with ServiceInstance

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

the class ConfigServerApplication method toApplicationInstance.

ApplicationInstance toApplicationInstance(List<String> hostnames) {
    Set<ServiceInstance> serviceInstances = hostnames.stream().map(hostname -> new ServiceInstance(new ConfigId(CONFIG_ID_PREFIX + hostname), new HostName(hostname), ServiceStatus.NOT_CHECKED)).collect(Collectors.toSet());
    ServiceCluster serviceCluster = new ServiceCluster(CLUSTER_ID, SERVICE_TYPE, serviceInstances);
    Set<ServiceCluster> serviceClusters = Stream.of(serviceCluster).collect(Collectors.toSet());
    ApplicationInstance applicationInstance = new ApplicationInstance(TENANT_ID, APPLICATION_INSTANCE_ID, serviceClusters);
    // Fill back-references
    serviceCluster.setApplicationInstance(applicationInstance);
    for (ServiceInstance serviceInstance : serviceCluster.serviceInstances()) {
        serviceInstance.setServiceCluster(serviceCluster);
    }
    return applicationInstance;
}
Also used : ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) ConfigId(com.yahoo.vespa.applicationmodel.ConfigId) ServiceCluster(com.yahoo.vespa.applicationmodel.ServiceCluster) Set(java.util.Set) ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) ClusterId(com.yahoo.vespa.applicationmodel.ClusterId) ServiceStatus(com.yahoo.vespa.applicationmodel.ServiceStatus) TenantId(com.yahoo.vespa.applicationmodel.TenantId) Collectors(java.util.stream.Collectors) ServiceType(com.yahoo.vespa.applicationmodel.ServiceType) List(java.util.List) ApplicationInstanceId(com.yahoo.vespa.applicationmodel.ApplicationInstanceId) Stream(java.util.stream.Stream) HostName(com.yahoo.vespa.applicationmodel.HostName) ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) ServiceCluster(com.yahoo.vespa.applicationmodel.ServiceCluster) ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) ConfigId(com.yahoo.vespa.applicationmodel.ConfigId) HostName(com.yahoo.vespa.applicationmodel.HostName)

Example 9 with ServiceInstance

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

the class ModelGeneratorTest method verifyOtherApplication.

private void verifyOtherApplication(ApplicationInstance applicationInstance) {
    assertEquals(String.format("%s:%s:%s:%s:%s", ExampleModel.TENANT, ExampleModel.APPLICATION_NAME, ENVIRONMENT, REGION, ExampleModel.INSTANCE_NAME), applicationInstance.reference().toString());
    assertEquals(ExampleModel.TENANT, applicationInstance.tenantId().toString());
    Set<ServiceCluster> serviceClusters = applicationInstance.serviceClusters();
    assertEquals(1, serviceClusters.size());
    ServiceCluster serviceCluster = serviceClusters.iterator().next();
    assertEquals(ExampleModel.CLUSTER_ID, serviceCluster.clusterId().toString());
    assertEquals(ExampleModel.SERVICE_TYPE, serviceCluster.serviceType().toString());
    Set<ServiceInstance> serviceInstances = serviceCluster.serviceInstances();
    assertEquals(1, serviceClusters.size());
    ServiceInstance serviceInstance = serviceInstances.iterator().next();
    assertEquals(HOSTNAME, serviceInstance.hostName().toString());
    assertEquals(ExampleModel.CONFIG_ID, serviceInstance.configId().toString());
    assertEquals(ServiceStatus.UP, serviceInstance.serviceStatus());
}
Also used : ServiceCluster(com.yahoo.vespa.applicationmodel.ServiceCluster) ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance)

Example 10 with ServiceInstance

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

the class ClusterApiImpl method storageNodeInGroup.

private Optional<StorageNode> storageNodeInGroup(Predicate<ServiceInstance> storageServicePredicate) {
    if (!VespaModelUtil.isStorage(serviceCluster)) {
        return Optional.empty();
    }
    Set<StorageNode> storageNodes = new HashSet<>();
    for (ServiceInstance serviceInstance : servicesInGroup) {
        if (!storageServicePredicate.test(serviceInstance)) {
            continue;
        }
        HostName hostName = serviceInstance.hostName();
        if (nodeGroup.contains(hostName)) {
            if (storageNodes.contains(hostName)) {
                throw new IllegalStateException("Found more than 1 storage service instance on " + hostName + ": last service instance is " + serviceInstance.configId() + " in storage cluster " + clusterInfo());
            }
            StorageNode storageNode = new StorageNodeImpl(nodeGroup.getApplication(), clusterId(), serviceInstance, clusterControllerClientFactory);
            storageNodes.add(storageNode);
        }
    }
    if (storageNodes.size() > 1) {
        throw new IllegalStateException("Found more than 1 storage node (" + storageNodes + ") in the same cluster (" + clusterInfo() + ") in the same node group (" + getNodeGroup().toCommaSeparatedString() + "): E.g. suspension of such a setup is not supported " + " by the Cluster Controller and is dangerous w.r.t. data redundancy.");
    }
    return storageNodes.stream().findFirst();
}
Also used : ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) HostName(com.yahoo.vespa.applicationmodel.HostName) HashSet(java.util.HashSet)

Aggregations

ServiceInstance (com.yahoo.vespa.applicationmodel.ServiceInstance)13 HostName (com.yahoo.vespa.applicationmodel.HostName)9 ServiceCluster (com.yahoo.vespa.applicationmodel.ServiceCluster)8 ApplicationInstance (com.yahoo.vespa.applicationmodel.ApplicationInstance)6 ClusterId (com.yahoo.vespa.applicationmodel.ClusterId)6 ConfigId (com.yahoo.vespa.applicationmodel.ConfigId)6 ApplicationInstanceId (com.yahoo.vespa.applicationmodel.ApplicationInstanceId)5 ApplicationInstanceReference (com.yahoo.vespa.applicationmodel.ApplicationInstanceReference)5 ServiceType (com.yahoo.vespa.applicationmodel.ServiceType)5 TenantId (com.yahoo.vespa.applicationmodel.TenantId)5 ApplicationId (com.yahoo.config.provision.ApplicationId)4 ServiceStatus (com.yahoo.vespa.applicationmodel.ServiceStatus)4 HashSet (java.util.HashSet)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Test (org.junit.Test)3 OrchestratorConfig (com.yahoo.vespa.orchestrator.config.OrchestratorConfig)2