Deploy Models

After creating a model, you need to deploy the model onto HDFS and submit a request for one or more instances of the model.

  1. Create a simple sample python model.
    Let's say that you have a model, exposed as a REST microservice called "mock_dga" that takes as an input argument "host" which represents an internet domain name and returns a field called "is_malicious" which is either "malicious" if the domain is thought to be malicious or "legit" if the domain is not thought to be malicious. The following is a very simple example service that thinks that the only legitimate domains are "" and "":
    from flask import Flask
    from flask import request,jsonify
    import socket
    app = Flask(__name__)
    @app.route("/apply", methods=['GET'])
    def predict():
            h = request.args.get('host')
            r = {}
            if h == '' or h == '':
                    r['is_malicious'] = 'legit'
                    r['is_malicious'] = 'malicious'
            return jsonify(r)
    if __name__ == "__main__":
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.bind(('localhost', 0))
            port = sock.getsockname()[1]
            with open("endpoint.dat", "w") as text_file:
                    text_file.write("{\"url\" : \"\"}" % port)
  , host="", port=port)
  2. Store this python model in a directory called /root/mock_dga as and an accompanying shell script called which starts the model:
  3. If you have not already done so, start MaaS:
    $METRON_HOME/bin/ -zk $ZOOKEEPER_HOST:2181
  4. Start one or more instances of the model, calling it "dga" and assigning an amount of memory to each instance:
    Because you have placed the model in the /root/mock_dga directory, enter the following:
    $METRON_HOME/bin/ -zk $ZOOKEEPER_HOST:2181 -lmp /root/mock_dga -hmp /user/root/models -mo ADD -m 512 -n dga -v 1.0 -ni 1
    -h, --h

    A list of functions for

    -hmp, --hdfs_model_path <arg>

    Model path (HDFS)

    -lmp, --local_model_path <arg>

    Model path (local)

    -m, --memory <arg>

    Memory for container

    -mo, --mode <arg>


    -n, --name <arg>

    Model name

    -ni, --num_instances <arg>

    Number of model instances

    -v, --version <arg>

    Model version

    -zq, --zk_quorum <arg>

    ZooKeeper quorum

    -zr, --zk_root <arg>

    ZooKeeper root