diff --git a/java/genericsdsensor/examples/sensors/tosca/README.md b/java/genericsdsensor/examples/sensors/tosca/README.md index e69de29b..dabfb21e 100644 --- a/java/genericsdsensor/examples/sensors/tosca/README.md +++ b/java/genericsdsensor/examples/sensors/tosca/README.md @@ -0,0 +1,22 @@ +## Run software-define sensor in TOSCA-based deployment tool (SALSA) + +This example includes 3 TOSCA files which can be deployed by [SALSA](http://tuwiendsg.github.io/SALSA/). The TOSCA files define the sensor runtime in 3 cases: plain machine, via Docker, and via Vagrant. + +The steps to run these examples are: + +1. Build the sensor source code. +2. Install and run SALSA. +3. Copy and pack following files into a single package: sensor-artifacts.tar.gz + 1. src/sdsensor/target/sdsensor-0.0.1-SNAPSHOT-jar-with-dependencies.jar + 2. src/sdcommon/target/sdcommon-0.0.1-SNAPSHOT.jar + 3. src/sdcloudconnectivity/target/cloud-connectivity-0.0.1-SNAPSHOT-jar-with-dependencies.jar + 4. src/sdsensor/conf/mqttcloud.json (must be edited to match with your MQTT broker) + 5. src/sdsensor/datasample/data.csv (optional: replace with your data file) +4. Copy execution file: runsensor.sh +5. Copy Dockerfile or Vagrantfile in the corresponding case. +4. Edit the path in ```ArtifactReference``` in TOSCA files to match with above artifacts. +5. Submit the TOSCA file to SALSA and wait for the provisioning completed. + +You can view the data being pushed to the MQTT broker with settings as in mqttcloud.json + +Note: In this example, we pack multiple artifacts for a better deliver. diff --git a/java/genericsdsensor/examples/sensors/tosca/sensors-docker.tosca.xml b/java/genericsdsensor/examples/sensors/tosca/sensors-docker.tosca.xml new file mode 100644 index 00000000..6a7f7812 --- /dev/null +++ b/java/genericsdsensor/examples/sensors/tosca/sensors-docker.tosca.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + localhost + + + + + + + + + + + + + + + localhost + 000000512 + a82e054f-4f01-49f9-bc4c-77a98045739c + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/genericsdsensor/examples/sensors/tosca/sensors-plain-machine.tosca.xml b/java/genericsdsensor/examples/sensors/tosca/sensors-plain-machine.tosca.xml new file mode 100644 index 00000000..b418f563 --- /dev/null +++ b/java/genericsdsensor/examples/sensors/tosca/sensors-plain-machine.tosca.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + localhost + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/genericsdsensor/examples/sensors/tosca/sensors-vagrant-virtualbox.tosca.xml b/java/genericsdsensor/examples/sensors/tosca/sensors-vagrant-virtualbox.tosca.xml new file mode 100644 index 00000000..36b7da15 --- /dev/null +++ b/java/genericsdsensor/examples/sensors/tosca/sensors-vagrant-virtualbox.tosca.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + localhost + + + + + + + + + + + + + + + /usr/bin/vagrant destroy + /usr/bin/vagrant up + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/genericsdsensor/examples/sensors/vagrant/README.md b/java/genericsdsensor/examples/sensors/vagrant/README.md index e69de29b..12211ac9 100644 --- a/java/genericsdsensor/examples/sensors/vagrant/README.md +++ b/java/genericsdsensor/examples/sensors/vagrant/README.md @@ -0,0 +1,27 @@ +## Run software-define sensor via Vagrant + +Vagrant enables to deploy sensor on top of different providers. This example contains two Vagrant files: for VirtualBox and for docker. VirtualBox is the default environment. + +To use the Vagrant, following steps need to be done: + +1. Install Vagrant by following [the documentation](https://www.vagrantup.com/docs/installation/). +2. Build the sensor source code. +3. Copy the all following sensor artifacts into the same folder with the Vagrant file: + 1. src/sdsensor/target/sdsensor-0.0.1-SNAPSHOT-jar-with-dependencies.jar + 2. src/sdcommon/target/sdcommon-0.0.1-SNAPSHOT.jar + 3. src/sdcloudconnectivity/target/cloud-connectivity-0.0.1-SNAPSHOT-jar-with-dependencies.jar + 4. src/sdsensor/conf/mqttcloud.json (must be edited to match with your MQTT broker) + 5. src/sdsensor/datasample/data.csv (optional: replace with your data file) +4. Based on which environment to run: + 1. Vagrant + Virtualbox: change `Vagrantfile.virtualbox` to `Vagrantfile` + 2. Vagrant + Docker: change `Vagrantfile.docker` to `Vagrantfile`, and copy the Dockerfile from docker example to this folder +3. Run following command: +``` +vagrant up +``` +4. You can view the data being pushed to the MQTT broker with settings as in mqttcloud.json + +Note: + +* In the case of Vagrant + Virtualbox, you need virtuabox installed localy. The image to be used in this case is Ubuntu 12.04, which has no Java. Thus, Vagrant will install JRE 1.7 during the provisioning. +* In the case of Vagrant + Docker, the result is similar to Docker example with Vagrant API to control the Docker container. diff --git a/java/genericsdsensor/examples/sensors/vagrant/Vagrantfile.docker b/java/genericsdsensor/examples/sensors/vagrant/Vagrantfile.docker new file mode 100644 index 00000000..a927ec8f --- /dev/null +++ b/java/genericsdsensor/examples/sensors/vagrant/Vagrantfile.docker @@ -0,0 +1,10 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure("2") do |config| + + config.vm.provider "docker" do |d| + d.build_dir = "." + end + + end diff --git a/java/genericsdsensor/examples/sensors/vagrant/Vagrantfile.virtualbox b/java/genericsdsensor/examples/sensors/vagrant/Vagrantfile.virtualbox new file mode 100644 index 00000000..a0247903 --- /dev/null +++ b/java/genericsdsensor/examples/sensors/vagrant/Vagrantfile.virtualbox @@ -0,0 +1,95 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://atlas.hashicorp.com/search. + config.vm.box = "hashicorp/precise64" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + # config.vm.synced_folder "../data", "/vagrant_data" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + # config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + # vb.memory = "1024" + # end + # + # View the documentation for the provider you are using for more + # information on available options. + + # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies + # such as FTP and Heroku are also available. See the documentation at + # https://docs.vagrantup.com/v2/push/atlas.html for more information. + # config.push.define "atlas" do |push| + # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" + # end + + # Enable provisioning with a shell script. Additional provisioners such as + # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the + # documentation for more information about their specific syntax and use. + + # Different providers, use + # Docker provider, run by: vagrant up --provider=docker + #config.vm.provider "docker" do |d| + # d.image = "leduchung/ubuntu:14.04-jre8" + #end + + # VirtualBox provider, run by: vagrant up --provider + + # Create a folder for sensor artifacts + config.vm.provision "shell", inline: <<-SHELL + mkdir -p /tmp/sensor + chmod 777 /tmp/sensor + apt-get update + apt-get install -y openjdk-7-jre-headless + SHELL + + config.vm.provision "file", source: "./cloud-connectivity-0.0.1-SNAPSHOT-jar-with-dependencies.jar", destination: "/tmp/sensor/cloud-connectivity-0.0.1-SNAPSHOT-jar-with-dependencies.jar" + config.vm.provision "file", source: "./sdsensor-0.0.1-SNAPSHOT-jar-with-dependencies.jar", destination: "/tmp/sensor/sdsensor-0.0.1-SNAPSHOT-jar-with-dependencies.jar" + config.vm.provision "file", source: "./sdcommon-0.0.1-SNAPSHOT.jar", destination: "/tmp/sensor/sdcommon-0.0.1-SNAPSHOT.jar" + config.vm.provision "file", source: "./mqttcloud.json", destination: "/tmp/sensor/mqttcloud.json" + config.vm.provision "file", source: "./data.csv", destination: "/tmp/sensor/data.csv" + config.vm.provision "file", source: "./runsensor.sh", destination: "/tmp/sensor/runsensor.sh" + + config.vm.provision "shell", inline: <<-SHELL + cd /tmp/sensor + /bin/bash runsensor.sh + SHELL + end