/** * Returns an empty {@link MetadataRecord} in the specified {@link MetadataScope}. */ public MetadataRecord(NamespacedEntityId entityId, MetadataScope scope) { this(entityId.toMetadataEntity(), scope); }
/** * Validates the given {@link NamespacedEntityId} to be supported by the {@link OwnerStore} * i.e. the entity can be associated with an owner. * * @param entityId {@link NamespacedEntityId} to be validated */ protected final void validate(NamespacedEntityId entityId) { if (!SUPPORTED_ENTITY_TYPES.contains(entityId.getEntityType())) { throw new IllegalArgumentException(String.format("The given entity '%s' is of unsupported types '%s'. " + "Entity ownership is only supported for '%s'.", entityId.getEntityName(), entityId.getEntityType(), SUPPORTED_ENTITY_TYPES)); } }
protected NamespacedEntityId(String namespace, EntityType entity) { super(entity); if (namespace == null) { throw new NullPointerException("Namespace can not be null."); } ensureValidNamespace(namespace); this.namespace = namespace; }
private NamespaceConfig getNamespaceConfig(NamespacedEntityId entityId) throws IOException { try { if (entityId.getNamespaceId().equals(NamespaceId.SYSTEM)) { return NamespaceMeta.SYSTEM.getConfig(); } return namespaceQueryAdmin.get(entityId.getNamespaceId()).getConfig(); } catch (IOException e) { throw e; } catch (Exception e) { throw new IOException(e); } }
public NamespaceId getNamespaceId() { return new NamespaceId(getNamespace()); } }
@Override public boolean equals(Object o) { if (!super.equals(o)) { return false; } NamespaceId that = (NamespaceId) o; return Objects.equals(namespace, that.namespace); }
if (impersonationRequest.getEntityId().getEntityType().equals(EntityType.NAMESPACE) && impersonationRequest.getImpersonatedOpType().equals(ImpersonatedOpType.EXPLORE)) { namespaceQueryAdmin.get(impersonationRequest.getEntityId().getNamespaceId()).getConfig(); if (!nsConfig.isExploreAsPrincipal()) { throw new FeatureDisabledException(FeatureDisabledException.Feature.EXPLORE,
@Override public String apply(NamespacedEntityId input) { return input.getEntityName(); } };
@Override public void perform(Arguments arguments, PrintStream output) throws Exception { String searchQuery = arguments.get(ArgumentName.SEARCH_QUERY.toString()); String type = arguments.getOptional(ArgumentName.TARGET_TYPE.toString()); MetadataSearchResponse metadataSearchResponse = metadataClient.searchMetadata(cliConfig.getCurrentNamespace(), searchQuery, parseTargetType(type)); Set<MetadataSearchResultRecord> searchResults = metadataSearchResponse.getResults(); Table table = Table.builder() .setHeader("Entity") .setRows(Lists.newArrayList(searchResults), searchResult -> Lists.newArrayList(searchResult.getEntityId().toString())).build(); cliConfig.getTableRenderer().render(cliConfig, output, table); }
private boolean isAccessingSystemNSAsMasterUser(EntityId entityId, Principal principal) { return entityId instanceof NamespacedEntityId && ((NamespacedEntityId) entityId).getNamespaceId().equals(NamespaceId.SYSTEM) && principal.equals(masterUser); }
public NamespaceId getNamespaceId() { return new NamespaceId(getNamespace()); } }
@Override public boolean equals(Object o) { if (!super.equals(o)) { return false; } NamespaceId that = (NamespaceId) o; return Objects.equals(namespace, that.namespace); }
@Nullable @Override public ImpersonationInfo getImpersonationInfo(NamespacedEntityId entityId) throws IOException { entityId = getEffectiveEntity(entityId); if (!entityId.getEntityType().equals(EntityType.NAMESPACE)) { KerberosPrincipalId effectiveOwner = ownerStore.getOwner(entityId); if (effectiveOwner != null) { return new ImpersonationInfo(effectiveOwner.getPrincipal(), SecurityUtil.getKeytabURIforPrincipal(effectiveOwner.getPrincipal(), cConf)); } } // (CDAP-8176) Since no owner was found for the entity return namespace principal if present. NamespaceConfig nsConfig = getNamespaceConfig(entityId.getNamespaceId()); return nsConfig.getPrincipal() == null ? null : new ImpersonationInfo(nsConfig.getPrincipal(), nsConfig.getKeytabURI()); }
@Override public String apply(NamespacedEntityId input) { return input.getEntityName(); } };
@Override public void perform(Arguments arguments, PrintStream output) throws Exception { String searchQuery = arguments.get(ArgumentName.SEARCH_QUERY.toString()); String type = arguments.getOptional(ArgumentName.TARGET_TYPE.toString()); MetadataSearchResponse metadataSearchResponse = metadataClient.searchMetadata(cliConfig.getCurrentNamespace(), searchQuery, parseTargetType(type), null, 0, Integer.MAX_VALUE, 0, null, false); Set<MetadataSearchResultRecord> searchResults = metadataSearchResponse.getResults(); Table table = Table.builder() .setHeader("Entity") .setRows(Lists.newArrayList(searchResults), searchResult -> Lists.newArrayList(searchResult.getEntityId().toString())).build(); cliConfig.getTableRenderer().render(cliConfig, output, table); }
/** * Returns an empty {@link MetadataRecord} in the specified {@link MetadataScope}. */ public MetadataRecord(NamespacedEntityId entityId, MetadataScope scope, Map<String, String> properties, Set<String> tags) { this(entityId.toMetadataEntity(), scope, properties, tags); }
/** * Get the profile id for the provided entity id from its own preferences from preference dataset. * * @param entityId entity id to lookup the profile id * @return the profile id configured for this entity id, if any */ private Optional<ProfileId> getProfileId(EntityId entityId) { NamespaceId namespaceId = entityId.getEntityType().equals(EntityType.INSTANCE) ? NamespaceId.SYSTEM : ((NamespacedEntityId) entityId).getNamespaceId(); String profileName = preferencesDataset.getPreferences(entityId).get(SystemArguments.PROFILE_NAME); return profileName == null ? Optional.empty() : Optional.of(ProfileId.fromScopedName(namespaceId, profileName)); }
private LineageRecord getLineage(NamespacedEntityId namespacedId, String path) throws IOException, UnauthenticatedException, NotFoundException, BadRequestException, UnauthorizedException { URL lineageURL = config.resolveNamespacedURLV3(new NamespaceId(namespacedId.getNamespace()), path); HttpResponse response = restClient.execute(HttpRequest.get(lineageURL).build(), config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_NOT_FOUND); if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) { throw new BadRequestException(response.getResponseBodyAsString()); } if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new NotFoundException(response.getResponseBodyAsString()); } return GSON.fromJson(response.getResponseBodyAsString(), LineageRecord.class); } }
@Override public boolean equals(Object o) { if (!super.equals(o)) { return false; } DatasetId datasetId = (DatasetId) o; return Objects.equals(namespace, datasetId.namespace) && Objects.equals(dataset, datasetId.dataset); }
/** * <p>Verifies the owner principal of an entity is same as the owner specified during entity creation. If an owner * was not specified during entity creation but is being specified later (i.e. during updating properties etc) the * specified owner principal is same as the effective impersonating principal.</p> * <p>Note: This method should not be called for an non-existing entity for example while the entity is being * created.</p> * @param existingEntity the existing entity whose owner principal is being verified * @param specifiedOwnerPrincipal the specified principal * @param ownerAdmin {@link OwnerAdmin} * @throws IOException if failed to query the given ownerAdmin * @throws UnauthorizedException if the specified owner information is not valid with the existing * impersonation principal */ public static void verifyOwnerPrincipal(NamespacedEntityId existingEntity, @Nullable String specifiedOwnerPrincipal, OwnerAdmin ownerAdmin) throws IOException, UnauthorizedException { // if an owner principal was not specified then ensure that a direct owner doesn't exist. Although, if an owner // principal was specified then it must be equal to the effective impersonating principal of this entity if (!((specifiedOwnerPrincipal == null && ownerAdmin.getOwnerPrincipal(existingEntity) == null) || Objects.equals(specifiedOwnerPrincipal, ownerAdmin.getImpersonationPrincipal(existingEntity)))) { // Not giving existing owner information as it might be unacceptable under some security scenarios throw new UnauthorizedException(String.format("%s '%s' already exists and the specified %s '%s' is not the " + "same as the existing one. The %s of an entity cannot be " + "changed.", existingEntity.getEntityType(), existingEntity.getEntityName(), Constants.Security.PRINCIPAL, specifiedOwnerPrincipal, Constants.Security.PRINCIPAL)); } }