Skip to content

Commit

Permalink
Feat/#514 무중단 배포를 위한 Actuator 추가, Profile API 생성 (#521)
Browse files Browse the repository at this point in the history
* feat: ProfileCheckController 구현

* config: Spring Actuator 의존성 추가

* config: submodule 변경 저장

---------

Co-authored-by: Eunsol Kim <[email protected]>
  • Loading branch information
splitCoding and Cyma-s authored Oct 19, 2023
1 parent a23c073 commit 280182e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ dependencies {
//xlsx reader
implementation group: 'org.apache.poi', name: 'poi', version: '5.0.0'
implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '5.0.0'

//actuator
implementation 'org.springframework.boot:spring-boot-starter-actuator'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package shook.shook.status;

import lombok.RequiredArgsConstructor;
import org.springframework.core.env.Environment;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import shook.shook.status.response.ProfileResponse;

@RestController
@RequestMapping("/status/profile")
@RequiredArgsConstructor
public class ProfileCheckController {

private final Environment environment;

@GetMapping
public ResponseEntity<ProfileResponse> getProfile() {
return ResponseEntity.ok(new ProfileResponse(environment.getActiveProfiles()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package shook.shook.status.response;

import java.util.Arrays;

public class ProfileResponse {

private final String profile;

public ProfileResponse(final String[] profiles) {
this.profile = findReservedProfile(profiles);
}

private String findReservedProfile(final String[] profiles) {
return Arrays.stream(profiles)
.filter(ReservedProfiles::isExist)
.findFirst()
.orElse(profiles[0]);
}

public String getProfiles() {
return profile;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package shook.shook.status.response;

import java.util.Arrays;
import java.util.Optional;

public enum ReservedProfiles {
PROD1,
PROD2,
DEV,
LOCAL,
TEST;

public static boolean isExist(final String target) {
final Optional<String> findProfile = Arrays.stream(values())
.map(ReservedProfiles::name)
.filter(valueName -> valueName.equals(target.toUpperCase()))
.findAny();
return findProfile.isPresent();
}
}

0 comments on commit 280182e

Please sign in to comment.