@Test( expected = UnauthorizedActionException.class ) public void testDeleteApplication_unauthorized() throws Exception { TestApplication app = new TestApplication(); app.setDirectory( this.folder.newFolder()); ManagedApplication ma = new ManagedApplication( app ); TestManagerWrapper.addManagedApplication( this.mngr, ma ); app.getMySqlVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); this.mngr.deleteApplication( ma ); }
@Override public void deleteApplication( ManagedApplication ma ) throws UnauthorizedActionException, IOException { String applicationName = ma.getApplication().getName(); for( Instance rootInstance : ma.getApplication().getRootInstances()) { if( rootInstance.getStatus() != InstanceStatus.NOT_DEPLOYED ) throw new UnauthorizedActionException( applicationName + " contains instances that are still deployed." ); } try { this.messagingMngr.checkMessagingConfiguration(); this.messagingMngr.getMessagingClient().listenToAgentMessages( ma.getApplication(), ListenerCommand.STOP ); this.messagingMngr.getMessagingClient().deleteMessagingServerArtifacts( ma.getApplication()); } catch( IOException e ) { Utils.logException( this.logger, e ); } this.randomMngr.releaseAllRandomValues( ma.getApplication()); this.notificationMngr.application( ma.getApplication(), EventType.DELETED ); Application app = ma.getApplication(); this.targetsMngr.applicationWasDeleted( app ); this.autonomicMngr.unloadApplicationRules( app ); this.logger.info( "Deleting the application called " + app.getName() + "..." ); this.nameToManagedApplication.remove( app.getName()); app.removeAssociationWithTemplate(); File targetDirectory = ConfigurationUtils.findApplicationDirectory( app.getName(), this.configurationMngr.getWorkingDirectory()); Utils.deleteFilesRecursively( targetDirectory ); this.logger.info( "Application " + app.getName() + " was successfully deleted." ); }
ApplicationMngrImpl implements IApplicationMngr { @Override public void deleteApplication( ManagedApplication ma ) throws UnauthorizedActionException, IOException { String applicationName = ma.getApplication().getName(); for( Instance rootInstance : ma.getApplication().getRootInstances()) { if( rootInstance.getStatus() != InstanceStatus.NOT_DEPLOYED ) throw new UnauthorizedActionException( applicationName + " contains instances that are still deployed." ); } try { this.messagingMngr.checkMessagingConfiguration(); this.messagingMngr.getMessagingClient().listenToAgentMessages( ma.getApplication(), ListenerCommand.STOP ); this.messagingMngr.getMessagingClient().deleteMessagingServerArtifacts( ma.getApplication()); } catch( IOException e ) { Utils.logException( this.logger, e ); } this.randomMngr.releaseAllRandomValues( ma.getApplication()); this.notificationMngr.application( ma.getApplication(), EventType.DELETED ); Application app = ma.getApplication(); this.targetsMngr.applicationWasDeleted( app ); this.autonomicMngr.unloadApplicationRules( app ); this.logger.info( "Deleting the application called " + app.getName() + "..." ); this.nameToManagedApplication.remove( app.getName()); app.removeAssociationWithTemplate(); File targetDirectory = ConfigurationUtils.findApplicationDirectory( app.getName(), this.configurationMngr.getWorkingDirectory()); Utils.deleteFilesRecursively( targetDirectory ); this.logger.info( "Application " + app.getName() + " was successfully deleted." ); } }
ApplicationMngrImpl implements IApplicationMngr { @Override public void deleteApplication( ManagedApplication ma ) throws UnauthorizedActionException, IOException { String applicationName = ma.getApplication().getName(); for( Instance rootInstance : ma.getApplication().getRootInstances()) { if( rootInstance.getStatus() != InstanceStatus.NOT_DEPLOYED ) throw new UnauthorizedActionException( applicationName + " contains instances that are still deployed." ); } try { this.messagingMngr.checkMessagingConfiguration(); this.messagingMngr.getMessagingClient().listenToAgentMessages( ma.getApplication(), ListenerCommand.STOP ); this.messagingMngr.getMessagingClient().deleteMessagingServerArtifacts( ma.getApplication()); } catch( IOException e ) { Utils.logException( this.logger, e ); } this.randomMngr.releaseAllRandomValues( ma.getApplication()); this.notificationMngr.application( ma.getApplication(), EventType.DELETED ); Application app = ma.getApplication(); this.targetsMngr.applicationWasDeleted( app ); this.autonomicMngr.unloadApplicationRules( app ); this.logger.info( "Deleting the application called " + app.getName() + "..." ); this.nameToManagedApplication.remove( app.getName()); app.removeAssociationWithTemplate(); File targetDirectory = ConfigurationUtils.findApplicationDirectory( app.getName(), this.configurationMngr.getWorkingDirectory()); Utils.deleteFilesRecursively( targetDirectory ); this.logger.info( "Application " + app.getName() + " was successfully deleted." ); } ApplicationMngrImpl(
			INotificationMngr notificationMngr,
			IConfigurationMngr configurationMngr,
			ITargetsMngr targetsMngr,
			IMessagingMngr messagingMngr,
			IRandomMngr randomMngr,
			IAutonomicMngr autonomicMngr ); }
