@Test public void testExecuteCommand_executionError() throws Exception { this.manager.commandsMngr().createOrUpdateCommand( this.app, "toto", "Good command"); Response resp = this.resource.executeCommand( this.app.getName(), "toto" ); Assert.assertEquals( Status.CONFLICT.getStatusCode(), resp.getStatus()); }
@Override public Response executeCommand( String app, String commandName ) { this.logger.fine("Request: execute command " + commandName + " in the " + app + " application."); String lang = lang( this.manager ); Response response = Response.ok().build(); try { Application application = this.manager.applicationMngr().findApplicationByName( app ); if( application == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( app )), lang ).build(); else this.manager.commandsMngr().execute( application, commandName, CommandHistoryItem.ORIGIN_REST_API, null ); } catch( NoSuchFileException e ) { response = RestServicesUtils.handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_INEXISTING, e, ErrorDetails.name( commandName )), lang ).build(); } catch( CommandException e ) { response = RestServicesUtils.handleError( Status.CONFLICT, new RestError( ErrorCode.REST_APP_EXEC_ERROR, e, ErrorDetails.name( commandName )), lang ).build(); } catch( Exception e ) { response = RestServicesUtils.handleError( Status.INTERNAL_SERVER_ERROR, new RestError( ErrorCode.REST_UNDETAILED_ERROR, e ), lang ).build(); } return response; }
ApplicationResource implements IApplicationResource { @Override public Response executeCommand( String app, String commandName ) { this.logger.fine("Request: execute command " + commandName + " in the " + app + " application."); String lang = lang( this.manager ); Response response = Response.ok().build(); try { Application application = this.manager.applicationMngr().findApplicationByName( app ); if( application == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( app )), lang ).build(); else this.manager.commandsMngr().execute( application, commandName, CommandHistoryItem.ORIGIN_REST_API, null ); } catch( NoSuchFileException e ) { response = RestServicesUtils.handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_INEXISTING, e, ErrorDetails.name( commandName )), lang ).build(); } catch( CommandException e ) { response = RestServicesUtils.handleError( Status.CONFLICT, new RestError( ErrorCode.REST_APP_EXEC_ERROR, e, ErrorDetails.name( commandName )), lang ).build(); } catch( Exception e ) { response = RestServicesUtils.handleError( Status.INTERNAL_SERVER_ERROR, new RestError( ErrorCode.REST_UNDETAILED_ERROR, e ), lang ).build(); } return response; } }
ApplicationResource implements IApplicationResource { @Override public Response executeCommand( String app, String commandName ) { this.logger.fine("Request: execute command " + commandName + " in the " + app + " application."); String lang = lang( this.manager ); Response response = Response.ok().build(); try { Application application = this.manager.applicationMngr().findApplicationByName( app ); if( application == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( app )), lang ).build(); else this.manager.commandsMngr().execute( application, commandName, CommandHistoryItem.ORIGIN_REST_API, null ); } catch( NoSuchFileException e ) { response = RestServicesUtils.handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_INEXISTING, e, ErrorDetails.name( commandName )), lang ).build(); } catch( CommandException e ) { response = RestServicesUtils.handleError( Status.CONFLICT, new RestError( ErrorCode.REST_APP_EXEC_ERROR, e, ErrorDetails.name( commandName )), lang ).build(); } catch( Exception e ) { response = RestServicesUtils.handleError( Status.INTERNAL_SERVER_ERROR, new RestError( ErrorCode.REST_UNDETAILED_ERROR, e ), lang ).build(); } return response; } ApplicationResource( Manager manager ); }
ApplicationResource implements IApplicationResource { @Override public Response executeCommand( String app, String commandName ) { this.logger.fine("Request: execute command " + commandName + " in the " + app + " application."); String lang = lang( this.manager ); Response response = Response.ok().build(); try { Application application = this.manager.applicationMngr().findApplicationByName( app ); if( application == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( app )), lang ).build(); else this.manager.commandsMngr().execute( application, commandName, CommandHistoryItem.ORIGIN_REST_API, null ); } catch( NoSuchFileException e ) { response = RestServicesUtils.handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_INEXISTING, e, ErrorDetails.name( commandName )), lang ).build(); } catch( CommandException e ) { response = RestServicesUtils.handleError( Status.CONFLICT, new RestError( ErrorCode.REST_APP_EXEC_ERROR, e, ErrorDetails.name( commandName )), lang ).build(); } catch( Exception e ) { response = RestServicesUtils.handleError( Status.INTERNAL_SERVER_ERROR, 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 executeCommand( String app, String commandName ) { this.logger.fine("Request: execute command " + commandName + " in the " + app + " application."); String lang = lang( this.manager ); Response response = Response.ok().build(); try { Application application = this.manager.applicationMngr().findApplicationByName( app ); if( application == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( app )), lang ).build(); else this.manager.commandsMngr().execute( application, commandName, CommandHistoryItem.ORIGIN_REST_API, null ); } catch( NoSuchFileException e ) { response = RestServicesUtils.handleError( Status.NOT_FOUND, new RestError( ErrorCode.REST_INEXISTING, e, ErrorDetails.name( commandName )), lang ).build(); } catch( CommandException e ) { response = RestServicesUtils.handleError( Status.CONFLICT, new RestError( ErrorCode.REST_APP_EXEC_ERROR, e, ErrorDetails.name( commandName )), lang ).build(); } catch( Exception e ) { response = RestServicesUtils.handleError( Status.INTERNAL_SERVER_ERROR, 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 );  }