demo-service-181's Issues
Create booking history method in internal controller
New method description is here
Payment service: дописать и исправить тесты
После рефакторинга сервиса и изменения семантики часть тестов начала падать и была отключена аннотацией @Disabled
. Надо бы переписать их и включить обратно.
Setup migrations via liquibase
Item Service controller doesn't work properly (403 Forbidden)
Add @Operation(security = {@SecurityRequirement(name = "bearerAuth")})
to Item Service
conroller for correct authentication.
Pass user service events to logger and notification service
Each action in each service must generate an Event for the logger to catch. Also, some of evens should be passed to Notification Service. See the example below.
- Create a notable events for our logger:
package com.itmo.microservices.demo.users.impl.logging;
import com.itmo.microservices.commonlib.logging.NotableEvent;
import org.jetbrains.annotations.NotNull;
public enum UserServiceNotableEvents implements NotableEvent {
I_USER_CREATED("User created: {}");
private final String template;
UserServiceNotableEvents(String template) {
this.template = template;
}
@NotNull
@Override
public String getName() {
return this.name();
}
@NotNull
@Override
public String getTemplate() {
return this.template;
}
}
- Create event classes for notification service:
package com.itmo.microservices.demo.user.api.messaging;
import com.itmo.microservices.shop.demo.api.model.UserModel;
public class UserCreatedEvent {
private final UserModel userModel;
public UserCreatedEvent(UserModel userModel) {
this.userModel = userModel;
}
public UserModel getUserModel() {
return userModel;
}
}
- And pass them to event bus:
package com.itmo.microservices.demo.users.impl.service;
import com.google.common.eventbus.EventBus;
import com.itmo.microservices.commonlib.annotations.InjectEventLogger;
import com.itmo.microservices.commonlib.logging.EventLogger;
import com.itmo.microservices.shop.user.impl.logging.UserServiceNotableEvents;
import com.itmo.microservices.shop.user.api.messaging.UserCreatedEvent;
import com.itmo.microservices.shop.user.api.model.RegistrationRequest;
@Service
@Suppress("UnstableApiUsage") /* Suppress warning about unstable event bus */
public class DefaultUserService {
@InjectEventLogger
private EventLogger eventLogger;
private final EventBus eventBus;
public UserService(EventBus eventBus) {
this.eventBus = eventBus;
}
@Override
public void registerUser(RegistrationRequest request) {
/* Your service code here */
var user = createUser(request);
/* Passing the event to logger */
if (eventLogger != null) {
eventLogger.info(UserServiceNotableEvents.I_USER_CREATED, user.getUsername());
}
/* Passing the event to logger */
eventBus.post(new UserCreatedEvent(user));
}
}
Order controller returns invalid OrderDto
Endpoint: GET /orders/$orderId
Actual invalid response:
{
"id": "5ccaccd8-7c9f-4ded-8650-135077678e49",
"timeCreated": 1637426853,
"status": "COLLECTING",
"itemsMap": {
"OrderItemDTO(id=3cd3283b-e057-406a-bb64-5c8a24c9be93, title=mock name, price=0)": 16,
"OrderItemDTO(id=f72fe1ff-c59f-4879-8ba2-afa6b5d63e02, title=mock name2, price=0)": 23
},
"deliveryDuration": 0,
"paymentHistory": []
}
which is expected to be:
{
"id": "5ccaccd8-7c9f-4ded-8650-135077678e49",
"timeCreated": 1637426853,
"status": "COLLECTING",
"itemsMap": {
"i3cd3283b-e057-406a-bb64-5c8a24c9be93": 16,
"f72fe1ff-c59f-4879-8ba2-afa6b5d63e02": 23
},
"deliveryDuration": 0,
"paymentHistory": []
}
See API description
Create SecurityConfiguration modification guide for other services
Place it as SecurityNotes.md
into repo root
Redundant functionality in delivery service
Add rate limiter to polling transaction processor
We have unified transaction processor for external service polling interaction. Now we should have a rate limiter to prevent external service overloading.
Expected usage example:
// Setup the rate limiter: 500 requests per second accepted
var rateLimiter = new RateLimiter(500, TimeUnit.SECONDS);
// And connect it to `TransactionPollingProcessor`
var pollingTransactionProcessor = TransactionPollingProcessor.<[...], [...], [...]>builder()
.withPollingExecutorService([...])
.withTransactionStarter([...])
.withTransactionUpdater([...])
.withTransactionFinishHandler([...])
.withTransactionStartRateLimiter(rateLimiter) /* !!! Pay attention to here !!! */
.build();
// Use transaction processor with the rate limiter
// When we hit rate limit, it's expected 'TransactionStartException' to be thrown.
TransactionWrapper<[...]> result = null;
try {
result = pollingTransactionProcessor.startTransaction(context);
} catch (TransactionStartException e) {
/* !!! We should get here on rate limit exceeding !!! */
}
The study course lecture about limiter can be helpful.
Add rate limiter to delivery service transaction processor
Create API 'user' subservice
Detailed description can be found here
Please meet the git rules
Fill catalog with items
Please add 100.000 items, each number in catalog should be 1.000.000
Improve booking mechanisms
Please provide:
- unique booking id generation on booking (see BookingDto)
- booking history storage (BookingLogRecord)
- method to book items that returns at lease booking id
- method to undo booking by booking id
- method to describe booking by by booking id
If needed, it's allowed to add new columns to existing db tables and create new ones.
[payment] Create db-based writeback storage for transaction processor
Merge service injections
Add email to user entity and model
Order service: реализовать сгорание заказа (переход в статус DISCARD)
В машине состояний заказ должен переходить COLLECTING
-> DISCARD
по таймауту бездействия.
- Реализовать можно аналогично "сгоранию" времени на оплату через
ScheduledThreadPoolExecutor
, см. payment service - Пусть время на сбоку заказа будет установлено в 1 час, после дискардим.
- Стоит быть осторожным, случайно не отменить заказ, если пользователь его всё-таки поменял. Возможно, в бд можно добавить новый атрибут
last_modified
для заказа
User service returns wrong code (400) on `authenticate` request with wrong username.
See the review
Pass delivery service events to logger
Each action in each service must generate an Event for the logger to catch. See an example below.
Create a notable events enum for your service:
import com.itmo.microservices.commonlib.logging.NotableEvent;
import org.jetbrains.annotations.NotNull;
public enum UserServiceNotableEvents implements NotableEvent {
I_USER_CREATED("User created: {}");
private final String template;
UserServiceNotableEvents(String template) {
this.template = template;
}
@NotNull
@Override
public String getName() {
return this.name();
}
@NotNull
@Override
public String getTemplate() {
return this.template;
}
}
And use it:
import com.itmo.microservices.commonlib.annotations.InjectEventLogger;
import com.itmo.microservices.commonlib.logging.EventLogger;
import com.itmo.microservices.shop.user.impl.logging.UserServiceNotableEvents;
@Service
public class DefaultUserService {
@InjectEventLogger
private EventLogger eventLogger;
@Override
public void registerUser(RegistrationRequest request) {
/* Your service code here */
if (eventLogger != null) {
eventLogger.info(UserServiceNotableEvents.I_USER_CREATED, user.getUsername());
}
}
}
Order service: дописать и исправить тесты
После рефакторинга сервиса и изменения семантики часть тестов начала падать и была отключена аннотацией @Disabled
. Надо бы переписать их и включить обратно.
Create API for 'items' subservice
Catalog service: дописать и исправить тесты
После рефакторинга сервиса и изменения семантики часть тестов начала падать и была отключена аннотацией @Disabled
. Надо бы переписать их и включить обратно.
Order service returns null paymentHistory on POST /orders
Create API 'notification' subservice
itmo-central and itmo-snapshots return '401 Unathorized' periodically
IDEA Log:
[WARNING] Failure to transfer com.itmo.microservices:common-lib:0.5.0-SNAPSHOT/maven-metadata.xml from http://77.234.215.138:30031/artifactory/libs-snapshot was cached in the local repository, resolution will not be reattempted until the update interval of itmo-snapshots has elapsed or updates are forced. Original error: Could not transfer metadata com.itmo.microservices:common-lib:0.5.0-SNAPSHOT/maven-metadata.xml from/to itmo-snapshots (http://77.234.215.138:30031/artifactory/libs-snapshot): Authentication failed for http://77.234.215.138:30031/artifactory/libs-snapshot/com/itmo/microservices/common-lib/0.5.0-SNAPSHOT/maven-metadata.xml 401 Unauthorized
Can be useful:
https://t.me/c/1436658303/500
https://t.me/c/1436658303/523
https://t.me/c/1436658303/1105
https://t.me/c/1436658303/1109
Update common-lib to 6.0.0-SNAPSHOT version
Requested here
Create delivery info record methods
See new related method.
If needed, it's allowed to add new columns to existing db tables and create new ones.
Implement controller for Authentication
Define endpoints /authentication and /refresh for access and refresh token
Tests. Pass fake authentication
Example how to use @WithMockCustomUser
notation:
@Test
public void whenUpdateItemWithoutAuthentication_thenReturnStatusForbidden() throws Exception {
Mockito.doNothing().when(itemService).updateItem(isA(UUID.class), isA(ItemDTO.class));
final String requestedBodyContent = mapper.writeValueAsString(hardcodedValues.mockedItemDTO);
this.mockMvc.perform(put("/items/{id}", UUID.randomUUID())
.contentType(MediaType.APPLICATION_JSON)
.content(requestedBodyContent))
.andDo(print())
.andExpect(status().isForbidden());
Mockito.verifyNoInteractions(itemService);
}
@Test
@WithMockCustomUser
public void whenUpdateItemWithAccessAuthority_thenReturnStatusForbidden() throws Exception {
Mockito.doNothing().when(itemService).updateItem(isA(UUID.class), isA(ItemDTO.class));
final String requestedBodyContent = mapper.writeValueAsString(hardcodedValues.mockedItemDTO);
this.mockMvc.perform(put("/items/{id}", UUID.randomUUID())
.contentType(MediaType.APPLICATION_JSON)
.content(requestedBodyContent))
.andDo(print())
.andExpect(status().isForbidden());
Mockito.verifyNoInteractions(itemService);
}
@Test
@WithMockCustomUser(roles = {"ACCESS", "ADMIN"})
public void whenUpdateItemWithAdminAuthority_thenReturnStatusOK() throws Exception {
Mockito.doNothing().when(itemService).updateItem(isA(UUID.class), isA(ItemDTO.class));
final String requestedBodyContent = mapper.writeValueAsString(hardcodedValues.mockedItemDTO);
this.mockMvc.perform(put("/items/{id}", UUID.randomUUID())
.contentType(MediaType.APPLICATION_JSON)
.content(requestedBodyContent))
.andDo(print())
.andExpect(status().isOk());
Mockito.verify(itemService).updateItem(Mockito.any(UUID.class), Mockito.any(ItemDTO.class));
Mockito.verifyNoMoreInteractions(itemService);
}
Update README based on new changes
Add admin-only access to some endpoints
- Set requirements towards endpoints, and categorize endpoints what need admin access.
- Add admin only to them
Delivery service: дописать и исправить тесты
После рефакторинга сервиса и изменения семантики часть тестов начала падать и была отключена аннотацией @Disabled
. Надо бы переписать их и включить обратно.
Payment service. Extract userUUID from authentication for FinLogController
Разобраться, как работает доставка
Заведена ишуя на квипи: тык
Как будет понятен алгоритм обработки (генерация слотов, таймауты, работа с внешней системой) - поправить у нас
Connect order and payment service
- create event for paying with fields
id, time, money
- create event for notification about successful/unsuccessful payment
- create
@Subscribe
for notification
Payment Service
- Refund:
1 ) Events:RefundOrderRequestEvent, RefundOrderAnswerEvent
2 ) Service\Subscribe:handleRefund(RefundOrderRequestEvent ... )
3 ) Service\Scheduled:doRefund()
4 ) Entity:RefundOrder
5 ) Repository:RefundOrderRepository
6 ) Logging:PaymentServiceNotableEvent
7 ) Model:RefundOrderDto implements Comparable<RefundOrderDto>
Order Service
- Subscribe:
handleRefundAnswer(RefundOrderAnswerEvent event)
-
EventBus::post(event)
| event <-- RefundOrderRequestEvent.class
Add external system integration to the notification service
Detailed task description can be found here. The external system documentation placed by this link, the whole API documentation is in already known place.
It's preferable to reuse already created classes from the packages:
com.itmo.microservices.shop.common.externalservice
com.itmo.microservices.shop.common.transactions
com.itmo.microservices.shop.common.executors
Usage example of these mechanisms can be found in the payment service (diff: 1bcff1a)
Create API for 'orders' subservice
Lombok plugin for kapt does not work properly with IntelliJ IDEA
Sometimes project fails to build because lombok-generated sources is not visible from Kotlin code.
Seems that Lombok compiler plugin does not work as expected. So all the lombok usages should be removed and replaced with manually written code where we have Kotlin interaction .
Improve delivery service test covarage
See comment
Connect order and delivery service
- create events for start and end delivery fields
orderUUID, timeSlot, userUUID
- create event for canceled delivery
- create
@Subscribe
for this events
Pass order service events to logger and notification service
Each action in each service must generate an Event for the logger to catch. Also, some of evens should be passed to Notification Service. See the example below.
- Create a notable events for our logger:
package com.itmo.microservices.demo.users.impl.logging;
import com.itmo.microservices.commonlib.logging.NotableEvent;
import org.jetbrains.annotations.NotNull;
public enum UserServiceNotableEvents implements NotableEvent {
I_USER_CREATED("User created: {}");
private final String template;
UserServiceNotableEvents(String template) {
this.template = template;
}
@NotNull
@Override
public String getName() {
return this.name();
}
@NotNull
@Override
public String getTemplate() {
return this.template;
}
}
- Create event classes for notification service:
package com.itmo.microservices.demo.user.api.messaging;
import com.itmo.microservices.shop.demo.api.model.UserModel;
public class UserCreatedEvent {
private final UserModel userModel;
public UserCreatedEvent(UserModel userModel) {
this.userModel = userModel;
}
public UserModel getUserModel() {
return userModel;
}
}
- And pass them to event bus:
package com.itmo.microservices.demo.users.impl.service;
import com.google.common.eventbus.EventBus;
import com.itmo.microservices.commonlib.annotations.InjectEventLogger;
import com.itmo.microservices.commonlib.logging.EventLogger;
import com.itmo.microservices.shop.user.impl.logging.UserServiceNotableEvents;
import com.itmo.microservices.shop.user.api.messaging.UserCreatedEvent;
import com.itmo.microservices.shop.user.api.model.RegistrationRequest;
@Service
@Suppress("UnstableApiUsage") /* Suppress warning about unstable event bus */
public class DefaultUserService {
@InjectEventLogger
private EventLogger eventLogger;
private final EventBus eventBus;
public UserService(EventBus eventBus) {
this.eventBus = eventBus;
}
@Override
public void registerUser(RegistrationRequest request) {
/* Your service code here */
var user = createUser(request);
/* Passing the event to logger */
if (eventLogger != null) {
eventLogger.info(UserServiceNotableEvents.I_USER_CREATED, user.getUsername());
}
/* Passing the event to logger */
eventBus.post(new UserCreatedEvent(user));
}
}
Remove 'admin' flab from UserDTO json
Pass catalog service events to logger and notification service
Each action in each service must generate an Event for the logger to catch. Also, some of evens should be passed to Notification Service. See the example below.
- Create a notable events for our logger:
package com.itmo.microservices.demo.users.impl.logging;
import com.itmo.microservices.commonlib.logging.NotableEvent;
import org.jetbrains.annotations.NotNull;
public enum UserServiceNotableEvents implements NotableEvent {
I_USER_CREATED("User created: {}");
private final String template;
UserServiceNotableEvents(String template) {
this.template = template;
}
@NotNull
@Override
public String getName() {
return this.name();
}
@NotNull
@Override
public String getTemplate() {
return this.template;
}
}
- Create event classes for notification service:
package com.itmo.microservices.demo.user.api.messaging;
import com.itmo.microservices.shop.demo.api.model.UserModel;
public class UserCreatedEvent {
private final UserModel userModel;
public UserCreatedEvent(UserModel userModel) {
this.userModel = userModel;
}
public UserModel getUserModel() {
return userModel;
}
}
- And pass them to event bus:
package com.itmo.microservices.demo.users.impl.service;
import com.google.common.eventbus.EventBus;
import com.itmo.microservices.commonlib.annotations.InjectEventLogger;
import com.itmo.microservices.commonlib.logging.EventLogger;
import com.itmo.microservices.shop.user.impl.logging.UserServiceNotableEvents;
import com.itmo.microservices.shop.user.api.messaging.UserCreatedEvent;
import com.itmo.microservices.shop.user.api.model.RegistrationRequest;
@Service
@Suppress("UnstableApiUsage") /* Suppress warning about unstable event bus */
public class DefaultUserService {
@InjectEventLogger
private EventLogger eventLogger;
private final EventBus eventBus;
public UserService(EventBus eventBus) {
this.eventBus = eventBus;
}
@Override
public void registerUser(RegistrationRequest request) {
/* Your service code here */
var user = createUser(request);
/* Passing the event to logger */
if (eventLogger != null) {
eventLogger.info(UserServiceNotableEvents.I_USER_CREATED, user.getUsername());
}
/* Passing the event to logger */
eventBus.post(new UserCreatedEvent(user));
}
}
Create API 'delivery' subservice
Create API for 'payment' subservice
Add rate limiter to payment service transaction processor
Add external system integration to the delivery service
Detailed task description can be found here. The external system documentation placed by this link, the whole API documentation is in already known place.
It's preferable to reuse already created classes from the packages:
com.itmo.microservices.shop.common.externalservice
com.itmo.microservices.shop.common.transactions
com.itmo.microservices.shop.common.executors
Usage example of these mechanisms can be found in the payment service (diff: 1bcff1a)
Connect order and catalog service
ItemService:
- create
getItemByUUID
- add method for booking Items
bookItems(Map<UUID, Integer>) -> List[UUID]
- faild items - add method for removing booking
deleteBooking(Map<UUID, Integer>) -> void
OrderService:
- integrate this methods to order service
Delivery service: реализовать запись лога доставки в базу данных
Сейчас лог доставки пишется примитивно в ArrayList. Надо бы создать таблицу в БД и писать его туда
Зачем оно вообще надо - см. документацию к api, endpoint - GET /_internal/deliveryLog/{orderId}
.
Скорее всего надо будет поправить модельку (не пихать в нее ненужный order id - сейчас заигнорен через @JsonIgnore
, и поправить сам контроллер. Постараться сделать так, чтобы не было идейских ворнингов.
[delivery] Create db-based writeback storage for transaction processor
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.