use of io.cdap.cdap.internal.profile.ProfileService in project cdap by caskdata.
the class TetheringServerHandlerTest method setup.
@BeforeClass
public static void setup() throws IOException {
cConf = CConfiguration.create();
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
topicPrefix = cConf.get(Constants.Tethering.TOPIC_PREFIX);
injector = Guice.createInjector(new ConfigModule(cConf), new SystemDatasetRuntimeModule().getInMemoryModules(), new TransactionModules().getInMemoryModules(), new TransactionExecutorModule(), new InMemoryDiscoveryModule(), new LocalLocationModule(), new MessagingServerRuntimeModule().getInMemoryModules(), new StorageModule(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getMasterModule(), new PrivateModule() {
@Override
protected void configure() {
bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class).in(Scopes.SINGLETON);
expose(MetricsCollectionService.class);
bind(MetricsSystemClient.class).toInstance(new NoOpMetricsSystemClient());
expose(MetricsSystemClient.class);
}
});
tetheringStore = new TetheringStore(injector.getInstance(TransactionRunner.class));
messagingService = injector.getInstance(MessagingService.class);
if (messagingService instanceof Service) {
((Service) messagingService).startAndWait();
}
profileService = injector.getInstance(ProfileService.class);
txManager = injector.getInstance(TransactionManager.class);
txManager.startAndWait();
}
use of io.cdap.cdap.internal.profile.ProfileService in project cdap by caskdata.
the class MetadataSubscriberServiceTest method testProfileMetadataWithNoProfilePreferences.
@Test
public void testProfileMetadataWithNoProfilePreferences() throws Exception {
Injector injector = getInjector();
// add a new profile in default namespace
ProfileService profileService = injector.getInstance(ProfileService.class);
ProfileId myProfile = new ProfileId(NamespaceId.DEFAULT.getNamespace(), "MyProfile");
Profile profile1 = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), Profile.NATIVE.getProvisioner());
profileService.saveProfile(myProfile, profile1);
// add a app with workflow to app meta store
ApplicationSpecification appSpec = Specifications.from(new AppWithWorkflow());
ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
ProgramId workflowId = appId.workflow("SampleWorkflow");
// get the metadata - should be empty since we haven't deployed the app
MetadataStorage mds = injector.getInstance(MetadataStorage.class);
Assert.assertEquals(Collections.emptyMap(), mds.read(new Read(workflowId.toMetadataEntity())).getProperties());
Store store = injector.getInstance(DefaultStore.class);
store.addApplication(appId, appSpec);
// set default namespace to use the profile, since now MetadataSubscriberService is not started,
// it should not affect the mds
PreferencesService preferencesService = injector.getInstance(PreferencesService.class);
preferencesService.setProperties(NamespaceId.DEFAULT, Collections.singletonMap(SystemArguments.PROFILE_NAME, "USER:MyProfile"));
try {
// Verify the workflow profile metadata is updated to my profile
Tasks.waitFor(myProfile.getScopedName(), () -> getProfileProperty(mds, workflowId), 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
// Set the property without profile is a replacement of the preference, so it is same as deletion of the profile
preferencesService.setProperties(NamespaceId.DEFAULT, Collections.emptyMap());
// Verify the workflow profile metadata is updated to default profile
Tasks.waitFor(ProfileId.NATIVE.getScopedName(), () -> getProfileProperty(mds, workflowId), 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
} finally {
// stop and clean up the store
preferencesService.deleteProperties(NamespaceId.DEFAULT);
store.removeAll(NamespaceId.DEFAULT);
profileService.disableProfile(myProfile);
profileService.deleteProfile(myProfile);
mds.apply(new MetadataMutation.Drop(workflowId.toMetadataEntity()), MutationOptions.DEFAULT);
}
}
use of io.cdap.cdap.internal.profile.ProfileService in project cdap by caskdata.
the class NativeProfileCreatorTest method setupClass.
@BeforeClass
public static void setupClass() {
Injector injector = AppFabricTestHelper.getInjector();
nativeProfileCreator = injector.getInstance(NativeProfileCreator.class);
profileService = injector.getInstance(ProfileService.class);
}
use of io.cdap.cdap.internal.profile.ProfileService in project cdap by caskdata.
the class SystemProfileCreatorTest method setupClass.
@BeforeClass
public static void setupClass() {
Injector injector = AppFabricTestHelper.getInjector();
profileCreator = injector.getInstance(SystemProfileCreator.class);
profileService = injector.getInstance(ProfileService.class);
}
use of io.cdap.cdap.internal.profile.ProfileService in project cdap by caskdata.
the class PreferencesServiceTest method testProfileAssignment.
@Test
public void testProfileAssignment() throws Exception {
PreferencesService preferencesService = getInjector().getInstance(PreferencesService.class);
ProfileService profileService = getInjector().getInstance(ProfileService.class);
ProfileId myProfile = NamespaceId.DEFAULT.profile("myProfile");
profileService.saveProfile(myProfile, Profile.NATIVE);
// add properties with profile information
Map<String, String> prop = new HashMap<>();
prop.put(SystemArguments.PROFILE_NAME, ProfileId.NATIVE.getScopedName());
ApplicationId myApp = NamespaceId.DEFAULT.app("myApp");
ProgramId myProgram = myApp.workflow("myProgram");
preferencesService.setProperties(prop);
preferencesService.setProperties(NamespaceId.DEFAULT, prop);
preferencesService.setProperties(myApp, prop);
preferencesService.setProperties(myProgram, prop);
// the assignment should be there for these entities
Set<EntityId> expected = new HashSet<>();
expected.add(new InstanceId(""));
expected.add(NamespaceId.DEFAULT);
expected.add(myApp);
expected.add(myProgram);
Assert.assertEquals(expected, profileService.getProfileAssignments(ProfileId.NATIVE));
// setting an empty property is actually deleting the assignment
prop.clear();
preferencesService.setProperties(myApp, prop);
expected.remove(myApp);
Assert.assertEquals(expected, profileService.getProfileAssignments(ProfileId.NATIVE));
// set my program to use a different profile, should update both profiles
prop.put(SystemArguments.PROFILE_NAME, myProfile.getScopedName());
preferencesService.setProperties(myProgram, prop);
expected.remove(myProgram);
Assert.assertEquals(expected, profileService.getProfileAssignments(ProfileId.NATIVE));
Assert.assertEquals(Collections.singleton(myProgram), profileService.getProfileAssignments(myProfile));
// delete all preferences
preferencesService.deleteProperties();
preferencesService.deleteProperties(NamespaceId.DEFAULT);
preferencesService.deleteProperties(myApp);
preferencesService.deleteProperties(myProgram);
Assert.assertEquals(Collections.emptySet(), profileService.getProfileAssignments(ProfileId.NATIVE));
Assert.assertEquals(Collections.emptySet(), profileService.getProfileAssignments(myProfile));
profileService.disableProfile(myProfile);
profileService.deleteProfile(myProfile);
}
Aggregations