Coder Social home page Coder Social logo

matthiasnoback / building-autonomous-services-workshop Goto Github PK

View Code? Open in Web Editor NEW
42.0 42.0 13.0 627 KB

Code and assignments for the "Building Autonomous Services" workshop module.

Home Page: https://training.matthiasnoback.nl

License: MIT License

Shell 3.43% PHP 94.64% Gherkin 1.37% Dockerfile 0.40% Hack 0.16%

building-autonomous-services-workshop's People

Contributors

blackikeeagle avatar dependabot[bot] avatar dereuromark avatar guilhermednt avatar gund avatar lisachenko avatar lucasvanlierop avatar matthiasnoback avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

building-autonomous-services-workshop's Issues

Fix assignment 2

See the fix-commit in myhammer branch. Also update the assignment: the response format of stock_web/stockLevels should be: { "productId": 10 }

[Windows] Use $(pwd -W) instead of $(pwd) when bin/install is used in GitBash

In Git Bash, $(pwd) returns the current working directory in MINGW, which looks something like "/c/building-autonomous-services-workshop", however this isn't the path we want in the bin/install script when composer install is executed.

$(pwd -W) would solve the issue.

E.g.:

# Check if the script is run in Git Bash and get working_dir accordingly.
if [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then
    working_dir=$(pwd -W)
else
    working_dir=$(pwd)
fi

# Pull Composer Docker image and run composer install
echo "Installing Composer dependencies"
docker pull composer:latest --quiet
docker run --rm --volume "$working_dir":/app:cached --user "$(id -u):$(id -g)" composer:latest \
  install \
  --ignore-platform-reqs \
  --prefer-dist \
  --no-progress

Docker fails to listen on localhost without specifying host part on MacOS

I think this is general trouble with Docker under Mac, when exposing ports in the docker-compose.yml files like this:

   ports:
        - "80:80"

Docker can bind then to any interface or ipv6 and then 127.0.0.1:80 won't be accessible. To fix this, we can use exact host:port binding long format, supported by Docker.

   ports:
        - "127.0.0.1:80:80"

Explain how to run docker without sudo

A colleague of mine ran into the problem, that he couldn't run docker without sudo.

On linux, to run docker without super user privileges, the desired user needs to be a member of the docker group.
(Tutorial: https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user)

I don't know if it is worth it to mention it in the README.

As there are already notes for windows users, there might be a place for linux users as well.

That being said, I'm happy if you want to close this without changes, as this is more of a "how to install docker" kind of thing.

Small install issue

bin/install

Pulling Docker images
Installing Composer dependencies
unknown flag: --quiet
See 'docker pull --help'.

It does seem to work none the less, but I guess that flag can be removed here.

Composer not recognized

Dear Matthias,

Apologies for the late notice.
I'm having trouble getting the project to work. I am using Windows and have already encountered some hick ups, but I don't seem to find any information to fix the latetst one I ran into:
C:\Users\jonia\building-autonomous-services-workshop>make up
process_begin: CreateProcess(NULL, uname -s, ...) failed.
process_begin: CreateProcess(NULL, id -u, ...) failed.
process_begin: CreateProcess(NULL, id -g, ...) failed.
(grep "127.0.0.1 dashboard.localhost sales.localhost purchase.localhost catalog.localhost stock.localhost" /etc/hosts) || echo '127.0.0.1 dashboard.localhost sales.localhost purchase.localhost catalog.localhost stock.localhost' | sudo tee -a /etc/hosts
127.0.0.1 dashboard.localhost sales.localhost purchase.localhost catalog.localhost stock.localhost
mkdir -p /.composer
The syntax of the command is incorrect.
make: *** [
/.composer] Fout 1

I have Docker desktop for windows and this contains the docker compose as instructed on the docker website. Do you have any tip how to solve this?

Thank you in advance.

Kind regards

Joni

Introduce Purchase Orders

  • Allow purchase orders to be created.
  • Allow purchase orders to be listed.
  • Link a goods receipt to a purchase order.

Improve assignment 5

"Since making a reservation effectively decreases the balance, it shouldn't happen again upon delivering a sales order. The Stock consumer should no longer manually decrease the balance. It should only produce the "stock level decreased" event. And it should do so upon receiving a "stock reservation accepted" event (not upon receiving a "sales order delivered" event)." - see solution to assignment 5 in mytheresa_2019: we should dispatch the other event also in the makeReservationAction().

bin/stop default argument does not find service

$ ./bin/stop                         
ERROR: No such service: 

bin/stop tries to offer a default value to stop all services. However, as the argument is enclosed in quotes, the shell will pass the empty string as an argument, as opposed to omitting the argument.

Omitting the quotes in combination with using $@ might be a solution to allow passing multiple service names.

[Bug] Balance reservations processing

As discussed during the training - the implementation of the Balance::processReceivedGoodsAndRetryRejectedReservations() method is not correct:

  1. The rejected reservation has to be moved to "accepted" reservations array
  2. The logic of finding the rejected order is not correct - it should compare it's quantity with "expected quantity of Balance" and not just quantity argument as it's simply an extra purchased goods quantity and not total balance quantity
  3. It's important to get out not only reservation ID but also it's total quantity to produce proper event - so it's better to return the whole reservation object

So the final method implementation should be:

final class Balance implements IdentifiableObject {
    public function processReceivedGoodsAndRetryRejectedReservations(int $quantity): ?Reservation
    {
        $expectedQuantity = $this->stockLevel + $quantity;

        foreach ($this->rejectedReservations as $key => $rejectedReservation) {
            if ($rejectedReservation->quantity() <= $expectedQuantity) {
                unset($this->rejectedReservations[$key]);
                $this->reservations[] = $rejectedReservation;

                // Decrease stock by reservation minus extra quantity that should be added to stock
                $this->decrease($rejectedReservation->quantity() - $quantity);

                return $rejectedReservation;
            }
        }

        $this->increase($quantity);

        return null;
    }
}

Or even simpler if we first - increase the quantity of balance and then decrease it by reservation quantity:

final class Balance implements IdentifiableObject {
    public function processReceivedGoodsAndRetryRejectedReservations(int $quantity): ?Reservation
    {
        $this->increase($quantity);

        foreach ($this->rejectedReservations as $key => $rejectedReservation) {
            if ($rejectedReservation->quantity() <= $this->stockLevel) {
                unset($this->rejectedReservations[$key]);
                $this->reservations[] = $rejectedReservation;

                $this->decrease($rejectedReservation->quantity());

                return $rejectedReservation;
            }
        }

        return null;
    }
}

P.S.: Both method implementations work in my solution =)

