Search in sources :

Example 71 with Profile

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);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) MetricsSystemClient(io.cdap.cdap.api.metrics.MetricsSystemClient) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Profile(io.cdap.cdap.proto.profile.Profile) Test(org.junit.Test)

Example 72 with 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());
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) Profile(io.cdap.cdap.proto.profile.Profile) Test(org.junit.Test)

Example 73 with Profile

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

Example 74 with Profile

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);
    }
}
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 75 with Profile

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

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