-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from hyun357123/main
update software catalog
- Loading branch information
Showing
86 changed files
with
1,415 additions
and
1,724 deletions.
There are no files selected for viewing
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
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
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
118 changes: 118 additions & 0 deletions
118
src/main/java/kr/co/mcmp/ape/cbtumblebug/api/CbtumblebugRestApi.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,118 @@ | ||
package kr.co.mcmp.ape.cbtumblebug.api; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Base64; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Component; | ||
|
||
import kr.co.mcmp.ape.cbtumblebug.dto.MciDto; | ||
import kr.co.mcmp.ape.cbtumblebug.dto.MciResponse; | ||
import kr.co.mcmp.ape.cbtumblebug.dto.NamespaceDto; | ||
import kr.co.mcmp.ape.cbtumblebug.dto.NamespaceResponse; | ||
import kr.co.mcmp.ape.cbtumblebug.exception.CbtumblebugException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class CbtumblebugRestApi { | ||
|
||
@Value("${cbtumblebug.url}") | ||
private String cbtumblebugUrl; | ||
|
||
@Value("${cbtumblebug.port}") | ||
private String cbtumblebugPort; | ||
|
||
@Value("${cbtumblebug.id}") | ||
private String cbtumblebugId; | ||
|
||
@Value("${cbtumblebug.pass}") | ||
private String cbtumblebugPass; | ||
|
||
private final CbtumblebugRestClient restClient; | ||
|
||
private HttpHeaders createCommonHeaders() { | ||
HttpHeaders headers = new HttpHeaders(); | ||
String auth = cbtumblebugId + ":" + cbtumblebugPass; | ||
byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(StandardCharsets.UTF_8)); | ||
String authHeader = "Basic " + new String(encodedAuth); | ||
headers.set("Authorization", authHeader); | ||
// headers.set("Content-Type", "application/json"); | ||
return headers; | ||
} | ||
|
||
private String createApiUrl(String endpoint) { | ||
return String.format("http://%s:%s%s", cbtumblebugUrl, cbtumblebugPort, endpoint); | ||
} | ||
|
||
public boolean checkTumblebug(){ | ||
log.info("check Tumblebug is ready"); | ||
String apiUrl = createApiUrl("/readyz"); | ||
HttpHeaders headers = createCommonHeaders(); | ||
try { | ||
ResponseEntity<String> response = restClient.request(apiUrl, headers, null, HttpMethod.GET, new ParameterizedTypeReference<String>() {}); | ||
return response.getStatusCode().is2xxSuccessful(); | ||
} catch (Exception e) { | ||
log.error("Tumblebug connection fail", e); | ||
return false; | ||
} | ||
} | ||
|
||
private <T> T executeWithConnectionCheck(String operationName, Supplier<T> apiCall) { | ||
if (!checkTumblebug()) { | ||
log.error("Tumblebug에 연결할 수 없습니다. {} 작업을 수행할 수 없습니다.", operationName); | ||
throw new CbtumblebugException("Tumblebug 연결 실패"); | ||
} | ||
return apiCall.get(); | ||
} | ||
|
||
public List<NamespaceDto> getAllNamespace() { | ||
log.info("Fetching all namespaces"); | ||
return executeWithConnectionCheck("Fetching all namespaces", () ->{ | ||
String apiUrl = createApiUrl("/tumblebug/ns"); | ||
HttpHeaders headers = createCommonHeaders(); | ||
ResponseEntity<NamespaceResponse> response = restClient.request(apiUrl, headers, null, HttpMethod.GET, new ParameterizedTypeReference<NamespaceResponse>() {}); | ||
return response.getBody() != null ? response.getBody().getNs() : Collections.emptyList(); | ||
}); | ||
} | ||
|
||
public List<MciDto> getMcisByNamespace(String namespace) { | ||
log.info("Fetching MCIs by namespace: {}", namespace); | ||
return executeWithConnectionCheck("Fetching MCIs by namespace", () ->{ | ||
String apiUrl = createApiUrl(String.format("/tumblebug/ns/%s/mci", namespace)); | ||
HttpHeaders headers = createCommonHeaders(); | ||
ResponseEntity<MciResponse> response = restClient.request(apiUrl, headers, null, HttpMethod.GET, new ParameterizedTypeReference<MciResponse>() {}); | ||
return response.getBody() != null ? response.getBody().getMci() : Collections.emptyList(); | ||
}); | ||
} | ||
|
||
public String getK8sClusterInfo(){ | ||
log.info("Fetching all K8sClusterInfo"); | ||
return executeWithConnectionCheck("Fetching all K8sClusterInfo", () ->{ | ||
String apiUrl = createApiUrl("/k8sClusterInfo"); | ||
HttpHeaders headers = createCommonHeaders(); | ||
ResponseEntity<String> response = restClient.request(apiUrl, headers, headers, HttpMethod.GET, new ParameterizedTypeReference<String>() {}); | ||
return response.getBody() != null ? response.getBody() : null; | ||
}); | ||
} | ||
|
||
public String getK8sClusterByNamespace(String namespace){ | ||
log.info("Fetching k8sCluster Info by namespace :{}", namespace); | ||
return executeWithConnectionCheck("Fetching k8sCluster Info by namespace", () ->{ | ||
String apiUrl = createApiUrl(String.format("/ns/%s/k8scluster", namespace)); | ||
HttpHeaders headers = createCommonHeaders(); | ||
ResponseEntity<String> response = restClient.request(apiUrl, headers, null, HttpMethod.GET, new ParameterizedTypeReference<String>() {}); | ||
return response.getBody() != null ? response.getBody() : null; | ||
}); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/kr/co/mcmp/ape/cbtumblebug/api/CbtumblebugRestClient.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,47 @@ | ||
package kr.co.mcmp.ape.cbtumblebug.api; | ||
|
||
|
||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.HttpStatusCodeException; | ||
import org.springframework.web.client.RestClientException; | ||
import org.springframework.web.client.RestClientResponseException; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.util.UriComponents; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
import kr.co.mcmp.ape.cbtumblebug.exception.CbtumblebugException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class CbtumblebugRestClient { | ||
|
||
private final RestTemplate restTemplate; | ||
|
||
public <T> ResponseEntity<T> request(String apiUrl, HttpHeaders headers, Object body, HttpMethod httpMethod, ParameterizedTypeReference<T> responseType) { | ||
try { | ||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(apiUrl); | ||
HttpEntity<?> entity = new HttpEntity<>(body, headers); | ||
|
||
return restTemplate.exchange(builder.toUriString(), httpMethod, entity, responseType); | ||
} catch (HttpStatusCodeException e) { | ||
log.error("HTTP error: {} {}", e.getRawStatusCode(), e.getStatusText()); | ||
log.error("Response body: {}", e.getResponseBodyAsString()); | ||
throw new CbtumblebugException(e.getRawStatusCode(), e.getResponseBodyAsString()); | ||
} catch (RestClientException e) { | ||
log.error("RestClientException: ", e); | ||
throw new CbtumblebugException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Internal server error occurred"); | ||
} catch (Exception e) { | ||
log.error("Unexpected error: ", e); | ||
throw new CbtumblebugException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Unexpected error occurred"); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/kr/co/mcmp/ape/cbtumblebug/controller/CbtumblebugController.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,53 @@ | ||
package kr.co.mcmp.ape.cbtumblebug.controller; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import kr.co.mcmp.ape.cbtumblebug.dto.MciDto; | ||
import kr.co.mcmp.ape.cbtumblebug.dto.NamespaceDto; | ||
import kr.co.mcmp.ape.cbtumblebug.service.CbtumblebugService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
|
||
@Tag(name="tumblebug", description = "tumblebug API 조회") | ||
@RestController | ||
@RequestMapping("/cbtumblebug") | ||
@RequiredArgsConstructor | ||
public class CbtumblebugController { | ||
|
||
private final CbtumblebugService cbtumblebugService; | ||
|
||
@GetMapping("/ns") | ||
@Operation(summary = "모든 네임스페이스 조회", description = "시스템에 등록된 모든 네임스페이스를 조회합니다.") | ||
public List<NamespaceDto> getAllNamespaces() { | ||
return cbtumblebugService.getAllNamespaces(); | ||
} | ||
|
||
@GetMapping("/ns/{nsId}/mcis") | ||
@Operation(summary = "특정 네임스페이스의 MCIS 조회", description = "지정된 네임스페이스에 속한 모든 MCIS를 조회합니다.") | ||
public List<MciDto> getMCISByNamespace(@Parameter(description = "네임스페이스 ID", required = true) | ||
@PathVariable String nsId) { | ||
return cbtumblebugService.getMcisByNamespace(nsId); | ||
} | ||
|
||
@GetMapping("/k8sCluster/info") | ||
@Operation(summary = "k8sCluster 정보 조회", description = "등록된 모든 K8s Cluster의 정보를 조회합니다.") | ||
public String getAllK8sClusterInfo() { | ||
return cbtumblebugService.getK8sClusterInfo(); | ||
} | ||
|
||
@GetMapping("/ns/{nsId}/k8scluster") | ||
public String getK8sCluster(@PathVariable String nsId) { | ||
return cbtumblebugService.getK8sClusterByNamespace(nsId); | ||
} | ||
|
||
|
||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/kr/co/mcmp/ape/cbtumblebug/dto/ConnectionConfig.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,46 @@ | ||
package kr.co.mcmp.ape.cbtumblebug.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
import io.swagger.annotations.ApiModel; | ||
import io.swagger.annotations.ApiModelProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@ApiModel(description = "Connection configuration") | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class ConnectionConfig { | ||
@ApiModelProperty(value = "Config name") | ||
private String configName; | ||
|
||
@ApiModelProperty(value = "Provider name") | ||
private String providerName; | ||
|
||
@ApiModelProperty(value = "Driver name") | ||
private String driverName; | ||
|
||
@ApiModelProperty(value = "Credential name") | ||
private String credentialName; | ||
|
||
@ApiModelProperty(value = "Credential holder") | ||
private String credentialHolder; | ||
|
||
@ApiModelProperty(value = "Region zone info name") | ||
private String regionZoneInfoName; | ||
|
||
@ApiModelProperty(value = "Region zone info") | ||
private RegionZoneInfo regionZoneInfo; | ||
|
||
@ApiModelProperty(value = "Region detail") | ||
private RegionDetail regionDetail; | ||
|
||
@ApiModelProperty(value = "Is region representative") | ||
private boolean regionRepresentative; | ||
|
||
@ApiModelProperty(value = "Is verified") | ||
private boolean verified; | ||
} |
Oops, something went wrong.