/** * Loads the application bindings into an application. * @param app a non-null application * @param configurationDirectory the DM's configuration directory */ public static void loadApplicationBindings( Application app ) { File descDir = new File( app.getDirectory(), Constants.PROJECT_DIR_DESC ); File appBindingsFile = new File( descDir, APP_BINDINGS_FILE ); Logger logger = Logger.getLogger( ConfigurationUtils.class.getName()); Properties props = Utils.readPropertiesFileQuietly( appBindingsFile, logger ); for( Map.Entry<?,?> entry : props.entrySet()) { for( String part : Utils.splitNicely((String) entry.getValue(), "," )) { if( ! Utils.isEmptyOrWhitespaces( part )) app.bindWithApplication((String) entry.getKey(), part ); } } }
@Override public void bindOrUnbindApplication( ManagedApplication ma, String externalExportPrefix, String applicationName, boolean bind ) throws UnauthorizedActionException, IOException { // Checks Application app = findApplicationByName( applicationName ); if( app == null ) throw new UnauthorizedActionException( "Application " + applicationName + " does not exist." ); if( ! externalExportPrefix.equals( app.getTemplate().getExternalExportsPrefix())) throw new UnauthorizedActionException( "Application " + applicationName + "'s template does not have " + externalExportPrefix + " as external exports prefix." ); // Update the model boolean notify = true; if( bind ) ma.getApplication().bindWithApplication( externalExportPrefix, applicationName ); else notify = ma.getApplication().unbindFromApplication( externalExportPrefix, applicationName ); // Update and propagate the modification if( notify ) { // Save the configuration ConfigurationUtils.saveApplicationBindings( ma.getApplication()); this.logger.fine( "External prefix " + externalExportPrefix + " is now bound to application " + applicationName + " in " + ma.getName() + "." ); // Notify the agents for( Instance inst : InstanceHelpers.findAllScopedInstances( ma.getApplication())) { MsgCmdChangeBinding msg = new MsgCmdChangeBinding( externalExportPrefix, ma.getApplication().getApplicationBindings().get( externalExportPrefix )); this.messagingMngr.sendMessageSafely( ma, inst, msg ); } } }