Search in sources :

Example 1 with Profile

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

the class ProfileHttpHandlerTest method testPutAndGetProfileWithTotalCPUSImplementedProvisioner.

@Test
public void testPutAndGetProfileWithTotalCPUSImplementedProvisioner() throws Exception {
    // put a profile with the mock provisioner with total cpus method implemented
    Profile expected = new Profile("MyProfile", "label", "my profile for testing", new ProvisionerInfo(MockProvisionerWithCpus.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();
    expected.getProvisioner().setTotalProcessingCpusLabel(MockProvisionerWithCpus.TEST_LABEL);
    Assert.assertEquals(expected, actual);
    disableProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
    deleteProfile(expectedProfileId, 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 2 with Profile

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

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

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

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

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

the class ProfileHttpHandlerTest method testSystemProfiles.

@Test
public void testSystemProfiles() throws Exception {
    Assert.assertEquals(Collections.singletonList(Profile.NATIVE), listSystemProfiles(HttpURLConnection.HTTP_OK));
    Profile p1 = new Profile("p1", "label", "desc", EntityScope.SYSTEM, new ProvisionerInfo(MockProvisioner.NAME, PROPERTY_SUMMARIES));
    putSystemProfile(p1.getName(), p1, HttpURLConnection.HTTP_OK);
    Optional<Profile> p1Optional = getSystemProfile(p1.getName(), HttpURLConnection.HTTP_OK);
    Assert.assertTrue(p1Optional.isPresent());
    Assert.assertEquals(p1, p1Optional.get());
    // check list contains both native and p1
    Set<Profile> expected = new HashSet<>();
    expected.add(Profile.NATIVE);
    expected.add(p1);
    Set<Profile> actual = new HashSet<>(listSystemProfiles(HttpURLConnection.HTTP_OK));
    Assert.assertEquals(expected, actual);
    // check that they're both visible to namespaces
    Assert.assertEquals(expected, new HashSet<>(listProfiles(NamespaceId.DEFAULT, true, HttpURLConnection.HTTP_OK)));
    // check we can add a profile with the same name in a namespace
    Profile p2 = new Profile(p1.getName(), p1.getLabel(), p1.getDescription(), EntityScope.USER, p1.getProvisioner());
    ProfileId p2Id = NamespaceId.DEFAULT.profile(p2.getName());
    putProfile(p2Id, p2, HttpURLConnection.HTTP_OK);
    // check that all are visible to the namespace
    expected.add(p2);
    Assert.assertEquals(expected, new HashSet<>(listProfiles(NamespaceId.DEFAULT, true, HttpURLConnection.HTTP_OK)));
    // check that namespaced profile is not visible in system list
    expected.remove(p2);
    Assert.assertEquals(expected, new HashSet<>(listSystemProfiles(HttpURLConnection.HTTP_OK)));
    disableProfile(p2Id, HttpURLConnection.HTTP_OK);
    deleteProfile(p2Id, HttpURLConnection.HTTP_OK);
    disableSystemProfile(p1.getName(), HttpURLConnection.HTTP_OK);
    deleteSystemProfile(p1.getName(), HttpURLConnection.HTTP_OK);
    doAs(READ_WRITE_USER_NAME, () -> {
        listSystemProfiles(HttpURLConnection.HTTP_OK);
        listProfiles(NamespaceId.DEFAULT, true, HttpURLConnection.HTTP_OK);
        putSystemProfile(p1.getName(), p1, HttpURLConnection.HTTP_OK);
        getSystemProfile(Profile.NATIVE.getName(), HttpURLConnection.HTTP_OK);
        disableSystemProfile(p1.getName(), HttpURLConnection.HTTP_OK);
        enableSystemProfile(p1.getName(), HttpURLConnection.HTTP_OK);
        disableSystemProfile(p1.getName(), HttpURLConnection.HTTP_OK);
        deleteSystemProfile(p1.getName(), HttpURLConnection.HTTP_OK);
    });
    doAs(READ_ONLY_SYSTEM_USER_NAME, () -> {
        listSystemProfiles(HttpURLConnection.HTTP_OK);
        listProfiles(NamespaceId.DEFAULT, true, HttpURLConnection.HTTP_OK);
        putSystemProfile(p1.getName(), p1, HttpURLConnection.HTTP_FORBIDDEN);
        getSystemProfile(Profile.NATIVE.getName(), HttpURLConnection.HTTP_OK);
        disableSystemProfile(p1.getName(), HttpURLConnection.HTTP_FORBIDDEN);
        enableSystemProfile(p1.getName(), HttpURLConnection.HTTP_FORBIDDEN);
        deleteSystemProfile(p1.getName(), HttpURLConnection.HTTP_FORBIDDEN);
    });
    doAs(READ_ONLY_USER_NAME, () -> {
        listSystemProfiles(HttpURLConnection.HTTP_FORBIDDEN);
        listProfiles(NamespaceId.DEFAULT, true, HttpURLConnection.HTTP_FORBIDDEN);
        listProfiles(NamespaceId.DEFAULT, false, HttpURLConnection.HTTP_OK);
        getSystemProfile(Profile.NATIVE.getName(), HttpURLConnection.HTTP_FORBIDDEN);
        putSystemProfile(p1.getName(), p1, HttpURLConnection.HTTP_FORBIDDEN);
        disableSystemProfile(p1.getName(), HttpURLConnection.HTTP_FORBIDDEN);
        enableSystemProfile(p1.getName(), HttpURLConnection.HTTP_FORBIDDEN);
        deleteSystemProfile(p1.getName(), HttpURLConnection.HTTP_FORBIDDEN);
    });
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) Profile(io.cdap.cdap.proto.profile.Profile) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with Profile

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

the class ProfileHttpHandlerTest method testListAndGetProfiles.

@Test
public void testListAndGetProfiles() throws Exception {
    // no profile should be there in default namespace
    List<Profile> profiles = listProfiles(NamespaceId.DEFAULT, false, HttpURLConnection.HTTP_OK);
    Assert.assertEquals(Collections.emptyList(), profiles);
    // try to list all profiles including system namespace before putting a new one, there should only exist a default
    // profile
    profiles = listProfiles(NamespaceId.DEFAULT, true, HttpURLConnection.HTTP_OK);
    Assert.assertEquals(Collections.singletonList(Profile.NATIVE), profiles);
    // test get single profile endpoint
    ProfileId profileId = NamespaceId.DEFAULT.profile("p1");
    Profile expected = new Profile("p1", "label", "my profile for testing", new ProvisionerInfo(MockProvisioner.NAME, PROPERTY_SUMMARIES));
    putProfile(profileId, expected, HttpURLConnection.HTTP_OK);
    Profile actual = getProfile(profileId, HttpURLConnection.HTTP_OK).get();
    Assert.assertEquals(expected, actual);
    // get a nonexisting profile should get a not found code
    getProfile(NamespaceId.DEFAULT.profile("nonExisting"), HttpURLConnection.HTTP_NOT_FOUND);
    doAs(READ_ONLY_USER_NAME, () -> {
        listProfiles(NamespaceId.DEFAULT, false, HttpURLConnection.HTTP_OK);
        getProfile(profileId, HttpURLConnection.HTTP_OK);
    });
    doAs(NO_ACCESS_USER_NAME, () -> {
        listProfiles(NamespaceId.DEFAULT, false, HttpURLConnection.HTTP_FORBIDDEN);
        getProfile(profileId, HttpURLConnection.HTTP_FORBIDDEN);
    });
}
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)43 ProfileId (io.cdap.cdap.proto.id.ProfileId)25 Test (org.junit.Test)24 ProvisionerInfo (io.cdap.cdap.proto.provisioner.ProvisionerInfo)16 NotFoundException (io.cdap.cdap.common.NotFoundException)8 ProfileConflictException (io.cdap.cdap.common.ProfileConflictException)7 ProgramId (io.cdap.cdap.proto.id.ProgramId)7 Field (io.cdap.cdap.spi.data.table.field.Field)7 ArrayList (java.util.ArrayList)7 ProvisionerPropertyValue (io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue)5 TableNotFoundException (io.cdap.cdap.spi.data.TableNotFoundException)5 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)4 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)4 HashMap (java.util.HashMap)4 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)3 Store (io.cdap.cdap.app.store.Store)3 DefaultStore (io.cdap.cdap.internal.app.store.DefaultStore)3 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)3 HashSet (java.util.HashSet)3 Injector (com.google.inject.Injector)2