Skip to content

Commit

Permalink
Merge pull request #12 from pankajjangid05/prod-development
Browse files Browse the repository at this point in the history
Prod development
  • Loading branch information
pankajjangid05 authored May 8, 2023
2 parents c02638a + 3263b94 commit b7e4741
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 39 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ name: Github Package
on:
push:
tags:
- 'v*.*.*'
["v*.*.*", "v*.*.*-*"]
branches:
["release-4.*.*", "release-5.*.*", "release-v2.*.*"]
["release-4.*.*", "release-5.*.*", "release-v2.*.*", "master", "development"]
pull_request:
branches:
["release-4.*.*", "release-5.*.*", "release-v2.*.*"]
["release-4.*.*", "release-5.*.*", "release-v2.*.*", "master", "development"]


jobs:
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
- name: Delete package specific version
uses: smartsquaregmbh/delete-old-packages@v0.4.0
with:
version: 2.1.0 # This should be same as in the pom.xml file,
version: 2.2.1 # This should be same as in the pom.xml file,
# to delete only the pom specified version, not the other older versions
names: |
com.uci.dao
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Maven Build
on:
push:
branches:
["release-4.*.*", "release-5.*.*", "release-v2.*.*"]
["release-4.*.*", "release-5.*.*", "release-v2.*.*", "master", "development"]
pull_request:
branches:
["release-4.*.*", "release-5.*.*", "release-v2.*.*"]
["release-4.*.*", "release-5.*.*", "release-v2.*.*", "master", "development"]

jobs:
build:
Expand Down
8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<name>dao</name>
<description>dao</description>
<packaging>jar</packaging>
<version>2.1.0</version>
<version>2.2.1</version>
<!-- On changing, Set version in deploy.xml to delete the previous packages if exists and deploy new package for the specified version -->

<parent>
Expand All @@ -21,6 +21,8 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<utils.version>2.2.1</utils.version>
<messagerosa.version>2.2.1</messagerosa.version>
</properties>
<!-- For Dao repository to upload to github packages -->
<profiles>
Expand Down Expand Up @@ -99,13 +101,13 @@
<dependency>
<groupId>com.uci</groupId>
<artifactId>message-rosa</artifactId>
<version>2.1.0</version>
<version>${messagerosa.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.uci</groupId>
<artifactId>utils</artifactId>
<version>2.1.0</version>
<version>${utils.version}</version>
<scope>compile</scope>
</dependency>

Expand Down
57 changes: 27 additions & 30 deletions src/main/java/com/uci/dao/service/HealthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,42 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.uci.dao.repository.XMessageRepository;
import com.uci.utils.UtilHealthService;
import reactor.core.publisher.Mono;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Service;

@Service
public class HealthService extends UtilHealthService {
@Autowired
private XMessageRepository xMessageRepository;

@Autowired
ObjectMapper mapper;

/**
* Returns health node
*
* @return Mono<JsonNode>
*/
public Mono<JsonNode> getCassandraHealthNode() {
return getIsCassandraHealthy().map(healthy -> new ObjectMapper().createObjectNode().put("healthy", healthy));
return Mono.fromCallable(() -> {
ObjectNode result = mapper.createObjectNode();
try {
xMessageRepository.existsByUserId("Test");
result.put("status", Status.UP.getCode());
return result;
} catch(Exception e) {
result.put("status", Status.DOWN.getCode());
result.put("message", e.getMessage());
return result;
}
});
}

/**
Expand All @@ -36,37 +52,18 @@ public Mono<JsonNode> getCassandraHealthNode() {
public Mono<JsonNode> getAllHealthNode() {
ObjectNode resultNode = new ObjectMapper().createObjectNode();
Mono<JsonNode> externalComponentHealth = super.getAllHealthNode();
Mono<JsonNode> cassandraHealth = getCassandraHealthNode().map(result -> {
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("name", "cassandra");
objectNode.set("healthy", result.get("healthy"));
return objectNode;
});
return Mono.zip(externalComponentHealth, cassandraHealth).map(healths -> {
resultNode.putArray("checks")
.add(healths.getT1().get("checks"))
.add(healths.getT2());
resultNode.put("healthy",
healths.getT1().get("healthy").booleanValue() &&
healths.getT2().get("healthy").booleanValue()
Mono<JsonNode> cassandraHealth = getCassandraHealthNode();
return Mono.zip(externalComponentHealth, cassandraHealth).map(results -> {
ObjectNode detailsNode = mapper.createObjectNode();
detailsNode.set("cassandra", results.getT2());
results.getT1().get("details").fields().forEachRemaining(detail -> detailsNode.set(detail.getKey(), detail.getValue()));
resultNode.set("details", detailsNode);
resultNode.put("status",
results.getT1().get("status").textValue().equals(Status.UP.getCode()) &&
results.getT2().get("status").textValue().equals(Status.UP.getCode())
? Status.UP.getCode() : Status.DOWN.getCode()
);
return resultNode;
});
}

/**
* Check if Cassandra connecting or not
*
* @return Mono<Boolean>
*/
private Mono<Boolean> getIsCassandraHealthy() {
return Mono.fromCallable(() -> {
try {
xMessageRepository.existsByUserId("Test");
return true;
} catch(Exception e) {
return false;
}
});
}
}

0 comments on commit b7e4741

Please sign in to comment.