@Test public void testUpdateResources() throws Exception { Resource.Type type = Resource.Type.Repository; AmbariManagementController managementController = EasyMock.createMock(AmbariManagementController.class); RepositoryResponse rr = new RepositoryResponse(VAL_BASE_URL, VAL_OS, VAL_REPO_ID, VAL_REPO_NAME, null, null ,null); Set<RepositoryResponse> allResponse = new HashSet<RepositoryResponse>(); allResponse.add(rr); expect(managementController.getRepositories(EasyMock.<Set<RepositoryRequest>>anyObject())).andReturn(allResponse).times(1); managementController.updateRepositories(EasyMock.<Set<RepositoryRequest>>anyObject()); replay(managementController); ResourceProvider provider = new RepositoryResourceProvider(managementController); Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID, "http: Request request = PropertyHelper.getUpdateRequest(properties, null); 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(); provider.updateResources(request, predicate); verify(managementController); }
@Override public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RepositoryRequest> requests = new HashSet<RepositoryRequest>(); Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { for (Map<String, Object> propertyMap : getPropertyMaps(iterator.next(), predicate)) { requests.add(getRequest(propertyMap)); } } modifyResources(new Command<Void>() { @Override public Void invoke() throws AmbariException { getManagementController().updateRepositories(requests); return null; } }); return getRequestStatus(null); }
RepositoryResourceProvider extends AbstractControllerResourceProvider { @Override public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RepositoryRequest> requests = new HashSet<RepositoryRequest>(); Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { for (Map<String, Object> propertyMap : getPropertyMaps(iterator.next(), predicate)) { requests.add(getRequest(propertyMap)); } } modifyResources(new Command<Void>() { @Override public Void invoke() throws AmbariException { getManagementController().updateRepositories(requests); return null; } }); return getRequestStatus(null); } }
RepositoryResourceProvider extends AbstractControllerResourceProvider { @Override public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RepositoryRequest> requests = new HashSet<RepositoryRequest>(); Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { for (Map<String, Object> propertyMap : getPropertyMaps(iterator.next(), predicate)) { requests.add(getRequest(propertyMap)); } } modifyResources(new Command<Void>() { @Override public Void invoke() throws AmbariException { getManagementController().updateRepositories(requests); return null; } }); return getRequestStatus(null); } RepositoryResourceProvider(AmbariManagementController managementController); }
RepositoryResourceProvider extends AbstractControllerResourceProvider { @Override public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RepositoryRequest> requests = new HashSet<RepositoryRequest>(); Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { for (Map<String, Object> propertyMap : getPropertyMaps(iterator.next(), predicate)) { requests.add(getRequest(propertyMap)); } } modifyResources(new Command<Void>() { @Override public Void invoke() throws AmbariException { getManagementController().updateRepositories(requests); return null; } }); return getRequestStatus(null); } 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 RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RepositoryRequest> requests = new HashSet<RepositoryRequest>(); Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { for (Map<String, Object> propertyMap : getPropertyMaps(iterator.next(), predicate)) { requests.add(getRequest(propertyMap)); } } modifyResources(new Command<Void>() { @Override public Void invoke() throws AmbariException { getManagementController().updateRepositories(requests); return null; } }); return getRequestStatus(null); } 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; }