Skip to content

Commit

Permalink
Upgraded various Spring Cloud dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
cer committed Jun 8, 2018
1 parent 1336a78 commit 6cf5107
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 71 deletions.
13 changes: 7 additions & 6 deletions build-and-restart-service.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#! /bin/bash -e

SNX=${1}
SN=${SNX?}
for SN in $* ; do

./gradlew :${SN?}:assemble
docker-compose build ${SN?}
docker-compose up -d ${SN?}
done

docker-compose logs -f $*

./gradlew :${SNX?}:assemble
docker-compose build ${SN?}
docker-compose up -d ${SN?}
docker-compose logs -f ${SN?}
29 changes: 29 additions & 0 deletions build-and-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#! /bin/bash -e

. ./set-env.sh

./gradlew assemble

docker-compose build

. ./set-env.sh

initializeDynamoDB() {
echo preparing dynamodblocal table data
cd dynamodblocal-init
./create-dynamodb-tables.sh
cd ..
echo data is prepared
}


docker-compose down -v
docker-compose up -d --build dynamodblocal mysql

./wait-for-mysql.sh

initializeDynamoDB

docker-compose up -d

./show-swagger-ui-urls.sh
12 changes: 6 additions & 6 deletions ftgo-api-gateway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ apply plugin: 'org.springframework.boot'

dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-gateway:2.0.0.M8'
mavenBom "org.springframework.cloud:spring-cloud-gateway:$springCloudGatewayVersion"
mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:$springCloudContractDependenciesVersion"
mavenBom 'org.springframework.cloud:spring-cloud-sleuth:2.0.0.M8'
mavenBom "org.springframework.cloud:spring-cloud-sleuth:$springCloudSleuthVersion"
}
}

Expand Down Expand Up @@ -53,16 +53,16 @@ dependencies {
compile 'org.springframework.cloud:spring-cloud-starter-zipkin'
compile 'io.zipkin.brave:brave-bom:4.17.1'

compile 'io.micrometer:micrometer-registry-prometheus:1.0.1'
compile "org.springframework.boot:spring-boot-starter-actuator:$springBootVersion"
compile "io.micrometer:micrometer-registry-prometheus:$micrometerVersion"
compile "org.springframework.boot:spring-boot-starter-actuator"

testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion2"
testCompile "org.springframework.boot:spring-boot-starter-test"
testCompile "junit:junit:4.12"
testCompile "net.chrisrichardson.ftgo:ftgo-order-service-contracts:unspecified:stubs"
testCompile "org.springframework.cloud:spring-cloud-contract-wiremock"
testCompile "org.springframework.cloud:spring-cloud-starter-contract-stub-runner"

// FIXME: gradle was downgrading: 5.0.3.RELEASE -> 5.0.0.M6
testCompile "org.springframework.integration:spring-integration-core:5.0.3.RELEASE"
// testCompile "org.springframework.integration:spring-integration-core:5.0.3.RELEASE"

}
2 changes: 1 addition & 1 deletion ftgo-api-gateway/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ logging.level.com.github.tomakehurst.wiremock=TRACE

management.endpoints.web.exposure.include=health,prometheus

spring.sleuth.sampler.percentage=1.0
spring.sleuth.sampler.probability=1.0
spring.sleuth.web.skipPattern=(^health.*)

# routes
4 changes: 2 additions & 2 deletions ftgo-order-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: ComponentTestsPlugin
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:$springCloudContractDependenciesVersion"
mavenBom 'org.springframework.cloud:spring-cloud-sleuth:2.0.0.M8'
mavenBom "org.springframework.cloud:spring-cloud-sleuth:$springCloudSleuthVersion"
}
}