ApplicationMngrImpl implements IApplicationMngr { @Override public void deleteApplication( ManagedApplication ma ) throws UnauthorizedActionException, IOException { String applicationName = ma.getApplication().getName(); for( Instance rootInstance : ma.getApplication().getRootInstances()) { if( rootInstance.getStatus() != InstanceStatus.NOT_DEPLOYED ) throw new UnauthorizedActionException( applicationName + " contains instances that are still deployed." ); } try { this.messagingMngr.checkMessagingConfiguration(); this.messagingMngr.getMessagingClient().listenToAgentMessages( ma.getApplication(), ListenerCommand.STOP ); this.messagingMngr.getMessagingClient().deleteMessagingServerArtifacts( ma.getApplication()); } catch( IOException e ) { Utils.logException( this.logger, e ); } this.randomMngr.releaseAllRandomValues( ma.getApplication()); this.notificationMngr.application( ma.getApplication(), EventType.DELETED ); Application app = ma.getApplication(); this.targetsMngr.applicationWasDeleted( app ); this.autonomicMngr.unloadApplicationRules( app ); this.logger.info( "Deleting the application called " + app.getName() + "..." ); this.nameToManagedApplication.remove( app.getName()); app.removeAssociationWithTemplate(); File targetDirectory = ConfigurationUtils.findApplicationDirectory( app.getName(), this.configurationMngr.getWorkingDirectory()); Utils.deleteFilesRecursively( targetDirectory ); this.logger.info( "Application " + app.getName() + " was successfully deleted." ); } ApplicationMngrImpl(
			INotificationMngr notificationMngr,
			IConfigurationMngr configurationMngr,
			ITargetsMngr targetsMngr,
			IMessagingMngr messagingMngr,
			IRandomMngr randomMngr,
			IAutonomicMngr autonomicMngr ); void setApplicationTemplateMngr( IApplicationTemplateMngr applicationTemplateMngr ); @Override Application findApplicationByName( String applicationName ); @Override ManagedApplication findManagedApplicationByName( String applicationName ); @Override Collection<ManagedApplication> getManagedApplications(); @Override ManagedApplication createApplication( String name, String description, String tplName, String tplQualifier ); @Override ManagedApplication createApplication( String name, String description, ApplicationTemplate tpl ); @Override void updateApplication( ManagedApplication ma, String newDesc ); @Override void deleteApplication( ManagedApplication ma ); @Override void restoreApplications(); @Override boolean isTemplateUsed( ApplicationTemplate tpl ); @Override void bindOrUnbindApplication( ManagedApplication ma, String externalExportPrefix, String applicationName, boolean bind ); @Override void replaceApplicationBindings( ManagedApplication ma, String externalExportPrefix, Set<String> applicationNames ); }
ApplicationMngrImpl implements IApplicationMngr { @Override public void deleteApplication( ManagedApplication ma ) throws UnauthorizedActionException, IOException { String applicationName = ma.getApplication().getName(); for( Instance rootInstance : ma.getApplication().getRootInstances()) { if( rootInstance.getStatus() != InstanceStatus.NOT_DEPLOYED ) throw new UnauthorizedActionException( applicationName + " contains instances that are still deployed." ); } try { this.messagingMngr.checkMessagingConfiguration(); this.messagingMngr.getMessagingClient().listenToAgentMessages( ma.getApplication(), ListenerCommand.STOP ); this.messagingMngr.getMessagingClient().deleteMessagingServerArtifacts( ma.getApplication()); } catch( IOException e ) { Utils.logException( this.logger, e ); } this.randomMngr.releaseAllRandomValues( ma.getApplication()); this.notificationMngr.application( ma.getApplication(), EventType.DELETED ); Application app = ma.getApplication(); this.targetsMngr.applicationWasDeleted( app ); this.autonomicMngr.unloadApplicationRules( app ); this.logger.info( "Deleting the application called " + app.getName() + "..." ); this.nameToManagedApplication.remove( app.getName()); app.removeAssociationWithTemplate(); File targetDirectory = ConfigurationUtils.findApplicationDirectory( app.getName(), this.configurationMngr.getWorkingDirectory()); Utils.deleteFilesRecursively( targetDirectory ); this.logger.info( "Application " + app.getName() + " was successfully deleted." ); } ApplicationMngrImpl(
			INotificationMngr notificationMngr,
			IConfigurationMngr configurationMngr,
			ITargetsMngr targetsMngr,
			IMessagingMngr messagingMngr,
			IRandomMngr randomMngr,
			IAutonomicMngr autonomicMngr ); void setApplicationTemplateMngr( IApplicationTemplateMngr applicationTemplateMngr ); @Override Application findApplicationByName( String applicationName ); @Override ManagedApplication findManagedApplicationByName( String applicationName ); @Override Collection<ManagedApplication> getManagedApplications(); @Override ManagedApplication createApplication( String name, String description, String tplName, String tplQualifier ); @Override ManagedApplication createApplication( String name, String description, ApplicationTemplate tpl ); @Override void updateApplication( ManagedApplication ma, String newDesc ); @Override void deleteApplication( ManagedApplication ma ); @Override void restoreApplications(); @Override boolean isTemplateUsed( ApplicationTemplate tpl ); @Override void bindOrUnbindApplication( ManagedApplication ma, String externalExportPrefix, String applicationName, boolean bind ); @Override void replaceApplicationBindings( ManagedApplication ma, String externalExportPrefix, Set<String> applicationNames );  }