ApplicationResource implements IApplicationResource { @Override public Response stopAll( String applicationName, String instancePath ) { this.logger.fine( "Request: stop instances in " + applicationName + ", from instance = " + instancePath + "." ); String lang = lang( this.manager ); Response response; try { ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName ); Instance instance = null; if( ma == null ) { response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( applicationName )), lang ).build(); } else if( instancePath != null && (instance = InstanceHelpers.findInstanceByPath( ma.getApplication(), instancePath )) == null ) { response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, instance( instancePath ), application( applicationName )), lang ).build(); } else { this.manager.instancesMngr().stopAll( ma, instance ); response = Response.ok().build(); } } catch( Exception 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 );  }
@Test public void testStopAll() throws Exception { Assert.assertEquals( 0, this.msgClient.allSentMessages.size()); Assert.assertEquals( 0, this.ma.removeAwaitingMessages( this.app.getTomcatVm()).size()); String instancePath = InstanceHelpers.computeInstancePath( this.app.getTomcat()); Response resp = this.resource.stopAll( this.app.getName(), instancePath ); 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()); Assert.assertEquals( MsgCmdChangeInstanceState.class, messages.get( 0 ).getClass()); Assert.assertEquals( instancePath, ((MsgCmdChangeInstanceState) messages.get( 0 )).getInstancePath()); }
@Test public void testStopAll_invalidApp() throws Exception { String instancePath = InstanceHelpers.computeInstancePath( this.app.getTomcat()); Response resp = this.resource.stopAll( "oops", instancePath ); Assert.assertEquals( Status.NOT_FOUND.getStatusCode(), resp.getStatus()); }
@Test public void testStopAll_invalidInstancePath() throws Exception { Response resp = this.resource.stopAll( this.app.getName(), "/invalid" ); Assert.assertEquals( Status.NOT_FOUND.getStatusCode(), resp.getStatus()); }
@Test public void testStopAll_IOException() throws Exception { this.msgClient.connected.set( false ); String instancePath = InstanceHelpers.computeInstancePath( this.app.getTomcat()); Response resp = this.resource.stopAll( this.app.getName(), instancePath ); Assert.assertEquals( Status.FORBIDDEN.getStatusCode(), resp.getStatus()); }