/** * Get the profile id from namespace and the argument. Note that the profile name in the args is initially a scoped * name. If it is in system scope, this method will return a profile id which is in SYSTEM namespace, otherwise, it * will be in the given namespace. * * @param namespaceId namespace this profile is in * @param args arguments to look up * @return the profile id if it is present */ public static Optional<ProfileId> getProfileIdFromArgs(NamespaceId namespaceId, Map<String, String> args) { if (args.containsKey(PROFILE_NAME)) { String scopedProfile = args.get(SystemArguments.PROFILE_NAME); ProfileId profileId = ProfileId.fromScopedName(namespaceId, scopedProfile); return Optional.of(profileId); } return Optional.empty(); }
/** * Get the profile id from namespace and the argument. Note that the profile name in the args is initially a scoped * name. If it is in system scope, this method will return a profile id which is in SYSTEM namespace, otherwise, it * will be in the given namespace. * * @param namespaceId namespace this profile is in * @param args arguments to look up * @return the profile id if it is present */ public static Optional<ProfileId> getProfileIdFromArgs(NamespaceId namespaceId, Map<String, String> args) { if (args.containsKey(PROFILE_NAME)) { String scopedProfile = args.get(SystemArguments.PROFILE_NAME); ProfileId profileId = ProfileId.fromScopedName(namespaceId, scopedProfile); return Optional.of(profileId); } return Optional.empty(); }
/** * 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)); }
/** * Get the profile id for the provided entity id from the resolved preferences from preference dataset, * if no profile is inside, it will return the default profile * * @param entityId entity id to lookup the profile id * @return the profile id which will be used by this entity id, default profile if not find */ // TODO: CDAP-13579 consider preference key starts with [scope].[name].system.profile.name private ProfileId getResolvedProfileId(EntityId entityId) { NamespaceId namespaceId = entityId.getEntityType().equals(EntityType.INSTANCE) ? NamespaceId.SYSTEM : ((NamespacedEntityId) entityId).getNamespaceId(); String profileName = preferencesDataset.getResolvedPreference(entityId, SystemArguments.PROFILE_NAME); return profileName == null ? ProfileId.NATIVE : ProfileId.fromScopedName(namespaceId, profileName); }