/** * @return {@link NamespacedEntityId} to which the {@link Metadata} belongs if it is a known cdap entity type for * example datasets, applications etc. Custom resources likes fields etc cannot be converted into cdap * {@link NamespacedEntityId} and calling this for {@link Metadata} associated with such resources will fail with a * {@link IllegalArgumentException}. * @throws IllegalArgumentException if the {@link Metadata} belong to a custom cdap resource and not a known cdap * entity. */ public NamespacedEntityId getEntityId() { return EntityId.fromMetadataEntity(metadataEntity); }
public AuditMessage(long time, EntityId entityId, String user, AuditType type, AuditPayload payload) { this(time, entityId.toMetadataEntity(), user, type, payload); }
public NotFoundException(EntityId entityId) { this(entityId, entityId.toString()); }
/** * 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 String getUserFriendlyEntityStr(EntityId entityId) { switch (entityId.getEntityType()) { case INSTANCE: return "the system instance"; case NAMESPACE: return String.format("namespace '%s'", entityId.getEntityName()); case APPLICATION: ApplicationId applicationId = (ApplicationId) entityId; return String.format("application '%s' in namespace '%s'", applicationId.getApplication(), applicationId.getNamespace()); case PROGRAM: ProgramId programId = (ProgramId) entityId; return String.format("%s '%s' in namespace '%s'", programId.getType().name().toLowerCase(), programId.getProgram(), programId.getNamespace()); } return entityId.toString(); }
metadataEntity = EntityId.fromMetadataEntity(metadataEntity).toMetadataEntity();
/** * Remove the profile metadata according to the message, currently only meant for application and schedule. */ private void removeProfileMetadata(MetadataMessage message) { EntityId entity = message.getEntityId(); Map<MetadataEntity, Set<String>> toRemove = new HashMap<>(); // We only care about application and schedules. if (entity.getEntityType().equals(EntityType.APPLICATION)) { ApplicationId appId = (ApplicationId) message.getEntityId(); ApplicationSpecification appSpec = message.getPayload(GSON, ApplicationSpecification.class); for (ProgramId programId : getAllProfileAllowedPrograms(appSpec, appId)) { toRemove.put(programId.toMetadataEntity(), PROFILE_METADATA_KEY_SET); } for (ScheduleId scheduleId : getSchedulesInApp(appId, appSpec.getProgramSchedules())) { toRemove.put(scheduleId.toMetadataEntity(), PROFILE_METADATA_KEY_SET); } } else if (entity.getEntityType().equals(EntityType.SCHEDULE)) { toRemove.put(entity.toMetadataEntity(), PROFILE_METADATA_KEY_SET); } if (!toRemove.isEmpty()) { metadataStore.removeProperties(MetadataScope.SYSTEM, toRemove); } }
throw new IllegalArgumentException("EntityId is required."); String entity = entityId.toString(); if (entityId.getEntityType().equals(EntityType.ARTIFACT) || entityId.getEntityType().equals(EntityType.APPLICATION) || entityId.getEntityType().equals(EntityType.PROGRAM)) { int versionStartIndex = entity.indexOf(EntityId.IDSTRING_PART_SEPARATOR, entity.indexOf(EntityId.IDSTRING_PART_SEPARATOR) + 1); int versionEndIndex = entity.length(); if (entityId.getEntityType().equals(EntityType.PROGRAM)) {
Multimap<AuditType, EntityId> actualAuditEntities = HashMultimap.create(); for (AuditMessage message : publishedMessages) { EntityId entityId = EntityId.fromMetadataEntity(message.getEntity()); if (entityId instanceof NamespacedEntityId) { if (((NamespacedEntityId) entityId).getNamespace().equals(NamespaceId.SYSTEM.getNamespace())) { if (entityId.getEntityType() == EntityType.ARTIFACT && entityId instanceof ArtifactId) { ArtifactId artifactId = (ArtifactId) entityId;
private boolean isEnforcingOnSamePrincipalId(EntityId entityId, Principal principal) { return entityId.getEntityType().equals(EntityType.KERBEROSPRINCIPAL) && principal.getName().equals(entityId.getEntityName()); } }
@Override public boolean equals(Object o) { if (!super.equals(o)) { return false; } QueryId queryId = (QueryId) o; return Objects.equals(handle, queryId.handle); }
public static ApplicationId fromString(String string) { return EntityId.fromString(string, ApplicationId.class); } }
if (!EntityId.isValidId(defn.getFlowletSpec().getName())) { return VerifyResult.failure(Err.NOT_AN_ID, flowName + ":" + flowletName); if (!EntityId.isValidDatasetId(dataSet)) { return VerifyResult.failure(Err.NOT_AN_ID, flowName + ":" + flowletName + ":" + dataSet);
public static void ensureValidDatasetId(String propertyName, String datasetId) { if (!isValidDatasetId(datasetId)) { throw new IllegalArgumentException(String.format("Invalid %s ID: %s. Should only contain alphanumeric " + "characters, $, ., _, or -.", propertyName, datasetId)); } }
/** * Returns the EntityId represented by the given MetadataEntity. Note: Custom MetadataEntity cannot be converted * into EntityId hence this call is only safe to be called if the MetadataEntity does represent an EntityId and can * actually be converted to an EntityId. * @param metadataEntity the MetadataEntity which needs to be converted to EntityId * @return the EntityId * @throws IllegalArgumentException if the metadataEntity does not represent an EntityId and is a custom * metadataEntity. */ public static <T extends EntityId> T fromMetadataEntity(MetadataEntity metadataEntity) { // check that the type of teh metadata entity is known type EntityType.valueOf(metadataEntity.getType().toUpperCase()); return getSelfOrParentEntityId(metadataEntity); }
private void addComponent(MDSKey.Builder keyBuilder, EntityId component) { if (component instanceof FlowletId) { keyBuilder.add(FLOWLET_MARKER) .add(component.getEntityName()); } else { keyBuilder.add(NONE_MARKER); } }
@Override protected boolean shouldRunInSeparateTx(MetadataMessage message) { EntityType entityType = message.getEntityId().getEntityType(); return entityType.equals(EntityType.INSTANCE) || entityType.equals(EntityType.NAMESPACE); }
private String getUserFriendlyEntityStr(EntityId entityId) { switch (entityId.getEntityType()) { case INSTANCE: return "the system instance"; case NAMESPACE: return String.format("namespace '%s'", entityId.getEntityName()); case APPLICATION: ApplicationId applicationId = (ApplicationId) entityId; return String.format("application '%s' in namespace '%s'", applicationId.getApplication(), applicationId.getNamespace()); case PROGRAM: ProgramId programId = (ProgramId) entityId; return String.format("%s '%s' in namespace '%s'", programId.getType().name().toLowerCase(), programId.getProgram(), programId.getNamespace()); } return entityId.toString(); }
metadataEntity = EntityId.fromMetadataEntity(metadataEntity).toMetadataEntity();
/** * Remove the profile metadata according to the message, currently only meant for application and schedule. */ private void removeProfileMetadata(MetadataMessage message) { EntityId entity = message.getEntityId(); // We only care about application and schedules. if (entity.getEntityType().equals(EntityType.APPLICATION)) { ApplicationId appId = (ApplicationId) message.getEntityId(); ApplicationSpecification appSpec = message.getPayload(GSON, ApplicationSpecification.class); for (ProgramId programId : getProgramsWithType(appId, ProgramType.WORKFLOW, appSpec.getWorkflows())) { metadataDataset.removeProperties(programId.toMetadataEntity(), Collections.singleton(PROFILE_METADATA_KEY)); } for (ScheduleId scheduleId : getSchedulesInApp(appId, appSpec.getProgramSchedules())) { metadataDataset.removeProperties(scheduleId.toMetadataEntity(), Collections.singleton(PROFILE_METADATA_KEY)); } } if (entity.getEntityType().equals(EntityType.SCHEDULE)) { metadataDataset.removeProperties(message.getEntityId().toMetadataEntity(), Collections.singleton(PROFILE_METADATA_KEY)); } }