@Test public void testCheckMessagingConnectionWithAgent_success() throws Exception { ManagedApplication ma = new ManagedApplication( this.app ); this.managerWrapper.addManagedApplication( ma ); Assert.assertEquals( 0, this.msgClient.allSentMessages.size()); UUID uuid = UUID.randomUUID(); String path = "/" + this.app.getMySqlVm().getName(); InstanceStatus[] statuses = new InstanceStatus[] { InstanceStatus.DEPLOYED_STARTED, InstanceStatus.DEPLOYED_STOPPED, InstanceStatus.PROBLEM, InstanceStatus.DEPLOYING }; for( InstanceStatus status : statuses ) { this.app.getMySqlVm().setStatus( status ); Response resp = this.resource.checkMessagingConnectionWithAgent( this.app.getName(), path, uuid.toString()); Assert.assertEquals( status.toString(), Status.OK.getStatusCode(), resp.getStatus()); Assert.assertEquals( status.toString(), 1, this.msgClient.allSentMessages.size()); Message msg = this.msgClient.allSentMessages.get( 0 ); Assert.assertEquals( status.toString(), MsgEcho.class, msg.getClass()); Assert.assertEquals( status.toString(), "PING:" + uuid.toString(), ((MsgEcho) msg).getContent()); this.msgClient.allSentMessages.clear(); } }
@Override public Response checkMessagingConnectionWithAgent( String applicationName, String scopedInstancePath, String message ) { this.logger.fine( "Request: check the connection with agent " + applicationName + " :: " + scopedInstancePath + ". message=" + message ); final ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName ); String lang = lang( this.manager ); Response response; int pingResult; final Instance instance; if( ma == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( applicationName )), lang ).build(); else if(( instance = InstanceHelpers.findInstanceByPath( ma.getApplication(), scopedInstancePath )) == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, instance( scopedInstancePath ), application( applicationName )), lang ).build(); else if(( pingResult = this.manager.debugMngr().pingAgent( ma, instance, message )) == 1 ) response = handleError( Status.BAD_REQUEST, new RestError( REST_DEBUG_AGENT_KO ), lang ).build(); else if( pingResult == 2 ) response = handleError( Status.INTERNAL_SERVER_ERROR, new RestError( REST_MESSAGING_ERROR ), lang ).build(); else response = handleError( Status.OK, new RestError( REST_DEBUG_AGENT_KO, name( "PING" ), value( message )), lang ).build(); return response; }
DebugResource implements IDebugResource { @Override public Response checkMessagingConnectionWithAgent( String applicationName, String scopedInstancePath, String message ) { this.logger.fine( "Request: check the connection with agent " + applicationName + " :: " + scopedInstancePath + ". message=" + message ); final ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName ); String lang = lang( this.manager ); Response response; int pingResult; final Instance instance; if( ma == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( applicationName )), lang ).build(); else if(( instance = InstanceHelpers.findInstanceByPath( ma.getApplication(), scopedInstancePath )) == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, instance( scopedInstancePath ), application( applicationName )), lang ).build(); else if(( pingResult = this.manager.debugMngr().pingAgent( ma, instance, message )) == 1 ) response = handleError( Status.BAD_REQUEST, new RestError( REST_DEBUG_AGENT_KO ), lang ).build(); else if( pingResult == 2 ) response = handleError( Status.INTERNAL_SERVER_ERROR, new RestError( REST_MESSAGING_ERROR ), lang ).build(); else response = handleError( Status.OK, new RestError( REST_DEBUG_AGENT_KO, name( "PING" ), value( message )), lang ).build(); return response; } }
DebugResource implements IDebugResource { @Override public Response checkMessagingConnectionWithAgent( String applicationName, String scopedInstancePath, String message ) { this.logger.fine( "Request: check the connection with agent " + applicationName + " :: " + scopedInstancePath + ". message=" + message ); final ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName ); String lang = lang( this.manager ); Response response; int pingResult; final Instance instance; if( ma == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( applicationName )), lang ).build(); else if(( instance = InstanceHelpers.findInstanceByPath( ma.getApplication(), scopedInstancePath )) == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, instance( scopedInstancePath ), application( applicationName )), lang ).build(); else if(( pingResult = this.manager.debugMngr().pingAgent( ma, instance, message )) == 1 ) response = handleError( Status.BAD_REQUEST, new RestError( REST_DEBUG_AGENT_KO ), lang ).build(); else if( pingResult == 2 ) response = handleError( Status.INTERNAL_SERVER_ERROR, new RestError( REST_MESSAGING_ERROR ), lang ).build(); else response = handleError( Status.OK, new RestError( REST_DEBUG_AGENT_KO, name( "PING" ), value( message )), lang ).build(); return response; } DebugResource( Manager manager ); }
DebugResource implements IDebugResource { @Override public Response checkMessagingConnectionWithAgent( String applicationName, String scopedInstancePath, String message ) { this.logger.fine( "Request: check the connection with agent " + applicationName + " :: " + scopedInstancePath + ". message=" + message ); final ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName ); String lang = lang( this.manager ); Response response; int pingResult; final Instance instance; if( ma == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( applicationName )), lang ).build(); else if(( instance = InstanceHelpers.findInstanceByPath( ma.getApplication(), scopedInstancePath )) == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, instance( scopedInstancePath ), application( applicationName )), lang ).build(); else if(( pingResult = this.manager.debugMngr().pingAgent( ma, instance, message )) == 1 ) response = handleError( Status.BAD_REQUEST, new RestError( REST_DEBUG_AGENT_KO ), lang ).build(); else if( pingResult == 2 ) response = handleError( Status.INTERNAL_SERVER_ERROR, new RestError( REST_MESSAGING_ERROR ), lang ).build(); else response = handleError( Status.OK, new RestError( REST_DEBUG_AGENT_KO, name( "PING" ), value( message )), lang ).build(); return response; } DebugResource( Manager manager ); @Override Response checkMessagingConnectionForTheDm( String message ); @Override Response checkMessagingConnectionWithAgent(
			String applicationName,
			String scopedInstancePath,
			String message ); @Override Response diagnoseInstance( String applicationName, String instancePath ); @Override List<Diagnostic> diagnoseApplication( String applicationName ); }
