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);
}
}
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));
}
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());
}
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);
}
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);
}
Aggregations