Skip to content

Commit

Permalink
Merge branch 'fix_pom' of github.com:pagopa/pagopa-stand-in-manager i…
Browse files Browse the repository at this point in the history
…nto fix_pom
  • Loading branch information
aomegax committed Jan 11, 2024
2 parents 0728e8e + 5108a62 commit 98a0b54
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 22 deletions.
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: pagopa-stand-in-manager
description: Microservice that handles Stand-In activation/deactivation process
type: application
version: 0.28.0
appVersion: 0.0.1-26-fix_pom
version: 0.35.0
appVersion: 0.0.1-33-fix_pom
dependencies:
- name: microservice-chart
version: 3.0.0
Expand Down
2 changes: 1 addition & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-stand-in-manager
tag: "0.0.1-26-fix_pom"
tag: "0.0.1-33-fix_pom"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ microservice-chart:
namespace: "nodo"
image:
repository: ghcr.io/pagopa/pagopa-stand-in-manager
tag: "0.0.1-26-fix_pom"
tag: "0.0.1-33-fix_pom"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ microservice-chart:
namespace: "nodo"
image:
repository: ghcr.io/pagopa/pagopa-stand-in-manager
tag: "0.0.1-26-fix_pom"
tag: "0.0.1-33-fix_pom"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>it.gov.pagopa</groupId>
<artifactId>stand-in-manager</artifactId>
<version>0.0.1-26-fix_pom</version>
<version>0.0.1-33-fix_pom</version>
<description>Stand in Manager</description>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

import com.azure.cosmos.CosmosClient;
import com.azure.cosmos.CosmosContainer;
import com.azure.cosmos.models.CosmosItemResponse;
import com.azure.cosmos.models.CosmosQueryRequestOptions;
import com.azure.cosmos.models.SqlQuerySpec;
import com.azure.cosmos.models.*;
import com.azure.cosmos.util.CosmosPagedIterable;
import it.gov.pagopa.standinmanager.repository.model.CosmosStandInStation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -34,6 +33,12 @@ private CosmosPagedIterable<CosmosStandInStation> query(SqlQuerySpec query) {
query, new CosmosQueryRequestOptions(), CosmosStandInStation.class);
}

private void delete(CosmosStandInStation station) {
log.info("deleting station:" + station.getStation());
CosmosContainer container = cosmosClient.getDatabase(dbname).getContainer(tablename);
container.deleteItem(station,new CosmosItemRequestOptions());
}

public CosmosItemResponse<CosmosStandInStation> save(CosmosStandInStation item) {
CosmosContainer container = cosmosClient.getDatabase(dbname).getContainer(tablename);
return container.createItem(item);
Expand All @@ -44,8 +49,22 @@ public List<CosmosStandInStation> getStations() {
return query(q).stream().collect(Collectors.toList());
}

public List<CosmosStandInStation> removeStation(String station) {
SqlQuerySpec q = new SqlQuerySpec("SELECT * FROM c");
return query(q).stream().collect(Collectors.toList());
public List<CosmosStandInStation> getStation(String station) {
SqlQuerySpec q = new SqlQuerySpec("SELECT * FROM c where station = @station");
List<SqlParameter> paramList = new ArrayList<>();
paramList.addAll(Arrays.asList(
new SqlParameter("@station", station)
));
return query(q.setParameters(paramList)).stream().collect(Collectors.toList());
}

public Boolean removeStation(CosmosStandInStation station) {
try{
delete(station);
return true;
}catch (Exception e){
log.error("error removing station",e);
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@NoArgsConstructor
@AllArgsConstructor
public class CosmosStandInStation {
private String id;
private String station;
private Instant timestamp;
@JsonProperty("PartitionKey")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
import java.text.DecimalFormat;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Slf4j
@Service
Expand All @@ -43,7 +42,7 @@ public class NodoCalcService {
private String mailto;

@Autowired private CosmosStationRepository cosmosStationRepository;
// @Autowired private StandInStationsRepository standInStationsRepository;
@Autowired private CosmosStationRepository standInStationsRepository;
@Autowired private CosmosNodeDataRepository cosmosRepository;
@Autowired private CosmosEventsRepository cosmosEventsRepository;
@Autowired private AwsSesClient awsSesClient;
Expand All @@ -66,13 +65,20 @@ public void runCalculations()
rangeMinutes,
slotMinutes);

List<CosmosNodeCallCounts> allCounts =
Set<String> standInStations = standInStationsRepository.getStations().stream().map(s->s.getStation()).collect(Collectors.toSet());

List<CosmosNodeCallCounts> allCounts =
cosmosRepository.getStationCounts(now.minusMinutes(rangeMinutes));


Map<String, List<CosmosNodeCallCounts>> allStationCounts =
allCounts.stream().collect(Collectors.groupingBy(CosmosNodeCallCounts::getStation));

allStationCounts.forEach(
(station, stationCounts) -> {
if(standInStations.contains(station)){
return;
}
Map<Instant, List<CosmosNodeCallCounts>> fiveMinutesIntervals =
stationCounts.stream()
.collect(
Expand Down Expand Up @@ -128,15 +134,15 @@ public void runCalculations()
totalSlots,
rangeMinutes);
// standInStationsRepository.save(new StandInStation(station));
cosmosStationRepository.save(new CosmosStandInStation(station,Instant.now()));
cosmosStationRepository.save(new CosmosStandInStation(UUID.randomUUID().toString(),station,Instant.now()));
cosmosEventsRepository.newEvent(
station,
Constants.EVENT_ADD_TO_STANDIN,
String.format(
"adding station [%s] to standIn stations because [%s] of [%s] slots failed",
station, failedSlots, totalSlots));
String sendResult = awsSesClient.sendEmail(
String.format("[StandInManager]Station [%s] added to standin"),
String.format("[StandInManager]Station [%s] added to standin",station),
String.format(
"[StandInManager]Station [%s] has been added to standin"
+ "\nbecause [%s] of [%s] slots failed",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import it.gov.pagopa.standinmanager.repository.CosmosStationDataRepository;
import it.gov.pagopa.standinmanager.repository.CosmosStationRepository;
import it.gov.pagopa.standinmanager.repository.model.CosmosForwarderCallCounts;
import it.gov.pagopa.standinmanager.repository.model.CosmosStandInStation;
import it.gov.pagopa.standinmanager.util.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -74,7 +75,10 @@ public void runCalculations()
successfulCalls,
rangeMinutes);
// standInStationsRepository.deleteById(station);
cosmosStationRepository.removeStation(station);
List<CosmosStandInStation> stations = cosmosStationRepository.getStation(station);
stations.forEach(s->{
cosmosStationRepository.removeStation(s);
});

cosmosEventsRepository.newEvent(
station,
Expand All @@ -85,7 +89,7 @@ public void runCalculations()
station, successfulCalls, rangeMinutes));

awsSesClient.sendEmail(
String.format("[StandInManager]Station [%s] removed from standin"),
String.format("[StandInManager]Station [%s] removed from standin",station),
String.format(
"[StandInManager]Station [%s] has been removed from standin"
+ "\nbecause [%s] calls were successful in the last %s minutes",
Expand Down

0 comments on commit 98a0b54

Please sign in to comment.