/** * 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(); } }
@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()); }
view.stage(mysql.getName(), mysql.getVersion()); Assert.assertEquals(ResourceStatus.STAGED, view.get(mysql.getName(), mysql.getVersion()).getStatus()); view.stage(apache.getName(), apache.getVersion()); Assert.assertEquals(ResourceStatus.ACTIVE, view.get(apache.getName(), apache.getVersion()).getStatus()); view.stage(hadoop2.getName(), hadoop2.getVersion()); Assert.assertEquals(ResourceStatus.INACTIVE, view.get(hadoop1.getName(), hadoop1.getVersion()).getStatus()); Assert.assertEquals(ResourceStatus.ACTIVE, view.get(hadoop2.getName(), hadoop2.getVersion()).getStatus()); view.stage(hadoop1.getName(), hadoop1.getVersion()); Assert.assertEquals(ResourceStatus.STAGED, view.get(hadoop1.getName(), hadoop1.getVersion()).getStatus()); Assert.assertEquals(ResourceStatus.RECALLED, view.get(hadoop2.getName(), hadoop2.getVersion()).getStatus()); view.stage(hadoop3.getName(), hadoop3.getVersion()); Assert.assertEquals(ResourceStatus.INACTIVE, view.get(hadoop1.getName(), hadoop1.getVersion()).getStatus()); Assert.assertEquals(ResourceStatus.RECALLED, view.get(hadoop2.getName(), hadoop2.getVersion()).getStatus());