@Test public void testCreateDryRunByAvailable() throws Exception { AmbariMetaInfo ami = injector.getInstance(AmbariMetaInfo.class); StackManager sm = ami.getStackManager(); int maxWait = 15000; int waitTime = 0; while (waitTime < maxWait && ! sm.haveAllRepoUrlsBeenResolved()) { Thread.sleep(5); waitTime += 5; } if (waitTime >= maxWait) { fail("Latest Repo tasks did not complete"); } Authentication authentication = TestAuthenticationFactory.createAdministrator(); SecurityContextHolder.getContext().setAuthentication(authentication); final ResourceProvider versionProvider = new VersionDefinitionResourceProvider(); Request getRequest = PropertyHelper.getReadRequest("VersionDefinition"); Set<Resource> results = versionProvider.getResources(getRequest, null); Assert.assertEquals(0, results.size()); Map<String, Object> createMap = new HashMap<>(); createMap.put("VersionDefinition/available", "HDP-2.2.0-2.2.1.0"); Map<String, String> infoProps = Collections.singletonMap(Request.DIRECTIVE_DRY_RUN, "true"); Request createRequest = PropertyHelper.getCreateRequest(Collections.singleton(createMap), infoProps); RequestStatus status = versionProvider.createResources(createRequest); Assert.assertEquals(1, status.getAssociatedResources().size()); Resource res = status.getAssociatedResources().iterator().next(); Assert.assertTrue(res.getPropertiesMap().containsKey("")); Map<String, Object> resMap = res.getPropertiesMap().get(""); Assert.assertTrue(resMap.containsKey("operating_systems")); Assert.assertTrue(res.getPropertiesMap().containsKey("VersionDefinition")); Assert.assertEquals("2.2.1.0", res.getPropertyValue("VersionDefinition/repository_version")); Assert.assertNotNull(res.getPropertyValue("VersionDefinition/show_available")); Assert.assertNotNull(res.getPropertyValue("VersionDefinition/validation")); Set<String> validation = (Set<String>) res.getPropertyValue("VersionDefinition/validation"); Assert.assertNotNull(validation); Assert.assertEquals(0, validation.size()); getRequest = PropertyHelper.getReadRequest("VersionDefinition"); results = versionProvider.getResources(getRequest, null); Assert.assertEquals(0, results.size()); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new HashSet<Resource>(); Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate); Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); if (propertyMaps.isEmpty()) { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } else { for (Map<String, Object> propertyMap : propertyMaps) { if (propertyMap.containsKey(SHOW_AVAILABLE) && Boolean.parseBoolean(propertyMap.get(SHOW_AVAILABLE).toString())) { for (Entry<String, VersionDefinitionXml> entry : s_metaInfo.get().getVersionDefinitions().entrySet()) { Resource res = toResource(entry.getKey(), entry.getValue(), requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { String id = (String) propertyMap.get(VERSION_DEF_ID); if (null != id) { if (NumberUtils.isDigits(id)) { RepositoryVersionEntity entity = s_repoVersionDAO.findByPK(Long.parseLong(id)); if (null != entity) { results.add(toResource(entity, requestPropertyIds)); } } else { VersionDefinitionXml xml = s_metaInfo.get().getVersionDefinition(id); if (null == xml) { throw new NoSuchResourceException(String.format("Could not find version %s", id)); } Resource res = toResource(id, xml, requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } } } } return results; }
VersionDefinitionResourceProvider extends AbstractAuthorizedResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new HashSet<Resource>(); Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate); Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); if (propertyMaps.isEmpty()) { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } else { for (Map<String, Object> propertyMap : propertyMaps) { if (propertyMap.containsKey(SHOW_AVAILABLE) && Boolean.parseBoolean(propertyMap.get(SHOW_AVAILABLE).toString())) { for (Entry<String, VersionDefinitionXml> entry : s_metaInfo.get().getVersionDefinitions().entrySet()) { Resource res = toResource(entry.getKey(), entry.getValue(), requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { String id = (String) propertyMap.get(VERSION_DEF_ID); if (null != id) { if (NumberUtils.isDigits(id)) { RepositoryVersionEntity entity = s_repoVersionDAO.findByPK(Long.parseLong(id)); if (null != entity) { results.add(toResource(entity, requestPropertyIds)); } } else { VersionDefinitionXml xml = s_metaInfo.get().getVersionDefinition(id); if (null == xml) { throw new NoSuchResourceException(String.format("Could not find version %s", id)); } Resource res = toResource(id, xml, requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } } } } return results; } }
VersionDefinitionResourceProvider extends AbstractAuthorizedResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new HashSet<Resource>(); Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate); Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); if (propertyMaps.isEmpty()) { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } else { for (Map<String, Object> propertyMap : propertyMaps) { if (propertyMap.containsKey(SHOW_AVAILABLE) && Boolean.parseBoolean(propertyMap.get(SHOW_AVAILABLE).toString())) { for (Entry<String, VersionDefinitionXml> entry : s_metaInfo.get().getVersionDefinitions().entrySet()) { Resource res = toResource(entry.getKey(), entry.getValue(), requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { String id = (String) propertyMap.get(VERSION_DEF_ID); if (null != id) { if (NumberUtils.isDigits(id)) { RepositoryVersionEntity entity = s_repoVersionDAO.findByPK(Long.parseLong(id)); if (null != entity) { results.add(toResource(entity, requestPropertyIds)); } } else { VersionDefinitionXml xml = s_metaInfo.get().getVersionDefinition(id); if (null == xml) { throw new NoSuchResourceException(String.format("Could not find version %s", id)); } Resource res = toResource(id, xml, requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } } } } return results; } VersionDefinitionResourceProvider(); }
VersionDefinitionResourceProvider extends AbstractAuthorizedResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new HashSet<Resource>(); Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate); Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); if (propertyMaps.isEmpty()) { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } else { for (Map<String, Object> propertyMap : propertyMaps) { if (propertyMap.containsKey(SHOW_AVAILABLE) && Boolean.parseBoolean(propertyMap.get(SHOW_AVAILABLE).toString())) { for (Entry<String, VersionDefinitionXml> entry : s_metaInfo.get().getVersionDefinitions().entrySet()) { Resource res = toResource(entry.getKey(), entry.getValue(), requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { String id = (String) propertyMap.get(VERSION_DEF_ID); if (null != id) { if (NumberUtils.isDigits(id)) { RepositoryVersionEntity entity = s_repoVersionDAO.findByPK(Long.parseLong(id)); if (null != entity) { results.add(toResource(entity, requestPropertyIds)); } } else { VersionDefinitionXml xml = s_metaInfo.get().getVersionDefinition(id); if (null == xml) { throw new NoSuchResourceException(String.format("Could not find version %s", id)); } Resource res = toResource(id, xml, requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } } } } return results; } VersionDefinitionResourceProvider(); @Override Set<Resource> getResources(Request request, Predicate predicate); }
VersionDefinitionResourceProvider extends AbstractAuthorizedResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new HashSet<Resource>(); Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate); Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate); if (propertyMaps.isEmpty()) { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } else { for (Map<String, Object> propertyMap : propertyMaps) { if (propertyMap.containsKey(SHOW_AVAILABLE) && Boolean.parseBoolean(propertyMap.get(SHOW_AVAILABLE).toString())) { for (Entry<String, VersionDefinitionXml> entry : s_metaInfo.get().getVersionDefinitions().entrySet()) { Resource res = toResource(entry.getKey(), entry.getValue(), requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { String id = (String) propertyMap.get(VERSION_DEF_ID); if (null != id) { if (NumberUtils.isDigits(id)) { RepositoryVersionEntity entity = s_repoVersionDAO.findByPK(Long.parseLong(id)); if (null != entity) { results.add(toResource(entity, requestPropertyIds)); } } else { VersionDefinitionXml xml = s_metaInfo.get().getVersionDefinition(id); if (null == xml) { throw new NoSuchResourceException(String.format("Could not find version %s", id)); } Resource res = toResource(id, xml, requestPropertyIds, null); res.setProperty(SHOW_AVAILABLE, true); results.add(res); } } else { List<RepositoryVersionEntity> versions = s_repoVersionDAO.findAllDefinitions(); for (RepositoryVersionEntity entity : versions) { results.add(toResource(entity, requestPropertyIds)); } } } } } return results; } VersionDefinitionResourceProvider(); @Override Set<Resource> getResources(Request request, Predicate predicate); static final String VERSION_DEF; static final String VERSION_DEF_BASE64_PROPERTY; static final String VERSION_DEF_STACK_NAME; static final String VERSION_DEF_STACK_VERSION; static final String DIRECTIVE_SKIP_URL_CHECK; static final String SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID; }