/** * Deletes the namespace meta and also invalidates the cache * @param namespaceId of namespace whose meta needs to be deleted */ private void deleteNamespaceMeta(NamespaceId namespaceId) { nsStore.delete(namespaceId); namespaceMetaCache.invalidate(namespaceId); } }
private NamespaceMeta fetchNamespaceMeta(NamespaceId namespaceId) throws Exception { NamespaceMeta ns = nsStore.get(namespaceId); if (ns == null) { throw new NamespaceNotFoundException(namespaceId); } return ns; }
nsStore.create(metadata); try { UserGroupInformation ugi;
/** * Lists all namespaces * * @return a list of {@link NamespaceMeta} for all namespaces */ @Override public List<NamespaceMeta> list() throws Exception { List<NamespaceMeta> namespaces = nsStore.list(); final Principal principal = authenticationContext.getPrincipal(); return AuthorizationUtil.isVisible(namespaces, authorizationEnforcer, principal, new Function<NamespaceMeta, EntityId>() { @Override public EntityId apply(NamespaceMeta input) { return input.getNamespaceId(); } }, new Predicate<NamespaceMeta>() { @Override public boolean apply(NamespaceMeta input) { return principal.getName().equals(input.getConfig().getPrincipal()); } }); }
@BeforeClass public static void setup() throws Exception { CConfiguration cConf = CConfiguration.create(); cConf.set(Constants.INSTANCE_NAME, EXISTS); Injector injector = AppFabricTestHelper.getInjector(cConf); NamespaceStore nsStore = injector.getInstance(NamespaceStore.class); ArtifactRepository artifactRepository = injector.getInstance(ArtifactRepository.class); cConf = injector.getInstance(CConfiguration.class); nsStore.create(new NamespaceMeta.Builder().setName(EXISTS).build()); existenceVerifier = injector.getInstance(Key.get(new TypeLiteral<EntityExistenceVerifier<EntityId>>() { })); LocalLocationFactory lf = new LocalLocationFactory(TEMPORARY_FOLDER.newFolder()); File artifactFile = new File(AppJarHelper.createDeploymentJar(lf, AllProgramsApp.class).toURI()); artifactRepository.addArtifact(Id.Artifact.fromEntityId(ARTIFACT), artifactFile); AppFabricTestHelper.deployApplication(Id.Namespace.fromEntityId(NAMESPACE), AllProgramsApp.class, null, cConf); }
/** * Lists all namespaces * * @return a list of {@link NamespaceMeta} for all namespaces */ @Override public List<NamespaceMeta> list() throws Exception { List<NamespaceMeta> namespaces = nsStore.list(); final Principal principal = authenticationContext.getPrincipal(); //noinspection ConstantConditions return AuthorizationUtil.isVisible(namespaces, authorizationEnforcer, principal, NamespaceMeta::getNamespaceId, input -> principal.getName().equals(input.getConfig().getPrincipal())); }
nsStore.create(metadata); try { UserGroupInformation ugi;
private NamespaceMeta fetchNamespaceMeta(NamespaceId namespaceId) throws Exception { NamespaceMeta ns = nsStore.get(namespaceId); if (ns == null) { throw new NamespaceNotFoundException(namespaceId); } return ns; }
/** * Deletes the namespace meta and also invalidates the cache * @param namespaceId of namespace whose meta needs to be deleted */ private void deleteNamespaceMeta(NamespaceId namespaceId) { nsStore.delete(namespaceId); namespaceMetaCache.invalidate(namespaceId); } }
@Test public void test() throws Exception { NamespaceId myspace = new NamespaceId("myspace"); NamespaceMeta myspaceMeta = new NamespaceMeta.Builder().setName(myspace.getNamespace()).build(); // the create/delete will look up meta so store that too namespaceStore.create(myspaceMeta); storageProviderNamespaceAdmin.create(myspaceMeta); Location namespaceLocation = namespacePathLocator.get(myspace); Assert.assertTrue(namespaceLocation.exists()); storageProviderNamespaceAdmin.delete(myspace); Assert.assertFalse(namespaceLocation.exists()); }
@Path("/namespaces/{namespace-id}/preferences") @DELETE public void deleteNamespacePrefs(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) throws Exception { NamespaceId namespaceId = new NamespaceId(namespace); if (nsStore.get(namespaceId) == null) { responder.sendString(HttpResponseStatus.NOT_FOUND, String.format("Namespace %s not present", namespace)); } else { preferencesService.deleteProperties(namespaceId); responder.sendStatus(HttpResponseStatus.OK); } }
@Path("/namespaces/{namespace-id}/preferences") @DELETE public void deleteNamespacePrefs(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) throws Exception { NamespaceId namespaceId = new NamespaceId(namespace); if (nsStore.get(namespaceId) == null) { responder.sendString(HttpResponseStatus.NOT_FOUND, String.format("Namespace %s not present", namespace)); } else { preferencesService.deleteProperties(namespaceId); responder.sendStatus(HttpResponseStatus.OK); } }
@Path("/namespaces/{namespace-id}/preferences") @GET public void getNamespacePrefs(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @QueryParam("resolved") boolean resolved) throws Exception { NamespaceId namespaceId = new NamespaceId(namespace); if (nsStore.get(namespaceId) == null) { responder.sendString(HttpResponseStatus.NOT_FOUND, String.format("Namespace %s not present", namespace)); } else { if (resolved) { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(preferencesService.getResolvedProperties(namespaceId))); } else { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(preferencesService.getProperties(namespaceId))); } } }
@Path("/namespaces/{namespace-id}/preferences") @GET public void getNamespacePrefs(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @QueryParam("resolved") boolean resolved) throws Exception { NamespaceId namespaceId = new NamespaceId(namespace); if (nsStore.get(namespaceId) == null) { responder.sendString(HttpResponseStatus.NOT_FOUND, String.format("Namespace %s not present", namespace)); } else { if (resolved) { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(preferencesService.getResolvedProperties(namespaceId))); } else { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(preferencesService.getProperties(namespaceId))); } } }
@Path("/namespaces/{namespace-id}/preferences") @PUT @AuditPolicy(AuditDetail.REQUEST_BODY) public void setNamespacePrefs(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) throws Exception { NamespaceId namespaceId = new NamespaceId(namespace); if (nsStore.get(namespaceId) == null) { responder.sendString(HttpResponseStatus.NOT_FOUND, String.format("Namespace %s not present", namespace)); return; } try { Map<String, String> propMap = decodeArguments(request); preferencesService.setProperties(namespaceId, propMap); responder.sendStatus(HttpResponseStatus.OK); } catch (JsonSyntaxException jsonEx) { responder.sendString(HttpResponseStatus.BAD_REQUEST, "Invalid JSON in body"); } }
@Path("/namespaces/{namespace-id}/preferences") @PUT @AuditPolicy(AuditDetail.REQUEST_BODY) public void setNamespacePrefs(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) throws Exception { NamespaceId namespaceId = new NamespaceId(namespace); if (nsStore.get(namespaceId) == null) { responder.sendString(HttpResponseStatus.NOT_FOUND, String.format("Namespace %s not present", namespace)); return; } try { Map<String, String> propMap = decodeArguments(request); preferencesService.setProperties(namespaceId, propMap); responder.sendStatus(HttpResponseStatus.OK); } catch (JsonSyntaxException jsonEx) { responder.sendString(HttpResponseStatus.BAD_REQUEST, "Invalid JSON in body"); } }