@Test public void testGetResources() throws Exception { String hostname = "host1"; String clustername = "Cluster100"; Predicate predicate = new PredicateBuilder().begin() .property(HostStackVersionResourceProvider.HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID).equals(hostname) .and() .property(HostStackVersionResourceProvider.HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID).equals(clustername) .end().and().begin() .property(HostStackVersionResourceProvider.HOST_STACK_VERSION_STATE_PROPERTY_ID).equals("INSTALLING") .or() .property(HostStackVersionResourceProvider.HOST_STACK_VERSION_STATE_PROPERTY_ID).equals("INSTALL_FAILED") .or() .property(HostStackVersionResourceProvider.HOST_STACK_VERSION_STATE_PROPERTY_ID).equals("OUT_OF_SYNC") .end().toPredicate(); Request request = PropertyHelper.getCreateRequest(Collections.<Map<String,Object>>emptySet(), null); ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider( type, PropertyHelper.getPropertyIds(type), PropertyHelper.getKeyPropertyIds(type), managementController); expect(hostVersionDAOMock.findByClusterAndHost(clustername, hostname)).andReturn(Collections.singletonList(hostVersionEntityMock)); expect(hostVersionEntityMock.getRepositoryVersion()).andReturn(repoVersion).anyTimes(); expect(repositoryVersionDAOMock.findByStackAndVersion(isA(StackId.class), isA(String.class))).andReturn(null).anyTimes(); expect(hostVersionEntityMock.getState()).andReturn(RepositoryVersionState.INSTALLING).anyTimes(); replay(hostVersionDAOMock, hostVersionEntityMock, repositoryVersionDAOMock); Set<Resource> resources = provider.getResources(request, predicate); assertEquals(1, resources.size()); verify(hostVersionDAOMock, hostVersionEntityMock, repositoryVersionDAOMock); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<Resource> resources = new HashSet<>(); final Set<String> requestedIds = getRequestPropertyIds(request, predicate); final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); for (Map<String, Object> propertyMap: propertyMaps) { final String hostName = propertyMap.get(HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID).toString(); String clusterName = null; if (propertyMap.containsKey(HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID)) { clusterName = propertyMap.get(HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID).toString(); } final Long id; List<HostVersionEntity> requestedEntities; if (propertyMap.get(HOST_STACK_VERSION_ID_PROPERTY_ID) == null) { if (clusterName == null) { requestedEntities = hostVersionDAO.findByHost(hostName); } else { requestedEntities = hostVersionDAO.findByClusterAndHost(clusterName, hostName); } } else { try { id = Long.parseLong(propertyMap.get(HOST_STACK_VERSION_ID_PROPERTY_ID).toString()); } catch (Exception ex) { throw new SystemException("Stack version should have numerical id"); } final HostVersionEntity entity = hostVersionDAO.findByPK(id); if (entity == null) { throw new NoSuchResourceException("There is no stack version with id " + id); } else { requestedEntities = Collections.singletonList(entity); } } if (requestedEntities != null) { addRequestedEntities(resources, requestedEntities, requestedIds, clusterName); } } return resources; }
HostStackVersionResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<Resource> resources = new HashSet<>(); final Set<String> requestedIds = getRequestPropertyIds(request, predicate); final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); for (Map<String, Object> propertyMap: propertyMaps) { final String hostName = propertyMap.get(HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID).toString(); String clusterName = null; if (propertyMap.containsKey(HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID)) { clusterName = propertyMap.get(HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID).toString(); } final Long id; List<HostVersionEntity> requestedEntities; if (propertyMap.get(HOST_STACK_VERSION_ID_PROPERTY_ID) == null) { if (clusterName == null) { requestedEntities = hostVersionDAO.findByHost(hostName); } else { requestedEntities = hostVersionDAO.findByClusterAndHost(clusterName, hostName); } } else { try { id = Long.parseLong(propertyMap.get(HOST_STACK_VERSION_ID_PROPERTY_ID).toString()); } catch (Exception ex) { throw new SystemException("Stack version should have numerical id"); } final HostVersionEntity entity = hostVersionDAO.findByPK(id); if (entity == null) { throw new NoSuchResourceException("There is no stack version with id " + id); } else { requestedEntities = Collections.singletonList(entity); } } if (requestedEntities != null) { addRequestedEntities(resources, requestedEntities, requestedIds, clusterName); } } return resources; } }
HostStackVersionResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<Resource> resources = new HashSet<>(); final Set<String> requestedIds = getRequestPropertyIds(request, predicate); final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); for (Map<String, Object> propertyMap: propertyMaps) { final String hostName = propertyMap.get(HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID).toString(); String clusterName = null; if (propertyMap.containsKey(HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID)) { clusterName = propertyMap.get(HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID).toString(); } final Long id; List<HostVersionEntity> requestedEntities; if (propertyMap.get(HOST_STACK_VERSION_ID_PROPERTY_ID) == null) { if (clusterName == null) { requestedEntities = hostVersionDAO.findByHost(hostName); } else { requestedEntities = hostVersionDAO.findByClusterAndHost(clusterName, hostName); } } else { try { id = Long.parseLong(propertyMap.get(HOST_STACK_VERSION_ID_PROPERTY_ID).toString()); } catch (Exception ex) { throw new SystemException("Stack version should have numerical id"); } final HostVersionEntity entity = hostVersionDAO.findByPK(id); if (entity == null) { throw new NoSuchResourceException("There is no stack version with id " + id); } else { requestedEntities = Collections.singletonList(entity); } } if (requestedEntities != null) { addRequestedEntities(resources, requestedEntities, requestedIds, clusterName); } } return resources; } HostStackVersionResourceProvider(
          AmbariManagementController managementController); }
HostStackVersionResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<Resource> resources = new HashSet<>(); final Set<String> requestedIds = getRequestPropertyIds(request, predicate); final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); for (Map<String, Object> propertyMap: propertyMaps) { final String hostName = propertyMap.get(HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID).toString(); String clusterName = null; if (propertyMap.containsKey(HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID)) { clusterName = propertyMap.get(HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID).toString(); } final Long id; List<HostVersionEntity> requestedEntities; if (propertyMap.get(HOST_STACK_VERSION_ID_PROPERTY_ID) == null) { if (clusterName == null) { requestedEntities = hostVersionDAO.findByHost(hostName); } else { requestedEntities = hostVersionDAO.findByClusterAndHost(clusterName, hostName); } } else { try { id = Long.parseLong(propertyMap.get(HOST_STACK_VERSION_ID_PROPERTY_ID).toString()); } catch (Exception ex) { throw new SystemException("Stack version should have numerical id"); } final HostVersionEntity entity = hostVersionDAO.findByPK(id); if (entity == null) { throw new NoSuchResourceException("There is no stack version with id " + id); } else { requestedEntities = Collections.singletonList(entity); } } if (requestedEntities != null) { addRequestedEntities(resources, requestedEntities, requestedIds, clusterName); } } return resources; } HostStackVersionResourceProvider(
          AmbariManagementController managementController); @Override Set<Resource> getResources(Request request, Predicate predicate); void addRequestedEntities(Set<Resource> resources,
                                   List<HostVersionEntity> requestedEntities,
                                   Set<String> requestedIds,
                                   String clusterName); @Override RequestStatus createResources(Request request); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); }
HostStackVersionResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<Resource> resources = new HashSet<>(); final Set<String> requestedIds = getRequestPropertyIds(request, predicate); final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); for (Map<String, Object> propertyMap: propertyMaps) { final String hostName = propertyMap.get(HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID).toString(); String clusterName = null; if (propertyMap.containsKey(HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID)) { clusterName = propertyMap.get(HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID).toString(); } final Long id; List<HostVersionEntity> requestedEntities; if (propertyMap.get(HOST_STACK_VERSION_ID_PROPERTY_ID) == null) { if (clusterName == null) { requestedEntities = hostVersionDAO.findByHost(hostName); } else { requestedEntities = hostVersionDAO.findByClusterAndHost(clusterName, hostName); } } else { try { id = Long.parseLong(propertyMap.get(HOST_STACK_VERSION_ID_PROPERTY_ID).toString()); } catch (Exception ex) { throw new SystemException("Stack version should have numerical id"); } final HostVersionEntity entity = hostVersionDAO.findByPK(id); if (entity == null) { throw new NoSuchResourceException("There is no stack version with id " + id); } else { requestedEntities = Collections.singletonList(entity); } } if (requestedEntities != null) { addRequestedEntities(resources, requestedEntities, requestedIds, clusterName); } } return resources; } HostStackVersionResourceProvider(
          AmbariManagementController managementController); @Override Set<Resource> getResources(Request request, Predicate predicate); void addRequestedEntities(Set<Resource> resources,
                                   List<HostVersionEntity> requestedEntities,
                                   Set<String> requestedIds,
                                   String clusterName); @Override RequestStatus createResources(Request request); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate);  }