Search in sources :

Example 11 with NamespaceMeta

use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class DatasetUpgrader method upgradeUserTables.

private void upgradeUserTables(final ExecutorService executor) throws Exception {
    final Map<String, Future<?>> allFutures = new HashMap<>();
    final List<Closeable> toClose = new ArrayList<>();
    for (final NamespaceMeta namespaceMeta : namespaceQueryAdmin.list()) {
        impersonator.doAs(namespaceMeta.getNamespaceId(), new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get();
                // register it for close, after all Futures are complete
                toClose.add(ddlExecutor);
                Map<String, Future<?>> futures = upgradeUserTables(namespaceMeta, executor, ddlExecutor);
                allFutures.putAll(futures);
                return null;
            }
        });
    }
    // Wait for the user dataset upgrades to complete
    try {
        Map<String, Throwable> failed = waitForUpgrade(allFutures);
        if (!failed.isEmpty()) {
            for (Map.Entry<String, Throwable> entry : failed.entrySet()) {
                LOG.error("Failed to upgrade user table {}", entry.getKey(), entry.getValue());
            }
            throw new Exception(String.format("Error upgrading user tables. %s of %s failed", failed.size(), allFutures.size()));
        }
    } finally {
        for (Closeable closeable : toClose) {
            Closeables.closeQuietly(closeable);
        }
    }
}
Also used : HBaseDDLExecutor(io.cdap.cdap.spi.hbase.HBaseDDLExecutor) HashMap(java.util.HashMap) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) Future(java.util.concurrent.Future) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with NamespaceMeta

use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class IntegrationTestBaseTest method testDeployApplicationInNamespace.

@Test
public void testDeployApplicationInNamespace() throws Exception {
    NamespaceId namespace = new NamespaceId("Test1");
    NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(namespace).build();
    getNamespaceClient().create(namespaceMeta);
    ClientConfig clientConfig = new ClientConfig.Builder(getClientConfig()).build();
    deployApplication(namespace, AllProgramsApp.class);
    // Check the default namespaces applications to see whether the application wasn't made in the default namespace
    ClientConfig defaultClientConfig = new ClientConfig.Builder(getClientConfig()).build();
    Assert.assertTrue(new ApplicationClient(defaultClientConfig).list(NamespaceId.DEFAULT).isEmpty());
    ApplicationClient applicationClient = new ApplicationClient(clientConfig);
    Assert.assertEquals(AllProgramsApp.NAME, applicationClient.list(namespace).get(0).getName());
    applicationClient.delete(namespace.app(AllProgramsApp.NAME));
    Assert.assertTrue(new ApplicationClient(clientConfig).list(namespace).isEmpty());
}
Also used : ApplicationClient(io.cdap.cdap.client.ApplicationClient) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ClientConfig(io.cdap.cdap.client.config.ClientConfig) Test(org.junit.Test)

Example 13 with NamespaceMeta

use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class IntegrationTestBase method checkSystemServices.

protected void checkSystemServices() throws TimeoutException, InterruptedException {
    Callable<Boolean> cdapAvailable = new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            // first wait for all system services to be 'OK'
            if (!getMonitorClient().allSystemServicesOk()) {
                return false;
            }
            // For non-default namespaces, simply check that the dataset service is up with list().
            // If list() does not throw exception, which means the http request receives response
            // status HTTP_OK and dataset service is up, then check if default namespace exists, if so return true.
            List<NamespaceMeta> list = getNamespaceClient().list();
            if (!configuredNamespace.equals(NamespaceId.DEFAULT)) {
                return true;
            }
            // default namespace exists before integration test starts
            for (NamespaceMeta namespaceMeta : list) {
                if (namespaceMeta.getNamespaceId().equals(NamespaceId.DEFAULT)) {
                    return true;
                }
            }
            return false;
        }
    };
    String errorMessage = String.format("CDAP Services are not available. Retried for %s seconds.", SERVICE_CHECK_TIMEOUT_SECONDS);
    try {
        checkServicesWithRetry(cdapAvailable, errorMessage);
    } catch (Throwable e) {
        Throwable rootCause = Throwables.getRootCause(e);
        if (rootCause instanceof UnauthenticatedException) {
            // security is enabled, we need to get access token before checking system services
            try {
                accessToken = fetchAccessToken();
            } catch (IOException ex) {
                throw Throwables.propagate(ex);
            }
            checkServicesWithRetry(cdapAvailable, errorMessage);
        } else {
            throw Throwables.propagate(rootCause);
        }
    }
    LOG.info("CDAP Services are up and running!");
}
Also used : UnauthenticatedException(io.cdap.cdap.security.spi.authentication.UnauthenticatedException) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) IOException(java.io.IOException) Callable(java.util.concurrent.Callable)

