the slick yaml based configuration by file in magnolia 5.4

34
THE SLICK, YAML -BASED CONFIGURATION BY FILE IN MAGNOLIA 5.4 #mconf15 Basel, 11 June 2015 Photo Credit:

Upload: magnolia

Post on 07-Aug-2015

472 views

Category:

Software


0 download

TRANSCRIPT

Page 1: The slick YAML based configuration by file in Magnolia 5.4

THE SLICK, YAML-BASEDCONFIGURATION BY FILE IN MAGNOLIA 5.4

#mconf15 Basel, 11 June 2015

Photo Credit:

Page 2: The slick YAML based configuration by file in Magnolia 5.4

Mikaël Geljić

SENIOR SOFTWARE ENGINEERMAGNOLIA

@mikaelgeljic

Page 3: The slick YAML based configuration by file in Magnolia 5.4

SPECIAL STAGESConfiguration by File, the story The new configuration (framework) YAML format and integration Demo

#registries #definitions #configSources #YAML

Page 5: The slick YAML based configuration by file in Magnolia 5.4

THE MASTER PLANMagnolia 5.4, a release for developers Overarching stories:

- Configure by file (or code) - Trouble-free and safe configuration - Develop sites without knowing Java - Streamline working with resources

#easeOfDevelopment #lightModules

Page 6: The slick YAML based configuration by file in Magnolia 5.4

"LIGHT MODULES"Maven module <maven-module-name>/ ├── pom.xml └── src/ └── main/ ├── java/ └── resources/ ├── META-INF/ │ └── magnolia/ │ └── module-name.xml └── <module-name>/ ├── apps/ ├── dialogs/ │ └── myDialog.yaml ├── resources/ └── templates/ ├── components/ │ ├── myComponent.ftl │ └── myComponent.yaml └── pages/ ├── myTemplate.ftl └── myTemplate.yaml

Light module ${magnolia.resources.dir}/└── <module-name>/ ├── apps/ ├── dialogs/ │ └── myDialog.yaml ├── resources/ └── templates/ ├── components/ │ ├── myComponent.ftl │ └── myComponent.yaml └── pages/ ├── myTemplate.ftl └── myTemplate.yaml

Page 7: The slick YAML based configuration by file in Magnolia 5.4

Photo Credit:

WHY CONFIG BY FILE?Hassles with JCR config

Lengthily crafted in the Configuration app verbose raw JCR exports: bootstrap files "persisted flavor of config"

- painful while developing (merge changes, wipe repo) - painful to upgrade, version-handlers

Page 8: The slick YAML based configuration by file in Magnolia 5.4

CONFIG BY FILEA lean, readable format: YAML Ease of editing Config files next to template scripts, all in one place File observation, instant changes Easier collaboration for dev teams (diff, no import/export) Greater validation capabilities

Photo Credit:

Page 9: The slick YAML based configuration by file in Magnolia 5.4

DATE FIELD CONFIG, BOOTSTRAP FILE

Page 10: The slick YAML based configuration by file in Magnolia 5.4

DATE FIELD CONFIG, YAML FILE

Page 11: The slick YAML based configuration by file in Magnolia 5.4

THE NEW CONFIGURATION(FRAMEWORK)

Photo Credit:

Page 12: The slick YAML based configuration by file in Magnolia 5.4

REGISTRIES IN MAGNOLIACollect various types of elements in the system

- e.g. templates, dialogs, apps

Up to 5.3 - no common ancestor, all duplicated! - paired with so-called (observing) managers - knows nothing if bean resolution fails

Page 13: The slick YAML based configuration by file in Magnolia 5.4

REGISTRY OUTLOOK (5.3)

JCR

Managers

Node2Bean

Registries

Server config

Modules config

JCR Config app

💩

💩

Page 14: The slick YAML based configuration by file in Magnolia 5.4

REGISTRY OUTLOOK (5.4)

JCR

Configuration Sources

File

Node2Bean

Registries

Server config

Modules config

Code

{}

Map2Bean

Config app

Page 15: The slick YAML based configuration by file in Magnolia 5.4

THE REGISTRY API

Registry - type() - metadataBuilder() - register() - getProvider()

info.magnolia.config.registry

Metadata id, module, location

DefinitionProvider bean, isValid

Raw view map representation

Page 16: The slick YAML based configuration by file in Magnolia 5.4

DEFINITION ID (STRATEGIES)Reference string glueing definitions together

- e.g. in template dialog: mte:components/textImage

Two approaches module + relativePath

- e.g. for templates, dialogs - <sample-module>:pages/article

name - e.g. for apps, field-types - pages, assets

