-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added Health Endpoint returning sync status. (#16)
* feat: added Health Endpoint returning sync status. * feat: added sync status dto. Sync status will be true if the syncjob won't start and will signalize it with a different status message. * feat: added sync status dto. Sync status will be true if the syncjob won't start and will signalize it with a different status message.
- Loading branch information
Showing
8 changed files
with
178 additions
and
6 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
api/src/main/java/org/cardanofoundation/tokenmetadata/registry/api/controller/HealthApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.cardanofoundation.tokenmetadata.registry.api.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.cardanofoundation.tokenmetadata.registry.api.model.rest.HealthResponse; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
@Validated | ||
@Tag(name = "health", description = "Health Endpoint for the cardano token metadata registry") | ||
public interface HealthApi { | ||
|
||
@Operation(operationId = "getHealthStatus", summary = "Returns health status of service including if the initial sync is done", responses = { | ||
@ApiResponse(responseCode = "200", content = @Content(mediaType = "application/json", schema = @Schema(implementation = HealthResponse.class))) | ||
}) | ||
@RequestMapping(method = RequestMethod.GET, value = "/health", produces = {"application/json;charset=utf-8"}) | ||
ResponseEntity<HealthResponse> getHealthStatus(); | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...java/org/cardanofoundation/tokenmetadata/registry/api/controller/HealthApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.cardanofoundation.tokenmetadata.registry.api.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.cardanofoundation.tokenmetadata.registry.api.model.rest.HealthResponse; | ||
import org.cardanofoundation.tokenmetadata.registry.service.SyncStatus; | ||
import org.cardanofoundation.tokenmetadata.registry.service.TokenMetadataSyncService; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@Controller | ||
@CrossOrigin | ||
@RequestMapping("${openapi.metadataServer.base-path:}") | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class HealthApiController implements HealthApi { | ||
|
||
private final TokenMetadataSyncService tokenMetadataSyncService; | ||
|
||
@Override | ||
public ResponseEntity<HealthResponse> getHealthStatus() { | ||
SyncStatus syncStatus = tokenMetadataSyncService.getSyncStatus(); | ||
return new ResponseEntity<>(HealthResponse.builder() | ||
.synced(syncStatus.isInitialSyncDone()) | ||
.syncStatus(syncStatus.getSyncStatus().toString()) | ||
.build(), HttpStatus.OK); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...main/java/org/cardanofoundation/tokenmetadata/registry/api/model/rest/HealthResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.cardanofoundation.tokenmetadata.registry.api.model.rest; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import jakarta.validation.Valid; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.cardanofoundation.tokenmetadata.registry.model.enums.SyncStatusEnum; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class HealthResponse { | ||
|
||
@JsonProperty("synced") | ||
@Valid | ||
private boolean synced; | ||
|
||
@JsonProperty("syncStatus") | ||
@Valid | ||
private String syncStatus; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...rc/main/java/org/cardanofoundation/tokenmetadata/registry/model/enums/SyncStatusEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.cardanofoundation.tokenmetadata.registry.model.enums; | ||
|
||
import org.cardanofoundation.tokenmetadata.registry.util.Constants; | ||
|
||
public enum SyncStatusEnum { | ||
|
||
SYNC_NOT_STARTED(Constants.SYNC_NOT_STARTED), | ||
SYNC_IN_PROGRESS(Constants.SYNC_IN_PROGRESS), | ||
SYNC_DONE(Constants.SYNC_DONE), | ||
SYNC_ERROR(Constants.SYNC_ERROR), | ||
SYNC_IN_EXTRA_JOB(Constants.SYNC_IN_EXTRA_JOB); | ||
|
||
private final String text; | ||
|
||
SyncStatusEnum(final String text) { | ||
this.text = text; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return text; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
common/src/main/java/org/cardanofoundation/tokenmetadata/registry/service/SyncStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.cardanofoundation.tokenmetadata.registry.service; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
import org.cardanofoundation.tokenmetadata.registry.model.enums.SyncStatusEnum; | ||
|
||
@Builder | ||
@Data | ||
public class SyncStatus { | ||
|
||
private boolean isInitialSyncDone; | ||
private SyncStatusEnum syncStatus; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
common/src/main/java/org/cardanofoundation/tokenmetadata/registry/util/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.cardanofoundation.tokenmetadata.registry.util; | ||
|
||
public class Constants { | ||
|
||
private Constants() {} | ||
|
||
public static String SYNC_NOT_STARTED = "Sync not started"; | ||
public static String SYNC_IN_PROGRESS = "Sync in progress"; | ||
public static String SYNC_DONE = "Sync done"; | ||
public static String SYNC_ERROR = "Error while syncing"; | ||
public static String SYNC_IN_EXTRA_JOB = "Sync will be done in a different job. Status unkown"; | ||
|
||
} |