@Test public void testParseStructuredOutput() { Resource.Type type = Resource.Type.Task; AmbariManagementController managementController = createMock(AmbariManagementController.class); TaskResourceProvider taskResourceProvider = new TaskResourceProvider( PropertyHelper.getPropertyIds(type), PropertyHelper.getKeyPropertyIds(type), managementController); replay(managementController); Map<?, ?> result = taskResourceProvider .parseStructuredOutput("{\"a\":\"b\", \"c\": {\"d\":\"e\",\"f\": [\"g\",\"h\"],\"i\": {\"k\":\"l\"}}}"); assertEquals(result.size(), 2); Map<?, ?> submap = (Map<?, ?>) result.get("c"); assertEquals(submap.size(), 3); List sublist = (List) submap.get("f"); assertEquals(sublist.size(), 2); Map<?, ?> subsubmap = (Map<?, ?>) submap.get("i"); assertEquals(subsubmap.size(), 1); assertEquals(subsubmap.get("k"), "l"); result = taskResourceProvider.parseStructuredOutput("{\"a\": invalid JSON}"); assertNull(result); result = taskResourceProvider.parseStructuredOutput("{\"a\": 5}"); assertEquals(result.get("a"), 5); verify(managementController); }
Map<?, ?> parseStructuredOutput(String structuredOutput) { if (null == structuredOutput || structuredOutput.isEmpty()) { return null; } Map<?, ?> result = null; try { result = mapper.readValue(structuredOutput, Map.class); } catch (Exception excepton) { LOG.warn("Unable to parse task structured output: {}", structuredOutput); } return result; }
TaskResourceProvider extends AbstractControllerResourceProvider { Map<?, ?> parseStructuredOutput(String structuredOutput) { if (null == structuredOutput || structuredOutput.isEmpty()) { return null; } Map<?, ?> result = null; try { result = mapper.readValue(structuredOutput, Map.class); } catch (Exception excepton) { LOG.warn("Unable to parse task structured output: {}", structuredOutput); } return result; } }
TaskResourceProvider extends AbstractControllerResourceProvider { Map<?, ?> parseStructuredOutput(String structuredOutput) { if (null == structuredOutput || structuredOutput.isEmpty()) { return null; } Map<?, ?> result = null; try { result = mapper.readValue(structuredOutput, Map.class); } catch (Exception excepton) { LOG.warn("Unable to parse task structured output: {}", structuredOutput); } return result; } TaskResourceProvider(Set<String> propertyIds,
                       Map<Resource.Type, String> keyPropertyIds,
                       AmbariManagementController managementController); }
TaskResourceProvider extends AbstractControllerResourceProvider { Map<?, ?> parseStructuredOutput(String structuredOutput) { if (null == structuredOutput || structuredOutput.isEmpty()) { return null; } Map<?, ?> result = null; try { result = mapper.readValue(structuredOutput, Map.class); } catch (Exception excepton) { LOG.warn("Unable to parse task structured output: {}", structuredOutput); } return result; } TaskResourceProvider(Set<String> propertyIds,
                       Map<Resource.Type, String> keyPropertyIds,
                       AmbariManagementController managementController); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); }
TaskResourceProvider extends AbstractControllerResourceProvider { Map<?, ?> parseStructuredOutput(String structuredOutput) { if (null == structuredOutput || structuredOutput.isEmpty()) { return null; } Map<?, ?> result = null; try { result = mapper.readValue(structuredOutput, Map.class); } catch (Exception excepton) { LOG.warn("Unable to parse task structured output: {}", structuredOutput); } return result; } TaskResourceProvider(Set<String> propertyIds,
                       Map<Resource.Type, String> keyPropertyIds,
                       AmbariManagementController managementController); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); static final String TASK_CLUSTER_NAME_PROPERTY_ID; static final String TASK_REQUEST_ID_PROPERTY_ID; static final String TASK_ID_PROPERTY_ID; static final String TASK_STAGE_ID_PROPERTY_ID; static final String TASK_HOST_NAME_PROPERTY_ID; static final String TASK_ROLE_PROPERTY_ID; static final String TASK_COMMAND_PROPERTY_ID; static final String TASK_STATUS_PROPERTY_ID; static final String TASK_EXIT_CODE_PROPERTY_ID; static final String TASK_STDERR_PROPERTY_ID; static final String TASK_STOUT_PROPERTY_ID; static final String TASK_OUTPUTLOG_PROPERTY_ID; static final String TASK_ERRORLOG_PROPERTY_ID; static final String TASK_STRUCT_OUT_PROPERTY_ID; static final String TASK_START_TIME_PROPERTY_ID; static final String TASK_END_TIME_PROPERTY_ID; static final String TASK_ATTEMPT_CNT_PROPERTY_ID; static final String TASK_COMMAND_DET_PROPERTY_ID; static final String TASK_CUST_CMD_NAME_PROPERTY_ID; }