diff --git a/Dockerfile b/Dockerfile index 35cea5f..b88c06d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ LABEL maintainer="Predix Edge Adoption" LABEL hub="https://hub.docker.com" LABEL org="https://hub.docker.com/u/predixedge" LABEL repo="predix-edge-sample-scaler-go" -LABEL version="1.0.3" +LABEL version="1.0.4" LABEL support="https://forum.predix.io" LABEL license="https://github.com/PredixDev/predix-docker-samples/blob/master/LICENSE.md" diff --git a/README.md b/README.md index bbbe889..da0ab3c 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,6 @@ Feb 28 03:23:52 predixedge b35f5fc9ed5b[319]: {"messageId":"flex-pipe","body":[{ ## Software You will Need In order to develop and run this sample locally you will need: -* [**Go**](https://golang.org/) * [**Docker**](https://www.docker.com/) * The *UAA URL*, *ClientID* and *Secret* for the Predix Cloud Time Series service to which you wish to ingest the app's output. @@ -409,6 +408,13 @@ docker logs 0000000000 #### Option 2: Run all the containers on your machine, except for the Go code +This is very similar to Option 1, only instead of running the application in a Docker container, you run it locally on your machine. + +## Software You will Need + +In order to develop and run this sample locally you will need: +* [**Go**](https://golang.org/) + ##### Step 1: Run the other containers of the Application Start the Data Broker. It is recommended to run this as a separate docker stack becuase the broker can be used with multiple applications and Predix Edge OS is shipped with the Broker already running. Execute the following command from the command line. diff --git a/config/config-cloud-gateway.json b/config/config-cloud-gateway.json index b1f97ff..5132208 100644 --- a/config/config-cloud-gateway.json +++ b/config/config-cloud-gateway.json @@ -4,7 +4,7 @@ "type": "timeseries", "config": { "log_name": "time_series_sender", - "log_level": "warn", + "log_level": "debug", "mqtt": { "transport_addr": "mqtt-tcp://predix-edge-broker", "qos": 0, @@ -22,7 +22,7 @@ "transport_addr": "wss://gateway-predix-data-services.run.aws-usw02-pr.ice.predix.io/v1/stream/messages", "predix_zone_id": "your-predix-zone-id" "token_file": "/edge-agent/access_token", - "proxy_url": "<>" + "proxy_url": "$https_proxy" } } } diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 8a23257..d201cd9 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -1,8 +1,9 @@ version: "3.0" +#This file combines all the edge services and our services so that it can be deployed as a unit services: opcua-simulator: - image: "predixedge/predix-edge-opcua-simulator:1.0.9" + image: "predixedge/predix-edge-opcua-simulator:1.0.10" hostname: "opcua-simulator" volumes: - ./config:/config @@ -10,7 +11,6 @@ services: - predix-edge-broker_net ports: - 4334:4334 - #entrypoint: ["sh", "-c", "sleep 500000"] opcua: image: "dtr.predix.io/predix-edge/protocol-adapter-opcua:amd64-1.1.0" environment: @@ -24,7 +24,11 @@ services: image: "dtr.predix.io/predix-edge/cloud-gateway:amd64-1.1.0" environment: config: "/config/config-cloud-gateway.json" - https_proxy: "$https_proxy" + http_proxy: ${http_proxy} + https_proxy: ${https_proxy} + HTTP_PROXY: ${HTTP_PROXY} + HTTPS_PROXY: ${HTTP_PROXY} + no_proxy: ${no_proxy} volumes: - ./config:/config - ./data:/data diff --git a/docker-compose-local.yml b/docker-compose-local.yml index bd58522..85fb4f7 100644 --- a/docker-compose-local.yml +++ b/docker-compose-local.yml @@ -2,7 +2,7 @@ version: "3.0" #This file combines all the edge services and our services so that it can be deployed as a unit services: opcua-simulator: - image: "predixedge/predix-edge-opcua-simulator:1.0.9" + image: "predixedge/predix-edge-opcua-simulator:1.0.10" hostname: "opcua-simulator" volumes: - ./config:/config @@ -10,7 +10,6 @@ services: - predix-edge-broker_net ports: - 4334:4334 - #entrypoint: ["sh", "-c", "sleep 500000"] opcua: image: "dtr.predix.io/predix-edge/protocol-adapter-opcua:amd64-1.1.0" environment: @@ -24,6 +23,11 @@ services: image: "dtr.predix.io/predix-edge/cloud-gateway:amd64-1.1.0" environment: config: "/config/config-cloud-gateway.json" + http_proxy: ${http_proxy} + https_proxy: ${https_proxy} + HTTP_PROXY: ${HTTP_PROXY} + HTTPS_PROXY: ${HTTP_PROXY} + no_proxy: ${no_proxy} volumes: - ./config:/config - ./data:/data @@ -31,7 +35,7 @@ services: networks: - predix-edge-broker_net edge-app: - image: "predixedge/predix-edge-sample-scaler-go:1.0.3" + image: "predixedge/predix-edge-sample-scaler-go:1.0.4" environment: CLIENT_ID: "go-simple" BROKER: "predix-edge-broker:1883" @@ -42,12 +46,6 @@ services: - ./config:/config - ./data:/data - ./data:/edge-agent - environment: - CLIENT_ID: "go-simple" - BROKER: "predix-edge-broker:1883" - PUB_TOPIC: "timeseries_data" - SUB_TOPIC: "app_data" - TAG_NAME: "My.App.DOUBLE1" networks: - predix-edge-broker_net #entrypoint: ["sh", "-c", "sleep 500000"] diff --git a/docker-compose.yml b/docker-compose.yml index 10d5c9c..085cd8d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,15 +2,14 @@ version: "3.0" services: opcua-simulator: - image: "predixedge/predix-edge-opcua-simulator:1.0.9" - hostname: "opcua-simulator" + image: "predixedge/predix-edge-opcua-simulator:1.0.10" networks: - predix-edge-broker_net ports: - 4334:4334 - #entrypoint: ["sh", "-c", "sleep 500000"] opcua: image: "dtr.predix.io/predix-edge/protocol-adapter-opcua:amd64-1.1.0" + environment: config: "/config/config-opcua.json" networks: @@ -24,7 +23,7 @@ services: networks: - predix-edge-broker_net edge-app: - image: "predixedge/predix-edge-sample-scaler-go:1.0.3" + image: "predixedge/predix-edge-sample-scaler-go:1.0.4" environment: CLIENT_ID: "go-simple" BROKER: "predix-edge-broker:1883" diff --git a/images/architecture.png b/images/architecture.png index 05c26b8..632906f 100644 Binary files a/images/architecture.png and b/images/architecture.png differ diff --git a/scripts/quickstart-edge-starter-sample-app.sh b/scripts/quickstart-edge-starter-sample-app.sh index ae5211b..06757fa 100755 --- a/scripts/quickstart-edge-starter-sample-app.sh +++ b/scripts/quickstart-edge-starter-sample-app.sh @@ -50,19 +50,19 @@ function local_read_args() { BRANCH="master" PRINT_USAGE=0 SKIP_SETUP=false -GITHUB_RAW="https://raw.githubusercontent.com" VERSION_JSON="version.json" PREDIX_SCRIPTS_ORG="PredixDev" PREDIX_SCRIPTS="predix-scripts" +GITHUB_RAW="https://raw.githubusercontent.com" +IZON_SH="https://raw.githubusercontent.com/PredixDev/izon/1.5.0/izon2.sh" GITHUB_ORG="PredixDev" REPO_NAME="predix-edge-sample-scaler-go" -IZON_SH="https://raw.githubusercontent.com/PredixDev/izon/1.5.0/izon2.sh" +DOCKER_STACK_NAME="predix-edge-sample-scaler-go" SCRIPT="-script edge-starter-deploy.sh -script-readargs edge-starter-deploy-readargs.sh" -SCRIPT_NAME="quickstart-edgesample-scaler-go-local.sh" +SCRIPT_NAME="quickstart-edge-starter-sample-app.sh" APP_DIR="edge-sample-scaler-go" APP_NAME="Predix Edge Sample Scaler App - Go" - TOOLS="Cloud Foundry CLI, Docker, Git, jq, yq, Go, Predix CLI" TOOLS_SWITCHES="--cf --docker --git --jq --yq --go --predixcli" @@ -75,10 +75,11 @@ local_read_args $@ SCRIPT_LOC="$GITHUB_RAW/$GITHUB_ORG/$REPO_NAME/$BRANCH/scripts/$SCRIPT_NAME" VERSION_JSON_URL="$GITHUB_RAW/$GITHUB_ORG/$REPO_NAME/$BRANCH/version.json" -if [[ "$SKIP_PREDIX_SERVICES" == "false" ]]; then - QUICKSTART_ARGS="$QUICKSTART_ARGS -uaa -ts -psts -app-name $REPO_NAME --run-edge-app -p $SCRIPT" +if [[ "$SKIP_PREDIX_SERVICES" == "true" ]]; then + QUICKSTART_ARGS="$QUICKSTART_ARGS $SCRIPT -uaa -ts -psts --run-edge-app -repo-name $REPO_NAME -app-name $DOCKER_STACK_NAME" else - QUICKSTART_ARGS="$QUICKSTART_ARGS -app-name $REPO_NAME --run-edge-app -p $SCRIPT" + PS_MODEL="sample-data/predix-asset/Compressor-CMMS-Compressor-2018-Scaled.json" + QUICKSTART_ARGS="$QUICKSTART_ARGS $SCRIPT -uaa -ts -psts -psmodel $PS_MODEL --run-edge-app -repo-name $REPO_NAME -app-name $DOCKER_STACK_NAME" fi function check_internet() { @@ -134,31 +135,35 @@ fi getPredixScripts #clone the repo itself if running from oneclick script -rm -rf predix-scripts/$REPO_NAME getCurrentRepo -docker images +if ! [ -d "$logDir" ]; then + mkdir "$logDir" + chmod 744 "$logDir" +fi +########### custom logic starts here ########### if [[ "$BUILD_APP" == "true" ]]; then cd $PREDIX_SCRIPTS/$REPO_NAME + dockerVersion=$(grep version Dockerfile | awk -F"=" '{print $2}' | tr -d "\"") + echo "$dockerVersion" docker build --build-arg HTTP_PROXY --build-arg HTTPS_PROXY --build-arg http_proxy --build-arg https_proxy -t predixedge/predix-edge-sample-scaler-go:latest . - version=$(jq -r .version version.json) - echo "version : $version" - docker tag predixedge/predix-edge-sample-scaler-go:latest predixedge/predix-edge-sample-scaler-go:${version} cd ../.. fi -echo "quickstart_args=$QUICKSTART_ARGS" -source $PREDIX_SCRIPTS/bash/quickstart.sh $QUICKSTART_ARGS -docker stack ls -docker stack services $REPO_NAME -docker ps +docker service ls +echo "" +echo "" +docker network ls +########### custom logic ends here ########### +echo "quickstart_args=$QUICKSTART_ARGS" +source $PREDIX_SCRIPTS/bash/quickstart.sh $QUICKSTART_ARGS cat $SUMMARY_TEXTFILE if [[ $SKIP_PREDIX_SERVICES == false ]]; then __append_new_line_log "To see the data in the cloud, using a browser, open the Front-end App URL shown above. With login=app_user_1, password=App_User_111" "$quickstartLogDir" fi __append_new_line_log "" "$logDir" -__append_new_line_log "Successfully completed Edge Sample Scaler Go installation!" "$quickstartLogDir" +__append_new_line_log "Successfully completed $APP_NAME installation!" "$quickstartLogDir" __append_new_line_log "" "$logDir" diff --git a/scripts/quickstart-package.sh b/scripts/quickstart-package.sh index 1af14ef..654ad35 100755 --- a/scripts/quickstart-package.sh +++ b/scripts/quickstart-package.sh @@ -69,12 +69,6 @@ SCRIPT_LOC="$GITHUB_RAW/$GITHUB_ORG/$REPO_NAME/$BRANCH/scripts/$SCRIPT_NAME" VERSION_JSON_URL="$GITHUB_RAW/$GITHUB_ORG/$REPO_NAME/$BRANCH/version.json" -#if [[ "$SKIP_PREDIX_SERVICES" == "false" ]]; then -# QUICKSTART_ARGS="$QUICKSTART_ARGS --run-edge-app -p $SCRIPT" -#else -# QUICKSTART_ARGS="$QUICKSTART_ARGS -uaa -ts -psts --run-edge-app -p $SCRIPT" -#fi - function check_internet() { set +e echo "" diff --git a/src/app.go b/src/app.go index 47d6e71..543eb7b 100644 --- a/src/app.go +++ b/src/app.go @@ -72,7 +72,7 @@ var defaultMessageHandler MQTT.MessageHandler = func(client MQTT.Client, msg MQT doubleData = doubleData * 1000 //put datapoint back into data m.Body[i].Datapoints[0][1] = doubleData - //m.Body[0].Name = tagName + ".scaled_by_1000" //Rename tag + m.Body[i].Name = m.Body[i].Name + ".scaled_x_1000" //Rename tag fmt.Println("Changed data for "+m.Body[i].Name) } } diff --git a/version.json b/version.json index 0eade2d..b7dfe0d 100644 --- a/version.json +++ b/version.json @@ -1,14 +1,14 @@ { "name": "Predix Edge Sample Scaler Go", - "version": "1.0.3", + "version": "1.0.4", "private": true, "dependencies": { "local-setup": "https://github.com/PredixDev/local-setup#1.0.106", - "predix-scripts": "https://github.com/PredixDev/predix-scripts#1.1.231", - "predix-webapp-starter": "https://github.com/PredixDev/predix-webapp-starter.git#2.0.80", + "predix-scripts": "https://github.com/PredixDev/predix-scripts#1.1.241", + "predix-webapp-starter": "https://github.com/PredixDev/predix-webapp-starter.git#2.0.92", "predix-edge-broker": "https://artifactory.predix.io/artifactory/PREDIX-EXT/predix-edge/2_1_0/os/predix-edge-broker-amd64-20180917-1.0.2.tar.gz#", "opcua": "https://artifactory.predix.io/artifactory/PREDIX-EXT/predix-edge/2_1_0/apps/adapters/predix-edge-opc-ua-adapter-amd64-20181002-1.1.0.tar.gz#", - "predix-edge-sample-scaler-go": "https://github.com/PredixDev/predix-edge-sample-scaler-go.git#1.0.3", + "predix-edge-sample-scaler-go": "https://github.com/PredixDev/predix-edge-sample-scaler-go.git#1.0.4", "cloud_gateway": "https://artifactory.predix.io/artifactory/PREDIX-EXT/predix-edge/2_1_0/apps/gateway/predix-edge-cloud-gateway-amd64-20181002-1.1.0.tar.gz#" }, "author": "gedesigntech"