2

Assume i am creating a charm which is having a java class in it say Helloworld.java. Now I want to compile and run this class by using jdk6 from a different charm.

Can somebody explain me what all changes I need to do. Basically I am struggling in relationship creation hence want to get it clear.

In my original implementation, I have a deb package in my charm, this deb package needs jdk6 and hadoop preinstalled(install script checks the availability checking JAVA_HOME and HADOOP_HOME in the PATH).

I am totally stuck on adding the relationship(in metadata.yaml and -relation-). I am not clear at all that how can I use java and hadoop from different charms.

2

1 Answer 1

2

If you want to use the jdk installed via another charm you will need to create a subordinate charm (https://jujucharms.com/docs/2.0/authors-subordinate-services). A subordinate charm operates in the same instance (container) as the charm he is subordinate for.

The metadata.yaml would look somewhat like this:

name: 
summary: 
maintainer: 
description: 
tags: [misc]
subordinate: true
requires:
  interface-name:
    interface: interface-name
series: ['trusty']

The following interfaces can be used for Java JDK and Hadoop:


Small example: Assuming you want the jdk from another charm I'll use the kafka charm as an example and use the jdk it installs.

metadata.yaml

name: layer-jdk-example
summary: <Fill in summary here>
maintainer: maintainer
description: |
  <Multi-line description here>
tags:
  - misc
subordinate: true
requires:
  kafka:
    interface: kafka
    scope: container
series: ['trusty']

layer.yaml

includes: ['layer:basic', 'interface:kafka']

reactive/layer-jdk-example.py

import os
from charms.reactive import when, when_not, set_state


@when_not('layer-jdk-example.installed')
def install_layer_jdk_example():    
    os.getenv("JAVA_HOME")
    # locate / download java file and compile
    # do stuff ... 
    set_state('layer-jdk-example.installed')

Build, deploy and add a relation to kafka. Hope this helps.

13
  • I know it sounds dumb but I couldn't write this. @user3499430, if you get time and can do me a favour then can you help me out personally? otherwise my charm will remain single on this valentine :) Thanks anyways.
    – ASR
    Feb 14, 2017 at 11:10
  • Are you creating a layered charm? Feb 14, 2017 at 12:19
  • Yes i am trying to create a layered one. I am actually referring apache-spark's charm, but that one is too complicated.
    – ASR
    Feb 14, 2017 at 12:23
  • without layer design will also work for me. I have created an empty public github repo @ link
    – ASR
    Feb 14, 2017 at 12:40
  • Added a small example, I don't have time for more atm. Will check on it again later. Feb 14, 2017 at 12:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .