use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class IntegrationTestBase method createNamespace.
@Deprecated
protected Id.Namespace createNamespace(String name) throws Exception {
Id.Namespace namespace = Id.Namespace.from(name);
NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(namespace).build();
getNamespaceClient().create(namespaceMeta);
return namespace;
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class CDAPEntities method collect.
@Override
public void collect() throws Exception {
reset();
List<NamespaceMeta> namespaceMetas;
namespaceMetas = nsQueryAdmin.list();
namespaces = namespaceMetas.size();
for (NamespaceMeta meta : namespaceMetas) {
List<ApplicationRecord> appRecords = appLifecycleService.getApps(meta.getNamespaceId(), Predicates.<ApplicationRecord>alwaysTrue());
apps += appRecords.size();
Set<ProgramType> programTypes = EnumSet.of(ProgramType.FLOW, ProgramType.MAPREDUCE, ProgramType.SERVICE, ProgramType.SPARK, ProgramType.WORKER, ProgramType.WORKFLOW);
for (ProgramType programType : programTypes) {
programs += programLifecycleService.list(meta.getNamespaceId(), programType).size();
}
artifacts += artifactRepository.getArtifactSummaries(meta.getNamespaceId(), true).size();
datasets += dsFramework.getInstances(meta.getNamespaceId()).size();
List<StreamSpecification> streamSpecs = streamAdmin.listStreams(meta.getNamespaceId());
streams += streamSpecs.size();
for (StreamSpecification streamSpec : streamSpecs) {
StreamId streamId = meta.getNamespaceId().stream(streamSpec.getName());
streamViews += streamAdmin.listViews(streamId).size();
}
}
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class AuthorizationTest method testCrossNSSystemDatasetAccessWithAuthSpark.
private void testCrossNSSystemDatasetAccessWithAuthSpark(SparkManager sparkManager) throws Exception {
addDatasetInstance(NamespaceId.SYSTEM.dataset("table1"), "keyValueTable").create();
addDatasetInstance(NamespaceId.SYSTEM.dataset("table2"), "keyValueTable").create();
NamespaceMeta otherNS = new NamespaceMeta.Builder().setName("otherNS").build();
getNamespaceAdmin().create(otherNS);
addDatasetInstance(otherNS.getNamespaceId().dataset("otherTable"), "keyValueTable").create();
addDummyData(NamespaceId.SYSTEM, "table1");
// give privilege to BOB on all the datasets
grantAndAssertSuccess(NamespaceId.SYSTEM.dataset("table1"), BOB, EnumSet.of(Action.READ));
grantAndAssertSuccess(NamespaceId.SYSTEM.dataset("table2"), BOB, EnumSet.of(Action.WRITE));
grantAndAssertSuccess(otherNS.getNamespaceId().dataset("otherTable"), BOB, ALL_ACTIONS);
// Switch to Bob and run the spark program. this will fail because bob is trying to read from a system dataset
SecurityRequestContext.setUserId(BOB.getName());
Map<String, String> args = ImmutableMap.of(TestSparkCrossNSDatasetApp.SparkCrossNSDatasetProgram.INPUT_DATASET_NAMESPACE, NamespaceId.SYSTEM.getNamespace(), TestSparkCrossNSDatasetApp.SparkCrossNSDatasetProgram.INPUT_DATASET_NAME, "table1", TestSparkCrossNSDatasetApp.SparkCrossNSDatasetProgram.OUTPUT_DATASET_NAMESPACE, otherNS.getNamespaceId().getNamespace(), TestSparkCrossNSDatasetApp.SparkCrossNSDatasetProgram.OUTPUT_DATASET_NAME, "otherTable");
assertProgramFailure(args, sparkManager);
assertDatasetIsEmpty(otherNS.getNamespaceId(), "otherTable");
// try running spark job with valid input namespace but writing to system namespace this should fail too
args = ImmutableMap.of(TestSparkCrossNSDatasetApp.SparkCrossNSDatasetProgram.INPUT_DATASET_NAMESPACE, otherNS.getNamespaceId().getNamespace(), TestSparkCrossNSDatasetApp.SparkCrossNSDatasetProgram.INPUT_DATASET_NAME, "otherTable", TestSparkCrossNSDatasetApp.SparkCrossNSDatasetProgram.OUTPUT_DATASET_NAMESPACE, NamespaceId.SYSTEM.getNamespace(), TestSparkCrossNSDatasetApp.SparkCrossNSDatasetProgram.OUTPUT_DATASET_NAME, "table2");
addDummyData(otherNS.getNamespaceId(), "otherTable");
assertProgramFailure(args, sparkManager);
assertDatasetIsEmpty(NamespaceId.SYSTEM, "table2");
// switch to back to ALICE
SecurityRequestContext.setUserId(ALICE.getName());
// cleanup
deleteDatasetInstance(NamespaceId.SYSTEM.dataset("table1"));
deleteDatasetInstance(NamespaceId.SYSTEM.dataset("table2"));
getNamespaceAdmin().delete(otherNS.getNamespaceId());
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class AuthorizationTest method testCrossNSDatasetAccessFromFlowlet.
private void testCrossNSDatasetAccessFromFlowlet(final FlowManager flowManager) throws Exception {
NamespaceMeta outputDatasetNS = new NamespaceMeta.Builder().setName("outputNS").build();
getNamespaceAdmin().create(outputDatasetNS);
addDatasetInstance(outputDatasetNS.getNamespaceId().dataset("store"), "keyValueTable");
// switch to BOB
SecurityRequestContext.setUserId(BOB.getName());
Map<String, String> args = ImmutableMap.of(CrossNsDatasetAccessApp.OUTPUT_DATASET_NS, outputDatasetNS.getNamespaceId().getNamespace(), CrossNsDatasetAccessApp.OUTPUT_DATASET_NAME, "store");
// But trying to run a flow as BOB will fail since this flow writes to a dataset in another namespace in which
// is not accessible to BOB.
flowManager.start(args);
// wait for flow to be running
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return flowManager.isRunning();
}
}, 120, TimeUnit.SECONDS);
// The above will be a runtime failure after the flow start since it will not be able to use the dataset in the
// another namespace. Since the failure will lead to no metrics being emitted we cannot actually check it tried
// processing or not. So stop the flow and check that the output dataset is empty
flowManager.stop();
SecurityRequestContext.setUserId(ALICE.getName());
assertDatasetIsEmpty(outputDatasetNS.getNamespaceId(), "store");
// Give BOB permission to write to the dataset in another namespace
grantAndAssertSuccess(outputDatasetNS.getNamespaceId().dataset("store"), BOB, EnumSet.of(Action.WRITE));
// switch back to BOB to run flow again
SecurityRequestContext.setUserId(BOB.getName());
// running the flow now should pass and write data in another namespace successfully
flowManager.start(args);
flowManager.getFlowletMetrics("saver").waitForProcessed(10, 30, TimeUnit.SECONDS);
// switch back to alice and verify the data its fine now to verify the run record here because if the flow failed
// to write we will not see any data
SecurityRequestContext.setUserId(ALICE.getName());
DataSetManager<KeyValueTable> dataSetManager = getDataset(outputDatasetNS.getNamespaceId().dataset("store"));
KeyValueTable results = dataSetManager.get();
for (int i = 0; i < 10; i++) {
byte[] key = String.valueOf(i).getBytes(Charsets.UTF_8);
Assert.assertArrayEquals(key, results.read(key));
}
flowManager.stop();
getNamespaceAdmin().delete(outputDatasetNS.getNamespaceId());
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class BatchStreamIntegrationTestRun method submitAndVerifyStreamOtherNamespaceBatchJob.
private void submitAndVerifyStreamOtherNamespaceBatchJob(Class<? extends AbstractApplication> appClass, String namespace, String streamWriter, String mapReduceName, int timeout) throws Exception {
NamespaceId namespaceId = new NamespaceId(namespace);
NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(namespace).build();
getNamespaceAdmin().create(namespaceMeta);
deployApplication(namespaceId, appClass);
ApplicationManager applicationManager = deployApplication(appClass);
StreamManager streamManager = getStreamManager(namespaceId.stream(streamWriter));
verifyStreamBatchJob(streamManager, applicationManager, mapReduceName, timeout);
}
Aggregations