diff --git a/cat/.DS_Store b/cat/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 Binary files /dev/null and b/cat/.DS_Store differ diff --git a/cat/Dockerfile b/cat/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..b9220815c09045364aa361bac9e5147d03602985 --- /dev/null +++ b/cat/Dockerfile @@ -0,0 +1,6 @@ +FROM golang:alpine +RUN mkdir /app +ADD . /app/ +WORKDIR /app +RUN go build . +CMD ["./ms-cat"] \ No newline at end of file diff --git a/cat/README.MD b/cat/README.MD new file mode 100644 index 0000000000000000000000000000000000000000..67dad0c0035673b5ac94f2ff3841d8aba9a9953d --- /dev/null +++ b/cat/README.MD @@ -0,0 +1,17 @@ +# Микросервис котика + +РРЅРѕРіРґР° РЅРµ понятно что должен говорить котик, +поэтому, для этого нужен http сервер, который знает правильный ответ. + +Данный микросервис позволит узнать что РіРѕРІРѕСЂРёС‚ котик + +## How-to-use +1. Cкомпилировать: +```shell +go build +``` +2. Запустить: +```shell +./ms-cat.exe +``` +3. Р’ браузере открыть: http://localhost:8080 \ No newline at end of file diff --git a/cat/cat_server.go b/cat/cat_server.go new file mode 100644 index 0000000000000000000000000000000000000000..11c54e0b2dd0ed7fa081620da3c8e3a1566f5ac1 --- /dev/null +++ b/cat/cat_server.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + "io" + "net/http" +) + +func whatCatSay(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, "Meow\n") +} + +func whoiami(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, "Cat") +} + +func main() { + http.HandleFunc("/", whatCatSay) + http.HandleFunc("/whoami", whoiami) + fmt.Printf("Try to start on port 8080") + if err := http.ListenAndServe(":8080", nil); err != nil { + fmt.Printf("An error: %s", err) + } +} diff --git a/cat/desktop.ini b/cat/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/cat/desktop.ini differ diff --git a/cat/go.mod b/cat/go.mod new file mode 100644 index 0000000000000000000000000000000000000000..b774a4f6fabe9dd575e8380848fe57a41fea787d --- /dev/null +++ b/cat/go.mod @@ -0,0 +1,3 @@ +module ms-cat + +go 1.17 diff --git a/child/.DS_Store b/child/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 Binary files /dev/null and b/child/.DS_Store differ diff --git a/child/Dockerfile b/child/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..e90b78d898a619f8b65cd73045089ed450b1dbc4 --- /dev/null +++ b/child/Dockerfile @@ -0,0 +1,6 @@ +FROM gradle:jdk17 +RUN mkdir /src +ADD . /src +WORKDIR /src +RUN gradle clean build +CMD ["java", "-jar", "./build/libs/child-0.1-all.jar"] \ No newline at end of file diff --git a/child/README.md b/child/README.md new file mode 100644 index 0000000000000000000000000000000000000000..33a04a38db2d3b63b7fd435ffa99352a5e675f52 --- /dev/null +++ b/child/README.md @@ -0,0 +1,22 @@ +# Микросервис ребёнка + +Микросервис ребёнка, который хочет понять что РіРѕРІРѕСЂСЏС‚ собачки Рё котики + +Для этого РЅСѓР¶РЅРѕ декларировать переменные среды: + +| Переменные среды | Назначение | +|------------------|------------------------------------------------| +| MS_DOG_HOST | РҐРѕСЃС‚ для микросервиса котика | +| MS_CAT_HOST | РҐРѕСЃС‚/название сервиса для микросервиса собачки | + +## РЎР±РѕСЂРєР° Рё запуск сервиса + +```shell +gradle clean build +``` + +Запуск: + +```shell +java -jar .\build\libs\child-0.1-all.jar +``` diff --git a/child/build.gradle b/child/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..aa73cc12142b788bf3e654c359d57e025aed8c10 --- /dev/null +++ b/child/build.gradle @@ -0,0 +1,45 @@ +plugins { + id("com.github.johnrengelman.shadow") version "7.1.2" + id("io.micronaut.application") version "3.5.1" +} + +version = "0.1" +group = "com.example" + +repositories { + mavenCentral() +} + +dependencies { + annotationProcessor("org.projectlombok:lombok") + annotationProcessor("io.micronaut:micronaut-http-validation") + implementation("io.micronaut:micronaut-http-client") + implementation("io.micronaut:micronaut-jackson-databind") + implementation("jakarta.annotation:jakarta.annotation-api") + compileOnly("org.projectlombok:lombok") + runtimeOnly("ch.qos.logback:logback-classic") + implementation("io.micronaut:micronaut-validation") + +} + + +application { + mainClass.set("com.example.Application") +} +java { + sourceCompatibility = JavaVersion.toVersion("17") + targetCompatibility = JavaVersion.toVersion("17") +} + +graalvmNative.toolchainDetection = false +micronaut { + runtime("netty") + testRuntime("junit5") + processing { + incremental(true) + annotations("com.example.*") + } +} + + + diff --git a/child/desktop.ini b/child/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/child/desktop.ini differ diff --git a/child/gradle.properties b/child/gradle.properties new file mode 100644 index 0000000000000000000000000000000000000000..104294cf1b4ed95ad90255ef35c921d8ee7ef47c --- /dev/null +++ b/child/gradle.properties @@ -0,0 +1 @@ +micronautVersion=3.6.1 diff --git a/child/gradle/desktop.ini b/child/gradle/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/child/gradle/desktop.ini differ diff --git a/child/gradle/wrapper/desktop.ini b/child/gradle/wrapper/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/child/gradle/wrapper/desktop.ini differ diff --git a/child/gradle/wrapper/gradle-wrapper.jar b/child/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..249e5832f090a2944b7473328c07c9755baa3196 Binary files /dev/null and b/child/gradle/wrapper/gradle-wrapper.jar differ diff --git a/child/gradle/wrapper/gradle-wrapper.properties b/child/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000000000000000000000000000000000..ae04661ee733431762e7ccf8ab9b7409ed44960c --- /dev/null +++ b/child/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/child/gradlew b/child/gradlew new file mode 100644 index 0000000000000000000000000000000000000000..a69d9cb6c20655813e44515156e7253a2a239138 --- /dev/null +++ b/child/gradlew @@ -0,0 +1,240 @@ +#!/bin/sh + +# +# Copyright В© 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions В«$varВ», В«${var}В», В«${var:-default}В», В«${var+SET}В», +# В«${var#prefix}В», В«${var%suffix}В», and В«$( cmd )В»; +# * compound commands having a testable exit status, especially В«caseВ»; +# * various built-in commands including В«commandВ», В«setВ», and В«ulimitВ». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/child/gradlew.bat b/child/gradlew.bat new file mode 100644 index 0000000000000000000000000000000000000000..f127cfd49d4024c3e1e0d08ba56399221b4fb25d --- /dev/null +++ b/child/gradlew.bat @@ -0,0 +1,91 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/child/micronaut-cli.yml b/child/micronaut-cli.yml new file mode 100644 index 0000000000000000000000000000000000000000..ef025fa782d4288e688f3a23750e4747917f49c6 --- /dev/null +++ b/child/micronaut-cli.yml @@ -0,0 +1,6 @@ +applicationType: default +defaultPackage: com.example +testFramework: junit +sourceLanguage: java +buildTool: gradle +features: [ annotation-api, app-name, gradle, http-client, jackson-databind, java, java-application, junit, logback, lombok, micronaut-build, netty-server, readme, shade, yaml ] diff --git a/child/settings.gradle b/child/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..85cf4463c54f33c5fecf3dfce6f9d43077244a76 --- /dev/null +++ b/child/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = "child" + diff --git a/child/src/desktop.ini b/child/src/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/child/src/desktop.ini differ diff --git a/child/src/main/desktop.ini b/child/src/main/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/child/src/main/desktop.ini differ diff --git a/child/src/main/java/com/desktop.ini b/child/src/main/java/com/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/child/src/main/java/com/desktop.ini differ diff --git a/child/src/main/java/com/example/Application.java b/child/src/main/java/com/example/Application.java new file mode 100644 index 0000000000000000000000000000000000000000..e13ce4318df7354f0b645f33a49958aa8660ab3d --- /dev/null +++ b/child/src/main/java/com/example/Application.java @@ -0,0 +1,9 @@ +package com.example; + +import io.micronaut.runtime.Micronaut; + +public class Application { + public static void main(String[] args) { + Micronaut.run(Application.class, args); + } +} diff --git a/child/src/main/java/com/example/config/CatConfig.java b/child/src/main/java/com/example/config/CatConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..f93c91204a727549065bee70f2503c4b301859d0 --- /dev/null +++ b/child/src/main/java/com/example/config/CatConfig.java @@ -0,0 +1,14 @@ +package com.example.config; + +import io.micronaut.context.annotation.ConfigurationProperties; +import lombok.AccessLevel; +import lombok.Data; +import lombok.experimental.FieldDefaults; + +@Data +@FieldDefaults(level = AccessLevel.PRIVATE) +@ConfigurationProperties("ms.cat") +public class CatConfig { + String host; + int port; +} diff --git a/child/src/main/java/com/example/config/DogConfig.java b/child/src/main/java/com/example/config/DogConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..17cb25af2a7854c30661c43ffc8f66fb2aa29f66 --- /dev/null +++ b/child/src/main/java/com/example/config/DogConfig.java @@ -0,0 +1,14 @@ +package com.example.config; + +import io.micronaut.context.annotation.ConfigurationProperties; +import lombok.AccessLevel; +import lombok.Data; +import lombok.experimental.FieldDefaults; + +@Data +@FieldDefaults(level = AccessLevel.PRIVATE) +@ConfigurationProperties("ms.dog") +public class DogConfig { + String host; + int port; +} diff --git a/child/src/main/java/com/example/config/desktop.ini b/child/src/main/java/com/example/config/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/child/src/main/java/com/example/config/desktop.ini differ diff --git a/child/src/main/java/com/example/controller/SimpleController.java b/child/src/main/java/com/example/controller/SimpleController.java new file mode 100644 index 0000000000000000000000000000000000000000..640f5c087f0de76a2c28eb1f09725007092a2f79 --- /dev/null +++ b/child/src/main/java/com/example/controller/SimpleController.java @@ -0,0 +1,77 @@ +package com.example.controller; + +import com.example.config.CatConfig; +import com.example.config.DogConfig; +import io.micronaut.http.MediaType; +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Get; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import lombok.experimental.FieldDefaults; +import lombok.extern.slf4j.Slf4j; + +import javax.annotation.PostConstruct; +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; + +@Controller +@Slf4j +@RequiredArgsConstructor +@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) +public class SimpleController { + static String WHOAMI_PATTERN = "http://%s:%d/whoami"; + static String BASE_PATTERN = "http://%s:%d"; + HttpClient client = HttpClient.newBuilder() + .build(); + CatConfig catConfig; + DogConfig dogConfig; + + + @Get(processes = MediaType.TEXT_PLAIN) + public String getHello() throws IOException, InterruptedException { + StringBuilder result = new StringBuilder(); + fillCat(result); + fillDog(result); + + return result.toString(); + } + + private void fillCat(StringBuilder result) throws IOException, InterruptedException { + result.append(client.send( + HttpRequest.newBuilder() + .uri(URI.create(String.format(WHOAMI_PATTERN, catConfig.getHost(), catConfig.getPort()))) + .build(), HttpResponse.BodyHandlers.ofString() + ).body().toString()); + result.append(" says "); + result.append(client.send( + HttpRequest.newBuilder() + .uri(URI.create(String.format(BASE_PATTERN, catConfig.getHost(), catConfig.getPort()))) + .build(), HttpResponse.BodyHandlers.ofString() + ).body().toString()); + result.append("\n"); + } + + private void fillDog(StringBuilder result) throws IOException, InterruptedException { + result.append(client.send( + HttpRequest.newBuilder() + .uri(URI.create(String.format(WHOAMI_PATTERN, dogConfig.getHost(), dogConfig.getPort()))) + .build(), HttpResponse.BodyHandlers.ofString() + ).body().toString()); + result.append(" says "); + result.append(client.send( + HttpRequest.newBuilder() + .uri(URI.create(String.format(BASE_PATTERN, dogConfig.getHost(), dogConfig.getPort()))) + .build(), HttpResponse.BodyHandlers.ofString() + ).body().toString()); + result.append("\n"); + } + + @PostConstruct + public void showInfo() { + log.info("Host: {}, Port: {} for cat", catConfig.getHost(), catConfig.getPort()); + log.info("Host: {}, Port: {} for dog", dogConfig.getHost(), dogConfig.getPort()); + } +} diff --git a/child/src/main/java/com/example/controller/desktop.ini b/child/src/main/java/com/example/controller/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/child/src/main/java/com/example/controller/desktop.ini differ diff --git a/child/src/main/java/com/example/desktop.ini b/child/src/main/java/com/example/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/child/src/main/java/com/example/desktop.ini differ diff --git a/child/src/main/java/desktop.ini b/child/src/main/java/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/child/src/main/java/desktop.ini differ diff --git a/child/src/main/resources/application.yml b/child/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..bcf5e9f4ca7f6b9e6b671600df12a9d62fde538a --- /dev/null +++ b/child/src/main/resources/application.yml @@ -0,0 +1,17 @@ +micronaut: + server: + port: ${SERVER_PORT:8080} + application: + name: child +netty: + default: + allocator: + max-order: 3 + +ms: + dog: + host: ${MS_DOG_HOST:localhost} + port: ${MS_DOG_PORT:8080} + cat: + host: ${MS_CAT_HOST:localhost} + port: ${MS_CAT_PORT:8080} \ No newline at end of file diff --git a/child/src/main/resources/desktop.ini b/child/src/main/resources/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/child/src/main/resources/desktop.ini differ diff --git a/child/src/main/resources/logback.xml b/child/src/main/resources/logback.xml new file mode 100644 index 0000000000000000000000000000000000000000..498c90a3e97c8cce0b21bd9a42ec31fa09ca6a4f --- /dev/null +++ b/child/src/main/resources/logback.xml @@ -0,0 +1,16 @@ +<configuration> + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <withJansi>true</withJansi> + <!-- encoders are assigned the type + ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> + <encoder> + <pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n + </pattern> + </encoder> + </appender> + + <root level="info"> + <appender-ref ref="STDOUT"/> + </root> +</configuration> diff --git a/child/src/test/desktop.ini b/child/src/test/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/child/src/test/desktop.ini differ diff --git a/child/src/test/java/com/desktop.ini b/child/src/test/java/com/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/child/src/test/java/com/desktop.ini differ diff --git a/child/src/test/java/com/example/AgregatorTest.java b/child/src/test/java/com/example/AgregatorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..93f27465835866ca994b030b29ba38fe5116edc1 --- /dev/null +++ b/child/src/test/java/com/example/AgregatorTest.java @@ -0,0 +1,21 @@ +package com.example; + +import io.micronaut.runtime.EmbeddedApplication; +import io.micronaut.test.extensions.junit5.annotation.MicronautTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; + +import jakarta.inject.Inject; + +@MicronautTest +class ChildTest { + + @Inject + EmbeddedApplication<?> application; + + @Test + void testItWorks() { + Assertions.assertTrue(application.isRunning()); + } + +} diff --git a/child/src/test/java/com/example/desktop.ini b/child/src/test/java/com/example/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/child/src/test/java/com/example/desktop.ini differ diff --git a/child/src/test/java/desktop.ini b/child/src/test/java/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/child/src/test/java/desktop.ini differ diff --git a/dog/.DS_Store b/dog/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 Binary files /dev/null and b/dog/.DS_Store differ diff --git a/dog/Dockerfile b/dog/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..ca38440674e36ad5f598c04a1fcf53db9c155cce --- /dev/null +++ b/dog/Dockerfile @@ -0,0 +1,6 @@ +FROM golang:alpine +RUN mkdir /app +ADD . /app/ +WORKDIR /app +RUN go build . +CMD ["./ms-dog"] \ No newline at end of file diff --git a/dog/README.MD b/dog/README.MD new file mode 100644 index 0000000000000000000000000000000000000000..727e509a543ee09d00756453385100c4f941b5d6 --- /dev/null +++ b/dog/README.MD @@ -0,0 +1,17 @@ +# Микросервис собачки + +РРЅРѕРіРґР° РЅРµ понятно что должен говорить собачки, +поэтому, для этого нужен http сервер, который знает правильный ответ. + +Данный микросервис позволит узнать что РіРѕРІРѕСЂРёС‚ собачка + +## How-to-use +1. Cкомпилировать: +```shell +go build +``` +2. Запустить: +```shell +./ms-dog.exe +``` +3. Р’ браузере открыть: http://localhost:8080 \ No newline at end of file diff --git a/dog/desktop.ini b/dog/desktop.ini new file mode 100644 index 0000000000000000000000000000000000000000..64ee3e7daeaf98eaa418cf6f5a45e887a97cb594 Binary files /dev/null and b/dog/desktop.ini differ diff --git a/dog/dog_server.go b/dog/dog_server.go new file mode 100644 index 0000000000000000000000000000000000000000..0d98459c60e449e2a73ea26e717174f1791edafe --- /dev/null +++ b/dog/dog_server.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + "io" + "net/http" +) + +func whatCatSay(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, "Wof\n") +} + +func whoiami(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, "Dog") +} + +func main() { + http.HandleFunc("/", whatCatSay) + http.HandleFunc("/whoami", whoiami) + fmt.Printf("Try to start on port 8080") + if err := http.ListenAndServe(":8080", nil); err != nil { + fmt.Printf("An error: %s", err) + } +} diff --git a/dog/go.mod b/dog/go.mod new file mode 100644 index 0000000000000000000000000000000000000000..0419459cebf7fcc55bfd08a6d7a41d0342896d38 --- /dev/null +++ b/dog/go.mod @@ -0,0 +1,3 @@ +module ms-dog + +go 1.17 diff --git a/gitlab-ci.yml b/gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..2a5c41ddc6acfc1175203f9b7c48e27bb7b40ad1 --- /dev/null +++ b/gitlab-ci.yml @@ -0,0 +1,67 @@ +stages: + - build + - testing + - packaging + +build_application: + stage: build + tags: + - docker_itsoft + script: + - echo "This application will build here..." + - pwd + - echo "Build application Done!" + +lint-testing: + stage: testing + tags: + - docker_itsoft + script: + - echo "This application will lint-test here..." + - pwd + - ls -a + - echo "Lint test Done!" + +unit-testing: + stage: testing + tags: + - docker_itsoft + needs: + - job: 'lint-testing' + optional: true + before_script: + - echo "Prepare test data" + script: + - echo "This application will unit-test here..." + + - echo "Unit test Done!" + rules: + - if: '$CI_COMMIT_BRANCH == "master"' + - if: '$CI_COMMIT_BRANCH == "develop"' + - if: '$CI_PIPELINE_SOURCE == "feature_new"' + +build-image-job: + stage: packaging + tags: + - docker_itsoft + rules: + - if: '$CI_COMMIT_BRANCH == "master"' + variables: + TAG: 'latest' + - if: '$CI_COMMIT_BRANCH == "develop"' + variables: + TAG: 'dev' + image: docker:20.10.16 + services: + - docker:20.10.16-dind + parallel: + matrix: + - SERVICE: [cat, dog, child] + script: + - echo "This application will package here..." + - cd $SERVICE + - docker login docker.io -u $DOCKER_USER -p $DOCKER_PASSWORD + - docker info + - docker build -t docker.io/pathmakantha/$SERVICE:$TAG . + - docker push docker.io/pathmakantha/$SERVICE:$TAG + - echo "Packaging Done!"