CIRCUIT – An Adobe Developer Event
Presented by ICF Interactive
10 Things Apache
Sling Can Do...
The Secrets of an Open
Source Project
•  RnD Adobe Research Switzerland
•  Team Lead / Founder of Adobe
Granite
•  Member of the Apache Software
Foundation
•  VP of Apache Felix and Sling
•  OSGi Core Platform and Enterprise
Expert Groups
•  Member of the OSGi Board
•  Book / article author, technical
reviewer, conference speaker
2
cziegele@adobe.com
@cziegeler
3
0	
  
History
•  Code donation to Apache in 2007
•  OSGi implementations
•  Tooling
•  Sling Framework
4
Statistics
•  Nearly 40 committers
•  Highly modular
•  ~ 15 releases per month
•  Platform for Adobe (AEM)
•  Used by various companies
5
6
1	
  
Sustainable through Modularity
•  Moduls from the start
•  Very stable client API (+7 years)
•  Extensions
•  The Power of OSGi
7
8
2	
  
Everything is a Resource
9
/	
  
content	
  
products	
  
misc	
  
workflows	
  images	
  
Resource	
  
	
  Provider	
  
[Oak]	
  
Resource	
  
	
  Provider	
  
[DB]	
  
Resource	
  
	
  Provider	
  
[File]	
  
Resource	
  
	
  Provider	
  
[Mongo]	
  
Resource API
•  Simple to use
•  Powerful through adapter pattern
•  Full CRUD Support
•  Queries
•  Access Gateway
10
11
3	
  
 
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
Cluster	
  99	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  	
  	
  	
  	
  	
  	
  Cluster	
  35	
  
Build for the Cloud
12
Clustered	
  JCR	
  JCR	
  
ID	
  :	
  A	
   ID	
  :	
  X	
   ID	
  :	
  42	
  ID	
  :	
  1	
  
Single	
  
Instance	
  
Instance	
  
1	
  
Instance	
  
2	
  
Instance	
  
3	
  
Leader	
   Leader	
  
Topology	
  
13
4	
  
Sling Jobs
•  Guaranteed processing,
•  Exactly once (can be at most once)
•  Load Balancing
14
Sling Job Distribution
15
Topology	
  
Instance	
  
Sling	
  ID:	
  1	
  
Job	
  Manager	
  
Instance	
  
Sling	
  ID:	
  2	
  
Job	
  Manager	
  
Instance	
  
Sling	
  ID:	
  3	
  
Job	
  Manager	
  
Job	
  Consumer	
  
Topic:	
  A	
  
Job	
  Consumer	
  
Topic:	
  B	
  
Sling Job Distribution
16
Instance	
  
Sling	
  ID:	
  1	
  
Job	
  Manager	
  
Instance	
  
Sling	
  ID:	
  2	
  
Job	
  Manager	
  
Instance	
  
Sling	
  ID:	
  3	
  
Job	
  Manager	
  A	
  
Job	
  Consumer	
  
Topic:	
  A	
  
Job	
  Consumer	
  
Topic:	
  B	
  
A:2	
  
Job	
  
Topology	
  
Sling Job Distribution
17
Instance	
  
Sling	
  ID:	
  1	
  
Job	
  Manager	
  
Instance	
  
Sling	
  ID:	
  2	
  
Job	
  Manager	
  
Instance	
  
Sling	
  ID:	
  3	
  
Job	
  Manager	
  B	
  
Job	
  Consumer	
  
Topic:	
  A	
  
Job	
  Consumer	
  
Topic:	
  B	
  
B:3	
  
Job	
  
Topology	
  
18
5	
  
Local Events
19
OSGi	
  Event	
  Admin	
  Component	
  A	
  
publish
deliver
Component	
  X	
  
Component	
  Y	
  
Remote Events
20
OSGi	
  Event	
  Admin	
  
Component	
  A	
  
publish
deliver
Component	
  X	
  
Component	
  Y	
  
OSGi	
  Event	
  Admin	
  
21
6	
  
Sightly – Beautiful Markup
•  Lightweight
•  Secure
•  Code-less
•  Powerful
•  Intuitive
22
Sightly
<a href="${properties.link || '#'}"
title="${properties.jcr:title}">
${properties.jcr:description}
</a>
23
Separate Content and Code
24
<!-­‐-­‐/*template.html	
  */-­‐-­‐>	
  
	
  
