Skip to content

Commit

Permalink
Added remote refreshing mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
openwms committed Mar 5, 2024
1 parent e42c370 commit 41ed70c
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/openwms/wms/movements/IndexController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.openwms.wms.movements;

import org.openwms.core.http.Index;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -29,6 +30,7 @@
* @author Heiko Scherrer
*/
@RestController("movementsIndexController")
@RefreshScope
class IndexController {

@GetMapping("/index")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.openwms.wms.movements.api.MovementVO;
import org.openwms.wms.movements.impl.ValidationGroups;
import org.openwms.wms.movements.spi.DefaultMovementState;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -48,6 +49,7 @@
*/
@Validated
@MeasuredRestController
@RefreshScope
public class MovementController extends AbstractWebController {

private final MovementService service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.openwms.wms.movements;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
Expand All @@ -30,6 +31,7 @@
*/
@Configuration
@ConfigurationProperties("owms.movement")
@RefreshScope
public class MovementProperties {

/** Shall the Putaway API be called to resolve a final target for Movements. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.retry.backoff.ExponentialBackOffPolicy;
import org.springframework.retry.support.RetryTemplate;

import java.util.Objects;

import static org.ameba.LoggingCategories.BOOT;

/**
Expand All @@ -52,6 +55,7 @@
*/
@Profile(SpringProfiles.ASYNCHRONOUS_PROFILE)
@EnableRabbit
@RefreshScope
@Configuration
class MovementAsyncConfiguration {

Expand All @@ -61,15 +65,15 @@ class MovementAsyncConfiguration {
@ConditionalOnExpression("'${owms.movements.serialization}'=='json'")
@Bean
MessageConverter messageConverter() {
Jackson2JsonMessageConverter messageConverter = new Jackson2JsonMessageConverter();
var messageConverter = new Jackson2JsonMessageConverter();
BOOT_LOGGER.info("Using JSON serialization over AMQP");
return messageConverter;
}

@ConditionalOnExpression("'${owms.movements.serialization}'=='barray'")
@Bean
MessageConverter serializerMessageConverter() {
SerializerMessageConverter messageConverter = new SerializerMessageConverter();
var messageConverter = new SerializerMessageConverter();
BOOT_LOGGER.info("Using byte array serialization over AMQP");
return messageConverter;
}
Expand All @@ -79,15 +83,15 @@ MessageConverter serializerMessageConverter() {
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory,
ObjectProvider<MessageConverter> messageConverter,
@Autowired(required = false) RabbitTemplateConfigurable rabbitTemplateConfigurable) {
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
var rabbitTemplate = new RabbitTemplate(connectionFactory);
var backOffPolicy = new ExponentialBackOffPolicy();
backOffPolicy.setMultiplier(2);
backOffPolicy.setMaxInterval(15000);
backOffPolicy.setInitialInterval(500);
RetryTemplate retryTemplate = new RetryTemplate();
var retryTemplate = new RetryTemplate();
retryTemplate.setBackOffPolicy(backOffPolicy);
rabbitTemplate.setRetryTemplate(retryTemplate);
rabbitTemplate.setMessageConverter(messageConverter.getIfUnique());
rabbitTemplate.setMessageConverter(Objects.requireNonNull(messageConverter.getIfUnique()));
if (rabbitTemplateConfigurable != null) {
rabbitTemplateConfigurable.configure(rabbitTemplate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -65,6 +66,7 @@
@EnableJpaAuditing
@EnableAspects(propagateRootCause = true)
@EnableScheduling
@RefreshScope
@Import(JSONConfiguration.class)
public class MovementModuleConfiguration implements WebMvcConfigurer {

Expand All @@ -87,13 +89,13 @@ public void addInterceptors(InterceptorRegistry registry) {
}

public @Bean LocaleResolver localeResolver() {
SessionLocaleResolver slr = new SessionLocaleResolver();
var slr = new SessionLocaleResolver();
slr.setDefaultLocale(Locale.US);
return slr;
}

public @Bean LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
var lci = new LocaleChangeInterceptor();
lci.setParamName("lang");
return lci;
}
Expand All @@ -108,7 +110,7 @@ protected MessageSource getMessageSource() {
}

@Bean MessageSource messageSource() {
NestedReloadableResourceBundleMessageSource messageSource = new NestedReloadableResourceBundleMessageSource();
var messageSource = new NestedReloadableResourceBundleMessageSource();
messageSource.setBasenames("classpath:/META-INF/i18n/mvm");
messageSource.setDefaultEncoding("UTF-8");
messageSource.setCommonMessages(new Properties());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class MovementCommandListener {
@RabbitListener(queues = "${owms.commands.movements.movement.queue-name}")
public void onCommand(@Valid @NotNull @Payload MovementCommand command) {
if (command.getType() == MovementCommand.Type.CREATE) {
MovementMO movement = command.getMovement();
var movement = command.getMovement();
LOGGER.debug("Got command to create a Movement [{}]", movement);
movementService.create(movement.getTransportUnitBK(), mapper.map(movement, MovementVO.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ReservationMessageListener(MovementService movementService) {
@Measured
@RabbitListener(queues = "${owms.events.shipping.split.queue-name}")
public void handle(@Payload SplitMO mo, @Header("amqp_receivedRoutingKey") String routingKey) {
MovementVO movement = new MovementVO();
var movement = new MovementVO();
movement.setTransportUnitBk(mo.getTransportUnitBK());
movement.setPriority(mo.getPriority());
movement.setTarget(mo.getTargetName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
import org.ameba.exception.NotFoundException;
import org.ameba.i18n.Translator;
import org.openwms.common.location.api.LocationApi;
import org.openwms.common.location.api.LocationVO;
import org.openwms.common.location.api.messages.LocationMO;
import org.openwms.common.transport.api.commands.TUCommand;
import org.openwms.common.transport.api.messages.TransportUnitMO;
import org.openwms.wms.movements.spi.common.AsyncTransportUnitApi;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

import java.util.Optional;

import static org.openwms.wms.movements.MovementsMessages.LOCATION_NOT_FOUND_BY_ERP_CODE;

/**
Expand All @@ -50,7 +47,7 @@ class MovementEventListener {

@TransactionalEventListener
public void onEvent(MovementTargetChangedEvent event) {
Optional<LocationVO> locationByErpCode = locationApi.findByErpCode(event.getSource().getTargetLocation());
var locationByErpCode = locationApi.findByErpCode(event.getSource().getTargetLocation());
if (locationByErpCode.isPresent()) {
asyncTransportUnitApi.process(
TUCommand.newBuilder(TUCommand.Type.CHANGE_TARGET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.plugin.core.PluginRegistry;
import org.springframework.validation.annotation.Validated;
Expand Down Expand Up @@ -71,6 +72,7 @@
*/
@Validated
@TxService
@RefreshScope
class MovementServiceImpl implements MovementService {

private static final Logger LOGGER = LoggerFactory.getLogger(MovementServiceImpl.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
package org.openwms.wms.movements.impl;

import org.ameba.annotation.TxService;
import org.openwms.common.location.api.LocationVO;
import org.openwms.wms.movements.Message;
import org.openwms.wms.movements.MovementProperties;
import org.openwms.wms.movements.spi.common.putaway.PutawayApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -36,6 +36,7 @@
* @author Heiko Scherrer
*/
@TxService
@RefreshScope
class PutawayAdapter {

private static final Logger LOGGER = LoggerFactory.getLogger(PutawayAdapter.class);
Expand All @@ -61,7 +62,7 @@ public void onEvent(MovementEvent event) {
try {
var movementTarget = properties.findTarget(movement.getTargetLocationGroup());
LOGGER.debug("Call putaway strategy to find target location for movement [{}] in [{}]", movement.getPersistentKey(), movementTarget.getSearchLocationGroupNames());
LocationVO target = putawayApi.findAndAssignNextInLocGroup(
var target = putawayApi.findAndAssignNextInLocGroup(
movement.getInitiator(),
movementTarget.getSearchLocationGroupNames(),
movement.getTransportUnitBk().getValue(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.openwms.transactions.api.commands.TransactionCommand;
import org.openwms.wms.movements.spi.common.AsyncTransportUnitApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;
Expand All @@ -47,6 +48,7 @@
*/
@Profile(SpringProfiles.ASYNCHRONOUS_PROFILE)
@Component
@RefreshScope
class TransactionWriter {

private final String applicationName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.openwms.wms.movements.spi;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

Expand All @@ -26,6 +27,7 @@
*/
@Profile("!CUSTOM")
@Component
@RefreshScope
class DefaultMovementStateResolver implements MovementStateResolver {

private final DefaultMovementState newState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import org.ameba.annotation.Measured;
import org.openwms.wms.movements.MovementProperties;
import org.openwms.wms.movements.MovementTarget;
import org.openwms.wms.movements.api.MovementType;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
Expand All @@ -34,6 +34,7 @@
@Validated
@Profile("!CUSTOM")
@Component
@RefreshScope
class DefaultMovementTypeResolver implements MovementTypeResolver {

private final MovementProperties properties;
Expand All @@ -48,7 +49,6 @@ class DefaultMovementTypeResolver implements MovementTypeResolver {
@Override
@Measured
public Optional<MovementType> resolve(@NotEmpty String transportUnitBK, @NotEmpty String target) {
MovementTarget movementTarget = properties.findTarget(target);
return Optional.of(movementTarget.getType());
return Optional.of(properties.findTarget(target).getType());
}
}

0 comments on commit 41ed70c

Please sign in to comment.