Search in sources :

Example 91 with NamespaceId

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);
}
Also used : ProgramScheduleStoreDataset(co.cask.cdap.internal.app.runtime.schedule.store.ProgramScheduleStoreDataset) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 92 with NamespaceId

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");
}
Also used : DatasetTypeClient(co.cask.cdap.client.DatasetTypeClient) DatasetTypeId(co.cask.cdap.proto.id.DatasetTypeId) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceClient(co.cask.cdap.client.NamespaceClient) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) DatasetTypeNotFoundException(co.cask.cdap.common.DatasetTypeNotFoundException) FakeDataset(co.cask.cdap.client.app.FakeDataset) Test(org.junit.Test)

Example 93 with NamespaceId

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();
            }
        }
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 94 with NamespaceId

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);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 95 with NamespaceId

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"));
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) FormatSpecification(co.cask.cdap.api.data.format.FormatSpecification) ViewSpecification(co.cask.cdap.proto.ViewSpecification) ProgramId(co.cask.cdap.proto.id.ProgramId) DatasetId(co.cask.cdap.proto.id.DatasetId) MetadataSearchResultRecord(co.cask.cdap.proto.metadata.MetadataSearchResultRecord) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) WordCountApp(co.cask.cdap.WordCountApp) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) StreamViewId(co.cask.cdap.proto.id.StreamViewId) Test(org.junit.Test)

Aggregations

NamespaceId (co.cask.cdap.proto.id.NamespaceId)234 Test (org.junit.Test)99 Path (javax.ws.rs.Path)47 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)43 ApplicationId (co.cask.cdap.proto.id.ApplicationId)35 IOException (java.io.IOException)34 StreamId (co.cask.cdap.proto.id.StreamId)30 DatasetId (co.cask.cdap.proto.id.DatasetId)27 TableId (co.cask.cdap.data2.util.TableId)26 Id (co.cask.cdap.proto.Id)24 ProgramId (co.cask.cdap.proto.id.ProgramId)24 NotFoundException (co.cask.cdap.common.NotFoundException)22 ArtifactId (co.cask.cdap.proto.id.ArtifactId)21 BadRequestException (co.cask.cdap.common.BadRequestException)20 TopicId (co.cask.cdap.proto.id.TopicId)19 GET (javax.ws.rs.GET)18 Location (org.apache.twill.filesystem.Location)18 ArrayList (java.util.ArrayList)15 TopicMetadata (co.cask.cdap.messaging.TopicMetadata)13 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)12