@Test public void testGetMetricsDescriptorForService() throws Exception { AmbariManagementController managementController = createNiceMock(AmbariManagementController.class); expect(managementController.getAmbariMetaInfo()).andReturn(metaInfo).anyTimes(); replay(managementController); StackArtifactResourceProvider resourceProvider = getStackArtifactResourceProvider(managementController); Set<String> propertyIds = new HashSet<String>(); propertyIds.add(ARTIFACT_NAME_PROPERTY_ID); propertyIds.add(STACK_NAME_PROPERTY_ID); propertyIds.add(STACK_VERSION_PROPERTY_ID); propertyIds.add(STACK_SERVICE_NAME_PROPERTY_ID); propertyIds.add(ARTIFACT_DATA_PROPERTY_ID); Request request = PropertyHelper.getReadRequest(propertyIds); Predicate predicate = new PredicateBuilder().property (ARTIFACT_NAME_PROPERTY_ID).equals("metrics_descriptor").and().property (STACK_NAME_PROPERTY_ID).equals("OTHER").and().property (STACK_VERSION_PROPERTY_ID).equals("1.0").and().property (STACK_SERVICE_NAME_PROPERTY_ID).equals("HDFS").toPredicate(); Set<Resource> resources = resourceProvider.getResources(request, predicate); Assert.assertEquals(1, resources.size()); Resource resource = resources.iterator().next(); Map<String, Map<String, Object>> propertyMap = resource.getPropertiesMap(); Map<String, Object> descriptor = propertyMap.get(ARTIFACT_DATA_PROPERTY_ID + "/HDFS/DATANODE"); Assert.assertNotNull(descriptor); Assert.assertEquals(1, ((ArrayList) descriptor.get("Component")).size()); MetricDefinition md = (MetricDefinition) ((ArrayList) descriptor.get("Component")).iterator().next(); Metric m1 = md.getMetrics().get("metrics/dfs/datanode/heartBeats_avg_time"); Metric m2 = md.getMetrics().get("metrics/rpc/closeRegion_num_ops"); Assert.assertEquals(326, md.getMetrics().size()); Assert.assertTrue(m1.isAmsHostMetric()); Assert.assertEquals("unitless", m1.getUnit()); Assert.assertFalse(m2.isAmsHostMetric()); verify(managementController); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> resources = new HashSet<Resource>(); resources.addAll(getKerberosDescriptors(request, predicate)); resources.addAll(getMetricsDescriptors(request, predicate)); resources.addAll(getWidgetsDescriptors(request, predicate)); if (resources.isEmpty()) { throw new NoSuchResourceException( "The requested resource doesn't exist: Artifact not found, " + predicate); } return resources; }
StackArtifactResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> resources = new HashSet<Resource>(); resources.addAll(getKerberosDescriptors(request, predicate)); resources.addAll(getMetricsDescriptors(request, predicate)); resources.addAll(getWidgetsDescriptors(request, predicate)); if (resources.isEmpty()) { throw new NoSuchResourceException( "The requested resource doesn't exist: Artifact not found, " + predicate); } return resources; } }
StackArtifactResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> resources = new HashSet<Resource>(); resources.addAll(getKerberosDescriptors(request, predicate)); resources.addAll(getMetricsDescriptors(request, predicate)); resources.addAll(getWidgetsDescriptors(request, predicate)); if (resources.isEmpty()) { throw new NoSuchResourceException( "The requested resource doesn't exist: Artifact not found, " + predicate); } return resources; } protected  StackArtifactResourceProvider(AmbariManagementController managementController); }
StackArtifactResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> resources = new HashSet<Resource>(); resources.addAll(getKerberosDescriptors(request, predicate)); resources.addAll(getMetricsDescriptors(request, predicate)); resources.addAll(getWidgetsDescriptors(request, predicate)); if (resources.isEmpty()) { throw new NoSuchResourceException( "The requested resource doesn't exist: Artifact not found, " + predicate); } return resources; } protected  StackArtifactResourceProvider(AmbariManagementController managementController); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus createResources(Request request); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); Map<String, Object> getWidgetsDescriptorForService(StackInfo stackInfo, String serviceName); Map<String, Object> getWidgetsDescriptorForCluster(StackInfo stackInfo); }
StackArtifactResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> resources = new HashSet<Resource>(); resources.addAll(getKerberosDescriptors(request, predicate)); resources.addAll(getMetricsDescriptors(request, predicate)); resources.addAll(getWidgetsDescriptors(request, predicate)); if (resources.isEmpty()) { throw new NoSuchResourceException( "The requested resource doesn't exist: Artifact not found, " + predicate); } return resources; } protected  StackArtifactResourceProvider(AmbariManagementController managementController); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus createResources(Request request); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); Map<String, Object> getWidgetsDescriptorForService(StackInfo stackInfo, String serviceName); Map<String, Object> getWidgetsDescriptorForCluster(StackInfo stackInfo); static final String STACK_NAME_PROPERTY_ID; static final String STACK_VERSION_PROPERTY_ID; static final String STACK_SERVICE_NAME_PROPERTY_ID; static final String STACK_COMPONENT_NAME_PROPERTY_ID; static final String ARTIFACT_NAME_PROPERTY_ID; static final String ARTIFACT_DATA_PROPERTY_ID; static Set<String> pkPropertyIds; static Map<Resource.Type, String> keyPropertyIds; static Set<String> propertyIds; static final String KERBEROS_DESCRIPTOR_NAME; static final String METRICS_DESCRIPTOR_NAME; static final String WIDGETS_DESCRIPTOR_NAME; }