diff options
| -rw-r--r-- | opendc-common/src/main/kotlin/org/opendc/common/utils/HTTPClient.kt | 17 | ||||
| -rw-r--r-- | opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/SmartScheduler.kt | 7 | ||||
| -rw-r--r-- | opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentCli.kt | 2 | ||||
| -rw-r--r-- | python_scripts/__init__.py | 0 | ||||
| -rw-r--r-- | python_scripts/__main__.py | 19 | ||||
| -rw-r--r-- | python_scripts/__pycache__/redis.cpython-314.pyc | bin | 0 -> 932 bytes | |||
| -rw-r--r-- | python_scripts/monitor.py | 24 | ||||
| -rw-r--r-- | shell_scripts/useful_commands.sh | 4 |
8 files changed, 66 insertions, 7 deletions
diff --git a/opendc-common/src/main/kotlin/org/opendc/common/utils/HTTPClient.kt b/opendc-common/src/main/kotlin/org/opendc/common/utils/HTTPClient.kt index fc5bc57b..f8e5e120 100644 --- a/opendc-common/src/main/kotlin/org/opendc/common/utils/HTTPClient.kt +++ b/opendc-common/src/main/kotlin/org/opendc/common/utils/HTTPClient.kt @@ -26,7 +26,16 @@ public class HTTPClient private constructor() { } } - // TODO: this class must send the experiment JSON file to the digital twin + public fun checkForInsights(){ + val request = HttpRequest.newBuilder() + .uri(URI.create("http://localhost:1234/check")) + .header("Content-type", "text/plain") + .GET() + .build() + val response = client?.send(request, ofString()) + check(response?.statusCode() == 200) + } + public fun sendExperiment(experiment: File) { val input = experiment.inputStream() val charArray = CharArray(experiment.length().toInt()) @@ -35,12 +44,12 @@ public class HTTPClient private constructor() { isr.read(charArray) val request = HttpRequest.newBuilder() - .uri(URI.create("http://localhost:8080/assets")) + .uri(URI.create("http://localhost:1234/assets")) .header("Content-type", "application/json") - // TODO: this is obviously wrong, find an efficient way to send JSON over network + // TODO(this is obviously wrong, find an efficient way to send JSON over network) .POST(HttpRequest.BodyPublishers.ofString(String(charArray))) .build() val response = client?.send(request, ofString()) check(response?.statusCode() == 200) } -}
\ No newline at end of file +} diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/SmartScheduler.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/SmartScheduler.kt index 7a540e86..cda4bec1 100644 --- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/SmartScheduler.kt +++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/SmartScheduler.kt @@ -1,6 +1,7 @@ package org.opendc.compute.simulator.scheduler +import org.opendc.common.utils.HTTPClient import org.opendc.compute.simulator.scheduler.filters.HostFilter import org.opendc.compute.simulator.service.HostView import org.opendc.compute.simulator.service.ServiceTask @@ -22,7 +23,7 @@ public class SmartScheduler : ComputeScheduler { private val hostsQueue = List(100, { mutableListOf<HostView>() }) private var minAvailableHost = 0 private var numHosts = 0 - + private val client = HTTPClient.getInstance() // Unlucky Hosts for WhatsApp //private var unluckyHosts = listOf("H01","H02-109","H02-229","H02-107","H02-227","H02-105","H02-226","H02-103","H02-101","H02-222","H02-221","H02-220","H02-213","H02-212","H02-210","H02-208","H02-207","H02-206","H02-204","H02-203","H02-202","H01-181","H01-184","H01-185","H01-186","H01-189","H01-170","H01-174","H01-175","H01-178","H01-179","H01-169","H01-164","H01-166","H01-167","H01-168","H02-197","H02-196","H02-195","H02-194","H01-270","H02-193","H01-271","H02-192","H01-152","H02-190","H01-275","H01-155","H01-157"," H01-91"," H01-94"," H01-84"," H02-52"," H02-54"," H01-87"," H02-55"," H01-88"," H01-89"," H02-57"," H02-58"," H02-59"," H02-70"," H01-95"," H02-63"," H01-96"," H02-64"," H02-65"," H01-98"," H02-66"," H01-99"," H02-67"," H02-69"," H02-83"," H02-74"," H02-76"," H02-78"," H02-90"," H02-91","H01-192","H01-193","H01-195"," H02-87"," H02-89","H01-103","H01-224","H01-105","H01-226","H01-106","H01-227","H01-228"," H01-50","H02-148","H02-147"," H01-48"," H02-16"," H02-17","H02-144","H02-265"," H02-18","H02-264","H02-141","H02-262","H02-140","H02-261","H02-260"," H01-42"," H02-10"," H01-43"," H02-12"," H01-45","H01-221"," H02-13"," H01-46","H01-101","H01-222"," H01-47","H01-102","H01-223"," H02-15","H01-213","H01-214","H01-215","H01-218","H01-219","H02-139","H02-138","H02-135","H02-256"," H01-59"," H02-27","H02-134","H02-133","H02-254","H02-253","H02-130","H02-250"," H01-53"," H02-21"," H01-54"," H02-22"," H01-55"," H01-56","H01-210","H01-211"," H02-25","H01-202","H01-203","H01-204","H01-206"," H01-70","H01-207"," H01-72","H01-209","H02-129","H02-248","H02-126","H02-246","H02-245"," H02-38","H02-122","H02-121","H02-242","H02-241"," H01-62"," H02-30"," H01-64"," H01-65"," H01-66"," H02-35","H01-200"," H02-36","H01-201"," H02-0"," H02-1"," H01-80"," H02-50"," H01-83"," H02-51","H02-118","H02-239","H02-117","H02-238","H02-237","H02-115","H02-113"," H02-49","H02-112","H02-233","H02-111","H02-231"," H02-41"," H01-75"," H02-43"," H02-9"," H02-4"," H02-45"," H02-46"," H01-79","H01-147","H01-268","H01-149","H02-189","H02-186","H02-185","H02-184","H02-183","H02-182","H01-260","H01-140","H02-180","H01-141","H01-262","H01-263","H01-264","H01-144","H01-145","H01-146","H01-267","H01-136","H01-257"," H01-3"," H01-2"," H01-17","H02-176","H02-175","H02-173","H02-172"," H01-9","H02-170"," H01-8","H01-250","H01-130","H01-251","H01-252"," H01-5"," H01-11"," H01-12"," H01-13"," H01-6","H01-135","H01-246","H01-126","H01-127","H01-129","H02-169"," H01-27","H02-165","H02-162","H02-161","H02-160","H01-240","H01-122"," H01-24","H01-124","H01-114","H01-236","H01-117","H01-238","H01-239","H01-119","H02-158","H02-157"," H01-39","H02-275","H02-274","H02-151","H02-150","H02-270"," H01-31"," H01-33","H01-110"," H01-34","H01-111","H01-232","H01-233"," H01-36","H01-113") @@ -31,7 +32,7 @@ public class SmartScheduler : ComputeScheduler { //private var unluckyHosts = listOf("H01-44","H01-66","H01-73","H01-74","H01-85","H01-86","H01-89","H01-10","H01-98","H01-13","H01-39") // Unlucky Hosts for Twitter - //private var unluckyHosts = listOf("H01-180","H01-181","H01-182","H01-184","H01-185","H01-186","H01-188","H01-171","H01-173","H01-176","H01-177","H01-178","H01-179","H01-169"," H01","H01-162","H01-163","H01-164","H01-165","H01-166","H01-168","H01-158","H01-270","H01-150","H01-271","H01-272","H01-273","H01-274","H01-154","H01-155","H01-156","H01-157"," H01-90"," H01-91"," H01-92"," H01-93"," H01-88"," H01-89"," H01-95"," H01-96"," H01-99","H01-190","H01-191","H01-192","H01-193","H01-196","H01-197","H01-198","H01-103","H01-224","H01-225","H01-106","H01-228","H01-108"," H01-50"," H01-40"," H01-42"," H01-43"," H01-44"," H01-45","H01-100","H01-222","H01-102","H01-223","H01-214","H01-215","H01-216","H01-217","H01-218"," H01-60"," H01-59"," H01-51"," H01-52"," H01-53"," H01-56","H01-210"," H01-57","H01-211","H01-212","H01-202","H01-204","H01-205","H01-206"," H01-70"," H01-71"," H01-72","H01-209"," H01-63"," H01-64"," H01-80"," H01-82"," H01-73"," H01-76"," H01-77","H01-268","H01-269","H01-149","H01-260","H01-140","H01-262","H01-263","H01-143","H01-144","H01-265","H01-145","H01-146","H01-267"," H01-1","H01-136","H01-257","H01-137","H01-258"," H01-3","H01-139"," H01-17"," H01-18"," H01-9"," H01-8","H01-130","H01-251","H01-252"," H01-4"," H01-12","H01-133","H01-254"," H01-7"," H01-14","H01-135","H01-256","H01-126"," H01-26"," H01-27"," H01-28"," H01-29"," H01-20","H01-120","H01-241"," H01-22","H01-242","H01-243"," H01-24","H01-123"," H01-25","H01-124","H01-115","H01-116","H01-237","H01-117","H01-118","H01-239"," H01-38"," H01-31","H01-230"," H01-33","H01-110"," H01-35","H01-233","H01-113") + //private var unluckyHosts = listOf("H01-180","H01-181","H01-182","H01-184","H01-185","H01-186","H01-188","H01-171","H01-173","H01-176","H01-177","H01-178","H01-179","H01-169","H01","H01-162","H01-163","H01-164","H01-165","H01-166","H01-168","H01-158","H01-270","H01-150","H01-271","H01-272","H01-273","H01-274","H01-154","H01-155","H01-156","H01-157"," H01-90"," H01-91"," H01-92"," H01-93"," H01-88"," H01-89"," H01-95"," H01-96"," H01-99","H01-190","H01-191","H01-192","H01-193","H01-196","H01-197","H01-198","H01-103","H01-224","H01-225","H01-106","H01-228","H01-108"," H01-50"," H01-40"," H01-42"," H01-43"," H01-44"," H01-45","H01-100","H01-222","H01-102","H01-223","H01-214","H01-215","H01-216","H01-217","H01-218"," H01-60"," H01-59"," H01-51"," H01-52"," H01-53"," H01-56","H01-210"," H01-57","H01-211","H01-212","H01-202","H01-204","H01-205","H01-206"," H01-70"," H01-71"," H01-72","H01-209"," H01-63"," H01-64"," H01-80"," H01-82"," H01-73"," H01-76"," H01-77","H01-268","H01-269","H01-149","H01-260","H01-140","H01-262","H01-263","H01-143","H01-144","H01-265","H01-145","H01-146","H01-267"," H01-1","H01-136","H01-257","H01-137","H01-258"," H01-3","H01-139"," H01-17"," H01-18"," H01-9"," H01-8","H01-130","H01-251","H01-252"," H01-4"," H01-12","H01-133","H01-254"," H01-7"," H01-14","H01-135","H01-256","H01-126"," H01-26"," H01-27"," H01-28"," H01-29"," H01-20","H01-120","H01-241"," H01-22","H01-242","H01-243"," H01-24","H01-123"," H01-25","H01-124","H01-115","H01-116","H01-237","H01-117","H01-118","H01-239"," H01-38"," H01-31","H01-230"," H01-33","H01-110"," H01-35","H01-233","H01-113") override fun addHost(host: HostView) { // We do not want a host available if it is in the list of unluckyHosts @@ -77,6 +78,8 @@ public class SmartScheduler : ComputeScheduler { } override fun select(iter: MutableIterator<SchedulingRequest>): SchedulingResult { + client?.checkForInsights() + if (numHosts == 0) { return SchedulingResult(SchedulingResultType.FAILURE) } diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentCli.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentCli.kt index 0e190df0..df62924b 100644 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentCli.kt +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentCli.kt @@ -48,7 +48,7 @@ internal class ExperimentCommand : CliktCommand(name = "experiment") { override fun run() { try { val experiment = getExperiment(experimentPath) - //HTTPClient.getInstance()?.sendExperiment(experimentPath) + HTTPClient.getInstance()?.sendExperiment(experimentPath) runExperiment(experiment) } catch (e: IOException) { println("${e.message}") diff --git a/python_scripts/__init__.py b/python_scripts/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/python_scripts/__init__.py diff --git a/python_scripts/__main__.py b/python_scripts/__main__.py new file mode 100644 index 00000000..9c375524 --- /dev/null +++ b/python_scripts/__main__.py @@ -0,0 +1,19 @@ +import uvicorn +from typing import Dict, Any +from fastapi import FastAPI + +PORT = 1234 +HOST = "localhost" +APP = FastAPI() + +@APP.post("/assets") +async def assets(payload: Dict[Any, Any]): + return payload, 200 + + +@APP.get("/check") +async def check(): + return 200 + +if __name__ == "__main__": + uvicorn.run(APP, host=HOST, port=PORT) diff --git a/python_scripts/__pycache__/redis.cpython-314.pyc b/python_scripts/__pycache__/redis.cpython-314.pyc Binary files differnew file mode 100644 index 00000000..5b2aaa57 --- /dev/null +++ b/python_scripts/__pycache__/redis.cpython-314.pyc diff --git a/python_scripts/monitor.py b/python_scripts/monitor.py new file mode 100644 index 00000000..23b8c2c4 --- /dev/null +++ b/python_scripts/monitor.py @@ -0,0 +1,24 @@ +import redis +from redis import Redis +from redis_streams.consumer import Consumer + +STREAM="postgres_topic" +GROUP="python_consumer" + +# It is crucial to enable "decode_response" feature of Redis +redis_conn = Redis(decode_responses=True) +consumer = Consumer( + redis_conn=redis_conn, + stream=STREAM, + consumer_group=GROUP, + batch_size=10, + max_wait_time_ms=30000 + ) + + +while True: + messages = consumer.get_items() + total_no_of_messages = len(messages) + for i, item in enumerate(messages): + print(f"Pocessing {i}/{total_no_of_messages} message:{item}") + consumer.remove_item_from_consumer_group(item_id=item.msgid) diff --git a/shell_scripts/useful_commands.sh b/shell_scripts/useful_commands.sh index 8ff604e2..4b46ad2c 100644 --- a/shell_scripts/useful_commands.sh +++ b/shell_scripts/useful_commands.sh @@ -17,3 +17,7 @@ redis-cli -h localhost -p 6379 XRANGE postgres_topic - + XTRIM postgres_topic MAXLEN 0 # https://codesignal.com/learn/courses/mastering-redis-for-high-performance-applications-with-java-and-jedis-1/lessons/redis-streams-with-java +# +# Creating a group for consumers to read from stream +XGROUP CREATE mystream mygroup 0 + |
