use of io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue in project cdap by cdapio.
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 cdapio.
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());
}
use of io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue in project cdap by cdapio.
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 SystemProfileCreatorTest method testExistingIsUnmodified.
@Test
public void testExistingIsUnmodified() throws Exception {
// write a profile
ProfileId profileId = NamespaceId.SYSTEM.profile("p1");
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);
profileService.saveProfile(profileId, profile);
// run the bootstrap step and make sure it succeeded
SystemProfileCreator.Arguments arguments = new SystemProfileCreator.Arguments(profile.getName(), "different label", "different desciption", profile.getProvisioner());
BootstrapStepResult result = profileCreator.execute("label", GSON.toJsonTree(arguments).getAsJsonObject());
BootstrapStepResult expected = new BootstrapStepResult("label", BootstrapStepResult.Status.SUCCEEDED);
Assert.assertEquals(expected, result);
// check that it didn't overwrite the existing profile
Assert.assertEquals(profile, profileService.getProfile(profileId));
}
use of io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue in project cdap by caskdata.
the class ProfileServiceTest method testProfileOverrides.
@Test
public void testProfileOverrides() throws Exception {
List<ProvisionerPropertyValue> provisionerProperties = new ArrayList<>();
provisionerProperties.add(new ProvisionerPropertyValue("editable1", "val", true));
provisionerProperties.add(new ProvisionerPropertyValue("editable2", "val", true));
provisionerProperties.add(new ProvisionerPropertyValue("final", "finalval", false));
ProvisionerInfo provisionerInfo = new ProvisionerInfo("provisioner", provisionerProperties);
Profile profile = new Profile("name", "label", "desc", provisionerInfo);
ProfileId profileId = NamespaceId.DEFAULT.profile("p");
profileService.saveProfile(profileId, profile);
try {
Map<String, String> args = new HashMap<>();
args.put("editable1", "newval");
args.put("final", "shouldnotwork");
args.put("newarg", "val");
// resolved properties should include all the stored properties,
// with 'final' not overridden and 'editable1' overridden.
List<ProvisionerPropertyValue> expectedProperties = new ArrayList<>();
expectedProperties.add(new ProvisionerPropertyValue("editable1", "newval", true));
expectedProperties.add(new ProvisionerPropertyValue("editable2", "val", true));
expectedProperties.add(new ProvisionerPropertyValue("final", "finalval", false));
expectedProperties.add(new ProvisionerPropertyValue("newarg", "val", true));
provisionerInfo = new ProvisionerInfo(provisionerInfo.getName(), expectedProperties);
Profile expected = new Profile(profile.getName(), "label", profile.getDescription(), provisionerInfo);
Profile actual = profileService.getProfile(profileId, args);
Assert.assertEquals(expected, actual);
} finally {
profileService.disableProfile(profileId);
profileService.deleteProfile(profileId);
}
}
Aggregations