<commit_before>haibu = require('haibu-api')
HttpClient = require("request-json").JsonClient


# Class to facilitate communications with Haibu, the application server
# and the cozy proxy to manage application installation.
class exports.AppManager

    # Setup haibu client and proxyClient.
    constructor: ->
        @proxyClient = new HttpClient "http://localhost:9104/"
        @client = haibu.createClient(
            host: '127.0.0.1'
            port: 9002
        ).drone

    # Ask to proxy to rebuild his routes.
    # Because route commands are public, we can't allow that someone add or
    # remove routes.
    resetProxy: (callback) ->
        console.info "Request for proxy reseting..."
        @proxyClient.get "routes/reset", (error, response, body) ->
            if error
                console.log error.message
                callback error
            else if response.statusCode != 200
                callback new Error "Something went wrong on proxy side when \
reseting routes"
            else
                console.info "Proxy successfully reseted."
                callback null


    # 1. Send a install request to haibu server ("start" request).
    # 2. Send a request to proxy to add a new route
    installApp: (app, callback) ->
        console.info "Request haibu for spawning #{app.name}..."

        console.log "haibu descriptor : "+JSON.stringify(app.getHaibuDescriptor())
        
        @client.start app.getHaibuDescriptor(), (err, result) =>
            if err
                console.log "Error spawning app: #{app.name}"
                console.log err.message
                console.log err.stack
                callback(err)
            else
                console.info "Successfully spawned app: #{app.name}"
                console.info "Update proxy..."
                callback null, result

    # Remove and reinstall app inside Haibu.
    updateApp: (app, callback) ->
        railway.logger.write "Request haibu for updating #{app.name}..."
        
        railway.logger.write "Step 1: remove #{app.name}..."
        @client.clean app.getHaibuDescriptor(), (err, result) =>
            if err
                console.log "Error cleaning app: #{app.name}"
                console.log err.message<commit_msg>info instead of log and use #{}<commit_after>haibu = require('haibu-api')
HttpClient = require("request-json").JsonClient


# Class to facilitate communications with Haibu, the application server
# and the cozy proxy to manage application installation.
class exports.AppManager

    # Setup haibu client and proxyClient.
    constructor: ->
        @proxyClient = new HttpClient "http://localhost:9104/"
        @client = haibu.createClient(
            host: '127.0.0.1'
            port: 9002
        ).drone

    # Ask to proxy to rebuild his routes.
    # Because route commands are public, we can't allow that someone add or
    # remove routes.
    resetProxy: (callback) ->
        console.info "Request for proxy reseting..."
        @proxyClient.get "routes/reset", (error, response, body) ->
            if error
                console.log error.message
                callback error
            else if response.statusCode != 200
                callback new Error "Something went wrong on proxy side when \
reseting routes"
            else
                console.info "Proxy successfully reseted."
                callback null


    # 1. Send a install request to haibu server ("start" request).
    # 2. Send a request to proxy to add a new route
    installApp: (app, callback) ->
        console.info "Request haibu for spawning #{app.name}..."
        console.info "haibu descriptor : #{JSON.stringify(app.getHaibuDescriptor())}"
        
        @client.start app.getHaibuDescriptor(), (err, result) =>
            if err
                console.log "Error spawning app: #{app.name}"
                console.log err.message
                console.log err.stack
                callback(err)
            else
                console.info "Successfully spawned app: #{app.name}"
                console.info "Update proxy..."
                callback null, result

    # Remove and reinstall app inside Haibu.
    updateApp: (app, callback) ->
        railway.logger.write "Request haibu for updating #{app.name}..."
        
        railway.logger.write "Step 1: remove #{app.name}..."
        @client.clean app.getHaibuDescriptor(), (err, result) =>
            if err
                console.log "Error cleaning app: #{app.name}"
                console.log err.message
{'fraction_non_alphanumeric': 0.09658344283837056, 'fraction_numerical': 0.008760402978537012, 'mean_word_length': 1.938867438867439, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5150902', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1155, 'n_words': 399}