<div	
  data-­‐sly-­‐use.nav="navigaon.js">${nav.foo}</div>	
  
	
  
	
  
<!-­‐-­‐/*navigaon.js	
  */-­‐-­‐>	
  
	
  
use(funcon	
  ()	
  {	
  return	
  {	
  
	
  	
  	
  	
  	
  	
  	
  foo:	
  "Hello	
  World"	
  
	
  };	
  
	
  
});	
  
Or	
  Java	
  
(+	
  Sling	
  Models)	
  
25
7	
  
Query API
26
{
Resource resource = ...;
while ((resource = resource.getParent()) != null) {
if (!resource.isResourceType("cq:Page")) {
continue;
}
Resource template = resource
.getChild("jcr:content/cq:template");
if (template != null
&& "my/template".equals(template.adaptTo(String.class))) {
break;
}
}
if (resource != null) {
// we've found appropriate ancestor
}
}
Query API
27
{
Resource resource = ...;
while ((resource = resource.getParent()) != null) {
if (!resource.isResourceType("cq:Page")) {
continue;
}
Resource template = resource
.getChild("jcr:content/cq:template");
if (template != null
&& "my/template".equals(template.adaptTo(String.class))) {
break;
}
}
if (resource != null) {
// we've found appropriate ancestor
}
}
import static org.apache.sling.query.SlingQuery.$;
//...
$(resource)
.closest("cq:Page[jcr:content/cq:template=my/template]")
28
8	
  
Provisioning Model
•  Text based instance description
– Runtime (OSGi Framework, Sling Launchpad,
Properties)
– Features (Modules, Content, Configuration)
– Application (Modules, Content, Configuration)
•  Supports run modes
29
Provisioning Model
30
[feature	
  name=quickstart]	
  
	
  	
  	
  	
  	
  
[arfacts]	
  
	
  
	
  	
  com.adobe.granite/com.adobe.granite.repository.checker/1.0.0	
  
	
  	
  org.apache.sling/org.apache.sling.tenant/1.0.2	
  
	
  	
  org.apache.sling/org.apache.sling.bundleresource.impl/2.2.0	
  
	
  	
  com.adobe.granite/crx-­‐auth-­‐token/2.5.20	
  
	
  	
  org.apache.sling/org.apache.sling.commons.compiler/2.2.0	
  
	
  	
  org.apache.sling/org.apache.sling.commons.html/1.0.0	
  
	
  	
  org.apache.sling/org.apache.sling.commons.mime/2.1.8	
  
	
  	
  org.apache.sling/org.apache.sling.engine/2.4.0	
  
	
  
[configuraons]	
  
	
  	
  com.adobe.granite.auth.oauth.impl.helper.ProviderConfigManager	
  
	
  	
  	
  	
  oauth.cookie.max.age="-­‐1"	
  
	
  	
  	
  	
  oauth.cookie.login.meout="-­‐1“	
  
Provisioning Model
•  Various tooling possible
•  New launchers
•  Diff between two versions of the
application
•  Only „deploy“ changed/new artifacts
31
32
9	
  
1…2…3…test…..test
•  Mocking of ResourceResolverFactory, ResourceResolver,
Resource, ….
•  Embedding a JCR Repository
•  Defer to Integration Tests
Apache Sling Testing Mocks
Resource Resolver Mock
ResourceResolverFactory factory =
new MockResourceResolverFactory();
ResourceResolver resolver = factory.getResourceResolver(null);	
  
resolver.getResource("/my/path");
resource.adaptTo(ValueMap.class);
resolver.create(parent, "new resource", properties);
resolver.delete(resource);
resource.adaptTo(ModifiableValueMap.class);
resolver.commit();
resolver.revert();	
  
Resource Resolver Mock
MockHelper.create(resolver)
.resource("/apps")
.resource("1").p("a", "1").p("b", "2")
.resource(".2")
.p(ResourceResolver.PROPERTY_RESOURCE_TYPE, "apps")
.resource(".3").p("e", "2")
.p(ResourceResolver.PROPERTY_RESOURCE_TYPE, "apps")
.resource("/libs")
.resource("1").p("d", "1").p("b", "5")
.resource(".2")
.p(ResourceResolver.PROPERTY_RESOURCE_TYPE, "apps")
.resource(".4").p("f", "2");
Sling Mocks for Everyone
•  Logging
•  OSGi
•  Resource Resolver
•  Sling
•  JCR / Jackrabbit / Oak
36
37
10	
  
