Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for using dependency information in configure #10

Open
ghost opened this issue May 12, 2015 · 3 comments
Open

Example for using dependency information in configure #10

ghost opened this issue May 12, 2015 · 3 comments

Comments

@ghost
Copy link

ghost commented May 12, 2015

Can you post an example for how to use the dependency information from the cluster in the configure(self, cluster) method?

I know I can do something like this.

def configure(self, cluster):
    pod = cluster.pods[cluster.key]
    return "java -jar $ARTIFACT_TARGET_PATH", { 'SEED_NODE': pod['ip'] }

Does the dependencies dict work the same way?

def configure(self, cluster):
    contactPoints = []
    for k in cluster.dependencies:
        if k == 'cassandra':
            contactPoints.append(cluster.dependencies[k]['ip'])
    contactPointsStr = "[" + ",".join(contactPoints) + "]"
    return "java -jar $ARTIFACT_TARGET_PATH", { 'CONTACT_POINTS': contactPointsStr }
@opaugam
Copy link

opaugam commented May 12, 2015

I see you are doing some real ochopoding there :)

The dependencies are simply defined in the pod script's model. It's an array of identifiers. Each identifier maps to a cluster assumed to be running in the same namespace. Let's take an example (my internal Kafka image I use for my stuff at Autodesk) ->

class Model(Reactive):
    damper = 15.0
    grace = 300.0
    probe_every = 30.0
    sequential = True
    depends_on = ['zookeeper']

That's it. If you run the Kafka container in namespace 'foo', it will only ever configure when it can find at least one container from namespace 'foo' called 'zookeeper'.

You can use the grep() helper on that Cluster wrapper to get you a connection string for a given port. So for instance if I was to do grep("zookeeper", 2181) in my example, i would get a bunch of IP: pointing to my zookeeper containers.

look at https://github.com/autodesk-cloud/ochopod/blob/master/sdk/ochopod/models/piped.py line 50 to see how I use the dependencies dict.

@opaugam
Copy link

opaugam commented May 12, 2015

another example .. this is my HAProxy pod script. In my case HAProxy is configuring itself against a cluster of Play! framework REST endpoint called "api" (which listens on TCP 9000).

class Model(Reactive):

    depends_on = ['api']

class Strategy(Piped):

    cwd = '/opt/haproxy'

    def can_configure(self, cluster):

        #
        # - we need at least one downstream url to redirect traffic to
        #
        assert cluster.grep('api', 9000), 'need 1+ downstream listener'

    def configure(self, cluster):

        #
        # - grep our listeners
        # - render into our 'local' backend directive (which is a standalone file)
        #
        urls = cluster.grep(api,9000).split(',')
        env = Environment(loader=FileSystemLoader(join(dirname(__file__), 'templates')))
        logger.info('%d downstream urls ->\n - %s' % (len(urls), '\n - '.join(urls)))
        mappings = \
            {
                'listeners': {'listener-%d' % index: endpoint for index, endpoint in enumerate(urls)}
            }

@ghost
Copy link
Author

ghost commented May 12, 2015

Looks great. I'll give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant