Proto creation

This commit is contained in:
n.pospolita 2018-12-19 17:27:31 +03:00
parent d7c71e3082
commit cc95459af0
7 changed files with 387 additions and 0 deletions

78
.gitignore vendored Normal file
View File

@ -0,0 +1,78 @@
# Created by .ignore support plugin (hsz.mobi)
.eunit
deps
*.o
*.beam
*.plt
erl_crash.dump
ebin/*.beam
rel/example_project
.concrete/DEV_MODE
.rebar
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/libraries
# Mongo Explorer plugin:
.idea/mongoSettings.xml
*.iws
*.ipr
*.iml
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
env.list

4
.gitmodules vendored Normal file
View File

@ -0,0 +1,4 @@
[submodule "build_utils"]
path = build_utils
url = git@github.com:rbkmoney/build_utils.git
branch = master

34
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,34 @@
#!groovy
// -*- mode: groovy -*-
build('schedulator-proto', 'docker-host') {
checkoutRepo()
loadBuildUtils()
def pipeDefault
def gitUtils
runStage('load pipeline') {
env.JENKINS_LIB = "build_utils/jenkins_lib"
pipeDefault = load("${env.JENKINS_LIB}/pipeDefault.groovy")
gitUtils = load("${env.JENKINS_LIB}/gitUtils.groovy")
}
pipeDefault() {
runStage('compile') {
sh "make wc_compile"
}
// Java
runStage('Execute build container') {
withCredentials([[$class: 'FileBinding', credentialsId: 'java-maven-settings.xml', variable: 'SETTINGS_XML']]) {
if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME.startsWith('epic/')) {
sh 'make SETTINGS_XML=${SETTINGS_XML} BRANCH_NAME=${BRANCH_NAME} wc_java.deploy'
} else {
sh 'make SETTINGS_XML=${SETTINGS_XML} wc_java.compile'
}
}
}
}
}

80
Makefile Normal file
View File

@ -0,0 +1,80 @@
THRIFT = $(or $(shell which thrift), $(error "`thrift' executable missing"))
REBAR = $(shell which rebar3 2>/dev/null || which ./rebar3)
SUBMODULES = build_utils
SUBTARGETS = $(patsubst %,%/.git,$(SUBMODULES))
UTILS_PATH := build_utils
TEMPLATES_PATH := .
# Name of the service
SERVICE_NAME := schedulator-proto
# Build image tag to be used
BUILD_IMAGE_TAG := 55e987e74e9457191a5b4a7c5dc9e3838ae82d2b
CALL_ANYWHERE := \
all submodules compile clean distclean \
java.compile java.deploy
CALL_W_CONTAINER := $(CALL_ANYWHERE)
all: compile
-include $(UTILS_PATH)/make_lib/utils_container.mk
.PHONY: $(CALL_W_CONTAINER)
# CALL_ANYWHERE
$(SUBTARGETS): %/.git: %
git submodule update --init $<
touch $@
submodules: $(SUBTARGETS)
compile:
$(REBAR) compile
clean:
$(REBAR) clean
distclean:
$(REBAR) clean -a
rm -rfv _build
# Java
ifdef SETTINGS_XML
DOCKER_RUN_OPTS = -v $(SETTINGS_XML):$(SETTINGS_XML)
DOCKER_RUN_OPTS += -e SETTINGS_XML=$(SETTINGS_XML)
endif
ifdef LOCAL_BUILD
DOCKER_RUN_OPTS += -v $$HOME/.m2:/home/$(UNAME)/.m2:rw
endif
COMMIT_HASH := $(shell git --no-pager log -1 --pretty=format:"%h")
NUMBER_COMMITS := $(shell git rev-list --count HEAD)
JAVA_PKG_VERSION := 1.$(NUMBER_COMMITS)-$(COMMIT_HASH)
ifdef BRANCH_NAME
ifeq "$(findstring epic,$(BRANCH_NAME))" "epic"
JAVA_PKG_VERSION := $(JAVA_PKG_VERSION)-epic
endif
endif
MVN = mvn -s $(SETTINGS_XML) -Dpath_to_thrift="$(THRIFT)" -Dcommit.number="$(NUMBER_COMMITS)"
java.compile: java.settings
$(MVN) compile
java.deploy: java.settings
$(MVN) versions:set versions:commit -DnewVersion="$(JAVA_PKG_VERSION)" && \
$(MVN) deploy
java.install: java.settings
$(MVN) clean && \
$(MVN) versions:set versions:commit -DnewVersion="$(JAVA_PKG_VERSION)" && \
$(MVN) install
java.settings:
$(if $(SETTINGS_XML),, echo "SETTINGS_XML not defined"; exit 1)

1
build_utils Submodule

@ -0,0 +1 @@
Subproject commit 269686d735abef363f9f40a1bf4e1b7c751f3722

90
pom.xml Normal file
View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.rbkmoney</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>schedulator-proto</artifactId>
<version>SNAPSHOT</version>
<packaging>jar</packaging>
<name>Schedulator</name>
<description>Generates jar artifact containing compiled thrift classes based on generated thrift IDL files
</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.rbkmoney.woody</groupId>
<artifactId>woody-thrift</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>damsel</artifactId>
<version>1.268-45c8524</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- THRIFT -->
<plugin>
<groupId>org.apache.thrift</groupId>
<artifactId>thrift-maven-plugin</artifactId>
<version>0.9.3-1</version>
<configuration>
<generator>java:fullcamel</generator>
<thriftSourceRoot>${project.basedir}/proto</thriftSourceRoot>
<thriftExecutable></thriftExecutable>
</configuration>
<executions>
<execution>
<id>thrift-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.rbkmoney.damsel</pattern>
<shadedPattern>com.rbkmoney.damsel.v${commit.number}</shadedPattern>
</relocation>
</relocations>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>v${commit.number}</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

100
proto/schedule.thrift Normal file
View File

@ -0,0 +1,100 @@
include "base.thrift"
include "domain.thrift"
include "payout_processing.thrift"
namespace java com.rbkmoney.damsel.schedule
namespace erlang com.rbkmoney.damsel.schedule
typedef string URL
struct ScheduledJobContext {
// путь до сервиса, который будет исполнять Job
1: required URL executor_service_path
// ссылка на расписание в Dominant-е. Можно оставить не ссылку, а полноценное расписание?
// Или вынести в отдельную структуру, чтобы можно было задавать и так и так
2: required domain.BusinessScheduleRef business_schedule_ref
// ссылка на календарь в Dominant-е. Можно также оставить полноценный календарь? Пока что хз
3: required domain.CalendarRef calendar_ref
4: required GenericServiceExecutionContext context
}
/**
* Общий контекст выполнения какого-то абстрактного сервиса
* Можно дополнять различными сервисами, которые должны выполнять Job-ы по расписанию
**/
union GenericServiceExecutionContext {
1: PayouterExecutionContext payouter_context
}
/** Конкретные контексты выполнения сервисов, чтобы выполняющий сервис знал, какую именно операцию ему совершать */
union PayouterExecutionContext {
1: payout_processing.GeneratePayoutParams context
}
union ContextValidationResponse {
1: required list<string> errors
}
union JobExecutionResponse {
1: SuccessfulExecution success
2: FailedExecution fail
}
struct SuccessfulExecution {}
struct FailedExecution {
1: optional string reason
2: optional RetryPolicy retry_policy
}
union RetryPolicy {
1: RetryNow retry_now
2: RetryLater retry_later
3: RetryNever retry_never
}
struct RetryNow {}
struct RetryLater {
1: optional base.TimeSpan delay
}
union RetryNever {
1: DeregisterJob deregister // Этим способом можно сказать, что Job больше не актуален.
2: RemainJob remain
}
struct DeregisterJob {}
struct RemainJob {}
exception NotFoundSchedule {}
exception ScheduleAlreadyExists {}
exception BadContextProvided {
1: required ContextValidationResponse validation_response
}
/**
* Интерфейс сервиса регистрирующего и высчитывающего расписания выполнений
**/
service Schedulator {
void RegisterJob(1: base.ID schedule_id, 2: ScheduledJobContext context)
throws (1: ScheduleAlreadyExists schedule_already_exists_ex, 2: BadContextProvided bad_context_provided_ex)
void DeregisterJob(1: base.ID schedule_id)
throws (1: NotFoundSchedule ex)
}
/**
* Интерфейс для сервисов, выполняющих Job-ы по расписанию
**/
service ScheduledJobExecutor {
/** метод вызывается при попытке зарегистрировать Job */
ContextValidationResponse ValidateExecutionContext(1: GenericServiceExecutionContext context)
JobExecutionResponse ExecuteJob(1: GenericServiceExecutionContext context)
}