use of org.bf2.srs.fleetmanager.rest.service.model.RegistryDeploymentsConfigList in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class RegistryDeploymentServiceImpl method init.
@Override
public void init() throws IOException, RegistryDeploymentStorageConflictException, RegistryDeploymentNotFoundException {
if (deploymentsConfigFile.isEmpty()) {
return;
}
log.info("Loading registry deployments config file from {}", deploymentsConfigFile.get().getAbsolutePath());
YAMLMapper mapper = new YAMLMapper();
RegistryDeploymentsConfigList deploymentsConfigList = mapper.readValue(deploymentsConfigFile.get(), RegistryDeploymentsConfigList.class);
List<RegistryDeploymentCreate> staticDeployments = deploymentsConfigList.getDeployments();
Set<String> names = new HashSet<>();
List<String> duplicatedNames = staticDeployments.stream().map(d -> {
Set<ConstraintViolation<RegistryDeploymentCreate>> 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 deployments config, duplicated deployments name: " + duplicatedNames.toString());
}
Map<String, RegistryDeploymentData> currentDeployments = storage.getAllRegistryDeployments().stream().collect(Collectors.toMap(d -> d.getName(), d -> d));
for (RegistryDeploymentCreate dep : staticDeployments) {
RegistryDeploymentData deploymentData = currentDeployments.get(dep.getName());
if (deploymentData == null) {
// deployment is new
deploymentData = convertRegistryDeployment.convert(dep);
} else {
if (deploymentData.getRegistryDeploymentUrl().equals(dep.getRegistryDeploymentUrl()) && deploymentData.getTenantManagerUrl().equals(dep.getTenantManagerUrl())) {
// no changes in the deployment
continue;
}
deploymentData.setRegistryDeploymentUrl(dep.getRegistryDeploymentUrl());
deploymentData.setTenantManagerUrl(dep.getTenantManagerUrl());
}
createOrUpdateRegistryDeployment(deploymentData);
}
}
Aggregations