From fd345f236aef6c6e347a01bcdceb5be1bd8c0a63 Mon Sep 17 00:00:00 2001
From: Sergey Yakubov <sergey.yakubov@desy.de>
Date: Fri, 13 Jul 2018 17:43:58 +0200
Subject: [PATCH] revert to single mongo instance

---
 deploy/nomad_jobs/asapo-brokers.nmd.in       |  46 ----
 deploy/nomad_jobs/asapo-mongo-sharded.nmd.in | 237 -------------------
 deploy/nomad_jobs/asapo-receivers.nmd.in     |  46 ----
 deploy/nomad_jobs/asapo-test.nomad           |  90 +++++++
 deploy/nomad_jobs/broker.json.tpl            |   2 +-
 deploy/nomad_jobs/init_mongo.sh              |  20 --
 deploy/nomad_jobs/mongo-configsrv.yaml.tpl   |   7 -
 deploy/nomad_jobs/mongo-mongos.yaml.tpl      |   5 -
 deploy/nomad_jobs/mongo-shardsrv.yaml.tpl    |   5 -
 deploy/nomad_jobs/receiver.json.tpl          |   2 +-
 deploy/nomad_jobs/start_asapo.sh             |   7 +-
 deploy/nomad_jobs/stop_asapo.sh              |   2 +-
 12 files changed, 94 insertions(+), 375 deletions(-)
 delete mode 100644 deploy/nomad_jobs/asapo-mongo-sharded.nmd.in
 create mode 100644 deploy/nomad_jobs/asapo-test.nomad
 delete mode 100644 deploy/nomad_jobs/init_mongo.sh
 delete mode 100644 deploy/nomad_jobs/mongo-configsrv.yaml.tpl
 delete mode 100644 deploy/nomad_jobs/mongo-mongos.yaml.tpl
 delete mode 100644 deploy/nomad_jobs/mongo-shardsrv.yaml.tpl

diff --git a/deploy/nomad_jobs/asapo-brokers.nmd.in b/deploy/nomad_jobs/asapo-brokers.nmd.in
index bbc0ced08..e60118437 100644
--- a/deploy/nomad_jobs/asapo-brokers.nmd.in
+++ b/deploy/nomad_jobs/asapo-brokers.nmd.in
@@ -72,51 +72,5 @@ job "asapo-brokers" {
         change_mode   = "restart"
       }
    } #task brokers
-
-    task "mongos-broker" {
-      driver = "docker"
-
-      config {
-        network_mode = "host"
-        image = "mongo:4.0.0"
-        dns_servers = ["127.0.0.1"]
-        command = "mongos"
-        args = ["--config","local/mongo-mongos.yaml"]
-
-      }
-
-      resources {
-        network {
-          port "mongos" {
-          static = 27016
-          }
-        }
-      }
-
-      service {
-        name = "mongos-broker"
-        check {
-          type     = "script"
-          name     = "mongos-broker-alive"
-          command  = "mongo"
-          args     = ["--host","${attr.unique.network.ip-address}","--port","27016","--eval","db.version()"]
-          interval = "10s"
-          timeout  = "5s"
-        }
-        check_restart {
-          limit = 2
-          grace = "90s"
-          ignore_warnings = false
-        }
-      }
-      template {
-         source        = "@NOMAD_INSTALL@/mongo-mongos.yaml.tpl"
-         destination   = "local/mongo-mongos.yaml"
-         change_mode   = "restart"
-      }
-    } # task mongos
-
-
-
   }
 }