Page 17: The slick YAML based configuration by file in Magnolia 5.4

Sample Registry impl@Singleton public class FieldTypeDefinitionRegistry extends AbstractRegistry<FieldTypeDefinition> {

@Override public DefinitionType type() { return DefinitionTypes.FIELD_TYPE; }

@Override public DefinitionMetadataBuilder newMetadataBuilder() { return DefinitionMetadataBuilder.usingNameAsId(); } }

Page 18: The slick YAML based configuration by file in Magnolia 5.4

THE CONFIGURATION SOURCEReplaces old managers Binds itself to a Registry ConfigurationSourceFactory

• JCR / YAML default binding settings (conventions)

e.g. in module start configSourceFactory.yaml().bindWithDefaults(dialogRegistry);

Page 19: The slick YAML based configuration by file in Magnolia 5.4

MINISTER OF REGISTRIESRegistryFacade Query definitions by module, source or type Guice multi-bindings to the rescue

RegistryFacade

info.magnolia.config.registry

TemplateRegistry DialogRegistry AppRegistry

Page 20: The slick YAML based configuration by file in Magnolia 5.4

THE CONFIG OVERVIEW APP

Page 23: The slick YAML based configuration by file in Magnolia 5.4

YAML FORMAT AND INTEGRATION

Photo Credit:

Page 24: The slick YAML based configuration by file in Magnolia 5.4

YAML: THE SPECyaml.org/spec/1.1/ indentation over enclosure marks scalars, sequences, mappings

key : valuetitle : Magnolia 5.4year : 2015boolean : true

F1Teams: - Ferrari - Williams - Lotus

subApps: browser: class: (...) actions: addItem : (...) editItem: (...) imageProvider: class: (...)

Page 25: The slick YAML based configuration by file in Magnolia 5.4

INTEGRATION WITH CONFIGCollect "resources" by matching pattern

- e.g. <module>/<deftype>/<relPath>/<name>.yaml

NamedDefinition - name property is inferred from file name - may still be overridden in file - e.g. <module>/apps/resources.yaml

Map2Bean

Page 26: The slick YAML based configuration by file in Magnolia 5.4

YAML VS. JCRYAML JCR

Map2Bean Node2Bean

bean instantiation as per target-types, class property, type-mappings

!include, references, merge keys extends

sequences, mappings nodes/sub-nodes for both lists/maps

Page 27: The slick YAML based configuration by file in Magnolia 5.4

LISTS VS. MAPS

public interface TabDefinition { List<FieldDefinition> getFields();}

fields: - name: title class: info.magnolia.ui.form.field.definition.TextFieldDefinition - name: text class: info.magnolia.ui.form.field.definition.RichTextFieldDefinition

Photo Credit:

Page 28: The slick YAML based configuration by file in Magnolia 5.4

LISTS VS. MAPS

public interface DialogDefinition { Map<String, ActionDefinition> getActions();}

actions: commit: class: info.magnolia.ui.admincentral.dialog.action.SaveDialogActionDefinition cancel: class: info.magnolia.ui.admincentral.dialog.action.CancelDialogActionDefinition

Photo Credit:

Page 29: The slick YAML based configuration by file in Magnolia 5.4

ADVANCED YAMLdocument references

- same document only

browser contentConnector: &contentConnector implementationClass: info.magnolia.resources.app.ResourcesContentConnector detail: contentConnector: *contentConnector

Page 30: The slick YAML based configuration by file in Magnolia 5.4

ADVANCED YAMLmerge keys

- good for appending - not suited for merging nested structures

fields: - &codeField name: content class: info.magnolia.ui.form.field.definition.CodeFieldDefinition fileNameProperty: name height: 500 - <<: *codeField readOnly: true

Page 31: The slick YAML based configuration by file in Magnolia 5.4

MODULARIZING YAML FILESThe !include directive

- Magnolia-specific, at YAML-reader level - caters to external file reference

columns: - name: name class: info.magnolia.ui.workbench.column.definition.PropertyColumnDefinition - !include /resources-app/generic/column/originName.yaml

Page 32: The slick YAML based configuration by file in Magnolia 5.4
Page 33: The slick YAML based configuration by file in Magnolia 5.4

THE JOURNEY ONLY BEGINSUpdated selected registries so far

- renderers, templates - dialogs, apps, fieldTypes, mediaeditors, messageViews

Will move more typical configurations to registries - e.g. appLauncherLayout, server config

Will productize and bundle the Config Overview app How about auto-suggest?

Page 34: The slick YAML based configuration by file in Magnolia 5.4

THANK YOU! QUESTIONS?

Photo Credit:

@mikaelgeljic

#mconf15 Basel, 11 June 2015