Пример #1
0
def updateApp():
    """
    Flask endpoint for updating an application on Marathon.

    Update the job running the given application(s) on Marathon.  POST body:

        {
            "appOne": {
                "cpus": 0.3,
                "mem": 16,
                "instances": 3
            },
            "appTwo": {
                "cpus": 0.2,
                "mem": 512,
                "instances": 3
            }
        }

    NOTE: The full [Marathon API](https://mesosphere.github.io/marathon/docs/rest-api.html#put-/v2/apps/%7Bappid%7D)
    allows more parameters to be changed, but we limit them for this API.
    """
    newConfig = json.loads(request.data)
    logger.info('Method called with: {0}'.format(newConfig))

    system = ServiceOrchestrator(CONFIG_FILE)
    ok = system.updateApps(newConfig)

    return 'ok'
Пример #2
0
def startServer(configFile):
    """
    Start the Flask server using some environment varils -al etc ables.
    """
    setupServer()
    port = os.environ.get('PORT', 3030)

    system = ServiceOrchestrator(configFile)
    #system = ServiceOrchestrator(CONFIG_FILE)
    system.startHaproxy()

    app.run(host='0.0.0.0', port=port)
Пример #3
0
def marathon():
    """
    Endpoint:
        http://[host]:[port]/marathon

    Takes an HTTP POST from Marathon, and if it is a *status_update_event*
    message, we will rewrite the HAProxy configuration and restart HAProxy.
    """
    logger.info("Marathon Event received...")
    updateEvt = json.loads(request.data)

    if updateEvt.get('eventType') != 'status_update_event':
        return 'not status_update_event'

    print 'IP ADDRESS:', request.remote_addr
    system = ServiceOrchestrator(CONFIG_FILE)
    ok = system.reloadHAProxy(request.remote_addr, updateEvt)

    return str(ok)
Пример #4
0
def refreshConfig ():
    system = ServiceOrchestrator("conf.json")
    tmpConfig =  os.path.join(SKYLR_HOME, 'haproxy.cfg')
    with open(tmpConfig, "w") as output:
        output.write(system.gen ())
    subprocess.call("sudo cp {0} {1}".format(tmpConfig, CONFIG_DESTINATION).split(" "))