Skip to content

Commit

Permalink
Updates after review
Browse files Browse the repository at this point in the history
Also some changes needed to make devcontainer work
  • Loading branch information
erikbosch committed Oct 24, 2024
1 parent d1cfc09 commit 3ad123e
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 58 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ RUN apt-get update && apt-get install -y ca-certificates openssl git curl golang
latest) \
export VERSION=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4)}') ;;\
esac && \
echo ${VERSION} && \
echo Wanted Hugo version is ${VERSION} && \
case $(uname -m) in \
aarch64) \
export ARCH=ARM64 ;; \
*) \
export ARCH=64bit ;; \
esac && \
echo ${ARCH} && \
echo Wanted Architecture is ${ARCH} && \
wget -O ${VERSION}.tar.gz https://github.com/gohugoio/hugo/releases/download/v${VERSION}/${VARIANT}_${VERSION}_Linux-${ARCH}.tar.gz && \
tar xf ${VERSION}.tar.gz && \
mv hugo /usr/bin/hugo
Expand Down
4 changes: 3 additions & 1 deletion .devcontainer/scripts/postCreateCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ export NODE_PATH=$NODE_PATH:`npm root -g`
npm install -g npm
npm install -g postcss postcss-cli autoprefixer
npm install
hugo mod get -u github.com/google/docsy@v0.6.0
hugo mod get -u github.com/google/docsy@v0.11.0

# install pre-commit
sudo apt update
sudo apt install -y python3-pip
pip install pre-commit==3.6.0 --break-system-packages

# add repo to git safe.directory & fix hugo issue with server start
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ jobs:
hugo-version: "0.123.3"
extended: true

- name: Verify that devcontainer works
run: |
cd .devcontainer
docker buildx build -f Dockerfile -t test:latest .
- name: Build
run: |
export NODE_PATH=$NODE_PATH:`npm root -g`
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ This repository contains the source code for the Velocitas Documentation.

## Building documentation locally

If using Debian you could install Hugo like this:
### Using Devcontainer

