Search in sources :

Example 16 with HostName

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);
}
Also used : PatchHostResponse(com.yahoo.vespa.orchestrator.restapi.wire.PatchHostResponse) PatchHostRequest(com.yahoo.vespa.orchestrator.restapi.wire.PatchHostRequest) Orchestrator(com.yahoo.vespa.orchestrator.Orchestrator) HostName(com.yahoo.vespa.applicationmodel.HostName) Test(org.junit.Test)

Example 17 with HostName

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);
}
Also used : ServiceCluster(com.yahoo.vespa.applicationmodel.ServiceCluster) ClusterId(com.yahoo.vespa.applicationmodel.ClusterId) ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) Host(com.yahoo.vespa.orchestrator.Host) Orchestrator(com.yahoo.vespa.orchestrator.Orchestrator) URI(java.net.URI) ApplicationInstanceId(com.yahoo.vespa.applicationmodel.ApplicationInstanceId) TenantId(com.yahoo.vespa.applicationmodel.TenantId) GetHostResponse(com.yahoo.vespa.orchestrator.restapi.wire.GetHostResponse) ServiceType(com.yahoo.vespa.applicationmodel.ServiceType) ApplicationInstanceReference(com.yahoo.vespa.applicationmodel.ApplicationInstanceReference) ConfigId(com.yahoo.vespa.applicationmodel.ConfigId) UriBuilder(javax.ws.rs.core.UriBuilder) HostName(com.yahoo.vespa.applicationmodel.HostName) Test(org.junit.Test)

Example 18 with HostName

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);
    }
}
Also used : HostStateChangeDeniedException(com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException) ClusterControllerStateResponse(com.yahoo.vespa.orchestrator.controller.ClusterControllerStateResponse) ClusterControllerClient(com.yahoo.vespa.orchestrator.controller.ClusterControllerClient) ConfigId(com.yahoo.vespa.applicationmodel.ConfigId) IOException(java.io.IOException) HostName(com.yahoo.vespa.applicationmodel.HostName)

Example 19 with HostName

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)");
    }
}
Also used : ClusterApi(com.yahoo.vespa.orchestrator.model.ClusterApi) ApplicationInstanceStatus(com.yahoo.vespa.orchestrator.status.ApplicationInstanceStatus) StorageNode(com.yahoo.vespa.orchestrator.model.StorageNode) HostName(com.yahoo.vespa.applicationmodel.HostName)

Example 20 with HostName

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();
}
Also used : BatchHostStateChangeDeniedException(com.yahoo.vespa.orchestrator.policy.BatchHostStateChangeDeniedException) HostStateChangeDeniedException(com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException) InOrder(org.mockito.InOrder) BatchHostStateChangeDeniedException(com.yahoo.vespa.orchestrator.policy.BatchHostStateChangeDeniedException) HostName(com.yahoo.vespa.applicationmodel.HostName) Test(org.junit.Test)

Aggregations

HostName (com.yahoo.vespa.applicationmodel.HostName)46 Test (org.junit.Test)20 ApplicationInstance (com.yahoo.vespa.applicationmodel.ApplicationInstance)14 ServiceType (com.yahoo.vespa.applicationmodel.ServiceType)13 ServiceCluster (com.yahoo.vespa.applicationmodel.ServiceCluster)9 ServiceInstance (com.yahoo.vespa.applicationmodel.ServiceInstance)9 ClusterId (com.yahoo.vespa.applicationmodel.ClusterId)8 HostStatus (com.yahoo.vespa.orchestrator.status.HostStatus)8 List (java.util.List)8 ApplicationId (com.yahoo.config.provision.ApplicationId)7 ApplicationInstanceReference (com.yahoo.vespa.applicationmodel.ApplicationInstanceReference)7 Orchestrator (com.yahoo.vespa.orchestrator.Orchestrator)7 Collectors (java.util.stream.Collectors)7 ApplicationInstanceId (com.yahoo.vespa.applicationmodel.ApplicationInstanceId)6 ConfigId (com.yahoo.vespa.applicationmodel.ConfigId)6 TenantId (com.yahoo.vespa.applicationmodel.TenantId)6 ServiceStatus (com.yahoo.vespa.applicationmodel.ServiceStatus)5 OrchestrationException (com.yahoo.vespa.orchestrator.OrchestrationException)5 StorageNode (com.yahoo.vespa.orchestrator.model.StorageNode)5 IOException (java.io.IOException)5