@PrePersist private void updateRedundantConfig() { // Checks to see if other SCs exist in the same partition and uses the same backend config if it // exists. if (this.blockStorageManager == null && this.getPartition() != null) { for (ServiceConfiguration s : ServiceConfigurations.listPartition(Storage.class, this.getPartition())) { StorageControllerConfiguration otherSc = (StorageControllerConfiguration) s; this.blockStorageManager = otherSc.getBlockStorageManager() != null ? otherSc.getBlockStorageManager() : null; } } }
@Override public boolean apply(Class arg0) { EntityTransaction db = Entities.get(StorageControllerConfiguration.class); try { // Get local IP addresses or host names Set<String> localAddresses = Internets.getAllLocalHostNamesIps(); List<StorageControllerConfiguration> entities = Entities.query(new StorageControllerConfiguration()); for (StorageControllerConfiguration entry : entities) { // This SC is running on the local machine, upgrade its block storage manager config if (localAddresses.contains(entry.getHostName())) { LOG.debug("Upgrading SC config " + entry.getPartition()); entry.setBlockStorageManager(loadLocalBlockStorageManagerConfig()); LOG.debug( "Set storage manager " + entry.getBlockStorageManager() + " for SC " + entry.getPartition()); break; } } db.commit(); return true; } catch (Exception ex) { db.rollback(); throw Exceptions.toUndeclared(ex); } }