@Test public void testGetResources() throws Exception{ AmbariManagementController managementController = EasyMock.createMock(AmbariManagementController.class); RepositoryResponse rr = new RepositoryResponse(VAL_BASE_URL, VAL_OS, VAL_REPO_ID, VAL_REPO_NAME, null, null, null); rr.setStackName(VAL_STACK_NAME); rr.setStackVersion(VAL_STACK_VERSION); Set<RepositoryResponse> allResponse = new HashSet<RepositoryResponse>(); allResponse.add(rr); expect(managementController.getRepositories(EasyMock.<Set<RepositoryRequest>>anyObject())).andReturn(allResponse).times(2); replay(managementController); ResourceProvider provider = new RepositoryResourceProvider(managementController); Set<String> propertyIds = new HashSet<String>(); propertyIds.add(RepositoryResourceProvider.REPOSITORY_STACK_NAME_PROPERTY_ID); propertyIds.add(RepositoryResourceProvider.REPOSITORY_STACK_VERSION_PROPERTY_ID); propertyIds.add(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID); propertyIds.add(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID); propertyIds.add(RepositoryResourceProvider.REPOSITORY_OS_TYPE_PROPERTY_ID); propertyIds.add(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID); propertyIds.add(RepositoryResourceProvider.REPOSITORY_CLUSTER_STACK_VERSION_PROPERTY_ID); Predicate predicate = new PredicateBuilder().property(RepositoryResourceProvider.REPOSITORY_STACK_NAME_PROPERTY_ID).equals(VAL_STACK_NAME) .and().property(RepositoryResourceProvider.REPOSITORY_STACK_VERSION_PROPERTY_ID).equals(VAL_STACK_VERSION) .toPredicate(); Request request = PropertyHelper.getReadRequest(propertyIds); Set<Resource> resources = provider.getResources(request, predicate); Assert.assertEquals(allResponse.size(), resources.size()); for (Resource resource : resources) { Object o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_STACK_NAME_PROPERTY_ID); Assert.assertEquals(VAL_STACK_NAME, o); o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_STACK_VERSION_PROPERTY_ID); Assert.assertEquals(VAL_STACK_VERSION, o); o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID); Assert.assertEquals(o, VAL_REPO_NAME); o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID); Assert.assertEquals(o, VAL_BASE_URL); o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_OS_TYPE_PROPERTY_ID); Assert.assertEquals(o, VAL_OS); o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID); Assert.assertEquals(o, VAL_REPO_ID); o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_CLUSTER_STACK_VERSION_PROPERTY_ID); Assert.assertNull(o); } rr.setClusterVersionId(525L); resources = provider.getResources(request, predicate); Assert.assertEquals(allResponse.size(), resources.size()); for (Resource resource : resources) { Object o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_STACK_NAME_PROPERTY_ID); Assert.assertEquals(VAL_STACK_NAME, o); o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_STACK_VERSION_PROPERTY_ID); Assert.assertEquals(VAL_STACK_VERSION, o); o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID); Assert.assertEquals(o, VAL_REPO_NAME); o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID); Assert.assertEquals(o, VAL_BASE_URL); o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_OS_TYPE_PROPERTY_ID); Assert.assertEquals(o, VAL_OS); o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID); Assert.assertEquals(o, VAL_REPO_ID); o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_CLUSTER_STACK_VERSION_PROPERTY_ID); Assert.assertEquals(525L, o); } verify(managementController); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RepositoryRequest> requests = new HashSet<RepositoryRequest>(); if (predicate == null) { requests.add(getRequest(Collections.<String, Object>emptyMap())); } else { for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequest(propertyMap)); } } Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<RepositoryResponse> responses = getResources(new Command<Set<RepositoryResponse>>() { @Override public Set<RepositoryResponse> invoke() throws AmbariException { return getManagementController().getRepositories(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (RepositoryResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.Repository); setResourceProperty(resource, REPOSITORY_STACK_NAME_PROPERTY_ID, response.getStackName(), requestedIds); setResourceProperty(resource, REPOSITORY_STACK_VERSION_PROPERTY_ID, response.getStackVersion(), requestedIds); setResourceProperty(resource, REPOSITORY_REPO_NAME_PROPERTY_ID, response.getRepoName(), requestedIds); setResourceProperty(resource, REPOSITORY_BASE_URL_PROPERTY_ID, response.getBaseUrl(), requestedIds); setResourceProperty(resource, REPOSITORY_OS_TYPE_PROPERTY_ID, response.getOsType(), requestedIds); setResourceProperty(resource, REPOSITORY_REPO_ID_PROPERTY_ID, response.getRepoId(), requestedIds); setResourceProperty(resource, REPOSITORY_MIRRORS_LIST_PROPERTY_ID, response.getMirrorsList(), requestedIds); setResourceProperty(resource, REPOSITORY_DEFAULT_BASE_URL_PROPERTY_ID, response.getDefaultBaseUrl(), requestedIds); setResourceProperty(resource, REPOSITORY_LATEST_BASE_URL_PROPERTY_ID, response.getLatestBaseUrl(), requestedIds); setResourceProperty(resource, REPOSITORY_UNIQUE_PROPERTY_ID, response.isUnique(), requestedIds); if (null != response.getClusterVersionId()) { setResourceProperty(resource, REPOSITORY_CLUSTER_STACK_VERSION_PROPERTY_ID, response.getClusterVersionId(), requestedIds); } if (null != response.getRepositoryVersionId()) { setResourceProperty(resource, REPOSITORY_REPOSITORY_VERSION_ID_PROPERTY_ID, response.getRepositoryVersionId(), requestedIds); } if (null != response.getVersionDefinitionId()) { setResourceProperty(resource, REPOSITORY_VERSION_DEFINITION_ID_PROPERTY_ID, response.getVersionDefinitionId(), requestedIds); } resources.add(resource); } return resources; }
RepositoryResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RepositoryRequest> requests = new HashSet<RepositoryRequest>(); if (predicate == null) { requests.add(getRequest(Collections.<String, Object>emptyMap())); } else { for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequest(propertyMap)); } } Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<RepositoryResponse> responses = getResources(new Command<Set<RepositoryResponse>>() { @Override public Set<RepositoryResponse> invoke() throws AmbariException { return getManagementController().getRepositories(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (RepositoryResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.Repository); setResourceProperty(resource, REPOSITORY_STACK_NAME_PROPERTY_ID, response.getStackName(), requestedIds); setResourceProperty(resource, REPOSITORY_STACK_VERSION_PROPERTY_ID, response.getStackVersion(), requestedIds); setResourceProperty(resource, REPOSITORY_REPO_NAME_PROPERTY_ID, response.getRepoName(), requestedIds); setResourceProperty(resource, REPOSITORY_BASE_URL_PROPERTY_ID, response.getBaseUrl(), requestedIds); setResourceProperty(resource, REPOSITORY_OS_TYPE_PROPERTY_ID, response.getOsType(), requestedIds); setResourceProperty(resource, REPOSITORY_REPO_ID_PROPERTY_ID, response.getRepoId(), requestedIds); setResourceProperty(resource, REPOSITORY_MIRRORS_LIST_PROPERTY_ID, response.getMirrorsList(), requestedIds); setResourceProperty(resource, REPOSITORY_DEFAULT_BASE_URL_PROPERTY_ID, response.getDefaultBaseUrl(), requestedIds); setResourceProperty(resource, REPOSITORY_LATEST_BASE_URL_PROPERTY_ID, response.getLatestBaseUrl(), requestedIds); setResourceProperty(resource, REPOSITORY_UNIQUE_PROPERTY_ID, response.isUnique(), requestedIds); if (null != response.getClusterVersionId()) { setResourceProperty(resource, REPOSITORY_CLUSTER_STACK_VERSION_PROPERTY_ID, response.getClusterVersionId(), requestedIds); } if (null != response.getRepositoryVersionId()) { setResourceProperty(resource, REPOSITORY_REPOSITORY_VERSION_ID_PROPERTY_ID, response.getRepositoryVersionId(), requestedIds); } if (null != response.getVersionDefinitionId()) { setResourceProperty(resource, REPOSITORY_VERSION_DEFINITION_ID_PROPERTY_ID, response.getVersionDefinitionId(), requestedIds); } resources.add(resource); } return resources; } }
RepositoryResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RepositoryRequest> requests = new HashSet<RepositoryRequest>(); if (predicate == null) { requests.add(getRequest(Collections.<String, Object>emptyMap())); } else { for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequest(propertyMap)); } } Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<RepositoryResponse> responses = getResources(new Command<Set<RepositoryResponse>>() { @Override public Set<RepositoryResponse> invoke() throws AmbariException { return getManagementController().getRepositories(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (RepositoryResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.Repository); setResourceProperty(resource, REPOSITORY_STACK_NAME_PROPERTY_ID, response.getStackName(), requestedIds); setResourceProperty(resource, REPOSITORY_STACK_VERSION_PROPERTY_ID, response.getStackVersion(), requestedIds); setResourceProperty(resource, REPOSITORY_REPO_NAME_PROPERTY_ID, response.getRepoName(), requestedIds); setResourceProperty(resource, REPOSITORY_BASE_URL_PROPERTY_ID, response.getBaseUrl(), requestedIds); setResourceProperty(resource, REPOSITORY_OS_TYPE_PROPERTY_ID, response.getOsType(), requestedIds); setResourceProperty(resource, REPOSITORY_REPO_ID_PROPERTY_ID, response.getRepoId(), requestedIds); setResourceProperty(resource, REPOSITORY_MIRRORS_LIST_PROPERTY_ID, response.getMirrorsList(), requestedIds); setResourceProperty(resource, REPOSITORY_DEFAULT_BASE_URL_PROPERTY_ID, response.getDefaultBaseUrl(), requestedIds); setResourceProperty(resource, REPOSITORY_LATEST_BASE_URL_PROPERTY_ID, response.getLatestBaseUrl(), requestedIds); setResourceProperty(resource, REPOSITORY_UNIQUE_PROPERTY_ID, response.isUnique(), requestedIds); if (null != response.getClusterVersionId()) { setResourceProperty(resource, REPOSITORY_CLUSTER_STACK_VERSION_PROPERTY_ID, response.getClusterVersionId(), requestedIds); } if (null != response.getRepositoryVersionId()) { setResourceProperty(resource, REPOSITORY_REPOSITORY_VERSION_ID_PROPERTY_ID, response.getRepositoryVersionId(), requestedIds); } if (null != response.getVersionDefinitionId()) { setResourceProperty(resource, REPOSITORY_VERSION_DEFINITION_ID_PROPERTY_ID, response.getVersionDefinitionId(), requestedIds); } resources.add(resource); } return resources; } RepositoryResourceProvider(AmbariManagementController managementController); }
RepositoryResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RepositoryRequest> requests = new HashSet<RepositoryRequest>(); if (predicate == null) { requests.add(getRequest(Collections.<String, Object>emptyMap())); } else { for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequest(propertyMap)); } } Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<RepositoryResponse> responses = getResources(new Command<Set<RepositoryResponse>>() { @Override public Set<RepositoryResponse> invoke() throws AmbariException { return getManagementController().getRepositories(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (RepositoryResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.Repository); setResourceProperty(resource, REPOSITORY_STACK_NAME_PROPERTY_ID, response.getStackName(), requestedIds); setResourceProperty(resource, REPOSITORY_STACK_VERSION_PROPERTY_ID, response.getStackVersion(), requestedIds); setResourceProperty(resource, REPOSITORY_REPO_NAME_PROPERTY_ID, response.getRepoName(), requestedIds); setResourceProperty(resource, REPOSITORY_BASE_URL_PROPERTY_ID, response.getBaseUrl(), requestedIds); setResourceProperty(resource, REPOSITORY_OS_TYPE_PROPERTY_ID, response.getOsType(), requestedIds); setResourceProperty(resource, REPOSITORY_REPO_ID_PROPERTY_ID, response.getRepoId(), requestedIds); setResourceProperty(resource, REPOSITORY_MIRRORS_LIST_PROPERTY_ID, response.getMirrorsList(), requestedIds); setResourceProperty(resource, REPOSITORY_DEFAULT_BASE_URL_PROPERTY_ID, response.getDefaultBaseUrl(), requestedIds); setResourceProperty(resource, REPOSITORY_LATEST_BASE_URL_PROPERTY_ID, response.getLatestBaseUrl(), requestedIds); setResourceProperty(resource, REPOSITORY_UNIQUE_PROPERTY_ID, response.isUnique(), requestedIds); if (null != response.getClusterVersionId()) { setResourceProperty(resource, REPOSITORY_CLUSTER_STACK_VERSION_PROPERTY_ID, response.getClusterVersionId(), requestedIds); } if (null != response.getRepositoryVersionId()) { setResourceProperty(resource, REPOSITORY_REPOSITORY_VERSION_ID_PROPERTY_ID, response.getRepositoryVersionId(), requestedIds); } if (null != response.getVersionDefinitionId()) { setResourceProperty(resource, REPOSITORY_VERSION_DEFINITION_ID_PROPERTY_ID, response.getVersionDefinitionId(), requestedIds); } resources.add(resource); } return resources; } RepositoryResourceProvider(AmbariManagementController managementController); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus createResources(Request request); @Override RequestStatus deleteResources(Request request, Predicate predicate); @Override Set<String> getPKPropertyIds(); }
RepositoryResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RepositoryRequest> requests = new HashSet<RepositoryRequest>(); if (predicate == null) { requests.add(getRequest(Collections.<String, Object>emptyMap())); } else { for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequest(propertyMap)); } } Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<RepositoryResponse> responses = getResources(new Command<Set<RepositoryResponse>>() { @Override public Set<RepositoryResponse> invoke() throws AmbariException { return getManagementController().getRepositories(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (RepositoryResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.Repository); setResourceProperty(resource, REPOSITORY_STACK_NAME_PROPERTY_ID, response.getStackName(), requestedIds); setResourceProperty(resource, REPOSITORY_STACK_VERSION_PROPERTY_ID, response.getStackVersion(), requestedIds); setResourceProperty(resource, REPOSITORY_REPO_NAME_PROPERTY_ID, response.getRepoName(), requestedIds); setResourceProperty(resource, REPOSITORY_BASE_URL_PROPERTY_ID, response.getBaseUrl(), requestedIds); setResourceProperty(resource, REPOSITORY_OS_TYPE_PROPERTY_ID, response.getOsType(), requestedIds); setResourceProperty(resource, REPOSITORY_REPO_ID_PROPERTY_ID, response.getRepoId(), requestedIds); setResourceProperty(resource, REPOSITORY_MIRRORS_LIST_PROPERTY_ID, response.getMirrorsList(), requestedIds); setResourceProperty(resource, REPOSITORY_DEFAULT_BASE_URL_PROPERTY_ID, response.getDefaultBaseUrl(), requestedIds); setResourceProperty(resource, REPOSITORY_LATEST_BASE_URL_PROPERTY_ID, response.getLatestBaseUrl(), requestedIds); setResourceProperty(resource, REPOSITORY_UNIQUE_PROPERTY_ID, response.isUnique(), requestedIds); if (null != response.getClusterVersionId()) { setResourceProperty(resource, REPOSITORY_CLUSTER_STACK_VERSION_PROPERTY_ID, response.getClusterVersionId(), requestedIds); } if (null != response.getRepositoryVersionId()) { setResourceProperty(resource, REPOSITORY_REPOSITORY_VERSION_ID_PROPERTY_ID, response.getRepositoryVersionId(), requestedIds); } if (null != response.getVersionDefinitionId()) { setResourceProperty(resource, REPOSITORY_VERSION_DEFINITION_ID_PROPERTY_ID, response.getVersionDefinitionId(), requestedIds); } resources.add(resource); } return resources; } RepositoryResourceProvider(AmbariManagementController managementController); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus createResources(Request request); @Override RequestStatus deleteResources(Request request, Predicate predicate); @Override Set<String> getPKPropertyIds(); static final String REPOSITORY_REPO_NAME_PROPERTY_ID; static final String REPOSITORY_STACK_NAME_PROPERTY_ID; static final String REPOSITORY_STACK_VERSION_PROPERTY_ID; static final String REPOSITORY_CLUSTER_STACK_VERSION_PROPERTY_ID; static final String REPOSITORY_OS_TYPE_PROPERTY_ID; static final String REPOSITORY_BASE_URL_PROPERTY_ID; static final String REPOSITORY_REPO_ID_PROPERTY_ID; static final String REPOSITORY_MIRRORS_LIST_PROPERTY_ID; static final String REPOSITORY_DEFAULT_BASE_URL_PROPERTY_ID; static final String REPOSITORY_VERIFY_BASE_URL_PROPERTY_ID; static final String REPOSITORY_LATEST_BASE_URL_PROPERTY_ID; static final String REPOSITORY_REPOSITORY_VERSION_ID_PROPERTY_ID; static final String REPOSITORY_VERSION_DEFINITION_ID_PROPERTY_ID; static final String REPOSITORY_UNIQUE_PROPERTY_ID; @SuppressWarnings("serial")
  static Set<String> propertyIds; @SuppressWarnings("serial")
  static Map<Type, String> keyPropertyIds; }