Expand Down Expand Up @@ -99,7 +99,7 @@ dependencies {

compile "org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion"
compile "org.springframework.boot:spring-boot-starter-actuator:$springBootVersion"
compile 'io.micrometer:micrometer-registry-prometheus:1.0.1'
compile "io.micrometer:micrometer-registry-prometheus:$micrometerVersion"
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
compile 'javax.el:javax.el-api:2.2.5'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
spring.application.name=ftgo-order-service

logging.level.org.hibernate.SQL=DEBUG
logging.level.org.springframework.cloud.contract=DEBUG
logging.level.io.eventuate=DEBUG
spring.jpa.generate-ddl=true
stubrunner.stream.enabled=false
stubrunner.integration.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,36 @@
@Transactional
public class OrderService {

private Logger logger = LoggerFactory.getLogger(getClass());

private OrderRepository orderRepository;

private RestaurantRepository restaurantRepository;

private SagaManager<CreateOrderSagaState> createOrderSagaManager;

private SagaManager<CancelOrderSagaData> cancelOrderSagaManager;

private SagaManager<ReviseOrderSagaData> reviseOrderSagaManager;

private OrderDomainEventPublisher orderAggregateEventPublisher;

private Optional<MeterRegistry> meterRegistry;

public OrderService(OrderRepository orderRepository, DomainEventPublisher eventPublisher, RestaurantRepository restaurantRepository, SagaManager<CreateOrderSagaState> createOrderSagaManager, SagaManager<CancelOrderSagaData> cancelOrderSagaManager, SagaManager<ReviseOrderSagaData> reviseOrderSagaManager, OrderDomainEventPublisher orderAggregateEventPublisher, Optional<MeterRegistry> meterRegistry) {
this.orderRepository = orderRepository;
this.restaurantRepository = restaurantRepository;
this.createOrderSagaManager = createOrderSagaManager;
this.cancelOrderSagaManager = cancelOrderSagaManager;
this.reviseOrderSagaManager = reviseOrderSagaManager;
this.orderAggregateEventPublisher = orderAggregateEventPublisher;
this.meterRegistry = meterRegistry;
}

public Order createOrder(long consumerId, long restaurantId,
List<MenuItemIdAndQuantity> lineItems) {
Restaurant restaurant = restaurantRepository.findById(restaurantId).get();
Restaurant restaurant = restaurantRepository.findById(restaurantId)
.orElseThrow(() -> new RestaurantNotFoundException(restaurantId));

List<OrderLineItem> orderLineItems = makeOrderLineItems(lineItems, restaurant);

Expand All @@ -46,37 +73,12 @@ public Order createOrder(long consumerId, long restaurantId,
CreateOrderSagaState data = new CreateOrderSagaState(order.getId(), orderDetails);
createOrderSagaManager.create(data, Order.class, order.getId());

meterRegistry.counter("placed_orders").increment();
meterRegistry.ifPresent( mr -> mr.counter("placed_orders").increment());

return order;
}


private Logger logger = LoggerFactory.getLogger(getClass());

private OrderRepository orderRepository;

private RestaurantRepository restaurantRepository;

private SagaManager<CreateOrderSagaState> createOrderSagaManager;

private SagaManager<CancelOrderSagaData> cancelOrderSagaManager;

private SagaManager<ReviseOrderSagaData> reviseOrderSagaManager;

private OrderDomainEventPublisher orderAggregateEventPublisher;

@Autowired
private MeterRegistry meterRegistry;

public OrderService(OrderRepository orderRepository, DomainEventPublisher eventPublisher, RestaurantRepository restaurantRepository, SagaManager<CreateOrderSagaState> createOrderSagaManager, SagaManager<CancelOrderSagaData> cancelOrderSagaManager, SagaManager<ReviseOrderSagaData> reviseOrderSagaManager, OrderDomainEventPublisher orderAggregateEventPublisher) {
this.orderRepository = orderRepository;
this.restaurantRepository = restaurantRepository;
this.createOrderSagaManager = createOrderSagaManager;
this.cancelOrderSagaManager = cancelOrderSagaManager;
this.reviseOrderSagaManager = reviseOrderSagaManager;
this.orderAggregateEventPublisher = orderAggregateEventPublisher;
}

private List<OrderLineItem> makeOrderLineItems(List<MenuItemIdAndQuantity> lineItems, Restaurant restaurant) {
return lineItems.stream().map(li -> {
Expand Down Expand Up @@ -123,12 +125,12 @@ private Optional<Order> updateOrder(long orderId, Function<Order, List<OrderDoma

public void approveOrder(long orderId) {
updateOrder(orderId, Order::noteApproved).orElseThrow(RuntimeException::new);
meterRegistry.counter("approved_orders").increment();
meterRegistry.ifPresent( mr -> mr.counter("approved_orders").increment());
}

public void rejectOrder(long orderId) {
updateOrder(orderId, Order::noteRejected).orElseThrow(RuntimeException::new);
meterRegistry.counter("rejected_orders").increment();
meterRegistry.ifPresent( mr -> mr.counter("rejected_orders").increment());
}

public void beginCancel(long orderId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.eventuate.tram.sagas.orchestration.SagaManagerImpl;
import io.eventuate.tram.sagas.orchestration.SagaOrchestratorConfiguration;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.MeterBinder;
import net.chrisrichardson.ftgo.common.CommonConfiguration;
import net.chrisrichardson.ftgo.orderservice.sagaparticipants.AccountingServiceProxy;
import net.chrisrichardson.ftgo.orderservice.sagaparticipants.ConsumerServiceProxy;
Expand All @@ -25,6 +24,8 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import java.util.Optional;

@Configuration
@Import({TramEventsPublisherConfiguration.class, SagaOrchestratorConfiguration.class, CommonConfiguration.class})
public class OrderServiceConfiguration {
Expand All @@ -38,9 +39,9 @@ public SagaCommandProducer sagaCommandProducer() {
@Bean
public OrderService orderService(RestaurantRepository restaurantRepository, OrderRepository orderRepository, DomainEventPublisher eventPublisher,
SagaManager<CreateOrderSagaState> createOrderSagaManager,
SagaManager<CancelOrderSagaData> cancelOrderSagaManager, SagaManager<ReviseOrderSagaData> reviseOrderSagaManager, OrderDomainEventPublisher orderAggregateEventPublisher) {
SagaManager<CancelOrderSagaData> cancelOrderSagaManager, SagaManager<ReviseOrderSagaData> reviseOrderSagaManager, OrderDomainEventPublisher orderAggregateEventPublisher, Optional<MeterRegistry> meterRegistry) {
return new OrderService(orderRepository, eventPublisher, restaurantRepository,
createOrderSagaManager, cancelOrderSagaManager, reviseOrderSagaManager, orderAggregateEventPublisher);
createOrderSagaManager, cancelOrderSagaManager, reviseOrderSagaManager, orderAggregateEventPublisher, meterRegistry);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.chrisrichardson.ftgo.orderservice.domain;

public class RestaurantNotFoundException extends RuntimeException {
public RestaurantNotFoundException(long restaurantId) {
super("Restaurant not found with id " + restaurantId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import brave.Span;
import brave.Tracer;
import org.springframework.cloud.sleuth.instrument.web.TraceFilter;
import org.springframework.cloud.sleuth.instrument.web.TraceWebServletAutoConfiguration;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.GenericFilterBean;
Expand All @@ -17,7 +17,7 @@
import java.io.IOException;

@Component
@Order(TraceFilter.ORDER + 1)
@Order(TraceWebServletAutoConfiguration.TRACING_FILTER_ORDER + 1)
class TraceIdResponseFilter extends GenericFilterBean {

private final Tracer tracer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spring.application.name=ftgo-order-service

spring.sleuth.sampler.percentage=1.0
spring.sleuth.sampler.probability=1.0
spring.sleuth.web.skipPattern=(^health.*)

management.endpoints.web.exposure.include=health,prometheus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void setup() {
orderAggregateEventPublisher = mock(OrderDomainEventPublisher.class);

orderService = new OrderService(orderRepository, eventPublisher, restaurantRepository,
createOrderSagaManager, cancelOrderSagaManager, reviseOrderSagaManager, orderAggregateEventPublisher);
createOrderSagaManager, cancelOrderSagaManager, reviseOrderSagaManager, orderAggregateEventPublisher, Optional.empty());
}


Expand Down
2 changes: 2 additions & 0 deletions ftgo-order-service/src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
spring.application.name=ftgo-order-service

logging.level.org.hibernate.SQL=DEBUG
logging.level.org.springframework.cloud.contract=DEBUG
logging.level.io.eventuate=DEBUG
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.chrisrichardson.ftgo.restaurantorderservice.domain;

public class RestaurantOrderNotFoundException extends RuntimeException {
public RestaurantOrderNotFoundException(long orderId) {
super("RestaurantOrder not found: " + orderId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public void createMenu(long id, RestaurantMenu menu) {
restaurantRepository.save(restaurant);
}

public void reviseMenu(long id, RestaurantMenu revisedMenu) {
Restaurant restaurant = restaurantRepository.findById(id).get();
public void reviseMenu(long restaurantOrderId, RestaurantMenu revisedMenu) {
Restaurant restaurant = restaurantRepository.findById(restaurantOrderId)
.orElseThrow(() -> new RestaurantOrderNotFoundException(restaurantOrderId));
restaurant.reviseMenu(revisedMenu);
}

Expand All @@ -42,65 +43,74 @@ public RestaurantOrder createRestaurantOrder(long restaurantId, Long restaurantO
return rwe.result;
}

public void accept(long orderId, LocalDateTime readyBy) {
RestaurantOrder restaurantOrder = restaurantOrderRepository.findById(orderId).get();
public void accept(long restaurantOrderId, LocalDateTime readyBy) {
RestaurantOrder restaurantOrder = restaurantOrderRepository.findById(restaurantOrderId)
.orElseThrow(() -> new RestaurantOrderNotFoundException(restaurantOrderId));
List<RestaurantOrderDomainEvent> events = restaurantOrder.accept(readyBy);
domainEventPublisher.publish(restaurantOrder, events);
}

public void confirmCreateRestaurantOrder(Long restaurantOrderId) {
RestaurantOrder ro = restaurantOrderRepository.findById(restaurantOrderId).get();
RestaurantOrder ro = restaurantOrderRepository.findById(restaurantOrderId)
.orElseThrow(() -> new RestaurantOrderNotFoundException(restaurantOrderId));
List<RestaurantOrderDomainEvent> events = ro.confirmCreate();
domainEventPublisher.publish(ro, events);
}

public void cancelCreateRestaurantOrder(Long restaurantOrderId) {
RestaurantOrder ro = restaurantOrderRepository.findById(restaurantOrderId).get();
RestaurantOrder ro = restaurantOrderRepository.findById(restaurantOrderId)
.orElseThrow(() -> new RestaurantOrderNotFoundException(restaurantOrderId));
List<RestaurantOrderDomainEvent> events = ro.cancelCreate();
domainEventPublisher.publish(ro, events);
}


public void cancelRestaurantOrder(long restaurantId, long orderId) {
RestaurantOrder restaurantOrder = restaurantOrderRepository.findById(orderId).get();
public void cancelRestaurantOrder(long restaurantId, long restaurantOrderId) {
RestaurantOrder restaurantOrder = restaurantOrderRepository.findById(restaurantOrderId)
.orElseThrow(() -> new RestaurantOrderNotFoundException(restaurantOrderId));
// TODO - verify restaurant id
List<RestaurantOrderDomainEvent> events = restaurantOrder.cancel();
domainEventPublisher.publish(restaurantOrder, events);
}


public void confirmCancelRestaurantOrder(long restaurantId, long orderId) {
RestaurantOrder restaurantOrder = restaurantOrderRepository.findById(orderId).get();
public void confirmCancelRestaurantOrder(long restaurantId, long restaurantOrderId) {
RestaurantOrder restaurantOrder = restaurantOrderRepository.findById(restaurantOrderId)
.orElseThrow(() -> new RestaurantOrderNotFoundException(restaurantOrderId));
// TODO - verify restaurant id
List<RestaurantOrderDomainEvent> events = restaurantOrder.confirmCancel();
domainEventPublisher.publish(restaurantOrder, events);
}

public void undoCancel(long restaurantId, long orderId) {
RestaurantOrder restaurantOrder = restaurantOrderRepository.findById(orderId).get();
public void undoCancel(long restaurantId, long restaurantOrderId) {
RestaurantOrder restaurantOrder = restaurantOrderRepository.findById(restaurantOrderId)
.orElseThrow(() -> new RestaurantOrderNotFoundException(restaurantOrderId));
// TODO - verify restaurant id
List<RestaurantOrderDomainEvent> events = restaurantOrder.undoCancel();
domainEventPublisher.publish(restaurantOrder, events);

}

public void beginReviseOrder(long restaurantId, Long orderId, Map<String, Integer> revisedLineItemQuantities) {
RestaurantOrder restaurantOrder = restaurantOrderRepository.findById(orderId).get();
public void beginReviseOrder(long restaurantId, Long restaurantOrderId, Map<String, Integer> revisedLineItemQuantities) {
RestaurantOrder restaurantOrder = restaurantOrderRepository.findById(restaurantOrderId)
.orElseThrow(() -> new RestaurantOrderNotFoundException(restaurantOrderId));
// TODO - verify restaurant id
List<RestaurantOrderDomainEvent> events = restaurantOrder.beginReviseOrder(revisedLineItemQuantities);
domainEventPublisher.publish(restaurantOrder, events);

}

public void undoBeginReviseOrder(long restaurantId, Long orderId) {
RestaurantOrder restaurantOrder = restaurantOrderRepository.findById(orderId).get();
public void undoBeginReviseOrder(long restaurantId, Long restaurantOrderId) {
RestaurantOrder restaurantOrder = restaurantOrderRepository.findById(restaurantOrderId)
.orElseThrow(() -> new RestaurantOrderNotFoundException(restaurantOrderId));
// TODO - verify restaurant id
List<RestaurantOrderDomainEvent> events = restaurantOrder.undoBeginReviseOrder();
domainEventPublisher.publish(restaurantOrder, events);
}

public void confirmReviseRestaurantOrder(long restaurantId, long orderId, Map<String, Integer> revisedLineItemQuantities) {
RestaurantOrder restaurantOrder = restaurantOrderRepository.findById(orderId).get();
public void confirmReviseRestaurantOrder(long restaurantId, long restaurantOrderId, Map<String, Integer> revisedLineItemQuantities) {
RestaurantOrder restaurantOrder = restaurantOrderRepository.findById(restaurantOrderId)
.orElseThrow(() -> new RestaurantOrderNotFoundException(restaurantOrderId));
// TODO - verify restaurant id
List<RestaurantOrderDomainEvent> events = restaurantOrder.confirmReviseRestaurantOrder(revisedLineItemQuantities);
domainEventPublisher.publish(restaurantOrder, events);
Expand Down
Loading

0 comments on commit 6cf5107

Please sign in to comment.