@Override public QueryHandle execute(FullHttpRequest request, HttpResponder responder) throws IllegalArgumentException, SQLException, ExploreException, IOException { NamespaceMeta namespaceMeta = GSON.fromJson(request.content().toString(StandardCharsets.UTF_8), NamespaceMeta.class); // Use the namespace id which was passed as path param. It will be same in the meta but this is for consistency // we do the same thing in NamespaceHttpHandler.create namespaceMeta = new NamespaceMeta.Builder(namespaceMeta).setName(namespaceId).build(); final NamespaceMeta finalNamespaceMeta = namespaceMeta; try { return impersonator.doAs(namespaceMeta.getNamespaceId(), new Callable<QueryHandle>() { @Override public QueryHandle call() throws Exception { return exploreService.createNamespace(finalNamespaceMeta); } }); } catch (ExploreException | SQLException e) { // we know that the callable only throws the above two declared exceptions: throw e; } catch (Exception e) { throw Throwables.propagate(e); } } });
@Before public void setUp() throws Exception { LOG.info("Beginning setUp."); checkSystemServices(); assertUnrecoverableResetEnabled(); boolean deleteUponTeardown = false; if (!getNamespaceClient().exists(configuredNamespace)) { getNamespaceClient().create(new NamespaceMeta.Builder().setName(configuredNamespace).build()); // if we created the configured namespace, delete it upon teardown deleteUponTeardown = true; } else { // only need to clear the namespace if it already existed doClear(configuredNamespace, false); } registeredNamespaces.put(configuredNamespace, deleteUponTeardown); LOG.info("Completed setUp."); }
@Override public NamespaceMeta get(NamespaceId namespaceId) throws Exception { return customNSMap.containsKey(namespaceId.getNamespace()) ? customNSMap.get(namespaceId.getNamespace()) : new NamespaceMeta.Builder().setName(namespaceId.getNamespace()).build(); }
@BeforeClass public static void setUp() throws Exception { CConfiguration conf = CConfiguration.create(); conf.set(Constants.Security.Store.FILE_PATH, TEMP_FOLDER.newFolder().getAbsolutePath()); SConfiguration sConf = SConfiguration.create(); sConf.set(Constants.Security.Store.FILE_PASSWORD, "secret"); InMemoryNamespaceAdmin namespaceClient = new InMemoryNamespaceAdmin(); NamespaceMeta namespaceMeta = new NamespaceMeta.Builder() .setName(NAMESPACE1) .build(); namespaceClient.create(namespaceMeta); FileSecureStoreService fileSecureStoreService = new FileSecureStoreService(conf, sConf, namespaceClient); // Starts a mock server to handle remote secure store requests httpService = NettyHttpService.builder("remoteSecureStoreTest") .setHttpHandlers(new SecureStoreHandler(fileSecureStoreService, fileSecureStoreService)) .setExceptionHandler(new HttpExceptionHandler()) .build(); httpService.start(); InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService(); discoveryService.register(new Discoverable(Constants.Service.SECURE_STORE_SERVICE, httpService.getBindAddress())); remoteSecureStore = new RemoteSecureStore(discoveryService); }
private void testDeployAppWithoutOwner() throws Exception { NamespaceId namespaceId = new NamespaceId("namespaceImpersonation"); // We will create a namespace as owner bob, the keytab url is provided to pass the check for DefaultNamespaceAdmin // in unit test, it is useless, since impersonation will never happen NamespaceMeta ownerNSMeta = new NamespaceMeta.Builder().setName(namespaceId.getNamespace()) .setPrincipal(BOB.getName()).setKeytabURI("/tmp/").build(); KerberosPrincipalId bobPrincipalId = new KerberosPrincipalId(BOB.getName()); // grant alice admin to the namespace, but creation should still fail since alice needs to have privilege on // principal bob grantAndAssertSuccess(namespaceId, ALICE, EnumSet.of(Action.ADMIN)); cleanUpEntities.add(namespaceId); try { getNamespaceAdmin().create(ownerNSMeta); Assert.fail("Namespace creation should fail since alice does not have privilege on principal bob"); } catch (UnauthorizedException e) { // expected } // grant alice admin on principal bob, now creation of namespace should work grantAndAssertSuccess(bobPrincipalId, ALICE, EnumSet.of(Action.ADMIN)); cleanUpEntities.add(bobPrincipalId); getNamespaceAdmin().create(ownerNSMeta); // deploy dummy app with ns impersonation deployDummyAppWithImpersonation(ownerNSMeta, null); }
@Override public void perform(Arguments arguments, PrintStream output) throws Exception { String name = arguments.get(ArgumentName.NAMESPACE_NAME.toString()); String description = arguments.getOptional(ArgumentName.DESCRIPTION.toString(), null); String principal = arguments.getOptional(ArgumentName.PRINCIPAL.toString(), null); String groupName = arguments.getOptional(ArgumentName.NAMESPACE_GROUP_NAME.toString(), null); String keytabPath = arguments.getOptional(ArgumentName.NAMESPACE_KEYTAB_PATH.toString(), null); String hbaseNamespace = arguments.getOptional(ArgumentName.NAMESPACE_HBASE_NAMESPACE.toString(), null); String hiveDatabase = arguments.getOptional(ArgumentName.NAMESPACE_HIVE_DATABASE.toString(), null); String schedulerQueueName = arguments.getOptional(ArgumentName.NAMESPACE_SCHEDULER_QUEUENAME.toString(), null); String rootDir = arguments.getOptional(ArgumentName.NAMESPACE_ROOT_DIR.toString(), null); String exploreAsPrinc = arguments.getOptional(ArgumentName.NAMESPACE_EXPLORE_AS_PRINCIPAL.toString(), "true"); Boolean exploreAsPrincipal = Boolean.valueOf(exploreAsPrinc); NamespaceMeta.Builder builder = new NamespaceMeta.Builder(); builder.setName(name).setDescription(description).setPrincipal(principal).setGroupName(groupName) .setKeytabURI(keytabPath).setRootDirectory(rootDir).setHBaseNamespace(hbaseNamespace) .setHiveDatabase(hiveDatabase).setSchedulerQueueName(schedulerQueueName) .setExploreAsPrincipal(exploreAsPrincipal); namespaceClient.create(builder.build()); output.println(String.format(SUCCESS_MSG, name)); }
@Override public void perform(Arguments arguments, PrintStream output) throws Exception { String name = arguments.get(ArgumentName.NAMESPACE_NAME.toString()); String description = arguments.getOptional(ArgumentName.DESCRIPTION.toString(), null); String principal = arguments.getOptional(ArgumentName.PRINCIPAL.toString(), null); String groupName = arguments.getOptional(ArgumentName.NAMESPACE_GROUP_NAME.toString(), null); String keytabPath = arguments.getOptional(ArgumentName.NAMESPACE_KEYTAB_PATH.toString(), null); String hbaseNamespace = arguments.getOptional(ArgumentName.NAMESPACE_HBASE_NAMESPACE.toString(), null); String hiveDatabase = arguments.getOptional(ArgumentName.NAMESPACE_HIVE_DATABASE.toString(), null); String schedulerQueueName = arguments.getOptional(ArgumentName.NAMESPACE_SCHEDULER_QUEUENAME.toString(), null); String rootDir = arguments.getOptional(ArgumentName.NAMESPACE_ROOT_DIR.toString(), null); String exploreAsPrinc = arguments.getOptional(ArgumentName.NAMESPACE_EXPLORE_AS_PRINCIPAL.toString(), "true"); Boolean exploreAsPrincipal = Boolean.valueOf(exploreAsPrinc); NamespaceMeta.Builder builder = new NamespaceMeta.Builder(); builder.setName(name).setDescription(description).setPrincipal(principal).setGroupName(groupName) .setKeytabURI(keytabPath).setRootDirectory(rootDir).setHBaseNamespace(hbaseNamespace) .setHiveDatabase(hiveDatabase).setSchedulerQueueName(schedulerQueueName) .setExploreAsPrincipal(exploreAsPrincipal); namespaceClient.create(builder.build()); output.println(String.format(SUCCESS_MSG, name)); }
@Test public void testScalaSparkCrossNSDataset() throws Exception { // Deploy and create a dataset in namespace datasetSpaceForSpark NamespaceMeta inputDSNSMeta = new NamespaceMeta.Builder().setName("datasetSpaceForSpark").build(); getNamespaceAdmin().create(inputDSNSMeta); deploy(inputDSNSMeta.getNamespaceId(), SparkAppUsingObjectStore.class); DataSetManager<ObjectStore<String>> keysManager = getDataset(inputDSNSMeta.getNamespaceId().dataset("keys")); prepareInputData(keysManager); Map<String, String> args = ImmutableMap.of(ScalaCharCountProgram.INPUT_DATASET_NAMESPACE(), inputDSNSMeta.getNamespaceId().getNamespace(), ScalaCharCountProgram.INPUT_DATASET_NAME(), "keys"); ApplicationManager applicationManager = deploy(NamespaceId.DEFAULT, SparkAppUsingObjectStore.class); SparkManager sparkManager = applicationManager.getSparkManager(ScalaCharCountProgram.class.getSimpleName()).start(args); sparkManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS); sparkManager.waitForStopped(60, TimeUnit.SECONDS); DataSetManager<KeyValueTable> countManager = getDataset("count"); checkOutputData(countManager); }
@Before public void setUp() throws Exception { CConfiguration conf = CConfiguration.create(); conf.set(Constants.Security.Store.FILE_PATH, TEMP_FOLDER.newFolder().getAbsolutePath()); SConfiguration sConf = SConfiguration.create(); sConf.set(Constants.Security.Store.FILE_PASSWORD, "secret"); InMemoryNamespaceAdmin namespaceClient = new InMemoryNamespaceAdmin(); NamespaceMeta namespaceMeta = new NamespaceMeta.Builder() .setName(NAMESPACE1) .build(); namespaceClient.create(namespaceMeta); namespaceMeta = new NamespaceMeta.Builder() .setName(NAMESPACE2) .build(); namespaceClient.create(namespaceMeta); FileSecureStoreService fileSecureStoreService = new FileSecureStoreService(conf, sConf, namespaceClient); secureStoreManager = fileSecureStoreService; secureStore = fileSecureStoreService; }
@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); }
@Before public void setUp() throws Exception { getNamespaceAdmin().create(new NamespaceMeta.Builder().setName(testSpace).build()); }
@Before public void setUp() throws Exception { getNamespaceAdmin().create(new NamespaceMeta.Builder().setName(testSpace).build()); }
private static void ensureNamespaceExists(NamespaceId namespaceId, CConfiguration cConf) throws Exception { NamespaceAdmin namespaceAdmin = getInjector(cConf).getInstance(NamespaceAdmin.class); try { if (!namespaceAdmin.exists(namespaceId)) { namespaceAdmin.create(new NamespaceMeta.Builder().setName(namespaceId).build()); } } catch (NamespaceAlreadyExistsException e) { // There can be race between exists() and create() call. if (!namespaceAdmin.exists(namespaceId)) { throw new IllegalStateException("Failed to create namespace " + namespaceId.getNamespace(), e); } } }
@Before public void beforeTest() throws Exception { super.beforeTest(); getNamespaceAdmin().create(new NamespaceMeta.Builder().setName(NAMESPACE).build()); getMessagingAdmin(NAMESPACE).createTopic(MessagingApp.CONTROL_TOPIC); }
@Test(timeout = 90000L) public void testSQLQuerySimpleNS() throws Exception { namespaceAdmin.create(new NamespaceMeta.Builder().setName(testSpace).build()); testSQLQuery(); namespaceAdmin.delete(testSpace); }
private void testDeployAppWithOwner() throws Exception { NamespaceId namespaceId = new NamespaceId("appImpersonation"); NamespaceMeta nsMeta = new NamespaceMeta.Builder().setName(namespaceId.getNamespace()).build(); // grant ALICE admin on namespace and create namespace grantAndAssertSuccess(namespaceId, ALICE, EnumSet.of(Action.ADMIN)); cleanUpEntities.add(namespaceId); getNamespaceAdmin().create(nsMeta); // deploy dummy app with app impersonation deployDummyAppWithImpersonation(nsMeta, BOB.getName()); }
@BeforeClass public static void setUp() throws Exception { InMemoryNamespaceAdmin namespaceClient = new InMemoryNamespaceAdmin(); NamespaceMeta namespaceMeta = new NamespaceMeta.Builder() .setName(NAMESPACE1) .build(); namespaceClient.create(namespaceMeta); secureStoreService = new SecretManagerSecureStoreService(namespaceClient, new MockSecretManagerContext(), "mock", new MockSecretManager()); secureStoreService.startAndWait(); }
private void createNamespace(NamespaceId namespaceId) throws Exception { // since the namespace admin here is an in memory one we need to create the location explicitly namespacePathLocator.get(namespaceId).mkdirs(); // the framework.delete looks up namespace config through namespaceadmin add the meta there too. namespaceAdmin.create(new NamespaceMeta.Builder().setName(namespaceId).build()); }
@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()); }
@BeforeClass public static void setup() throws Exception { NamespacePathLocator namespacePathLocator = AppFabricTestHelper.getInjector().getInstance(NamespacePathLocator.class); namespaceHomeLocation = namespacePathLocator.get(DefaultId.NAMESPACE); NamespaceAdmin namespaceAdmin = AppFabricTestHelper.getInjector().getInstance(NamespaceAdmin.class); namespaceAdmin.create(new NamespaceMeta.Builder().setName(DefaultId.NAMESPACE).build()); Locations.mkdirsIfNotExists(namespaceHomeLocation); }