AbstractResourceProvider implements ResourceProvider { public static ResourceProvider getResourceProvider(Resource.Type type, ClusterDefinition clusterDefinition) { if (type.equals(Resource.Type.Cluster)) { return new ClusterProvider(clusterDefinition); } else if (type.equals(Resource.Type.Service)) { return new ServiceProvider(clusterDefinition); } else if (type.equals(Resource.Type.Component)) { return new ComponentProvider(clusterDefinition); } else if (type.equals(Resource.Type.Host)) { return new HostProvider(clusterDefinition); } else if (type.equals(Resource.Type.HostComponent)) { return new HostComponentProvider(clusterDefinition); } else if (type.equals(Resource.Type.Request)) { return new RequestProvider(clusterDefinition); } else if (type.equals(Resource.Type.Task)) { return new TaskProvider(clusterDefinition); } else if (type.equals(Resource.Type.Configuration)) { return new ConfigurationProvider(clusterDefinition); } else { return new NoOpProvider(type, clusterDefinition); } } AbstractResourceProvider(Resource.Type type, ClusterDefinition clusterDefinition); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Predicate predicate); @Override Map<Resource.Type, String> getKeyPropertyIds(); @Override Set<String> checkPropertyIds(Set<String> propertyIds); abstract void updateProperties(Resource resource, Request request, Predicate predicate); abstract int updateProperties(Resource resource, Map<String, Object> properties); Resource.Type getType(); static ResourceProvider getResourceProvider(Resource.Type type,
                                                     ClusterDefinition clusterDefinition);  }
@Test public void testGetResourceProvider() throws Exception { ClusterDefinition clusterDefinition = new ClusterDefinition(new TestStateProvider(), new TestClusterDefinitionProvider(), new TestHostInfoProvider()); clusterDefinition.setServiceState("HDFS", "INSTALLED"); for (Resource.Type type : types) { ResourceProvider provider = AbstractResourceProvider.getResourceProvider(type, clusterDefinition); Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest(), null); for (Resource resource : resources) { Assert.assertEquals(type, resource.getType()); } } }