use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
the class ProfileService method deleteProfile.
/**
* Deletes the profile from the profile store. Native profile cannot be deleted.
* Other profile deletion must satisfy the following:
* 1. Profile must exist and must be DISABLED
* 2. Profile must not be assigned to any entities. Profiles can be assigned to an entity by setting a preference
* or a schedule property.
* 3. There must be no active program runs using this profile
*
* @param profileId the id of the profile to delete
* @throws NotFoundException if the profile is not found
* @throws ProfileConflictException if the profile is enabled
* @throws MethodNotAllowedException if trying to delete the Native profile
*/
public void deleteProfile(ProfileId profileId) throws MethodNotAllowedException, NotFoundException, ProfileConflictException {
if (profileId.equals(ProfileId.NATIVE)) {
throw new MethodNotAllowedException(String.format("Profile Native %s cannot be deleted.", profileId.getScopedName()));
}
TransactionRunners.run(transactionRunner, context -> {
ProfileStore profileStore = ProfileStore.get(context);
Profile profile = profileStore.getProfile(profileId);
AppMetadataStore appMetadataStore = AppMetadataStore.create(context);
deleteProfile(profileStore, appMetadataStore, profileId, profile);
}, NotFoundException.class, ProfileConflictException.class);
deleteMetrics(profileId);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
the class SystemProfileCreator method execute.
@Override
public void execute(Arguments arguments) {
Profile profile = new Profile(arguments.name, arguments.getLabel(), arguments.getDescription(), EntityScope.SYSTEM, arguments.getProvisioner());
profileService.createIfNotExists(arguments.getId(), profile);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
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 SystemProfileCreatorTest method testExistingIsUnmodified.
@Test
public void testExistingIsUnmodified() throws Exception {
// write a profile
ProfileId profileId = NamespaceId.SYSTEM.profile("p1");
List<ProvisionerPropertyValue> properties = new ArrayList<>();
properties.add(new ProvisionerPropertyValue("name1", "val1", true));
properties.add(new ProvisionerPropertyValue("name2", "val2", true));
ProvisionerInfo provisionerInfo = new ProvisionerInfo(MockProvisioner.NAME, properties);
Profile profile = new Profile(profileId.getProfile(), "profile label", "profile description", EntityScope.SYSTEM, provisionerInfo);
profileService.saveProfile(profileId, profile);
// run the bootstrap step and make sure it succeeded
SystemProfileCreator.Arguments arguments = new SystemProfileCreator.Arguments(profile.getName(), "different label", "different desciption", profile.getProvisioner());
BootstrapStepResult result = profileCreator.execute("label", GSON.toJsonTree(arguments).getAsJsonObject());
BootstrapStepResult expected = new BootstrapStepResult("label", BootstrapStepResult.Status.SUCCEEDED);
Assert.assertEquals(expected, result);
// check that it didn't overwrite the existing profile
Assert.assertEquals(profile, profileService.getProfile(profileId));
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class SystemProfileCreatorTest method testCreation.
@Test
public void testCreation() throws Exception {
ProfileId profileId = NamespaceId.SYSTEM.profile("p1");
try {
profileService.getProfile(profileId);
Assert.fail("profile should not exist.");
} catch (NotFoundException e) {
// expected
}
List<ProvisionerPropertyValue> properties = new ArrayList<>();
properties.add(new ProvisionerPropertyValue("name1", "val1", true));
properties.add(new ProvisionerPropertyValue("name2", "val2", true));
ProvisionerInfo provisionerInfo = new ProvisionerInfo(MockProvisioner.NAME, properties);
Profile profile = new Profile(profileId.getProfile(), "profile label", "profile description", EntityScope.SYSTEM, provisionerInfo);
SystemProfileCreator.Arguments arguments = new SystemProfileCreator.Arguments(profile.getName(), profile.getLabel(), profile.getDescription(), profile.getProvisioner());
BootstrapStepResult result = profileCreator.execute("label", GSON.toJsonTree(arguments).getAsJsonObject());
BootstrapStepResult expected = new BootstrapStepResult("label", BootstrapStepResult.Status.SUCCEEDED);
Assert.assertEquals(expected, result);
Assert.assertEquals(profile, profileService.getProfile(profileId));
}
Aggregations