Skip to content
Snippets Groups Projects
Commit 85127ba7 authored by sydkbc's avatar sydkbc
Browse files

Rebase on master and merge the scaling into it

parents 4e85c258 6a52bf80
No related branches found
No related tags found
No related merge requests found
Showing
with 284 additions and 21 deletions
tosca_definitions_version: tosca_simple_yaml_1_3
interface_types:
radon.interfaces.scaling.ScaleUp:
derived_from: tosca.interfaces.Root
operations:
scale_up:
description: Interface to trigger the scale up action
\ No newline at end of file
- name: create
hosts: localhost
gather_facts: true
hosts: all
gather_facts: yes
remote_user: "{{ ssh_user }}"
vars:
ansible_ssh_private_key_file: "{{ ssh_key_file }}"
......@@ -15,11 +15,6 @@
vpc_subnet_id: "{{ vpc_subnet_id }}"
assign_public_ip: true
register: ec2
- name: wait for instance to come up
delegate_to: "{{ ec2.instances[0].public_dns_name }}"
wait_for_connection:
delay: 60
timeout: 320
- name: set outputs
set_stats:
data:
......@@ -27,3 +22,23 @@
public_ip: "{{ ec2.instances[0].public_ip }}"
private_address: "{{ ec2.instances[0].private_dns_name }}"
id: "{{ ec2.instance_ids[0] }}"
- name: Create temporary inventory for ssh wait
add_host:
name: server
groups: vms
ansible_host: "{{ ec2.instances[0].public_dns_name }}"
ansible_user: "{{ ssh_user }}"
ansible_ssh_private_key_file: "{{ ssh_key_file }}"
ansible_ssh_common_args: >
-o IdentitiesOnly=yes
-o BatchMode=yes
-o UserKnownHostsFile=/dev/null
-o StrictHostKeyChecking=no
- hosts: vms
gather_facts: no
tasks:
- name: Wait for ssh on EC2 instance to come up
wait_for_connection:
delay: 60
sleep: 30
timeout: 320
......@@ -8,15 +8,31 @@ node_types:
abstract: "false"
final: "false"
attributes:
cpu_upper_bound:
type: float
role_arn:
description: ARN for the role of the function
type: string
<<<<<<< HEAD
arn:
description: Amazon Resource Name (ARN) for this function
type: string
region:
description: AWS region in which the function is deployed
type: string
=======
callbackUrlCPU:
type: string
adjustment:
type: float
arn:
description: Amazon Resource Name (ARN) for this function
type: string
region:
type: string
ram_upper_bound:
type: float
>>>>>>> scaling
properties:
handler:
type: string
......@@ -29,6 +45,9 @@ node_types:
type: integer
description: Function memory in MB
default: 128
function_name:
type: string
description: Lambda Function name
memory_range:
type: range
description: Range of function memory in MB to search
......@@ -79,6 +98,19 @@ node_types:
relationship: radon.relationships.monitoring.AWSIsMonitoredBy
occurrences: [ 0, UNBOUNDED ]
interfaces:
scale_up:
type: radon.interfaces.scaling.ScaleUp
operations:
scale_up:
inputs:
adjustment: { default: 1, type: integer }
cpu_upper_bound: { default: 80.0, type: float }
ram_upper_bound: { default: 80.0, type: float }
callbackUrlCPU: { default: "null", type: string }
description: Operation for scaling up.
implementation:
primary: scaleUp
timeout: 0
Standard:
type: tosca.interfaces.node.lifecycle.Standard
inputs:
......@@ -98,10 +130,17 @@ node_types:
type: string
required: true
default: { get_property: [ SELF, runtime ] }
<<<<<<< HEAD
function_name:
type: string
required: true
default: { get_property: [ SELF, name ] }
=======
callbackUrlCPU:
type: string
required: false
default: { get_property: [ radon.policies.scaling.ScaleUp, callbackUrlCPU ] }
>>>>>>> scaling
lambda_timeout:
type: integer
required: true
......@@ -134,6 +173,37 @@ node_types:
type: string
required: false
default: { get_property: [ SELF, env_vars ] }
<<<<<<< HEAD
=======
cpu_upper_bound:
type: float
required: false
default: { get_property: [ radon.policies.scaling.ScaleUp, cpu_upper_bound ] }
s3_bucket_key:
type: string
required: true
default: { get_property: [ SELF, s3_bucket_key ] }
aws_region:
type: string
required: true
default: { get_property: [ SELF, host, region ] }
role_arn:
type: string
required: true
default: { get_attribute: [ SELF, host, role_arn ] }
function_name:
type: string
required: true
default: { get_property: [ SELF, name ] }
adjustment:
type: float
required: false
default: { get_property: [ radon.policies.scaling.ScaleUp, adjustment ] }
ram_upper_bound:
type: float
required: false
default: { get_property: [ radon.policies.scaling.ScaleUp, ram_upper_bound ] }
>>>>>>> scaling
operations:
create:
implementation:
......@@ -150,3 +220,6 @@ node_types:
delete:
type: radon.artifacts.Ansible
file: delete.yml
scaleUp:
type: radon.artifacts.Ansible
file: scaleUp.yml
\ No newline at end of file
......@@ -42,3 +42,11 @@
arn: "{{ alias_info.alias_arn }}"
role_arn: "{{ role_arn }}"
region: "{{ aws_region }}"
- name: set outputs regarding to scaling policies
set_stats:
data:
cpu_upper_bound: "{{ cpu_upper_bound }}"
ram_upper_bound: "{{ ram_upper_bound }}"
adjustment: "{{ adjustment }}"
callbackUrlCPU: "{{ callbackUrlCPU }}"
---
- name: scaleUp
hosts: localhost
gather_facts: no
become: true
become_method: sudo
vars:
notification_obj: "{{ notification | regex_replace('[^a-zA-Z0-9:,-]') }}"
notification_obj1: "{{ notification_obj.split(':') }}"
notification_obj2: "{{ notification_obj1[2].split(',') }}"
monitored_function_name: "{{ notification_obj2[0] }}"
tasks:
- name: Start scaling up of Lambda function {{ monitored_function_name }}
debug:
msg: "Scaling up initiated."
- name: See what's in the notification file from monitoring that was supplied to opera notify "{{ notification }}"
debug:
msg: "{{ notification }}"
- name: Fecth the Labda function current memory size in order to increase it.
shell: aws lambda get-function-configuration --region eu-central-1 --function-name {{ monitored_function_name }}
register: current_function
- name: Get Current AWS Memory Size
set_fact:
memory: "{{ (current_function.stdout_lines | join('\n') | from_json).MemorySize }}"
- name: Adjust AWS Memory size
set_fact:
memory: "{{ 2*memory|int }}"
- name: Scale Up Lambda function by incesing the Memory Size.
shell: aws lambda update-function-configuration --function-name {{ monitored_function_name }} --region eu-central-1 --memory-size {{ memory }}
- name: Finish scaling up of {{ monitored_function_name }}
debug:
msg: "Scaling up concluded."
......@@ -46,6 +46,19 @@ node_types:
type: tosca.interfaces.node.lifecycle.Standard
operations:
create:
inputs:
pushgateway_ip:
type: string
required: true
default: { get_attribute: [ SELF, dependency, public_ip ] }
ssh_user:
type: string
required: true
default: { get_attribute: [ SELF, dependency, ssh_user ] }
ssh_key_file:
type: string
required: true
default: { get_attribute: [ SELF, dependency, ssh_key_file ] }
implementation:
primary: create
timeout: 0
......@@ -67,6 +80,14 @@ node_types:
type: string
required: true
default: { get_property: [ SELF, consul_ip ] }
ssh_user:
type: string
required: true
default: { get_attribute: [ SELF, dependency, ssh_user ] }
ssh_key_file:
type: string
required: true
default: { get_attribute: [ SELF, dependency, ssh_key_file ] }
implementation:
primary: configure
timeout: 0
......@@ -80,6 +101,14 @@ node_types:
type: string
required: true
default: { get_property: [ SELF, consul_ip ] }
ssh_user:
type: string
required: true
default: { get_attribute: [ SELF, dependency, ssh_user ] }
ssh_key_file:
type: string
required: true
default: { get_attribute: [ SELF, dependency, ssh_key_file ] }
implementation:
primary: delete
timeout: 0
......@@ -92,4 +121,4 @@ node_types:
file: configure.yml
delete:
type: radon.artifacts.Ansible
file: delete.yml
file: delete.yml
\ No newline at end of file
---
- name: configure
hosts: all
gather_facts: true
gather_facts: no
become: true
become_method: sudo
vars:
ansible_ssh_private_key_file: "{{ ssh_key_file }}"
ansible_ssh_user: "{{ ssh_user }}"
tasks:
- name: Install consul module for python
pip:
......
---
- name: create
hosts: all
gather_facts: true
gather_facts: no
become: true
become_method: sudo
vars:
ansible_ssh_private_key_file: "{{ ssh_key_file }}"
ansible_ssh_user: "{{ ssh_user }}"
tasks:
- name: Install Python pip module prerequisites (Linux)
apt:
......@@ -11,13 +15,13 @@
- python3-virtualenv
- python3-setuptools
- python3-docker
update_cache: true
update_cache: yes
state: present
when: ansible_os_family == "Debian"
- name: Run Prometheus Pushgateway Docker image
docker_container:
name: DeploymentAgent
image: prom/pushgateway
pull: true
pull: yes
ports:
- "9091:9091"
---
- name: delete
hosts: all
gather_facts: true
gather_facts: no
become: true
become_method: sudo
vars:
ansible_ssh_private_key_file: "{{ ssh_key_file }}"
ansible_ssh_user: "{{ ssh_user }}"
tasks:
- name: Remove Push Gateway instance from Radon Consul
consul:
......
tosca_definitions_version: tosca_simple_yaml_1_3
policy_types:
radon.policies.scaling.ScaleOut:
radon.policies.scaling.ScaleUp:
derived_from: tosca.policies.Scaling
metadata:
targetNamespace: "radon.policies.scaling"
......@@ -14,15 +14,40 @@ policy_types:
required: false
constraints:
- less_or_equal: 100.0
callbackUrlCPU:
type: string
description: The callback URL in SaaS
required: false
adjustment:
type: integer
description: The amount by which to scale
required: false
constraints:
- greater_or_equal: 1
ram_upper_bound:
type: float
description: The upper bound for the RAM
required: false
constraints:
- less_or_equal: 100.0
cpu_lower_bound:
type: float
description: The lower bound for the CPU
required: false
constraints:
- greater_or_equal: 0.0
targets: [ radon.nodes.aws.AwsLambdaFunctionFromS3 ]
triggers:
radon.triggers.scaling.ScaleUp:
description: A scale up action
event: scale_up_trigger
target_filter:
node: radon.nodes.aws.AwsLambdaFunctionFromS3
action:
- call_operation:
operation: scale_up.scale_up
inputs:
adjustment: { get_property: [ SELF, adjustment ] }
cpu_upper_bound: { get_property: [ SELF, cpu_upper_bound ] }
ram_upper_bound: { get_property: [ SELF, ram_upper_bound ] }
callbackUrlCPU: { get_property: [ SELF, callbackUrlCPU ] }
\ No newline at end of file
......@@ -11,6 +11,10 @@ relationship_types:
Configure:
type: tosca.interfaces.relationship.Configure
inputs:
cpu_upper_bound:
type: string
required: true
default: { get_attribute: [ SOURCE, cpu_upper_bound ] }
user_email:
type: string
required: true
......@@ -18,7 +22,7 @@ relationship_types:
monitored_function:
type: string
required: true
default: { get_property: [ SOURCE, name ] }
default: { get_property: [ SOURCE, function_name ] }
pushgateway_ip:
type: string
required: true
......@@ -27,8 +31,28 @@ relationship_types:
type: string
required: true
default: { get_property: [ TARGET, grafana_api_ip ] }
callbackUrlCPU:
type: string
required: true
default: { get_attribute: [ SOURCE, callbackUrlCPU ] }
adjustment:
type: string
required: true
default: { get_attribute: [ SOURCE, adjustment ] }
ssh_user:
type: string
required: true
default: { get_property: [ TARGET, dependency, ssh_user ] }
ssh_key_file:
type: string
required: true
default: { get_property: [ TARGET, dependency, ssh_key_file ] }
ram_upper_bound:
type: string
required: true
default: { get_attribute: [ SOURCE, ram_upper_bound ] }
operations:
post_configure_source:
implementation:
primary: grafana-injection.yml
timeout: 30
timeout: 30
\ No newline at end of file
---
- name: configure
hosts: all
gather_facts: false
- hosts: all
gather_facts: no
become: true
become_method: sudo
vars:
ansible_ssh_private_key_file: "{{ ssh_key_file }}"
ansible_ssh_user: "{{ ssh_user }}"
tasks:
- name: "Policy on AWS Lambda. The grafana API should be set to generate the alert towards xOpera SaaS for {{ adjustment }} and {{ cpu_upper_bound }}"
debug:
msg: "Policy Data: {{ adjustment }} and {{ cpu_upper_bound }}"
- name: Configure Grafana dashboards for the monitored_function of user_email and setup Alerts
uri:
url: "{{ grafana_api_ip }}"
method: POST
body_format: json
body:
"email": "{{ user_email }}"
"jobid": "{{ monitored_function }}"
"type": "custom"
"cpuAlertThreshold": "{{ cpu_upper_bound }}"
"ramAlertThreshold": "{{ ram_upper_bound }}"
"callbackURL": "{{ callbackUrlCPU }}"
when: (cpu_upper_bound is defined) and (ram_upper_bound is defined) and (callbackUrlCPU is defined)
- name: Configure Grafana dashboards for the monitored_function of user_email
uri:
url: "{{ grafana_api_ip }}"
......@@ -12,5 +33,12 @@
"email": "{{ user_email }}"
"jobid": "{{ monitored_function }}"
"type": "custom"
when: (cpu_upper_bound is undefined) or (ram_upper_bound is undefined) or (callbackUrlCPU is undefined)
- name: Install prerequsiste packages
apt:
name:
- awscli
state: latest
- name: Inject the PUSH_GATEWAY_HOST env variable to the function to create the AWS-PushGateway relation
shell: "aws lambda update-function-configuration --function-name {{ monitored_function }} --environment Variables={PUSH_GATEWAY_HOST={{ pushgateway_ip }}:9091}"
shell: aws lambda update-function-configuration --function-name {{ monitored_function }} --region eu-central-1 --environment Variables={PUSH_GATEWAY_HOST=http://{{ pushgateway_ip }}:9091}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment