Search in sources :

Example 96 with ProfileId

use of io.cdap.cdap.proto.id.ProfileId in project cdap by cdapio.

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 97 with ProfileId

use of io.cdap.cdap.proto.id.ProfileId in project cdap by cdapio.

the class SystemArgumentsTest method testGetProgramProfile.

@Test
public void testGetProgramProfile() {
    ProfileId profileId = NamespaceId.DEFAULT.profile("p");
    Map<String, String> args = Collections.singletonMap(SystemArguments.PROFILE_NAME, profileId.getScopedName());
    ApplicationId appId = NamespaceId.DEFAULT.app("a");
    ProgramId mrId = appId.mr("mr");
    ProgramId serviceId = appId.service("serv");
    ProgramId sparkId = appId.spark("spark");
    ProgramId workerId = appId.worker("worker");
    ProgramId workflowID = appId.workflow("wf");
    Assert.assertEquals(profileId, SystemArguments.getProfileIdForProgram(mrId, args));
    Assert.assertEquals(ProfileId.NATIVE, SystemArguments.getProfileIdForProgram(serviceId, args));
    Assert.assertEquals(profileId, SystemArguments.getProfileIdForProgram(sparkId, args));
    Assert.assertEquals(profileId, SystemArguments.getProfileIdForProgram(workerId, args));
    Assert.assertEquals(profileId, SystemArguments.getProfileIdForProgram(workflowID, args));
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Test(org.junit.Test)

Example 98 with ProfileId

use of io.cdap.cdap.proto.id.ProfileId in project cdap by cdapio.

the class SystemArgumentsTest method testGetProfileId.

@Test
public void testGetProfileId() {
    // should get null profile id if the args is empty
    Assert.assertFalse(SystemArguments.getProfileIdFromArgs(NamespaceId.DEFAULT, Collections.emptyMap()).isPresent());
    Map<String, String> args = new HashMap<>();
    args.put("system.log.level", "DEBUG");
    args.put("system.log.leveldummyKey", "ERROR");
    // Having other unrelated args should also get null profile id
    Assert.assertFalse(SystemArguments.getProfileIdFromArgs(NamespaceId.DEFAULT, args).isPresent());
    // without scope the profile will be considered in user scope
    ProfileId expected = NamespaceId.DEFAULT.profile("MyProfile");
    args.put("system.profile.name", expected.getProfile());
    Assert.assertEquals(expected, SystemArguments.getProfileIdFromArgs(NamespaceId.DEFAULT, args).get());
    // put a profile with scope SYSTEM, the profile we get should be in system namespace
    expected = NamespaceId.SYSTEM.profile("MyProfile");
    args.put("system.profile.name", expected.getScopedName());
    Assert.assertEquals(expected, SystemArguments.getProfileIdFromArgs(NamespaceId.DEFAULT, args).get());
    // put a profile with scope USER, the profile we get should be in the user namespace
    expected = NamespaceId.DEFAULT.profile("MyProfile");
    args.put("system.profile.name", expected.getScopedName());
    Assert.assertEquals(expected, SystemArguments.getProfileIdFromArgs(NamespaceId.DEFAULT, args).get());
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 99 with ProfileId

use of io.cdap.cdap.proto.id.ProfileId in project cdap by cdapio.

the class ProfileHttpHandler method writeSystemProfile.

@PUT
@Path("/profiles/{profile-name}")
public void writeSystemProfile(FullHttpRequest request, HttpResponder responder, @PathParam("profile-name") String profileName) throws Exception {
    ProfileId profileId = getValidatedProfile(NamespaceId.SYSTEM, profileName);
    checkPutProfilePermissions(profileId);
    writeProfile(profileId, request);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 100 with ProfileId

use of io.cdap.cdap.proto.id.ProfileId in project cdap by cdapio.

the class ProfileHttpHandler method deleteSystemProfile.

@DELETE
@Path("/profiles/{profile-name}")
public void deleteSystemProfile(HttpRequest request, HttpResponder responder, @PathParam("profile-name") String profileName) throws Exception {
    ProfileId profileId = getValidatedProfile(NamespaceId.SYSTEM, profileName);
    accessEnforcer.enforce(profileId, authenticationContext.getPrincipal(), StandardPermission.DELETE);
    profileService.deleteProfile(getValidatedProfile(NamespaceId.SYSTEM, profileName));
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

ProfileId (io.cdap.cdap.proto.id.ProfileId)112 Test (org.junit.Test)68 Profile (io.cdap.cdap.proto.profile.Profile)50 ProgramId (io.cdap.cdap.proto.id.ProgramId)26 ProvisionerInfo (io.cdap.cdap.proto.provisioner.ProvisionerInfo)26 Path (javax.ws.rs.Path)22 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)16 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)14 HashMap (java.util.HashMap)14 ProfileConflictException (io.cdap.cdap.common.ProfileConflictException)12 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)12 MetricStore (io.cdap.cdap.api.metrics.MetricStore)10 NotFoundException (io.cdap.cdap.common.NotFoundException)10 ProgramSchedule (io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule)10 ProfileService (io.cdap.cdap.internal.profile.ProfileService)10 ArrayList (java.util.ArrayList)10 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)8 ScheduleId (io.cdap.cdap.proto.id.ScheduleId)8 POST (javax.ws.rs.POST)8 Store (io.cdap.cdap.app.store.Store)6