Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,3 @@ Supports advanced functionality to improve the user experience.
- Does not use ec2 inventory
- Uses node and npm to manage phases
- Network characteristics can be changed at runtime and on a per-container level
- No prerequisites for ami, just needs to be Amazon Linux 2
2 changes: 1 addition & 1 deletion node-agent/lib/controllers/networkController.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function(app) {
res.status(500).send({"message": "Could not update network as tcconfig is not installed", "error": result})
} else {
logger.error("Unexpected error:")
logger.error(error)
logger.error(result)
res.status(500).send({"message": "Could not update network, there was an unexpected error", "error": result.stack})
}
}
Expand Down
1 change: 1 addition & 0 deletions node-agent/lib/services/dockerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async function updateMCRConfigs(newList) {
currentMCRList = newList
} catch (error) {
logger.error("Could not update machine container resource configurations")
logger.error(JSON.stringify(error))
throw error
}
}
Expand Down
2 changes: 1 addition & 1 deletion node-agent/lib/services/networkService.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function getOtherHostIPs(json) {
ips = []

try {
for (host in config["eth1"]["outgoing"]) {
for (host in config["ens6"]["outgoing"]) {
ips.push(host.toString().replace("dst-network=", "").split("/")[0])
}
} catch(error) {
Expand Down
4 changes: 2 additions & 2 deletions node-agent/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
"tcconfig": {
"type": "object",
"properties": {
"eth0": {
"ens5": {
"type": "object",
"properties": {
"outgoing": {
Expand All @@ -309,7 +309,7 @@
}
}
},
"eth1": {
"ens6": {
"type": "object",
"properties": {
"outgoing": {
Expand Down
5 changes: 3 additions & 2 deletions node-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The Node Manager is configured by four configuration files that should be placed
- `orchestration.jsonc`: defines the orchestration schedule

You can find documentation on how to structure these configuration files and available capabilities in the two provided examples.
Note that MockFog has only been tested with AMIs based on Ubuntu 20.04; also, there needs to be an ubuntu user.
The [CRExplorer example](./run-example-crexplorer) will result in the deployment of the [CRExplorer](https://github.com/MoeweX/crexplorer) container on two machines out of three emulated servers. The orchestration schedule lets CRExplorer explore available resources and network characteristics.
The [Smart Factory example](./run-example-smartfactory) will result in the deployment of a [Smart Factory Application](https://github.com/MoeweX/smart-factory-fog-example) on multiple machines. The orchestration schedule comprises infrastructure and workload generation changes.

Expand All @@ -31,8 +32,8 @@ Start this phase by running `node app.js bootstrap`, this:
- Creates a var file for the bootstrap playbook at `run/vars/`
- Bootstraps the infrastructure on AWS based on `run/infrastructure.jsonc`
- Setup a VPC
- Setup a management subnet (access to internet, only ssh and node agent) -> mapped to eth0
- Setup an internal subnet (access to all other machines, all traffic) -> mapped to eth1
- Setup a management subnet (access to internet, only ssh and node agent) -> assumed to be mapped to ens5
- Setup an internal subnet (access to all other machines, all traffic) -> assumed to be mapped to ens6
- Start EC2 instances that are part of this VPC
- Pulls ssh key and writes it to `run/<configured name>.pem`.
- Pulls machine facts and writes them to `run/machines/machine_meta.jsonc`
Expand Down
46 changes: 45 additions & 1 deletion node-manager/lib/data/machine-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function getPublicIP(machine_name, instances) {
}

/**
* Returns the the machine name of the machine with the given public_ip.
* Returns the machine name of the machine with the given public_ip.
*
* @param {String} public_ip
* @param {Object} instances the machine meta json instances object
Expand All @@ -61,6 +61,47 @@ function getMachineNameFromPublicIp(public_ip, instances) {
}
}

/**
* Returns the netplan string
* @param {String} machine_name
* @param {Object} instances the machine meta json instances object
*/

function getNetplanString(machine_name, instances) {
const network_interfaces = getInstance(machine_name, instances).network_interfaces

// mac addresses
const addresses = {}

for (const network_interface of network_interfaces) {
const ip = network_interface.private_ip_address
if (ip.startsWith("10.0.2.")) {
addresses["internal"] = network_interface.mac_address
} else if (ip.startsWith("10.0.1.")) {
addresses["management"] = network_interface.mac_address
}
}

return `network:
ethernets:
ens5:
dhcp4: true
dhcp6: false
match:
macaddress: ${addresses["management"]}
set-name: ens5
ens6:
dhcp4: true
dhcp6: false
match:
macaddress: ${addresses["internal"]}
set-name: ens6
version: 2
`


}

//*************************************
// Hosts file helper
//*************************************
Expand Down Expand Up @@ -98,6 +139,9 @@ module.exports = function(fileLocation) {
getMachineNameFromPublicIp: function(public_ip) {
return getMachineNameFromPublicIp(public_ip, machineMeta.instances)
},
getNetplanString: function(machine_name) {
return getNetplanString(machine_name, machineMeta.instances)
},
hostsDataObject: getHostsDataObject(machineMeta)
}
}
2 changes: 1 addition & 1 deletion node-manager/lib/data/multi-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function getHosts(machineMeta, container, deployment) {
const hostsDataObject = machineMeta.hostsDataObject

return `[all:vars]
ansible_ssh_user=ec2-user
ansible_user=ubuntu
ansible_ssh_common_args='-o StrictHostKeyChecking=no'

# ---------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions node-manager/lib/services/manipulationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ function getTCConfigs(infrastructure, machineMeta) {
}

tcConfig[start.machine_name] = {
"eth0": {
"ens5": {
"outgoing": {},
"incoming": {}
},
"eth1": {
"ens6": {
"outgoing": outgoing,
"incoming": {}
}
Expand Down
14 changes: 14 additions & 0 deletions node-manager/lib/stages/01_infrastructure/02_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require("fs")
const fsp = fs.promises

const infrastructure = require("../../data/infrastructure.js")
const machineMetaF = require("../../data/machine-meta.js")

const common = require("../common.js")
const Phase = require("../phase.js")
Expand All @@ -20,13 +21,26 @@ class Child extends Phase {

async parseInput() {
this.infra = infrastructure()
this.machineMeta = machineMetaF()
}

async runPrePlaybookTasks() {
// write var file
await fsp.writeFile(this.varPath, this.infra.awsYML)
this.logger.info("Agent playbook vars written to " + this.varPath)

// write netplan file
for (const machine of this.infra.infra.machines) {
const machine_name = machine.machine_name
const netplan_string = this.machineMeta.getNetplanString(machine_name)
const machine_dir = conf.runMachinesDir + machine_name
conf.checkFolderExists(machine_dir)
const netplan_path = machine_dir + "/netplan.yml"

await fsp.writeFile(netplan_path, netplan_string)
this.logger.info("Wrote netplan file for " + machine_name + " to " + netplan_path)
}

// create playbook object
this.playbook = new common.Playbook(this.playbookPath, this.varPath, ["-i", `${conf.runDir}hosts`, `--key-file=${conf.runDir}${this.infra.infra.aws.ssh_key_name}.pem`])
}
Expand Down
53 changes: 45 additions & 8 deletions node-manager/playbooks/0102_agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,54 @@
hosts: machines

tasks:
- name: Install Yum Packages
yum:
- name: Print Network Interfaces
debug:
msg: "{{ hostvars[inventory_hostname]['ansible_%s' | format(item)] }}"
with_items: "{{ ansible_interfaces }}"

- name: Install Packages
apt:
name: "{{ packages }}"
state: present
update_cache: yes
become: yes
vars:
packages:
- iproute-tc
- iproute2
- python3
- python3-pip
- rsync
- chrony

# to allow non-root usage to use tcconfig for easier manual debugging
# to allow non-root usage to use tcconfig for easier manual debugging
- name: Allow TC Usage
shell: setcap cap_net_admin+ep /usr/sbin/tc
become: yes

- name: Copy Netplan Configuration
copy:
src: "{{ playbook_dir }}/../run/machines/{{ hostvars[inventory_hostname].machine_name }}/netplan.yml"
dest: "/etc/netplan/50-cloud-init.yaml"
become: yes
register: copy_code

- name: Apply Netplan Configuration
shell: netplan --debug apply
become: yes
when: copy_code.changed

- name: Install Node
script: scripts/install_node.sh
args:
creates: ~/.nvm/nvm.sh
when: copy_code.changed

- name: Install TCConfig
shell: pip3 install "tcconfig==0.25.2"
become: yes
when: copy_code.changed

- name: Install Docker
script: scripts/install_docker.sh
when: copy_code.changed

- name: Install Docker SDK
pip:
Expand All @@ -41,14 +64,28 @@
state: started
become: yes

- name: Create Docker Group for non Sudo Access
shell: groupadd docker
become: yes
ignore_errors: yes

- name: Add User to Docker Group
user:
name: ubuntu
group: docker
become: yes

- name: Reset SSH Connection
meta: reset_connection

- name: Copy Agent
synchronize:
src: "{{ playbook_dir }}/../../node-agent"
dest: "/home/ec2-user/"
dest: "~/"

- name: Install Agent
npm:
path: "/home/ec2-user/node-agent"
path: "~/node-agent"
state: present

- name: Allow Hard Time Sync
Expand Down
Loading