Search in sources :

Example 11 with ApplicationInstance

use of com.yahoo.vespa.applicationmodel.ApplicationInstance 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 12 with ApplicationInstance

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

the class ModelGenerator method toServiceModel.

/**
 * Create service model based primarily on super model.
 *
 * If the configServerhosts is non-empty, a config server application is added.
 */
ServiceModel toServiceModel(SuperModel superModel, Zone zone, List<String> configServerHosts, ServiceStatusProvider serviceStatusProvider) {
    Map<ApplicationInstanceReference, ApplicationInstance> applicationInstances = new HashMap<>();
    for (ApplicationInfo applicationInfo : superModel.getAllApplicationInfos()) {
        ApplicationInstance applicationInstance = toApplicationInstance(applicationInfo, zone, serviceStatusProvider);
        applicationInstances.put(applicationInstance.reference(), applicationInstance);
    }
    // The config server is part of the service model (but not super model)
    if (!configServerHosts.isEmpty()) {
        ConfigServerApplication configServerApplication = new ConfigServerApplication();
        ApplicationInstance configServerApplicationInstance = configServerApplication.toApplicationInstance(configServerHosts);
        applicationInstances.put(configServerApplicationInstance.reference(), configServerApplicationInstance);
    }
    return new ServiceModel(applicationInstances);
}
Also used : ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) HashMap(java.util.HashMap) ServiceModel(com.yahoo.vespa.service.monitor.ServiceModel) ApplicationInfo(com.yahoo.config.model.api.ApplicationInfo) ApplicationInstanceReference(com.yahoo.vespa.applicationmodel.ApplicationInstanceReference)

Example 13 with ApplicationInstance

use of com.yahoo.vespa.applicationmodel.ApplicationInstance 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 14 with ApplicationInstance

use of com.yahoo.vespa.applicationmodel.ApplicationInstance 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 15 with ApplicationInstance

use of com.yahoo.vespa.applicationmodel.ApplicationInstance 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)

Aggregations

ApplicationInstance (com.yahoo.vespa.applicationmodel.ApplicationInstance)24 HostName (com.yahoo.vespa.applicationmodel.HostName)14 ApplicationInstanceReference (com.yahoo.vespa.applicationmodel.ApplicationInstanceReference)11 Test (org.junit.Test)10 ServiceType (com.yahoo.vespa.applicationmodel.ServiceType)9 ClusterId (com.yahoo.vespa.applicationmodel.ClusterId)6 ServiceCluster (com.yahoo.vespa.applicationmodel.ServiceCluster)6 ServiceInstance (com.yahoo.vespa.applicationmodel.ServiceInstance)6 ApplicationInstanceId (com.yahoo.vespa.applicationmodel.ApplicationInstanceId)5 TenantId (com.yahoo.vespa.applicationmodel.TenantId)5 HashMap (java.util.HashMap)5 ConfigId (com.yahoo.vespa.applicationmodel.ConfigId)4 NodeGroup (com.yahoo.vespa.orchestrator.model.NodeGroup)4 HostStatus (com.yahoo.vespa.orchestrator.status.HostStatus)4 MutableStatusRegistry (com.yahoo.vespa.orchestrator.status.MutableStatusRegistry)4 ServiceModel (com.yahoo.vespa.service.monitor.ServiceModel)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 SuperModel (com.yahoo.config.model.api.SuperModel)3 ApplicationId (com.yahoo.config.provision.ApplicationId)3