@Test public void testReplaceApplicationBindings_success() throws Exception { TestApplication app2 = new TestApplication(); app2.setDirectory( this.folder.newFolder()); app2.getTemplate().setName( "tpl-other" ); app2.getTemplate().setExternalExportsPrefix( "eep" ); app2.setName( "app-other" ); this.managerWrapper.addManagedApplication( new ManagedApplication( app2 )); Assert.assertEquals( 0, this.msgClient.allSentMessages.size()); Assert.assertEquals( 0, this.ma.removeAwaitingMessages( this.app.getTomcatVm()).size()); Assert.assertEquals( 0, this.ma.removeAwaitingMessages( this.app.getMySqlVm()).size()); Response resp = this.resource.replaceApplicationBindings( this.ma.getName(), app2.getTemplate().getExternalExportsPrefix(), Arrays.asList( app2.getName())); Assert.assertEquals( Status.OK.getStatusCode(), resp.getStatus()); Assert.assertEquals( 0, this.msgClient.allSentMessages.size()); List<Message> messages = this.ma.removeAwaitingMessages( this.app.getTomcatVm()); Assert.assertEquals( 1, messages.size()); messages.addAll( this.ma.removeAwaitingMessages( this.app.getMySqlVm())); Assert.assertEquals( 2, messages.size()); for( Message m : this.msgClient.allSentMessages ) { Assert.assertEquals( MsgCmdChangeBinding.class, m.getClass()); MsgCmdChangeBinding msg = (MsgCmdChangeBinding) m; Assert.assertEquals( app2.getTemplate().getExternalExportsPrefix(), msg.getExternalExportsPrefix()); Assert.assertNotNull( msg.getAppNames()); Assert.assertEquals( 1, msg.getAppNames().size()); Assert.assertTrue( msg.getAppNames().contains( app2.getName())); } resp = this.resource.replaceApplicationBindings( this.ma.getName(), app2.getTemplate().getExternalExportsPrefix(), new ArrayList<String>( 0 )); Assert.assertEquals( Status.OK.getStatusCode(), resp.getStatus()); Assert.assertEquals( 0, this.msgClient.allSentMessages.size()); messages = this.ma.removeAwaitingMessages( this.app.getTomcatVm()); Assert.assertEquals( 1, messages.size()); messages.addAll( this.ma.removeAwaitingMessages( this.app.getMySqlVm())); Assert.assertEquals( 2, messages.size()); for( Message m : this.msgClient.allSentMessages ) { Assert.assertEquals( MsgCmdChangeBinding.class, m.getClass()); MsgCmdChangeBinding msg = (MsgCmdChangeBinding) m; Assert.assertEquals( app2.getTemplate().getExternalExportsPrefix(), msg.getExternalExportsPrefix()); Assert.assertNull( msg.getAppNames()); } resp = this.resource.replaceApplicationBindings( this.ma.getName(), app2.getTemplate().getExternalExportsPrefix(), null ); Assert.assertEquals( Status.OK.getStatusCode(), resp.getStatus()); Assert.assertEquals( 0, this.msgClient.allSentMessages.size()); messages = this.ma.removeAwaitingMessages( this.app.getTomcatVm()); Assert.assertEquals( 0, messages.size()); messages.addAll( this.ma.removeAwaitingMessages( this.app.getMySqlVm())); Assert.assertEquals( 0, messages.size()); }
@Override public Response replaceApplicationBindings( String applicationName, String externalExportPrefix, List<String> boundApps ) { if( this.logger.isLoggable( Level.FINE )) { StringBuilder sb = new StringBuilder(); sb.append( "Replacing the bindings for the " ); sb.append( externalExportPrefix ); sb.append( " prefix with " ); sb.append( Arrays.toString( boundApps.toArray())); sb.append( " in application " ); sb.append( applicationName ); sb.append( "." ); this.logger.fine( sb.toString()); } String lang = lang( this.manager ); Response response; try { ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName ); if( ma == null ) { response = RestServicesUtils.handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_INEXISTING, application( applicationName )), lang ).build(); } else { Set<String> apps = new TreeSet<> (); if( boundApps != null ) apps.addAll( boundApps ); this.manager.applicationMngr().replaceApplicationBindings( ma, externalExportPrefix, apps ); response = Response.ok().build(); } } catch( UnauthorizedActionException | IOException e ) { response = RestServicesUtils.handleError( Status.FORBIDDEN, new RestError( ErrorCode.REST_UNDETAILED_ERROR, e ), lang ).build(); } return response; }
ApplicationResource implements IApplicationResource { @Override public Response replaceApplicationBindings( String applicationName, String externalExportPrefix, List<String> boundApps ) { if( this.logger.isLoggable( Level.FINE )) { StringBuilder sb = new StringBuilder(); sb.append( "Replacing the bindings for the " ); sb.append( externalExportPrefix ); sb.append( " prefix with " ); sb.append( Arrays.toString( boundApps.toArray())); sb.append( " in application " ); sb.append( applicationName ); sb.append( "." ); this.logger.fine( sb.toString()); } String lang = lang( this.manager ); Response response; try { ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName ); if( ma == null ) { response = RestServicesUtils.handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_INEXISTING, application( applicationName )), lang ).build(); } else { Set<String> apps = new TreeSet<> (); if( boundApps != null ) apps.addAll( boundApps ); this.manager.applicationMngr().replaceApplicationBindings( ma, externalExportPrefix, apps ); response = Response.ok().build(); } } catch( UnauthorizedActionException | IOException e ) { response = RestServicesUtils.handleError( Status.FORBIDDEN, new RestError( ErrorCode.REST_UNDETAILED_ERROR, e ), lang ).build(); } return response; } }
ApplicationResource implements IApplicationResource { @Override public Response replaceApplicationBindings( String applicationName, String externalExportPrefix, List<String> boundApps ) { if( this.logger.isLoggable( Level.FINE )) { StringBuilder sb = new StringBuilder(); sb.append( "Replacing the bindings for the " ); sb.append( externalExportPrefix ); sb.append( " prefix with " ); sb.append( Arrays.toString( boundApps.toArray())); sb.append( " in application " ); sb.append( applicationName ); sb.append( "." ); this.logger.fine( sb.toString()); } String lang = lang( this.manager ); Response response; try { ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName ); if( ma == null ) { response = RestServicesUtils.handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_INEXISTING, application( applicationName )), lang ).build(); } else { Set<String> apps = new TreeSet<> (); if( boundApps != null ) apps.addAll( boundApps ); this.manager.applicationMngr().replaceApplicationBindings( ma, externalExportPrefix, apps ); response = Response.ok().build(); } } catch( UnauthorizedActionException | IOException e ) { response = RestServicesUtils.handleError( Status.FORBIDDEN, new RestError( ErrorCode.REST_UNDETAILED_ERROR, e ), lang ).build(); } return response; } ApplicationResource( Manager manager ); }
ApplicationResource implements IApplicationResource { @Override public Response replaceApplicationBindings( String applicationName, String externalExportPrefix, List<String> boundApps ) { if( this.logger.isLoggable( Level.FINE )) { StringBuilder sb = new StringBuilder(); sb.append( "Replacing the bindings for the " ); sb.append( externalExportPrefix ); sb.append( " prefix with " ); sb.append( Arrays.toString( boundApps.toArray())); sb.append( " in application " ); sb.append( applicationName ); sb.append( "." ); this.logger.fine( sb.toString()); } String lang = lang( this.manager ); Response response; try { ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName ); if( ma == null ) { response = RestServicesUtils.handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_INEXISTING, application( applicationName )), lang ).build(); } else { Set<String> apps = new TreeSet<> (); if( boundApps != null ) apps.addAll( boundApps ); this.manager.applicationMngr().replaceApplicationBindings( ma, externalExportPrefix, apps ); response = Response.ok().build(); } } catch( UnauthorizedActionException | IOException e ) { response = RestServicesUtils.handleError( Status.FORBIDDEN, new RestError( ErrorCode.REST_UNDETAILED_ERROR, e ), lang ).build(); } return response; } ApplicationResource( Manager manager ); @Override Response changeInstanceState( String applicationName, String newState, String instancePath ); @Override Response setDescription( String applicationName, String desc ); @Override Response deployAndStartAll( String applicationName, String instancePath ); @Override Response stopAll( String applicationName, String instancePath ); @Override Response undeployAll( String applicationName, String instancePath ); @Override List<Instance> listChildrenInstances( String applicationName, String instancePath, boolean allChildren ); @Override Response bindApplication( String applicationName, String externalExportPrefix, String boundApp ); @Override Response unbindApplication( String applicationName, String externalExportPrefix, String boundApp ); @Override Response replaceApplicationBindings( String applicationName, String externalExportPrefix, List<String> boundApps ); @Override Response getApplicationBindings( String applicationName ); @Override Response addInstance( String applicationName, String parentInstancePath, Instance instance ); @Override Response removeInstance( String applicationName, String instancePath ); @Override List<TargetAssociation> findTargetAssociations( String applicationName ); @Override Response resynchronize( String applicationName ); @Override List<Component> listComponents( String applicationName ); @Override List<Component> findComponentChildren( String applicationName, String componentName ); @Override List<Component> findComponentAncestors( String applicationName, String componentName ); @Override List<String> listCommands( String app ); @Override Response executeCommand( String app, String commandName ); @Override Response getCommandInstructions( String appName, String commandName ); @Override Response replaceTags( String name, String version, List<String> tags ); }
ApplicationResource implements IApplicationResource { @Override public Response replaceApplicationBindings( String applicationName, String externalExportPrefix, List<String> boundApps ) { if( this.logger.isLoggable( Level.FINE )) { StringBuilder sb = new StringBuilder(); sb.append( "Replacing the bindings for the " ); sb.append( externalExportPrefix ); sb.append( " prefix with " ); sb.append( Arrays.toString( boundApps.toArray())); sb.append( " in application " ); sb.append( applicationName ); sb.append( "." ); this.logger.fine( sb.toString()); } String lang = lang( this.manager ); Response response; try { ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName ); if( ma == null ) { response = RestServicesUtils.handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_INEXISTING, application( applicationName )), lang ).build(); } else { Set<String> apps = new TreeSet<> (); if( boundApps != null ) apps.addAll( boundApps ); this.manager.applicationMngr().replaceApplicationBindings( ma, externalExportPrefix, apps ); response = Response.ok().build(); } } catch( UnauthorizedActionException | IOException e ) { response = RestServicesUtils.handleError( Status.FORBIDDEN, new RestError( ErrorCode.REST_UNDETAILED_ERROR, e ), lang ).build(); } return response; } ApplicationResource( Manager manager ); @Override Response changeInstanceState( String applicationName, String newState, String instancePath ); @Override Response setDescription( String applicationName, String desc ); @Override Response deployAndStartAll( String applicationName, String instancePath ); @Override Response stopAll( String applicationName, String instancePath ); @Override Response undeployAll( String applicationName, String instancePath ); @Override List<Instance> listChildrenInstances( String applicationName, String instancePath, boolean allChildren ); @Override Response bindApplication( String applicationName, String externalExportPrefix, String boundApp ); @Override Response unbindApplication( String applicationName, String externalExportPrefix, String boundApp ); @Override Response replaceApplicationBindings( String applicationName, String externalExportPrefix, List<String> boundApps ); @Override Response getApplicationBindings( String applicationName ); @Override Response addInstance( String applicationName, String parentInstancePath, Instance instance ); @Override Response removeInstance( String applicationName, String instancePath ); @Override List<TargetAssociation> findTargetAssociations( String applicationName ); @Override Response resynchronize( String applicationName ); @Override List<Component> listComponents( String applicationName ); @Override List<Component> findComponentChildren( String applicationName, String componentName ); @Override List<Component> findComponentAncestors( String applicationName, String componentName ); @Override List<String> listCommands( String app ); @Override Response executeCommand( String app, String commandName ); @Override Response getCommandInstructions( String appName, String commandName ); @Override Response replaceTags( String name, String version, List<String> tags );  }