Search in sources :

Example 81 with Profile

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

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 82 with Profile

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

the class ProfileHttpHandlerTest method testSystemNamespaceProfilesNotAllowed.

@Test
public void testSystemNamespaceProfilesNotAllowed() throws Exception {
    listProfiles(NamespaceId.SYSTEM, false, HttpURLConnection.HTTP_BAD_METHOD);
    getProfile(NamespaceId.SYSTEM.profile("abc"), HttpURLConnection.HTTP_BAD_METHOD);
    disableProfile(NamespaceId.SYSTEM.profile("abc"), HttpURLConnection.HTTP_BAD_METHOD);
    enableProfile(NamespaceId.SYSTEM.profile("abc"), HttpURLConnection.HTTP_BAD_METHOD);
    Profile profile = new Profile("abc", "label", "desc", new ProvisionerInfo("xyz", Collections.emptyList()));
    putProfile(NamespaceId.SYSTEM.profile("abc"), profile, HttpURLConnection.HTTP_BAD_METHOD);
}
Also used : ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) Profile(io.cdap.cdap.proto.profile.Profile) Test(org.junit.Test)

Example 83 with Profile

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

the class ProfileHttpHandlerTest method testPutAndDeleteProfiles.

@Test
public void testPutAndDeleteProfiles() throws Exception {
    Profile invalidProfile = new Profile("MyProfile", "label", "my profile for testing", new ProvisionerInfo("nonExisting", PROPERTY_SUMMARIES));
    // adding a profile with non-existing provisioner should get a 400
    putProfile(NamespaceId.DEFAULT.profile(invalidProfile.getName()), invalidProfile, HttpURLConnection.HTTP_BAD_REQUEST);
    // put a profile with the mock provisioner
    Profile expected = new Profile("MyProfile", "label", "my profile for testing", new ProvisionerInfo(MockProvisioner.NAME, PROPERTY_SUMMARIES));
    ProfileId expectedProfileId = NamespaceId.DEFAULT.profile(expected.getName());
    putProfile(expectedProfileId, expected, HttpURLConnection.HTTP_OK);
    // get the profile
    Profile actual = getProfile(expectedProfileId, HttpURLConnection.HTTP_OK).get();
    Assert.assertEquals(expected, actual);
    // list all profiles, should get 2 profiles
    List<Profile> profiles = listProfiles(NamespaceId.DEFAULT, true, HttpURLConnection.HTTP_OK);
    Set<Profile> expectedList = ImmutableSet.of(Profile.NATIVE, expected);
    Assert.assertEquals(expectedList.size(), profiles.size());
    Assert.assertEquals(expectedList, new HashSet<>(profiles));
    // adding the same profile should still succeed
    putProfile(expectedProfileId, expected, HttpURLConnection.HTTP_OK);
    // get non-existing profile should get a 404
    deleteProfile(NamespaceId.DEFAULT.profile("nonExisting"), HttpURLConnection.HTTP_NOT_FOUND);
    // delete the profile should fail first time since it is by default enabled
    deleteProfile(expectedProfileId, HttpURLConnection.HTTP_CONFLICT);
    // disable the profile then delete should work
    disableProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
    deleteProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
    Assert.assertEquals(Collections.emptyList(), listProfiles(NamespaceId.DEFAULT, false, HttpURLConnection.HTTP_OK));
    // if given some unrelated json, it should return a 400 instead of 500
    ProvisionerSpecification spec = new MockProvisioner().getSpec();
    ProvisionerDetail test = new ProvisionerDetail(spec.getName(), spec.getLabel(), spec.getDescription(), new ArrayList<>(), null, null, false);
    putProfile(NamespaceId.DEFAULT.profile(test.getName()), test, HttpURLConnection.HTTP_BAD_REQUEST);
    doAs(READ_ONLY_USER_NAME, () -> {
        putProfile(expectedProfileId, expected, HttpURLConnection.HTTP_FORBIDDEN);
        disableProfile(expectedProfileId, HttpURLConnection.HTTP_FORBIDDEN);
        enableProfile(expectedProfileId, HttpURLConnection.HTTP_FORBIDDEN);
        deleteProfile(expectedProfileId, HttpURLConnection.HTTP_FORBIDDEN);
    });
    doAs(READ_WRITE_USER_NAME, () -> {
        putProfile(expectedProfileId, expected, HttpURLConnection.HTTP_OK);
        disableProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
        enableProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
        disableProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
        deleteProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
    });
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProvisionerSpecification(io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) MockProvisioner(io.cdap.cdap.internal.provision.MockProvisioner) Profile(io.cdap.cdap.proto.profile.Profile) ProvisionerDetail(io.cdap.cdap.proto.provisioner.ProvisionerDetail) Test(org.junit.Test)

Example 84 with Profile

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

the class ProfileHttpHandlerTest method testNullProvisionerProperty.

@Test
public void testNullProvisionerProperty() throws Exception {
    // provide a profile with null provsioner property, it should still succeed
    List<ProvisionerPropertyValue> listWithNull = new ArrayList<>();
    listWithNull.add(null);
    Profile profile = new Profile("ProfileWithNull", "label", "should succeed", new ProvisionerInfo(MockProvisioner.NAME, listWithNull));
    putProfile(NamespaceId.DEFAULT.profile(profile.getName()), profile, HttpURLConnection.HTTP_OK);
    // Get the profile, it should not contain the null value, the property should be an empty list
    Profile actual = getProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK).get();
    Assert.assertNotNull(actual);
    Assert.assertEquals(Collections.EMPTY_SET, actual.getProvisioner().getProperties());
    disableProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK);
    deleteProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK);
    // provide a profile with mixed properties with null, it should still succeed
    List<ProvisionerPropertyValue> listMixed = new ArrayList<>(PROPERTY_SUMMARIES);
    listMixed.addAll(listWithNull);
    profile = new Profile("ProfileMixed", "label", "should succeed", new ProvisionerInfo(MockProvisioner.NAME, listMixed));
    putProfile(NamespaceId.DEFAULT.profile(profile.getName()), profile, HttpURLConnection.HTTP_OK);
    // Get the profile, it should not contain the null value, the property should be all non-null properties in the list
    actual = getProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK).get();
    Assert.assertNotNull(actual);
    Assert.assertEquals(PROPERTY_SUMMARIES, actual.getProvisioner().getProperties());
    disableProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK);
    deleteProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK);
}
Also used : ProvisionerPropertyValue(io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) ArrayList(java.util.ArrayList) Profile(io.cdap.cdap.proto.profile.Profile) Test(org.junit.Test)

