Skip to content

Commit

Permalink
HOOK-33: up damsel version (#19)
Browse files Browse the repository at this point in the history
* HOOK-33: up damsel version
  • Loading branch information
inallyoung authored and konanykhin committed Jul 17, 2017
1 parent 5a70e4f commit ae4514b
Show file tree
Hide file tree
Showing 29 changed files with 127 additions and 170 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ build('hooker', 'java-maven') {
}

try {
if (env.BRANCH_NAME == 'master') {
if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME.startsWith('epic')) {
runStage('Push Service image') {
docker.withRegistry('https://dr.rbkmoney.com/v2/', 'dockerhub-rbkmoneycibot') {
serviceImage.push();
Expand Down
22 changes: 15 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>hooker</artifactId>
<version>1.1.3-SNAPSHOT</version>
<version>1.1.4-SNAPSHOT</version>
<packaging>jar</packaging>

<name>hooker</name>
Expand All @@ -22,7 +22,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<postgresql.jdbc.version>9.4.1212</postgresql.jdbc.version>
<dockerfile.base.service.tag>f26fcc19d1941ab74f1c72dd8a408be17a769333</dockerfile.base.service.tag>
<damsel.version>1.151-4018c41</damsel.version>
<damsel.version>1.186-7bb67fc-epic</damsel.version>
<shared.resources.version>0.2.1</shared.resources.version>

<db.host.name>db-pg-shared</db.host.name>
Expand Down Expand Up @@ -65,6 +65,16 @@
<artifactId>okhttp</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>${jooq.version}</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>${flyway.version}</version>
</dependency>
<!--Spring libs-->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -110,14 +120,14 @@
</dependency>
<!--RBK libs-->
<dependency>
<groupId>com.rbkmoney.dbinit</groupId>
<groupId>com.rbkmoney</groupId>
<artifactId>dbinit</artifactId>
<version>1.0.3</version>
<version>1.0.9</version>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>eventstock-client</artifactId>
<version>1.0.7</version>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
Expand Down Expand Up @@ -175,9 +185,7 @@
<version>1.1.8</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<resources>
<resource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.rbkmoney.eventstock.client.*;
import com.rbkmoney.eventstock.client.poll.EventFlowFilter;
import com.rbkmoney.eventstock.client.poll.PollingEventPublisherBuilder;
import com.rbkmoney.hooker.handler.poller.EventStockErrorHandler;
import com.rbkmoney.hooker.handler.poller.EventStockHandler;
import com.rbkmoney.hooker.handler.poller.PollingEventHandler;
import com.rbkmoney.hooker.service.EventService;
Expand Down Expand Up @@ -39,7 +38,6 @@ public EventPublisher eventPublisher() throws IOException {
return new PollingEventPublisherBuilder()
.withURI(bmUri.getURI())
.withEventHandler(new EventStockHandler(pollingEventHandlers))
.withErrorHandler(new EventStockErrorHandler())
.withMaxPoolSize(maxPoolSize)
.withPollDelay(pollDelay)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
*/
public class WebhookAdditionalFilter {
private EventType eventType;
private Integer invoiceShopId;
private String invoiceShopId;
private String invoiceStatus;
private String invoicePaymentStatus;

public WebhookAdditionalFilter(EventType eventType, Integer invoiceShopId, String invoiceStatus, String invoicePaymentStatus) {
public WebhookAdditionalFilter(EventType eventType, String invoiceShopId, String invoiceStatus, String invoicePaymentStatus) {
this.eventType = eventType;
this.invoiceShopId = invoiceShopId;
this.invoiceStatus = invoiceStatus;
this.invoicePaymentStatus = invoicePaymentStatus;
}

public WebhookAdditionalFilter(EventType eventType, Integer invoiceShopId) {
public WebhookAdditionalFilter(EventType eventType, String invoiceShopId) {
this.eventType = eventType;
this.invoiceShopId = invoiceShopId;
}
Expand All @@ -39,11 +39,11 @@ public void setEventType(EventType eventType) {
this.eventType = eventType;
}

public Integer getInvoiceShopId() {
public String getInvoiceShopId() {
return invoiceShopId;
}

public void setInvoiceShopId(Integer invoiceShopId) {
public void setInvoiceShopId(String invoiceShopId) {
this.invoiceShopId = invoiceShopId;
}

Expand All @@ -63,4 +63,4 @@ public void setInvoicePaymentStatus(String invoicePaymentStatus) {
this.invoicePaymentStatus = invoicePaymentStatus;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private String createOrGetPubKey(String partyId) {
rs.getString("pub_key"),
rs.getBoolean("enabled"),
new WebhookAdditionalFilter(EventType.valueOf(rs.getString("event_type")),
rs.getInt("invoice_shop_id"),
rs.getString("invoice_shop_id"),
rs.getString("invoice_status"),
rs.getString("invoice_payment_status")));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class MessageDaoImpl extends NamedParameterJdbcDaoSupport implements Mess
Invoice invoice = new Invoice();
message.setInvoice(invoice);
invoice.setId(rs.getString(INVOICE_ID));
invoice.setShopID(rs.getInt(SHOP_ID));
invoice.setShopID(rs.getString(SHOP_ID));
invoice.setCreatedAt(rs.getString(INVOICE_CREATED_AT));
invoice.setStatus(rs.getString(INVOICE_STATUS));
invoice.setReason(rs.getString(INVOICE_REASON));
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/com/rbkmoney/hooker/handler/Handler.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.rbkmoney.hooker.handler;

import com.rbkmoney.geck.filter.Filter;

/**
* Created by inal on 24.11.2016.
*/
public interface Handler<T> {

boolean accept(T value);

void handle(T value) throws PollingException;
public interface Handler<C, P> {
default boolean accept(C change) {
return getFilter().match(change);
}
void handle(C change, P parent);
Filter getFilter();
}
14 changes: 0 additions & 14 deletions src/main/java/com/rbkmoney/hooker/handler/PollingException.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.rbkmoney.hooker.handler.poller;

import com.rbkmoney.damsel.event_stock.StockEvent;
import com.rbkmoney.damsel.payment_processing.InvoiceChange;
import com.rbkmoney.eventstock.client.EventAction;
import com.rbkmoney.eventstock.client.EventHandler;
import com.rbkmoney.hooker.handler.PollingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -19,22 +20,22 @@ public EventStockHandler(List<PollingEventHandler> pollingEventHandlers) {
}

@Override
public void handleEvent(StockEvent stockEvent, String subsKey) {
for (PollingEventHandler pollingEventHandler : pollingEventHandlers) {
if (pollingEventHandler.accept(stockEvent)) {
try {
pollingEventHandler.handle(stockEvent);
} catch (PollingException e) {
log.error("PaymentStatusError when poller handling", e);
//TODO what should I do?
public EventAction handle(StockEvent stockEvent, String subsKey) {
if (stockEvent.getSourceEvent().getProcessingEvent().getPayload().isSetInvoiceChanges()) {
List<InvoiceChange> invoiceChanges = stockEvent.getSourceEvent().getProcessingEvent().getPayload().getInvoiceChanges();
for (InvoiceChange ic : invoiceChanges) {
for (PollingEventHandler pollingEventHandler : pollingEventHandlers) {
if (pollingEventHandler.accept(ic)) {
try {
pollingEventHandler.handle(ic, stockEvent);
} catch (Exception e) {
log.error("Error when poller handling", e);
}
break;
}
}
break;
}
}
}

@Override
public void handleNoMoreElements(String subsKey) {
log.info("HandleNoMoreElements with subsKey {}", subsKey);
return EventAction.CONTINUE;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.rbkmoney.hooker.handler.poller;

import com.rbkmoney.damsel.event_stock.StockEvent;
import com.rbkmoney.damsel.payment_processing.InvoiceChange;
import com.rbkmoney.hooker.handler.Handler;
import com.rbkmoney.thrift.filter.Filter;

public interface PollingEventHandler<T> extends Handler<T> {
default boolean accept(T value) {
return getFilter().match(value);
}
public interface PollingEventHandler extends Handler<InvoiceChange, StockEvent> {

Filter getFilter();
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
package com.rbkmoney.hooker.handler.poller.impl;

import com.rbkmoney.damsel.event_stock.StockEvent;
import com.rbkmoney.damsel.payment_processing.Event;
import com.rbkmoney.damsel.payment_processing.InvoiceChange;
import com.rbkmoney.hooker.dao.DaoException;
import com.rbkmoney.hooker.handler.poller.PollingEventHandler;

/**
* Created by inalarsanukaev on 07.04.17.
*/
public abstract class AbstractInvoiceEventHandler extends AbstractEventHandler{
public abstract class AbstractInvoiceEventHandler implements PollingEventHandler {

public static final String INVOICE = "invoice";
public static final String PAYMENT = "payment";

@Override
public void handle(InvoiceChange ic, StockEvent value){
Event event = value.getSourceEvent().getProcessingEvent();
saveEvent(ic, event);
}

protected abstract void saveEvent(InvoiceChange ic, Event event) throws DaoException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import com.rbkmoney.damsel.domain.Invoice;
import com.rbkmoney.damsel.payment_processing.Event;
import com.rbkmoney.damsel.payment_processing.InvoiceChange;
import com.rbkmoney.geck.filter.Filter;
import com.rbkmoney.geck.filter.PathConditionFilter;
import com.rbkmoney.geck.filter.condition.IsNullCondition;
import com.rbkmoney.geck.filter.rule.PathConditionRule;
import com.rbkmoney.hooker.dao.DaoException;
import com.rbkmoney.hooker.dao.MessageDao;
import com.rbkmoney.hooker.model.EventType;
import com.rbkmoney.hooker.model.InvoiceContent;
import com.rbkmoney.hooker.model.Message;
import com.rbkmoney.thrift.filter.Filter;
import com.rbkmoney.thrift.filter.PathConditionFilter;
import com.rbkmoney.thrift.filter.rule.PathConditionRule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -24,12 +26,12 @@ public class InvoiceCreatedHandler extends AbstractInvoiceEventHandler {
private EventType eventType = EventType.INVOICE_CREATED;

public InvoiceCreatedHandler() {
filter = new PathConditionFilter(new PathConditionRule(eventType.getThriftFilterPathCoditionRule()));
filter = new PathConditionFilter(new PathConditionRule(eventType.getThriftFilterPathCoditionRule(), new IsNullCondition().not()));
}

@Override
protected void saveEvent(Event event) throws DaoException {
Invoice invoiceOrigin = event.getPayload().getInvoiceEvent().getInvoiceCreated().getInvoice();
protected void saveEvent(InvoiceChange ic, Event event) throws DaoException {
Invoice invoiceOrigin = ic.getInvoiceCreated().getInvoice();
//////
Message message = new Message();
message.setEventId(event.getId());
Expand Down
Loading

0 comments on commit ae4514b

Please sign in to comment.