Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik

4.941 visualizaciones

Publicado el

OSGi Community Event 2014

Abstract:
Experience level: Beginner

Apache Karaf is a small OSGi based runtime which provides a lightweight container onto which various components and applications can be deployed.

This session gives an overview over Apache Karaf, how to manage and configure Apache Karaf and how to use the comprehensive command shell that Karaf provides. By the example of a simple pet clinic application we will demonstrate how to build and deploy a web application on Apache Karaf. This talk will introduce the different deployment mechanisms available in Karaf and how to deploy bundles from the file system, command shell or via a maven repository. You will learn how to manage external dependencies via features, use the Karaf maven plugin to create features and build and configure persistence bundles for Apache Karaf. We will further give an overview, how to use Karaf in a cloud environment and how to use the Apache Cellar project to build up an Apache Karaf cluster.

Speaker Bios:

Torsten Frank

Torsten Frank is an entrepreneur and healthcare IT expert with international experience and a strong background in product and business development. He is CEO and founder of medisite, a company that delivers highly specialized healthcare IT solutions to their customers for more than 10 years. medisite is a winner of the Federal Ministry for Economic Affairs and Energy (BMWi) “Trusted Cloud” technology competition, geared toward secure cloud computing for SMEs and the public sector. Torsten Frank holds a medical degree from the Hannover Medical School, where he also has worked for several years as a physician at the Department of Cardiothoracic Surgery after completing his medical studies in Hannover, Germany and Chicago, USA.

Alexander Grzesik

Alexander is the head of development of medisite Systemhaus GmbH and responsible for the development of the the PaaS+ cloud platform the clinical information system m.life and software architect for the TRESOR Project.

He has 15 years of work experience in medical Software development as team leader and software architect.

Expert for Software Architecture, OSGi, Java and Java EE.

Alexander has been a speaker at several conferences including EclipseCon Europe and the OpenShift Community Day.