Example 85 with Profile

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

the class ProfileHttpHandlerTest method testPutPermissionChecks.

@Test
public void testPutPermissionChecks() throws Exception {
    Profile profile = new Profile(PERMISSIONS_TEST_PROFILE, "label", "default permissions testing profile", new ProvisionerInfo(MockProvisioner.NAME, Collections.emptyList()));
    ProfileId profileId = NamespaceId.DEFAULT.profile(PERMISSIONS_TEST_PROFILE);
    // Verify the UPDATE user does not have permissions to create a profile
    doAs(UPDATE_PROFILE_USER.getName(), () -> {
        putProfile(profileId, profile, HttpURLConnection.HTTP_FORBIDDEN);
        putSystemProfile(profile.getName(), profile, HttpURLConnection.HTTP_FORBIDDEN);
    });
    // Verify that the CREATE user can create both profiles
    doAs(CREATE_PROFILE_USER.getName(), () -> {
        putProfile(profileId, profile, HttpURLConnection.HTTP_OK);
        putSystemProfile(profile.getName(), profile, HttpURLConnection.HTTP_OK);
    });
    // Verify that the UPDATE user can modify the profiles after they have been created
    doAs(UPDATE_PROFILE_USER.getName(), () -> {
        putProfile(profileId, profile, HttpURLConnection.HTTP_OK);
        putSystemProfile(profile.getName(), profile, HttpURLConnection.HTTP_OK);
        // Disable the profiles in preparation for deletion.
        disableProfile(profileId, HttpURLConnection.HTTP_OK);
        disableSystemProfile(profile.getName(), HttpURLConnection.HTTP_OK);
        // Verify deletion failure
        deleteProfile(profileId, HttpURLConnection.HTTP_FORBIDDEN);
        deleteSystemProfile(profile.getName(), HttpURLConnection.HTTP_FORBIDDEN);
    });
    // Verify that the CREATE user cannot update profiles after they have been created
    doAs(CREATE_PROFILE_USER.getName(), () -> {
        putProfile(profileId, profile, HttpURLConnection.HTTP_FORBIDDEN);
        putSystemProfile(profile.getName(), profile, HttpURLConnection.HTTP_FORBIDDEN);
    });
    // Delete profiles
    doAs(DELETE_PROFILE_USER.getName(), () -> {
        deleteProfile(profileId, HttpURLConnection.HTTP_OK);
        deleteSystemProfile(profile.getName(), 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)

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