Velocitas-docs provides a [Devcontainer](https://code.visualstudio.com/docs/devcontainers/containers) that can be used to build and run the documentation server locally.
As the last step when starting the devcontainer the webserver is started, and it is reachable outside Devcontainer.
If you update source pages the local server will be automatically updated.

`Web Server is available at http://localhost:1313/velocitas/ (bind address 127.0.0.1)`

### Using Native Envioronment

It is also possible to build and run the documentation outside the Devcontainer. If using Debian you could install Hugo like this:

`sudo apt install hugo`

Expand All @@ -31,6 +41,12 @@ The Velocitas Documentation Site is not automatically updated when something is
Instead a Velocitas committer needs to manually run the `Publish Documentation` workflow.
That results in that the `docs` branch is updated and triggers the `pages-build-deployment` workflow that publishes the new version to the Velocitas Documentation Site.

## Theme Upgrade

Velocitas-docs use the [Docsy Theme](https://github.com/google/docsy).
To upgrade change version in [postCreateCommand.sh](.devcontainer/scripts/postCreateCommand.sh). Then rebuild the devcontainer.
This will result in that `go.mod`and `go.sum` gets updated.

## Community

- [GitHub Issues](https://github.com/eclipse-velocitas/velocitas-docs/issues)
Expand Down
11 changes: 6 additions & 5 deletions content/en/docs/tutorials/grpc_service_generation/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ The setup used for the examples have been as followed:
* One Velocitas Devcontainer running the Server, based on the [Vehicle App C++ Template](https://github.com/eclipse-velocitas/vehicle-app-cpp-template).
* Databroker running on localhost.

For this to work the `.devcontainer/devcontainer.json` were changed. In the setup `--network=host` were added to allow the containers
to use the host network, and for the server `forwardPorts": [ 5555 ]` were used to forward port 5555.
For this to work the `.devcontainer/devcontainer.json` was changed.
In the setup `--network=host` was added to allow the containers to use the host network,
and for the server `forwardPorts": [ 5555 ]` was used to forward port 5555.

```
"forwardPorts": [ 5555 ],
Expand All @@ -49,10 +50,10 @@ Note that changes to `.devcontainer/devcontainer.json` may be overwritten when `
To run the examples the following actions needs to be performed in the following order:

* Databroker needs to be started.
If using a Databroker on host make sure that it is compatible with the Velocitas version you are using.
If using a Databroker on host make sure that it is compatible with the Velocitas version you are using
The catalog used must also be compatible with the signals used in the example
* With a Databroker Client ([Kuksa Python Client](https://pypi.org/project/kuksa-client/) or [Databroker CLI](https://github.com/eclipse-kuksa/kuksa-databroker)) set the current value of `Vehicle.Cabin.Seat.Row1.DriverSide.Position` to a valid value, for example 12.
* Set the current value of `Vehicle.Cabin.Seat.Row1.DriverSide.Position` to a valid value, for example 12, using a Databroker Client ([Kuksa Python Client](https://pypi.org/project/kuksa-client/) or [Databroker CLI](https://github.com/eclipse-kuksa/kuksa-databroker))
* Start the server
* Start the client
* Verify that no (unexpected) errors are reported
* Using the Databroker Client, verify that the target value of `Vehicle.Cabin.Seat.Row1.DriverSide.Position` has been set to 75.
* Use the Databroker Client to verify that the target value of `Vehicle.Cabin.Seat.Row1.DriverSide.Position` has been set to 75
21 changes: 9 additions & 12 deletions content/en/docs/tutorials/grpc_service_generation/create_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ description: >
Learn how to create a client for a service definition.
---


# Introduction

This example is based on that you have used the [Velocitas App C++ Template](https://github.com/eclipse-velocitas/vehicle-app-cpp-template) to create a new repository,
and now you want to modify it to act as a client.
This example assumes that you have used the [Velocitas App C++ Template](https://github.com/eclipse-velocitas/vehicle-app-cpp-template) to create a new repository and now want to modify it to be a grpc service client.
The example files can also be found in the [Github repository](https://github.com/eclipse-velocitas/velocitas-docs/examples/grpc_client).

# Velocitas components
Expand All @@ -29,8 +27,8 @@ Below is the minimum set needed in `.velocitas.json` if deploying Databroker on

## App configuration

In the `AppManifest.json` file you need to specify which interfaces your App want to use or provide.
In this case it declares that it want to use `Move` and `CurrentPosition` from the Seats service defined in `seats.proto`.
In the `AppManifest.json` file you need to specify which interfaces your App wants to use or provide.
In this case it declares that it wants to use `Move` and `CurrentPosition` from the Seats service defined in `seats.proto`.


```json
Expand All @@ -53,22 +51,22 @@ In this case it declares that it want to use `Move` and `CurrentPosition` from t
}
```


## File Generation

When rebuilding the devcontainer with the configuration no new files will appear in your repository,
but the SDK has been updated in the background so you can use it in the file containing `main()`.
You can also regenerate the SDK with the `(Re-)generate gRPC SDKs` task.

## Launcher.cpp

You need to add a file that implement the client behavior, in this example called `Launcher.cpp`.
You need to add `Launcher.cpp` to `src/CMakeLists.txt`.
You need to have a file that implements the client behavior,
in this example we modify the file `Launcher.cpp` that already exist in the [template](https://github.com/eclipse-velocitas/vehicle-app-cpp-template).

The logic of the example client is simple. It tries to set the target position for the seat and if it
succeeds it tries to read current position.

``` cpp
include <sdk/middleware/Middleware.h>
#include <sdk/middleware/Middleware.h>
#include <services/seats/SeatsServiceClientFactory.h>
#include <services/seats/seats.grpc.pb.h>

Expand Down Expand Up @@ -124,7 +122,7 @@ int main(int argc, char** argv) {
auto status_curr_pos = serviceClient->CurrentPosition(&context, request, &response);
std::cout << "gRPC Server returned code: " << status_curr_pos.error_code() << std::endl;
std::cout << "gRPC error message: " << status_curr_pos.error_message().c_str() << std::endl;
if (status.error_code() == ::grpc::StatusCode::OK)
if (status_curr_pos.ok())
std::cout << "current Position:" << response.seat().position().base() << std::endl;
return 0;
}
Expand All @@ -134,8 +132,7 @@ int main(int argc, char** argv) {
## Building and Running
To (re-)build the App after changing the code you can use the [build script](https://github.com/eclipse-velocitas/vehicle-app-cpp-template/blob/main/build.sh).
As preparation for running you must also set two environment variables to indicate where the address/port of the
server.
As preparation for running you must also set an environment variables to define the address/port of the server.
```bash
./build.sh
Expand Down
80 changes: 61 additions & 19 deletions content/en/docs/tutorials/grpc_service_generation/create_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ description: >

# Introduction

This example is based on that you have used the [Velocitas App C++ Template](https://github.com/eclipse-velocitas/vehicle-app-cpp-template) to create a new repository,
and now you want to modify it to act as a client.
This example assumes that you have used the [Velocitas App C++ Template](https://github.com/eclipse-velocitas/vehicle-app-cpp-template) to create a new repository and now want to modify it to be a grpc service client.
The example files can also be found in the [Github repository](https://github.com/eclipse-velocitas/velocitas-docs/examples/grpc_server).

## Velocitas components
Expand All @@ -30,9 +29,9 @@ Below is the minimum set needed in `.velocitas.json` if deploying Databroker on

## App configuration

In the `AppManifest.json` file you need to specify which interfaces your App want to use or provide.
In this case it declares that it want to implement everything from the Seats service defined in `seats.proto`,
and that it want write access to the VSS signal `Vehicle.Cabin.Seat.Row1.DriverSide.Position`.
In the `AppManifest.json` file you need to specify which interfaces your server will provide.
If it require access to signals in Databroker it must also be specified.
In this case it declares to implement everything from the Seats service defined in `seats.proto` and that it needs write access to the VSS signal `Vehicle.Cabin.Seat.Row1.DriverSide.Position`.

```json

Expand Down Expand Up @@ -71,21 +70,64 @@ When rebuilding the devcontainer with the configuration above two files will be
* `SeatsServiceImpl.cpp`
* `SeatsServiceImpl.h`

They contain the stub for the server. You need to fill in the actual implementation of the services.
They contain the stubs for the server. You still need to fill in the actual implementation of the services.

## SeatsServiceImpl.h

The service will access the vehicle model, in this tutorial we manage that by adding a private class variable `vehicle`
to the file `SeatsServiceImpl.h`

```cpp
#ifndef VELOCITAS_SERVICE_IMPL_Seats_H
#define VELOCITAS_SERVICE_IMPL_Seats_H

#include "vehicle/Vehicle.hpp"
#include <grpc/grpc.h>
#include <services/seats/seats.grpc.pb.h>

namespace velocitas {

class SeatsService final : public sdv::edge::comfort::seats::v1::Seats::Service {
public:
SeatsService(){};
virtual ~SeatsService(){};

// <auto-generated>
::grpc::Status Move(::grpc::ServerContext* context,
const ::sdv::edge::comfort::seats::v1::MoveRequest* request,
::sdv::edge::comfort::seats::v1::MoveReply* response) override;
::grpc::Status
MoveComponent(::grpc::ServerContext* context,
const ::sdv::edge::comfort::seats::v1::MoveComponentRequest* request,
::sdv::edge::comfort::seats::v1::MoveComponentReply* response) override;
::grpc::Status
CurrentPosition(::grpc::ServerContext* context,
const ::sdv::edge::comfort::seats::v1::CurrentPositionRequest* request,
::sdv::edge::comfort::seats::v1::CurrentPositionReply* response) override;
// </auto-generated>

private:
vehicle::Vehicle vehicle;
};

} // namespace velocitas

#include "SeatsServiceImpl.cpp"

#endif // VELOCITAS_SERVICE_IMPL_Seats_H
```


## SeatsServiceImpl.cpp

In the file `SeatsServiceImpl.cpp` we need to implement the services.
In this example we only implement two of them.
The example also show basic error handling.
The example also shows basic error handling.

The business logic of the server is to wait for `Move` and `CurrentPosition` requests, and when received
just forward the request to the Databroker and return the result.
You do not need to add `SeatsServiceImpl.cpp` to `src/CMakeLists.txt`
as the header includes the *.cpp file and th header file will be included from `Launcher.cpp`.
The business logic of the server is to wait for `Move` and `CurrentPosition` requests and when received just forward the request to the Databroker and return the result.
You do not need to add `SeatsServiceImpl.cpp` to `src/CMakeLists.txt` as the header includes the *.cpp file and the header file will be included in the `Launcher.cpp`.

``` cpp
```cpp
#include "SeatsServiceImpl.h"
#include <sdk/VehicleApp.h>
#include <sdk/VehicleModelContext.h>
Expand All @@ -108,8 +150,7 @@ namespace velocitas {

try {
auto status =
m_vehicleModel->Cabin.Seat.Row1.DriverSide.Position.set(seat.position().base())
->await();
vehicle.Cabin.Seat.Row1.DriverSide.Position.set(seat.position().base())->await();

if (status.ok()) {

Expand Down Expand Up @@ -153,7 +194,7 @@ SeatsService::MoveComponent(::grpc::ServerContext*
auto seat = response->mutable_seat();
auto seat_position = seat->mutable_position();
try {
auto seatPos = m_vehicleModel->Cabin.Seat.Row1.DriverSide.Position.get()->await().value();
auto seatPos = vehicle.Cabin.Seat.Row1.DriverSide.Position.get()->await().value();

std::cout << "Success!!" << std::endl;
seat_position->set_base(seatPos);
Expand All @@ -178,10 +219,11 @@ SeatsService::MoveComponent(::grpc::ServerContext*
## Launcher.cpp
In addition to the `SeatsServiceImpl.cpp` file we also need a file that starts the server,
in this example called `Launcher.cpp`. It has very simple logic, it only starts the service and
You need to have a file that that starts the server,
in this example we modify the file `Launcher.cpp` that already exist in the [template](https://github.com/eclipse-velocitas/vehicle-app-cpp-template).
It has very simple logic, it only starts the service and
waits until the service shuts down, if ever.
You need to add `Launcher.cpp` to `src/CMakeLists.txt`.
``` cpp
#include "SeatsServiceImpl.h"
Expand Down Expand Up @@ -214,7 +256,7 @@ int main(int argc, char** argv) {
## Building and Running

To (re-)build the App after changing the code you can use the [build script](https://github.com/eclipse-velocitas/vehicle-app-cpp-template/blob/main/build.sh).
As preparation for running you must also set two environment variables to indicate where the address/port of the
As preparation for running you must also set two environment variables to define where the address/port of the
server and the Databroker.

```bash
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc_client/src/Launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int main(int argc, char** argv) {
auto status_curr_pos = serviceClient->CurrentPosition(&context, request, &response);
std::cout << "gRPC Server returned code: " << status_curr_pos.error_code() << std::endl;
std::cout << "gRPC error message: " << status_curr_pos.error_message().c_str() << std::endl;
if (status.error_code() == ::grpc::StatusCode::OK)
if (status_curr_pos.ok())
std::cout << "current Position:" << response.seat().position().base() << std::endl;
return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions examples/grpc_server/src/Launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ int main(int argc, char** argv) {
velocitas::VehicleModelContext::getInstance().setVdbc(
velocitas::IVehicleDataBrokerClient::createInstance("vehicledatabroker"));

vehicle::Vehicle vehicle;

auto seatServer = SeatsServiceServerFactory::create(Middleware::getInstance(), seatsImpl);

seatServer->Wait();
Expand Down
5 changes: 2 additions & 3 deletions examples/grpc_server/src/SeatsServiceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ ::grpc::Status SeatsService::Move(::grpc::ServerContext*

try {
auto status =
m_vehicleModel->Cabin.Seat.Row1.DriverSide.Position.set(seat.position().base())
->await();
vehicle.Cabin.Seat.Row1.DriverSide.Position.set(seat.position().base())->await();

if (status.ok()) {

Expand Down Expand Up @@ -81,7 +80,7 @@ ::grpc::Status SeatsService::CurrentPosition(
auto seat = response->mutable_seat();
auto seat_position = seat->mutable_position();
try {
auto seatPos = m_vehicleModel->Cabin.Seat.Row1.DriverSide.Position.get()->await().value();
auto seatPos = vehicle.Cabin.Seat.Row1.DriverSide.Position.get()->await().value();

std::cout << "Success!!" << std::endl;
seat_position->set_base(seatPos);
Expand Down
19 changes: 13 additions & 6 deletions examples/grpc_server/src/SeatsServiceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,25 @@ namespace velocitas {

class SeatsService final : public sdv::edge::comfort::seats::v1::Seats::Service {
public:
SeatsService() { m_vehicleModel = std::make_shared<vehicle::Vehicle>(); }
SeatsService(){};
virtual ~SeatsService(){};

// <auto-generated>
::grpc::Status Move(::grpc::ServerContext* context, const ::sdv::edge::comfort::seats::v1::MoveRequest* request, ::sdv::edge::comfort::seats::v1::MoveReply* response) override;
::grpc::Status MoveComponent(::grpc::ServerContext* context, const ::sdv::edge::comfort::seats::v1::MoveComponentRequest* request, ::sdv::edge::comfort::seats::v1::MoveComponentReply* response) override;
::grpc::Status CurrentPosition(::grpc::ServerContext* context, const ::sdv::edge::comfort::seats::v1::CurrentPositionRequest* request, ::sdv::edge::comfort::seats::v1::CurrentPositionReply* response) override;
::grpc::Status Move(::grpc::ServerContext* context,
const ::sdv::edge::comfort::seats::v1::MoveRequest* request,
::sdv::edge::comfort::seats::v1::MoveReply* response) override;
::grpc::Status
MoveComponent(::grpc::ServerContext* context,
const ::sdv::edge::comfort::seats::v1::MoveComponentRequest* request,
::sdv::edge::comfort::seats::v1::MoveComponentReply* response) override;
::grpc::Status
CurrentPosition(::grpc::ServerContext* context,
const ::sdv::edge::comfort::seats::v1::CurrentPositionRequest* request,
::sdv::edge::comfort::seats::v1::CurrentPositionReply* response) override;
// </auto-generated>

private:
// vehicle::Vehicle vehicle;
std::shared_ptr<vehicle::Vehicle> m_vehicleModel;
vehicle::Vehicle vehicle;
};

} // namespace velocitas
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/eclipse-velocitas/velocitas-docs

go 1.13

require github.com/google/docsy v0.6.0 // indirect
require (
github.com/google/docsy v0.11.0 // indirect
github.com/google/docsy/dependencies v0.7.2 // indirect
)
Loading

0 comments on commit 3ad123e

Please sign in to comment.