use of io.cdap.cdap.common.NamespaceNotFoundException in project cdap by caskdata.
the class RemoteApplicationDetailFetcher method list.
/**
* Get details of all applications in the given namespace
*/
public List<ApplicationDetail> list(String namespace) throws IOException, NamespaceNotFoundException, UnauthorizedException {
String url = String.format("namespaces/%s/apps", namespace);
HttpRequest.Builder requestBuilder = remoteClient.requestBuilder(HttpMethod.GET, url);
HttpResponse httpResponse;
try {
httpResponse = execute(requestBuilder.build());
} catch (NotFoundException e) {
throw new NamespaceNotFoundException(new NamespaceId(namespace));
}
ObjectResponse<List<ApplicationDetail>> objectResponse = ObjectResponse.fromJsonBody(httpResponse, APPLICATION_DETAIL_LIST_TYPE, GSON);
return objectResponse.getResponseObject();
}
use of io.cdap.cdap.common.NamespaceNotFoundException in project cdap by caskdata.
the class SecureStoreClient method listKeys.
/**
* List all the secure keys in the namespace
* @param namespaceId {@link NamespaceId} namespace id
* @return list of key names and descriptions
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws NamespaceNotFoundException if the given namespace is not found
*/
public List<SecureStoreMetadata> listKeys(NamespaceId namespaceId) throws IOException, UnauthenticatedException, NamespaceNotFoundException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(namespaceId, SECURE_KEYS);
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NamespaceNotFoundException(namespaceId);
}
return ObjectResponse.fromJsonBody(response, new TypeToken<List<SecureStoreMetadata>>() {
}).getResponseObject();
}
use of io.cdap.cdap.common.NamespaceNotFoundException in project cdap by caskdata.
the class DefaultNamespaceAdmin method updateProperties.
@Override
public synchronized void updateProperties(NamespaceId namespaceId, NamespaceMeta namespaceMeta) throws Exception {
if (!exists(namespaceId)) {
throw new NamespaceNotFoundException(namespaceId);
}
accessEnforcer.enforce(namespaceId, authenticationContext.getPrincipal(), StandardPermission.UPDATE);
NamespaceMeta existingMeta = nsStore.get(namespaceId);
// Already ensured that namespace exists, so namespace meta should not be null
Preconditions.checkNotNull(existingMeta);
NamespaceMeta.Builder builder = new NamespaceMeta.Builder(existingMeta);
if (namespaceMeta.getDescription() != null) {
builder.setDescription(namespaceMeta.getDescription());
}
NamespaceConfig config = namespaceMeta.getConfig();
if (config != null && !Strings.isNullOrEmpty(config.getSchedulerQueueName())) {
builder.setSchedulerQueueName(config.getSchedulerQueueName());
}
if (config != null && config.getKeytabURI() != null) {
String keytabURI = config.getKeytabURI();
if (keytabURI.isEmpty()) {
throw new BadRequestException("Cannot update keytab URI with an empty URI.");
}
String existingKeytabURI = existingMeta.getConfig().getKeytabURIWithoutVersion();
if (existingKeytabURI == null) {
throw new BadRequestException("Cannot update keytab URI since there is no existing principal or keytab URI.");
}
if (keytabURI.equals(existingKeytabURI)) {
// The given keytab URI is the same as the existing one, but the content of the keytab file might be changed.
// Increment the keytab URI version so that the cache will reload content in the updated keytab file.
builder.incrementKeytabURIVersion();
} else {
builder.setKeytabURIWithoutVersion(keytabURI);
// clear keytab URI version
builder.setKeytabURIVersion(0);
}
}
if (config != null) {
builder.setExploreAsPrincipal(config.isExploreAsPrincipal());
}
Set<String> difference = existingMeta.getConfig().getDifference(config);
if (!difference.isEmpty()) {
throw new BadRequestException(String.format("Mappings %s for namespace %s cannot be updated once the namespace " + "is created.", difference, namespaceId));
}
NamespaceMeta updatedMeta = builder.build();
nsStore.update(updatedMeta);
// refresh the cache with new meta
namespaceMetaCache.refresh(namespaceId);
LOG.info("Namespace {} updated with meta {}", namespaceId, updatedMeta);
}
use of io.cdap.cdap.common.NamespaceNotFoundException in project cdap by caskdata.
the class DefaultNamespaceAdmin method get.
/**
* Gets details of a namespace
*
* @param namespaceId the {@link Id.Namespace} of the requested namespace
* @return the {@link NamespaceMeta} of the requested namespace
* @throws NamespaceNotFoundException if the requested namespace is not found
* @throws UnauthorizedException if the namespace is not authorized to the logged-user
*/
@Override
public NamespaceMeta get(NamespaceId namespaceId) throws Exception {
Principal principal = authenticationContext.getPrincipal();
UnauthorizedException lastUnauthorizedException = null;
// See: CDAP-7387
if (masterShortUserName == null || !masterShortUserName.equals(principal.getName())) {
try {
accessEnforcer.enforce(namespaceId, principal, StandardPermission.GET);
} catch (UnauthorizedException e) {
lastUnauthorizedException = e;
}
}
NamespaceMeta namespaceMeta = null;
try {
namespaceMeta = namespaceMetaCache.get(namespaceId);
} catch (Exception e) {
if (lastUnauthorizedException == null) {
Throwable cause = e.getCause();
if (cause instanceof NamespaceNotFoundException || cause instanceof IOException || cause instanceof UnauthorizedException) {
throw (Exception) cause;
}
throw e;
}
}
// If the requesting user is same as namespace owner, we do not care about if the user is authorized or not
if (namespaceMeta != null && principal.getName().equals(namespaceMeta.getConfig().getPrincipal())) {
return namespaceMeta;
}
if (lastUnauthorizedException != null) {
throw lastUnauthorizedException;
}
return namespaceMeta;
}
Aggregations