use of com.yahoo.vespa.hosted.controller.application.ClusterInfo in project vespa by vespa-engine.
the class ApplicationSerializerTest method createClusterInfo.
private Map<ClusterSpec.Id, ClusterInfo> createClusterInfo(int clusters, int hosts) {
Map<ClusterSpec.Id, ClusterInfo> result = new HashMap<>();
for (int cluster = 0; cluster < clusters; cluster++) {
List<String> hostnames = new ArrayList<>();
for (int host = 0; host < hosts; host++) {
hostnames.add("hostname" + cluster * host + host);
}
result.put(ClusterSpec.Id.from("id" + cluster), new ClusterInfo("flavor" + cluster, 10, 2, 4, 50, ClusterSpec.Type.content, hostnames));
}
return result;
}
use of com.yahoo.vespa.hosted.controller.application.ClusterInfo in project vespa by vespa-engine.
the class ClusterInfoMaintainer method getClusterInfo.
private Map<ClusterSpec.Id, ClusterInfo> getClusterInfo(NodeList nodes, ZoneId zone) {
Map<ClusterSpec.Id, ClusterInfo> infoMap = new HashMap<>();
// Group nodes by clusterid
Map<String, List<NodeRepositoryNode>> clusters = nodes.nodes().stream().filter(node -> node.getMembership() != null).collect(Collectors.groupingBy(ClusterInfoMaintainer::clusterid));
// For each cluster - get info
for (String id : clusters.keySet()) {
List<NodeRepositoryNode> clusterNodes = clusters.get(id);
// Assume they are all equal and use first node as a representative for the cluster
NodeRepositoryNode node = clusterNodes.get(0);
// Extract flavor info
double cpu = 0;
double mem = 0;
double disk = 0;
// TODO: This code was never run. Reenable when flavours are available from a FlavorRegistry or something, or remove.
/*if (zone.nodeFlavors().isPresent()) {
Optional<Flavor> flavorOptional = zone.nodeFlavors().get().getFlavor(node.flavor);
if ((flavorOptional.isPresent())) {
Flavor flavor = flavorOptional.get();
cpu = flavor.getMinCpuCores();
mem = flavor.getMinMainMemoryAvailableGb();
disk = flavor.getMinMainMemoryAvailableGb();
}
}*/
// Add to map
List<String> hostnames = clusterNodes.stream().map(NodeRepositoryNode::getHostname).collect(Collectors.toList());
ClusterInfo inf = new ClusterInfo(node.getFlavor(), node.getCost(), cpu, mem, disk, ClusterSpec.Type.from(node.getMembership().clustertype), hostnames);
infoMap.put(new ClusterSpec.Id(id), inf);
}
return infoMap;
}
use of com.yahoo.vespa.hosted.controller.application.ClusterInfo in project vespa by vespa-engine.
the class ClusterInfoMaintainer method maintain.
@Override
protected void maintain() {
for (Application application : ApplicationList.from(controller().applications().asList()).notPullRequest().asList()) {
for (Deployment deployment : application.deployments().values()) {
DeploymentId deploymentId = new DeploymentId(application.id(), deployment.zone());
try {
NodeList nodes = controller.nodeRepositoryClient().listNodes(deploymentId.zoneId(), deploymentId.applicationId().tenant().value(), deploymentId.applicationId().application().value(), deploymentId.applicationId().instance().value());
Map<ClusterSpec.Id, ClusterInfo> clusterInfo = getClusterInfo(nodes, deployment.zone());
controller().applications().lockIfPresent(application.id(), lockedApplication -> controller.applications().store(lockedApplication.withClusterInfo(deployment.zone(), clusterInfo)));
} catch (IOException | IllegalArgumentException e) {
log.log(Level.WARNING, "Failing getting cluster info of for " + deploymentId, e);
}
}
}
}
use of com.yahoo.vespa.hosted.controller.application.ClusterInfo in project vespa by vespa-engine.
the class ApplicationApiTest method setDeploymentMaintainedInfo.
/**
* Cluster info, utilization and application and deployment metrics are maintained async by maintainers.
*
* This sets these values as if the maintainers has been ran.
*
* @param controllerTester
*/
private void setDeploymentMaintainedInfo(ContainerControllerTester controllerTester) {
for (Application application : controllerTester.controller().applications().asList()) {
controllerTester.controller().applications().lockOrThrow(application.id(), lockedApplication -> {
lockedApplication = lockedApplication.with(new ApplicationMetrics(0.5, 0.7));
for (Deployment deployment : application.deployments().values()) {
Map<ClusterSpec.Id, ClusterInfo> clusterInfo = new HashMap<>();
List<String> hostnames = new ArrayList<>();
hostnames.add("host1");
hostnames.add("host2");
clusterInfo.put(ClusterSpec.Id.from("cluster1"), new ClusterInfo("flavor1", 37, 2, 4, 50, ClusterSpec.Type.content, hostnames));
Map<ClusterSpec.Id, ClusterUtilization> clusterUtils = new HashMap<>();
clusterUtils.put(ClusterSpec.Id.from("cluster1"), new ClusterUtilization(0.3, 0.6, 0.4, 0.3));
DeploymentMetrics metrics = new DeploymentMetrics(1, 2, 3, 4, 5);
lockedApplication = lockedApplication.withClusterInfo(deployment.zone(), clusterInfo).withClusterUtilization(deployment.zone(), clusterUtils).with(deployment.zone(), metrics);
}
controllerTester.controller().applications().store(lockedApplication);
});
}
}
Aggregations