use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.
the class HostResourceTest method patch_works.
@Test
public void patch_works() throws OrchestrationException {
Orchestrator orchestrator = mock(Orchestrator.class);
HostResource hostResource = new HostResource(orchestrator, uriInfo);
String hostNameString = "hostname";
PatchHostRequest request = new PatchHostRequest();
request.state = "NO_REMARKS";
PatchHostResponse response = hostResource.patch(hostNameString, request);
assertEquals(response.description, "ok");
verify(orchestrator, times(1)).setNodeStatus(new HostName(hostNameString), HostStatus.NO_REMARKS);
}
use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.
the class HostResourceTest method getHost_works.
@Test
public void getHost_works() throws Exception {
Orchestrator orchestrator = mock(Orchestrator.class);
HostResource hostResource = new HostResource(orchestrator, uriInfo);
HostName hostName = new HostName("hostname");
UriBuilder baseUriBuilder = mock(UriBuilder.class);
when(uriInfo.getBaseUriBuilder()).thenReturn(baseUriBuilder);
when(baseUriBuilder.path(any(String.class))).thenReturn(baseUriBuilder);
when(baseUriBuilder.path(any(Class.class))).thenReturn(baseUriBuilder);
URI uri = new URI("https://foo.com/bar");
when(baseUriBuilder.build()).thenReturn(uri);
ServiceInstance serviceInstance = new ServiceInstance(new ConfigId("configId"), hostName, ServiceStatus.UP);
ServiceCluster serviceCluster = new ServiceCluster(new ClusterId("clusterId"), new ServiceType("serviceType"), Collections.singleton(serviceInstance));
serviceInstance.setServiceCluster(serviceCluster);
Host host = new Host(hostName, HostStatus.ALLOWED_TO_BE_DOWN, new ApplicationInstanceReference(new TenantId("tenantId"), new ApplicationInstanceId("applicationId")), Collections.singletonList(serviceInstance));
when(orchestrator.getHost(hostName)).thenReturn(host);
GetHostResponse response = hostResource.getHost(hostName.s());
assertEquals("https://foo.com/bar", response.applicationUrl());
assertEquals("hostname", response.hostname());
assertEquals("ALLOWED_TO_BE_DOWN", response.state());
assertEquals(1, response.services().size());
assertEquals("clusterId", response.services().get(0).clusterId);
assertEquals("configId", response.services().get(0).configId);
assertEquals("UP", response.services().get(0).serviceStatus);
assertEquals("serviceType", response.services().get(0).serviceType);
}
use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.
the class StorageNodeImpl method setNodeState.
@Override
public void setNodeState(ClusterControllerNodeState wantedNodeState) throws HostStateChangeDeniedException {
// The "cluster name" used by the Cluster Controller IS the cluster ID.
String clusterId = this.clusterId.s();
List<HostName> clusterControllers = VespaModelUtil.getClusterControllerInstancesInOrder(applicationInstance, this.clusterId);
ClusterControllerClient client = clusterControllerClientFactory.createClient(clusterControllers, clusterId);
ConfigId configId = storageService.configId();
int nodeIndex = VespaModelUtil.getStorageNodeIndex(configId);
logger.log(LogLevel.DEBUG, () -> "Setting cluster controller state for " + "application " + applicationInstance.reference().asString() + ", host " + hostName() + ", cluster name " + clusterId + ", node index " + nodeIndex + ", node state " + wantedNodeState);
ClusterControllerStateResponse response;
try {
response = client.setNodeState(nodeIndex, wantedNodeState);
} catch (IOException e) {
throw new HostStateChangeDeniedException(hostName(), HostedVespaPolicy.CLUSTER_CONTROLLER_AVAILABLE_CONSTRAINT, "Failed to communicate with cluster controllers " + clusterControllers + ": " + e, e);
}
if (!response.wasModified) {
throw new HostStateChangeDeniedException(hostName(), HostedVespaPolicy.SET_NODE_STATE_CONSTRAINT, "Failed to set state to " + wantedNodeState + " in cluster controller: " + response.reason);
}
}
use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.
the class HostedVespaPolicy method acquirePermissionToRemove.
@Override
public void acquirePermissionToRemove(ApplicationApi applicationApi) throws HostStateChangeDeniedException {
ApplicationInstanceStatus applicationStatus = applicationApi.getApplicationStatus();
if (applicationStatus == ApplicationInstanceStatus.ALLOWED_TO_BE_DOWN) {
throw new HostStateChangeDeniedException(applicationApi.getNodeGroup(), HostedVespaPolicy.APPLICATION_SUSPENDED_CONSTRAINT, "Unable to test availability constraints as the application " + applicationApi.applicationId() + " is allowed to be down");
}
// Apply per-cluster policy
for (ClusterApi cluster : applicationApi.getClusters()) {
clusterPolicy.verifyGroupGoingDownPermanentlyIsFine(cluster);
}
// These storage nodes are guaranteed to be NO_REMARKS
for (StorageNode storageNode : applicationApi.getStorageNodesInGroupInClusterOrder()) {
storageNode.setNodeState(ClusterControllerNodeState.DOWN);
log.log(LogLevel.INFO, "The storage node on " + storageNode.hostName() + " has been set DOWN");
}
// Ensure all nodes in the group are marked as allowed to be down
for (HostName hostName : applicationApi.getNodesInGroupWithStatus(HostStatus.NO_REMARKS)) {
applicationApi.setHostState(hostName, HostStatus.ALLOWED_TO_BE_DOWN);
log.log(LogLevel.INFO, hostName + " is now allowed to be down (suspended)");
}
}
use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.
the class OrchestratorImplTest method whenSuspendAllFails.
@Test
public void whenSuspendAllFails() throws Exception {
// A spy is preferential because suspendAll() relies on delegating the hard work to suspend() and resume().
OrchestratorImpl orchestrator = spy(this.orchestrator);
Throwable supensionFailure = new HostStateChangeDeniedException(DummyInstanceLookupService.TEST6_HOST_NAME, "some-constraint", "error message");
doThrow(supensionFailure).when(orchestrator).suspendGroup(DummyInstanceLookupService.TEST6_NODE_GROUP);
try {
orchestrator.suspendAll(new HostName("parentHostname"), Arrays.asList(DummyInstanceLookupService.TEST1_HOST_NAME, DummyInstanceLookupService.TEST3_HOST_NAME, DummyInstanceLookupService.TEST6_HOST_NAME));
fail();
} catch (BatchHostStateChangeDeniedException e) {
assertEquals("Failed to suspend NodeGroup{application=tenant-id-3:application-instance-3:prod:utopia-1:default, " + "hostNames=[test6.hostname.tld]} with parent host parentHostname: " + "Changing the state of test6.hostname.tld would violate " + "some-constraint: error message", e.getMessage());
}
InOrder order = inOrder(orchestrator);
order.verify(orchestrator).suspendGroup(DummyInstanceLookupService.TEST3_NODE_GROUP);
order.verify(orchestrator).suspendGroup(DummyInstanceLookupService.TEST6_NODE_GROUP);
order.verifyNoMoreInteractions();
}
Aggregations