Commit 8b7c2364 authored by Artem Dobrynin (EPAM)'s avatar Artem Dobrynin (EPAM) Committed by Riabokon Stanislav(EPAM)[GCP]
Browse files

Migrate Partition Service to Anthos (new approach) (GONRG-3881)

parent e5739aec
......@@ -55,12 +55,6 @@
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.1.10.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
......@@ -70,11 +64,6 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-data-datastore</artifactId>
<version>1.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
......
......@@ -20,17 +20,13 @@ package org.opengroup.osdu.partition.provider.gcp;
import org.opengroup.osdu.core.gcp.di.GcpPartitionClientFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gcp.data.datastore.repository.config.EnableDatastoreRepositories;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@ComponentScan(basePackages = {"org.opengroup.osdu"}, excludeFilters =
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {GcpPartitionClientFactory.class})
)
@SpringBootApplication
@EnableDatastoreRepositories
@EnableTransactionManagement
public class PartitionGcpApplication {
public static void main(String[] args) {
......
......@@ -32,6 +32,7 @@ import org.springframework.stereotype.Component;
import org.threeten.bp.Duration;
import java.io.IOException;
import java.util.Map;
import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_SINGLETON;
......@@ -43,7 +44,7 @@ public class OsmDatastoreDestinationResolver implements DsDestinationResolver {
protected static final RetrySettings RETRY_SETTINGS = RetrySettings.newBuilder().setMaxAttempts(6).setInitialRetryDelay(Duration.ofSeconds(10L)).setMaxRetryDelay(Duration.ofSeconds(32L)).setRetryDelayMultiplier(2.0D).setTotalTimeout(Duration.ofSeconds(50L)).setInitialRpcTimeout(Duration.ofSeconds(50L)).setRpcTimeoutMultiplier(1.0D).setMaxRpcTimeout(Duration.ofSeconds(50L)).build();
protected static final TransportOptions TRANSPORT_OPTIONS = HttpTransportOptions.newBuilder().setReadTimeout(30000).build();
private final Datastore partitionDatastore;
private final Map<String, Datastore> datastoreCache;
/**
* Takes provided Destination with partitionId set to needed tenantId, returns its TenantInfo.projectId.
......@@ -54,17 +55,7 @@ public class OsmDatastoreDestinationResolver implements DsDestinationResolver {
@Override
public DsDestinationResolution resolve(Destination destination) {
String projectId = destination.getPartitionId();
Datastore datastore =
partitionDatastore == null
? DatastoreOptions.newBuilder()
.setRetrySettings(RETRY_SETTINGS)
.setTransportOptions(TRANSPORT_OPTIONS)
.setProjectId(projectId)
.setNamespace(destination.getNamespace().getName())
.build()
.getService()
: partitionDatastore;
Datastore datastore = datastoreCache.computeIfAbsent(projectId, key -> getDatastoreFor(destination, key, projectId));
return DsDestinationResolution.builder()
.projectId(datastore.getOptions().getProjectId())
......@@ -72,6 +63,17 @@ public class OsmDatastoreDestinationResolver implements DsDestinationResolver {
.build();
}
private Datastore getDatastoreFor(Destination destination, String key, String projectId) {
return datastoreCache.computeIfAbsent(key, k ->
DatastoreOptions.newBuilder()
.setRetrySettings(RETRY_SETTINGS)
.setTransportOptions(TRANSPORT_OPTIONS)
.setProjectId(projectId)
.setNamespace(destination.getNamespace().getName())
.build()
.getService());
}
@Override
public void close() throws IOException {
//Method stub
......
......@@ -71,7 +71,7 @@ public class AuthorizationService implements IAuthorizationService {
} catch (AppException e){
throw e;
} catch (Exception ex) {
log.warn(String.format("User %s is not unauthorized. %s.", email, ex));
log.warn(String.format("User %s unauthorized. %s.", email, ex));
throw AppException.createUnauthorized("Unauthorized. The JWT token could not be validated");
}
}
......
......@@ -29,16 +29,10 @@ import org.opengroup.osdu.partition.provider.gcp.model.PartitionPropertyEntity;
import org.opengroup.osdu.partition.provider.gcp.osm.repository.OsmPartitionPropertyRepository;
import org.opengroup.osdu.partition.provider.interfaces.IPartitionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
@Service
@RequiredArgsConstructor
......@@ -178,7 +172,6 @@ public class PartitionServiceImpl implements IPartitionService {
}
}
@Transactional
@Override
public boolean deletePartition(String partitionId) {
if (!this.partitionPropertyEntityRepository.findByPartitionId(partitionId).isPresent()) {
......@@ -195,16 +188,15 @@ public class PartitionServiceImpl implements IPartitionService {
return true;
}
@Transactional
@Override
public List<String> getAllPartitions() {
List<String> partitions = partitionListCache.get(PARTITION_LIST_KEY);
if (partitions == null) {
List<String> allPartitions = this.partitionPropertyEntityRepository.getAllPartitions();
partitions = (allPartitions.isEmpty() ? null : allPartitions);
partitions = (allPartitions.isEmpty() ? Collections.emptyList() : allPartitions);
if (partitions != null) {
if (!CollectionUtils.isEmpty(partitions)) {
partitionListCache.put(PARTITION_LIST_KEY, partitions);
}
}
......
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