com.yahoo.config.model.api.SuperModel Maven / Gradle / Ivy
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.model.api;
import com.google.common.collect.ImmutableMap;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.TenantName;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
/**
* The SuperModel contains the ApplicationInfo of all active applications
*/
public class SuperModel {
private final Map models;
private final boolean complete;
public SuperModel() {
this(Map.of(), false);
}
public SuperModel(Map models, boolean complete) {
this.models = models;
this.complete = complete;
}
public Map> getModelsPerTenant() {
Map> newModels = new LinkedHashMap<>();
this.models.forEach((key, value) -> {
if (!newModels.containsKey(key.tenant())) {
newModels.put(key.tenant(), new LinkedHashSet<>());
}
newModels.get(key.tenant()).add(value);
});
return newModels;
}
public Map getModels() {
return ImmutableMap.copyOf(models);
}
public boolean isComplete() { return complete; }
public List getAllApplicationInfos() {
return new ArrayList<>(models.values());
}
public Optional getApplicationInfo(ApplicationId applicationId) {
ApplicationInfo applicationInfo = models.get(applicationId);
return applicationInfo == null ? Optional.empty() : Optional.of(applicationInfo);
}
public SuperModel cloneAndSetApplication(ApplicationInfo application) {
Map newModels = cloneModels(models);
newModels.put(application.getApplicationId(), application);
return new SuperModel(newModels, complete);
}
public SuperModel cloneAndRemoveApplication(ApplicationId applicationId) {
Map newModels = cloneModels(models);
newModels.remove(applicationId);
return new SuperModel(newModels, complete);
}
public SuperModel cloneAsComplete() { return new SuperModel(models, true); }
public Set getApplicationIds() { return models.keySet(); }
private static Map cloneModels(Map models) {
return new LinkedHashMap<>(models);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy