Search in sources :

Example 1 with NamespaceMeta

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);
}
Also used : ProgramScheduleStoreDataset(co.cask.cdap.internal.app.runtime.schedule.store.ProgramScheduleStoreDataset) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 2 with NamespaceMeta

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);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 3 with NamespaceMeta

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;
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ProgramId(co.cask.cdap.proto.id.ProgramId) Nullable(javax.annotation.Nullable)

Example 4 with NamespaceMeta

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();
    }
}
Also used : TableId(co.cask.cdap.data2.util.TableId) HashMap(java.util.HashMap) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Future(java.util.concurrent.Future) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 5 with NamespaceMeta

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();
    }
}
Also used : NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ExploreExecutionResult(co.cask.cdap.explore.client.ExploreExecutionResult) Test(org.junit.Test)

Aggregations

NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)58 NamespaceId (co.cask.cdap.proto.id.NamespaceId)26 Test (org.junit.Test)22 IOException (java.io.IOException)12 Location (org.apache.twill.filesystem.Location)6 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)5 BadRequestException (co.cask.cdap.common.BadRequestException)5 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)5 ApplicationManager (co.cask.cdap.test.ApplicationManager)5 ExecutionException (java.util.concurrent.ExecutionException)5 NamespaceConfig (co.cask.cdap.proto.NamespaceConfig)4 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)4 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)3 RowMaker (co.cask.cdap.cli.util.RowMaker)3 Table (co.cask.cdap.cli.util.table.Table)3 NotFoundException (co.cask.cdap.common.NotFoundException)3 CConfiguration (co.cask.cdap.common.conf.CConfiguration)3 NamespaceAdmin (co.cask.cdap.common.namespace.NamespaceAdmin)3 Id (co.cask.cdap.proto.Id)3 ApplicationId (co.cask.cdap.proto.id.ApplicationId)3