Skip to content

Tutorials 

Getting Started with mimik Edge Cloud Engine

Setup Your Development Envrionment
For new developers, we provide a simple ‘hello world’ template for you to get started with edge microservice development with express.js like API interfaces. To use it, clone the following GitHub repository.
git clone https://github.com/edgeMicroservice/starter-microservice.git

Building a microservice 

1. Navigate to the folder of starter microservice that you have cloned, run the following command to install microservice dependencies :

npm i

2. Run the following command to build the image of the microservice. 

npm run build

3. Run the following command to pack your image file in the folder that you specify under config/default.yml 

npm run package
Deploying a microservice

– edgeSDK running on the deployment targeted device.

– Obtained edge Acess Token and associate the device from mimik-edge-cli.

– Run the following commands under the same directory of your containerized microservice file using mimik-edge-cli:

mimik-edge-cli image deploy --image={YOUR_IMAGE_PATH} --token={EDGE_ACCESS_TOKEN}

Once microservice is successfully deployed you should get a response that looks like this:

created: 1617907116
digest:  sha265:e38a0314ea4bca42802bbc315637d9db9251158494e85ece4c0d789e2ab0b191
id:      79279c04-8945-4141-8b52-2cb92b78cf43-microservice-v1
name:    microservice-v1
size:    75855
status:  successfully deployed

Now open start.json in editor of choice. It can be found in the repo.

copy the name of the microservice that you got in the response when you deployed the image.

replace {{imageName}} with the name you copied.

replace {{containerName}} with the name you copied.

replace {{YOUR_PATH}} with a path of your choosing. we recommend keeping it simple.

for example:

"MCM.BASE_API_PATH": "sample/v1",

OPTIONAL:

You can edit “add your environment variable name”: “{{add your environment variable}}” to anything of your choosing related to your development environment. If you just want to get started for now, you can remove this line from start.json Read the source code for more information on custom environment variables.

save the newly updated start.json file

navigate to where the start.json file is located via terminal

run command:

mimik-edge-cli container deploy --payload start.json --token={EDGE_ACCESS_TOKEN}
Making API requests to microservice

You can get a response from your starter microservice simply by calling an HTTP API:

Note: Replace the <MCM.BASE_API_PATH> with MCM.BASE_API_PATH from the response you get when you started your microservice from previous step.

Hint: You can also make API request to your starter microservice from your web browser or an API client like Postman. 

curl http://localhost:8083/< MCM.BASE_API_PATH>/
curl http://localhost:8083/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/sample/v1/
Expected Response:
Hello World!

Hint: You can also make API request to your starter microservice from your web browser or an API client like Postman.

Modifying microservice

You can program microservice to do all sorts of things, such as getting a list of Edge Cloud Engine-powered devices on your local network. 

Navigate to the directory of starter microservice and navigate to src directory.

Open the index.js file, go to the end of the file and add the following code to allow your microservice to retrieve your network’sEdge Cloud Engine linkLocal clustering information: 

app.get('/localDevices', (request, response) => {
context.http.request(({
url: 'http://localhost:8083/mds/v1/nodes?clusters=linkLocal',
success: function(r) {
if (!request.authorization) {
response.status = 403;
response.end(JSON.stringify({ 'msg': 'missing bearer token' }, 2, null));
return;
}
const authorization = request.authorization.split(' ');
if (authorization.length < 2) {
response.status = 403;
response.end(JSON.stringify({ 'msg': 'missing bearer token' }, 2, null));
return;
}
const token = authorization[1];
const nodes = JSON.parse(r.data);
const data = JSON.stringify(nodes.data);

context.edge.decryptEncryptedNodesJson({
type: 'local',
data,
token,
success: function(result) {
response.end(JSON.stringify(JSON.parse(result.data), null, 2));
},
error: function(err) {
response.end(err.message);
}
});
},
error: function(err) {
response.end(err.message);
}
}));
});

Save index.js, then repeat Building a microservice steps to re-build it and Deploying a microservice steps to deploy and start it.

Hint: MCM.BASE_API_PATH will not change from re-deployment since it is associated to your project on mimik developer console. 

Get the devices in your local Edge Cloud Engine cluster 

Our newly added endpoint is protected by edge Access Token, so we can only make the HTTP call programmatically from application, curl or API client. In this example, we will be using CURL:
curl -i -H 'Authorization: Bearer <edge access token>’ http://localhost:8083/<MCM.BASE_API_PATH>/localDevices
Example response:
{
  "localLinkNetwork": {
    "localLinkNetworkId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "nodes": [ // array contains all the edge nodes within your local network.
      {
        "APIVersion": "v1",
        "account": {
          "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // account ID of the edge node
          "self": ""
        },
        "addresses": [
          {
            "type": "local",
            "url": {
              "href": "http://x.x.x.x:8083" // url of the edge node
            }
          }
        ],
        "characteristics": [
          {
            "name": "cpu",
            "value": "Intel(R) Core(TM) i7-8500U" // cpu of the edge node
          },
          {
            "name": "edgeVersion",
            "value": "v2.2.0" // edgeEngine version on the edge node
          },
          {
            "name": "os",
            "value": "linux" //operating system of the edge node
          },
          {
            "name": "totalPhysicalMemory",
            "value": "2061750272" //total RAM in bits of the edge node
          },
          {
            "name": "totalStorage",
            "value": "15784157184" //total Disk space in bits of the edge node
          }
        ],
        "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // node ID of the edge node
        "networkAddress": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "rolesInCluster": [
          "superNodeLocalLinkNetwork" // the role of the edge node
        ],
        "services": [ // the edge microservices deployed on the edge node
          {
            "id": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-microservice-v1",
            "serviceType": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-microservice-v1",
            "tenant": {
              "id": "",
              "self": ""
            }
          }
        ],
        "tenant": {
          "id": "mimik|001",
          "self": ""
        }
      }
    ]
  }
}

Your feedback is important to us ~