diff --git a/deploy/nomad_jobs/asapo-mongo-sharded.nmd.in b/deploy/nomad_jobs/asapo-mongo-sharded.nmd.in
deleted file mode 100644
index 137484ad0..000000000
--- a/deploy/nomad_jobs/asapo-mongo-sharded.nmd.in
+++ /dev/null
@@ -1,237 +0,0 @@
-job "asapo-mongo-sharded" {
-  datacenters = ["dc1"]
-
-  update {
-    max_parallel = 1
-    min_healthy_time = "10s"
-    healthy_deadline = "3m"
-    auto_revert = false
-  }
-
-  group "mongo-config-srv" {
-    count = 1
-
-    restart {
-      attempts = 2
-      interval = "3m"
-      delay = "15s"
-      mode = "fail"
-    }
-
-    task "mongo-config-srv" {
-      driver = "docker"
-
-      config {
-        network_mode = "host"
-        image = "mongo:4.0.0"
-        dns_servers = ["127.0.0.1"]
-        volumes = ["/${meta.shared_storage}/mongodb_config:/data/configdb"]
-        command = "mongod"
-        args = ["--config","local/mongo-configsrv.yaml"]
-
-      }
-
-      resources {
-        network {
-          port "config" {
-          static = 27010
-          }
-        }
-      }
-
-      service {
-        port = "config"
-        name = "mongo-config-srv"
-        check {
-          type     = "script"
-          name     = "alive"
-          command  = "mongo"
-          args     = ["--host","${attr.unique.network.ip-address}","--port","27010","--eval","db.version()"]
-          interval = "10s"
-          timeout  = "5s"
-        }
-        check_restart {
-          limit = 2
-          grace = "90s"
-          ignore_warnings = false
-        }
-      }
-
-      template {
-         source        = "@NOMAD_INSTALL@/mongo-configsrv.yaml.tpl"
-         destination   = "local/mongo-configsrv.yaml"
-         change_mode   = "restart"
-      }
-
-
-    }
-  } # config server group
-  group "mongo-shard1" {
-    count = 1
-
-    restart {
-      attempts = 2
-      interval = "3m"
-      delay = "15s"
-      mode = "fail"
-    }
-
-    task "mongo-shard1" {
-      driver = "docker"
-
-      config {
-        network_mode = "host"
-        image = "mongo:4.0.0"
-        dns_servers = ["127.0.0.1"]
-        volumes = ["/${meta.shared_storage}/mongodb_shard1:/data/db"]
-        command = "mongod"
-        args = ["--config","local/mongo-shardsrv.yaml"]
-
-      }
-
-      resources {
-        network {
-          port "shard" {
-          static = 27011
-          }
-        }
-      }
-
-      service {
-        port = "shard"
-        name = "mongo-shard1"
-        check {
-          type     = "script"
-          name     = "alive"
-          command  = "mongo"
-          args     = ["--host","${attr.unique.network.ip-address}","--port","27011","--eval","db.version()"]
-          interval = "10s"
-          timeout  = "5s"
-        }
-        check_restart {
-          limit = 2
-          grace = "90s"
-          ignore_warnings = false
-        }
-      }
-      template {
-         source        = "@NOMAD_INSTALL@/mongo-shardsrv.yaml.tpl"
-         destination   = "local/mongo-shardsrv.yaml"
-         change_mode   = "restart"
-      }
-    }
-  } # shard1 group
-
-    group "mongo-shard2" {
-      count = 1
-
-      restart {
-        attempts = 2
-        interval = "3m"
-        delay = "15s"
-        mode = "fail"
-      }
-
-      task "mongo-shard2" {
-        driver = "docker"
-
-        config {
-          network_mode = "host"
-          image = "mongo:4.0.0"
-          dns_servers = ["127.0.0.1"]
-          volumes = ["/${meta.shared_storage}/mongodb_shard2:/data/db"]
-          command = "mongod"
-          args = ["--config","local/mongo-shardsrv.yaml"]
-
-        }
-
-        resources {
-          network {
-            port "shard" {
-            static = 27012
-            }
-          }
-        }
-
-        service {
-          port = "shard"
-          name = "mongo-shard2"
-          check {
-            type     = "script"
-            name     = "alive"
-            command  = "mongo"
-            args     = ["--host","${attr.unique.network.ip-address}","--port","27012","--eval","db.version()"]
-            interval = "10s"
-            timeout  = "5s"
-          }
-          check_restart {
-            limit = 2
-            grace = "90s"
-            ignore_warnings = false
-          }
-        }
-        template {
-           source        = "@NOMAD_INSTALL@/mongo-shardsrv.yaml.tpl"
-           destination   = "local/mongo-shardsrv.yaml"
-           change_mode   = "restart"
-        }
-      }
-    } # shard2 group
-
-
-    group "mongo-shard3" {
-      count = 1
-
-      restart {
-        attempts = 2
-        interval = "3m"
-        delay = "15s"
-        mode = "fail"
-      }
-
-      task "mongo-shard3" {
-        driver = "docker"
-
-        config {
-          network_mode = "host"
-          image = "mongo:4.0.0"
-          dns_servers = ["127.0.0.1"]
-          volumes = ["/${meta.shared_storage}/mongodb_shard3:/data/db"]
-          command = "mongod"
-          args = ["--config","local/mongo-shardsrv.yaml"]
-
-        }
-
-        resources {
-          network {
-            port "shard" {
-            static = 27013
-            }
-          }
-        }
-
-        service {
-          port = "shard"
-          name = "mongo-shard3"
-          check {
-            type     = "script"
-            name     = "alive"
-            command  = "mongo"
-            args     = ["--host","${attr.unique.network.ip-address}","--port","27013","--eval","db.version()"]
-            interval = "10s"
-            timeout  = "5s"
-          }
-          check_restart {
-            limit = 2
-            grace = "90s"
-            ignore_warnings = false
-          }
-        }
-        template {
-           source        = "@NOMAD_INSTALL@/mongo-shardsrv.yaml.tpl"
-           destination   = "local/mongo-shardsrv.yaml"
-           change_mode   = "restart"
-        }
-      }
-    } # shard3 group
-}
diff --git a/deploy/nomad_jobs/asapo-receivers.nmd.in b/deploy/nomad_jobs/asapo-receivers.nmd.in
index 709577670..ef453031a 100644
--- a/deploy/nomad_jobs/asapo-receivers.nmd.in
+++ b/deploy/nomad_jobs/asapo-receivers.nmd.in
@@ -65,52 +65,6 @@ job "asapo-receivers" {
          change_mode   = "restart"
       }
    } #task receivers
