/** * Get all resource metadata of the given type that belong to the given account that have the given status. * * @param account Account containing the resources * @param resourceType Type of resource to get * @param status Status of the resources to get. If null, resources of any status are returned. * @return Immutable map of resource name to resource metadata * @throws IOException if there was an error getting the resources */ public Map<String, Set<ResourceMeta>> getAll(Account account, ResourceType resourceType, ResourceStatus status) throws IOException { if (status == null) { return metaStoreService.getResourceTypeView(account, resourceType).getAll(); } return metaStoreService.getResourceTypeView(account, resourceType).getAll(status); }
/** * Get all metadata for versions of the given resource that have the given status. * * @param account Account containing the resource * @param resourceType Type of resource to get * @param name Name of the resource to get * @param status Status of the resources to get. If null, resources of any status are returned. * @return Immutable set of metadata for versions of the given module * @throws IOException if there was an error getting the module versions */ public Set<ResourceMeta> getAll(Account account, ResourceType resourceType, String name, ResourceStatus status) throws IOException { if (status == null) { return metaStoreService.getResourceTypeView(account, resourceType).getAll(name); } return metaStoreService.getResourceTypeView(account, resourceType).getAll(name, status); }
/** * Bootstrap an account's resources by copying what the superadmin has into the account. * * @param account Account to bootstrap */ public void bootstrapResources(Account account) throws IOException { for (ImmutablePair<ResourceType, ResourceTypeSpecification> typePair : getTypesAndFormats(Account.SUPERADMIN)) { ResourceType type = typePair.getFirst(); Map<String, Set<ResourceMeta>> resources = metaStoreService.getResourceTypeView(Account.SUPERADMIN, type).getAll(); for (Set<ResourceMeta> metas : resources.values()) { for (ResourceMeta meta : metas) { LOG.debug("copying version {} of resource {} of type {} from superadmin account to account {}", meta.getVersion(), meta.getName(), type, account); copySuperadminResource(account, type, meta); } } } }
try { PluginResourceTypeView view = metaStoreService.getResourceTypeView(account, resourceType); Set<ResourceMeta> metas = view.getAll(name); for (ResourceMeta meta : metas) { if (meta.getStatus() != ResourceStatus.INACTIVE) {
"mysql", ImmutableSet.<ResourceMeta>of(mysql1, mysql2), "apache", ImmutableSet.<ResourceMeta>of(apache)), ImmutableMap.copyOf(view.getAll()) ); Assert.assertEquals(hadoops, ImmutableSet.copyOf(view.getAll("hadoop"))); Assert.assertEquals(mysqls, ImmutableSet.copyOf(view.getAll("mysql"))); Assert.assertEquals(apaches, ImmutableSet.copyOf(view.getAll("apache"))); "hadoop", ImmutableSet.<ResourceMeta>of(hadoop3), "mysql", ImmutableSet.<ResourceMeta>of(mysql2)), ImmutableMap.copyOf(view.getAll(ResourceStatus.ACTIVE)) ); Assert.assertEquals(Sets.newHashSet(hadoop3), view.getAll("hadoop", ResourceStatus.ACTIVE)); Assert.assertEquals(Sets.newHashSet(mysql2), view.getAll("mysql", ResourceStatus.ACTIVE)); Assert.assertTrue(view.getAll("apache", ResourceStatus.ACTIVE).isEmpty()); "hadoop", ImmutableSet.<ResourceMeta>of(hadoop2), "mysql", ImmutableSet.<ResourceMeta>of(mysql1)), ImmutableMap.copyOf(view.getAll(ResourceStatus.STAGED)) ); Assert.assertEquals(Sets.newHashSet(hadoop2), view.getAll("hadoop", ResourceStatus.STAGED)); Assert.assertEquals(Sets.newHashSet(mysql1), view.getAll("mysql", ResourceStatus.STAGED)); Assert.assertTrue(view.getAll("apache", ResourceStatus.STAGED).isEmpty()); ImmutableMap.<String, Set<ResourceMeta>>of( "apache", ImmutableSet.<ResourceMeta>of(apache)), ImmutableMap.copyOf(view.getAll(ResourceStatus.RECALLED)) ); Assert.assertTrue(view.getAll("hadoop", ResourceStatus.RECALLED).isEmpty());