tutorials distributed calculator fix (#727)

* tutorials distributed calculator fix

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>

* Removed debugger statement

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>

* Removed some expected lines

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>

* Removed distributed calculator from the workflow

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>

* Changed go dapr command

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>

* Added distributed calculator back to the workflow

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>

* README changes

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>

* README changes in the curl commands

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>

* Added back the whole string

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>

* Reverting the changes for the curl commands

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>

* Added console log statements

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>

* Added missing link to flask

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>
This commit is contained in:
amulyavarote 2022-08-24 10:14:28 -07:00 committed by GitHub
parent 9ab0a6d0b3
commit 694830d8d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 88 additions and 42 deletions

View File

@ -3,7 +3,7 @@
This quickstart shows method invocation and state persistent capabilities of Dapr through a distributed calculator where each operation is powered by a different service written in a different language/framework:
- **Addition**: Go [mux](https://github.com/gorilla/mux) application
- **Multiplication**: Python [flask](https://flask.palletsprojects.com/en/1.0.x/) application
- **Multiplication**: Python [flask](https://flask.palletsprojects.com/en/2.2.x/) application
- **Division**: Node [Express](https://expressjs.com/) application
- **Subtraction**: [.NET Core](https://docs.microsoft.com/en-us/dotnet/core/) application
@ -41,7 +41,7 @@ These instructions start the four calculator operator apps (add, subtract, multi
1. Add App - Open a terminal window and navigate to the go directory and follow the steps below:
<!-- STEP
name: "Build go app"
name: "Install the gorilla/mux"
working_dir: "./go"
-->
@ -49,6 +49,14 @@ working_dir: "./go"
```bash
go get -u github.com/gorilla/mux
```
<!-- END_STEP -->
<!-- STEP
name: "Build go app"
working_dir: "./go"
-->
- Build the app. Run:
```bash
go build .
@ -72,7 +80,7 @@ sleep: 2
- Run dapr using the command:
```bash
dapr run --app-id addapp --app-port 6000 --dapr-http-port 3503 ./app
dapr run --app-id addapp --app-port 6000 --dapr-http-port 3503 go run app.go
```
<!-- END_STEP -->
@ -239,7 +247,7 @@ sleep: 15
- Start Dapr using command below:
```bash
dapr run --app-id frontendapp --app-port 8080 --dapr-http-port 3500 node server.js
dapr run --app-id frontendapp --app-port 8080 --dapr-http-port 3507 node server.js
```
<!-- END_STEP -->
@ -531,7 +539,6 @@ expected_stdout_lines:
- "18"
- "1.5294"
- "1768"
- '"total":"54"'
output_match_mode: substring
name: "Curl test"
-->
@ -552,6 +559,17 @@ curl -s http://localhost:8000/calculate/divide -H Content-Type:application/json
curl -s http://localhost:8000/calculate/multiply -H Content-Type:application/json --data @operands.json
```
<!-- END_STEP -->
<!-- STEP
expected_stdout_lines:
- '"total":"54"'
output_match_mode: substring
name: "Curl test"
sleep: 2
timeout_seconds: 10
-->
```bash
curl -s http://localhost:8000/persist -H Content-Type:application/json --data @persist.json
```
@ -580,16 +598,16 @@ You should get the following output:
<!-- STEP
name: Cleanup kubernetes
expected_stdout_lines:
- 'configuration.dapr.io "appconfig" deleted'
- 'deployment.apps "subtractapp" deleted'
- 'deployment.apps "addapp" deleted'
- 'deployment.apps "divideapp" deleted'
- 'deployment.apps "multiplyapp" deleted'
- 'service "calculator-front-end" deleted'
- 'deployment.apps "calculator-front-end" deleted'
- 'component.dapr.io "statestore" deleted'
working_dir: "./deploy"
expected_stdout_lines:
- configuration.dapr.io "appconfig" deleted
- deployment.apps "subtractapp" deleted
- deployment.apps "addapp" deleted
- deployment.apps "divideapp" deleted
- deployment.apps "multiplyapp" deleted
- service "calculator-front-end" deleted
- deployment.apps "calculator-front-end" deleted
- component.dapr.io "statestore" deleted
-->
```bash

View File

@ -21,7 +21,7 @@
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/subtract",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"applicationUrl": "https://localhost:7001;http://localhost:7000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}

View File

@ -15,4 +15,4 @@
"devDependencies": {
"concurrently": "^4.0.1"
}
}
}

View File

@ -22,51 +22,75 @@ The following routes forward requests (using pipe) from our React client to our
*/
app.post('/calculate/add', async (req, res) => {
// Invoke Dapr add app
const appResponse = await axios.post(`${daprUrl}/addapp/method/add`, req.body);
try {
// Invoke Dapr add app
const appResponse = await axios.post(`${daprUrl}/addapp/method/add`, req.body);
// Return expected string result to client
return res.send(`${appResponse.data}`);
// Return expected string result to client
return res.send(`${appResponse.data}`);
} catch (err) {
console.log(err);
}
});
app.post('/calculate/subtract', async (req, res) => {
// Invoke Dapr subtract app
const appResponse = await axios.post(`${daprUrl}/subtractapp/method/subtract`, req.body);
// Return expected string result to client
return res.send(`${appResponse.data}`);
try {
// Invoke Dapr subtract app
console.log("subtract app** 1")
const appResponse = await axios.post(`${daprUrl}/subtractapp/method/subtract`, req.body);
console.log("subtract app** 2")
// Return expected string result to client
return res.send(`${appResponse.data}`);
} catch (err) {
console.log(err);
}
});
app.post('/calculate/multiply', async (req, res) => {
// Dapr invoke multiply app
const appResponse = await axios.post(`${daprUrl}/multiplyapp/method/multiply`, req.body);
try {
// Dapr invoke multiply app
const appResponse = await axios.post(`${daprUrl}/multiplyapp/method/multiply`, req.body);
// Return expected string result to client
return res.send(`${appResponse.data}`);
// Return expected string result to client
return res.send(`${appResponse.data}`);
} catch (err) {
console.log(err);
}
});
app.post('/calculate/divide', async (req, res) => {
// Dapr invoke divide app
const appResponse = await axios.post(`${daprUrl}/divideapp/method/divide`, req.body);
try {
// Dapr invoke divide app
const appResponse = await axios.post(`${daprUrl}/divideapp/method/divide`, req.body);
// Return expected string result to client
return res.send(`${appResponse.data}`);
// Return expected string result to client
return res.send(`${appResponse.data}`);
} catch (err) {
console.log(err);
}
});
// Forward state retrieval to Dapr state endpoint
app.get('/state', async (req, res) => {
// Getting Dapr state
const apiResponse = await axios.get(`${stateUrl}/calculatorState`);
try {
// Getting Dapr state
const apiResponse = await axios.get(`${stateUrl}/calculatorState`);
return res.send(apiResponse.data);
return res.send(apiResponse.data);
} catch (err) {
console.log(err);
}
});
// Forward state persistence to Dapr state endpoint
app.post('/persist', async (req, res) => {
// Saving Dapr state
const apiResponse = await axios.post(stateUrl, req.body);
return res.send(apiResponse.data);
try {
// Saving Dapr state
const apiResponse = await axios.post(stateUrl, req.body);
return res.send(apiResponse.data);
} catch (err) {
console.log(err);
}
});
// Serve static files
@ -74,7 +98,11 @@ app.use(express.static(path.join(__dirname, 'client/build')));
// For default home request route to React client
app.get('/', async function (_req, res) {
return await res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
try {
return await res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
} catch (err) {
console.log(err);
}
});
app.listen(process.env.PORT || port, () => console.log(`Listening on port ${port}!`));

View File

@ -506,7 +506,7 @@ expected_stdout_lines:
- "C: Message on C"
expected_stderr_lines:
output_match_mode: substring
sleep: 5
sleep: 10
-->
```bash