/** * 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); } }
/** * 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)); } }
Assert.assertEquals(Collections.emptyMap(), mds.getProperties(scheduleId.toMetadataEntity())); () -> mds.getProperties(scheduleId.toMetadataEntity()).get("profile"), 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); Tasks.waitFor(myProfile.getScopedName(), () -> mds.getProperties(scheduleId.toMetadataEntity()).get("profile"), 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); Tasks.waitFor(myProfile2.getScopedName(), () -> mds.getProperties(scheduleId.toMetadataEntity()).get("profile"), 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); Tasks.waitFor(myProfile2.getScopedName(), () -> mds.getProperties(scheduleId.toMetadataEntity()).get("profile"), 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); Tasks.waitFor(myProfile.getScopedName(), () -> mds.getProperties(scheduleId.toMetadataEntity()).get("profile"), 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); () -> mds.getProperties(scheduleId.toMetadataEntity()).get("profile"), 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); } finally { profileService.deleteAllProfiles(myProfile.getNamespaceId()); mds.removeMetadata(workflowId.toMetadataEntity()); mds.removeMetadata(scheduleId.toMetadataEntity());
ScheduleId scheduleId2 = new ApplicationId("ns", "app", "2").schedule("s"); // custom version mdsValueKey = MetadataKey.createValueRowKey(scheduleId1.toMetadataEntity(), "key1"); actual = MetadataKey.extractMetadataEntityFromKey(mdsValueKey.getKey()); Assert.assertEquals(scheduleId1.toMetadataEntity(), actual); mdsValueKey = MetadataKey.createValueRowKey(scheduleId2.toMetadataEntity(), "key1"); actual = MetadataKey.extractMetadataEntityFromKey(mdsValueKey.getKey()); Assert.assertEquals(scheduleId1.toMetadataEntity(), actual);