Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

This scenario aims to showcase technical consumption of SAP BTP services in a non-enterprise use case. It also showcases how to use and implement WebSockets, serverless, open connectors, etc., in a Node.js application.

License

Notifications You must be signed in to change notification settings

SAP-samples/cloud-kyma-serverless-nodejs

Gamified Business Technology Platform Kyma Nodejs Application

REUSE status

⚠ ARCHIVED - NO MAINTENANCE ⚠

📢 Please be aware that this sample is no longer maintained and the repository is archived

As an alternative, we recommend to use the samples based on the SAP BTP Developer Guide.

Description

The Gamified Application is a sample Node.js application that showcases how to use and implement WebSockets, SAP BTP, serverless runtime, SAP Open Connectors and others. This application runs on the SAP BTP, Cloud Foundry environment, and the SAP BTP, Kyma environment. The current scope of the application is to demonstrate the capabilities of the SAP Event Mesh service for creating service instances, queues, subscriptions for these queue, and sending and consuming the messages through APIs.

Architecture

Solution Diagram

The Gamified Application is developed using Node.js and runs on the SAP Business Technology Platform (SAP BTP). It consumes services in SAP BTP like SAP Event Mesh and SAP Open Connectors. The events generated in the gaming backend are inserted into a queue in the Event Mesh service. The application consumes these events to calculate the game result, and the serverless function publishes the result on Twitter via the SAP Open Connectors. solution diagram

Game Flow

1. Create Room

Create Room

2. Play Game

Play Game

3. End Game

End Game

4. Publish Result

Publish Result

Requirements

  • Global account in SAP Business Technology Platform

For local development you would require the following:

Configure the Entitlements

The application requires below set of SAP Business Technology Platform entitlements and quota:

Service Plan Number of Instances
Event Mesh default 1
Kyma runtime 1
Open Connectors 1
SAP HANA Cloud 1
SAP HANA Schemas & HDI Containers hdi-shared 1

For more information, see Configure Entitlements and Quotas for Subaccounts.

Clone the GitHub Repository

  1. Clone the repository.
  2. Open a command prompt and run the command npm install.

Set Up a Subaccount in SAP BTP

  1. Enable Kyma Runtime environment.
  2. Subscribe to the SAP Open Connectors from service market place in SAP BTP Subaccount.
  3. Choose go to application to create a Twitter open connector instance. See Serverless Extensions – Part 2: Configure SAP Cloud Platform Open Connectors to connect to Whatsapp and Twitter
  4. Copy the Twitter Authorization Token and save it for later.
  5. Subscribe to the SAP Event Mesh service. See Subscribe to Event Mesh.
  6. Create SAP HANA Schemas & HDI Containers hdi-shared instance
    • Open terminal and perform the below commands:
    1. Create Hana cloud instance if you do not have one in your SAP BTP environment. You can find a tutorial for creating a HANA Cloud instance at SAP Help Portal.
      • cf create-service hana-cloud hana my_hana_db -c '{"data":{"edition":"cloud","memory":30,"systempassword":""}}'
    2. Retrieve the GUID of the Hana cloud instance (if you have mulitple Hana cloud instances)
      • cf service <hana cloud instance name> --guid
    3. create instance with hdi-shared plan
      • cf create-service hana hdi-shared BusinessPartnerValidation-db -c '{"database_id" :"<guid>"}'
    4. Copy service key
      • cf create-service-key SERVICE_INSTANCE SERVICE_KEY

Deploy the Application in the SAP BTP, Kyma Environment

  1. Generate a URL for the game by replacing host name and kyma API endpoint in the below URL:

    • "https://{host name}.{kyma API End Point}"
    • Make sure the host name and the apphost in values.yaml in line 34, both are same.
  2. Copy the generated URL and replace with the URL in src/config.js:

  3. Replace the Twitter API Endpoint URL in line 2 of serverless/twitter/handler.js.

  4. Replace the Twitter Authorization token(copied in SAP BTP setup step 5) in line 3 of serverless/twitter/handler.js.

  5. Replace the HANA hdi-shared credentials(copied in SAP BTP setup step 7) in:

  6. Run the command node src/db.js to create data model in HANA db.

  7. Delete the file src/db.js or comment all the content of src/db.js.

  8. Build Docker Image:

    • docker build --pull --rm -f "Dockerfile" -t {username}/{appname}:latest "."
    • docker push {username}/{appname}:latest
  9. Update helmcharts/values.yaml:

    • Change variable values:
      • namespace: replace with your Kyma runtime namespace.
      • Image: replace with your Docker image name.
      • apphost: replace hostname with the name that we chose for app URL.
      • giturl: upload the game in a git repositiory and paste the link in this variable.
    • Replace git username and password with your git username and passowrd in base64.
  10. Deploy The application via helm:

    • Open directory of helmcharts.
    • Use the command helm install {deployment name} ./ -n={namespace} to push the application.

Start the Game

  1. Create New Room:
    • Go to the index page and enter a room name, Number of participants(min:2 and max:5) and choose create room button.
    • Once Room is created, you will be redirected to the admin page.
    • Create Room
  2. Join The Room:
    • On the Index page, you can join any room from the Room's list.
    • You can directly Join the Room via Scanning the Room's QR code, which the Room's admin will share.
    • Create Room
  3. Start The Game:
    • Once sufficient players have joined the Room, the admin can start the game by clicking on the Start Game button.
    • If the admin wants to share the live gameBoard, the admin can click on the gameBoard button before starting the game.
  4. Play The Game:
    • Once the admin starts the game, all players can start playing the game by clicking on the screen.
    • Create Room

License

Copyright (c) 2021 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the LICENSE file.

About

This scenario aims to showcase technical consumption of SAP BTP services in a non-enterprise use case. It also showcases how to use and implement WebSockets, serverless, open connectors, etc., in a Node.js application.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •