@Override public void handleError(Throwable t) { LOG.error("Error uploading version {} of resource {} of type {} for account {}.", version, name, resourceType, account, t); try { os.close(); // deletion flags the entry in the database as deleted metaStoreService.getResourceTypeView(account, resourceType).delete(name, version); // dont need the file in the plugin store if there was an error so delete it pluginStore.deleteResource(account, resourceType, name, version); responder.sendError(HttpResponseStatus.INTERNAL_SERVER_ERROR, t.getCause().getMessage()); } catch (IOException e) { LOG.error("Error uploading resource {} of type {} for account {}.", resourceMeta, resourceType, account, e); } } };
OutputStream outStream = null; try { inStream = pluginStore.getResourceInputStream(Account.SUPERADMIN, type, name, version); outStream = pluginStore.getResourceOutputStream(account, type, name, version); if (inStream == null) { LOG.error("Could not get input stream for version {} of resource {} of type {} for account {}.",
@Override protected void startUp() throws Exception { pluginStore.initialize(conf); metaStoreService.startAndWait(); }
@Test public void testDeleteWithinTenant() throws Exception { PluginStore store = getInitializedStore(); String contents = "hadoop cookbook"; ResourceType resourceType = new ResourceType(PluginType.AUTOMATOR, "chef-solo", "cookbooks"); String name = "hadoop"; int version = 1; // write different versions of the same module writeToStore(store, account1, resourceType, name, version, contents); // check it's there. Assert.assertEquals(contents, readFromStore(store, account1, resourceType, name, version)); // delete and check there's nothing store.deleteResource(account1, resourceType, name, version); Assert.assertNull(store.getResourceInputStream(account1, resourceType, name, version)); }
private String readFromStore(PluginStore store, Account account, ResourceType resourceType, String name, int version) throws IOException { Reader reader = new InputStreamReader( store.getResourceInputStream(account, resourceType, name, version), Charsets.UTF_8); try { return CharStreams.toString(reader); } finally { reader.close(); } } }
private void writeToStore(PluginStore store, Account account, ResourceType resourceType, String name, int version, String content) throws IOException { OutputStream outputStream = store.getResourceOutputStream(account, resourceType, name, version); try { outputStream.write(content.getBytes(Charsets.UTF_8)); } finally { outputStream.close(); } }
@Test public void testDeleteOnlyAffectsTenant() throws Exception { PluginStore store = getInitializedStore(); String contents = "hadoop cookbook"; ResourceType resourceType = new ResourceType(PluginType.AUTOMATOR, "chef-solo", "cookbooks"); String name = "hadoop"; int version = 1; // write different versions of the same module writeToStore(store, account1, resourceType, name, version, contents); writeToStore(store, account2, resourceType, name, version, contents); // check it's there. Assert.assertEquals(contents, readFromStore(store, account1, resourceType, name, version)); Assert.assertEquals(contents, readFromStore(store, account2, resourceType, name, version)); // delete and check there's nothing for the tenant it was deleted from, but is still there for the other store.deleteResource(account1, resourceType, name, version); Assert.assertNull(store.getResourceInputStream(account1, resourceType, name, version)); Assert.assertEquals(contents, readFromStore(store, account2, resourceType, name, version)); }
/** * Get an input stream for reading the plugin resource. * * @param account Account the resource belongs to * @param resourceType Type of resource * @param name Name of resource to get an input stream for * @param version Version of resource to get an input stream for * @return Input stream for reading the given plugin resource * @throws MissingEntityException if there is no such resource version * @throws IOException if there was an error getting the input stream for the resource */ public InputStream getResourceInputStream(final Account account, ResourceType resourceType, String name, int version) throws MissingEntityException, IOException { // no lock needed since each resource uploaded gets its own id. ResourceMeta meta = metaStoreService.getResourceTypeView(account, resourceType).get(name, version); if (meta == null) { throw new MissingEntityException("Resource not found."); } LOG.debug("getting input stream for version {} of resource {} of type {} for account {}.", version, name, resourceType, account); return pluginStore.getResourceInputStream(account, resourceType, meta.getName(), meta.getVersion()); }
version, name, resourceType, account); final OutputStream os = pluginStore.getResourceOutputStream(account, resourceType, name, version);
LOG.debug("deleted version {} of resource {} of type {} for account {} from meta store.", version, name, resourceType, account); pluginStore.deleteResource(account, resourceType, meta.getName(), meta.getVersion()); LOG.debug("deleted version {} of resource {} of type {} for account {} from plugin store.", version, name, resourceType, account);
pluginStore.deleteResource(account, resourceType, meta.getName(), meta.getVersion()); LOG.debug("deleted version {} of resource {} of type {} for account {}.", meta.getVersion(), name, resourceType, account);