Publicado en: Tecnología

Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik

  1. 1. Apache Karaf Develop OSGi Applications with Apache Karaf
  2. 2. 2 Today‘s speakers Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf TorstenFrank CEO & Founder Physician 15+ years experience in business and product development Healthcare IT expert Qualified medical device consultant Alexander Grzesik Head of software development, Chief Software Architect Java Expert 15+ years experience in software development Validator for computer validation (GAMP 5)
  3. 3. 3 medisite & Cloudyle • Specialized for over 10 years in the development of software focused on the healthcare market. • Our products m.life® and m.care® are comprehensive healthcare solutions. • Expanded to the cloud with the spin-off Cloudyle, with offices in Berlin, Hannover, Germany and soon in the US. Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf
  4. 4. 4 Agenda Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf Run •Files & Folders •Start andStop •Command Line Develop •Configuration •Logging •Web Deploy •Maven •Features •Kar Archives Test •Debug •Integration Testing Production •Clustering •Cloud
  5. 5. 5 Apache KarafHighlights Flexible ProvisioningandDeployment Applicationprovisioningby„Features“ Lightweight andmodular AdvancedLogging Dynamic Configuration Command Line Remote Management Supports different OSGi Frameworks Lots ofavailablefeatures Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf
  6. 6. 6 Apache KarafOverview Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf
  7. 7. 7 ImportantFiles andFolders +---bin: Startup scriptsandcommands +---data: Karafworkdirectory | +---cache: Installedbundles | +---log: Default log directory | +---tmp: Temporaryfiles +---deploy: Directory forfilesystemdeployment +---etc: Configurationfiles +---instances: Instance management +---lib: Core libraries +---system: System bundlerepository Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf
  8. 8. 8 KarafSpecificEnvironment Variables KARAF_HOME: thelocationofyourApache Karafinstallation(defaultisfounddependingwhereyoulaunchthestartupscript). KARAF_BASE: thelocationofyourApache Karafbase(defaultisKARAF_HOME). KARAF_DATA: thelocationofyourApache Karafdatafolder(defaultisKARAF_BASE/data). KARAF_ETC: thelocationofyourApache Karafetcfolder(defaultisKARAF_BASE/etc). KARAF_OPTS: extra argumentspassedtotheJava commandline(defaultisnull). KARAF_DEBUG: if'true', enablethedebugmode(defaultisnull). Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf
  9. 9. 9 Commandline Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf
  10. 10. 10 Command Groups (Karaf3.x) bundle:* -Install and control bundles dev:* -Development support feature:* -Manage features instance:* -Control of multiple instances jaas:* -JAAS role and rights management log:* -log display obr:* -Interaction with OSGi Bundle Repositories scr:* -Declarative Services management service:* -Manage OSGi Services shell:* -useful helper functions (i.e. grep, more, java info) ssh:* -SSH connections system:* -OSGi framework management web:* -WAR bundle management wrapper:* -OS service installation Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf
  11. 11. 11 Remote Management Usecommandlinevia SSH: Configurationvia: org.apache.karaf.shell.cfg User andRolemanagementvia JAAS Configurevia users.properties org.apache.karaf.command.acl.* forcommandspecificpermissions Default roles: viewer, manager, admin Connect tootherKarafusingsshcommand Connect tolocalrunningKarafusingtheclientscript Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf ssh-p 38031karaf@karaf-mydomain.paasplus.com
  12. 12. 12 Webconsole Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf
  13. 13. 13 Scripting Scripting allowscustomizingconsole Variable assignment: msg= “Welcome toPaaS+“ Lists, Mapsmap= [Jan=1 Feb=2 Mar=3] Pipe commands($.contextbundles) | grep-i PaaS+ Flow controlshell:if, shell:each Startup scriptsconfiguredin shell.init.script Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf paasplus:refresh={ feature:repo-remove-u mvn:com.cloudyle.paasplus/$args/LATEST/xml/features; feature:repo-addmvn:com.cloudyle.paasplus/$args/LATEST/xml/features; feature:install$args} ;
  14. 14. 14 Custom Commands Add customcommandsfromyourbundles Extendorg.apache.karaf.shell.console.OsgiCommandSupport Add @org.apache.karaf.shell.commands.CommandAnnotation Register commandvia Blueprint Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf publicclassStartInstanceCommandextendsOsgiCommandSupport{ @Argument(index=0,name="key",description="Processdefinitionkey", required=true,multiValued=false) String key; @Override protectedObjectdoExecute()throwsException{ finalProcessInstanceinstance=startProcessInstance(this.key); System.out.println("Instance id: "+instance.getProcessInstanceId()); returnnull; } … <shell:command-bundle> <shell:command> <shell:actionclass="com.cloudyle.paasplus.commands.StartInstanceCommand"> <shell:propertyname="runtimeService"ref="runtimeBean"/> </shell:action> </shell:command> </shell:command-bundle>
  15. 15. 15 Developer Commands dev:dump-create Createsa systemdumpofKaraf bundle:diag Givesdetailswhybundledidnot start bundle:dynamic-import enable or disable the dynamic import of a given bundle log:exception-display Displays the last occurred exception from the log log:tail Continuouslydisplaylog entries bundle:tree-show Show bundledependencytree bundle:watch Automaticupdate frommavenrepo Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf
  16. 16. 16 PetClinic Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf PetClinic Persistence ClinicService API Provider GUI Feature https://github.com/Cloudyle/petclinic JPA-Bundle Configuration, Logging Web App Bundle Feature generation
  17. 17. 17 Persistence Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf https://github.com/Cloudyle/aries/tree/cloudyle JPA API JPA Container Container Context Container Blueprint Aries JPA Hibernate OpenJPA EclipseLink PersistenceBundle •Entities •Persistence.xml •Meta-Persistenceflag <Meta-Persistence> META-INF/persistence.xml </Meta-Persistence> <beanid="persistenceUnit" class=„... " init-method="init"> <jpa:unitproperty="entityManagerFactory" unitname="persistence-petclinic-nosql" /> </bean>
  18. 18. 18 Database Connection Configurationvia Blueprint Simplydeployblueprint.xml intoKaraf Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf <beanid="dataSource"class="org.postgresql.ds.PGPoolingDataSource" destroy-method="close"> <propertyname="serverName"value="${host}:${port}/${database}"/> <propertyname="user"value="${user}"/> <propertyname="password"value="${password}"/> <propertyname="dataSourceName"value="defaultConnectionPool"/> <propertyname="initialConnections"value="${initialConnections}"/> <propertyname="maxConnections"value="${maxConnections}"/> </bean> <serviceinterface="javax.sql.DataSource"ref="dataSource"> <service-properties> <entrykey="osgi.jndi.service.name"value="jdbc/default"/> <entrykey="datasource.name"value="postgres"/> </service-properties> </service>
  19. 19. 19 Logging Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf log4j slf4j commonslogging Java utillogging logback OSGi LoggingService log4j Pax logging etc/org.ops4j.pax.logging.cfg Commands: log:display log:tail log:set log:get log:log Import-package: org.slf4j;provider=paxlogging
  20. 20. 20 Configuration Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf Bundle ConfigAdmin Bundle Config Global Config Pid.cfg config.properties custom.properties System Config system.properties Java -D Commands: config:list config:edit config:property-list config:property-set
  21. 21. 21 UsagewithBlueprint Import configurationin blueprint: Property Placeholders: ManagedProperties Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf <cm:property-placeholderid="property-placeholder"persistent- id="com.cloudyle.paasplus.petclinic"update-strategy="reload"> <cm:default-properties> <cm:propertyname="dataDir"value="data"/> <cm:propertyname="createSampleData"value="true"/> </cm:default-properties> </cm:property-placeholder> <beanid="reportHelper"class="com.cloudyle.paasplus.petclinic.impl.ReportHelper"> <propertyname="dataDir"value="${dataDir}"/> </bean> <beanid="clinicS"class="com.cloudyle.paasplus.petclinic.impl.ClinicServiceImpl"> <cm:managed-propertiespersistent-id=clinicServiceConfig" update-strategy="container-managed"/> </bean>
  22. 22. 22 Web Applications Webappsupportvia Pax Web feature Integrated Jetty etc/jetty.xml OSGi http Service (Whiteboard pattern) Register Web applicationresourcesasOSGi services FullWebapp Deploywar orwab CDI support Commands web:list, stop, start(Webapps) http:list (Servlets) Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf
  23. 23. 23 Web ApplicationBundle Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf Web App Bundle META-INF MANIFEST WEB-INF classes web.xml <Web-ContextPath>/petclinic </Web-ContextPath> <_wab>src/main/resources</_wab> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <supportedProjectTypes> <supportedProjectType>jar</supportedProjectType> <supportedProjectType>bundle</supportedProjectType> <supportedProjectType>war</supportedProjectType> </supportedProjectTypes>
  24. 24. 24 Deployment Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf Deploymentof: Bundles Blueprint files(xml) Features Kar Archives „plain“ jarfiles
  25. 25. 25 Features Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf Bundle A Bundle C Bundle B ConfigA Feature Dependency Feature XML <featurename="com.cloudyle.paasplus.samples.petclinic.feature"version="0.9.0" description="PaaS+ Sample -PetClinic-Deploymentfeature"resolver="(obr)" install="auto"> <details>PetClinicFeature.</details> <configfilefinalname="/etc/com.cloudyle.paasplus.petclinic.cfg"> mvn:com.cloudyle.paasplus.samples/com.cloudyle.paasplus.samples.petclinic.provider/0.9.0/cfg</configfile> <feature>paasplus-persistence-service</feature> <bundlestart-level="75">mvn:com.cloudyle.paasplus.samples/ com.cloudyle.paasplus.samples.petclinic.persistence/0.9.0</bundle> <bundlestart-level="75">mvn:com.cloudyle.paasplus.samples/ com.cloudyle.paasplus.samples.petclinic.api/0.9.0</bundle> </feature>
  26. 26. 26 MavenDeployment Deployvia anyMavenrepository Bundles Features Configurations Add additional repostoorg.ops4j.pax.url.mvn.cfg Installfeaturesorbundles UsefulCommands bundle:install, update, list feature:install, list Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf org.ops4j.pax.url.mvn.repositories= http://nexus.paasplus.com:8081/nexus/content/groups/public/, http://repo1.maven.org/maven2@id=central, repo-add mvn:com.cloudyle.paasplus/com.cloudyle.paasplus.karaf.deployment.services/ LATEST/xml/features; feature:installpaasplus-persistence-service; bundle:installmvn:com.cloudyle.paasplus.samples/ com.cloudyle.paasplus.samples.petclinic.api;
  27. 27. 27 KarafMavenPlugin Generatefeature.xml withprojectdependencies Generatecommanddocumentation Kar packaging Custom Karafdistribution Kar andfeaturepackaging Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf <plugin> <groupId>org.apache.karaf.tooling</groupId> <artifactId>karaf-maven-plugin</artifactId> <version>3.0.2</version> <extensions>true</extensions> </plugin>
  28. 28. 28 Integrated Development Process Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf Develop Debug, Integration Tests mvn install bundle:install, update Manage Feature XML mvn:…/.. repo-add
  29. 29. 29 JMX Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf
  30. 30. 30 Integration Testing AutomatedTestingvia PaxExam JUnittestsrunningin Apache Karafinstance Configureandmanage Karafvia JUnittest Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf @RunWith(PaxExam.class) publicclassServiceProviderITextendsAbstractBaseTest{ @Configuration publicOption[]config(){ returncombine(super.config(),newOption[]{ editConfigurationFileExtend("etc/org.apache.karaf.features.cfg","featuresRepositories", ",mvn:com.cloudyle.paasplus:com.cloudyle.paasplus.karaf.deployment.services:xml:features"), newKarafDistributionConfigurationFileReplacementOption("etc/org.elasticsearch.connection.cfg", newFile("src/test/resources/etc/org.elasticsearch.connection.cfg")), features("mvn:com.cloudyle.paasplus/com.cloudyle.paasplus.karaf.deployment.services/LATEST/xml/features","paasplus-report-service"), vmOption("-Djava.net.preferIPv4Stack=true"),vmOption("-XX:MaxPermSize=256M")});} @Test publicvoiddoTest(){ …
  31. 31. 31 CellarClustering Cluster solution for Apache Karaf Based on Hazelcast Support for different topologies Synchronization of deployments and configurations Cross-Node Event publishing Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf Node Node Node Node Node Node Cluster Manager
  32. 32. 32 PaaS+withKarafsupport CloudylePaaS+allows easy creation of Karafapplications Try out PetClinichttp://devcenter.cloudyle.com/display/public/PAAS/Pet+Clinic+ Tutorial Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf
  33. 33. 33 See youtomorrow: Build bundles in the cloud -How CloudylePaaS+helps creating OSGi applications in the cloud Wednesday, October29, 2014 14:30 to15:05 Seminarräume 1 -3 Eclipsecon Europe 2014 Develop OSGi Applications with Apache Karaf

×