use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class AbstractHBaseTableUtilTest method exists.
private boolean exists(TableId tableId) throws IOException {
HBaseTableUtil tableUtil = getTableUtil();
TableId hTableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
return tableUtil.tableExists(hAdmin, hTableId);
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class AbstractHBaseTableUtilTest method getTableId.
private TableId getTableId(String namespace, String tableName) throws IOException {
HBaseTableUtil tableUtil = getTableUtil();
List<TableId> tableIds = tableUtil.listTablesInNamespace(hAdmin, tableUtil.getHBaseNamespace(new NamespaceId(namespace)));
for (TableId tId : tableIds) {
if (tId.getTableName().endsWith(tableName)) {
return tId;
}
}
return null;
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class AbstractHBaseTableUtilTest method getTableStats.
private HBaseTableUtil.TableStats getTableStats(String namespace, String tableName) throws IOException {
HBaseTableUtil tableUtil = getTableUtil();
// todo : should support custom table-prefix
TableId tableId = tableUtil.createHTableId(new NamespaceId(namespace), tableName);
Map<TableId, HBaseTableUtil.TableStats> statsMap = tableUtil.getTableStats(hAdmin);
return statsMap.get(tableId);
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class HiveExploreServiceTestRun method testQueriesCount.
@Test
public void testQueriesCount() throws Exception {
NamespaceId testNamespace1 = new NamespaceId("testQueriesCount");
NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(testNamespace1).build();
namespaceAdmin.create(namespaceMeta);
exploreClient.addNamespace(namespaceMeta).get();
try {
Assert.assertEquals(0, exploreService.getActiveQueryCount(testNamespace1));
ListenableFuture<ExploreExecutionResult> future = exploreClient.submit(testNamespace1, "show tables");
ExploreExecutionResult result = null;
try {
result = future.get();
Assert.assertEquals(1, exploreService.getActiveQueryCount(testNamespace1));
} finally {
if (result != null) {
result.close();
}
Assert.assertEquals(0, exploreService.getActiveQueryCount(testNamespace1));
}
} finally {
exploreClient.removeNamespace(testNamespace1).get();
}
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method toScheduleDetail.
private ScheduleDetail toScheduleDetail(ScheduleUpdateDetail updateDetail, ProgramSchedule existing) {
ScheduleUpdateDetail.Schedule scheduleUpdate = updateDetail.getSchedule();
if (scheduleUpdate == null) {
return new ScheduleDetail(null, null, null, updateDetail.getProperties(), null, null, null);
}
Trigger trigger = null;
if (scheduleUpdate.getCronExpression() != null && (scheduleUpdate.getStreamName() != null || scheduleUpdate.getDataTriggerMB() != null)) {
throw new IllegalArgumentException(String.format("Cannot define time trigger with cron expression and define stream size trigger with" + " stream name and data trigger configuration in the same schedule update details %s. " + "Schedule update detail must contain only one trigger.", updateDetail));
}
NamespaceId namespaceId = existing.getProgramId().getNamespaceId();
if (scheduleUpdate.getCronExpression() != null) {
trigger = new TimeTrigger(updateDetail.getSchedule().getCronExpression());
} else if (existing.getTrigger() instanceof StreamSizeTrigger) {
// if the existing trigger is StreamSizeTrigger, use the field in the existing trigger if the corresponding field
// in schedule update detail is null
StreamSizeTrigger existingTrigger = (StreamSizeTrigger) existing.getTrigger();
String streamName = Objects.firstNonNull(scheduleUpdate.getStreamName(), existingTrigger.getStreamId().getStream());
int dataTriggerMB = Objects.firstNonNull(scheduleUpdate.getDataTriggerMB(), existingTrigger.getTriggerMB());
trigger = new StreamSizeTrigger(namespaceId.stream(streamName), dataTriggerMB);
} else if (scheduleUpdate.getStreamName() != null && scheduleUpdate.getDataTriggerMB() != null) {
trigger = new StreamSizeTrigger(namespaceId.stream(scheduleUpdate.getStreamName()), scheduleUpdate.getDataTriggerMB());
} else if (scheduleUpdate.getStreamName() != null || scheduleUpdate.getDataTriggerMB() != null) {
throw new IllegalArgumentException(String.format("Only one of stream name and data trigger MB is defined in schedule update details %s. " + "Must provide both stream name and data trigger MB to update the existing schedule with " + "trigger of type %s to a schedule with stream size trigger.", updateDetail, existing.getTrigger().getClass()));
}
List<Constraint> constraints = toConstraints(scheduleUpdate.getRunConstraints());
return new ScheduleDetail(null, scheduleUpdate.getDescription(), null, updateDetail.getProperties(), trigger, constraints, null);
}
Aggregations