Search in sources :

Example 6 with ProvisionerInfo

use of io.cdap.cdap.proto.provisioner.ProvisionerInfo in project cdap by caskdata.

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 7 with ProvisionerInfo

use of io.cdap.cdap.proto.provisioner.ProvisionerInfo in project cdap by caskdata.

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)

Example 8 with ProvisionerInfo

use of io.cdap.cdap.proto.provisioner.ProvisionerInfo in project cdap by caskdata.

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)

Example 9 with ProvisionerInfo

use of io.cdap.cdap.proto.provisioner.ProvisionerInfo in project cdap by caskdata.

the class ProfileService method getProfile.

/**
 * Get the profile information about the given profile with property overrides. If a non-editable property is
 * in the overrides, it will be ignored, but a message will be logged.
 *
 * @param profileId the id of the profile to look up
 * @param overrides overrides to the profile properties
 * @return the profile information about the given profile
 * @throws NotFoundException if the profile is not found
 */
public Profile getProfile(ProfileId profileId, Map<String, String> overrides) throws NotFoundException {
    Profile storedProfile = getProfile(profileId);
    List<ProvisionerPropertyValue> properties = new ArrayList<>();
    Set<String> remainingOverrides = new HashSet<>(overrides.keySet());
    // add all  properties from the stored profile
    for (ProvisionerPropertyValue storedProperty : storedProfile.getProvisioner().getProperties()) {
        String propertyName = storedProperty.getName();
        String storedVal = storedProperty.getValue();
        if (!storedProperty.isEditable()) {
            if (overrides.containsKey(propertyName)) {
                LOG.info("Profile property {} cannot be edited. The original value will be used.", propertyName);
            }
            properties.add(storedProperty);
        } else {
            String val = overrides.getOrDefault(propertyName, storedVal);
            properties.add(new ProvisionerPropertyValue(propertyName, val, true));
        }
        remainingOverrides.remove(propertyName);
    }
    // add all remaining overrides
    for (String propertyName : remainingOverrides) {
        properties.add(new ProvisionerPropertyValue(propertyName, overrides.get(propertyName), true));
    }
    ProvisionerInfo provisionerInfo = new ProvisionerInfo(storedProfile.getProvisioner().getName(), properties);
    return new Profile(storedProfile.getName(), storedProfile.getLabel(), storedProfile.getDescription(), storedProfile.getScope(), storedProfile.getStatus(), provisionerInfo, storedProfile.getCreatedTsSeconds());
}
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) HashSet(java.util.HashSet)

Example 10 with ProvisionerInfo

use of io.cdap.cdap.proto.provisioner.ProvisionerInfo in project cdap by caskdata.

the class SystemProfileCreatorTest method testMissingProfileName.

@Test
public void testMissingProfileName() throws Exception {
    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);
    SystemProfileCreator.Arguments arguments = new SystemProfileCreator.Arguments("", "label", "desc", provisionerInfo);
    BootstrapStepResult result = profileCreator.execute("label", GSON.toJsonTree(arguments).getAsJsonObject());
    Assert.assertEquals(BootstrapStepResult.Status.FAILED, result.getStatus());
}
Also used : 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) Test(org.junit.Test)

Aggregations

ProvisionerInfo (io.cdap.cdap.proto.provisioner.ProvisionerInfo)44 Test (org.junit.Test)40 Profile (io.cdap.cdap.proto.profile.Profile)32 ProfileId (io.cdap.cdap.proto.id.ProfileId)26 ProvisionerPropertyValue (io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue)12 ArrayList (java.util.ArrayList)12 NotFoundException (io.cdap.cdap.common.NotFoundException)6 BootstrapStepResult (io.cdap.cdap.proto.bootstrap.BootstrapStepResult)6 MetricsSystemClient (io.cdap.cdap.api.metrics.MetricsSystemClient)4 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)4 TransactionRunner (io.cdap.cdap.spi.data.transaction.TransactionRunner)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 ProgramOptions (io.cdap.cdap.app.runtime.ProgramOptions)2 BadRequestException (io.cdap.cdap.common.BadRequestException)2 ProfileConflictException (io.cdap.cdap.common.ProfileConflictException)2 MockProvisioner (io.cdap.cdap.internal.provision.MockProvisioner)2 ProgramType (io.cdap.cdap.proto.ProgramType)2 ProgramId (io.cdap.cdap.proto.id.ProgramId)2 ProvisionerDetail (io.cdap.cdap.proto.provisioner.ProvisionerDetail)2