use of org.yaml.snakeyaml.introspector.Property in project studio by craftercms.
the class AbstractPluginDescriptorUpgradeOperation method execute.
@Override
public void execute(final String site) throws UpgradeException {
Path descriptorFile = getRepositoryPath(site).getParent().resolve(descriptorPath);
if (Files.notExists(descriptorFile)) {
logger.info("Plugin descriptor file not found for site {0}", site);
return;
}
try (Reader reader = Files.newBufferedReader(descriptorFile)) {
PluginDescriptor descriptor = descriptorReader.read(reader);
if (descriptor.getDescriptorVersion().equals(descriptorVersion)) {
logger.info("Plugin descriptor already update for site " + site);
return;
}
logger.info("Updating plugin descriptor for site " + site);
doPluginDescriptorUpdates(descriptor);
descriptor.setDescriptorVersion(descriptorVersion);
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setPrettyFlow(true);
Yaml yaml = new Yaml(new DisableClassLoadingConstructor(), new Representer() {
@Override
protected NodeTuple representJavaBeanProperty(final Object javaBean, final Property property, final Object propertyValue, final Tag customTag) {
if (propertyValue != null) {
return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
}
return null;
}
}, options);
String content = yaml.dumpAsMap(descriptor);
writeToRepo(site, descriptorPath, new ByteArrayInputStream(content.getBytes()));
commitAllChanges(site);
} catch (Exception e) {
throw new UpgradeException("Plugin descriptor can't be read for site " + site);
}
}
use of org.yaml.snakeyaml.introspector.Property in project sdc by onap.
the class ToscaExportHandler method convertInterfaceNodeType.
public Either<ToscaTemplate, ToscaError> convertInterfaceNodeType(Map<String, Component> componentsCache, Component component, ToscaTemplate toscaNode, Map<String, ToscaNodeType> nodeTypes, boolean isAssociatedComponent) {
log.debug("start convert node type for {}", component.getUniqueId());
ToscaNodeType toscaNodeType = createNodeType(component);
Either<Map<String, InterfaceDefinition>, StorageOperationStatus> lifecycleTypeEither = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(component.getModel());
if (lifecycleTypeEither.isRight() && !StorageOperationStatus.NOT_FOUND.equals(lifecycleTypeEither.right().value())) {
log.debug("Failed to fetch all interface types :", lifecycleTypeEither.right().value());
return Either.right(ToscaError.GENERAL_ERROR);
}
if (lifecycleTypeEither.isLeft()) {
List<String> allGlobalInterfaceTypes = lifecycleTypeEither.left().value().values().stream().map(InterfaceDataDefinition::getType).collect(Collectors.toList());
toscaNode.setInterface_types(addInterfaceTypeElement(component, allGlobalInterfaceTypes));
}
Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> dataTypesEither = applicationDataTypeCache.getAll(component.getModel());
if (dataTypesEither.isRight()) {
log.debug("Failed to fetch all data types :", dataTypesEither.right().value());
return Either.right(ToscaError.GENERAL_ERROR);
}
Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
List<InputDefinition> inputDef = component.getInputs();
Map<String, ToscaProperty> mergedProperties = new HashMap<>();
interfacesOperationsConverter.addInterfaceDefinitionElement(component, toscaNodeType, dataTypes, isAssociatedComponent);
addInputsToProperties(dataTypes, inputDef, mergedProperties);
final Map<String, ToscaAttribute> toscaAttributeMap;
toscaAttributeMap = convertToToscaAttributes(component.getAttributes(), dataTypes);
if (!toscaAttributeMap.isEmpty()) {
toscaNodeType.setAttributes(toscaAttributeMap);
}
if (CollectionUtils.isNotEmpty(component.getProperties())) {
List<PropertyDefinition> properties = component.getProperties();
Map<String, ToscaProperty> convertedProperties = properties.stream().map(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition, component.getInputs())).collect(Collectors.toMap(PropertyDataDefinition::getName, property -> propertyConvertor.convertProperty(dataTypes, property, PropertyConvertor.PropertyType.PROPERTY)));
// merge component properties and inputs properties
mergedProperties.putAll(convertedProperties);
}
if (MapUtils.isNotEmpty(mergedProperties)) {
toscaNodeType.setProperties(mergedProperties);
}
/* convert private data_types */
List<DataTypeDefinition> privateDataTypes = component.getDataTypes();
if (CollectionUtils.isNotEmpty(privateDataTypes)) {
Map<String, ToscaDataType> toscaDataTypeMap = new HashMap<>();
for (DataTypeDefinition dataType : privateDataTypes) {
log.debug("Emitting private data type: component.name={} dataType.name={}", component.getNormalizedName(), dataType.getName());
ToscaDataType toscaDataType = new ToscaDataType();
toscaDataType.setDerived_from(dataType.getDerivedFromName());
toscaDataType.setDescription(dataType.getDescription());
toscaDataType.setVersion(dataType.getVersion());
if (CollectionUtils.isNotEmpty(dataType.getProperties())) {
toscaDataType.setProperties(dataType.getProperties().stream().collect(Collectors.toMap(PropertyDataDefinition::getName, s -> propertyConvertor.convertProperty(dataTypes, s, PropertyType.PROPERTY), (toscaPropertyTobeValidated, toscaProperty) -> validateToscaProperty(privateDataTypes, toscaPropertyTobeValidated, toscaProperty))));
}
toscaDataTypeMap.put(dataType.getName(), toscaDataType);
}
toscaNode.setData_types(toscaDataTypeMap);
}
// Extracted to method for code reuse
return convertReqCapAndTypeName(componentsCache, component, toscaNode, nodeTypes, toscaNodeType, dataTypes);
}
use of org.yaml.snakeyaml.introspector.Property in project cassandra by apache.
the class ConfigCompatabilityTest method diff.
private void diff(Loader loader, Map<Class<?>, Map<String, Replacement>> replacements, ClassTree previous, Class<?> type, String prefix, Set<String> missing, Set<String> errors) {
Map<String, Replacement> replaces = replacements.getOrDefault(type, Collections.emptyMap());
Map<String, Property> properties = loader.getProperties(type);
Sets.SetView<String> missingInCurrent = Sets.difference(previous.properties.keySet(), properties.keySet());
Sets.SetView<String> inBoth = Sets.intersection(previous.properties.keySet(), properties.keySet());
for (String name : missingInCurrent) {
Replacement replacement = replaces.get(name);
// can we find the property in @Replaces?
if (replacement == null) {
missing.add(prefix + name);
} else {
// do types match?
Node node = previous.properties.get(name);
if (node instanceof Leaf && replacement.oldType != null)
typeCheck(replacement.converter, toString(replacement.oldType), ((Leaf) node).type, name, errors);
}
}
for (String name : inBoth) {
Property prop = properties.get(name);
Node node = previous.properties.get(name);
// if nested, look at sub-fields
if (node instanceof ClassTree) {
// current is nested type
diff(loader, replacements, (ClassTree) node, prop.getType(), prefix + name + ".", missing, errors);
} else {
// current is flat type
Replacement replacement = replaces.get(name);
if (replacement != null && replacement.oldType != null) {
typeCheck(replacement.converter, toString(replacement.oldType), ((Leaf) node).type, name, errors);
} else {
// previous is leaf, is current?
Map<String, Property> children = Properties.isPrimitive(prop) || Properties.isCollection(prop) ? Collections.emptyMap() : loader.getProperties(prop.getType());
if (!children.isEmpty())
errors.add(String.format("Property %s used to be a value-type, but now is nested type %s", name, prop.getType()));
typeCheck(null, toString(prop.getType()), ((Leaf) node).type, name, errors);
}
}
}
}
use of org.yaml.snakeyaml.introspector.Property in project cassandra by apache.
the class ConfigCompatabilityTest method addProperties.
private static void addProperties(Loader loader, ClassTree node, Class<?> type) {
SortedMap<String, Property> properties = new TreeMap<>(loader.getProperties(type));
for (Map.Entry<String, Property> e : properties.entrySet()) {
Property property = e.getValue();
Map<String, Property> subProperties = Properties.isPrimitive(property) || Properties.isCollection(property) ? Collections.emptyMap() : loader.getProperties(property.getType());
Node child;
if (subProperties.isEmpty()) {
child = new Leaf(toString(property.getType()));
} else {
ClassTree subTree = new ClassTree(property.getType());
addProperties(loader, subTree, property.getType());
child = subTree;
}
node.addProperty(e.getKey(), child);
}
}
use of org.yaml.snakeyaml.introspector.Property in project cassandra by apache.
the class PropertiesTest method backAndForth.
@Test
public void backAndForth() throws Exception {
Map<String, Property> ps = loader.flatten(Config.class);
Config config = new Config();
Set<String> keys = ImmutableSet.of("server_encryption_options.enabled", "client_encryption_options.enabled", "server_encryption_options.optional", "client_encryption_options.optional");
for (Property prop : ps.values()) {
// skip these properties as they don't allow get/set within the context of this test
if (keys.contains(prop.getName()))
continue;
Object value = prop.get(config);
if (value == null)
continue;
prop.set(config, value);
Object back = prop.get(config);
assertThat(back).isEqualTo(value);
}
}
Aggregations