use of co.cask.cdap.proto.NamespaceMeta 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);
}
use of co.cask.cdap.proto.NamespaceMeta 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);
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class ProgramLifecycleService method retrieveProgramIdForRunRecord.
/**
* Helper method to get {@link ProgramId} for a RunRecord for type of program
*
* @param programType Type of program to search
* @param runId The target id of the {@link RunRecord} to find
* @return the program id of the run record or {@code null} if does not exist.
*/
@Nullable
private ProgramId retrieveProgramIdForRunRecord(ProgramType programType, String runId) {
// Get list of namespaces (borrow logic from AbstractAppFabricHttpHandler#listPrograms)
List<NamespaceMeta> namespaceMetas = nsStore.list();
// For each, get all programs under it
ProgramId targetProgramId = null;
for (NamespaceMeta nm : namespaceMetas) {
NamespaceId namespace = Ids.namespace(nm.getName());
Collection<ApplicationSpecification> appSpecs = store.getAllApplications(namespace);
// For each application get the programs checked against run records
for (ApplicationSpecification appSpec : appSpecs) {
switch(programType) {
case FLOW:
for (String programName : appSpec.getFlows().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case MAPREDUCE:
for (String programName : appSpec.getMapReduce().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case SPARK:
for (String programName : appSpec.getSpark().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case SERVICE:
for (String programName : appSpec.getServices().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case WORKER:
for (String programName : appSpec.getWorkers().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case WORKFLOW:
for (String programName : appSpec.getWorkflows().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case CUSTOM_ACTION:
case WEBAPP:
// no-op
break;
default:
LOG.debug("Unknown program type: " + programType.name());
break;
}
if (targetProgramId != null) {
break;
}
}
if (targetProgramId != null) {
break;
}
}
return targetProgramId;
}
use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.
the class HBaseQueueAdmin method upgrade.
@Override
public void upgrade() throws Exception {
int numThreads = cConf.getInt(Constants.Upgrade.UPGRADE_THREAD_POOL_SIZE);
final ExecutorService executor = Executors.newFixedThreadPool(numThreads, new ThreadFactoryBuilder().setNameFormat("hbase-cmd-executor-%d").setDaemon(true).build());
try {
final Map<TableId, Future<?>> allFutures = new HashMap<>();
// For each queue config table and queue data table in each namespace, perform an upgrade
for (final NamespaceMeta namespaceMeta : namespaceQueryAdmin.list()) {
impersonator.doAs(namespaceMeta.getNamespaceId(), new Callable<Void>() {
@Override
public Void call() throws Exception {
Map<TableId, Future<?>> futures = upgradeQueues(namespaceMeta, executor);
allFutures.putAll(futures);
return null;
}
});
}
// Wait for the queue upgrades to complete
Map<TableId, Throwable> failed = waitForUpgrade(allFutures);
if (!failed.isEmpty()) {
for (Map.Entry<TableId, Throwable> entry : failed.entrySet()) {
LOG.error("Failed to upgrade queue table {}", entry.getKey(), entry.getValue());
}
throw new Exception(String.format("Error upgrading queue tables. %s of %s failed", failed.size(), allFutures.size()));
}
} finally {
// We'll have tasks pending in the executor only on an interrupt, when user wants to abort the upgrade.
// Use shutdownNow() to interrupt the tasks and abort.
executor.shutdownNow();
}
}
use of co.cask.cdap.proto.NamespaceMeta 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();
}
}
Aggregations