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);
}
}
}
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);
}
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());
}
}
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);
}
}
};
}
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);
}
Aggregations