Search in sources :

Example 31 with NamespaceId

use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class QueryClientTest method testAll.

@Test
public void testAll() throws Exception {
    NamespaceId namespace = new NamespaceId("queryClientTestNamespace");
    NamespaceId otherNamespace = new NamespaceId("queryClientOtherNamespace");
    namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
    ApplicationId app = namespace.app(FakeApp.NAME);
    FlowId flow = app.flow(FakeFlow.NAME);
    DatasetId dataset = namespace.dataset(FakeApp.DS_NAME);
    appClient.deploy(namespace, createAppJarFile(FakeApp.class));
    try {
        programClient.start(flow);
        assertProgramRunning(programClient, flow);
        StreamId stream = namespace.stream(FakeApp.STREAM_NAME);
        streamClient.sendEvent(stream, "bob:123");
        streamClient.sendEvent(stream, "joe:321");
        Thread.sleep(3000);
        executeBasicQuery(namespace, FakeApp.DS_NAME);
        exploreClient.disableExploreDataset(dataset).get();
        try {
            queryClient.execute(namespace, "select * from " + FakeApp.DS_NAME).get();
            Assert.fail("Explore Query should have thrown an ExecutionException since explore is disabled");
        } catch (ExecutionException e) {
        // ignored
        }
        exploreClient.enableExploreDataset(dataset).get();
        executeBasicQuery(namespace, FakeApp.DS_NAME);
        try {
            queryClient.execute(otherNamespace, "show tables").get();
            Assert.fail("Explore Query should have thrown an ExecutionException since the database should not exist");
        } catch (ExecutionException e) {
        // expected
        }
    } finally {
        programClient.stop(flow);
        assertProgramStopped(programClient, flow);
        try {
            appClient.delete(app);
        } catch (Exception e) {
            LOG.error("Error deleting app {} during test cleanup.", e);
        }
    }
}
Also used : FlowId(co.cask.cdap.proto.id.FlowId) FakeApp(co.cask.cdap.client.app.FakeApp) StreamId(co.cask.cdap.proto.id.StreamId) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ExecutionException(java.util.concurrent.ExecutionException) ExecutionException(java.util.concurrent.ExecutionException) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 32 with NamespaceId

use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class SecureStoreClientTest method testErrorScenarios.

@Test
public void testErrorScenarios() throws Exception {
    try {
        client.listKeys(new NamespaceId("notfound"));
        Assert.fail("Should have thrown exception since namespace doesn't exist");
    } catch (NamespaceNotFoundException e) {
    // expected
    }
    try {
        client.deleteKey(new SecureKeyId(NamespaceId.DEFAULT.getNamespace(), "badkey"));
        Assert.fail("Should have thrown exception since the key doesn't exist");
    } catch (SecureKeyNotFoundException e) {
    // expected
    }
    try {
        client.getData(new SecureKeyId(NamespaceId.DEFAULT.getNamespace(), "badkey"));
        Assert.fail("Should have thrown exception since the key doesn't exist");
    } catch (SecureKeyNotFoundException e) {
    // expected
    }
    try {
        client.getKeyMetadata(new SecureKeyId(NamespaceId.DEFAULT.getNamespace(), "badkey"));
        Assert.fail("Should have thrown exception since the key doesn't exist");
    } catch (SecureKeyNotFoundException e) {
    // expected
    }
    try {
        client.getKeyMetadata(new SecureKeyId("notfound", "somekey"));
        Assert.fail("Should have thrown exception since the namespace doesn't exist");
    } catch (SecureKeyNotFoundException e) {
    // expected
    }
    SecureKeyId id = new SecureKeyId(NamespaceId.DEFAULT.getNamespace(), "key1");
    SecureKeyCreateRequest request = new SecureKeyCreateRequest("", "a", ImmutableMap.<String, String>of());
    client.createKey(id, request);
    try {
        client.createKey(id, request);
        Assert.fail("Should have thrown exception since the key already exists");
    } catch (SecureKeyAlreadyExistsException e) {
    // expected
    }
    client.deleteKey(id);
}
Also used : SecureKeyCreateRequest(co.cask.cdap.proto.security.SecureKeyCreateRequest) SecureKeyAlreadyExistsException(co.cask.cdap.common.SecureKeyAlreadyExistsException) SecureKeyId(co.cask.cdap.proto.id.SecureKeyId) SecureKeyNotFoundException(co.cask.cdap.common.SecureKeyNotFoundException) NamespaceId(co.cask.cdap.proto.id.NamespaceId) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException) Test(org.junit.Test)