DebugResource implements IDebugResource { @Override public Response checkMessagingConnectionWithAgent( String applicationName, String scopedInstancePath, String message ) { this.logger.fine( "Request: check the connection with agent " + applicationName + " :: " + scopedInstancePath + ". message=" + message ); final ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName ); String lang = lang( this.manager ); Response response; int pingResult; final Instance instance; if( ma == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, application( applicationName )), lang ).build(); else if(( instance = InstanceHelpers.findInstanceByPath( ma.getApplication(), scopedInstancePath )) == null ) response = handleError( Status.NOT_FOUND, new RestError( REST_INEXISTING, instance( scopedInstancePath ), application( applicationName )), lang ).build(); else if(( pingResult = this.manager.debugMngr().pingAgent( ma, instance, message )) == 1 ) response = handleError( Status.BAD_REQUEST, new RestError( REST_DEBUG_AGENT_KO ), lang ).build(); else if( pingResult == 2 ) response = handleError( Status.INTERNAL_SERVER_ERROR, new RestError( REST_MESSAGING_ERROR ), lang ).build(); else response = handleError( Status.OK, new RestError( REST_DEBUG_AGENT_KO, name( "PING" ), value( message )), lang ).build(); return response; } DebugResource( Manager manager ); @Override Response checkMessagingConnectionForTheDm( String message ); @Override Response checkMessagingConnectionWithAgent(
			String applicationName,
			String scopedInstancePath,
			String message ); @Override Response diagnoseInstance( String applicationName, String instancePath ); @Override List<Diagnostic> diagnoseApplication( String applicationName );  }