use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class HBaseStreamConsumerStateStoreFactory method create.
@Override
public synchronized StreamConsumerStateStore create(StreamConfig streamConfig) throws IOException {
NamespaceId namespace = streamConfig.getStreamId().getParent();
TableId streamStateStoreTableId = StreamUtils.getStateStoreTableId(namespace);
TableId hbaseTableId = tableUtil.createHTableId(new NamespaceId(streamStateStoreTableId.getNamespace()), streamStateStoreTableId.getTableName());
boolean tableExist;
try (HBaseAdmin admin = new HBaseAdmin(hConf)) {
tableExist = tableUtil.tableExists(admin, hbaseTableId);
}
if (!tableExist) {
try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) {
TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(hbaseTableId, cConf);
ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(Bytes.toString(QueueEntryRow.COLUMN_FAMILY), hConf);
tdBuilder.addColumnFamily(cfdBuilder.build());
ddlExecutor.createTableIfNotExists(tdBuilder.build(), null);
}
}
HTable hTable = tableUtil.createHTable(hConf, hbaseTableId);
hTable.setWriteBufferSize(Constants.Stream.HBASE_WRITE_BUFFER_SIZE);
hTable.setAutoFlushTo(false);
return new HBaseStreamConsumerStateStore(streamConfig, hTable);
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class StreamHandlerTest method testStreamCreateInNonexistentNamespace.
@Test
public void testStreamCreateInNonexistentNamespace() throws Exception {
NamespaceId originallyNonExistentNamespace = new NamespaceId("originallyNonExistentNamespace");
StreamId streamId = originallyNonExistentNamespace.stream("streamName");
HttpResponse response = createStream(streamId, 404);
Assert.assertEquals(HttpResponseStatus.NOT_FOUND.getCode(), response.getResponseCode());
// once the namespace exists, the same stream create works.
namespaceAdmin.create(new NamespaceMeta.Builder().setName(originallyNonExistentNamespace).build());
createStream(streamId);
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class LogHandlerTestRun method testPrevRunId.
private void testPrevRunId(String appId, String entityType, String entityId, String namespace, String format, List<String> suppress) throws Exception {
ProgramId programId = new NamespaceId(namespace).app(appId).program(ProgramType.valueOfCategoryName(entityType), entityId);
RunRecord runRecord = mockLogReader.getRunRecord(programId);
int expectedEvents = 20;
if (runRecord.getStatus() == ProgramRunStatus.RUNNING || runRecord.getStatus() == ProgramRunStatus.SUSPENDED) {
expectedEvents = 30;
}
String prevRunIdUrl;
if (suppress.isEmpty()) {
prevRunIdUrl = String.format("apps/%s/%s/%s/runs/%s/logs/prev?format=%s&max=100", appId, entityType, entityId, runRecord.getPid(), format);
} else {
String fieldsToSuppress = getSuppressStr(suppress);
prevRunIdUrl = String.format("apps/%s/%s/%s/runs/%s/logs/prev?format=%s&max=100&suppress=%s", appId, entityType, entityId, runRecord.getPid(), format, fieldsToSuppress);
}
HttpResponse response = doGet(getVersionedAPIPath(prevRunIdUrl, namespace));
verifyLogs(response, entityId, format, true, false, true, expectedEvents, 20, suppress);
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class LogHandlerTestRun method testNativeMethodField.
// Verify the Json returned for logs has isNativeMethod set correctly
@Test
public void testNativeMethodField() throws Exception {
ProgramId programId = new NamespaceId(MockLogReader.TEST_NAMESPACE).app("testTemplate1").program(ProgramType.valueOfCategoryName("workflows"), "testWorkflow1");
RunRecord runRecord = mockLogReader.getRunRecord(programId);
String logsUrl = String.format("apps/%s/%s/%s/runs/%s/logs/next?format=json", "testTemplate1", "workflows", "testWorkflow1", runRecord.getPid());
HttpResponse response = doGet(getVersionedAPIPath(logsUrl, MockLogReader.TEST_NAMESPACE));
Assert.assertEquals(HttpResponseStatus.OK.getCode(), response.getStatusLine().getStatusCode());
String out = EntityUtils.toString(response.getEntity());
List<LogDataOffset> logDataOffsetList = GSON.fromJson(out, LIST_LOGDATA_OFFSET_TYPE);
Assert.assertEquals(logDataOffsetList.size(), 15);
Assert.assertEquals(logDataOffsetList.get(0).getLog().getNativeMethod(), true);
Assert.assertEquals(logDataOffsetList.get(1).getLog().getNativeMethod(), false);
Assert.assertEquals(logDataOffsetList.get(2).getLog().getNativeMethod(), false);
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class PreviewHttpHandler method getData.
@GET
@Path("/previews/{preview-id}/tracers/{tracer-id}")
public void getData(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("preview-id") String previewId, @PathParam("tracer-id") String tracerId) throws Exception {
NamespaceId namespace = new NamespaceId(namespaceId);
ApplicationId application = namespace.app(previewId);
responder.sendString(HttpResponseStatus.OK, GSON.toJson(previewManager.getRunner(application).getData(tracerId)));
}
Aggregations