/** * Recall the given resource for the given account. A no-op if there is no staged version. * * @param account Account that contains the resource * @param resourceType Type of resource to deactivate * @param name Name of the resource to deactivate * @param version Version of resource to stage * @throws MissingEntityException if there is no such module * @throws IOException if there was an error deactivating all versions of the module */ public void recall(Account account, ResourceType resourceType, String name, int version) throws MissingEntityException, IOException { LOG.debug("Recalling version {} of resource {} of type {} for account {}.", version, name, resourceType, account); Lock lock = getResourceLock(account, resourceType, name); lock.lock(); try { PluginResourceTypeView view = metaStoreService.getResourceTypeView(account, resourceType); if (!view.exists(name, version)) { throw new MissingEntityException("Resource " + name + " does not exist."); } view.recall(name, version); } finally { lock.unlock(); } }
/** * Atomically stage the specified resource version for the given account and recall the previous staged version. * A staged version will get pushed to provisioners during a sync, and will stay staged unless explicitly recalled. * * @param account Account that contains the resource * @param resourceType Type of resource to stage * @param name Name of resource to stage * @param version Version of resource to stage * @throws MissingEntityException if there is no such resource version * @throws IOException if there was an error staging the resource */ public void stage(Account account, ResourceType resourceType, String name, int version) throws MissingEntityException, IOException { LOG.debug("staging version {} of resource {} of type {} for account {}.", version, name, resourceType, account); Lock lock = getResourceLock(account, resourceType, name); lock.lock(); try { PluginResourceTypeView view = metaStoreService.getResourceTypeView(account, resourceType); if (!view.exists(name, version)) { throw new MissingEntityException("Resource does not exist."); } view.stage(name, version); } finally { lock.unlock(); } }
if (!metaView.exists(name, version)) { metaView.add(meta);
@Test public void testAccountSeparation() throws Exception { PluginMetaStoreService service = getPluginResourceMetaStoreService(); PluginResourceTypeView view1 = service.getResourceTypeView(account1, type1); PluginResourceTypeView view2 = service.getResourceTypeView(account2, type1); String name = "name"; int version = 1; ResourceMeta meta = new ResourceMeta(name, version); view1.add(meta); Assert.assertTrue(view1.exists(name, version)); Assert.assertFalse(view2.exists(name, version)); Assert.assertEquals(meta, view1.get(name, version)); Assert.assertNull(view2.get(name, version)); view2.add(meta); Assert.assertTrue(view1.exists(name, version)); Assert.assertTrue(view2.exists(name, version)); Assert.assertEquals(meta, view1.get(name, version)); Assert.assertEquals(meta, view2.get(name, version)); view1.delete(name, version); Assert.assertFalse(view1.exists(name, version)); Assert.assertTrue(view2.exists(name, version)); Assert.assertNull(view1.get(name, version)); Assert.assertEquals(meta, view2.get(name, version)); view2.delete(name, version); Assert.assertFalse(view1.exists(name, version)); Assert.assertFalse(view2.exists(name, version)); Assert.assertNull(view1.get(name, version)); Assert.assertNull(view2.get(name, version)); }
@Test public void testTypeSeparation() throws Exception { PluginMetaStoreService service = getPluginResourceMetaStoreService(); PluginResourceTypeView view1 = service.getResourceTypeView(account1, type1); PluginResourceTypeView view2 = service.getResourceTypeView(account1, type2); String name = "name"; int version = 1; ResourceMeta meta = new ResourceMeta(name, version); view1.add(meta); Assert.assertTrue(view1.exists(name, version)); Assert.assertFalse(view2.exists(name, version)); Assert.assertEquals(meta, view1.get(name, version)); Assert.assertNull(view2.get(name, version)); view2.add(meta); Assert.assertTrue(view1.exists(name, version)); Assert.assertTrue(view2.exists(name, version)); Assert.assertEquals(meta, view1.get(name, version)); Assert.assertEquals(meta, view2.get(name, version)); view1.delete(name, version); Assert.assertFalse(view1.exists(name, version)); Assert.assertTrue(view2.exists(name, version)); Assert.assertNull(view1.get(name, version)); Assert.assertEquals(meta, view2.get(name, version)); view2.delete(name, version); Assert.assertFalse(view1.exists(name, version)); Assert.assertFalse(view2.exists(name, version)); Assert.assertNull(view1.get(name, version)); Assert.assertNull(view2.get(name, version)); }
@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)); }