Search in sources :

Example 6 with ProfileService

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();
}
Also used : NoOpMetricsSystemClient(io.cdap.cdap.common.metrics.NoOpMetricsSystemClient) InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) StorageModule(io.cdap.cdap.data.runtime.StorageModule) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) NettyHttpService(io.cdap.http.NettyHttpService) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) MessagingService(io.cdap.cdap.messaging.MessagingService) ProfileService(io.cdap.cdap.internal.profile.ProfileService) Service(com.google.common.util.concurrent.Service) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) MessagingServerRuntimeModule(io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) AuthorizationTestModule(io.cdap.cdap.security.authorization.AuthorizationTestModule) MessagingService(io.cdap.cdap.messaging.MessagingService) TransactionModules(org.apache.tephra.runtime.TransactionModules) TransactionExecutorModule(io.cdap.cdap.data.runtime.TransactionExecutorModule) ProfileService(io.cdap.cdap.internal.profile.ProfileService) LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) TransactionManager(org.apache.tephra.TransactionManager) SystemDatasetRuntimeModule(io.cdap.cdap.data.runtime.SystemDatasetRuntimeModule) MetricsSystemClient(io.cdap.cdap.api.metrics.MetricsSystemClient) NoOpMetricsSystemClient(io.cdap.cdap.common.metrics.NoOpMetricsSystemClient) AuthorizationEnforcementModule(io.cdap.cdap.security.authorization.AuthorizationEnforcementModule) PrivateModule(com.google.inject.PrivateModule) BeforeClass(org.junit.BeforeClass)

Example 7 with ProfileService

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);
    }
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) DefaultStore(io.cdap.cdap.internal.app.store.DefaultStore) Store(io.cdap.cdap.app.store.Store) ProgramId(io.cdap.cdap.proto.id.ProgramId) Profile(io.cdap.cdap.proto.profile.Profile) AppWithWorkflow(io.cdap.cdap.AppWithWorkflow) PreferencesService(io.cdap.cdap.config.PreferencesService) Read(io.cdap.cdap.spi.metadata.Read) MetadataMutation(io.cdap.cdap.spi.metadata.MetadataMutation) ProfileService(io.cdap.cdap.internal.profile.ProfileService) Injector(com.google.inject.Injector) MetadataStorage(io.cdap.cdap.spi.metadata.MetadataStorage) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 8 with ProfileService

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);
}
Also used : ProfileService(io.cdap.cdap.internal.profile.ProfileService) Injector(com.google.inject.Injector) BeforeClass(org.junit.BeforeClass)

Example 9 with ProfileService

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);
}
Also used : ProfileService(io.cdap.cdap.internal.profile.ProfileService) Injector(com.google.inject.Injector) BeforeClass(org.junit.BeforeClass)

Example 10 with ProfileService

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);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) EntityId(io.cdap.cdap.proto.id.EntityId) ProfileService(io.cdap.cdap.internal.profile.ProfileService) HashMap(java.util.HashMap) InstanceId(io.cdap.cdap.proto.id.InstanceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ProfileService (io.cdap.cdap.internal.profile.ProfileService)22 BeforeClass (org.junit.BeforeClass)12 Injector (com.google.inject.Injector)10 ProfileId (io.cdap.cdap.proto.id.ProfileId)10 ProgramId (io.cdap.cdap.proto.id.ProgramId)10 Test (org.junit.Test)10 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)6 InMemoryDiscoveryModule (io.cdap.cdap.common.guice.InMemoryDiscoveryModule)6 LocalLocationModule (io.cdap.cdap.common.guice.LocalLocationModule)6 PreferencesService (io.cdap.cdap.config.PreferencesService)6 TransactionExecutorModule (io.cdap.cdap.data.runtime.TransactionExecutorModule)6 MessagingServerRuntimeModule (io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule)6 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)6 MetadataStorage (io.cdap.cdap.spi.metadata.MetadataStorage)6 AuthenticationContextModules (io.cdap.cdap.security.auth.context.AuthenticationContextModules)5 AuthorizationEnforcementModule (io.cdap.cdap.security.authorization.AuthorizationEnforcementModule)5 TransactionManager (org.apache.tephra.TransactionManager)5 Service (com.google.common.util.concurrent.Service)4 PrivateModule (com.google.inject.PrivateModule)4 AppWithWorkflow (io.cdap.cdap.AppWithWorkflow)4