use of com.yahoo.vespa.applicationmodel.ApplicationInstance in project vespa by vespa-engine.
the class ApplicationApiImplTest method testGetClustersThatAreOnAtLeastOneNodeInGroup.
@Test
public void testGetClustersThatAreOnAtLeastOneNodeInGroup() {
HostName hostName1 = new HostName("host1");
HostName hostName2 = new HostName("host2");
HostName hostName3 = new HostName("host3");
HostName hostName4 = new HostName("host4");
ApplicationInstance applicationInstance = modelUtils.createApplicationInstance(Arrays.asList(modelUtils.createServiceCluster("cluster-3", new ServiceType("service-type-3"), Arrays.asList(modelUtils.createServiceInstance("config-id-1", hostName1, ServiceStatus.UP), modelUtils.createServiceInstance("config-id-2", hostName2, ServiceStatus.UP))), modelUtils.createServiceCluster("cluster-1", new ServiceType("service-type-1"), Arrays.asList(modelUtils.createServiceInstance("config-id-3", hostName1, ServiceStatus.UP), modelUtils.createServiceInstance("config-id-4", hostName3, ServiceStatus.UP))), modelUtils.createServiceCluster("cluster-2", new ServiceType("service-type-2"), Arrays.asList(modelUtils.createServiceInstance("config-id-5", hostName1, ServiceStatus.UP), modelUtils.createServiceInstance("config-id-6", hostName2, ServiceStatus.UP)))));
verifyClustersInOrder(modelUtils.createApplicationApiImpl(applicationInstance, hostName1), 1, 2, 3);
verifyClustersInOrder(modelUtils.createApplicationApiImpl(applicationInstance, hostName2), 2, 3);
verifyClustersInOrder(modelUtils.createApplicationApiImpl(applicationInstance, hostName3), 1);
verifyClustersInOrder(modelUtils.createApplicationApiImpl(applicationInstance, hostName4));
}
use of com.yahoo.vespa.applicationmodel.ApplicationInstance in project vespa by vespa-engine.
the class ApplicationApiImplTest method verifyUpConditionWith.
private void verifyUpConditionWith(HostStatus hostStatus, ServiceStatus serviceStatus, boolean expectUp) {
HostName hostName1 = modelUtils.createNode("host1", hostStatus);
ApplicationInstance applicationInstance = modelUtils.createApplicationInstance(Arrays.asList(modelUtils.createServiceCluster("cluster-1", VespaModelUtil.STORAGENODE_SERVICE_TYPE, Arrays.asList(modelUtils.createServiceInstance("config-id-1", hostName1, serviceStatus)))));
ApplicationApiImpl applicationApi = modelUtils.createApplicationApiImpl(applicationInstance, hostName1);
List<HostName> upStorageNodes = expectUp ? Arrays.asList(hostName1) : new ArrayList<>();
List<HostName> actualStorageNodes = applicationApi.getUpStorageNodesInGroupInClusterOrder().stream().map(storageNode -> storageNode.hostName()).collect(Collectors.toList());
assertEquals(upStorageNodes, actualStorageNodes);
}
use of com.yahoo.vespa.applicationmodel.ApplicationInstance 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());
}
use of com.yahoo.vespa.applicationmodel.ApplicationInstance in project vespa by vespa-engine.
the class OrchestratorImpl method resume.
@Override
public void resume(HostName hostName) throws HostStateChangeDeniedException, HostNameNotFoundException {
/*
* When making a state transition to this state, we have to consider that if the host has been in
* ALLOWED_TO_BE_DOWN state, services on the host may recently have been stopped (and, presumably, started).
* Service monitoring may not have had enough time to detect that services were stopped,
* and may therefore mistakenly report services as up, even if they still haven't initialized and
* are not yet ready for serving. Erroneously reporting both host and services as up causes a race
* where services on other hosts may be stopped prematurely. A delay here ensures that service
* monitoring will have had time to catch up. Since we don't want do the delay with the lock held,
* and the host status service's locking functionality does not support something like condition
* variables or Object.wait(), we break out here, releasing the lock before delaying.
*/
sleep(serviceMonitorConvergenceLatencySeconds, TimeUnit.SECONDS);
ApplicationInstance appInstance = getApplicationInstance(hostName);
try (MutableStatusRegistry statusRegistry = statusService.lockApplicationInstance_forCurrentThreadOnly(appInstance.reference())) {
final HostStatus currentHostState = statusRegistry.getHostStatus(hostName);
if (HostStatus.NO_REMARKS == currentHostState) {
return;
}
ApplicationInstanceStatus appStatus = statusService.forApplicationInstance(appInstance.reference()).getApplicationInstanceStatus();
if (appStatus == ApplicationInstanceStatus.NO_REMARKS) {
policy.releaseSuspensionGrant(appInstance, hostName, statusRegistry);
}
}
}
use of com.yahoo.vespa.applicationmodel.ApplicationInstance 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;
}
Aggregations