use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProfileServiceTest method testProfileCreationDisabled.
@Test(expected = MethodNotAllowedException.class)
public void testProfileCreationDisabled() throws Exception {
CConfiguration cConfWithProfileCreationDisabled = CConfiguration.copy(cConf);
cConfWithProfileCreationDisabled.setBoolean(Constants.Profile.UPDATE_ALLOWED, false);
ProfileService service = new ProfileService(cConfWithProfileCreationDisabled, getInjector().getInstance(MetricsSystemClient.class), getInjector().getInstance(TransactionRunner.class));
ProfileId profileId = NamespaceId.DEFAULT.profile("MyProfile");
Profile profile = new Profile("MyProfile", "label", "my profile for testing", new ProvisionerInfo("defaultProvisioner", PROPERTY_SUMMARIES));
// Add a profile
service.saveProfile(profileId, profile);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProfileServiceTest method testProfileCreationTime.
@Test
public void testProfileCreationTime() throws Exception {
ProfileId myProfile = NamespaceId.DEFAULT.profile("MyProfile");
long creationTime = TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
Profile profile = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), ProfileStatus.ENABLED, Profile.NATIVE.getProvisioner(), creationTime);
profileService.saveProfile(myProfile, profile);
Assert.assertEquals(creationTime, profileService.getProfile(myProfile).getCreatedTsSeconds());
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProfileServiceTest method testProfileOverrides.
@Test
public void testProfileOverrides() throws Exception {
List<ProvisionerPropertyValue> provisionerProperties = new ArrayList<>();
provisionerProperties.add(new ProvisionerPropertyValue("editable1", "val", true));
provisionerProperties.add(new ProvisionerPropertyValue("editable2", "val", true));
provisionerProperties.add(new ProvisionerPropertyValue("final", "finalval", false));
ProvisionerInfo provisionerInfo = new ProvisionerInfo("provisioner", provisionerProperties);
Profile profile = new Profile("name", "label", "desc", provisionerInfo);
ProfileId profileId = NamespaceId.DEFAULT.profile("p");
profileService.saveProfile(profileId, profile);
try {
Map<String, String> args = new HashMap<>();
args.put("editable1", "newval");
args.put("final", "shouldnotwork");
args.put("newarg", "val");
// resolved properties should include all the stored properties,
// with 'final' not overridden and 'editable1' overridden.
List<ProvisionerPropertyValue> expectedProperties = new ArrayList<>();
expectedProperties.add(new ProvisionerPropertyValue("editable1", "newval", true));
expectedProperties.add(new ProvisionerPropertyValue("editable2", "val", true));
expectedProperties.add(new ProvisionerPropertyValue("final", "finalval", false));
expectedProperties.add(new ProvisionerPropertyValue("newarg", "val", true));
provisionerInfo = new ProvisionerInfo(provisionerInfo.getName(), expectedProperties);
Profile expected = new Profile(profile.getName(), "label", profile.getDescription(), provisionerInfo);
Profile actual = profileService.getProfile(profileId, args);
Assert.assertEquals(expected, actual);
} finally {
profileService.disableProfile(profileId);
profileService.deleteProfile(profileId);
}
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProgramLifecycleServiceTest method testProfileProgramTypeRestrictions.
@Test
public void testProfileProgramTypeRestrictions() throws Exception {
deploy(AllProgramsApp.class, 200);
ProfileId profileId = NamespaceId.DEFAULT.profile("profABC");
ProvisionerInfo provisionerInfo = new ProvisionerInfo(MockProvisioner.NAME, Collections.emptyList());
Profile profile = new Profile("profABC", "label", "desc", provisionerInfo);
profileService.createIfNotExists(profileId, profile);
try {
Map<String, String> userArgs = new HashMap<>();
userArgs.put(SystemArguments.PROFILE_NAME, profileId.getProfile());
Map<String, String> systemArgs = new HashMap<>();
Set<ProgramId> programIds = ImmutableSet.of(NamespaceId.DEFAULT.app(AllProgramsApp.NAME).program(ProgramType.SPARK, AllProgramsApp.NoOpSpark.NAME), NamespaceId.DEFAULT.app(AllProgramsApp.NAME).program(ProgramType.MAPREDUCE, AllProgramsApp.NoOpMR.NAME), NamespaceId.DEFAULT.app(AllProgramsApp.NAME).program(ProgramType.SERVICE, AllProgramsApp.NoOpService.NAME), NamespaceId.DEFAULT.app(AllProgramsApp.NAME).program(ProgramType.WORKER, AllProgramsApp.NoOpWorker.NAME));
Set<ProgramType> allowCustomProfiles = EnumSet.of(ProgramType.MAPREDUCE, ProgramType.SPARK, ProgramType.WORKFLOW, ProgramType.WORKER);
for (ProgramId programId : programIds) {
ProgramOptions options = programLifecycleService.createProgramOptions(programId, userArgs, systemArgs, false);
Optional<ProfileId> opt = SystemArguments.getProfileIdFromArgs(NamespaceId.DEFAULT, options.getArguments().asMap());
Assert.assertTrue(opt.isPresent());
if (allowCustomProfiles.contains(programId.getType())) {
Assert.assertEquals(profileId, opt.get());
} else {
Assert.assertEquals(ProfileId.NATIVE, opt.get());
}
}
} finally {
profileService.disableProfile(profileId);
profileService.deleteProfile(profileId);
}
}
use of io.cdap.cdap.proto.profile.Profile 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);
}
}
Aggregations