|
| 1 | +# run this in the DigitalTwin directory |
| 2 | +# these should not be shared outside oracle |
| 3 | +source ../OCISetup/OCIDs.sh |
| 4 | + |
| 5 | +# change these names as required |
| 6 | +export IOT_DOMAIN_GROUP_NAME=iot-domain-group-timg |
| 7 | +export IOT_DOMAIN_NAME=iot-domain-timg |
| 8 | + |
| 9 | + |
| 10 | +export DIGITAL_TWIN_MODEL_NAME=testmodel |
| 11 | +export DIGITAL_TWIN_MODEL_FILE_NAME=testmodel.json |
| 12 | +export DIGITAL_TWIN_MODEL_FILE=file://$DIGITAL_TWIN_MODEL_FILE_NAME |
| 13 | + |
| 14 | +export DIGITAL_TWIN_ADAPTOR_ROUTE_MAPPINGS_FILE=file://testadapter.json |
| 15 | +export DIGITAL_TWIN_ADAPTOR_ENVELOPE_MAPPINGS_FILE=file://testenvelope.json |
| 16 | +export DIGITAL_TWIN_ADAPTER_NAME=testadapter |
| 17 | + |
| 18 | +if [[ -z "$IOT_COMPARTMENT_OCID" ]] |
| 19 | +then |
| 20 | + echo "IOT_COMPARTMENT_OCID is not set, this should contain the compartment ocid that contains the IOT domain group and other resources" |
| 21 | +fi |
| 22 | + |
| 23 | +export IOT_DOMAIN_GROUP_OCID=`oci iot domain-group list --display-name $IOT_DOMAIN_GROUP_NAME --compartment-id $IOT_COMPARTMENT_OCID | jq -r '.data.items[]| select (."lifecycle-state" == "ACTIVE") | ."id"'` |
| 24 | +if [[ -z "$IOT_DOMAIN_GROUP_OCID" ]] |
| 25 | +then |
| 26 | + echo Creating IotDomainGroup $IOT_DOMAIN_GROUP_NAME |
| 27 | + # Create the IoT Domain Group imstructions at https://docs.oracle.com/en-us/iaas/Content/internet-of-things/create-domain-group.htm |
| 28 | + # to make sure it's in a ready state |
| 29 | + echo oci iot domain-group create --compartment-id $IOT_COMPARTMENT_OCID --display-name $IOT_DOMAIN_GROUP_NAME --wait-for-state SUCCEEDED --wait-for-state FAILED |
| 30 | + oci iot domain-group create --compartment-id $IOT_COMPARTMENT_OCID --display-name $IOT_DOMAIN_GROUP_NAME --wait-for-state SUCCEEDED --wait-for-state FAILED |
| 31 | + # get the domain group ocid (only run this once' it's created) |
| 32 | + export IOT_DOMAIN_GROUP_OCID=`oci iot domain-group list --display-name $IOT_DOMAIN_GROUP_NAME --compartment-id $IOT_COMPARTMENT_OCID | jq -r '.data.items[]| select (."lifecycle-state" == "ACTIVE") | ."id"'` |
| 33 | + # get the data host |
| 34 | + export IOT_DOMAIN_GROUP_DATA_HOST=`oci iot domain-group get --iot-domain-group-id $IOT_DOMAIN_GROUP_OCID | jq -r '.data."data-host"'` |
| 35 | + export IOT_DOMAIN_GROUP_SHORT_ID=`echo $IOT_DOMAIN_GROUP_DATA_HOST| tr '.' ' ' | awk '{print $1}'` |
| 36 | + echo Created IotDomainGroup $IOT_DOMAIN_GROUP_NAME |
| 37 | +else |
| 38 | + echo "Iot Domain Group $IOT_DOMAIN_GROUP_NAME already exists" |
| 39 | +fi |
| 40 | + |
| 41 | +export IOT_DOMAIN_OCID=`oci iot domain list --display-name $IOT_DOMAIN_NAME --compartment-id $IOT_COMPARTMENT_OCID --iot-domain-group-id $IOT_DOMAIN_GROUP_OCID | jq -r '.data.items[]| select (."lifecycle-state" == "ACTIVE") | ."id"'` |
| 42 | +if [[ -z "$IOT_DOMAIN_OCID" ]] |
| 43 | +then |
| 44 | + echo Creating IotDomain $IOT_DOMAIN_NAME |
| 45 | + #Create the IoT domain within the group |
| 46 | + echo oci iot domain create --compartment-id $IOT_COMPARTMENT_OCID --display-name $IOT_DOMAIN_NAME --iot-domain-group-id $IOT_DOMAIN_GROUP_OCID --wait-for-state SUCCEEDED --wait-for-state FAILED |
| 47 | + oci iot domain create --compartment-id $IOT_COMPARTMENT_OCID --display-name $IOT_DOMAIN_NAME --iot-domain-group-id $IOT_DOMAIN_GROUP_OCID --wait-for-state SUCCEEDED --wait-for-state FAILED |
| 48 | + # this will return on success or fail, also this may start a work request, which runs in the background, use this command to see if it's created |
| 49 | + oci iot domain list --display-name $IOT_DOMAIN_NAME --compartment-id $IOT_COMPARTMENT_OCID --iot-domain-group-id $IOT_DOMAIN_GROUP_OCID |
| 50 | + #Get the OCID we will need |
| 51 | + export IOT_DOMAIN_OCID=`oci iot domain list --display-name $IOT_DOMAIN_NAME --compartment-id $IOT_COMPARTMENT_OCID --iot-domain-group-id $IOT_DOMAIN_GROUP_OCID | jq -r '.data.items[]| select (."lifecycle-state" == "ACTIVE") | ."id"'` |
| 52 | + export IOT_DOMAIN_HOST=`oci iot domain get --iot-domain-id $IOT_DOMAIN_OCID | jq -r '.data."device-host"'` |
| 53 | + export IOT_DOMAIN_SHORT_ID=`echo $IOT_DOMAIN_HOST| tr '.' ' ' | awk '{print $1}'` |
| 54 | + echo Created IotDomain $IOT_DOMAIN_NAME |
| 55 | +else |
| 56 | + echo "Iot Domain $IOT_DOMAIN_NAME already exists" |
| 57 | +fi |
| 58 | + |
| 59 | + |
| 60 | +export DIGITAL_TWIN_MODEL_ID=`oci iot digital-twin-model list --iot-domain-id $IOT_DOMAIN_OCID --display-name $DIGITAL_TWIN_MODEL_NAME | jq -r '.data.items[]| select (."lifecycle-state" == "ACTIVE") | ."id"'` |
| 61 | +if [[ -z "$DIGITAL_TWIN_MODEL_ID" ]] |
| 62 | +then |
| 63 | + echo Creating Digital Twin Model $DIGITAL_TWIN_MODEL_NAME |
| 64 | + # Create the digtal twin model for the generic home battery, run from within the DigitalTwin folder |
| 65 | + echo oci iot digital-twin-model create --iot-domain-id $IOT_DOMAIN_OCID --display-name $DIGITAL_TWIN_MODEL_NAME --spec $DIGITAL_TWIN_MODEL_FILE --wait-for-state ACTIVE |
| 66 | + oci iot digital-twin-model create --iot-domain-id $IOT_DOMAIN_OCID --display-name $DIGITAL_TWIN_MODEL_NAME --spec $DIGITAL_TWIN_MODEL_FILE --wait-for-state ACTIVE |
| 67 | + # get the id of the model you just created |
| 68 | + export DIGITAL_TWIN_MODEL_ID=`oci iot digital-twin-model list --iot-domain-id $IOT_DOMAIN_OCID --display-name $DIGITAL_TWIN_MODEL_NAME | jq -r '.data.items[]| select (."lifecycle-state" == "ACTIVE") | ."id"'` |
| 69 | + echo Created Digital Twin Model $DIGITAL_TWIN_MODEL_NAME |
| 70 | +else |
| 71 | + echo "Digital twin model $DIGITAL_TWIN_MODEL_NAME already exists" |
| 72 | +fi |
| 73 | +# and the models name |
| 74 | +export DIGITAL_TWIN_MODEL_IDENTIFIER=`cat $DIGITAL_TWIN_MODEL_FILE_NAME | jq -r '.["@id"]'` |
| 75 | + |
| 76 | + |
| 77 | +export DIGITAL_TWIN_ADAPTER_OCID=`oci iot digital-twin-adapter list --iot-domain-id $IOT_DOMAIN_OCID --display-name $DIGITAL_TWIN_ADAPTER_NAME | jq -r '.data.items[]| select (."lifecycle-state" == "ACTIVE") | ."id"'` |
| 78 | +if [[ -z "$DIGITAL_TWIN_ADAPTER_OCID" ]] |
| 79 | +then |
| 80 | + echo Creating Digital Twin adapter $DIGITAL_TWIN_ADAPTER_NAME |
| 81 | + # create the adaptor using the multiple routes file. |
| 82 | + # note that as the file contents is inlined into the JSON request then the stricture of the JSON files MUST be OK (if not you'll get missing param errors, even though you have specifried all fo the actual flags correctly |
| 83 | + echo oci iot digital-twin-adapter create --iot-domain-id $IOT_DOMAIN_OCID --digital-twin-model-id $DIGITAL_TWIN_MODEL_ID --inbound-routes $DIGITAL_TWIN_ADAPTOR_ROUTE_MAPPINGS_FILE --display-name $DIGITAL_TWIN_ADAPTER_NAME --inbound-envelope $DIGITAL_TWIN_ADAPTOR_ENVELOPE_MAPPINGS_FILE --wait-for-state ACTIVE |
| 84 | + oci iot digital-twin-adapter create --iot-domain-id $IOT_DOMAIN_OCID --digital-twin-model-id $DIGITAL_TWIN_MODEL_ID --inbound-routes $DIGITAL_TWIN_ADAPTOR_ROUTE_MAPPINGS_FILE --display-name $DIGITAL_TWIN_ADAPTER_NAME --inbound-envelope $DIGITAL_TWIN_ADAPTOR_ENVELOPE_MAPPINGS_FILE --wait-for-state ACTIVE |
| 85 | + # get the OCID of the new adaptor |
| 86 | + export DIGITAL_TWIN_ADAPTER_OCID=`oci iot digital-twin-adapter list --iot-domain-id $IOT_DOMAIN_OCID --display-name $DIGITAL_TWIN_ADAPTER_NAME | jq -r '.data.items[]| select (."lifecycle-state" == "ACTIVE") | ."id"'` |
| 87 | + echo Created Digital Twin adapter $DIGITAL_TWIN_ADAPTER_NAME |
| 88 | +else |
| 89 | + echo "Digital twin adapter $DIGITAL_TWIN_ADAPTER_NAME already exists" |
| 90 | +fi |
| 91 | +echo Remember, no digital twin instances have been created |
0 commit comments