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);
}
}
}
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());
}
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!");
}
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));
}
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));
}
Aggregations