use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class CoreSchedulerService method migrateSchedules.
private void migrateSchedules(final NamespaceQueryAdmin namespaceQueryAdmin, final Store appMetaStore) throws Exception {
List<NamespaceMeta> namespaceMetas = namespaceQueryAdmin.list();
boolean migrateComplete = execute(new StoreTxRunnable<Boolean, RuntimeException>() {
@Override
public Boolean run(ProgramScheduleStoreDataset store) {
return store.isMigrationComplete();
}
}, RuntimeException.class);
if (migrateComplete) {
// no need to migrate if migration is complete
return;
}
String completedNamespace = null;
for (NamespaceMeta namespaceMeta : namespaceMetas) {
final NamespaceId namespaceId = namespaceMeta.getNamespaceId();
// the current namespace lexicographically, then the current namespace is already migrated. Skip this namespace.
if (completedNamespace != null && completedNamespace.compareTo(namespaceId.toString()) > 0) {
continue;
}
completedNamespace = execute(new StoreTxRunnable<String, RuntimeException>() {
@Override
public String run(ProgramScheduleStoreDataset store) {
return store.migrateFromAppMetadataStore(namespaceId, appMetaStore);
}
}, RuntimeException.class);
}
// Set migration complete after migrating all namespaces
execute(new StoreTxRunnable<Void, RuntimeException>() {
@Override
public Void run(ProgramScheduleStoreDataset store) {
store.setMigrationComplete();
return null;
}
}, RuntimeException.class);
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class CLIMainTest method testDataset.
@Test
public void testDataset() throws Exception {
String datasetName = PREFIX + "sdf123lkj";
String ownedDatasetName = PREFIX + "owned";
DatasetTypeClient datasetTypeClient = new DatasetTypeClient(cliConfig.getClientConfig());
DatasetTypeMeta datasetType = datasetTypeClient.list(NamespaceId.DEFAULT).get(0);
testCommandOutputContains(cli, "create dataset instance " + datasetType.getName() + " " + datasetName + " \"a=1\"", "Successfully created dataset");
testCommandOutputContains(cli, "list dataset instances", FakeDataset.class.getSimpleName());
testCommandOutputContains(cli, "get dataset instance properties " + datasetName, "a,1");
// test dataset creation with owner
String commandOutput = getCommandOutput(cli, "create dataset instance " + datasetType.getName() + " " + ownedDatasetName + " \"a=1\"" + " " + "someDescription " + ArgumentName.PRINCIPAL + " alice/somehost.net@somekdc.net");
Assert.assertTrue(commandOutput.contains("Successfully created dataset"));
Assert.assertTrue(commandOutput.contains("alice/somehost.net@somekdc.net"));
// test describing the table returns the given owner information
testCommandOutputContains(cli, "describe dataset instance " + ownedDatasetName, "alice/somehost.net@somekdc.net");
NamespaceClient namespaceClient = new NamespaceClient(cliConfig.getClientConfig());
NamespaceId barspace = new NamespaceId("bar");
namespaceClient.create(new NamespaceMeta.Builder().setName(barspace).build());
cliConfig.setNamespace(barspace);
// list of dataset instances is different in 'foo' namespace
testCommandOutputNotContains(cli, "list dataset instances", FakeDataset.class.getSimpleName());
// also can not create dataset instances if the type it depends on exists only in a different namespace.
DatasetTypeId datasetType1 = barspace.datasetType(datasetType.getName());
testCommandOutputContains(cli, "create dataset instance " + datasetType.getName() + " " + datasetName, new DatasetTypeNotFoundException(datasetType1).getMessage());
testCommandOutputContains(cli, "use namespace default", "Now using namespace 'default'");
try {
testCommandOutputContains(cli, "truncate dataset instance " + datasetName, "Successfully truncated");
} finally {
testCommandOutputContains(cli, "delete dataset instance " + datasetName, "Successfully deleted");
}
String datasetName2 = PREFIX + "asoijm39485";
String description = "test-description-for-" + datasetName2;
testCommandOutputContains(cli, "create dataset instance " + datasetType.getName() + " " + datasetName2 + " \"a=1\"" + " " + description, "Successfully created dataset");
testCommandOutputContains(cli, "list dataset instances", description);
testCommandOutputContains(cli, "delete dataset instance " + datasetName2, "Successfully deleted");
testCommandOutputContains(cli, "delete dataset instance " + ownedDatasetName, "Successfully deleted");
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class DeleteNamespaceCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream out) throws Exception {
NamespaceId namespaceId = new NamespaceId(arguments.get(ArgumentName.NAMESPACE_NAME.toString()));
ConsoleReader consoleReader = new ConsoleReader();
if (NamespaceId.DEFAULT.equals(namespaceId)) {
out.println("WARNING: Deleting contents of a namespace is an unrecoverable operation");
String prompt = String.format("Are you sure you want to delete contents of namespace '%s' [y/N]? ", namespaceId.getNamespace());
String userConfirm = consoleReader.readLine(prompt);
if ("y".equalsIgnoreCase(userConfirm)) {
namespaceClient.delete(namespaceId);
out.printf("Contents of namespace '%s' were deleted successfully", namespaceId.getNamespace());
out.println();
}
} else {
out.println("WARNING: Deleting a namespace is an unrecoverable operation");
String prompt = String.format("Are you sure you want to delete namespace '%s' [y/N]? ", namespaceId.getNamespace());
String userConfirm = consoleReader.readLine(prompt);
if ("y".equalsIgnoreCase(userConfirm)) {
namespaceClient.delete(namespaceId);
out.println(String.format(SUCCESS_MSG, namespaceId.getNamespace()));
if (cliConfig.getCurrentNamespace().equals(namespaceId)) {
cliConfig.setNamespace(NamespaceId.DEFAULT);
out.printf("Now using namespace '%s'", NamespaceId.DEFAULT.getNamespace());
out.println();
}
}
}
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class DescribeNamespaceCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
NamespaceId namespace = new NamespaceId(arguments.get(ArgumentName.NAMESPACE_NAME.getName()));
NamespaceMeta namespaceMeta = namespaceClient.get(namespace);
Table table = Table.builder().setHeader("name", "description", "config").setRows(Lists.newArrayList(namespaceMeta), new RowMaker<NamespaceMeta>() {
@Override
public List<?> makeRow(NamespaceMeta object) {
return Lists.newArrayList(object.getName(), object.getDescription(), NamespaceCommandUtils.prettyPrintNamespaceConfigCLI(object.getConfig()));
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method testSearchMetadataDeleteNamespace.
@Test
public void testSearchMetadataDeleteNamespace() throws Exception {
NamespaceId namespace = new NamespaceId("ns2");
namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
// Deploy app
appClient.deploy(namespace, createAppJarFile(WordCountApp.class, WordCountApp.class.getSimpleName(), "1.0"));
Set<String> tags = ImmutableSet.of("tag1", "tag2");
ArtifactId artifact = namespace.artifact("WordCountApp", "1.0");
ApplicationId app = namespace.app("WordCountApp");
ProgramId flow = app.flow("WordCountFlow");
ProgramId service = app.service("WordFrequencyService");
StreamId stream = namespace.stream("text");
DatasetId datasetInstance = namespace.dataset("mydataset");
StreamViewId view = stream.view("view");
streamViewClient.createOrUpdate(view, new ViewSpecification(new FormatSpecification("csv", null, null)));
// Add metadata
addTags(app, tags);
addTags(flow, tags);
addTags(stream, tags);
addTags(datasetInstance, tags);
addTags(view, tags);
Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(stream), new MetadataSearchResultRecord(view)), searchMetadata(namespace, "text"));
Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(datasetInstance)), searchMetadata(namespace, "mydataset"));
Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(app), new MetadataSearchResultRecord(flow), new MetadataSearchResultRecord(artifact), new MetadataSearchResultRecord(service)), searchMetadata(namespace, "word*"));
Assert.assertEquals(ImmutableSet.of(new MetadataSearchResultRecord(app), new MetadataSearchResultRecord(flow), new MetadataSearchResultRecord(stream), new MetadataSearchResultRecord(datasetInstance), new MetadataSearchResultRecord(view)), searchMetadata(namespace, "tag1"));
// Delete namespace
namespaceClient.delete(namespace);
// Assert no metadata
Assert.assertEquals(ImmutableSet.of(), searchMetadata(namespace, "text"));
Assert.assertEquals(ImmutableSet.of(), searchMetadata(namespace, "mydataset"));
Assert.assertEquals(ImmutableSet.of(), searchMetadata(namespace, "word*"));
Assert.assertEquals(ImmutableSet.of(), searchMetadata(namespace, "tag1"));
}
Aggregations