use of org.bf2.srs.fleetmanager.service.model.QuotaPlan in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class FileQuotaPlansService method init.
@Override
public void init() throws IOException {
log.debug("Using FileQuotaPlansService implementation of QuotaPlansService");
if (plansConfigFile.isEmpty()) {
throw new IllegalArgumentException("Error in static quota plans config: Property 'registry.quota.plans.config.file' is required.");
}
log.info("Loading registry quota plans config file from {}", plansConfigFile.get().getAbsolutePath());
YAMLMapper mapper = SerDesObjectMapperProducer.getYAMLMapper();
QuotaPlansConfigList quotaPlansConfigList = mapper.readValue(plansConfigFile.get(), QuotaPlansConfigList.class);
List<QuotaPlan> staticQuotaPlans = quotaPlansConfigList.getPlans();
Set<String> names = new HashSet<>();
List<String> duplicatedNames = staticQuotaPlans.stream().map(d -> {
Set<ConstraintViolation<QuotaPlan>> errors = validator.validate(d);
if (!errors.isEmpty()) {
throw new ConstraintViolationException(errors);
}
return d;
}).filter(d -> !names.add(d.getName())).map(d -> d.getName()).collect(Collectors.toList());
if (!duplicatedNames.isEmpty()) {
throw new IllegalArgumentException("Error in static quota plans config, duplicated plan name: " + duplicatedNames.toString());
}
if (!names.contains(defaultQuotaPlan)) {
throw new IllegalArgumentException("Error in static quota plans config, default plan does not exist in plans config, default plan name: " + defaultQuotaPlan);
}
for (QuotaPlan p : staticQuotaPlans) {
tmClient.validateConfig(p.getResources());
plans.put(p.getName(), p);
}
List<OrganizationAssignment> staticOrganizationAssignments = quotaPlansConfigList.getOrganizations();
if (staticOrganizationAssignments == null)
staticOrganizationAssignments = Collections.emptyList();
for (OrganizationAssignment assignment : staticOrganizationAssignments) {
if (!plans.containsKey(assignment.getPlan())) {
throw new IllegalStateException("Could not find quota plan named '" + assignment.getPlan() + "' intended for organization ID '" + assignment.getOrgId() + "'");
}
organizationAssignments.put(assignment.getOrgId(), assignment);
}
if (quotaPlansConfigList.getReconcile() != null && quotaPlansConfigList.getReconcile()) {
reconcile();
}
}
Aggregations