@Test public void getServiceState() throws URISyntaxException, IOException { final MockHttpResponse response = get(MicroServiceStateAPI.BASE_URI, MediaType.APPLICATION_JSON_TYPE); assertEquals(HttpStatus.SC_OK, response.getStatus()); final Map<String, ?> json = json(response); assertEquals("Mock Micro Service", json.get("name")); assertEquals("RUNNING", json.get("state")); }
@Override public ServiceState getServiceState() { Context context = getMicroServiceApplication().getMicroServiceContext(); List<ServiceState.InputQueueState> inputQueues = new ArrayList<>(); ResourceManager<InputQueueDescriptor, InputQueueConfiguration, ManagedInputQueue> queuesManager = context.getQueuesManager(); List<ManagedInputQueue> managedQueuesStats = queuesManager.getManagedResources(); if (!managedQueuesStats.isEmpty()) { for (ManagedInputQueue currManagedQueue : managedQueuesStats) { List<ServiceState.InputQueueReceiver> receivers = new ArrayList<>(); if (!currManagedQueue.getReceivers().isEmpty()) { for (QueueReceiver currReceiver : currManagedQueue.getReceivers()) { QueueExecutionState currState = ((QueueReceiverImpl) currReceiver).getMessageListener().getQueueExecutionState(); QueueExecutionState.ReceiverRunningState state = currState.getState(); Date lastExecutionTime = null; Date currExecutionStartTime = null; Map<String, String> properties = null; switch (state) { case RUNNING: currExecutionStartTime = new Date(currState.getExecutionStartTime()); Map<String, String> headers = currState.getHeaders(); if (!headers.isEmpty()) { properties = new HashMap<>(headers); } break; case IDLE: Long executionEndTime = currState.getExecutionEndTime(); if (executionEndTime != null) { lastExecutionTime = new Date(executionEndTime); } break; default: break; } receivers.add(new ServiceState.InputQueueReceiver( currState.getState().name(), currState.getInitializedDate(), lastExecutionTime, currExecutionStartTime, properties)); } } inputQueues.add(new ServiceState.InputQueueState(currManagedQueue.getQueueName(), receivers)); } } final StaticObjectMetric<RestCallInfo> restCallInfoStaticObjectMetric = context.getMetricsRegistry().getStaticObjectMetric(RestCallInfo.class); final long currentTimeMillis = System.currentTimeMillis(); return new ServiceState( context.getMicroServiceName(), ServiceState.ServiceStateEnum.valueOf(context.getServiceState().name()), context.getLogger().getName(), inputQueues, restCallInfoStaticObjectMetric.list() .stream() .map((i) -> new ServiceState.RestRequestState( i.getMethod(), i.getUrl(), currentTimeMillis - i.getStartTime().getTime())) .collect(Collectors.toList()) ); }
MicroServiceStateResource extends MicroServiceResource implements MicroServiceStateAPI { @Override public ServiceState getServiceState() { Context context = getMicroServiceApplication().getMicroServiceContext(); List<ServiceState.InputQueueState> inputQueues = new ArrayList<>(); ResourceManager<InputQueueDescriptor, InputQueueConfiguration, ManagedInputQueue> queuesManager = context.getQueuesManager(); List<ManagedInputQueue> managedQueuesStats = queuesManager.getManagedResources(); if (!managedQueuesStats.isEmpty()) { for (ManagedInputQueue currManagedQueue : managedQueuesStats) { List<ServiceState.InputQueueReceiver> receivers = new ArrayList<>(); if (!currManagedQueue.getReceivers().isEmpty()) { for (QueueReceiver currReceiver : currManagedQueue.getReceivers()) { QueueExecutionState currState = ((QueueReceiverImpl) currReceiver).getMessageListener().getQueueExecutionState(); QueueExecutionState.ReceiverRunningState state = currState.getState(); Date lastExecutionTime = null; Date currExecutionStartTime = null; Map<String, String> properties = null; switch (state) { case RUNNING: currExecutionStartTime = new Date(currState.getExecutionStartTime()); Map<String, String> headers = currState.getHeaders(); if (!headers.isEmpty()) { properties = new HashMap<>(headers); } break; case IDLE: Long executionEndTime = currState.getExecutionEndTime(); if (executionEndTime != null) { lastExecutionTime = new Date(executionEndTime); } break; default: break; } receivers.add(new ServiceState.InputQueueReceiver( currState.getState().name(), currState.getInitializedDate(), lastExecutionTime, currExecutionStartTime, properties)); } } inputQueues.add(new ServiceState.InputQueueState(currManagedQueue.getQueueName(), receivers)); } } final StaticObjectMetric<RestCallInfo> restCallInfoStaticObjectMetric = context.getMetricsRegistry().getStaticObjectMetric(RestCallInfo.class); final long currentTimeMillis = System.currentTimeMillis(); return new ServiceState( context.getMicroServiceName(), ServiceState.ServiceStateEnum.valueOf(context.getServiceState().name()), context.getLogger().getName(), inputQueues, restCallInfoStaticObjectMetric.list() .stream() .map((i) -> new ServiceState.RestRequestState( i.getMethod(), i.getUrl(), currentTimeMillis - i.getStartTime().getTime())) .collect(Collectors.toList()) ); } }
MicroServiceStateResource extends MicroServiceResource implements MicroServiceStateAPI { @Override public ServiceState getServiceState() { Context context = getMicroServiceApplication().getMicroServiceContext(); List<ServiceState.InputQueueState> inputQueues = new ArrayList<>(); ResourceManager<InputQueueDescriptor, InputQueueConfiguration, ManagedInputQueue> queuesManager = context.getQueuesManager(); List<ManagedInputQueue> managedQueuesStats = queuesManager.getManagedResources(); if (!managedQueuesStats.isEmpty()) { for (ManagedInputQueue currManagedQueue : managedQueuesStats) { List<ServiceState.InputQueueReceiver> receivers = new ArrayList<>(); if (!currManagedQueue.getReceivers().isEmpty()) { for (QueueReceiver currReceiver : currManagedQueue.getReceivers()) { QueueExecutionState currState = ((QueueReceiverImpl) currReceiver).getMessageListener().getQueueExecutionState(); QueueExecutionState.ReceiverRunningState state = currState.getState(); Date lastExecutionTime = null; Date currExecutionStartTime = null; Map<String, String> properties = null; switch (state) { case RUNNING: currExecutionStartTime = new Date(currState.getExecutionStartTime()); Map<String, String> headers = currState.getHeaders(); if (!headers.isEmpty()) { properties = new HashMap<>(headers); } break; case IDLE: Long executionEndTime = currState.getExecutionEndTime(); if (executionEndTime != null) { lastExecutionTime = new Date(executionEndTime); } break; default: break; } receivers.add(new ServiceState.InputQueueReceiver( currState.getState().name(), currState.getInitializedDate(), lastExecutionTime, currExecutionStartTime, properties)); } } inputQueues.add(new ServiceState.InputQueueState(currManagedQueue.getQueueName(), receivers)); } } final StaticObjectMetric<RestCallInfo> restCallInfoStaticObjectMetric = context.getMetricsRegistry().getStaticObjectMetric(RestCallInfo.class); final long currentTimeMillis = System.currentTimeMillis(); return new ServiceState( context.getMicroServiceName(), ServiceState.ServiceStateEnum.valueOf(context.getServiceState().name()), context.getLogger().getName(), inputQueues, restCallInfoStaticObjectMetric.list() .stream() .map((i) -> new ServiceState.RestRequestState( i.getMethod(), i.getUrl(), currentTimeMillis - i.getStartTime().getTime())) .collect(Collectors.toList()) ); }  }
MicroServiceStateResource extends MicroServiceResource implements MicroServiceStateAPI { @Override public ServiceState getServiceState() { Context context = getMicroServiceApplication().getMicroServiceContext(); List<ServiceState.InputQueueState> inputQueues = new ArrayList<>(); ResourceManager<InputQueueDescriptor, InputQueueConfiguration, ManagedInputQueue> queuesManager = context.getQueuesManager(); List<ManagedInputQueue> managedQueuesStats = queuesManager.getManagedResources(); if (!managedQueuesStats.isEmpty()) { for (ManagedInputQueue currManagedQueue : managedQueuesStats) { List<ServiceState.InputQueueReceiver> receivers = new ArrayList<>(); if (!currManagedQueue.getReceivers().isEmpty()) { for (QueueReceiver currReceiver : currManagedQueue.getReceivers()) { QueueExecutionState currState = ((QueueReceiverImpl) currReceiver).getMessageListener().getQueueExecutionState(); QueueExecutionState.ReceiverRunningState state = currState.getState(); Date lastExecutionTime = null; Date currExecutionStartTime = null; Map<String, String> properties = null; switch (state) { case RUNNING: currExecutionStartTime = new Date(currState.getExecutionStartTime()); Map<String, String> headers = currState.getHeaders(); if (!headers.isEmpty()) { properties = new HashMap<>(headers); } break; case IDLE: Long executionEndTime = currState.getExecutionEndTime(); if (executionEndTime != null) { lastExecutionTime = new Date(executionEndTime); } break; default: break; } receivers.add(new ServiceState.InputQueueReceiver( currState.getState().name(), currState.getInitializedDate(), lastExecutionTime, currExecutionStartTime, properties)); } } inputQueues.add(new ServiceState.InputQueueState(currManagedQueue.getQueueName(), receivers)); } } final StaticObjectMetric<RestCallInfo> restCallInfoStaticObjectMetric = context.getMetricsRegistry().getStaticObjectMetric(RestCallInfo.class); final long currentTimeMillis = System.currentTimeMillis(); return new ServiceState( context.getMicroServiceName(), ServiceState.ServiceStateEnum.valueOf(context.getServiceState().name()), context.getLogger().getName(), inputQueues, restCallInfoStaticObjectMetric.list() .stream() .map((i) -> new ServiceState.RestRequestState( i.getMethod(), i.getUrl(), currentTimeMillis - i.getStartTime().getTime())) .collect(Collectors.toList()) ); }  @Override ServiceState getServiceState(); }
MicroServiceStateResource extends MicroServiceResource implements MicroServiceStateAPI { @Override public ServiceState getServiceState() { Context context = getMicroServiceApplication().getMicroServiceContext(); List<ServiceState.InputQueueState> inputQueues = new ArrayList<>(); ResourceManager<InputQueueDescriptor, InputQueueConfiguration, ManagedInputQueue> queuesManager = context.getQueuesManager(); List<ManagedInputQueue> managedQueuesStats = queuesManager.getManagedResources(); if (!managedQueuesStats.isEmpty()) { for (ManagedInputQueue currManagedQueue : managedQueuesStats) { List<ServiceState.InputQueueReceiver> receivers = new ArrayList<>(); if (!currManagedQueue.getReceivers().isEmpty()) { for (QueueReceiver currReceiver : currManagedQueue.getReceivers()) { QueueExecutionState currState = ((QueueReceiverImpl) currReceiver).getMessageListener().getQueueExecutionState(); QueueExecutionState.ReceiverRunningState state = currState.getState(); Date lastExecutionTime = null; Date currExecutionStartTime = null; Map<String, String> properties = null; switch (state) { case RUNNING: currExecutionStartTime = new Date(currState.getExecutionStartTime()); Map<String, String> headers = currState.getHeaders(); if (!headers.isEmpty()) { properties = new HashMap<>(headers); } break; case IDLE: Long executionEndTime = currState.getExecutionEndTime(); if (executionEndTime != null) { lastExecutionTime = new Date(executionEndTime); } break; default: break; } receivers.add(new ServiceState.InputQueueReceiver( currState.getState().name(), currState.getInitializedDate(), lastExecutionTime, currExecutionStartTime, properties)); } } inputQueues.add(new ServiceState.InputQueueState(currManagedQueue.getQueueName(), receivers)); } } final StaticObjectMetric<RestCallInfo> restCallInfoStaticObjectMetric = context.getMetricsRegistry().getStaticObjectMetric(RestCallInfo.class); final long currentTimeMillis = System.currentTimeMillis(); return new ServiceState( context.getMicroServiceName(), ServiceState.ServiceStateEnum.valueOf(context.getServiceState().name()), context.getLogger().getName(), inputQueues, restCallInfoStaticObjectMetric.list() .stream() .map((i) -> new ServiceState.RestRequestState( i.getMethod(), i.getUrl(), currentTimeMillis - i.getStartTime().getTime())) .collect(Collectors.toList()) ); }  @Override ServiceState getServiceState();  }