use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class RemoteNamespaceQueryTest method testCustomNS.
@Test
public void testCustomNS() throws Exception {
String cdapNamespace = "NS1";
String hbaseNamespace = "custHBase";
String rootDirectory = "/directory";
String hiveDb = "myHive";
String schedulerQueue = "schQ";
String description = "Namespace with custom HBase mapping";
NamespaceConfig namespaceConfig = new NamespaceConfig(schedulerQueue, rootDirectory, hbaseNamespace, hiveDb, null, null, null);
NamespaceMeta meta = new NamespaceMeta.Builder().setName(cdapNamespace).setDescription(description).setSchedulerQueueName(schedulerQueue).setRootDirectory(rootDirectory).setHBaseNamespace(hbaseNamespace).setHiveDatabase(hiveDb).build();
// create the ns location since admin expect it to exists
Location nsLocation = namespacedLocationFactory.get(meta);
nsLocation.mkdirs();
namespaceAdmin.create(meta);
NamespaceId namespaceId = new NamespaceId(cdapNamespace);
Assert.assertTrue(queryClient.exists(namespaceId));
NamespaceMeta resultMeta = queryClient.get(namespaceId);
Assert.assertEquals(namespaceConfig, resultMeta.getConfig());
namespaceAdmin.delete(namespaceId);
Assert.assertTrue(!queryClient.exists(namespaceId));
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class CLIMainTest method testNamespacesOutput.
private static void testNamespacesOutput(CLI cli, String command, final List<NamespaceMeta> expected) throws Exception {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream output = new PrintStream(outputStream);
Table table = Table.builder().setHeader("name", "description", "config").setRows(expected, new RowMaker<NamespaceMeta>() {
@Override
public List<?> makeRow(NamespaceMeta object) {
return Lists.newArrayList(object.getName(), object.getDescription(), NamespaceCommandUtils.prettyPrintNamespaceConfigCLI(object.getConfig()));
}
}).build();
cliMain.getTableRenderer().render(cliConfig, output, table);
final String expectedOutput = outputStream.toString();
testCommand(cli, command, new Function<String, Void>() {
@Nullable
@Override
public Void apply(@Nullable String output) {
Assert.assertNotNull(output);
Assert.assertEquals(expectedOutput, output);
return null;
}
});
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class CLIMainTest method testNamespaces.
@Test
public void testNamespaces() throws Exception {
final String name = PREFIX + "testNamespace";
final String description = "testDescription";
final String keytab = "keytab";
final String principal = "principal";
final String group = "group";
final String hbaseNamespace = "hbase";
final String hiveDatabase = "hiveDB";
final String schedulerQueueName = "queue";
File rootdir = TEMPORARY_FOLDER.newFolder("rootdir");
final String rootDirectory = rootdir.getAbsolutePath();
final String defaultFields = PREFIX + "defaultFields";
final String doesNotExist = "doesNotExist";
createHiveDB(hiveDatabase);
// initially only default namespace should be present
NamespaceMeta defaultNs = new NamespaceMeta.Builder().setName("default").setDescription("Default Namespace").build();
List<NamespaceMeta> expectedNamespaces = Lists.newArrayList(defaultNs);
testNamespacesOutput(cli, "list namespaces", expectedNamespaces);
// describe non-existing namespace
testCommandOutputContains(cli, String.format("describe namespace %s", doesNotExist), String.format("Error: 'namespace:%s' was not found", doesNotExist));
// delete non-existing namespace
// TODO: uncomment when fixed - this makes build hang since it requires confirmation from user
// testCommandOutputContains(cli, String.format("delete namespace %s", doesNotExist),
// String.format("Error: namespace '%s' was not found", doesNotExist));
// create a namespace
String command = String.format("create namespace %s description %s principal %s group-name %s keytab-URI %s " + "hbase-namespace %s hive-database %s root-directory %s %s %s %s %s", name, description, principal, group, keytab, hbaseNamespace, hiveDatabase, rootDirectory, ArgumentName.NAMESPACE_SCHEDULER_QUEUENAME, schedulerQueueName, ArgumentName.NAMESPACE_EXPLORE_AS_PRINCIPAL, false);
testCommandOutputContains(cli, command, String.format("Namespace '%s' created successfully.", name));
NamespaceMeta expected = new NamespaceMeta.Builder().setName(name).setDescription(description).setPrincipal(principal).setGroupName(group).setKeytabURI(keytab).setHBaseNamespace(hbaseNamespace).setSchedulerQueueName(schedulerQueueName).setHiveDatabase(hiveDatabase).setRootDirectory(rootDirectory).setExploreAsPrincipal(false).build();
expectedNamespaces = Lists.newArrayList(defaultNs, expected);
// list namespaces and verify
testNamespacesOutput(cli, "list namespaces", expectedNamespaces);
// get namespace details and verify
expectedNamespaces = Lists.newArrayList(expected);
command = String.format("describe namespace %s", name);
testNamespacesOutput(cli, command, expectedNamespaces);
// try creating a namespace with existing id
command = String.format("create namespace %s", name);
testCommandOutputContains(cli, command, String.format("Error: 'namespace:%s' already exists\n", name));
// create a namespace with default name and description
command = String.format("create namespace %s", defaultFields);
testCommandOutputContains(cli, command, String.format("Namespace '%s' created successfully.", defaultFields));
NamespaceMeta namespaceDefaultFields = new NamespaceMeta.Builder().setName(defaultFields).setDescription("").build();
// test that there are 3 namespaces including default
expectedNamespaces = Lists.newArrayList(defaultNs, namespaceDefaultFields, expected);
testNamespacesOutput(cli, "list namespaces", expectedNamespaces);
// describe namespace with default fields
expectedNamespaces = Lists.newArrayList(namespaceDefaultFields);
testNamespacesOutput(cli, String.format("describe namespace %s", defaultFields), expectedNamespaces);
// delete namespace and verify
// TODO: uncomment when fixed - this makes build hang since it requires confirmation from user
// command = String.format("delete namespace %s", name);
// testCommandOutputContains(cli, command, String.format("Namespace '%s' deleted successfully.", name));
dropHiveDb(hiveDatabase);
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class BaseHiveExploreServiceTest method createNamespace.
/**
* Create a namespace because app fabric is not started in explore tests.
*/
protected static void createNamespace(NamespaceId namespaceId) throws Exception {
namespacedLocationFactory.get(namespaceId).mkdirs();
NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(namespaceId.toId()).build();
namespaceAdmin.create(namespaceMeta);
if (!NamespaceId.DEFAULT.equals(namespaceId)) {
exploreService.createNamespace(namespaceMeta);
}
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class ExploreDisabledTest method start.
@BeforeClass
public static void start() throws Exception {
Injector injector = Guice.createInjector(createInMemoryModules(CConfiguration.create(), new Configuration()));
transactionManager = injector.getInstance(TransactionManager.class);
transactionManager.startAndWait();
dsOpExecutor = injector.getInstance(DatasetOpExecutor.class);
dsOpExecutor.startAndWait();
datasetService = injector.getInstance(DatasetService.class);
datasetService.startAndWait();
exploreClient = injector.getInstance(DiscoveryExploreClient.class);
try {
exploreClient.ping();
Assert.fail("Expected not to be able to ping explore client.");
} catch (ServiceUnavailableException e) {
// expected
}
datasetFramework = injector.getInstance(DatasetFramework.class);
namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
NamespacedLocationFactory namespacedLocationFactory = injector.getInstance(NamespacedLocationFactory.class);
NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(namespaceId).build();
namespaceAdmin.create(namespaceMeta);
// This happens when you create a namespace via REST APIs. However, since we do not start AppFabricServer in
// Explore tests, simulating that scenario by explicitly calling DatasetFramework APIs.
namespacedLocationFactory.get(namespaceId).mkdirs();
exploreClient.addNamespace(namespaceMeta);
}
Aggregations