use of com.yahoo.vespa.applicationmodel.HostName 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.HostName in project vespa by vespa-engine.
the class OrchestratorImpl method setClusterStateInController.
private void setClusterStateInController(ApplicationInstance application, ClusterControllerNodeState state) throws ApplicationStateChangeDeniedException, ApplicationIdNotFoundException {
// Get all content clusters for this application
Set<ClusterId> contentClusterIds = application.serviceClusters().stream().filter(VespaModelUtil::isContent).map(ServiceCluster::clusterId).collect(Collectors.toSet());
// For all content clusters set in maintenance
log.log(LogLevel.INFO, String.format("Setting content clusters %s for application %s to %s", contentClusterIds, application.applicationInstanceId(), state));
for (ClusterId clusterId : contentClusterIds) {
List<HostName> clusterControllers = VespaModelUtil.getClusterControllerInstancesInOrder(application, clusterId);
ClusterControllerClient client = clusterControllerClientFactory.createClient(clusterControllers, clusterId.s());
try {
ClusterControllerStateResponse response = client.setApplicationState(state);
if (!response.wasModified) {
String msg = String.format("Fail to set application %s, cluster name %s to cluster state %s due to: %s", application.applicationInstanceId(), clusterId, state, response.reason);
throw new ApplicationStateChangeDeniedException(msg);
}
} catch (IOException e) {
throw new ApplicationStateChangeDeniedException(e.getMessage());
}
}
}
use of com.yahoo.vespa.applicationmodel.HostName in project vespa by vespa-engine.
the class HostSuspensionResource method suspendAll.
@Override
public BatchOperationResult suspendAll(String parentHostnameString, List<String> hostnamesAsStrings) {
HostName parentHostname = new HostName(parentHostnameString);
List<HostName> hostnames = hostnamesAsStrings.stream().map(HostName::new).collect(Collectors.toList());
try {
orchestrator.suspendAll(parentHostname, hostnames);
} catch (BatchHostStateChangeDeniedException e) {
log.log(LogLevel.DEBUG, "Failed to suspend nodes " + hostnames + " with parent host " + parentHostname, e);
throw createWebApplicationException(e.getMessage(), Response.Status.CONFLICT);
} catch (BatchHostNameNotFoundException e) {
log.log(LogLevel.DEBUG, "Failed to suspend nodes " + hostnames + " with parent host " + parentHostname, e);
// by the URL path was found. It's one of the hostnames in the request it failed to find.
throw createWebApplicationException(e.getMessage(), Response.Status.BAD_REQUEST);
} catch (BatchInternalErrorException e) {
log.log(LogLevel.DEBUG, "Failed to suspend nodes " + hostnames + " with parent host " + parentHostname, e);
throw createWebApplicationException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR);
}
log.log(LogLevel.DEBUG, "Suspended " + hostnames + " with parent " + parentHostname);
return BatchOperationResult.successResult();
}
use of com.yahoo.vespa.applicationmodel.HostName 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;
}
use of com.yahoo.vespa.applicationmodel.HostName 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;
}
Aggregations