Search in sources :

Example 6 with ApplicationInstanceReference

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

the class OrchestratorImplTest method testGetHost.

@Test
public void testGetHost() throws Exception {
    ClusterControllerClientFactory clusterControllerClientFactory = mock(ClusterControllerClientFactory.class);
    StatusService statusService = mock(StatusService.class);
    InstanceLookupService lookupService = mock(InstanceLookupService.class);
    orchestrator = new OrchestratorImpl(clusterControllerClientFactory, statusService, new OrchestratorConfig(new OrchestratorConfig.Builder()), lookupService);
    HostName hostName = new HostName("host.yahoo.com");
    TenantId tenantId = new TenantId("tenant");
    ApplicationInstanceId applicationInstanceId = new ApplicationInstanceId("applicationInstanceId");
    ApplicationInstanceReference reference = new ApplicationInstanceReference(tenantId, applicationInstanceId);
    ApplicationInstance applicationInstance = new ApplicationInstance(tenantId, applicationInstanceId, Stream.of(new ServiceCluster(new ClusterId("clusterId"), new ServiceType("serviceType"), Stream.of(new ServiceInstance(new ConfigId("configId1"), hostName, ServiceStatus.UP), new ServiceInstance(new ConfigId("configId2"), hostName, ServiceStatus.NOT_CHECKED)).collect(Collectors.toSet()))).collect(Collectors.toSet()));
    when(lookupService.findInstanceByHost(hostName)).thenReturn(Optional.of(applicationInstance));
    ReadOnlyStatusRegistry readOnlyStatusRegistry = mock(ReadOnlyStatusRegistry.class);
    when(statusService.forApplicationInstance(reference)).thenReturn(readOnlyStatusRegistry);
    when(readOnlyStatusRegistry.getHostStatus(hostName)).thenReturn(HostStatus.ALLOWED_TO_BE_DOWN);
    Host host = orchestrator.getHost(hostName);
    assertEquals(reference, host.getApplicationInstanceReference());
    assertEquals(hostName, host.getHostName());
    assertEquals(HostStatus.ALLOWED_TO_BE_DOWN, host.getHostStatus());
    assertEquals(2, host.getServiceInstances().size());
}
Also used : OrchestratorConfig(com.yahoo.vespa.orchestrator.config.OrchestratorConfig) ServiceCluster(com.yahoo.vespa.applicationmodel.ServiceCluster) ClusterId(com.yahoo.vespa.applicationmodel.ClusterId) ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) StatusService(com.yahoo.vespa.orchestrator.status.StatusService) InMemoryStatusService(com.yahoo.vespa.orchestrator.status.InMemoryStatusService) 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) ReadOnlyStatusRegistry(com.yahoo.vespa.orchestrator.status.ReadOnlyStatusRegistry) ClusterControllerClientFactory(com.yahoo.vespa.orchestrator.controller.ClusterControllerClientFactory) HostName(com.yahoo.vespa.applicationmodel.HostName) Test(org.junit.Test)

Example 7 with ApplicationInstanceReference

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

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

the class OrchestratorUtil method parseAppInstanceReference.

/**
 * Returns an ApplicationInstanceReference constructed from the serialized format used in the REST API.
 */
public static ApplicationInstanceReference parseAppInstanceReference(String restFormat) {
    if (restFormat == null) {
        throw new IllegalArgumentException("Could not construct instance id from null string");
    }
    Matcher matcher = APPLICATION_INSTANCE_REFERENCE_REST_FORMAT_PATTERN.matcher(restFormat);
    if (!matcher.matches()) {
        throw new IllegalArgumentException("Could not construct instance id from string \"" + restFormat + "\"");
    }
    TenantId tenantId = new TenantId(matcher.group(1));
    ApplicationInstanceId applicationInstanceId = new ApplicationInstanceId(matcher.group(2));
    return new ApplicationInstanceReference(tenantId, applicationInstanceId);
}
Also used : ApplicationInstanceId(com.yahoo.vespa.applicationmodel.ApplicationInstanceId) TenantId(com.yahoo.vespa.applicationmodel.TenantId) Matcher(java.util.regex.Matcher) ApplicationInstanceReference(com.yahoo.vespa.applicationmodel.ApplicationInstanceReference)

Example 9 with ApplicationInstanceReference

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

the class ZookeeperStatusService method getAllSuspendedApplications.

@Override
public Set<ApplicationInstanceReference> getAllSuspendedApplications() {
    try {
        Set<ApplicationInstanceReference> resultSet = new HashSet<>();
        // Return empty set if the base path does not exist
        Stat stat = curator.framework().checkExists().forPath(APPLICATION_STATUS_BASE_PATH);
        if (stat == null)
            return resultSet;
        // The path exist and we may have children
        for (String appRefStr : curator.framework().getChildren().forPath(APPLICATION_STATUS_BASE_PATH)) {
            ApplicationInstanceReference appRef = OrchestratorUtil.parseAppInstanceReference(appRefStr);
            resultSet.add(appRef);
        }
        return resultSet;
    } catch (Exception e) {
        log.log(LogLevel.DEBUG, "Something went wrong while listing out applications in suspend.", e);
        throw new RuntimeException(e);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) ApplicationInstanceReference(com.yahoo.vespa.applicationmodel.ApplicationInstanceReference) TimeoutException(java.util.concurrent.TimeoutException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) HashSet(java.util.HashSet)

Example 10 with ApplicationInstanceReference

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

Aggregations

ApplicationInstanceReference (com.yahoo.vespa.applicationmodel.ApplicationInstanceReference)17 ApplicationInstance (com.yahoo.vespa.applicationmodel.ApplicationInstance)10 HostName (com.yahoo.vespa.applicationmodel.HostName)6 ClusterId (com.yahoo.vespa.applicationmodel.ClusterId)5 ConfigId (com.yahoo.vespa.applicationmodel.ConfigId)5 ServiceType (com.yahoo.vespa.applicationmodel.ServiceType)5 Test (org.junit.Test)5 ApplicationId (com.yahoo.config.provision.ApplicationId)4 ApplicationInstanceId (com.yahoo.vespa.applicationmodel.ApplicationInstanceId)4 TenantId (com.yahoo.vespa.applicationmodel.TenantId)4 ServiceCluster (com.yahoo.vespa.applicationmodel.ServiceCluster)3 ServiceInstance (com.yahoo.vespa.applicationmodel.ServiceInstance)3 ServiceModel (com.yahoo.vespa.service.monitor.ServiceModel)3 HashMap (java.util.HashMap)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 SuperModel (com.yahoo.config.model.api.SuperModel)2 Zone (com.yahoo.config.provision.Zone)2 OrchestratorUtil.getHostsUsedByApplicationInstance (com.yahoo.vespa.orchestrator.OrchestratorUtil.getHostsUsedByApplicationInstance)2