Search in sources :

Example 1 with RegistryDeploymentsConfigList

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);
    }
}
Also used : RegistryDeployment(org.bf2.srs.fleetmanager.rest.service.model.RegistryDeployment) RegistryDeploymentNotFoundException(org.bf2.srs.fleetmanager.storage.RegistryDeploymentNotFoundException) RegistryDeploymentData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryDeploymentData) KEY_DEPLOYMENT_ID(org.bf2.srs.fleetmanager.common.operation.auditing.AuditingConstants.KEY_DEPLOYMENT_ID) LoggerFactory(org.slf4j.LoggerFactory) RegistryDeploymentStorageConflictException(org.bf2.srs.fleetmanager.storage.RegistryDeploymentStorageConflictException) Audited(org.bf2.srs.fleetmanager.common.operation.auditing.Audited) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Valid(javax.validation.Valid) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) RegistryDeploymentCreate(org.bf2.srs.fleetmanager.rest.service.model.RegistryDeploymentCreate) ResourceStorage(org.bf2.srs.fleetmanager.storage.ResourceStorage) Map(java.util.Map) ConstraintViolation(javax.validation.ConstraintViolation) RegistryDeploymentStatusValue(org.bf2.srs.fleetmanager.rest.service.model.RegistryDeploymentStatusValue) ConvertRegistryDeployment(org.bf2.srs.fleetmanager.rest.service.convert.ConvertRegistryDeployment) Logger(org.slf4j.Logger) ForbiddenException(javax.ws.rs.ForbiddenException) Set(java.util.Set) Validator(javax.validation.Validator) IOException(java.io.IOException) RegistryDeploymentsConfigList(org.bf2.srs.fleetmanager.rest.service.model.RegistryDeploymentsConfigList) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ConstraintViolationException(javax.validation.ConstraintViolationException) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) RegistryDeploymentService(org.bf2.srs.fleetmanager.rest.service.RegistryDeploymentService) HashSet(java.util.HashSet) Set(java.util.Set) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) RegistryDeploymentData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryDeploymentData) RegistryDeploymentsConfigList(org.bf2.srs.fleetmanager.rest.service.model.RegistryDeploymentsConfigList) ConstraintViolationException(javax.validation.ConstraintViolationException) RegistryDeploymentCreate(org.bf2.srs.fleetmanager.rest.service.model.RegistryDeploymentCreate) HashSet(java.util.HashSet)

Aggregations

YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)1 File (java.io.File)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 ConstraintViolation (javax.validation.ConstraintViolation)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 Valid (javax.validation.Valid)1 Validator (javax.validation.Validator)1 ForbiddenException (javax.ws.rs.ForbiddenException)1 Audited (org.bf2.srs.fleetmanager.common.operation.auditing.Audited)1 KEY_DEPLOYMENT_ID (org.bf2.srs.fleetmanager.common.operation.auditing.AuditingConstants.KEY_DEPLOYMENT_ID)1 RegistryDeploymentService (org.bf2.srs.fleetmanager.rest.service.RegistryDeploymentService)1