Sling IDE
•  Eclipse based
•  AEM extensions
•  Fast round trips
– Content
– Bundles
38
39
11	
  
It‘s Open Source
•  Everyone can participate!
40
41
42	
  
And now you J
Q&A
42
CIRCUIT – An Adobe Developer Event
Presented by ICF Interactive
10 Things You
can do for
Apache Sling...
The END
43

CIRCUIT 2015 - 10 Things Apache Sling Can Do

  • 1.
    CIRCUIT – AnAdobe Developer Event Presented by ICF Interactive 10 Things Apache Sling Can Do... The Secrets of an Open Source Project
  • 2.
    •  RnD AdobeResearch Switzerland •  Team Lead / Founder of Adobe Granite •  Member of the Apache Software Foundation •  VP of Apache Felix and Sling •  OSGi Core Platform and Enterprise Expert Groups •  Member of the OSGi Board •  Book / article author, technical reviewer, conference speaker 2 cziegele@adobe.com @cziegeler
  • 3.
  • 4.
    History •  Code donationto Apache in 2007 •  OSGi implementations •  Tooling •  Sling Framework 4
  • 5.
    Statistics •  Nearly 40committers •  Highly modular •  ~ 15 releases per month •  Platform for Adobe (AEM) •  Used by various companies 5
  • 6.
  • 7.
    Sustainable through Modularity • Moduls from the start •  Very stable client API (+7 years) •  Extensions •  The Power of OSGi 7
  • 8.
  • 9.
    Everything is aResource 9 /   content   products   misc   workflows  images   Resource    Provider   [Oak]   Resource    Provider   [DB]   Resource    Provider   [File]   Resource    Provider   [Mongo]  
  • 10.
    Resource API •  Simpleto use •  Powerful through adapter pattern •  Full CRUD Support •  Queries •  Access Gateway 10
  • 11.
  • 12.
                          Cluster  99                                      Cluster  35   Build for the Cloud 12 Clustered  JCR  JCR   ID  :  A   ID  :  X   ID  :  42  ID  :  1   Single   Instance   Instance   1   Instance   2   Instance   3   Leader   Leader   Topology  
  • 13.
  • 14.
    Sling Jobs •  Guaranteedprocessing, •  Exactly once (can be at most once) •  Load Balancing 14
  • 15.
    Sling Job Distribution 15 Topology   Instance   Sling  ID:  1   Job  Manager   Instance   Sling  ID:  2   Job  Manager   Instance   Sling  ID:  3   Job  Manager   Job  Consumer   Topic:  A   Job  Consumer   Topic:  B  
  • 16.
    Sling Job Distribution 16 Instance   Sling  ID:  1   Job  Manager   Instance   Sling  ID:  2   Job  Manager   Instance   Sling  ID:  3   Job  Manager  A   Job  Consumer   Topic:  A   Job  Consumer   Topic:  B   A:2   Job   Topology  
  • 17.
    Sling Job Distribution 17 Instance   Sling  ID:  1   Job  Manager   Instance   Sling  ID:  2   Job  Manager   Instance   Sling  ID:  3   Job  Manager  B   Job  Consumer   Topic:  A   Job  Consumer   Topic:  B   B:3   Job   Topology  
  • 18.
  • 19.
    Local Events 19 OSGi  Event  Admin  Component  A   publish deliver Component  X   Component  Y  
  • 20.
    Remote Events 20 OSGi  Event  Admin   Component  A   publish deliver Component  X   Component  Y   OSGi  Event  Admin  
  • 21.
  • 22.
    Sightly – BeautifulMarkup •  Lightweight •  Secure •  Code-less •  Powerful •  Intuitive 22
  • 23.
    Sightly <a href="${properties.link ||'#'}" title="${properties.jcr:title}"> ${properties.jcr:description} </a> 23
  • 24.
    Separate Content andCode 24 <!-­‐-­‐/*template.html  */-­‐-­‐>     <div  data-­‐sly-­‐use.nav="navigaon.js">${nav.foo}</div>       <!-­‐-­‐/*navigaon.js  */-­‐-­‐>     use(funcon  ()  {  return  {                foo:  "Hello  World"    };     });   Or  Java   (+  Sling  Models)  
  • 25.
  • 26.
    Query API 26 { Resource resource= ...; while ((resource = resource.getParent()) != null) { if (!resource.isResourceType("cq:Page")) { continue; } Resource template = resource .getChild("jcr:content/cq:template"); if (template != null && "my/template".equals(template.adaptTo(String.class))) { break; } } if (resource != null) { // we've found appropriate ancestor } }
  • 27.
    Query API 27 { Resource resource= ...; while ((resource = resource.getParent()) != null) { if (!resource.isResourceType("cq:Page")) { continue; } Resource template = resource .getChild("jcr:content/cq:template"); if (template != null && "my/template".equals(template.adaptTo(String.class))) { break; } } if (resource != null) { // we've found appropriate ancestor } } import static org.apache.sling.query.SlingQuery.$; //... $(resource) .closest("cq:Page[jcr:content/cq:template=my/template]")
  • 28.
  • 29.
    Provisioning Model •  Textbased instance description – Runtime (OSGi Framework, Sling Launchpad, Properties) – Features (Modules, Content, Configuration) – Application (Modules, Content, Configuration) •  Supports run modes 29
  • 30.
    Provisioning Model 30 [feature  name=quickstart]             [arfacts]        com.adobe.granite/com.adobe.granite.repository.checker/1.0.0      org.apache.sling/org.apache.sling.tenant/1.0.2      org.apache.sling/org.apache.sling.bundleresource.impl/2.2.0      com.adobe.granite/crx-­‐auth-­‐token/2.5.20      org.apache.sling/org.apache.sling.commons.compiler/2.2.0      org.apache.sling/org.apache.sling.commons.html/1.0.0      org.apache.sling/org.apache.sling.commons.mime/2.1.8      org.apache.sling/org.apache.sling.engine/2.4.0     [configuraons]      com.adobe.granite.auth.oauth.impl.helper.ProviderConfigManager          oauth.cookie.max.age="-­‐1"          oauth.cookie.login.meout="-­‐1“  
  • 31.
    Provisioning Model •  Varioustooling possible •  New launchers •  Diff between two versions of the application •  Only „deploy“ changed/new artifacts 31
  • 32.
  • 33.
    1…2…3…test…..test •  Mocking ofResourceResolverFactory, ResourceResolver, Resource, …. •  Embedding a JCR Repository •  Defer to Integration Tests Apache Sling Testing Mocks
  • 34.
    Resource Resolver Mock ResourceResolverFactoryfactory = new MockResourceResolverFactory(); ResourceResolver resolver = factory.getResourceResolver(null);   resolver.getResource("/my/path"); resource.adaptTo(ValueMap.class); resolver.create(parent, "new resource", properties); resolver.delete(resource); resource.adaptTo(ModifiableValueMap.class); resolver.commit(); resolver.revert();  
  • 35.
    Resource Resolver Mock MockHelper.create(resolver) .resource("/apps") .resource("1").p("a","1").p("b", "2") .resource(".2") .p(ResourceResolver.PROPERTY_RESOURCE_TYPE, "apps") .resource(".3").p("e", "2") .p(ResourceResolver.PROPERTY_RESOURCE_TYPE, "apps") .resource("/libs") .resource("1").p("d", "1").p("b", "5") .resource(".2") .p(ResourceResolver.PROPERTY_RESOURCE_TYPE, "apps") .resource(".4").p("f", "2");
  • 36.
    Sling Mocks forEveryone •  Logging •  OSGi •  Resource Resolver •  Sling •  JCR / Jackrabbit / Oak 36
  • 37.
  • 38.
    Sling IDE •  Eclipsebased •  AEM extensions •  Fast round trips – Content – Bundles 38
  • 39.
  • 40.
    It‘s Open Source • Everyone can participate! 40
  • 41.
  • 42.
    And now youJ Q&A 42
  • 43.
    CIRCUIT – AnAdobe Developer Event Presented by ICF Interactive 10 Things You can do for Apache Sling... The END 43