@Test public void testChangeState_deployRoot_success() throws Exception { TestTargetResolver iaasResolver = new TestTargetResolver(); this.manager.setTargetResolver( iaasResolver ); String targetId = this.manager.targetsMngr().createTarget( "id: tid\nhandler: test" ); this.manager.targetsMngr().associateTargetWith( targetId, this.app, null ); Assert.assertEquals( 0, iaasResolver.instancePathToRunningStatus.size()); Response resp = this.resource.changeInstanceState( this.app.getName(), InstanceStatus.DEPLOYED_STARTED.toString(), InstanceHelpers.computeInstancePath( this.app.getMySqlVm())); String path = InstanceHelpers.computeInstancePath( this.app.getMySqlVm()); Assert.assertEquals( Status.OK.getStatusCode(), resp.getStatus()); Assert.assertEquals( 1, iaasResolver.instancePathToRunningStatus.size()); Assert.assertTrue( iaasResolver.instancePathToRunningStatus.get( path )); }
@Override public Response changeInstanceState( String applicationName, String newState, String instancePath ) { this.logger.fine( "Request: change state of " + instancePath + " to '" + newState + "' in " + applicationName + "." ); Response response = Response.ok().build(); String lang = lang( this.manager ); try { ManagedApplication ma; Instance instance; if( ! InstanceStatus.isValidState( newState )) response = handleError( Status.FORBIDDEN, new RestError( REST_INEXISTING, name( newState )), lang ).build(); else if(( ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName )) == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( applicationName )), lang ).build(); else if(( 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().changeInstanceState( ma, instance, InstanceStatus.whichStatus( newState )); } catch( IOException | TargetException e ) { response = RestServicesUtils.handleError( Status.FORBIDDEN, new RestError( ErrorCode.REST_UNDETAILED_ERROR, e ), 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 changeInstanceState( String applicationName, String newState, String instancePath ) { this.logger.fine( "Request: change state of " + instancePath + " to '" + newState + "' in " + applicationName + "." ); Response response = Response.ok().build(); String lang = lang( this.manager ); try { ManagedApplication ma; Instance instance; if( ! InstanceStatus.isValidState( newState )) response = handleError( Status.FORBIDDEN, new RestError( REST_INEXISTING, name( newState )), lang ).build(); else if(( ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName )) == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( applicationName )), lang ).build(); else if(( 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().changeInstanceState( ma, instance, InstanceStatus.whichStatus( newState )); } catch( IOException | TargetException e ) { response = RestServicesUtils.handleError( Status.FORBIDDEN, new RestError( ErrorCode.REST_UNDETAILED_ERROR, e ), 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 changeInstanceState( String applicationName, String newState, String instancePath ) { this.logger.fine( "Request: change state of " + instancePath + " to '" + newState + "' in " + applicationName + "." ); Response response = Response.ok().build(); String lang = lang( this.manager ); try { ManagedApplication ma; Instance instance; if( ! InstanceStatus.isValidState( newState )) response = handleError( Status.FORBIDDEN, new RestError( REST_INEXISTING, name( newState )), lang ).build(); else if(( ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName )) == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( applicationName )), lang ).build(); else if(( 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().changeInstanceState( ma, instance, InstanceStatus.whichStatus( newState )); } catch( IOException | TargetException e ) { response = RestServicesUtils.handleError( Status.FORBIDDEN, new RestError( ErrorCode.REST_UNDETAILED_ERROR, e ), 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 changeInstanceState( String applicationName, String newState, String instancePath ) { this.logger.fine( "Request: change state of " + instancePath + " to '" + newState + "' in " + applicationName + "." ); Response response = Response.ok().build(); String lang = lang( this.manager ); try { ManagedApplication ma; Instance instance; if( ! InstanceStatus.isValidState( newState )) response = handleError( Status.FORBIDDEN, new RestError( REST_INEXISTING, name( newState )), lang ).build(); else if(( ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName )) == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( applicationName )), lang ).build(); else if(( 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().changeInstanceState( ma, instance, InstanceStatus.whichStatus( newState )); } catch( IOException | TargetException e ) { response = RestServicesUtils.handleError( Status.FORBIDDEN, new RestError( ErrorCode.REST_UNDETAILED_ERROR, e ), 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 changeInstanceState( String applicationName, String newState, String instancePath ) { this.logger.fine( "Request: change state of " + instancePath + " to '" + newState + "' in " + applicationName + "." ); Response response = Response.ok().build(); String lang = lang( this.manager ); try { ManagedApplication ma; Instance instance; if( ! InstanceStatus.isValidState( newState )) response = handleError( Status.FORBIDDEN, new RestError( REST_INEXISTING, name( newState )), lang ).build(); else if(( ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName )) == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( applicationName )), lang ).build(); else if(( 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().changeInstanceState( ma, instance, InstanceStatus.whichStatus( newState )); } catch( IOException | TargetException e ) { response = RestServicesUtils.handleError( Status.FORBIDDEN, new RestError( ErrorCode.REST_UNDETAILED_ERROR, e ), 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 );  }