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);
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class ApplicationLifecycleServiceTest method testOwnerInImpersonatedNS.
@Test
public void testOwnerInImpersonatedNS() throws Exception {
// create a namespace with principal
String nsPrincipal = "nsCreator/somehost.net@somekdc.net";
String nsKeytabURI = "some/path";
NamespaceMeta impNsMeta = new NamespaceMeta.Builder().setName("impNs").setPrincipal(nsPrincipal).setKeytabURI(nsKeytabURI).build();
createNamespace(GSON.toJson(impNsMeta), impNsMeta.getName());
// deploy an app without owner
HttpResponse response = deploy(WordCountApp.class, Constants.Gateway.API_VERSION_3_TOKEN, impNsMeta.getName());
Assert.assertEquals(HttpResponseStatus.OK.getCode(), response.getStatusLine().getStatusCode());
// try to redeploy with some owner different than namespace principal it should fail
response = deploy(WordCountApp.class, Constants.Gateway.API_VERSION_3_TOKEN, impNsMeta.getName(), "bob/somehost.net@somekdc.net");
Assert.assertEquals(HttpResponseStatus.FORBIDDEN.getCode(), response.getStatusLine().getStatusCode());
// although trying to re-deploy the app with namespace principal should work
response = deploy(WordCountApp.class, Constants.Gateway.API_VERSION_3_TOKEN, impNsMeta.getName(), nsPrincipal);
Assert.assertEquals(HttpResponseStatus.OK.getCode(), response.getStatusLine().getStatusCode());
// re-deploy without any owner should also work
response = deploy(WordCountApp.class, Constants.Gateway.API_VERSION_3_TOKEN, impNsMeta.getName());
Assert.assertEquals(HttpResponseStatus.OK.getCode(), response.getStatusLine().getStatusCode());
// cleanup
deleteNamespace(impNsMeta.getName());
Assert.assertEquals(HttpResponseCodes.SC_NOT_FOUND, getNamespace(impNsMeta.getName()).getStatusLine().getStatusCode());
// create an impersonated ns again
createNamespace(GSON.toJson(impNsMeta), impNsMeta.getName());
// deploy an app with an owner
response = deploy(WordCountApp.class, Constants.Gateway.API_VERSION_3_TOKEN, impNsMeta.getName(), "bob/somehost.net@somekdc.net");
Assert.assertEquals(HttpResponseStatus.OK.getCode(), response.getStatusLine().getStatusCode());
// re-deploy with namespace principal should fail
response = deploy(WordCountApp.class, Constants.Gateway.API_VERSION_3_TOKEN, impNsMeta.getName(), impNsMeta.getConfig().getPrincipal());
Assert.assertEquals(HttpResponseStatus.FORBIDDEN.getCode(), response.getStatusLine().getStatusCode());
// although redeploy with same app principal should work
response = deploy(WordCountApp.class, Constants.Gateway.API_VERSION_3_TOKEN, impNsMeta.getName(), "bob/somehost.net@somekdc.net");
Assert.assertEquals(HttpResponseStatus.OK.getCode(), response.getStatusLine().getStatusCode());
}
Aggregations