Example 14 with NamespaceMeta

use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class NamespaceHttpHandler method getNamespace.

@GET
@Path("/namespaces/{namespace-id}")
public void getNamespace(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
    // return keytab URI without version
    NamespaceMeta ns = new NamespaceMeta.Builder(namespaceAdmin.get(new NamespaceId(namespaceId))).buildWithoutKeytabURIVersion();
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ns));
}
Also used : NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 15 with NamespaceMeta

use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class ApplicationLifecycleServiceTest method testOwnerInImpersonatedNS.

@Test
public void testOwnerInImpersonatedNS() throws Exception {
    // create a namespace with principal
    String nsPrincipal = "nsCreator/somehost.net@somekdc.net";
    String nsKeytabURI = "some/path";
    NamespaceMeta impNsMeta = new NamespaceMeta.Builder().setName("impNs").setPrincipal(nsPrincipal).setKeytabURI(nsKeytabURI).build();
    createNamespace(GSON.toJson(impNsMeta), impNsMeta.getName());
    // deploy an app without owner
    deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, impNsMeta.getName());
    // try to redeploy with some owner different than namespace principal it should fail
    deploy(AllProgramsApp.class, HttpResponseStatus.FORBIDDEN.code(), Constants.Gateway.API_VERSION_3_TOKEN, impNsMeta.getName(), "bob/somehost.net@somekdc.net");
    // although trying to re-deploy the app with namespace principal should work
    deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, impNsMeta.getName(), nsPrincipal);
    // re-deploy without any owner should also work
    deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, impNsMeta.getName());
    // cleanup
    deleteNamespace(impNsMeta.getName());
    Assert.assertEquals(HttpResponseCodes.SC_NOT_FOUND, getNamespace(impNsMeta.getName()).getResponseCode());
    // create an impersonated ns again
    createNamespace(GSON.toJson(impNsMeta), impNsMeta.getName());
    // deploy an app with an owner
    deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, impNsMeta.getName(), "bob/somehost.net@somekdc.net");
    // re-deploy with namespace principal should fail
    deploy(AllProgramsApp.class, HttpResponseStatus.FORBIDDEN.code(), Constants.Gateway.API_VERSION_3_TOKEN, impNsMeta.getName(), impNsMeta.getConfig().getPrincipal());
    // although redeploy with same app principal should work
    deploy(AllProgramsApp.class, HttpResponseStatus.OK.code(), Constants.Gateway.API_VERSION_3_TOKEN, impNsMeta.getName(), "bob/somehost.net@somekdc.net");
    // delete, otherwise it conflicts with other tests
    deleteAppAndData(impNsMeta.getNamespaceId().app(AllProgramsApp.NAME));
}
Also used : NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) Test(org.junit.Test)

Aggregations

NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)144 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)76 Test (org.junit.Test)54 IOException (java.io.IOException)30 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)18 BadRequestException (io.cdap.cdap.common.BadRequestException)14 NotFoundException (io.cdap.cdap.common.NotFoundException)14 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)14 DatasetId (io.cdap.cdap.proto.id.DatasetId)14 HashMap (java.util.HashMap)14 HashSet (java.util.HashSet)14 EntityId (io.cdap.cdap.proto.id.EntityId)12 GrantedPermission (io.cdap.cdap.proto.security.GrantedPermission)12 Location (org.apache.twill.filesystem.Location)12 Set (java.util.Set)11 ImmutableSet (com.google.common.collect.ImmutableSet)10 KeyValueTable (io.cdap.cdap.api.dataset.lib.KeyValueTable)10 PartitionedFileSet (io.cdap.cdap.api.dataset.lib.PartitionedFileSet)10 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)10 AccessPermission (io.cdap.cdap.proto.security.AccessPermission)10