Commit 75cf5e8a authored by Jean-Didier Totow's avatar Jean-Didier Totow
Browse files

Merge branch 'morphemic-rc2.5' into 'camel_converter'

# Conflicts:
#   .gitlab-ci.yml
parents 6fa0e123 92dc9d77
FROM python:3.5
RUN pip install --upgrade pip
COPY ./requirements.txt /
RUN pip install -r /requirements.txt
RUN apt-get update
RUN apt-get install -y git supervisor
RUN git clone https://github.com/openai/multiagent-particle-envs
RUN pip install -e ./multiagent-particle-envs
RUN mkdir /app
COPY ./src /app/
#RUN git clone https://www.github.com/alexandrosraikos/dependency-extractor
#RUN pip install ./dependency-extractor
WORKDIR /app
EXPOSE 7879
RUN mkdir -p /run/pid
RUN mkdir -p /var/log/supervisor
RUN virtualenv -p python3.7 /apivenv
RUN /apivenv/bin/pip install fastapi uvicorn pydantic stomp.py slugify
COPY ./src/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
\ No newline at end of file
version: '2'
services:
activemq:
image: jdtotow/activemq
container_name: activemq
ports:
# mqtt
- "1883:1883"
# amqp
- "5672:5672"
# ui
- "8161:8161"
# stomp
- "61613:61613"
# ws
- "61614:61614"
# jms
- "61616:61616"
# jms prometheus agent
- "8080:8080"
#volumes: ["activemq-data:/opt/activemq/conf", "activemq-data:/data/activemq", "activemq-data:/var/log/activemq"]
environment:
ACTIVEMQ_REMOVE_DEFAULT_ACCOUNT: "true"
ACTIVEMQ_ADMIN_LOGIN: aaa
ACTIVEMQ_ADMIN_PASSWORD: "111"
ACTIVEMQ_WRITE_LOGIN: aaa
ACTIVEMQ_WRITE_PASSWORD: "111"
ACTIVEMQ_READ_LOGIN: aaa
ACTIVEMQ_READ_PASSWORD: "111"
ACTIVEMQ_JMX_LOGIN: aaa
ACTIVEMQ_JMX_PASSWORD: "111"
ACTIVEMQ_STATIC_TOPICS: static-topic-1;static-topic-2
ACTIVEMQ_STATIC_QUEUES: static-queue-1;static-queue-2
ACTIVEMQ_ENABLED_SCHEDULER: "true"
ACTIVEMQ_MIN_MEMORY: 512
ACTIVEMQ_MAX_MEMORY: 2048
cdoserver:
image: gitlab.ow2.org:4567/melodic/model-repository/cdo-server:master
volumes:
- ./cdoserver/config:/config
- ./cdoserver/logs:/logs
environment:
- MYSQL_ROOT_PASSWORD=admin
- MYSQL_DATABASE=repo1
- MYSQL_USER=root
- MYSQL_PASSWORD=admin
- MELODIC_CONFIG_DIR=/config
- PAASAGE_CONFIG_DIR=/config
- spring.config.location=/config/eu.paasage.mddb.cdo.server.properties
- LOG_FILE=/logs/cdoserver.log
pid: host
ports:
- 2036:2036
- 3306:3306
solver:
image: polymorphic_solver
build:
context: .
container_name: solver
restart: always
ports:
- 7879:7879
environment:
- "ACTIVEMQ_HOST=activemq"
- "ACTIVEMQ_PORT=61610"
- "MULE_HOSTNAME=http://mule:8088"
- "CAME_CONVERTER_URL=http://camel_converter:7676"
volumes:
- "/tmp/jsons:/json"
- "./models:/app/src/models" #models should be the same with the camel converter
gym==0.10.5
numpy==1.14.5
torch
requests
#grpcio
protobuf
stomp.py
slugify
virtualenv
pyjnius~=1.3.0
\ No newline at end of file
Collecting torch
Downloading torch-1.10.1-cp39-none-macosx_10_9_x86_64.whl (147.1 MB)
Requirement already satisfied: typing-extensions in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from torch) (3.7.4.3)
Installing collected packages: torch
import os
import logging
from numbers import Number
from pathlib import Path
from typing import Dict
import jnius_config
#jnius_config.add_classpath("./morphemic/adapter/*")
from jnius import autoclass, JavaException
CDOAdapterClass = autoclass("morphemic.adapter.CdoService")
ArrayList = autoclass("java.util.ArrayList")
class Adapter():
def __init__(self, application_id):
self.application = application_id
self.adapter = CDOAdapterClass()
def transformCamelToXMI(self, path):
return self.adapter.exportModelsToXMI(self.application,path)
def saveXMI(self, path):
return self.adapter.saveXMI(path)
def saveModel(self, archetype, xmi_path):
self.adapter.saveModels(self.application, archetype, xmi_path)
adapter = Adapter("app-1")
import torch as T
from networks import ActorNetwork, CriticNetwork
from os import path
class Agent:
def __init__(self, name, actor_dims, critic_dims, n_actions, n_agents, agent_idx, chkpt_dir,
alpha=0.01, beta=0.01, fc1=64,
fc2=64, gamma=0.95, tau=0.01):
self.gamma = gamma
self.tau = tau
self.name = name
self.n_actions = n_actions
self.chkpt_file = chkpt_dir
self.agent_name = 'agent_%s' % agent_idx
self.actor = ActorNetwork(alpha, actor_dims, fc1, fc2, n_actions,
chkpt_dir=chkpt_dir, name=self.agent_name+'_actor')
self.critic = CriticNetwork(beta, critic_dims,
fc1, fc2, n_agents, n_actions,
chkpt_dir=chkpt_dir, name=self.agent_name+'_critic')
self.target_actor = ActorNetwork(alpha, actor_dims, fc1, fc2, n_actions,
chkpt_dir=chkpt_dir,
name=self.agent_name+'_target_actor')
self.target_critic = CriticNetwork(beta, critic_dims,
fc1, fc2, n_agents, n_actions,
chkpt_dir=chkpt_dir,
name=self.agent_name+'_target_critic')
self.update_network_parameters(tau=1)
def getName(self):
return self.name
def choose_action(self, observation):
state = T.tensor([observation], dtype=T.float).to(self.actor.device)
actions = self.actor.forward(state)
noise = T.rand(self.n_actions).to(self.actor.device)
action = actions + noise
return action.detach().cpu().numpy()[0]
def update_network_parameters(self, tau=None):
if tau is None:
tau = self.tau
target_actor_params = self.target_actor.named_parameters()
actor_params = self.actor.named_parameters()
target_actor_state_dict = dict(target_actor_params)
actor_state_dict = dict(actor_params)
for name in actor_state_dict:
actor_state_dict[name] = tau*actor_state_dict[name].clone() + \
(1-tau)*target_actor_state_dict[name].clone()
self.target_actor.load_state_dict(actor_state_dict)
target_critic_params = self.target_critic.named_parameters()
critic_params = self.critic.named_parameters()
target_critic_state_dict = dict(target_critic_params)
critic_state_dict = dict(critic_params)
for name in critic_state_dict:
critic_state_dict[name] = tau*critic_state_dict[name].clone() + \
(1-tau)*target_critic_state_dict[name].clone()
self.target_critic.load_state_dict(critic_state_dict)
def save_models(self):
self.actor.save_checkpoint()
self.target_actor.save_checkpoint()
self.critic.save_checkpoint()
self.target_critic.save_checkpoint()
def load_models(self):
if path.exists(self.chkpt_file+"/agent_0_critic"):
self.actor.load_checkpoint()
self.target_actor.load_checkpoint()
self.critic.load_checkpoint()
self.target_critic.load_checkpoint()
class Metric(enumerate):
"""
[0] (current/detected) Metrics & SLOs Events Format:
This event is aggregated by EMS and it is persisted in InfluxDB. Moreover,
Prediction Orchestrator will subscribe and receive the current metrics in order to
evaluate the forecasting methods, according to the defined KPIs (e.g., MAPE)
* Topic: [metric_name]
> (e.g. MaxCPULoad)
{
"metricValue": 12.34,
"level": 1,
"timestamp": 143532341251,
"refersTo": "MySQL_12345",
"cloud": "AWS-Dublin",
"provider": "AWS"
}
https://confluence.7bulls.eu/display/MOR/Forecasting+Mechanism+Sub-components+Communication
"""
TIMESTAMP = "timestamp"
METRIC_VALUE = "metricValue"
REFERS_TO = "refersTo"
CLOUD = "cloud"
PROVIDER = "provider"
class PredictionMetric(enumerate):
"""
[1] Predicted Metrics & SLOs Events Format
This event is produced by the Prediction Orchestrator and reflects the final predicted value for a metric.
- Topic: prediction.[metric_name]
> (e.g. prediction.MaxCPULoad)
{
"metricValue": 12.34,
"level": 1,
"timestamp": 143532341251,
"probability": 0.98,
"confidence_interval " : [8,15]
"predictionTime": 143532342,
"refersTo": "MySQL_12345",
"cloud": "AWS-Dublin",
"provider": "AWS"
}
https://confluence.7bulls.eu/display/MOR/Forecasting+Mechanism+Sub-components+Communication
"""
_match = "prediction."
METRICVALUE= "metricValue"
'''Predicted metric value'''
LEVEL= "level"
'''Level of VM where prediction occurred or refers'''
TIMESTAMP= "timestamp"
'''Prediction creation date/time from epoch'''
PROBABILITY= "probability"
'''Probability of the predicted metric value (range 0..1)'''
CONFIDENCE_INTERVAL= "confidence_interval"
'''the probability-confidence interval for the prediction'''
PREDICTION_TIME= "predictionTime"
'''This refers to time point in the imminent future (that is relative to the time
that is needed for reconfiguration) for which the predicted value is considered
valid/accurate (in UNIX Epoch)'''
REFERSTO= "refersTo"
'''The id of the application or component or (VM) host for which the prediction refers to'''
CLOUD= "cloud"
'''Cloud provider of the VM (with location)'''
PROVIDER= "provider"
'''Cloud provider name'''
class MetricsToPredict(enumerate):
"""
[2] Translator – to – Forecasting Methods/Prediction Orchestrator Events Format
This event is produced by the translator, to:
imform Dataset Maker which metrics should subscribe to in order to aggregate the appropriate tanning dataset in the time-series DB.
instruct each of the Forecasting methods to predict the values of one or more monitoring metrics
inform the Prediction Orchestrator for the metrics which will be forecasted
* Topic: metrics_to_predict
*Note:* This event could be communicated through Mule
[
{
"metric": "MaxCPULoad",
"level": 3,
"publish_rate": 60000,
},
{
"metric": "MinCPULoad",
"level": 3,
"publish_rate": 50000,
}
]
https://confluence.7bulls.eu/display/MOR/Forecasting+Mechanism+Sub-components+Communication
"""
_match = "metrics_to_predict"
METRIC = "metric"
'''name of the metric to predict'''
LEVEL = "level"
'''Level of monitoring topology where this metric may be produced/found'''
PUBLISH_RATE = "publish_rate"
'''expected rate for datapoints regarding the specific metric (according to CAMEL)'''
class TraningModels(enumerate):
"""
[3] Forecasting Methods – to – Prediction Orchestrator Events Format
This event is produced by each of the Forecasting methods, to inform the
Prediction Orchestrator that the method has (re-)trained its model for one or more metrics.
* Topic: training_models
{
"metrics": ["MaxCPULoad","MinCPULoad"]",
"forecasting_method": "ESHybrid",
"timestamp": 143532341251,
}
https://confluence.7bulls.eu/display/MOR/Forecasting+Mechanism+Sub-components+Communication
"""
_match = "training_models"
METRICS = "metrics"
'''metrics for which a certain forecasting method has successfully trained or re-trained its model'''
FORECASTING_METHOD = "forecasting_method"
'''the method that is currently re-training its models'''
TIMESTAMP = "timestamp"
'''date/time of model(s) (re-)training'''
class IntermediatePrediction(enumerate):
"""
[4] Forecasting Methods – to – Prediction Orchestrator Events Format
This event is produced by each of the Forecasting methods, and is used by the Prediction Orchestrator to determine the final prediction value for the particular metric.
* Topic: intermediate_prediction.[forecasting_method].[metric_name]
* (e.g. intermediate_prediction.ESHybrid.MaxCPULoad)
* We note that any component will be able to subscribe to topics like:
* intermediate_prediction.*.MaxCPULoad → gets MaxCPULoad predictions produced by all forecasting methods or
* intermediate_prediction.ESHybrid.* → gets all metrics predictions from ESHybrid method
* We consider that each forecasting method publishes a static (but configurable) number m of predicted values (under the same timestamp) for time points into the future. These time points into the future are relevant to the reconfiguration time that it is needed (and can also be updated).
* For example if we configure m=5 predictions into the future and the reconfiguration time needed is TR=10 minutes, then at t0 a forecasting method publishes 5 events with the same timestamp and prediction times t0+10, t0+20, t0+30, t0+40, t0+50.
{
"metricValue": 12.34,
"level": 3,
"timestamp": 143532341251,
"probability": 0.98,
"confidence_interval " : [8,15]
"predictionTime": 143532342,
"refersTo": "MySQL_12345",
"cloud": "AWS-Dublin",
"provider": "AWS"
}
https://confluence.7bulls.eu/display/MOR/Forecasting+Mechanism+Sub-components+Communication
"""
_match="intermediate_prediction."
METRICVALUE = "metricValue"
'''Predicted metric value (more than one such events will be produced for different time points into the future – this can be valuable to the Prediction Orchestrator in certain situations e.g., forecasting method is unreachable for a time period)'''
LEVEL = "level"
'''Level of VM where prediction occurred or refers'''
TIMESTAMP = "timestamp"
'''Prediction creation date/time from epoch'''
PROBABILITY = "probability"
'''Probability of the predicted metric value (range 0..1)'''
CONFIDENCE_INTERVAL = "confidence_interval"
'''the probability-confidence interval for the prediction'''
PREDICTION_TIME = "predictionTime"
'''This refers to time point in the imminent future (that is relative to the time that is needed for reconfiguration) for which the predicted value is considered valid/accurate (in UNIX Epoch)'''
REFERS_TO = "refersTo"
'''The id of the application or component or (VM) host for which the prediction refers to'''
CLOUD = "cloud"
'''Cloud provider of the VM (with location)'''
PROVIDER = "provider"
'''Cloud provider name'''
class Prediction(enumerate):
"""
[5] Prediction Orchestrator – to – Severity-based SLO Violation Detector Events Format
This event is used by the Prediction Orchestrator to inform the SLO Violation Detector about the current values of a metric, which can possibly lead to an SLO Violation detection.
* Topic: prediction.[metric_name]
* (e.g. prediction.MaxCPULoad)
{
"metricValue": 12.34,
"level": 1,
"timestamp": 143532341251,
"probability": 0.98,
"confidence_interval " : [8,15]
"predictionTime": 143532342,
"refersTo": "MySQL_12345",
"cloud": "AWS-Dublin",
"provider": "AWS"
}
https://confluence.7bulls.eu/display/MOR/Forecasting+Mechanism+Sub-components+Communication
"""
_match = "prediction."
METRICVALUE = "metricValue"
'''Predicted metric value'''
LEVEL = "level"
'''Level of VM where prediction occurred or refers'''
TIMESTAMP = "timestamp"
'''Prediction creation date/time from epoch'''
PROBABILITY = "probability"
'''Probability of the predicted metric value (range 0..1)'''
CONFIDENCE_INTERVAL = "confidence_interval"
'''the probability-confidence interval for the prediction'''
PREDICTIONTIME = "predictionTime"
'''This refers to time point in the imminent future (that is relative to the time that is needed for reconfiguration) for which the predicted value is considered valid/accurate (in UNIX Epoch)'''
REFERSTO = "refersTo"
'''The id of the application or component or (VM) host for which the prediction refers to'''
CLOUD = "cloud"
'''Cloud provider of the VM (with location)'''
PROVIDER = "provider"
'''Cloud provider name'''
class StopForecasting(enumerate):
"""
[6] Prediction Orchestrator – to – Forecasting Methods Events Format
This event is used by the Prediction Orchestrator to instruct a forecasting method to stop producing predicted values for a selection of metrics.
* Topic: stop_forecasting.[forecasting_method]
* Each component that implements a specific forecasting method it should subscribe to its relevant topic (e.g. the ES-Hybrid component should subscribe to stop_forecasting.eshybrid topic)
{
"metrics": ["MaxCPULoad","MinCPULoad"],
"timestamp": 143532341251,
}
https://confluence.7bulls.eu/display/MOR/Forecasting+Mechanism+Sub-components+Communication
"""
_match="stop_forecasting."
METRICS = "metrics"
'''metrics for which a certain method should stop producing predictions (because of poor results)'''
TIMESTAMP = "timestamp"
'''date/time of the command of the orchestrator'''
class StartForecasting(enumerate):
"""
[7] Prediction Orchestrator – to – Forecasting Methods Events Format
This event is used by the Prediction Orchestrator to instruct a forecasting method to start producing predicted values for a selection of metrics.
* Topic: start_forecasting.[forecasting_method]
* Each component that implements a specific forecasting method it should subscribe to its relevant topic (e.g. the ES-Hybrid component should subscribe to start_forecasting.eshybrid topic)
* We consider that each forecasting method should publish a static (but configurable) number m of predicted values (under the same timestamp) for time points into the future. These time points into the future are relevant to the reconfiguration time that it is needed (and can also be updated).
* For example if we configure m=5 predictions into the future and the reconfiguration time needed is TR=10 minutes, then at t0 a forecasting method publishes 5 events with the same timestamp and prediction times t0+10, t0+20, t0+30, t0+40, t0+50.