Commit 3be3b176 authored by Dmitriy Novikov's avatar Dmitriy Novikov
Browse files

Replace DpsHeaders with ThreadLocalHeaders

parent 2fec6092
Pipeline #100802 failed with stages
in 35 seconds
......@@ -17,12 +17,11 @@
package org.opengroup.osdu.indexer.di;
import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
......@@ -34,18 +33,14 @@ import org.springframework.stereotype.Component;
@Component("gcpTenantInfoFactory")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Primary
@RequiredArgsConstructor
public class TenantInfoFactory implements FactoryBean<TenantInfo> {
@Autowired
private ITenantFactory tenantFactory;
@Autowired
private DpsHeaders headers;
public TenantInfoFactory() {
}
private final ITenantFactory tenantFactory;
private final ThreadLocalHeaders headers;
public TenantInfo getObject() throws Exception {
String id = this.headers.getPartitionIdWithFallbackToAccountId();
String id = headers.getDataPartitionIdAtomic().get();
TenantInfo tenantInfo = this.tenantFactory.getTenantInfo(id);
if (tenantInfo == null) {
throw AppException.createUnauthorized(
......@@ -59,6 +54,7 @@ public class TenantInfoFactory implements FactoryBean<TenantInfo> {
return TenantInfo.class;
}
@Override
public boolean isSingleton() {
return false;
}
......
......@@ -3,7 +3,6 @@ package org.opengroup.osdu.indexer.di;
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.multitenancy.ITenantInfoService;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
......@@ -20,11 +19,11 @@ import org.springframework.web.context.annotation.RequestScope;
public class TenantInfoService implements ITenantInfoService {
private final ITenantFactory tenantFactory;
private final DpsHeaders headers;
private final ThreadLocalHeaders headers;
@Override
public TenantInfo getTenantInfo() {
return tenantFactory.getTenantInfo(headers.getPartitionId());
return tenantFactory.getTenantInfo(headers.getDataPartitionIdAtomic().get());
}
@Override
......
......@@ -67,11 +67,11 @@ public class OqmSubscriberManager {
private static final String ACKNOWLEDGE = "message acknowledged by client";
private static final String NOT_ACKNOWLEDGE = "message not acknowledged by client";
private final OqmDriver driver;
private final IndexerConfigProperties properties;
private final ITenantFactory tenantFactory;
private final IndexerService indexerService;
private final ReindexService reindexService;
private final OqmDriver driver;
private String subscriptionName;
......@@ -154,8 +154,7 @@ public class OqmSubscriberManager {
}
private void ackSendingMessage(OqmMessage oqmMessage, OqmAckReplier oqmAckReplier) {
DpsHeaders headers = getHeaders(oqmMessage);
if (headers.getPartitionId() == null) {
if (oqmMessage.getAttributes().get("data-partition-id") == null) {
log.error("Partition id is not set for message: {}", oqmMessage.getId());
oqmAckReplier.ack();
}
......@@ -214,13 +213,6 @@ public class OqmSubscriberManager {
return new Gson().fromJson(recordChangedMessages.getData(), listType);
}
@NotNull
private DpsHeaders getHeaders(OqmMessage oqmMessage) {
DpsHeaders headers = new DpsHeaders();
headers.getHeaders().put("data-partition-id", oqmMessage.getAttributes().get("data-partition-id"));
return headers;
}
private OqmDestination getDestination(TenantInfo tenantInfo) {
return OqmDestination.builder()
.partitionId(tenantInfo.getDataPartitionId())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment