Skip to content

Commit

Permalink
Merge pull request #61 from hyun357123/main
Browse files Browse the repository at this point in the history
update software catalog
  • Loading branch information
Strato-YangSungHun authored Sep 30, 2024
2 parents 3182e41 + 32837b6 commit 4ab5fdc
Show file tree
Hide file tree
Showing 86 changed files with 1,415 additions and 1,724 deletions.
7 changes: 7 additions & 0 deletions bin/main/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,10 @@ object:

aes:
key: fb1755281b0ca6184a0ee644e6477ee7

cbtumblebug:
#url: 192.168.189.128
url: 13.125.199.35
port: 1323
id: default
pass: default
43 changes: 35 additions & 8 deletions bin/main/import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,26 @@ VALUES
('GRAFANA', 'Your observability stack, faster and easier\n\nWith Grafana Cloud, enable observability - from operational dashboards to a fully centralized system and everything in between - without the overhead of building and maintaining your own stack.', 'observability', '/images/grafana.jpg', 'OBSERVABILITY');



INSERT INTO SOFTWARE_CATALOG_REF(CATALOG_ID, REF_IDX, REF_VALUE, REF_DESC, REF_TYPE)
VALUES
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE TOMCAT'), 0, 'https://tomcat.apache.org/', '', 'HOMEPAGE'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE TOMCAT'), 0, 'apache', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE TOMCAT'), 0, 'oss', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE TOMCAT'), 0, 'server', '', 'TAG');
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE TOMCAT'), 0, 'server', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE TOMCAT'), 0, 'vm_application_install', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE TOMCAT'), 0, 'vm_application_uninstall', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE TOMCAT'), 0, 'helm_application_install', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE TOMCAT'), 0, 'helm_application_uninstall', '', 'workflow');
INSERT INTO SOFTWARE_CATALOG_REF(CATALOG_ID, REF_IDX, REF_VALUE, REF_DESC, REF_TYPE)
VALUES
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'REDIS'), 0, 'https://redis.io/', '', 'HOMEPAGE'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'REDIS'), 0, 'NoSQL', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'REDIS'), 0, 'oss', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'REDIS'), 0, 'inMemoryDB', '', 'TAG');
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'REDIS'), 0, 'inMemoryDB', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'REDIS'), 0, 'vm_application_install', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'REDIS'), 0, 'vm_application_uninstall', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'REDIS'), 0, 'helm_application_install', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'REDIS'), 0, 'helm_application_uninstall', '', 'workflow');
INSERT INTO SOFTWARE_CATALOG_REF(CATALOG_ID, REF_IDX, REF_VALUE, REF_DESC, REF_TYPE)
VALUES
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NGINX'), 0, 'https://nginx.org/en/', '', 'HOMEPAGE'),
Expand All @@ -42,33 +49,53 @@ VALUES
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NGINX'), 0, 'proxy', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NGINX'), 0, 'web', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NGINX'), 0, 'frontend', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NGINX'), 0, 'server', '', 'TAG');
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NGINX'), 0, 'server', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NGINX'), 0, 'vm_application_install', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NGINX'), 0, 'vm_application_uninstall', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NGINX'), 0, 'helm_application_install', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NGINX'), 0, 'helm_application_uninstall', '', 'workflow');
INSERT INTO SOFTWARE_CATALOG_REF(CATALOG_ID, REF_IDX, REF_VALUE, REF_DESC, REF_TYPE)
VALUES
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE'), 0, 'https://httpd.apache.org/', '', 'HOMEPAGE'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE'), 0, 'web', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE'), 0, 'oss', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE'), 0, 'frontend', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE'), 0, 'webserver', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE'), 0, 'httpd', '', 'TAG');
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE'), 0, 'httpd', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE'), 0, 'vm_application_install', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE'), 0, 'vm_application_uninstall', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE'), 0, 'helm_application_install', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'APACHE'), 0, 'helm_application_uninstall', '', 'workflow');
INSERT INTO SOFTWARE_CATALOG_REF(CATALOG_ID, REF_IDX, REF_VALUE, REF_DESC, REF_TYPE)
VALUES
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NEXUS'), 0, 'https://www.sonatype.com/products/sonatype-nexus-repository', '', 'HOMEPAGE'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NEXUS'), 0, 'repository', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NEXUS'), 0, 'oss', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NEXUS'), 0, 'license', '', 'TAG');
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NEXUS'), 0, 'license', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NEXUS'), 0, 'vm_application_install', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NEXUS'), 0, 'vm_application_uninstall', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NEXUS'), 0, 'helm_application_install', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'NEXUS'), 0, 'helm_application_uninstall', '', 'workflow');
INSERT INTO SOFTWARE_CATALOG_REF(CATALOG_ID, REF_IDX, REF_VALUE, REF_DESC, REF_TYPE)
VALUES
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'MARIA DB'), 0, 'https://mariadb.org/', '', 'HOMEPAGE'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'MARIA DB'), 0, 'RDBMS', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'MARIA DB'), 0, 'oss', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'MARIA DB'), 0, 'database', '', 'TAG');
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'MARIA DB'), 0, 'database', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'MARIA DB'), 0, 'vm_application_install', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'MARIA DB'), 0, 'vm_application_uninstall', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'MARIA DB'), 0, 'helm_application_install', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'MARIA DB'), 0, 'helm_application_uninstall', '', 'workflow');
INSERT INTO SOFTWARE_CATALOG_REF(CATALOG_ID, REF_IDX, REF_VALUE, REF_DESC, REF_TYPE)
VALUES
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'GRAFANA'), 0, 'https://grafana.com/', '', 'HOMEPAGE'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'GRAFANA'), 0, 'view', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'GRAFANA'), 0, 'observer', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'GRAFANA'), 0, 'oss', '', 'TAG');
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'GRAFANA'), 0, 'oss', '', 'TAG'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'GRAFANA'), 0, 'vm_application_install', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'GRAFANA'), 0, 'vm_application_uninstall', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'GRAFANA'), 0, 'helm_application_install', '', 'workflow'),
((SELECT ID FROM SOFTWARE_CATALOG WHERE TITLE = 'GRAFANA'), 0, 'helm_application_uninstall', '', 'workflow');



Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ dependencies {

implementation 'org.springdoc:springdoc-openapi-ui:1.6.8'

implementation 'org.bouncycastle:bcpkix-jdk15on:1.68'

testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")

Expand Down
118 changes: 118 additions & 0 deletions src/main/java/kr/co/mcmp/ape/cbtumblebug/api/CbtumblebugRestApi.java
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;
});
}

}
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");
}
}
}
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 src/main/java/kr/co/mcmp/ape/cbtumblebug/dto/ConnectionConfig.java
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;
}
Loading

0 comments on commit 4ab5fdc

Please sign in to comment.