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