HostComponentResourceProvider extends AbstractControllerResourceProvider { @Override public Set<String> checkPropertyIds(Set<String> propertyIds) { propertyIds = super.checkPropertyIds(propertyIds); if (propertyIds.isEmpty()) { return propertyIds; } Set<String> unsupportedProperties = new HashSet<String>(); for (String propertyId : propertyIds) { if (!propertyId.equals("config")) { String propertyCategory = PropertyHelper.getPropertyCategory(propertyId); if (propertyCategory == null || !propertyCategory.equals("config")) { unsupportedProperties.add(propertyId); } } } return unsupportedProperties; } @AssistedInject  HostComponentResourceProvider(@Assisted Set<String> propertyIds,
                                       @Assisted Map<Resource.Type, String> keyPropertyIds,
                                       @Assisted AmbariManagementController managementController,
                                       Injector injector); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(final Request request, Predicate predicate); @Override Set<String> checkPropertyIds(Set<String> propertyIds); RequestStatusResponse install(String cluster, String hostname, Collection<String> skipInstallForComponents, Collection<String> dontSkipInstallForComponents, boolean skipFailure); RequestStatusResponse start(String cluster, String hostName); RequestStatusResponse start(String cluster, String hostName, Collection<String> installOnlyComponents, boolean skipFailure); boolean isDirectTransition(State oldState, State newState); static final String HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID; static final String HOST_COMPONENT_SERVICE_NAME_PROPERTY_ID; static final String HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID; static final String HOST_COMPONENT_DISPLAY_NAME_PROPERTY_ID; static final String HOST_COMPONENT_HOST_NAME_PROPERTY_ID; static final String HOST_COMPONENT_PUBLIC_HOST_NAME_PROPERTY_ID; static final String HOST_COMPONENT_STATE_PROPERTY_ID; static final String HOST_COMPONENT_DESIRED_STATE_PROPERTY_ID; static final String HOST_COMPONENT_STACK_ID_PROPERTY_ID; static final String HOST_COMPONENT_DESIRED_STACK_ID_PROPERTY_ID; static final String HOST_COMPONENT_ACTUAL_CONFIGS_PROPERTY_ID; static final String HOST_COMPONENT_STALE_CONFIGS_PROPERTY_ID; static final String HOST_COMPONENT_DESIRED_ADMIN_STATE_PROPERTY_ID; static final String HOST_COMPONENT_MAINTENANCE_STATE_PROPERTY_ID; static final String HOST_COMPONENT_HDP_VERSION_PROPERTY_ID; static final String HOST_COMPONENT_UPGRADE_STATE_PROPERTY_ID; }
@Test public void testCheckPropertyIds() throws Exception { Set<String> propertyIds = new HashSet<String>(); propertyIds.add("foo"); propertyIds.add("cat1/foo"); propertyIds.add("cat2/bar"); propertyIds.add("cat2/baz"); propertyIds.add("cat3/sub1/bam"); propertyIds.add("cat4/sub2/sub3/bat"); propertyIds.add("cat5/subcat5/map"); Map<Resource.Type, String> keyPropertyIds = new HashMap<Resource.Type, String>(); AmbariManagementController managementController = createMock(AmbariManagementController.class); Injector injector = createNiceMock(Injector.class); HostComponentResourceProvider provider = new HostComponentResourceProvider(propertyIds, keyPropertyIds, managementController, injector); Set<String> unsupported = provider.checkPropertyIds(Collections.singleton("foo")); Assert.assertTrue(unsupported.isEmpty()); Assert.assertTrue(provider.checkPropertyIds(Collections.singleton("cat5/subcat5/map/key")).isEmpty()); unsupported = provider.checkPropertyIds(Collections.singleton("bar")); Assert.assertEquals(1, unsupported.size()); Assert.assertTrue(unsupported.contains("bar")); unsupported = provider.checkPropertyIds(Collections.singleton("cat1/foo")); Assert.assertTrue(unsupported.isEmpty()); unsupported = provider.checkPropertyIds(Collections.singleton("cat1")); Assert.assertTrue(unsupported.isEmpty()); unsupported = provider.checkPropertyIds(Collections.singleton("config")); Assert.assertTrue(unsupported.isEmpty()); unsupported = provider.checkPropertyIds(Collections.singleton("config/unknown_property")); Assert.assertTrue(unsupported.isEmpty()); }