use of io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue 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.ProvisionerPropertyValue 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.ProvisionerPropertyValue in project cdap by caskdata.
the class SystemArguments method addProfileArgs.
/**
* Adds any profile related arguments to the map
*
* @param args arguments to add to
* @param profile the profile to add
*/
public static void addProfileArgs(Map<String, String> args, Profile profile) {
args.put(PROFILE_NAME, profile.getScopedName());
args.put(PROFILE_PROVISIONER, profile.getProvisioner().getName());
for (ProvisionerPropertyValue property : profile.getProvisioner().getProperties()) {
String key = PROFILE_PROPERTIES_PREFIX + property.getName();
if (!property.isEditable()) {
args.put(key, property.getValue());
} else if (!args.containsKey(key)) {
args.put(key, property.getValue());
}
}
}
use of io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue 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.ProvisionerPropertyValue 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