public AppRegistry(UriRegistry uriRegistry, ResourceLoader resourceLoader, EavRegistryRepository eavRegistryRepository) { this.uriRegistry = uriRegistry; this.uriRegistryPopulator = new UriRegistryPopulator(); this.uriRegistryPopulator.setResourceLoader(resourceLoader); this.resourceLoader = resourceLoader; this.eavRegistryRepository = eavRegistryRepository; }
private URI metadataUriFromRegistry(String key) { try { return uriRegistry.find(metadataKey(key)); } catch (IllegalArgumentException ignored) { return null; } }
public List<AppRegistration> findAll() { List<AppRegistration> apps = new ArrayList<>(); for (Map.Entry<String, URI> entry : this.uriRegistry.findAll().entrySet()) { apps.add(createAppRegistration(entry.getKey(), entry.getValue())); } return apps; }
/** * Deletes an {@link AppRegistration}. If the {@link AppRegistration} does not exist, a * {@link NoSuchAppRegistrationException} will be thrown. * * @param name Name of the AppRegistration to delete * @param type Type of the AppRegistration to delete */ public void delete(String name, ApplicationType type) { if (this.find(name, type) != null) { this.uriRegistry.unregister(key(name, type)); this.uriRegistry.unregister(metadataKey(name, type)); } else { throw new NoSuchAppRegistrationException(name, type); } }
public List<AppRegistration> importAll(boolean overwrite, String... resourceUris) { List<AppRegistration> apps = new ArrayList<>(); for (String uri : resourceUris) { try { Map<String, URI> registered = this.uriRegistryPopulator.populateRegistry( overwrite, this.uriRegistry, uri); for (Map.Entry<String, URI> entry : registered.entrySet()) { apps.add(createAppRegistration(entry.getKey(), entry.getValue())); } } catch (Exception e) { throw new IllegalStateException("Error when registering applications from " + uri + ": " + e.getMessage(), e); } } return apps; }
public AppRegistration find(String name, String type) { try { URI uri = this.uriRegistry.find(key(name, type)); return new AppRegistration(name, type, uri, this.resourceLoader); } catch (IllegalArgumentException e) { return null; } }
public AppRegistration save(String name, String type, URI uri) { this.uriRegistry.register(key(name, type), uri); this.eavRegistryRepository.save("spring-cloud-deployer-admin-app-" + name, "type", type); return new AppRegistration(name, type, uri, this.resourceLoader); }
@Override protected boolean isOverwrite(AppRegistration app, boolean overwrite) { if (overwrite) { return true; } return !uriRegistry.findAll().keySet().contains(key(app.getName(), app.getType())); }
/** * Deletes an {@link AppRegistration}. If the {@link AppRegistration} does not * exist, a {@link NoSuchAppRegistrationException} will be thrown. * * @param name Name of the AppRegistration to delete * @param type Type of the AppRegistration to delete */ public void delete(String name, String type) { if (this.find(name, type) != null) { this.uriRegistry.unregister(key(name, type)); } else { throw new NoSuchAppRegistrationException(name, type); } }
public AppRegistration find(String name, ApplicationType type) { try { String key = key(name, type); URI uri = this.uriRegistry.find(key); URI metadataUri = metadataUriFromRegistry(key); return new AppRegistration(name, type, uri, metadataUri); } catch (IllegalArgumentException e) { return null; // ignore and treat as not found } }
@Override public List<AppRegistration> findAll() { return this.uriRegistry.findAll().entrySet().stream() .flatMap(kv -> toValidAppRegistration(kv, metadataUriFromRegistry(kv.getKey()))) .sorted((a, b) -> a.compareTo(b)) .collect(Collectors.toList()); }