Make it work with latest Docker version

Somehow it doesn't pull all the required images when using Docker version 20.x
It does work on Linux. So, maybe it's a Docker Desktop issue?

  • Upgrade to latest Docker
  • Fix docker-compose setup (maybe stop using templates)

[Docs] Missing hosts binding step

After the install and start of the app - the links will not work as they are custom domains that require to set them in hosts of the OS.

So there should be a step that lists domains which should be added to the local OS hosts file:

127.0.0.1 dashboard.localtest.me
127.0.0.1 catalog.localtest.me
127.0.0.1 stock.localtest.me
127.0.0.1 sales.localtest.me
127.0.0.1 purchase.localtest.me

Also another suggestion would be to get rid of the domain names and instead expose the ports from docker containers to host OS to be able to use URLs like localhost:9001, localhost:9002, etc.

ERROR: Service '...' needs to be built, but --no-build was passed.

After running bin/start, I get the following error:

Creating network "building-autonomous-services-workshop_default" with the default driver
Creating network "building-autonomous-services-workshop_traefik" with the default driver
ERROR: Service 'catalog_php' needs to be built, but --no-build was passed.

When rerunning the command, it cycles through different services that need to be built.

Removing the --no-build flag, or separately building the containers, resolves the issue.

I don't know why you pass the --no-build flag. I assume this is for good reason. Therefore, I think the problem could be fixed in the documentation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.