Skip to content

Commit

Permalink
Oppdatert config #deploy-test-dolly-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
krharum committed Oct 23, 2023
1 parent 011ecbc commit ba9297f
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 56 deletions.
4 changes: 2 additions & 2 deletions apps/dolly-backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
implementation 'org.springframework.retry:spring-retry:2.0.0'

// implementation 'org.opensearch.client:spring-data-opensearch:1.1.0'
implementation 'org.opensearch.client:spring-data-opensearch-starter:1.2.0'
implementation 'org.opensearch.client:spring-data-opensearch:1.2.0'
// implementation 'com.fasterxml.jackson.core:jackson-core:2.15.2'
// implementation 'org.elasticsearch.client:elasticsearch-rest-high-level-client:7.16.1'

Expand Down
3 changes: 2 additions & 1 deletion apps/dolly-backend/config.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ spec:
tenant: nav.no
image: {{image}}
openSearch:
instance: dolly-bestilling-test
instance: dolly-bestilling-dev
access: admin
env:
- name: SPRING_PROFILES_ACTIVE
value: dev
envFrom:
- secret: user-encryption-dev
- secret: dolly-bestilling-dev
replicas:
min: 1
max: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package no.nav.dolly;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration;

@SpringBootApplication
@Slf4j
@SpringBootApplication(exclude = {ElasticsearchDataAutoConfiguration.class})
public class DollyBackendApplicationStarter {
public static void main(String[] args) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
package no.nav.dolly.config;

import org.opensearch.client.RestHighLevelClient;
import org.opensearch.data.client.orhlc.AbstractOpenSearchConfiguration;
import org.opensearch.data.client.orhlc.ClientConfiguration;
import org.opensearch.data.client.orhlc.RestClients;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchConfiguration;

import java.time.Duration;

@Profile({"prod", "dev"})
@Profile("!test")
@Configuration
public class ElasticSearchConfig extends ReactiveElasticsearchConfiguration {
public class ElasticSearchConfig extends AbstractOpenSearchConfiguration {

@Value("${OPEN_SEARCH_USERNAME}")
@Value("${open.search.username}")
private String username;

@Value("${OPEN_SEARCH_PASSWORD}")
@Value("${open.search.password}")
private String password;

@Value("${OPEN_SEARCH_URI}")
@Value("${open.search.uri}")
private String uri;

@Value("${open.search.port}")
private String port;

@Override
public ClientConfiguration clientConfiguration() {
return ClientConfiguration.builder()
.connectedTo(uri.replace("https://", ""))
public RestHighLevelClient opensearchClient() {

return RestClients.create(ClientConfiguration.builder()
.connectedTo(String.format("%s:%s", uri, port))
.usingSsl()
.withBasicAuth(username, password)
.withConnectTimeout(Duration.ofSeconds(10))
.withSocketTimeout(Duration.ofSeconds(5))
.build();
.build())
.rest();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.nav.dolly.elastic;

import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

public interface BestillingElasticRepository extends ElasticsearchRepository<ElasticBestilling, Long> {
public interface BestillingElasticRepository {
// public interface BestillingElasticRepository extends ElasticsearchRepository<ElasticBestilling, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package no.nav.dolly.provider.api;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import no.nav.dolly.domain.jpa.Bestilling;
import no.nav.dolly.domain.resultset.RsDollyBestilling;
import no.nav.dolly.service.ElasticService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/elastic")
@RequiredArgsConstructor
public class ElasticController {

private final ElasticService elasticService;

@Deprecated
@PostMapping
public void lagreBestilling(@RequestBody Wrapper bestilling) {

elasticService.lagreBestillingMedStatus(bestilling.getDollyBestilling(), bestilling.getBestillingStatus());
}

@GetMapping
public List<String> getIdenter() {

return null;
}

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class Wrapper {

private RsDollyBestilling dollyBestilling;
private Bestilling bestillingStatus;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import no.nav.dolly.domain.resultset.aareg.RsAareg;
import no.nav.dolly.domain.resultset.aareg.RsOrganisasjon;
import no.nav.dolly.domain.resultset.entity.bestilling.RsBestillingFragment;
import no.nav.dolly.elastic.BestillingElasticRepository;
import no.nav.dolly.elastic.ElasticBestilling;
import no.nav.dolly.exceptions.ConstraintViolationException;
import no.nav.dolly.exceptions.DollyFunctionalException;
import no.nav.dolly.exceptions.NotFoundException;
Expand Down Expand Up @@ -77,7 +75,6 @@ public class BestillingService {
private final TestgruppeRepository testgruppeRepository;
private final BrukerService brukerService;
private final GetUserInfo getUserInfo;
private final BestillingElasticRepository bestillingElasticRepository;
private final MapperFacade mapperFacade;

public Bestilling fetchBestillingById(Long bestillingId) {
Expand Down Expand Up @@ -224,7 +221,6 @@ public Bestilling saveBestilling(RsDollyUpdateRequest request, String ident) {
if (isNotBlank(request.getMalBestillingNavn())) {
bestillingMalService.saveBestillingMal(bestilling, request.getMalBestillingNavn(), bruker);
}
saveBestillingToElasticServer(request);
return saveBestillingToDB(bestilling);
}

Expand All @@ -248,7 +244,6 @@ public Bestilling saveBestilling(Long gruppeId, RsDollyBestilling request, Integ
if (isNotBlank(request.getMalBestillingNavn())) {
bestillingMalService.saveBestillingMal(bestilling, request.getMalBestillingNavn(), bruker);
}
saveBestillingToElasticServer(request);
return saveBestillingToDB(bestilling);
}

Expand Down Expand Up @@ -335,7 +330,6 @@ public Bestilling saveBestilling(Long gruppeId, RsDollyImportFraPdlRequest reque
if (isNotBlank(request.getMalBestillingNavn())) {
bestillingMalService.saveBestillingMal(bestilling, request.getMalBestillingNavn(), bruker);
}
saveBestillingToElasticServer(request);
return saveBestillingToDB(bestilling);
}

Expand All @@ -346,7 +340,6 @@ public Bestilling saveBestilling(Long gruppeId, RsDollyBestillingLeggTilPaaGrupp
var size = identRepository.countByTestgruppe(gruppeId);
log.info("Antall testidenter {} i gruppe {} ", size, gruppeId);
fixAaregAbstractClassProblem(request.getAareg());
saveBestillingToElasticServer(request);
return saveBestillingToDB(
Bestilling.builder()
.gruppe(gruppe)
Expand Down Expand Up @@ -449,11 +442,4 @@ private static void fixAaregAbstractClassProblem(List<RsAareg> aaregdata) {
}
});
}

private void saveBestillingToElasticServer(RsDollyBestilling request) {

if (request.isNonEmpty()) {
bestillingElasticRepository.save(mapperFacade.map(request, ElasticBestilling.class));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package no.nav.dolly.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import ma.glasnost.orika.MapperFacade;
import no.nav.dolly.domain.jpa.Bestilling;
import no.nav.dolly.domain.jpa.BestillingProgress;
import no.nav.dolly.domain.resultset.RsDollyBestilling;
import no.nav.dolly.elastic.ElasticBestilling;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.stereotype.Service;

import java.util.List;

import static org.apache.commons.lang3.StringUtils.isBlank;

@Slf4j
@Service
@RequiredArgsConstructor
public class ElasticService {

private final MapperFacade mapperFacade;
// private final ElasticsearchRepository elasticsearchRepository;
private final ElasticsearchOperations elasticsearchOperations;

public void lagreBestillingMedStatus(RsDollyBestilling dollyBestilling, Bestilling bestillingMedStatus) {

var elasticBestilling = mapperFacade.map(dollyBestilling, ElasticBestilling.class);
elasticBestilling.setIdenter(bestillingMedStatus.getProgresser().stream()
.filter(BestillingProgress::isIdentGyldig)
.filter(progress -> isBlank(progress.getFeil()))
.map(BestillingProgress::getIdent)
.toList());

// var resultat = elasticsearchRepository.save(elasticBestilling);
//
// log.info("Elastic search record lagret {}", resultat);
}

public List<String> getIdenterForBestilling() {


// elasticsearchOperations.search()
return null;
}
}
7 changes: 7 additions & 0 deletions apps/dolly-backend/src/main/resources/application-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ management:
path-mapping:
prometheus: "prometheus"

open:
search:
username: dolly
password: kBU0JYmilht2pGRQ
uri: opensearch-dolly-testdata-gjeter-nav-dev.aivencloud.com
port: 26482

consumers:
testnav-pdl-forvalter:
name: testnav-pdl-forvalter-dev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import java.time.LocalDate;
import java.util.List;
Expand All @@ -21,6 +22,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

@ActiveProfiles("test")
@SpringBootTest
class TestgruppeMappingStrategyTest {

Expand Down

0 comments on commit ba9297f

Please sign in to comment.