Skip to content

Commit

Permalink
Merge branch 'release-4.9.0' of https://github.com/samagra-comms/orch…
Browse files Browse the repository at this point in the history
…estrator into release-4.10.0
  • Loading branch information
surabhi-mahawar committed Jul 22, 2022
2 parents c3709b6 + 8e8891a commit 8fa65e9
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 71 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Build on Push & Pull Request
# Build on Push & Pull Request
name: Maven Build
on:
push:
branches:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Docker Build & Push on Tag

# Docker Build & Push on Tag
name: Docker Build
on:
push:
tags:
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
![Maven Build](https://github.com/samagra-comms/orchestrator/actions/workflows/build.yml/badge.svg)
![Docker Build](https://github.com/samagra-comms/orchestrator/actions/workflows/docker-build-push.yml/badge.svg)

# Overview
Orchestrator authenticates & processes the user data from whom the message is received. The XMessage will then be pushed to the kafka topic, the transformer will listen to this topic to further process it.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public class ReactiveConsumer {
@Value("${broadcast-transformer}")
public String broadcastTransformerTopic;

@Value("${generic-transformer}")
public String genericTransformerTopic;

@Autowired
public BotService botService;

Expand Down Expand Up @@ -167,6 +170,8 @@ public void accept(XMessage msg) {
log.info("final msg.toXML(): "+msg.toXML().toString());
if(firstTransformer.get("type") != null && firstTransformer.get("type").asText().equals("broadcast")) {
kafkaProducer.send(broadcastTransformerTopic, msg.toXML());
} else if(firstTransformer.get("type") != null && firstTransformer.get("type").asText().equals("generic")) {
kafkaProducer.send(genericTransformerTopic, msg.toXML());
} else {
kafkaProducer.send(odkTransformerTopic, msg.toXML());
}
Expand Down Expand Up @@ -242,6 +247,10 @@ private XMessage setXMessageTransformers(XMessage xMessage, JsonNode campaign) {
metaData.put("federatedUsers", getFederatedUsersMeta(campaign, transformer));
}

if(transformer.get("type") != null && transformer.get("type").asText().equals("generic")) {
metaData.put("url", transformer.findValue("url").asText());
}

if(transformer.findValue("hiddenFields") != null && !transformer.findValue("hiddenFields").isEmpty()) {
metaData.put("hiddenFields", campaign.findValue("hiddenFields").toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.uci.dao.service.HealthService;

import com.uci.utils.model.ApiResponse;
import com.uci.utils.model.ApiResponseParams;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -26,18 +29,15 @@ public class HealthController {
private HealthService healthService;

@RequestMapping(value = "/health", method = RequestMethod.GET, produces = { "application/json", "text/json" })
public ResponseEntity<JsonNode> statusCheck() throws JsonProcessingException, IOException {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree("{\"id\":\"api.content.health\",\"ver\":\"3.0\",\"ts\":\"2021-06-26T22:47:05Z+05:30\",\"params\":{\"resmsgid\":\"859fee0c-94d6-4a0d-b786-2025d763b78a\",\"msgid\":null,\"err\":null,\"status\":\"successful\",\"errmsg\":null},\"responseCode\":\"OK\",\"result\":{\"checks\":[{\"name\":\"redis cache\",\"healthy\":true},{\"name\":\"graph db\",\"healthy\":true},{\"name\":\"cassandra db\",\"healthy\":true}],\"healthy\":true}}");

((ObjectNode) jsonNode).put("result", healthService.getAllHealthNode());

/* Current Date Time */
LocalDateTime localNow = LocalDateTime.now();
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
String dateString = fmt.format(localNow).toString();
((ObjectNode) jsonNode).put("ts", dateString);

return ResponseEntity.ok(jsonNode);
public ResponseEntity<ApiResponse> statusCheck() throws JsonProcessingException, IOException {
log.error("Health API called");
ApiResponse response = ApiResponse.builder()
.id("api.health")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(healthService.getAllHealthNode())
.build();

return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.uci.dao.service.HealthService;
import com.uci.utils.model.ApiResponse;
import com.uci.utils.model.ApiResponseParams;
import com.uci.utils.telemetry.LogTelemetryBuilder;
import com.uci.utils.telemetry.TelemetryLogger;

Expand All @@ -16,6 +18,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -29,65 +32,39 @@ public class ServiceStatusController {
@Autowired
private HealthService healthService;

@RequestMapping(value = "/health", method = RequestMethod.GET, produces = { "application/json", "text/json" })
public ResponseEntity<JsonNode> statusCheck() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree("{\"id\":\"api.content.service.health\",\"ver\":\"3.0\",\"ts\":null,\"params\":{\"resmsgid\":null,\"msgid\":null,\"err\":null,\"status\":\"successful\",\"errmsg\":null},\"responseCode\":\"OK\",\"result\":{\"healthy\":true}}");
return ResponseEntity.ok(json);
}

@RequestMapping(value = "/health/cassandra", method = RequestMethod.GET, produces = { "application/json", "text/json" })
public ResponseEntity<JsonNode> cassandraStatusCheck() throws IOException, JsonProcessingException {
JsonNode jsonNode = getResponseJsonNode();
((ObjectNode) jsonNode).put("result", healthService.getCassandraHealthNode());

return ResponseEntity.ok(jsonNode);
public ResponseEntity<ApiResponse> cassandraStatusCheck() throws IOException, JsonProcessingException {
ApiResponse response = ApiResponse.builder()
.id("api.service.health.cassandra")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(healthService.getCassandraHealthNode())
.build();

return ResponseEntity.ok(response);
}

@RequestMapping(value = "/health/kafka", method = RequestMethod.GET, produces = { "application/json", "text/json" })
public ResponseEntity<JsonNode> kafkaStatusCheck() throws IOException, JsonProcessingException {
JsonNode jsonNode = getResponseJsonNode();
// ((ObjectNode) jsonNode).put("result", healthService.getKafkaHealthNode());

return ResponseEntity.ok(jsonNode);
public ResponseEntity<ApiResponse> kafkaStatusCheck() throws IOException, JsonProcessingException {
ApiResponse response = ApiResponse.builder()
.id("api.service.health.kafka")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(healthService.getKafkaHealthNode())
.build();

return ResponseEntity.ok(response);
}

@RequestMapping(value = "/health/campaign", method = RequestMethod.GET, produces = { "application/json", "text/json" })
public ResponseEntity<JsonNode> campaignUrlStatusCheck() throws JsonProcessingException, IOException {
JsonNode jsonNode = getResponseJsonNode();
((ObjectNode) jsonNode).put("result", healthService.getCampaignUrlHealthNode());

return ResponseEntity.ok(jsonNode);
}

// private static final Logger logger = LogManager.getLogger();
//
// /*
// * Test with default kafka appender
// * telemetry object build internally via custom layout mentioned in xml by sent message
// */
// @RequestMapping(value = "/test/logs", method = RequestMethod.GET, produces = { "application/json", "text/json" })
// public ResponseEntity<JsonNode> testKafkaLogAppender() throws JsonProcessingException, IOException {
// ObjectMapper mapper = new ObjectMapper();
// JsonNode jsonNode = mapper.readTree("{\"responseCode\":\"OK\"}");
//
// logger.info("Info Test Message");
//
// logger.error("Error Test Message");
//
// return ResponseEntity.ok(jsonNode);
// }

/**
* Returns json node for service response
*
* @return JsonNode
* @throws JsonMappingException
* @throws JsonProcessingException
*/
private JsonNode getResponseJsonNode() throws JsonMappingException, JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree("{\"id\":\"api.content.service.health\",\"ver\":\"3.0\",\"ts\":null,\"params\":{\"resmsgid\":null,\"msgid\":null,\"err\":null,\"status\":\"successful\",\"errmsg\":null},\"responseCode\":\"OK\",\"result\":{\"healthy\":false}}");
return jsonNode;
public ResponseEntity<ApiResponse> campaignUrlStatusCheck() throws JsonProcessingException, IOException {
ApiResponse response = ApiResponse.builder()
.id("api.service.health.campaign")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(healthService.getCampaignUrlHealthNode())
.build();

return ResponseEntity.ok(response);
}
}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ inbound-error=${KAFKA_INBOUND_ERROR_TOPIC}
odk-transformer=${KAFKA_ODK_TRANSFORMER_TOPIC}
kafka.logs.topic = logs
broadcast-transformer=${KAFKA_BROADCAST_TRANSFORMER_TOPIC:#{"broadcast-transformer"}}
generic-transformer=${KAFKA_GENERIC_TRANSFORMER_TOPIC:#{"generic-transformer"}}
processOutbound=${KAFKA_PROCESS_OUTBOUND}
outbound=${KAFKA_OUTBOUND_TOPIC}

Expand Down

0 comments on commit 8fa65e9

Please sign in to comment.