/** * Update the metadata store, syncing the resources in the given collection for the given account. * * @param account Account containing resources to sync * @param resourceCollection Collection of synced resources * @throws IOException */ public void syncResourceMeta(Account account, ResourceCollection resourceCollection) throws IOException { metaStoreService.getAccountView(account).syncResources(resourceCollection); }
@Override public PluginResourceTypeView getResourceTypeView(Account account, ResourceType type) { return getAccountView(account).getResourceTypeView(type); } }
@Override protected void startUp() throws Exception { pluginStore.initialize(conf); metaStoreService.startAndWait(); }
@Test public void testGetNumResources() throws Exception { PluginMetaStoreService service = getPluginResourceMetaStoreService(); // for account1 write 6 resources (7 but one is deleted) in all different states service.getResourceTypeView(account1, type1).add(new ResourceMeta("r1", 1, ResourceStatus.ACTIVE)); service.getResourceTypeView(account1, type1).add(new ResourceMeta("r1", 2, ResourceStatus.INACTIVE)); service.getResourceTypeView(account1, type1).add(new ResourceMeta("r2", 1, ResourceStatus.INACTIVE)); service.getResourceTypeView(account1, type1).add(new ResourceMeta("r2", 2, ResourceStatus.STAGED)); service.getResourceTypeView(account1, type2).add(new ResourceMeta("r3", 1, ResourceStatus.RECALLED)); service.getResourceTypeView(account1, type2).add(new ResourceMeta("r3", 2, ResourceStatus.STAGED)); service.getResourceTypeView(account1, type2).add(new ResourceMeta("r3", 3, ResourceStatus.STAGED)); service.getResourceTypeView(account1, type2).delete("r3", 3); Assert.assertEquals(6, service.getAccountView(account1).numResources()); // account 2 should have nothing Assert.assertEquals(0, service.getAccountView(account2).numResources()); }
@Test public void testWriteDeleteExistsGetWithinAccount() throws Exception { PluginMetaStoreService service = getPluginResourceMetaStoreService(); PluginResourceTypeView view = service.getResourceTypeView(account1, type1); String name = "name"; int version = 1; ResourceMeta meta = new ResourceMeta(name, version); view.add(meta); Assert.assertTrue(view.exists(name, version)); Assert.assertEquals(meta, view.get(name, version)); view.delete(name, version); Assert.assertFalse(view.exists(name, version)); Assert.assertNull(view.get(name, version)); }
@Test public void testStageOnNothingIsNoOp() throws Exception { PluginMetaStoreService service = getPluginResourceMetaStoreService(); PluginResourceTypeView view = service.getResourceTypeView(account1, type1); ResourceMeta hadoop = new ResourceMeta("hadoop", 1, ResourceStatus.STAGED); view.add(hadoop); // if we stage a non-existent version, the current staged version should not be affected view.stage(hadoop.getName(), hadoop.getVersion() + 1); Assert.assertEquals(ResourceStatus.STAGED, view.get(hadoop.getName(), hadoop.getVersion()).getStatus()); }
@Test public void testWriteGetDeleteProvisioner() throws IOException { ProvisionerStore store = getProvisionerStore(); String id = provisioner1.getId(); Assert.assertNull(store.getProvisioner(id)); store.writeProvisioner(provisioner1); Assert.assertEquals(provisioner1, store.getProvisioner(id)); store.deleteProvisioner(id); Assert.assertNull(store.getProvisioner(id)); }
/** * 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 the number of all versions of all resources in the account. Resources can be in any state. * * @param account Account to get the number of resources for * @return Number of resources in the account * @throws IOException */ public int numResources(Account account) throws IOException { return metaStoreService.getAccountView(account).numResources(); }
/** * Get the provisioner for the given id for external display, with tenant ids mapped to tenant names, * or null if none exists. * * @param provisionerId Id of the provisioner to get * @return Provisioner for the given id with tenant ids mapped to tenant names, or null if none exists * @throws IOException */ public Provisioner getProvisioner(String provisionerId) throws IOException { return createExternalProvisioner(provisionerStore.getProvisioner(provisionerId)); }
private void checkCapacity(int diff) throws IOException, CapacityException { if (diff > provisionerStore.getFreeCapacity()) { throw new CapacityException("Not enough capacity."); } } }
@Override public PluginResourceTypeView getResourceTypeView(ResourceType type) { return new SQLPluginResourceTypeView(dbConnectionPool, dbQueryExecutor, account, type); }
@Override protected void shutDown() throws Exception { metaStoreService.stopAndWait(); }
private void setConstantFields(PreparedStatement statement) throws SQLException { setConstantFields(statement, 1); }
@Override public void deleteResource(Account account, ResourceType type, String name, int version) throws IOException { File file = getFile(account, type, name, version); if (file.exists()) { // TODO: delete directory structure if empty file.delete(); } }
@Override void clearData() throws Exception { service.clearData(); } }
@Override PluginStore getInitializedStore() { store.initialize(conf); return store; }
@Override void clearData() throws Exception { store.clearData(); } }
@Override void clearData() { store.clearData(); } }
/** * 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); }