Search in sources :

Example 66 with Profile

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);
}
Also used : MethodNotAllowedException(io.cdap.cdap.common.MethodNotAllowedException) AppMetadataStore(io.cdap.cdap.internal.app.store.AppMetadataStore) ProfileStore(io.cdap.cdap.internal.app.store.profile.ProfileStore) Profile(io.cdap.cdap.proto.profile.Profile)

Example 67 with Profile

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);
}
Also used : Profile(io.cdap.cdap.proto.profile.Profile)

Example 68 with 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);
    }
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) HashMap(java.util.HashMap) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) ProgramType(io.cdap.cdap.proto.ProgramType) ProgramId(io.cdap.cdap.proto.id.ProgramId) Profile(io.cdap.cdap.proto.profile.Profile) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) Test(org.junit.Test)

Example 69 with Profile

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));
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProvisionerPropertyValue(io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) ArrayList(java.util.ArrayList) BootstrapStepResult(io.cdap.cdap.proto.bootstrap.BootstrapStepResult) Profile(io.cdap.cdap.proto.profile.Profile) Test(org.junit.Test)

Example 70 with Profile

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));
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProvisionerPropertyValue(io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) ArrayList(java.util.ArrayList) NotFoundException(io.cdap.cdap.common.NotFoundException) BootstrapStepResult(io.cdap.cdap.proto.bootstrap.BootstrapStepResult) Profile(io.cdap.cdap.proto.profile.Profile) Test(org.junit.Test)

Aggregations

Profile (io.cdap.cdap.proto.profile.Profile)86 ProfileId (io.cdap.cdap.proto.id.ProfileId)50 Test (org.junit.Test)48 ProvisionerInfo (io.cdap.cdap.proto.provisioner.ProvisionerInfo)32 NotFoundException (io.cdap.cdap.common.NotFoundException)16 ProfileConflictException (io.cdap.cdap.common.ProfileConflictException)14 ProgramId (io.cdap.cdap.proto.id.ProgramId)14 Field (io.cdap.cdap.spi.data.table.field.Field)14 ArrayList (java.util.ArrayList)14 ProvisionerPropertyValue (io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue)10 TableNotFoundException (io.cdap.cdap.spi.data.TableNotFoundException)10 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)8 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)8 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)6 Store (io.cdap.cdap.app.store.Store)6 DefaultStore (io.cdap.cdap.internal.app.store.DefaultStore)6 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)6 Injector (com.google.inject.Injector)4