-
-    task "mongos-receiver" {
-      driver = "docker"
-
-      config {
-        network_mode = "host"
-        image = "mongo:4.0.0"
-        dns_servers = ["127.0.0.1"]
-        command = "mongos"
-        args = ["--config","local/mongo-mongos.yaml"]
-
-      }
-
-      resources {
-        network {
-          port "mongos" {
-          static = 27015
-          }
-        }
-      }
-
-      service {
-        name = "mongos-receiver"
-        check {
-          type     = "script"
-          name     = "mongos-receiver-alive"
-          command  = "mongo"
-          args     = ["--host","${attr.unique.network.ip-address}","--port","27015","--eval","db.version()"]
-          interval = "10s"
-          timeout  = "5s"
-        }
-        check_restart {
-          limit = 2
-          grace = "90s"
-          ignore_warnings = false
-        }
-      }
-      template {
-         source        = "@NOMAD_INSTALL@/mongo-mongos.yaml.tpl"
-         destination   = "local/mongo-mongos.yaml"
-         change_mode   = "restart"
-      }
-    } # task mongos
-
-
-
   }
 }
 
diff --git a/deploy/nomad_jobs/asapo-test.nomad b/deploy/nomad_jobs/asapo-test.nomad
new file mode 100644
index 000000000..6974aa1b2
--- /dev/null
+++ b/deploy/nomad_jobs/asapo-test.nomad
@@ -0,0 +1,90 @@
+job "asapo-test" {
+  datacenters = ["dc1"]
+
+  type = "batch"
+
+  group "windows-test" {
+
+    constraint {
+      attribute = "${attr.kernel.name}"
+      value = "windows"
+    }
+
+    count = 1
+    task "producer" {
+      driver = "raw_exec"
+
+      config {
+        command = "local/dummy-data-producer.exe"
+        args = [
+          "psana002:8400",
+          "asapo_test1",
+          "5000",
+          "10000",
+          "8",
+          "0",
+          "100"]
+      }
+
+      artifact {
+        source = "https://stash.desy.de/rest/git-lfs/storage/ASAPO/asapo-bin/d42330e599f0197e8acc17fedb10c8ae897b57def38b207f1a58f14c8a524100?response-content-disposition=attachment%253B%2520filename%253D%2522dummy-data-producer.exe%2522%253B%2520filename*%253Dutf-8%27%27dummy-data-producer.exe"
+        mode = "file"
+        destination = "local/dummy-data-producer.exe"
+
+      }
+
+      #      resources {
+      #        cpu = 5000
+      #        memory = 128
+      #        network {
+      #          mbits = 10000
+      #        }
+    }
+
+  } #windows
+
+  group "linux-test" {
+
+    constraint {
+      attribute = "${attr.kernel.name}"
+      value = "linux"
+    }
+
+    constraint {
+      attribute = "${meta.location}"
+      value = "petra3"
+    }
+
+    count = 1
+
+    task "producer" {
+      driver = "raw_exec"
+
+      config {
+        command = "local/dummy-data-producer"
+        args = [
+          "psana002:8400",
+          "asapo_test2",
+          "5000",
+          "10000",
+          "8",
+          "0",
+          "100"]
+      }
+
+      artifact {
+        source = "https://stash.desy.de/projects/ASAPO/repos/asapo-bin/raw/dummy-data-producer?at=refs%2Fheads%2Ffeature_ha"
+      }
+
+      #      resources {
+      #        cpu = 5000
+      #        memory = 128
+      #        network {
+      #          mbits = 10000
+      #        }
+      #      }
+
+    }
+
+  } #linux
+}
\ No newline at end of file
diff --git a/deploy/nomad_jobs/broker.json.tpl b/deploy/nomad_jobs/broker.json.tpl
index db6eb18f8..fe73cff79 100644
--- a/deploy/nomad_jobs/broker.json.tpl
+++ b/deploy/nomad_jobs/broker.json.tpl
@@ -1,5 +1,5 @@
 {
-  "BrokerDbAddress":"{{ env "attr.unique.network.ip-address" }}:27016",
+  "BrokerDbAddress":"mongo.service.asapo:27017",
   "MonitorDbAddress":"influxdb.service.asapo:8086",
   "MonitorDbName": "asapo_brokers",
   "port":{{ env "NOMAD_PORT_broker" }},
diff --git a/deploy/nomad_jobs/init_mongo.sh b/deploy/nomad_jobs/init_mongo.sh
deleted file mode 100644
index 47303b629..000000000
--- a/deploy/nomad_jobs/init_mongo.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/env bash
-
-mongoaddr=`dig +short @127.0.0.1 mongo-config-srv.service.asapo | head -1`
-cont=$(ssh $mongoaddr bash -c "'docker ps | grep mongo-config-srv'")
-image=`echo "${cont##* }"`
-ssh $mongoaddr docker exec $image bash -c "'echo \"rs.initiate()\" | mongo --host $mongoaddr --port 27010'"
-
-
-mongoaddr=`dig +short @127.0.0.1 mongos-broker.service.asapo | head -1`
-cont=$(ssh $mongoaddr bash -c "'docker ps | grep mongos'")
-image=`echo "${cont##* }"`
-
-shardaddr1=`dig +short @127.0.0.1 mongo-shard1.service.asapo | head -1`
-shardaddr2=`dig +short @127.0.0.1 mongo-shard2.service.asapo | head -1`
-shardaddr3=`dig +short @127.0.0.1 mongo-shard3.service.asapo | head -1`
-
-
-ssh $mongoaddr docker exec $image bash -c "'echo \"sh.addShard('\"'$shardaddr1:27011'\"')\" | mongo --host $mongoaddr --port 27016'"
-ssh $mongoaddr docker exec $image bash -c "'echo \"sh.addShard('\"'$shardaddr2:27012'\"')\" | mongo --host $mongoaddr --port 27016 '"
-ssh $mongoaddr docker exec $image bash -c "'echo \"sh.addShard('\"'$shardaddr3:27013'\"')\" | mongo --host $mongoaddr --port 27016 '"
diff --git a/deploy/nomad_jobs/mongo-configsrv.yaml.tpl b/deploy/nomad_jobs/mongo-configsrv.yaml.tpl
deleted file mode 100644
index 4f7caf9c1..000000000
--- a/deploy/nomad_jobs/mongo-configsrv.yaml.tpl
+++ /dev/null
@@ -1,7 +0,0 @@
-sharding:
-  clusterRole: configsvr
-replication:
-  replSetName: config
-net:
-  bindIp: {{ env "attr.unique.network.ip-address" }}
-  port: {{ env "NOMAD_PORT_config" }}
diff --git a/deploy/nomad_jobs/mongo-mongos.yaml.tpl b/deploy/nomad_jobs/mongo-mongos.yaml.tpl
deleted file mode 100644
index a950ec0c2..000000000
--- a/deploy/nomad_jobs/mongo-mongos.yaml.tpl
+++ /dev/null
@@ -1,5 +0,0 @@
-sharding:
-  configDB: "config/mongo-config-srv.service.asapo:27010"
-net:
-  bindIp: {{ env "attr.unique.network.ip-address" }}
-  port: {{ env "NOMAD_PORT_mongos" }}
diff --git a/deploy/nomad_jobs/mongo-shardsrv.yaml.tpl b/deploy/nomad_jobs/mongo-shardsrv.yaml.tpl
deleted file mode 100644
index fb54ad434..000000000
--- a/deploy/nomad_jobs/mongo-shardsrv.yaml.tpl
+++ /dev/null
@@ -1,5 +0,0 @@
-sharding:
-  clusterRole: shardsvr
-net:
-  bindIp: {{ env "attr.unique.network.ip-address" }}
-  port: {{ env "NOMAD_PORT_shard" }}
diff --git a/deploy/nomad_jobs/receiver.json.tpl b/deploy/nomad_jobs/receiver.json.tpl
index 7c1be0567..b4cabe708 100644
--- a/deploy/nomad_jobs/receiver.json.tpl
+++ b/deploy/nomad_jobs/receiver.json.tpl
@@ -1,7 +1,7 @@
 {
   "MonitorDbAddress":"influxdb.service.asapo:8086",
   "MonitorDbName": "asapo_receivers",
-  "BrokerDbAddress":"{{ env "attr.unique.network.ip-address" }}:27015",
+  "BrokerDbAddress":"mongo.service.asapo:27017",
   "AuthorizationServer": "asapo-authorizer.service.asapo:5007",
   "AuthorizationInterval": 10000,
   "ListenPort": {{ env "NOMAD_PORT_recv" }},
diff --git a/deploy/nomad_jobs/start_asapo.sh b/deploy/nomad_jobs/start_asapo.sh
index bcca591b2..59a12f2b1 100644
--- a/deploy/nomad_jobs/start_asapo.sh
+++ b/deploy/nomad_jobs/start_asapo.sh
@@ -2,12 +2,7 @@
 
 nomad run asapo-nginx.nmd
 nomad run asapo-logging.nmd
-nomad run asapo-mongo-sharded.nmd
-
-#if mongo replica sets and shards not created yet might be necessary to wait here, than start mongos (run init_mongo.sh first time to create replicas,
-#then start mongos (e.g. in asapo-brokers job), then run init_mongo.sh once more
-
-
+nomad run asapo-mongo.nmd
 nomad run asapo-brokers.nmd
 nomad run asapo-services.nmd
 nomad run asapo-perfmetrics.nmd
diff --git a/deploy/nomad_jobs/stop_asapo.sh b/deploy/nomad_jobs/stop_asapo.sh
index 07b8f2ebe..9ede6dd7d 100644
--- a/deploy/nomad_jobs/stop_asapo.sh
+++ b/deploy/nomad_jobs/stop_asapo.sh
@@ -2,7 +2,7 @@
 
 nomad stop asapo-nginx
 nomad stop asapo-logging
-nomad stop asapo-mongo-sharded
+nomad stop asapo-mongo
 nomad stop asapo-services
 nomad stop asapo-perfmetrics
 nomad stop asapo-receivers
-- 
GitLab