Example 33 with NamespaceId

use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class LocalStreamService method initialize.

@Override
protected void initialize() throws Exception {
    for (Map.Entry<NamespaceId, StreamSpecification> streamSpecEntry : streamMetaStore.listStreams().entries()) {
        StreamId streamId = streamSpecEntry.getKey().stream(streamSpecEntry.getValue().getName());
        StreamConfig config;
        try {
            config = streamAdmin.getConfig(streamId);
        } catch (FileNotFoundException e) {
            // TODO: this kind of inconsistency should not happen. [CDAP-5722]
            LOG.warn("Inconsistent stream state: Stream '{}' exists in meta store " + "but its configuration file does not exist", streamId);
            continue;
        } catch (Exception e) {
            LOG.warn("Inconsistent stream state: Stream '{}' exists in meta store " + "but its configuration cannot be read:", streamId, e);
            continue;
        }
        long eventsSizes = getStreamEventsSize(streamId);
        createSizeAggregator(streamId, eventsSizes, config.getNotificationThresholdMB());
    }
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) FileNotFoundException(java.io.FileNotFoundException) StreamConfig(co.cask.cdap.data2.transaction.stream.StreamConfig) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) NotificationFeedException(co.cask.cdap.notifications.feeds.NotificationFeedException) FileNotFoundException(java.io.FileNotFoundException)

Example 34 with NamespaceId

use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class DistributedStreamService method createRequirementModifier.

/**
   * Creates a {@link ResourceModifier} that updates stream resource requirement by consulting stream meta store.
   */
private ResourceModifier createRequirementModifier() {
    return new ResourceModifier() {

        @Nullable
        @Override
        public ResourceRequirement apply(@Nullable ResourceRequirement existingRequirement) {
            try {
                // Create one requirement for the resource coordinator for all the streams.
                // One stream is identified by one partition
                ResourceRequirement.Builder builder = ResourceRequirement.builder(Constants.Service.STREAMS);
                for (Map.Entry<NamespaceId, StreamSpecification> streamSpecEntry : streamMetaStore.listStreams().entries()) {
                    StreamId streamId = streamSpecEntry.getKey().stream(streamSpecEntry.getValue().getName());
                    LOG.debug("Adding {} stream as a resource to the coordinator to manager streams leaders.", streamId);
                    builder.addPartition(new ResourceRequirement.Partition(streamId.toString(), 1));
                }
                return builder.build();
            } catch (Throwable e) {
                LOG.warn("Could not create requirement for coordinator in Stream handler leader: " + e.getMessage());
                LOG.debug("Could not create requirement for coordinator in Stream handler leader", e);
                throw Throwables.propagate(e);
            }
        }
    };
}
Also used : ResourceModifier(co.cask.cdap.common.zookeeper.coordination.ResourceModifier) StreamId(co.cask.cdap.proto.id.StreamId) StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) ResourceRequirement(co.cask.cdap.common.zookeeper.coordination.ResourceRequirement) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Nullable(javax.annotation.Nullable)

Example 35 with NamespaceId

use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class StreamHandler method listStreams.

@GET
@Path("/")
public void listStreams(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
    // Check for namespace existence. Throws NotFoundException if namespace doesn't exist
    namespaceQueryAdmin.get(new NamespaceId(namespaceId));
    List<StreamSpecification> specifications = streamAdmin.listStreams(new NamespaceId(namespaceId));
    List<StreamDetail> streamDetails = new ArrayList<>(specifications.size());
    for (StreamSpecification specification : specifications) {
        streamDetails.add(new StreamDetail(specification.getName()));
    }
    responder.sendJson(HttpResponseStatus.OK, streamDetails);
}
Also used : StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) StreamDetail(co.cask.cdap.proto.StreamDetail) ArrayList(java.util.ArrayList) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

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