Search in sources :

Example 56 with Profile

use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.

the class ProfileHttpHandlerTest method testEnableDisableProfile.

@Test
public void testEnableDisableProfile() throws Exception {
    Profile expected = new Profile("MyProfile", "label", "my profile for testing", new ProvisionerInfo(MockProvisioner.NAME, PROPERTY_SUMMARIES));
    ProfileId profileId = NamespaceId.DEFAULT.profile(expected.getName());
    // enable and disable a non-existing profile should give a 404
    enableProfile(profileId, HttpURLConnection.HTTP_NOT_FOUND);
    disableProfile(profileId, HttpURLConnection.HTTP_NOT_FOUND);
    // put the profile
    putProfile(profileId, expected, HttpURLConnection.HTTP_OK);
    // by default the status should be enabled
    Assert.assertEquals(ProfileStatus.ENABLED, getProfileStatus(profileId, HttpURLConnection.HTTP_OK).get());
    // enable it again should give a 409
    enableProfile(profileId, HttpURLConnection.HTTP_CONFLICT);
    // disable should work
    disableProfile(profileId, HttpURLConnection.HTTP_OK);
    Assert.assertEquals(ProfileStatus.DISABLED, getProfileStatus(profileId, HttpURLConnection.HTTP_OK).get());
    // disable again should give a 409
    disableProfile(profileId, HttpURLConnection.HTTP_CONFLICT);
    // enable should work
    enableProfile(profileId, HttpURLConnection.HTTP_OK);
    Assert.assertEquals(ProfileStatus.ENABLED, getProfileStatus(profileId, HttpURLConnection.HTTP_OK).get());
    // now delete should not work since we have the profile enabled
    deleteProfile(profileId, HttpURLConnection.HTTP_CONFLICT);
    // disable and delete
    disableProfile(profileId, HttpURLConnection.HTTP_OK);
    deleteProfile(profileId, HttpURLConnection.HTTP_OK);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) Profile(io.cdap.cdap.proto.profile.Profile) Test(org.junit.Test)

Example 57 with Profile

use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.

the class AppFabricTestBase method getSystemProfile.

protected Optional<Profile> getSystemProfile(String profileName, int expectedCode) throws Exception {
    HttpResponse response = doGet(String.format("/v3/profiles/%s", profileName));
    assertResponseCode(expectedCode, response);
    if (expectedCode == HttpResponseStatus.OK.code()) {
        return Optional.of(GSON.fromJson(response.getResponseBodyAsString(), Profile.class));
    }
    return Optional.empty();
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) Profile(io.cdap.cdap.proto.profile.Profile)

Example 58 with Profile

use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.

the class CoreSchedulerServiceTest method testAddScheduleWithDisabledProfile.

@Test
public void testAddScheduleWithDisabledProfile() throws Exception {
    // put my profile and by default it is enabled
    ProfileId profileId = NS_ID.profile("MyProfile");
    Profile profile = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), Profile.NATIVE.getProvisioner());
    putProfile(profileId, profile, 200);
    // add a schedule, it should succeed since the profile is enabled.
    ProgramSchedule tsched1 = new ProgramSchedule("tsched1", "one time schedule", PROG1_ID, ImmutableMap.of("prop1", "nn", SystemArguments.PROFILE_NAME, "USER:MyProfile"), new TimeTrigger("* * ? * 1"), ImmutableList.<Constraint>of());
    scheduler.addSchedule(tsched1);
    Assert.assertEquals(Collections.singletonList(tsched1), scheduler.listSchedules(PROG1_ID));
    // now disable the profile
    disableProfile(profileId, 200);
    // delete it
    scheduler.deleteSchedule(TSCHED1_ID);
    Assert.assertEquals(Collections.emptyList(), scheduler.listSchedules(PROG1_ID));
    // add it again should also fail since the profile is disabled
    try {
        scheduler.addSchedule(tsched1);
        Assert.fail();
    } catch (ProfileConflictException e) {
    // expected
    }
    // clean up
    deleteProfile(profileId, 200);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) TimeTrigger(io.cdap.cdap.internal.app.runtime.schedule.trigger.TimeTrigger) ProgramSchedule(io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule) ProfileConflictException(io.cdap.cdap.common.ProfileConflictException) Profile(io.cdap.cdap.proto.profile.Profile) Test(org.junit.Test)

Example 59 with Profile

use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.

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)

Example 60 with Profile

use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.

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)

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