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; }
@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); }
@Test public void testGetMetricsDescriptorRpcForNamenode() 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/NAMENODE"); Assert.assertNotNull(descriptor); Assert.assertEquals(2, ((ArrayList) descriptor.get("Component")).size()); MetricDefinition md = (MetricDefinition) ((ArrayList) descriptor.get("Component")).iterator().next(); Assert.assertEquals("rpcdetailed.rpcdetailed.client.BlockReceivedAndDeletedAvgTime", md.getMetrics().get("metrics/rpcdetailed/client/blockReceived_avg_time").getName()); Assert.assertEquals("rpc.rpc.healthcheck.CallQueueLength", md.getMetrics().get("metrics/rpc/healthcheck/callQueueLen").getName()); Assert.assertEquals("rpcdetailed.rpcdetailed.datanode.DeleteNumOps", md.getMetrics().get("metrics/rpcdetailed/datanode/delete_num_ops").getName()); verify(managementController); }
@Test @SuppressWarnings("unchecked") public void testGetWidgetDescriptorForService() 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("widgets_descriptor").and().property (STACK_NAME_PROPERTY_ID).equals("OTHER").and().property (STACK_VERSION_PROPERTY_ID).equals("2.0").and().property (STACK_SERVICE_NAME_PROPERTY_ID).equals("HBASE").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); Assert.assertNotNull(descriptor); Assert.assertEquals(1, ((List<Object>) descriptor.get("layouts")).size()); WidgetLayout layout = ((List<WidgetLayout>) descriptor.get("layouts")).iterator().next(); Assert.assertEquals("default_hbase_layout", layout.getLayoutName()); Assert.assertEquals("HBASE_SUMMARY", layout.getSectionName()); Assert.assertEquals(5, layout.getWidgetLayoutInfoList().size()); verify(managementController); }