├── README.md ├── src ├── main │ ├── java │ │ └── org │ │ │ └── paasta │ │ │ └── caas │ │ │ └── api │ │ │ ├── adminToken │ │ │ ├── AdminToken.java │ │ │ └── AdminTokenController.java │ │ │ ├── nodes │ │ │ ├── support │ │ │ │ ├── NodesAddress.java │ │ │ │ ├── NodesStatus.java │ │ │ │ └── NodesSystemInfo.java │ │ │ ├── NodesList.java │ │ │ ├── Nodes.java │ │ │ ├── NodesController.java │ │ │ └── NodesService.java │ │ │ ├── common │ │ │ ├── model │ │ │ │ ├── CommonAddresses.java │ │ │ │ ├── CommonPodSpec.java │ │ │ │ ├── CommonNotReadyAddresses.java │ │ │ │ ├── CommonPort.java │ │ │ │ ├── CommonOwnerReferences.java │ │ │ │ ├── CommonLabelSelector.java │ │ │ │ ├── CommonPodTemplateSpec.java │ │ │ │ ├── CommonRoleRule.java │ │ │ │ ├── CommonTypedLocalObjectReference.java │ │ │ │ ├── CommonSubset.java │ │ │ │ ├── CommonResourceRequirement.java │ │ │ │ ├── CommonObjectReference.java │ │ │ │ ├── CommonContainer.java │ │ │ │ ├── CommonStatus.java │ │ │ │ ├── CommonCondition.java │ │ │ │ ├── CommonMetaData.java │ │ │ │ └── CommonSpec.java │ │ │ ├── Constants.java │ │ │ ├── CommonUtils.java │ │ │ ├── CommonService.java │ │ │ ├── AspectService.java │ │ │ ├── PropertyService.java │ │ │ └── RestTemplateService.java │ │ │ ├── workloads │ │ │ ├── pods │ │ │ │ ├── support │ │ │ │ │ ├── Volume.java │ │ │ │ │ └── SecretVolumeSource.java │ │ │ │ ├── PodsList.java │ │ │ │ ├── Pods.java │ │ │ │ ├── PodsController.java │ │ │ │ └── PodsService.java │ │ │ ├── deployments │ │ │ │ ├── support │ │ │ │ │ ├── DeploymentsStrategy.java │ │ │ │ │ ├── RollingUpdateDeployments.java │ │ │ │ │ ├── DeploymentsStatus.java │ │ │ │ │ └── DeploymentsSpec.java │ │ │ │ ├── DeploymentsList.java │ │ │ │ ├── Deployments.java │ │ │ │ ├── DeploymentsController.java │ │ │ │ └── DeploymentsService.java │ │ │ └── replicaSets │ │ │ │ ├── ReplicaSetsList.java │ │ │ │ ├── ReplicaSets.java │ │ │ │ ├── ReplicaSetsController.java │ │ │ │ └── ReplicaSetsService.java │ │ │ ├── roles │ │ │ ├── RolesList.java │ │ │ ├── Roles.java │ │ │ ├── RolesController.java │ │ │ └── RolesService.java │ │ │ ├── events │ │ │ ├── EventsList.java │ │ │ ├── Events.java │ │ │ ├── EventsController.java │ │ │ └── EventsService.java │ │ │ ├── accessInfo │ │ │ ├── AccessToken.java │ │ │ ├── AccessTokenController.java │ │ │ └── AccessTokenService.java │ │ │ ├── endpoints │ │ │ ├── EndpointsList.java │ │ │ ├── Endpoints.java │ │ │ ├── EndpointsController.java │ │ │ └── EndpointsService.java │ │ │ ├── PaasTaCaasApiApplication.java │ │ │ ├── roleBindings │ │ │ ├── RoleBindingsList.java │ │ │ ├── RoleBindings.java │ │ │ ├── RoleBindingsController.java │ │ │ └── RoleBindingsService.java │ │ │ ├── customServices │ │ │ ├── CustomServicesList.java │ │ │ ├── CustomServices.java │ │ │ ├── CustomServicesController.java │ │ │ └── CustomServicesService.java │ │ │ ├── clusters │ │ │ └── namespaces │ │ │ │ ├── ResourceQuotaList.java │ │ │ │ ├── ResourceQuotaStatus.java │ │ │ │ ├── ResourceQuotaSpec.java │ │ │ │ ├── ResourceQuota.java │ │ │ │ ├── Namespaces.java │ │ │ │ ├── NamespacesController.java │ │ │ │ └── NamespacesService.java │ │ │ ├── users │ │ │ ├── Users.java │ │ │ ├── UsersController.java │ │ │ └── UsersService.java │ │ │ ├── persistentVolumeClaims │ │ │ ├── PersistentVolumeClaimsList.java │ │ │ ├── support │ │ │ │ ├── PersistentVolumeClaimsStatus.java │ │ │ │ └── PersistentVolumeClaimsSpec.java │ │ │ ├── PersistentVolumeClaims.java │ │ │ ├── PersistentVolumeClaimsController.java │ │ │ └── PersistentVolumeClaimsService.java │ │ │ ├── config │ │ │ ├── GsonConfig.java │ │ │ ├── RestTemplateConfig.java │ │ │ └── SecurityConfig.java │ │ │ ├── exception │ │ │ └── GlobalControllerExceptionHandler.java │ │ │ └── authenticate │ │ │ ├── AuthenticateController.java │ │ │ └── AuthenticateService.java │ └── resources │ │ ├── application.yml │ │ └── logback-spring.xml └── test │ ├── java │ └── org │ │ └── paasta │ │ └── caas │ │ └── api │ │ ├── PaasTaCaasApiApplicationTest.java │ │ ├── users │ │ └── UsersServiceTest.java │ │ ├── authenticate │ │ └── AuthenticateServiceTest.java │ │ ├── accessInfo │ │ └── AccessTokenServiceTest.java │ │ ├── roles │ │ └── RolesServiceTest.java │ │ ├── clusters │ │ └── namespaces │ │ │ └── NamespacesServiceTest.java │ │ ├── nodes │ │ └── NodesServiceTest.java │ │ ├── endpoints │ │ └── EndpointsServiceTest.java │ │ ├── persistentVolumeClaims │ │ └── PersistentVolumeClaimsServiceTest.java │ │ ├── customServices │ │ └── CustomServiceServicesTest.java │ │ ├── events │ │ └── EventsServiceTest.java │ │ └── workloads │ │ └── Deployments │ │ └── DeploymentsServiceTest.java │ └── resources │ └── application.yml └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | # PAAS-TA-CAAS-API 2 | PaaS-TA 에서 제공하는 Container 서비스를 제어하기 위한 REST API 를 제공하는 서비스이다. 3 | 4 | ## 개발 환경 5 | - JDK 8 6 | - Gradle 4.4.1 7 | - Spring Io Platform Cairo-SR3 8 | - Spring Boot 2.0.4 9 | - Apache Http Client 4.5.6 10 | - Lombok 1.18.2 11 | - Gson 2.8.5 12 | - Jacoco 0.8.1 -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/adminToken/AdminToken.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.adminToken; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class AdminToken { 7 | 8 | private String tokenName; 9 | private String tokenValue; 10 | private String resultCode; 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/nodes/support/NodesAddress.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.nodes.support; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * Nodes address 클래스 7 | * 8 | * @author Hyungu Cho 9 | * @version 1.0 10 | * @since 2018.09.17 11 | */ 12 | @Data 13 | class NodesAddress { 14 | private String address; 15 | private String type; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonAddresses.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * Common Addresses Model 클래스 7 | * 8 | * @author REX 9 | * @version 1.0 10 | * @since 2018.08.13 11 | */ 12 | @Data 13 | class CommonAddresses { 14 | private String ip; 15 | private String nodeName; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/pods/support/Volume.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.pods.support; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * Volume Model 클래스 7 | * 8 | * @author Hyungu Cho 9 | * @version 1.0 10 | * @since 2018.09.04 11 | */ 12 | @Data 13 | public class Volume { 14 | private String name; 15 | private SecretVolumeSource secret; 16 | } -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonPodSpec.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * CommonPodSpec Model 클래스 9 | * 10 | * @author CISS 11 | * @version 1.0 12 | * @since 2018.08.07 13 | */ 14 | @Data 15 | public class CommonPodSpec { 16 | private List containers; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonNotReadyAddresses.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * Common Not Ready Addresses Model 클래스 7 | * 8 | * @author REX 9 | * @version 1.0 10 | * @since 2018.09.14 11 | */ 12 | @Data 13 | class CommonNotReadyAddresses { 14 | private String ip; 15 | private String nodeName; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonPort.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * Common Ports Model 클래스 7 | * 8 | * @author REX 9 | * @version 1.0 10 | * @since 2018.08.13 11 | */ 12 | @Data 13 | public class CommonPort { 14 | private String name; 15 | private String port; 16 | private String protocol; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/roles/RolesList.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.roles; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Role List Model 클래스 9 | * 10 | * @author hrjin 11 | * @version 1.0 12 | * @since 2018-08-14 13 | */ 14 | @Data 15 | public class RolesList { 16 | 17 | private String resultCode; 18 | private List items; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonOwnerReferences.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * Common CommonOwnerReferences Model 클래스 7 | * 8 | * @author Hyungu Cho 9 | * @version 1.0 10 | * @since 2018.09.19 11 | */ 12 | @Data 13 | class CommonOwnerReferences { 14 | private String name; 15 | private boolean controller; 16 | } -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/events/EventsList.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.events; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Events List Model 클래스 9 | * 10 | * @author Ciss 11 | * @version 1.0 12 | * @since 2018.8.13 13 | */ 14 | @Data 15 | public class EventsList { 16 | 17 | private String resultCode; 18 | private List items; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/accessInfo/AccessToken.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.accessInfo; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * AccessToken Model 클래스 7 | * 8 | * @author hrjin 9 | * @version 1.0 10 | * @since 2018-09-04 11 | */ 12 | @Data 13 | public class AccessToken { 14 | private String resultCode; 15 | private String caCertToken; 16 | private String userAccessToken; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonLabelSelector.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * CommonLabelSelector Model 클래스 9 | * 10 | * @author CISS 11 | * @version 1.0 12 | * @since 2018.08.07 13 | */ 14 | @Data 15 | public class CommonLabelSelector { 16 | private Map matchLabels; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonPodTemplateSpec.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * CommonPodTemplateSpec Model 클래스 7 | * 8 | * @author CISS 9 | * @version 1.0 10 | * @since 2018.08.07 11 | */ 12 | @Data 13 | public class CommonPodTemplateSpec { 14 | private CommonMetaData metadata; 15 | private CommonPodSpec spec; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/endpoints/EndpointsList.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.endpoints; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Endpoints List Model 클래스 9 | * 10 | * @author REX 11 | * @version 1.0 12 | * @since 2018.8.13 13 | */ 14 | @Data 15 | public class EndpointsList { 16 | 17 | private String resultCode; 18 | private List items; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonRoleRule.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author hrjin 9 | * @version 1.0 10 | * @since 2018-08-17 11 | */ 12 | @Data 13 | public class CommonRoleRule { 14 | private List apiGroups; 15 | private List resources; 16 | private List verbs; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/PaasTaCaasApiApplication.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class PaasTaCaasApiApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(PaasTaCaasApiApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/roleBindings/RoleBindingsList.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.roleBindings; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * RoleBinding List Model 클래스 9 | * 10 | * @author hrjin 11 | * @version 1.0 12 | * @since 2018-08-17 13 | */ 14 | @Data 15 | public class RoleBindingsList { 16 | 17 | private String resultCode; 18 | private List items; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/pods/support/SecretVolumeSource.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.pods.support; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * Secret Volume Source Model 클래스 (Secret 클래스가 아님) 7 | * 8 | * @author Hyungu Cho 9 | * @version 1.0 10 | * @since 2018.09.04 11 | */ 12 | @Data 13 | class SecretVolumeSource { 14 | private String secretName; 15 | private String defaultMode; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/deployments/support/DeploymentsStrategy.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.deployments.support; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * DeploymentsStrategy Model 클래스 7 | * 8 | * @author PHR 9 | * @version 1.0 10 | * @since 2018.08.13 11 | */ 12 | @Data 13 | public class DeploymentsStrategy { 14 | private String type; 15 | private RollingUpdateDeployments rollingUpdate; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/deployments/support/RollingUpdateDeployments.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.deployments.support; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * RollingUpdateDeployments Model 클래스 7 | * 8 | * @author PHR 9 | * @version 1.0 10 | * @since 2018.08.13 11 | */ 12 | @Data 13 | public class RollingUpdateDeployments { 14 | private String maxSurge; 15 | private String maxUnavailable; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonTypedLocalObjectReference.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * TypedLocalObjectReference Model 클래스 7 | * 8 | * @author hrjin 9 | * @version 1.0 10 | * @since 2019-10-24 11 | */ 12 | @Data 13 | public class CommonTypedLocalObjectReference { 14 | private String apiGroup; 15 | private String kind; 16 | private String name; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/deployments/DeploymentsList.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.deployments; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Deployments List Model 클래스 9 | * 10 | * @author PHR 11 | * @version 1.0 12 | * @since 2018.08.13 13 | */ 14 | @Data 15 | public class DeploymentsList { 16 | private String resultCode; 17 | 18 | private List items; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/customServices/CustomServicesList.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.customServices; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Custom Services List Model 클래스 9 | * 10 | * @author REX 11 | * @version 1.0 12 | * @since 2018.08.09 13 | */ 14 | @Data 15 | public class CustomServicesList { 16 | 17 | private String resultCode; 18 | private List items; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/nodes/NodesList.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.nodes; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * Nodes List Model 클래스 10 | * 11 | * @author Hyungu Cho 12 | * @version 1.0 13 | * @since 2018.08.13 14 | */ 15 | @Data 16 | public class NodesList { 17 | private String resultCode; 18 | 19 | private List items = new ArrayList<>(); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/clusters/namespaces/ResourceQuotaList.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.clusters.namespaces; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * ResourceQuotaList Model 클래스 9 | * 10 | * @author indra 11 | * @version 1.0 12 | * @since 2018.08.28 13 | */ 14 | @Data 15 | public class ResourceQuotaList { 16 | 17 | private String resultCode; 18 | private List items; 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/pods/PodsList.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.pods; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * Pods List Model 클래스 10 | * 11 | * @author Hyungu Cho 12 | * @version 1.0 13 | * @since 2018.8.13 14 | */ 15 | @Data 16 | public class PodsList { 17 | private String resultCode; 18 | 19 | private List items = new ArrayList<>(); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/clusters/namespaces/ResourceQuotaStatus.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.clusters.namespaces; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * ResourceQuotaStatus Model 클래스 9 | * 10 | * @author indra 11 | * @version 1.0 12 | * @since 2018.08.28 13 | */ 14 | @Data 15 | public class ResourceQuotaStatus { 16 | 17 | private Map hard; 18 | private Map used; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/users/Users.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.users; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonMetaData; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * @author hrjin 11 | * @version 1.0 12 | * @since 2018-09-03 13 | */ 14 | @Data 15 | public class Users { 16 | private String resultCode; 17 | private CommonMetaData metadata; 18 | private List secrets; 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/org/paasta/caas/api/PaasTaCaasApiApplicationTest.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class PaasTaCaasApiApplicationTest { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/clusters/namespaces/ResourceQuotaSpec.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.clusters.namespaces; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | /** 9 | * ResourceQuotaSpec Model 클래스 10 | * 11 | * @author indra 12 | * @version 1.0 13 | * @since 2018.08.28 14 | */ 15 | @Data 16 | public class ResourceQuotaSpec { 17 | 18 | private Map hard; 19 | private List scopes; 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/persistentVolumeClaims/PersistentVolumeClaimsList.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.persistentVolumeClaims; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * PersistentVolumeClaims List Model 클래스 9 | * 10 | * @author hrjin 11 | * @version 1.0 12 | * @since 2019-10-24 13 | */ 14 | @Data 15 | public class PersistentVolumeClaimsList { 16 | private String resultCode; 17 | private List items; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonSubset.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Common Subsets Model 클래스 9 | * 10 | * @author REX 11 | * @version 1.0 12 | * @since 2018.08.13 13 | */ 14 | @Data 15 | public class CommonSubset { 16 | private List addresses; 17 | private List notReadyAddresses; 18 | private List ports; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonResourceRequirement.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * Common Resource Requirement Model 클래스 9 | * 10 | * @author Hyungu Cho 11 | * @version 1.0 12 | * @since 2018.08.16 13 | */ 14 | @Data 15 | public class CommonResourceRequirement { 16 | // TODO :: USE MODEL 17 | private Map limits; 18 | private Map requests; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/replicaSets/ReplicaSetsList.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.replicaSets; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonMetaData; 5 | import java.util.List; 6 | 7 | /** 8 | * ReplicaSets Model 클래스 9 | * 10 | * @author CISS 11 | * @version 1.0 12 | * @since 2018.08.07 13 | */ 14 | @Data 15 | public class ReplicaSetsList { 16 | 17 | private String resultCode; 18 | private List items; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonObjectReference.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * ObjectReference Model 클래스 7 | * 8 | * @author CISS 9 | * @version 1.0 10 | * @since 2018.08.23 11 | */ 12 | @Data 13 | public class CommonObjectReference { 14 | private String apiVersion; 15 | private String fieldPath; 16 | private String kind; 17 | private String name; 18 | private String namespace; 19 | private String resourceVersion; 20 | private String uid; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/roles/Roles.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.roles; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonMetaData; 5 | import org.paasta.caas.api.common.model.CommonRoleRule; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Role Model 클래스 11 | * 12 | * @author hrjin 13 | * @version 1.0 14 | * @since 2018-08-14 15 | */ 16 | @Data 17 | public class Roles { 18 | 19 | private String resultCode; 20 | private CommonMetaData metadata; 21 | private List rules; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/clusters/namespaces/ResourceQuota.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.clusters.namespaces; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonMetaData; 5 | 6 | /** 7 | * ResourceQuota Model 클래스 8 | * 9 | * @author indra 10 | * @version 1.0 11 | * @since 2018.08.28 12 | */ 13 | @Data 14 | public class ResourceQuota { 15 | 16 | private String apiVersion; 17 | private String kind; 18 | private CommonMetaData metadata; 19 | private ResourceQuotaSpec spec; 20 | private ResourceQuotaStatus status; 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/nodes/Nodes.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.nodes; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonMetaData; 5 | import org.paasta.caas.api.common.model.CommonSpec; 6 | import org.paasta.caas.api.nodes.support.NodesStatus; 7 | 8 | /** 9 | * Nodes Model 클래스 10 | * 11 | * @author Hyungu Cho 12 | * @version 1.0 13 | * @since 2018.08.13 14 | */ 15 | @Data 16 | public class Nodes { 17 | private String resultCode; 18 | 19 | private CommonMetaData metadata; 20 | private CommonSpec spec; 21 | private NodesStatus status; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/nodes/support/NodesStatus.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.nodes.support; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonCondition; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * Nodes status model 클래스 11 | * 12 | * @author Hyungu Cho 13 | * @version 1.0 14 | * @since 2018.08.17 15 | */ 16 | @Data 17 | public class NodesStatus { 18 | private Map capacity; 19 | private Map allocatable; 20 | private List conditions; 21 | private List addresses; 22 | private NodesSystemInfo nodeInfo; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/roleBindings/RoleBindings.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.roleBindings; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonMetaData; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * RoleBindings Model 클래스 11 | * 12 | * @author hrjin 13 | * @version 1.0 14 | * @since 2018-08-17 15 | */ 16 | @Data 17 | public class RoleBindings { 18 | 19 | private String resultCode; 20 | 21 | private String apiVersion; 22 | private String kind; 23 | 24 | private CommonMetaData metadata; 25 | private List subjects; 26 | private Map roleRef; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonContainer.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | /** 9 | * CommonContainer Model 클래스 10 | * 11 | * @author REX 12 | * @author CISS 13 | * @author Hyungu Cho 14 | * @version 1.0 15 | * @since 2018.08.16 16 | */ 17 | @Data 18 | public class CommonContainer { 19 | private String name; 20 | private String image; 21 | private List args; 22 | private List env; 23 | private List ports; 24 | private CommonResourceRequirement resources; 25 | private List command; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/persistentVolumeClaims/support/PersistentVolumeClaimsStatus.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.persistentVolumeClaims.support; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonCondition; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * PersistentVolumeClaimsStatus Model 클래스 11 | * 12 | * @author hrjin 13 | * @version 1.0 14 | * @since 2019-10-24 15 | */ 16 | @Data 17 | public class PersistentVolumeClaimsStatus { 18 | private List accessModes; 19 | private Map capacity; 20 | private List conditions; 21 | private String phase; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/customServices/CustomServices.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.customServices; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonMetaData; 5 | import org.paasta.caas.api.common.model.CommonSpec; 6 | import org.paasta.caas.api.common.model.CommonStatus; 7 | 8 | /** 9 | * Custom Services Model 클래스 10 | * 11 | * @author REX 12 | * @version 1.0 13 | * @since 2018.08.09 14 | */ 15 | @Data 16 | public class CustomServices { 17 | 18 | private String resultCode; 19 | private CommonMetaData metadata; 20 | private CommonSpec spec; 21 | private CommonStatus status; 22 | private String sourceTypeYaml; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/replicaSets/ReplicaSets.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.replicaSets; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonMetaData; 5 | import org.paasta.caas.api.common.model.CommonSpec; 6 | import org.paasta.caas.api.common.model.CommonStatus; 7 | 8 | /** 9 | * ReplicaSets Model 클래스 10 | * 11 | * @author CISS 12 | * @version 1.0 13 | * @since 2018.08.07 14 | */ 15 | @Data 16 | public class ReplicaSets { 17 | 18 | private String resultCode; 19 | private CommonMetaData metadata; 20 | private CommonSpec spec; 21 | private CommonStatus status; 22 | private String sourceTypeYaml; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/nodes/support/NodesSystemInfo.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.nodes.support; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * Nodes system information model 클래스 7 | * 8 | * @author Hyungu Cho 9 | * @version 1.0 10 | * @since 2018.09.17 11 | */ 12 | @Data 13 | class NodesSystemInfo { 14 | private String architecture; 15 | private String bootID; 16 | private String containerRuntimeVersion; 17 | private String kernelVersion; 18 | private String kubeProxyVersion; 19 | private String kubeletVersion; 20 | private String machineID; 21 | private String operatingSystem; 22 | private String osImage; 23 | private String systemUUID; 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonStatus.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Common Status Model 클래스 9 | * 10 | * @author CISS 11 | * @version 1.0 12 | * @since 2018.08.07 13 | */ 14 | @Data 15 | public class CommonStatus { 16 | private int availableReplicas; 17 | private int fullyLabeledReplicas; 18 | private long observedGeneration; 19 | private int readyReplicas; 20 | private int replicas; 21 | private String phase; 22 | private List containerStatuses; 23 | private List conditions; 24 | private String podIP; 25 | private String qosClass; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/clusters/namespaces/Namespaces.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.clusters.namespaces; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonMetaData; 5 | import org.paasta.caas.api.common.model.CommonSpec; 6 | import org.paasta.caas.api.common.model.CommonStatus; 7 | 8 | /** 9 | * Namespace Model 클래스 10 | * 11 | * @author indra 12 | * @version 1.0 13 | * @since 2018.08.28 14 | */ 15 | @Data 16 | public class Namespaces { 17 | 18 | private String resultCode; 19 | 20 | private String kind; 21 | private String apiVersion; 22 | 23 | private CommonMetaData metadata; 24 | private CommonSpec spec; 25 | private CommonStatus status; 26 | } 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # ignore output and build directories 14 | build/** 15 | bin/** 16 | out/** 17 | 18 | # Package Files # 19 | *.jar 20 | *.war 21 | *.ear 22 | *.zip 23 | *.tar.gz 24 | *.rar 25 | 26 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 27 | hs_err_pid* 28 | 29 | # generated gradle directories and files 30 | .gradle 31 | .settings 32 | 33 | # eclise settings 34 | .classpath 35 | .project 36 | 37 | # idea settings 38 | *.iml 39 | *.ipr 40 | *.iws 41 | *.idea 42 | .idea/* 43 | 44 | # remove spring bean configuration 45 | .spring* 46 | 47 | /logs/* 48 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/endpoints/Endpoints.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.endpoints; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonMetaData; 5 | import org.paasta.caas.api.common.model.CommonSpec; 6 | import org.paasta.caas.api.common.model.CommonStatus; 7 | import org.paasta.caas.api.common.model.CommonSubset; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Endpoints Model 클래스 13 | * 14 | * @author REX 15 | * @version 1.0 16 | * @since 2018.08.13 17 | */ 18 | @Data 19 | public class Endpoints { 20 | 21 | private String resultCode; 22 | private CommonMetaData metadata; 23 | private CommonSpec spec; 24 | private CommonStatus status; 25 | private List subsets; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/deployments/support/DeploymentsStatus.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.deployments.support; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonCondition; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * DeploymentsStatus Model 클래스 10 | * 11 | * @author PHR 12 | * @version 1.0 13 | * @since 2018.08.13 14 | */ 15 | @Data 16 | public class DeploymentsStatus { 17 | private int availableReplicas; 18 | private int collisionCount; 19 | private List conditions; 20 | private long observedGeneration; 21 | private int readyReplicas; 22 | private int replicas; 23 | private int unavailableReplicas; 24 | private int updatedReplicas; 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/pods/Pods.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.pods; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonMetaData; 5 | import org.paasta.caas.api.common.model.CommonSpec; 6 | import org.paasta.caas.api.common.model.CommonStatus; 7 | 8 | import java.util.Map; 9 | 10 | /** 11 | * Pods Model 클래스 12 | * 13 | * @author Hyungu Cho 14 | * @version 1.0 15 | * @since 2018.08.13 16 | */ 17 | @Data 18 | public class Pods { 19 | private String resultCode; 20 | 21 | private CommonMetaData metadata; 22 | private CommonSpec spec; 23 | private CommonStatus status; 24 | private String selector; 25 | 26 | private Map source; 27 | private String sourceTypeYaml; 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/deployments/support/DeploymentsSpec.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.deployments.support; 2 | 3 | import lombok.Data; 4 | 5 | import org.paasta.caas.api.common.model.CommonLabelSelector; 6 | import org.paasta.caas.api.common.model.CommonPodTemplateSpec; 7 | 8 | /** 9 | * DeploymentsSpec Model 클래스 10 | * 11 | * @author PHR 12 | * @version 1.0 13 | * @since 2018.08.13 14 | */ 15 | @Data 16 | public class DeploymentsSpec { 17 | private int minReadySeconds; 18 | private boolean paused; 19 | private int progressDeadlineSeconds; 20 | private int replicas; 21 | private int revisionHistoryLimit; 22 | private CommonLabelSelector selector; 23 | private DeploymentsStrategy strategy; 24 | private CommonPodTemplateSpec template; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/deployments/Deployments.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.deployments; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonMetaData; 5 | import org.paasta.caas.api.workloads.deployments.support.DeploymentsSpec; 6 | import org.paasta.caas.api.workloads.deployments.support.DeploymentsStatus; 7 | 8 | import java.util.Map; 9 | 10 | /** 11 | * Deployments Model 클래스 12 | * 13 | * @author PHR 14 | * @version 1.0 15 | * @since 2018.08.13 16 | */ 17 | @Data 18 | public class Deployments { 19 | private String resultCode; 20 | 21 | private CommonMetaData metadata; 22 | private DeploymentsSpec spec; 23 | private DeploymentsStatus status; 24 | 25 | private Map source; 26 | private String sourceTypeYaml; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonCondition.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.CommonUtils; 5 | 6 | /** 7 | * Common Condition Model 클래스 8 | * 9 | * @author REX 10 | * @author Hyungu Cho 11 | * @version 1.0 12 | * @since 2018.08.13 13 | */ 14 | @Data 15 | public class CommonCondition { 16 | private String type; 17 | private String status; 18 | private String message; 19 | private String reason; 20 | private String lastHeartbeatTime; 21 | private String lastTransitionTime; 22 | 23 | public String getLastHeartbeatTime() { 24 | return CommonUtils.procSetTimestamp(lastHeartbeatTime); 25 | } 26 | 27 | public String getLastTransitionTime() { 28 | return CommonUtils.procSetTimestamp(lastTransitionTime); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/adminToken/AdminTokenController.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.adminToken; 2 | 3 | import org.paasta.caas.api.common.RestTemplateService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | public class AdminTokenController { 10 | 11 | private final RestTemplateService adminTokenService; 12 | 13 | @Autowired 14 | public AdminTokenController(RestTemplateService adminTokenService) { 15 | this.adminTokenService = adminTokenService; 16 | } 17 | 18 | @GetMapping(value = "/adminToken") 19 | public AdminToken getAdminToken(){ 20 | AdminToken adminTokenValue = adminTokenService.getAdminToken(); 21 | 22 | return adminTokenValue; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/persistentVolumeClaims/PersistentVolumeClaims.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.persistentVolumeClaims; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonMetaData; 5 | import org.paasta.caas.api.persistentVolumeClaims.support.PersistentVolumeClaimsSpec; 6 | import org.paasta.caas.api.persistentVolumeClaims.support.PersistentVolumeClaimsStatus; 7 | 8 | import java.util.Map; 9 | 10 | /** 11 | * PersistentVolumeClaims Model 클래스 12 | * 13 | * @author hrjin 14 | * @version 1.0 15 | * @since 2019-10-24 16 | */ 17 | @Data 18 | public class PersistentVolumeClaims { 19 | private String resultCode; 20 | 21 | private CommonMetaData metadata; 22 | private PersistentVolumeClaimsSpec spec; 23 | private PersistentVolumeClaimsStatus status; 24 | 25 | private Map source; 26 | private String sourceTypeYaml; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/persistentVolumeClaims/support/PersistentVolumeClaimsSpec.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.persistentVolumeClaims.support; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.model.CommonLabelSelector; 5 | import org.paasta.caas.api.common.model.CommonResourceRequirement; 6 | import org.paasta.caas.api.common.model.CommonTypedLocalObjectReference; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * PersistentVolumeClaimsSpec Model 클래스 12 | * 13 | * @author hrjin 14 | * @version 1.0 15 | * @since 2019-10-24 16 | */ 17 | @Data 18 | public class PersistentVolumeClaimsSpec { 19 | private List accessModes; 20 | private String volumeName; 21 | private String storageClassName; 22 | private String volumeMode; 23 | private CommonTypedLocalObjectReference dataSource; 24 | private CommonResourceRequirement resources; 25 | private CommonLabelSelector selector; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | application: 4 | name: caas-api 5 | security: 6 | username: 7 | password: 8 | 9 | project: 10 | name: caas-api 11 | artifactId: caas-api 12 | description: caas-api management service 13 | 14 | management: # If you set off security... 15 | security: 16 | enabled: false 17 | 18 | --- 19 | spring: 20 | profiles: 21 | active: local 22 | 23 | logging: 24 | level: 25 | ROOT: INFO 26 | path: classpath:logback-spring.xml 27 | file: logs/application.log 28 | 29 | # HTTP Server 30 | server: 31 | port: ${PORT:3333} # HTTP (Tomcat) port 32 | 33 | kubernetes: 34 | adminToken: ADMIN_TOKEN 35 | api: 36 | endpoint: KUBE_API_ENDPOINT 37 | 38 | --- 39 | spring: 40 | profiles: dev 41 | 42 | logging: 43 | level: 44 | ROOT: INFO 45 | path: classpath:logback-spring.xml 46 | file: logs/application.log 47 | 48 | # HTTP Server 49 | server: 50 | port: ${PORT:3333} # HTTP (Tomcat) port 51 | 52 | kubernetes: 53 | adminToken: ADMIN_TOKEN 54 | api: 55 | endpoint: KUBE_API_ENDPOINT 56 | -------------------------------------------------------------------------------- /src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | true 7 | 8 | application.%d{yyyy-MM-dd}.log 9 | 7 10 | 11 | 12 | INFO 13 | 14 | 15 | 16 | %d{yyyy:MM:dd HH:mm:ss.SSS} %-5level --- [%thread] %logger{35} : %msg %n 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/config/GsonConfig.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.config; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.GsonBuilder; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | /** 10 | * Gson bean config class (GsonBuilder, Converter for GsonBuilder) 11 | * 12 | * @author Hyungu Cho 13 | * @version 1.0 14 | * @since 2018.09.18 15 | */ 16 | @Configuration 17 | public class GsonConfig { 18 | 19 | /** 20 | * Instantiates a new Gson builder bean (without another GsonBuilder). 21 | * 22 | * @return the gson builder 23 | */ 24 | @Bean 25 | public GsonBuilder gsonBuilder() { 26 | return new GsonBuilder(); 27 | } 28 | 29 | /** 30 | * Instantiates a new Gson builder bean (with another GsonBuilder). 31 | * 32 | * @param builder the another gson builder 33 | * @return the gson builder 34 | */ 35 | @Bean 36 | @Autowired 37 | public Gson gson(GsonBuilder builder) { 38 | return builder.create(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/Constants.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common; 2 | 3 | import org.springframework.http.MediaType; 4 | 5 | /** 6 | * Constants 클래스 7 | * 8 | * @author CISS 9 | * @version 1.0 10 | * @since 2018.08.01 최초작성 11 | */ 12 | public class Constants { 13 | 14 | public static final String RESULT_STATUS_SUCCESS = "SUCCESS"; 15 | public static final String RESULT_STATUS_FAIL = "FAIL"; 16 | 17 | public static final String TARGET_CAAS_MASTER_API = "caasMasterApi"; 18 | public static final String ACCEPT_TYPE_YAML = String.valueOf(MediaType.valueOf("application/yaml")); 19 | 20 | public static final String TOKEN_KEY = "caas_admin"; 21 | 22 | public static final String TARGET_COMMON_API = "commonApi"; 23 | 24 | public static final String URI_COMMON_API_ADMIN_TOKEN_DETAIL = "/adminToken/{tokenName:.+}"; 25 | 26 | static final String STRING_DATE_TYPE = "yyyy-MM-dd HH:mm:ss"; 27 | static final String STRING_ORIGINAL_DATE_TYPE = "yyyy-MM-dd'T'HH:mm:ss'Z'"; 28 | static final String STRING_TIME_ZONE_ID = "Asia/Seoul"; 29 | 30 | static final String ACCEPT_TYPE_JSON = MediaType.APPLICATION_JSON_VALUE; 31 | 32 | 33 | public Constants() { 34 | throw new IllegalStateException(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/events/Events.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.events; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.common.CommonUtils; 5 | import org.paasta.caas.api.common.model.CommonMetaData; 6 | import org.paasta.caas.api.common.model.CommonObjectReference; 7 | 8 | /** 9 | * Events Model 클래스 10 | * 11 | * @author CISS 12 | * @version 1.0 13 | * @since 2018.08.13 14 | */ 15 | @Data 16 | public class Events { 17 | 18 | private String resultCode; 19 | private CommonMetaData metadata; 20 | //private String action; 21 | private int count; 22 | //private String eventTime; 23 | private String firstTimestamp; 24 | private String lastTimestamp; 25 | private String message; 26 | //private String reason; 27 | private EventSource source; 28 | private String type; 29 | private CommonObjectReference involvedObject; 30 | 31 | public String getFirstTimestamp() { 32 | return CommonUtils.procSetTimestamp(firstTimestamp); 33 | } 34 | 35 | 36 | public String getLastTimestamp() { 37 | return CommonUtils.procSetTimestamp(lastTimestamp); 38 | } 39 | 40 | 41 | @Data 42 | public class EventSource { 43 | private String component; 44 | private String host; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonMetaData.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | import lombok.experimental.Accessors; 6 | import org.paasta.caas.api.common.CommonUtils; 7 | 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | /** 12 | * ListMeta Model 클래스 13 | * 14 | * @author CISS 15 | * @version 1.0 16 | * @since 2018.08.07 17 | */ 18 | @Data 19 | public class CommonMetaData { 20 | private Map labels; 21 | private String name; 22 | private String namespace; 23 | private Map annotations; 24 | private String clusterName; 25 | private String creationTimestamp; 26 | private long deletionGracePeriodSeconds; 27 | private String deletionTimestamp; 28 | private List finalizers; 29 | private String generateName; 30 | private long generation; 31 | private String uid; 32 | private String resourceVersion; 33 | private String selfLink; 34 | private List ownerReferences; 35 | 36 | @Accessors(prefix = "_") 37 | @SerializedName("continue") 38 | private String _continue; 39 | 40 | public String getCreationTimestamp() { 41 | return CommonUtils.procSetTimestamp(creationTimestamp); 42 | } 43 | 44 | public String getDeletionTimestamp() { 45 | return CommonUtils.procSetTimestamp(deletionTimestamp); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/CommonUtils.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | import java.util.TimeZone; 6 | 7 | /** 8 | * Common utils 클래스 9 | * 10 | * @author REX 11 | * @version 1.0 12 | * @since 2018.09.17 13 | */ 14 | public class CommonUtils { 15 | 16 | /** 17 | * Timestamp Timezone 을 변경하여 재설정한다. 18 | * 19 | * @param requestTimestamp the request timestamp 20 | * @return the string 21 | */ 22 | public static String procSetTimestamp(String requestTimestamp) { 23 | String resultString = ""; 24 | 25 | if (null == requestTimestamp || "".equals(requestTimestamp)) { 26 | return resultString; 27 | } 28 | 29 | SimpleDateFormat simpleDateFormatForOrigin = new SimpleDateFormat(Constants.STRING_ORIGINAL_DATE_TYPE); 30 | SimpleDateFormat simpleDateFormatForSet = new SimpleDateFormat(Constants.STRING_DATE_TYPE); 31 | 32 | try { 33 | Date parseDate = simpleDateFormatForOrigin.parse(requestTimestamp); 34 | long parseDateTime = parseDate.getTime(); 35 | int offset = TimeZone.getTimeZone(Constants.STRING_TIME_ZONE_ID).getOffset(parseDateTime); 36 | 37 | resultString = simpleDateFormatForSet.format(parseDateTime + offset); 38 | } catch (Exception e) { 39 | e.printStackTrace(); 40 | } 41 | 42 | return resultString; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/users/UsersController.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.users; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.DeleteMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * Users Controller 클래스 11 | * 12 | * @author hrjin 13 | * @version 1.0 14 | * @since 2018-09-03 15 | */ 16 | @RestController 17 | @RequestMapping(value = "/namespaces/{namespace:.+}/serviceAccounts") 18 | public class UsersController { 19 | 20 | private final UsersService usersService; 21 | 22 | /** 23 | * Instantiates a new Users controller 24 | * 25 | * @param usersService the users service 26 | */ 27 | @Autowired 28 | public UsersController(UsersService usersService) { 29 | this.usersService = usersService; 30 | } 31 | 32 | /** 33 | * Users 를 삭제한다. 34 | * 35 | * @param namespace the namespace 36 | * @param caasAccountName the caasAccountName 37 | * @return the Users 38 | */ 39 | @DeleteMapping(value = "/{caasAccountName:.+}") 40 | public Users deleteUser(@PathVariable("namespace") String namespace, @PathVariable("caasAccountName") String caasAccountName) { 41 | return usersService.deleteServiceAccount(namespace, caasAccountName); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/nodes/NodesController.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.nodes; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * Nodes Controller 클래스 11 | * 12 | * @author Hyungu Cho 13 | * @version 1.0 14 | * @since 2018.08.13 15 | */ 16 | @RestController 17 | @RequestMapping(value = "/nodes") 18 | public class NodesController { 19 | private final NodesService nodesService; 20 | 21 | /** 22 | * Instantiates a new Nodes controller. 23 | * 24 | * @param nodesService the node service 25 | */ 26 | @Autowired 27 | public NodesController(NodesService nodesService) { 28 | this.nodesService = nodesService; 29 | } 30 | 31 | /** 32 | * Node 목록을 조회한다. 33 | * 34 | * @return the node list 35 | */ 36 | @GetMapping 37 | public NodesList getNodeList() { 38 | return nodesService.getNodeList(); 39 | } 40 | 41 | 42 | /** 43 | * Node를 조회한다. 44 | * 45 | * @param nodeName the node name 46 | * @return the node 47 | */ 48 | @GetMapping(value = "/{nodeName:.+}") 49 | public Nodes getNode(@PathVariable(value = "nodeName") String nodeName) { 50 | return nodesService.getNode(nodeName); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/model/CommonSpec.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common.model; 2 | 3 | import lombok.Data; 4 | import org.paasta.caas.api.workloads.pods.support.Volume; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * Common Spec Model 클래스 11 | * 12 | * @author CISS 13 | * @version 1.0 14 | * @since 2018.08.07 15 | */ 16 | @Data 17 | public class CommonSpec { 18 | private int minReadySeconds; 19 | private int replicas; 20 | private CommonPodTemplateSpec template; 21 | private long activeDeadlineSeconds; 22 | private boolean automountServiceAccountToken; 23 | private String dnsPolicy; 24 | private boolean hostIPC; 25 | private boolean hostNetwork; 26 | private boolean hostPID; 27 | private String hostname; 28 | private String nodeName; 29 | private Map nodeSelector; 30 | private int priority; 31 | private String priorityClassName; 32 | private String restartPolicy; 33 | private String schedulerName; 34 | private String serviceAccount; 35 | private String serviceAccountName; 36 | private boolean shareProcessNamespace; 37 | private String subdomain; 38 | private long terminationGracePeriodSeconds; 39 | private String type; 40 | private String clusterIP; 41 | private List ports; 42 | private String sessionAffinity; 43 | private Map selector; 44 | private List containers; 45 | private String podCIDR; 46 | private List> taints; 47 | private List volumes; 48 | private List externalIPs; 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/accessInfo/AccessTokenController.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.accessInfo; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * AccessToken Controller 클래스 10 | * 11 | * @author hrjin 12 | * @version 1.0 13 | * @since 2018-09-04 14 | */ 15 | @RestController 16 | @RequestMapping("/namespaces/{namespace:.+}/secrets") 17 | public class AccessTokenController { 18 | 19 | private final AccessTokenService accessTokenService; 20 | 21 | /** 22 | * Instantiates a new accessToken controller 23 | * 24 | * @param accessTokenService the accessToken service 25 | */ 26 | @Autowired 27 | public AccessTokenController(AccessTokenService accessTokenService) { 28 | this.accessTokenService = accessTokenService; 29 | } 30 | 31 | /** 32 | * Secret 상세 정보를 조회한다. 33 | * 34 | * @param namespace the namespace 35 | * @param accessTokenName the accessTokenName 36 | * @return the AccessToken 37 | */ 38 | @RequestMapping(value = "/{accessTokenName:.+}") 39 | @ResponseBody 40 | public AccessToken getSecret(@PathVariable("namespace") String namespace, @PathVariable("accessTokenName") String accessTokenName) { 41 | return accessTokenService.getSecret(namespace, accessTokenName); 42 | } 43 | 44 | @PostMapping() 45 | public Map createSecret(@PathVariable("namespace") String namespace, @RequestBody Object secret){ 46 | return accessTokenService.createSecret(namespace, secret); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/roles/RolesController.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.roles; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | /** 7 | * Role Controller 클래스 8 | * 9 | * @author hrjin 10 | * @version 1.0 11 | * @since 2018-08-14 12 | */ 13 | @RestController 14 | @RequestMapping(value = "/namespaces/{namespace:.+}/roles") 15 | public class RolesController { 16 | 17 | private final RolesService roleService; 18 | 19 | /** 20 | * Instantiates a new Roles controller 21 | * 22 | * @param roleService the role service 23 | */ 24 | @Autowired 25 | public RolesController(RolesService roleService) { 26 | this.roleService = roleService; 27 | } 28 | 29 | 30 | /** 31 | * Role 을 삭제한다. 32 | * 33 | * @param namespace the namespace 34 | * @param roleName the roleName 35 | * @return String 36 | */ 37 | @DeleteMapping(value = "/{roleName:.+}") 38 | public String deleteRole(@PathVariable("namespace") String namespace, @PathVariable("roleName") String roleName) { 39 | return roleService.deleteRole(namespace, roleName); 40 | } 41 | 42 | /** 43 | * Role 을 수정한다. 44 | * 45 | * @param namespace the namespace 46 | * @param roleName the roleName 47 | * @param yml the yml 48 | * @return String 49 | */ 50 | @PutMapping(value = "/{roleName:.+}") 51 | public String updateRole(@PathVariable("namespace") String namespace, @PathVariable("roleName") String roleName, @RequestBody String yml) { 52 | return roleService.updateRole(namespace, roleName, yml); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/events/EventsController.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.events; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | /** 7 | * Events Controller 클래스 8 | * 9 | * @author CISS 10 | * @version 1.0 11 | * @since 2018.08.13 12 | */ 13 | @RestController 14 | @RequestMapping("/namespaces/{namespace:.+}/events") 15 | public class EventsController { 16 | 17 | private final EventsService eventsService; 18 | 19 | /** 20 | * Instantiates a new Events controller. 21 | * 22 | * @param eventsService the events service 23 | */ 24 | @Autowired 25 | public EventsController(EventsService eventsService) { 26 | this.eventsService = eventsService; 27 | } 28 | 29 | 30 | /** 31 | * Events 목록을 조회한다. 32 | * 33 | * @param namespace the namespace 34 | * @param resourceUid the resourceUid 35 | * @return the events list 36 | */ 37 | @GetMapping(value = "/resources/{resourceUid:.+}") 38 | public EventsList getEventsList(@PathVariable("namespace") String namespace, @PathVariable("resourceUid") String resourceUid, @RequestParam(value="type", required=false) String type) { 39 | return eventsService.getEventsList(namespace, resourceUid, type); 40 | } 41 | 42 | /** 43 | * Events 목록을 조회한다.(for namespace) 44 | * 45 | * @param namespace the namespace 46 | * @return the events list 47 | */ 48 | @GetMapping 49 | public EventsList getNamespaceEventsList(@PathVariable("namespace") String namespace) { 50 | return eventsService.getNamespaceEventsList(namespace); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/clusters/namespaces/NamespacesController.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.clusters.namespaces; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * Namespaces Controller 클래스. 11 | * 12 | * @author indra 13 | * @version 1.0 14 | * @since 2018.08.01 최초작성 15 | */ 16 | @RestController 17 | @RequestMapping("/namespaces") 18 | public class NamespacesController { 19 | 20 | private final NamespacesService namespacesService; 21 | 22 | /** 23 | * Instantiates a Namespaces controller. 24 | * 25 | * @param namespacesService the namespaces service 26 | */ 27 | @Autowired 28 | public NamespacesController(NamespacesService namespacesService) { 29 | this.namespacesService = namespacesService; 30 | } 31 | 32 | /** 33 | * Namespaces 상세정보를 조회한다. 34 | * 35 | * @param namespace the namespaces 36 | * @return the namespaces 37 | */ 38 | @GetMapping("/{namespace:.+}") 39 | public Namespaces getNamespaces(@PathVariable("namespace") String namespace) { 40 | return namespacesService.getNamespaces(namespace); 41 | } 42 | 43 | /** 44 | * ResourceQuota 목록을 조회한다. 45 | * 46 | * @param namespace the namespaces 47 | * @return the ResourceQuotaList 48 | */ 49 | @GetMapping("/{namespace:.+}/resourceQuotas") 50 | public ResourceQuotaList getResourceQuotaList(@PathVariable("namespace") String namespace) { 51 | return namespacesService.getResourceQuotaList(namespace); 52 | } 53 | 54 | @PostMapping() 55 | public Map createDeploymentsYaml(@RequestBody Object namespace) { 56 | return namespacesService.createNamespaces(namespace); 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/endpoints/EndpointsController.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.endpoints; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * Endpoints Controller 클래스 11 | * 12 | * @author REX 13 | * @version 1.0 14 | * @since 2018.08.13 15 | */ 16 | @RestController 17 | @RequestMapping("/namespaces/{namespace:.+}/endpoints") 18 | public class EndpointsController { 19 | 20 | private final EndpointsService endpointsService; 21 | 22 | /** 23 | * Instantiates a new Endpoints controller. 24 | * 25 | * @param endpointsService the endpoints service 26 | */ 27 | @Autowired 28 | public EndpointsController(EndpointsService endpointsService) {this.endpointsService = endpointsService;} 29 | 30 | 31 | /** 32 | * Endpoints 목록을 조회한다. 33 | * 34 | * @param namespace the namespace 35 | * @return the endpoints list 36 | */ 37 | @GetMapping 38 | public EndpointsList getEndpointsList(@PathVariable("namespace") String namespace) { 39 | return endpointsService.getEndpointsList(namespace); 40 | } 41 | 42 | 43 | /** 44 | * Endpoints 상세 정보를 조회한다. 45 | * 46 | * @param namespace the namespace 47 | * @param serviceName the service name 48 | * @return the endpoints 49 | */ 50 | @GetMapping(value = "/{serviceName:.+}") 51 | public Endpoints getEndpoints(@PathVariable("namespace") String namespace, @PathVariable("serviceName") String serviceName) { 52 | return endpointsService.getEndpoints(namespace, serviceName); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/exception/GlobalControllerExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.exception; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.MessageSource; 7 | import org.springframework.web.bind.annotation.ControllerAdvice; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.ResponseBody; 10 | import org.springframework.web.client.HttpClientErrorException; 11 | 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | /** 15 | * Api ExceptionHandler 클래스 16 | * 17 | * @author CISS 18 | * @version 1.0 19 | * @since 2018.08.01 20 | */ 21 | @ControllerAdvice 22 | public class GlobalControllerExceptionHandler { 23 | 24 | private static final Logger LOGGER = LoggerFactory.getLogger(GlobalControllerExceptionHandler.class); 25 | 26 | @Autowired 27 | public MessageSource messageSource; 28 | 29 | // Rest API Template Error Exception 30 | @ExceptionHandler(HttpClientErrorException.class) 31 | @ResponseBody 32 | public void httpClientErrorException(HttpClientErrorException ex, HttpServletResponse response) throws Exception { 33 | 34 | LOGGER.error("HttpClientErrorException : " + ex ); 35 | 36 | String message = 37 | "{\"resultMessage\":\""+ex.getStatusText()+"\"" + 38 | //",\"resultCode\":\""+ex.getStatusCode()+"\"}"; 39 | ",\"resultCode\":\""+"FAIL"+"\"}"; 40 | // errorCode를 받지만, 에러를 "FAIL"로 코드 통일 41 | 42 | // CAAS-API 통신 성공을 위한 SC_OK(200) 및 kubernetes API 에러코드 및 메시지 전달 43 | response.resetBuffer(); 44 | response.setStatus(HttpServletResponse.SC_OK); 45 | response.setHeader("Content-Type", "application/json;charset=utf-8"); 46 | response.setContentType("application/json; charset=UTF-8"); 47 | response.getWriter().print(message); 48 | response.flushBuffer(); 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/config/RestTemplateConfig.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.config; 2 | 3 | import org.apache.http.conn.ssl.SSLConnectionSocketFactory; 4 | import org.apache.http.impl.client.CloseableHttpClient; 5 | import org.apache.http.impl.client.HttpClients; 6 | import org.apache.http.ssl.TrustStrategy; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; 10 | import org.springframework.web.client.RestTemplate; 11 | 12 | import javax.net.ssl.SSLContext; 13 | import java.security.KeyManagementException; 14 | import java.security.KeyStoreException; 15 | import java.security.NoSuchAlgorithmException; 16 | import java.security.cert.X509Certificate; 17 | 18 | /** 19 | * The type Rest template config. 20 | */ 21 | @Configuration 22 | public class RestTemplateConfig { 23 | 24 | /** 25 | * Rest template rest template. 26 | * 27 | * @return the rest template 28 | * @throws KeyStoreException the key store exception 29 | * @throws NoSuchAlgorithmException the no such algorithm exception 30 | * @throws KeyManagementException the key management exception 31 | */ 32 | @Bean 33 | public RestTemplate restTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { 34 | TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true; 35 | SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build(); 36 | SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext); 37 | CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(csf).build(); 38 | HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); 39 | requestFactory.setHttpClient(httpClient); 40 | 41 | return new RestTemplate(requestFactory); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/authenticate/AuthenticateController.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.authenticate; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | /** 7 | * Authenticate Controller 클래스. 8 | * 9 | * @author indra 10 | * @version 1.0 11 | * @since 2018.09.05 최초작성 12 | */ 13 | @RestController 14 | public class AuthenticateController { 15 | 16 | private final AuthenticateService authenticateService; 17 | 18 | /** 19 | * Instantiates a Authenticate controller. 20 | * 21 | * @param authenticateService the authenticate service 22 | */ 23 | @Autowired 24 | public AuthenticateController(AuthenticateService authenticateService) { 25 | this.authenticateService = authenticateService; 26 | } 27 | 28 | /** 29 | * 유저를 생성한다. 30 | * 31 | * @param namespace the namespace 32 | * @param yml the yml 33 | */ 34 | @PostMapping(value = "/namespaces/{namespace}/serviceaccounts") 35 | public void createUser(@PathVariable("namespace") String namespace, @RequestBody String yml){ 36 | authenticateService.createUser(namespace, yml); 37 | } 38 | 39 | /** 40 | * 롤을 생성한다. 41 | * 42 | * @param namespace the namespace 43 | * @param yml the yml 44 | */ 45 | @PostMapping(value = "/namespaces/{namespace}/roles") 46 | public void createRole(@PathVariable("namespace") String namespace, @RequestBody String yml){ 47 | authenticateService.createRole(namespace, yml); 48 | } 49 | 50 | /** 51 | * 롤을 바인딩한다. 52 | * 53 | * @param namespace the namespace 54 | * @param yml the yml 55 | */ 56 | @PostMapping(value = "/namespaces/{namespace}/rolebindings") 57 | public void createRoleBinding(@PathVariable("namespace") String namespace, @RequestBody String yml){ 58 | authenticateService.createRoleBinding(namespace, yml); 59 | } 60 | 61 | /** 62 | * 토큰을 조회한다. 63 | * 64 | * @param namespace the namespace 65 | * @param userName the user name 66 | * @return the String 67 | */ 68 | @GetMapping(value = "/namespaces/{namespace}/serviceaccounts/{userName}") 69 | public String getToken(@PathVariable("namespace") String namespace, @PathVariable("userName") String userName){ 70 | return authenticateService.getToken(namespace, userName); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/users/UsersService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.users; 2 | 3 | import org.paasta.caas.api.common.CommonService; 4 | import org.paasta.caas.api.common.Constants; 5 | import org.paasta.caas.api.common.PropertyService; 6 | import org.paasta.caas.api.common.RestTemplateService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpMethod; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * Users(Service Account) Service 클래스 16 | * 17 | * @author hrjin 18 | * @version 1.0 19 | * @since 2018 -09-03 20 | */ 21 | @Service 22 | public class UsersService { 23 | private final RestTemplateService restTemplateService; 24 | private final CommonService commonService; 25 | private final PropertyService propertyService; 26 | 27 | /** 28 | * Instantiates a new Users service 29 | * 30 | * @param restTemplateService the rest template service 31 | * @param commonService the common service 32 | * @param propertyService the property service 33 | */ 34 | @Autowired 35 | public UsersService(RestTemplateService restTemplateService, CommonService commonService, PropertyService propertyService) { 36 | this.restTemplateService = restTemplateService; 37 | this.commonService = commonService; 38 | this.propertyService = propertyService; 39 | } 40 | 41 | 42 | /** 43 | * Service Account 를 삭제한다. 44 | * 45 | * @param namespace the namespace 46 | * @param caasAccountName the caasAccountNmae 47 | * @return the Users 48 | */ 49 | Users deleteServiceAccount(String namespace, String caasAccountName) { 50 | Users responseObject; 51 | String resultCode; 52 | 53 | String apiUrl = propertyService.getCaasMasterApiListUsersDeleteUrl() 54 | .replace("{namespace}", namespace) 55 | .replace("{name}", caasAccountName); 56 | 57 | HashMap responseMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, apiUrl, HttpMethod.DELETE, null, Map.class); 58 | 59 | responseObject = commonService.setResultObject(responseMap, Users.class); 60 | resultCode = Constants.RESULT_STATUS_SUCCESS; 61 | 62 | return (Users) commonService.setResultModel(responseObject, resultCode); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/nodes/NodesService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.nodes; 2 | 3 | import org.paasta.caas.api.common.CommonService; 4 | import org.paasta.caas.api.common.Constants; 5 | import org.paasta.caas.api.common.PropertyService; 6 | import org.paasta.caas.api.common.RestTemplateService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpMethod; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * Nodes Service 클래스 16 | * 17 | * @author Hyungu Cho 18 | * @version 1.0 19 | * @since 2018.8.13 20 | */ 21 | @Service 22 | public class NodesService { 23 | private final RestTemplateService restTemplateService; 24 | private final CommonService commonService; 25 | private final PropertyService propertyService; 26 | 27 | /** 28 | * Instantiates a new Nodes service. 29 | * 30 | * @param restTemplateService the rest template service 31 | * @param commonService the common service 32 | * @param propertyService the property service 33 | */ 34 | @Autowired 35 | public NodesService(RestTemplateService restTemplateService, CommonService commonService, 36 | PropertyService propertyService) { 37 | this.restTemplateService = restTemplateService; 38 | this.commonService = commonService; 39 | this.propertyService = propertyService; 40 | } 41 | 42 | 43 | /** 44 | * Node 목록을 조회한다. 45 | * 46 | * @return the node list 47 | */ 48 | NodesList getNodeList() { 49 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 50 | propertyService.getCaasMasterApiListNodesListUrl(), HttpMethod.GET, null, Map.class); 51 | 52 | return (NodesList) commonService.setResultModel(commonService.setResultObject(resultMap, NodesList.class), Constants.RESULT_STATUS_SUCCESS); 53 | } 54 | 55 | 56 | /** 57 | * Node를 조회한다. 58 | * 59 | * @param nodeName the node name 60 | * @return the node 61 | */ 62 | Nodes getNode(String nodeName) { 63 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 64 | propertyService.getCaasMasterApiListNodesGetUrl().replace("{name}", nodeName), HttpMethod.GET, null, Map.class); 65 | 66 | return (Nodes) commonService.setResultModel(commonService.setResultObject(resultMap, Nodes.class), Constants.RESULT_STATUS_SUCCESS); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/roles/RolesService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.roles; 2 | 3 | import org.paasta.caas.api.common.Constants; 4 | import org.paasta.caas.api.common.PropertyService; 5 | import org.paasta.caas.api.common.RestTemplateService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.HttpMethod; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * Role Service 클래스 15 | * 16 | * @author hrjin 17 | * @version 1.0 18 | * @since 2018 -08-14 19 | */ 20 | @Service 21 | public class RolesService { 22 | 23 | private final RestTemplateService restTemplateService; 24 | private final PropertyService propertyService; 25 | 26 | /** 27 | * Instantiates a new Roles service 28 | * 29 | * @param restTemplateService the rest template service 30 | * @param propertyService the property service 31 | */ 32 | @Autowired 33 | public RolesService(RestTemplateService restTemplateService, PropertyService propertyService) { 34 | this.restTemplateService = restTemplateService; 35 | this.propertyService = propertyService; 36 | } 37 | 38 | 39 | /** 40 | * Role 을 삭제한다. 41 | * 42 | * @param namespace the namespace 43 | * @param roleName the roleName 44 | * @return String string 45 | */ 46 | String deleteRole(String namespace, String roleName) { 47 | String apiUrl = propertyService.getCaasMasterApiListRolesDeleteUrl() 48 | .replace("{namespace}", namespace) 49 | .replace("{name}", roleName); 50 | 51 | HashMap responseMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, apiUrl, HttpMethod.DELETE, null, Map.class); 52 | 53 | if (responseMap != null) { 54 | return Constants.RESULT_STATUS_SUCCESS; 55 | } 56 | return Constants.RESULT_STATUS_FAIL; 57 | } 58 | 59 | /** 60 | * Role 을 수정한다. 61 | * 62 | * @param namespace the namespace 63 | * @param roleName the roleName 64 | * @param yml the yml 65 | * @return String string 66 | */ 67 | String updateRole(String namespace, String roleName, String yml) { 68 | String apiUrl = propertyService.getCaasMasterApiListRolesUpdateUrl() 69 | .replace("{namespace}", namespace) 70 | .replace("{name}", roleName); 71 | 72 | String resultString = restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, apiUrl, HttpMethod.PUT, yml, String.class, Constants.ACCEPT_TYPE_YAML, Constants.ACCEPT_TYPE_YAML); 73 | 74 | if (resultString != null) { 75 | return Constants.RESULT_STATUS_SUCCESS; 76 | } 77 | return Constants.RESULT_STATUS_FAIL; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/org/paasta/caas/api/users/UsersServiceTest.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.users; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.mockito.InjectMocks; 7 | import org.mockito.Mock; 8 | import org.paasta.caas.api.common.CommonService; 9 | import org.paasta.caas.api.common.Constants; 10 | import org.paasta.caas.api.common.PropertyService; 11 | import org.paasta.caas.api.common.RestTemplateService; 12 | import org.springframework.http.HttpMethod; 13 | import org.springframework.test.context.TestPropertySource; 14 | import org.springframework.test.context.junit4.SpringRunner; 15 | 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | 20 | import static org.assertj.core.api.Assertions.assertThat; 21 | import static org.junit.Assert.assertEquals; 22 | import static org.mockito.Mockito.when; 23 | 24 | @RunWith(SpringRunner.class) 25 | @TestPropertySource("classpath:application.yml") 26 | public class UsersServiceTest { 27 | 28 | private static final String NAMESPACE = "test-namespace"; 29 | private static final String CAAS_ACCOUNT_NAME = "test-caas-account-name"; 30 | private static final String DELETE_URL = "/api/v1/namespaces/test-namespace/serviceaccounts/test-caas-account-name"; 31 | 32 | private static HashMap gResultMap = null; 33 | private static Users gResultModel = null; 34 | private static Users gFinalResultModel = null; 35 | 36 | @Mock 37 | RestTemplateService restTemplateService; 38 | 39 | @Mock 40 | PropertyService propertyService; 41 | 42 | @Mock 43 | CommonService commonService; 44 | 45 | @InjectMocks 46 | UsersService usersService; 47 | 48 | @Before 49 | public void setUp() { 50 | gResultMap = new HashMap(); 51 | gResultModel = new Users(); 52 | gFinalResultModel = new Users(); 53 | gFinalResultModel.setResultCode(Constants.RESULT_STATUS_SUCCESS); 54 | } 55 | 56 | @Test 57 | public void deleteServiceAccount(){ 58 | // CONDITION 59 | 60 | when(propertyService.getCaasMasterApiListUsersDeleteUrl()).thenReturn("/api/v1/namespaces/{namespace}/serviceaccounts/{name}"); 61 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, DELETE_URL, HttpMethod.DELETE, null, Map.class)).thenReturn(gResultMap); 62 | when(commonService.setResultObject(gResultMap, Users.class)).thenReturn(gResultModel); 63 | when(commonService.setResultModel(gResultModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultModel); 64 | 65 | // TEST 66 | Users resultModel = usersService.deleteServiceAccount(NAMESPACE, CAAS_ACCOUNT_NAME); 67 | 68 | // VERIFY 69 | assertThat(resultModel).isNotNull(); 70 | assertEquals(Constants.RESULT_STATUS_SUCCESS, resultModel.getResultCode()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/endpoints/EndpointsService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.endpoints; 2 | 3 | import org.paasta.caas.api.common.CommonService; 4 | import org.paasta.caas.api.common.Constants; 5 | import org.paasta.caas.api.common.PropertyService; 6 | import org.paasta.caas.api.common.RestTemplateService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpMethod; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * Endpoints Service 클래스 16 | * 17 | * @author REX 18 | * @version 1.0 19 | * @since 2018.08.13 20 | */ 21 | @Service 22 | public class EndpointsService { 23 | 24 | private final RestTemplateService restTemplateService; 25 | private final CommonService commonService; 26 | private final PropertyService propertyService; 27 | 28 | /** 29 | * Instantiates a new Endpoints service. 30 | * 31 | * @param restTemplateService the rest template service 32 | * @param commonService the common service 33 | * @param propertyService the property service 34 | */ 35 | @Autowired 36 | public EndpointsService(RestTemplateService restTemplateService, CommonService commonService, PropertyService propertyService) { 37 | this.restTemplateService = restTemplateService; 38 | this.commonService = commonService; 39 | this.propertyService = propertyService; 40 | } 41 | 42 | 43 | /** 44 | * Endpoints 목록을 조회한다. 45 | * 46 | * @param namespace the namespace 47 | * @return the endpoints list 48 | */ 49 | EndpointsList getEndpointsList(String namespace) { 50 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 51 | propertyService.getCaasMasterApiListEndpointsListUrl() 52 | .replace("{namespace}", namespace), HttpMethod.GET, null, Map.class); 53 | 54 | return (EndpointsList) commonService.setResultModel(commonService.setResultObject(resultMap, EndpointsList.class), Constants.RESULT_STATUS_SUCCESS); 55 | } 56 | 57 | 58 | /** 59 | * Endpoints 상세 정보를 조회한다. 60 | * 61 | * @param namespace the namespace 62 | * @param serviceName the service name 63 | * @return the endpoints 64 | */ 65 | Endpoints getEndpoints(String namespace, String serviceName) { 66 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 67 | propertyService.getCaasMasterApiListEndpointsGetUrl() 68 | .replace("{namespace}", namespace) 69 | .replace("{name}", serviceName), HttpMethod.GET, null, Map.class); 70 | 71 | return (Endpoints) commonService.setResultModel(commonService.setResultObject(resultMap, Endpoints.class), Constants.RESULT_STATUS_SUCCESS); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/CommonService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common; 2 | 3 | import com.google.gson.Gson; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.lang.reflect.InvocationTargetException; 10 | import java.lang.reflect.Method; 11 | 12 | /** 13 | * Common Service 클래스 14 | * 15 | * @author REX 16 | * @version 1.0 17 | * @since 2018.08.07 18 | */ 19 | @Service 20 | public class CommonService { 21 | 22 | private static final Logger LOGGER = LoggerFactory.getLogger(CommonService.class); 23 | private final Gson gson; 24 | 25 | /** 26 | * Instantiates a new Common service. 27 | * 28 | * @param gson the gson 29 | */ 30 | @Autowired 31 | public CommonService(Gson gson) {this.gson = gson;} 32 | 33 | 34 | /** 35 | * Sets result model. 36 | * 37 | * @param reqObject the req object 38 | * @param resultCode the result code 39 | * @return the result model 40 | */ 41 | public Object setResultModel(Object reqObject, String resultCode) { 42 | try { 43 | Class aClass = reqObject.getClass(); 44 | 45 | Method methodSetResultCode = aClass.getMethod("setResultCode", String.class); 46 | methodSetResultCode.invoke(reqObject, resultCode); 47 | 48 | } catch (NoSuchMethodException e) { 49 | LOGGER.error("NoSuchMethodException :: {}", e); 50 | } catch (IllegalAccessException e1) { 51 | LOGGER.error("IllegalAccessException :: {}", e1); 52 | } catch (InvocationTargetException e2) { 53 | LOGGER.error("InvocationTargetException :: {}", e2); 54 | } 55 | 56 | return reqObject; 57 | } 58 | 59 | 60 | /** 61 | * Sets result object. 62 | * 63 | * @param the type parameter 64 | * @param requestObject the request object 65 | * @param requestClass the request class 66 | * @return the result object 67 | */ 68 | public T setResultObject(Object requestObject, Class requestClass) { 69 | return this.fromJson(this.toJson(requestObject), requestClass); 70 | } 71 | 72 | 73 | /** 74 | * To json string. 75 | * 76 | * @param requestObject the request object 77 | * @return the string 78 | */ 79 | private String toJson(Object requestObject) { 80 | return gson.toJson(requestObject); 81 | } 82 | 83 | 84 | /** 85 | * From json t. 86 | * 87 | * @param the type parameter 88 | * @param requestString the request string 89 | * @param requestClass the request class 90 | * @return the t 91 | */ 92 | private T fromJson(String requestString, Class requestClass) { 93 | return gson.fromJson(requestString, requestClass); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/replicaSets/ReplicaSetsController.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.replicaSets; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * ReplicaSets Controller 클래스 11 | * 12 | * @author CISS 13 | * @version 1.0 14 | * @since 2018.08.01 15 | */ 16 | @RestController 17 | @RequestMapping("/namespaces/{namespace:.+}/replicaSets") 18 | public class ReplicaSetsController { 19 | 20 | private final ReplicaSetsService replicaSetsService; 21 | 22 | /** 23 | * Instantiates a new ReplicaSets controller. 24 | * 25 | * @param replicaSetsService the replicaSets service 26 | */ 27 | @Autowired 28 | public ReplicaSetsController(ReplicaSetsService replicaSetsService) { this.replicaSetsService = replicaSetsService;} 29 | 30 | /** 31 | * ReplicaSets 목록을 조회한다. 32 | * 33 | * @param namespace the namespace 34 | * @return the replicaSets list 35 | */ 36 | @GetMapping 37 | public ReplicaSetsList getReplicaSetsList(@PathVariable("namespace") String namespace){ 38 | return replicaSetsService.getReplicaSetsList(namespace); 39 | } 40 | 41 | /** 42 | * ReplicaSets 상세정보를 조회한다. 43 | * 44 | * @param namespace the namespace 45 | * @param replicaSetName the replicaSets name 46 | * @return the replicaSets 47 | */ 48 | @GetMapping(value = "/{replicaSetName:.+}") 49 | public ReplicaSets getReplicaSets(@PathVariable("namespace") String namespace, @PathVariable("replicaSetName") String replicaSetName) { 50 | return replicaSetsService.getReplicaSets(namespace, replicaSetName); 51 | } 52 | 53 | /** 54 | * ReplicaSets YAML을 조회한다. 55 | * 56 | * @param namespace the namespace 57 | * @param replicaSetName the replicaSets name 58 | * @return the replicaSets yaml 59 | */ 60 | @GetMapping(value = "/{replicaSetName:.+}/yaml") 61 | public ReplicaSets getReplicaSetsYaml(@PathVariable(value = "namespace") String namespace, @PathVariable(value = "replicaSetName") String replicaSetName) { 62 | return replicaSetsService.getReplicaSetsYaml(namespace, replicaSetName); 63 | } 64 | 65 | /** 66 | * ReplicaSets 목록을 조회한다.(Label Selector) 67 | * @param namespace namespace 68 | * @param selectors selectors 69 | * @return the replicaSets list 70 | */ 71 | @GetMapping(value = "/resources/{selector:.+}") 72 | public ReplicaSetsList getReplicaSetsListLabelSelector(@PathVariable("namespace") String namespace, @PathVariable("selector") String selectors ) { 73 | return replicaSetsService.getReplicaSetsListLabelSelector(namespace, selectors); 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/persistentVolumeClaims/PersistentVolumeClaimsController.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.persistentVolumeClaims; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import java.util.HashMap; 10 | 11 | /** 12 | * PersistentVolumeClaims Controller 클래스 13 | * 14 | * @author hrjin 15 | * @version 1.0 16 | * @since 2019-10-24 17 | */ 18 | @RestController 19 | @RequestMapping("/namespaces/{namespace:.+}/persistentVolumeClaims") 20 | public class PersistentVolumeClaimsController { 21 | private final PersistentVolumeClaimsService persistentVolumeClaimsService; 22 | 23 | /** 24 | * Instantiates a new persistentVolumeClaims controller. 25 | * 26 | * @param persistentVolumeClaimsService the persistentVolumeClaims service 27 | */ 28 | @Autowired 29 | public PersistentVolumeClaimsController(PersistentVolumeClaimsService persistentVolumeClaimsService) { 30 | this.persistentVolumeClaimsService = persistentVolumeClaimsService; 31 | } 32 | 33 | /** 34 | * PersistentVolumeClaims 목록을 조회한다. 35 | * 36 | * @param namespace the namespace 37 | * @return the PersistentVolumeClaims List 38 | */ 39 | @GetMapping 40 | public PersistentVolumeClaimsList getPersistentVolumeClaimsList(@PathVariable(value = "namespace") String namespace) { 41 | return persistentVolumeClaimsService.getPersistentVolumeClaimsList(namespace); 42 | } 43 | 44 | /** 45 | * PersistentVolumeClaims 상세 정보를 조회한다. 46 | * 47 | * @param namespace the namespace 48 | * @param persistentVolumeClaimName the PersistentVolumeClaims 49 | * @return the PersistentVolumeClaims 50 | */ 51 | @GetMapping(value = "/{persistentVolumeClaimName:.+}") 52 | public PersistentVolumeClaims getPersistentVolumeClaims(@PathVariable(value = "namespace") String namespace, @PathVariable(value = "persistentVolumeClaimName") String persistentVolumeClaimName) { 53 | return persistentVolumeClaimsService.getPersistentVolumeClaims(namespace, persistentVolumeClaimName); 54 | } 55 | 56 | /** 57 | * PersistentVolumeClaims YAML 을 조회한다. 58 | * 59 | * @param namespace the namespace 60 | * @param persistentVolumeClaimName the PersistentVolumeClaims 61 | * @return the PersistentVolumeClaims 62 | */ 63 | @GetMapping(value = "/{persistentVolumeClaimName:.+}/yaml") 64 | public PersistentVolumeClaims getPersistentVolumeClaimsYaml(@PathVariable(value = "namespace") String namespace, @PathVariable(value = "persistentVolumeClaimName") String persistentVolumeClaimName) { 65 | return persistentVolumeClaimsService.getPersistentVolumeClaimsYaml(namespace, persistentVolumeClaimName, new HashMap<>()); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/AspectService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common; 2 | 3 | import org.aspectj.lang.JoinPoint; 4 | import org.aspectj.lang.annotation.Aspect; 5 | import org.aspectj.lang.annotation.Before; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.stereotype.Service; 9 | import org.springframework.web.context.request.RequestContextHolder; 10 | import org.springframework.web.context.request.ServletRequestAttributes; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import java.util.Arrays; 14 | import java.util.Enumeration; 15 | import java.util.Objects; 16 | 17 | /** 18 | * Aspect Service 클래스 19 | * 20 | * @author REX 21 | * @version 1.0 22 | * @since 2018.08.06 23 | */ 24 | @Aspect 25 | @Service 26 | public class AspectService { 27 | 28 | private static final Logger LOGGER = LoggerFactory.getLogger(AspectService.class); 29 | 30 | /** 31 | * On before log service access. 32 | * 33 | * @param joinPoint the join point 34 | */ 35 | @Before("execution(* org.paasta.caas..*Service.*(..))") 36 | public void onBeforeLogServiceAccess(JoinPoint joinPoint) { 37 | LOGGER.warn("######## ON BEFORE SERVICE ACCESS :: {}", joinPoint); 38 | } 39 | 40 | 41 | /** 42 | * On before log controller access. 43 | * 44 | * @param joinPoint the join point 45 | */ 46 | @Before("execution(* org.paasta.caas..*Controller.*(..))") 47 | public void onBeforeLogControllerAccess(JoinPoint joinPoint) { 48 | LOGGER.warn("#### API :: ON BEFORE CONTROLLER ACCESS :: {}", joinPoint); 49 | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); 50 | 51 | LOGGER.warn("## Entering in Method: {}", joinPoint.getSignature().getName()); 52 | LOGGER.warn("## Class Name: {}", joinPoint.getSignature().getDeclaringTypeName()); 53 | LOGGER.warn("## Arguments: {}", Arrays.toString(joinPoint.getArgs())); 54 | LOGGER.warn("## Target class: {}", joinPoint.getTarget().getClass().getName()); 55 | 56 | if (null != request) { 57 | LOGGER.warn("## Request Path info: {}", request.getServletPath()); 58 | LOGGER.warn("## Method Type: {}", request.getMethod()); 59 | LOGGER.warn("================================================================================"); 60 | LOGGER.warn("Start Header Section of request"); 61 | Enumeration headerNames = request.getHeaderNames(); 62 | while (headerNames.hasMoreElements()) { 63 | String headerName = (String) headerNames.nextElement(); 64 | String headerValue = request.getHeader(headerName); 65 | LOGGER.warn(" Header Name: {} || Header Value: {}", headerName, headerValue); 66 | } 67 | LOGGER.warn("End Header Section of request"); 68 | LOGGER.warn("================================================================================"); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/pods/PodsController.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.pods; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | /** 7 | * Pods Controller 클래스 8 | * 9 | * @author Hyungu Cho 10 | * @version 1.0 11 | * @since 2018.08.01 12 | */ 13 | @RestController 14 | @RequestMapping(value = "/namespaces/{namespace:.+}/pods") 15 | public class PodsController { 16 | private final PodsService podsService; 17 | 18 | /** 19 | * Instantiates a new Pods controller. 20 | * 21 | * @param podsService the pod service 22 | */ 23 | @Autowired 24 | public PodsController(PodsService podsService) { 25 | this.podsService = podsService; 26 | } 27 | 28 | /** 29 | * Pod 목록을 조회한다. 30 | * 31 | * @param namespace the namespace 32 | * @return the pod list 33 | */ 34 | @GetMapping 35 | @ResponseBody 36 | public PodsList getPodList(@PathVariable(value = "namespace") String namespace) { 37 | return podsService.getPodList(namespace); 38 | } 39 | 40 | /** 41 | * Selector를 이용해 Pod 목록을 조회한다. (특정 네임스페이스) 42 | * 43 | * @param namespace the namespace 44 | * @param selector the selector 45 | * @return the pod list 46 | */ 47 | @GetMapping(value = "/resources/{selector:.+}") 48 | @ResponseBody 49 | public PodsList getPodListBySelector(@PathVariable(value = "namespace") String namespace, 50 | @PathVariable(value = "selector") String selector) { 51 | return podsService.getPodListWithLabelSelector(namespace, selector); 52 | } 53 | 54 | /** 55 | * Node 이름을 이용해 Pod 목록를 조회한다. (특정 네임스페이스) 56 | * 57 | * @param namespace the namespace 58 | * @param nodeName the node name 59 | * @return the pod list 60 | */ 61 | @GetMapping(value = "/nodes/{nodeName:.+}") 62 | public PodsList getPodListByNode(@PathVariable(value = "namespace") String namespace, 63 | @PathVariable(value = "nodeName") String nodeName) { 64 | return podsService.getPodListByNode(namespace, nodeName); 65 | } 66 | 67 | /** 68 | * Pod를 조회한다. 69 | * 70 | * @param namespace the namespace 71 | * @param podName the pod's name 72 | * @return the pod 73 | */ 74 | @GetMapping(value = "/{podName:.+}") 75 | public Pods getPod(@PathVariable(value = "namespace") String namespace, 76 | @PathVariable(value = "podName") String podName) { 77 | return podsService.getPod(namespace, podName); 78 | } 79 | 80 | /** 81 | * Pod의 YAML을 조회한다. 82 | * 83 | * @param namespace the namespace 84 | * @param podName the pod's name 85 | * @return the pods 86 | */ 87 | @GetMapping(value = "/{podName:.+}/yaml") 88 | public Pods getPodYaml(@PathVariable(value = "namespace") String namespace, 89 | @PathVariable(value = "podName") String podName) { 90 | return podsService.getPodYaml(namespace, podName); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/events/EventsService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.events; 2 | 3 | import org.paasta.caas.api.common.CommonService; 4 | import org.paasta.caas.api.common.Constants; 5 | import org.paasta.caas.api.common.PropertyService; 6 | import org.paasta.caas.api.common.RestTemplateService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpMethod; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.HashMap; 12 | import java.util.LinkedList; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * Events Service 클래스 18 | * 19 | * @author CISS 20 | * @version 1.0 21 | * @since 2018.08.13 22 | */ 23 | @Service 24 | public class EventsService { 25 | 26 | private final RestTemplateService restTemplateService; 27 | private final CommonService commonService; 28 | private final PropertyService propertyService; 29 | 30 | /** 31 | * Instantiates a new Events service. 32 | * 33 | * @param restTemplateService the rest template service 34 | * @param commonService the common service 35 | * @param propertyService the property service 36 | */ 37 | @Autowired 38 | public EventsService(RestTemplateService restTemplateService, CommonService commonService, PropertyService propertyService) { 39 | this.restTemplateService = restTemplateService; 40 | this.commonService = commonService; 41 | this.propertyService = propertyService; 42 | } 43 | 44 | /** 45 | * Events 목록을 조회한다. 46 | * 47 | * @param namespace the namespace 48 | * @param resourceUid the resourceUid 49 | * @return the events list 50 | */ 51 | EventsList getEventsList(String namespace, String resourceUid, String type) { 52 | String requestSelector = "?fieldSelector=involvedObject.uid=" + resourceUid; 53 | 54 | if(type != null) { 55 | requestSelector = "?fieldSelector=involvedObject.name=" + resourceUid; 56 | } 57 | 58 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 59 | propertyService.getCaasMasterApiListEventsListUrl() 60 | .replace("{namespace}", namespace) + requestSelector, HttpMethod.GET, null, Map.class); 61 | 62 | return (EventsList) commonService.setResultModel( 63 | commonService.setResultObject(resultMap, EventsList.class), Constants.RESULT_STATUS_SUCCESS); 64 | } 65 | 66 | /** 67 | * Events 목록을 조회한다.(for namespace) 68 | * 69 | * @param namespace the namespace 70 | * @return the events list 71 | */ 72 | EventsList getNamespaceEventsList(String namespace) { 73 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 74 | propertyService.getCaasMasterApiListEventsListUrl() 75 | .replace("{namespace}", namespace), HttpMethod.GET, null, Map.class); 76 | 77 | return (EventsList) commonService.setResultModel( 78 | commonService.setResultObject(resultMap, EventsList.class), Constants.RESULT_STATUS_SUCCESS); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/roleBindings/RoleBindingsController.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.roleBindings; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | /** 7 | * RoleBinding Controller 클래스 8 | * 9 | * @author hrjin 10 | * @version 1.0 11 | * @since 2018-08-17 12 | */ 13 | @RestController 14 | @RequestMapping(value = "/namespaces/{namespace:.+}/roleBindings") 15 | public class RoleBindingsController { 16 | 17 | private final RoleBindingsService roleBindingService; 18 | 19 | /** 20 | * Instantiates a new RoleBinding controller 21 | * 22 | * @param roleBindingService the roleBinding service 23 | */ 24 | @Autowired 25 | public RoleBindingsController(RoleBindingsService roleBindingService) { 26 | this.roleBindingService = roleBindingService; 27 | } 28 | 29 | /** 30 | * RoleBindingList 객체의 리스트를 조회한다. 31 | * 32 | * @param namespace the namespace 33 | * @return the RoleBindingsList 34 | */ 35 | @GetMapping 36 | public RoleBindingsList getRoleBindingList(@PathVariable("namespace") String namespace){ 37 | return roleBindingService.getRoleBindingList(namespace); 38 | } 39 | 40 | /** 41 | * RoleBinding 객체를 조회한다. 42 | * 43 | * @param namespace the namespace 44 | * @param roleBindingName the roleBindingName 45 | * @return the RoleBindings 46 | */ 47 | @GetMapping(value = "/{roleBindingName:.+}") 48 | public RoleBindings getRoleBinding(@PathVariable("namespace") String namespace, @PathVariable("roleBindingName") String roleBindingName){ 49 | return roleBindingService.getRoleBinding(namespace, roleBindingName); 50 | } 51 | 52 | /** 53 | * RoleBinding 권한을 할당한다. 54 | * 55 | * @param namespace the namespace 56 | * @param roleBinding the roleBinding 57 | * @return the roleBindings 58 | */ 59 | @PostMapping 60 | public RoleBindings createRoleBinding(@PathVariable("namespace") String namespace, @RequestBody RoleBindings roleBinding){ 61 | return roleBindingService.createRoleBinding(namespace, roleBinding); 62 | } 63 | 64 | /** 65 | * RoleBinding 권한을 해지한다. 66 | * 67 | * @param namespace the namespace 68 | * @param roleBindingName the roleBindingName 69 | * @return String 70 | */ 71 | @DeleteMapping(value = "/{roleBindingName:.+}") 72 | public String deleteRoleBinding(@PathVariable("namespace") String namespace, @PathVariable("roleBindingName") String roleBindingName){ 73 | return roleBindingService.deleteRoleBinding(namespace, roleBindingName); 74 | } 75 | 76 | /** 77 | * RoleBinding 권한을 변경한다. 78 | * 79 | * @param namespace the namespace 80 | * @param roleBindingName the roleBindingName 81 | * @param yml the yml 82 | * @return String 83 | */ 84 | @PutMapping(value = "/{roleBindingName:.+}") 85 | public String updateRoleBinding(@PathVariable("namespace") String namespace, @PathVariable("roleBindingName") String roleBindingName, @RequestBody String yml){ 86 | return roleBindingService.updateRoleBinding(namespace, roleBindingName, yml); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/clusters/namespaces/NamespacesService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.clusters.namespaces; 2 | 3 | import org.paasta.caas.api.common.CommonService; 4 | import org.paasta.caas.api.common.Constants; 5 | import org.paasta.caas.api.common.PropertyService; 6 | import org.paasta.caas.api.common.RestTemplateService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpMethod; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * Namespaces Service 클래스. 16 | * 17 | * @author indra 18 | * @version 1.0 19 | * @since 2018.8.01 최초작성 20 | */ 21 | @Service 22 | public class NamespacesService { 23 | 24 | private final RestTemplateService restTemplateService; 25 | private final CommonService commonService; 26 | private final PropertyService propertyService; 27 | 28 | /** 29 | * Instantiates a new Namespace service. 30 | * 31 | * @param restTemplateService the rest template service 32 | * @param commonService the common service 33 | * @param propertyService the property service 34 | */ 35 | @Autowired 36 | public NamespacesService(RestTemplateService restTemplateService, CommonService commonService, PropertyService propertyService) { 37 | this.restTemplateService = restTemplateService; 38 | this.commonService = commonService; 39 | this.propertyService = propertyService; 40 | } 41 | 42 | /** 43 | * Namespaces 상세정보를 조회한다. 44 | * 45 | * @param namespace the namespaces 46 | * @return Namespaces the namespaces 47 | */ 48 | Namespaces getNamespaces(String namespace) { 49 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 50 | propertyService.getCaasMasterApiListNamespaceGetUrl() 51 | .replace("{namespace}", namespace), HttpMethod.GET, null, Map.class); 52 | 53 | return (Namespaces) commonService.setResultModel(commonService.setResultObject(resultMap, Namespaces.class), Constants.RESULT_STATUS_SUCCESS); 54 | } 55 | 56 | /** 57 | * ResourceQuota 목록을 조회한다. 58 | * 59 | * @param namespace the namespaces 60 | * @return ResourceQuotaList the ResourceQuotaList 61 | */ 62 | ResourceQuotaList getResourceQuotaList(String namespace) { 63 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 64 | propertyService.getCaasMasterApiListResourceQuotasListUrl() 65 | .replace("{namespace}", namespace), HttpMethod.GET, null, Map.class); 66 | 67 | return (ResourceQuotaList) commonService.setResultModel(commonService.setResultObject(resultMap, ResourceQuotaList.class), Constants.RESULT_STATUS_SUCCESS); 68 | } 69 | 70 | 71 | /** 72 | * NameSpace를 생성한다. 73 | * 74 | * @param namespace the namespaces 75 | * @return ResourceQuotaList the ResourceQuotaList 76 | */ 77 | Map createNamespaces(Object namespace){ 78 | return (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 79 | propertyService.getCaasMasterApiListNamespaceCreateUrl(), HttpMethod.POST, namespace, Map.class); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/deployments/DeploymentsController.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.deployments; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * Deployments Controller 클래스 11 | * 12 | * @author PHR 13 | * @version 1.0 14 | * @since 2018.08.13 15 | */ 16 | @RestController 17 | @RequestMapping("/namespaces/{namespace:.+}/deployments") 18 | public class DeploymentsController { 19 | 20 | private final DeploymentsService deploymentsService; 21 | 22 | /** 23 | * Instantiates a new deployments controller. 24 | * 25 | * @param deploymentsService the deployments service 26 | */ 27 | @Autowired 28 | public DeploymentsController(DeploymentsService deploymentsService) { 29 | this.deploymentsService = deploymentsService; 30 | } 31 | 32 | /** 33 | * Deployments 목록을 조회한다. 34 | * 35 | * @param namespace the namespace 36 | * @return the deployments list 37 | */ 38 | @GetMapping 39 | public DeploymentsList getDeploymentsList(@PathVariable(value = "namespace") String namespace) { 40 | return deploymentsService.getDeploymentsList(namespace); 41 | } 42 | 43 | /** 44 | * Deployments 상세정보를 조회한다. 45 | * 46 | * @param namespace the namespace 47 | * @param deploymentName the deploymentName name 48 | * @return the deployments 49 | */ 50 | @GetMapping(value = "/{deploymentName:.+}") 51 | public Deployments getDeployments(@PathVariable(value = "namespace") String namespace, @PathVariable(value = "deploymentName") String deploymentName) { 52 | return deploymentsService.getDeployments(namespace, deploymentName); 53 | } 54 | 55 | /** 56 | * Deployments YAML을 조회한다. 57 | * 58 | * @param namespace the namespace 59 | * @param deploymentName the deploymentName name 60 | * @return the deployments yaml 61 | */ 62 | @GetMapping(value = "/{deploymentName:.+}/yaml") 63 | public Deployments getDeploymentsYaml(@PathVariable(value = "namespace") String namespace, @PathVariable(value = "deploymentName") String deploymentName) { 64 | return deploymentsService.getDeploymentsYaml(namespace, deploymentName, new HashMap<>()); 65 | } 66 | 67 | /** 68 | * Deployments를 생성한다. 69 | * 70 | * @param namespace the namespace 71 | * @param deployment the Deployments 72 | * @return the deployments yaml 73 | */ 74 | @PostMapping 75 | public Map createDeploymentsYaml(@PathVariable(value = "namespace") String namespace, @RequestBody Object deployment) { 76 | return deploymentsService.createDeploymentsYaml(namespace, deployment, new HashMap<>()); 77 | } 78 | 79 | /** 80 | * Deployments를 삭제한다. 81 | * 82 | * @param namespace the namespace 83 | * @param name the Deployments name 84 | * @return the deployments yaml 85 | */ 86 | @DeleteMapping("/{name}") 87 | public Map deleteDeploymentsYaml(@PathVariable(value = "namespace") String namespace, @PathVariable(value = "name") String name) { 88 | return deploymentsService.deleteDeploymentsYaml(namespace, name, new HashMap<>()); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/customServices/CustomServicesController.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.customServices; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * Custom Services Controller 클래스 11 | * 12 | * @author REX 13 | * @version 1.0 14 | * @since 2018.08.09 15 | */ 16 | @RestController 17 | @RequestMapping("/namespaces/{namespace:.+}/services") 18 | public class CustomServicesController { 19 | 20 | private final CustomServicesService customServicesService; 21 | 22 | /** 23 | * Instantiates a new Custom services controller. 24 | * 25 | * @param customServicesService the custom services service 26 | */ 27 | @Autowired 28 | public CustomServicesController(CustomServicesService customServicesService) {this.customServicesService = customServicesService;} 29 | 30 | 31 | /** 32 | * Services 목록을 조회한다. 33 | * 34 | * @param namespace the namespace 35 | * @return the custom services list 36 | */ 37 | @GetMapping 38 | public CustomServicesList getCustomServicesList(@PathVariable(value = "namespace") String namespace) { 39 | return customServicesService.getCustomServicesList(namespace); 40 | } 41 | 42 | 43 | /** 44 | * Services 상세 정보를 조회한다. 45 | * 46 | * @param namespace the namespace 47 | * @param serviceName the service name 48 | * @return the custom services 49 | */ 50 | @GetMapping(value = "/{serviceName:.+}") 51 | public CustomServices getCustomServices(@PathVariable(value = "namespace") String namespace, @PathVariable(value = "serviceName") String serviceName) { 52 | return customServicesService.getCustomServices(namespace, serviceName); 53 | } 54 | 55 | 56 | /** 57 | * Services YAML을 조회한다. 58 | * 59 | * @param namespace the namespace 60 | * @param serviceName the service name 61 | * @return the custom services yaml 62 | */ 63 | @GetMapping(value = "/{serviceName:.+}/yaml") 64 | public CustomServices getCustomServicesYaml(@PathVariable(value = "namespace") String namespace, @PathVariable(value = "serviceName") String serviceName) { 65 | return customServicesService.getCustomServicesYaml(namespace, serviceName, new HashMap<>()); 66 | } 67 | 68 | 69 | /** 70 | * Services를 생성한다. 71 | * 72 | * @param namespace the namespace 73 | * @param services the Services 74 | * @return return is succeeded 75 | */ 76 | @PostMapping 77 | public Map createServicesYaml(@PathVariable(value = "namespace") String namespace, @RequestBody Object services) { 78 | return customServicesService.createServicesYaml(namespace, services, new HashMap<>()); 79 | } 80 | 81 | 82 | /** 83 | * Services를 제거한다. 84 | * 85 | * @param namespace the namespace 86 | * @param name the Services name 87 | * @return return is succeeded 88 | */ 89 | @DeleteMapping("/{name}") 90 | public Map deleteServicesYaml(@PathVariable(value = "namespace") String namespace, @PathVariable(value = "name") String name) { 91 | return customServicesService.deleteServicesYaml(namespace, name, new HashMap<>()); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/accessInfo/AccessTokenService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.accessInfo; 2 | 3 | import org.paasta.caas.api.common.CommonService; 4 | import org.paasta.caas.api.common.Constants; 5 | import org.paasta.caas.api.common.PropertyService; 6 | import org.paasta.caas.api.common.RestTemplateService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpMethod; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | 13 | import java.util.Base64; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | /** 18 | * AccessToken Service 클래스 19 | * 20 | * @author hrjin 21 | * @version 1.0 22 | * @since 2018-09-04 23 | */ 24 | @Service 25 | public class AccessTokenService { 26 | private final RestTemplateService restTemplateService; 27 | private final PropertyService propertyService; 28 | private final CommonService commonService; 29 | 30 | /** 31 | * Instantiates a new accessToken service 32 | * @param restTemplateService the rest template service 33 | * @param propertyService the property service 34 | * @param commonService the common service 35 | */ 36 | @Autowired 37 | public AccessTokenService(RestTemplateService restTemplateService, PropertyService propertyService, CommonService commonService) { 38 | this.restTemplateService = restTemplateService; 39 | this.propertyService = propertyService; 40 | this.commonService = commonService; 41 | } 42 | 43 | /** 44 | * Secret 에서 cluster certification token 과 user token 을 조회한다. 45 | * 46 | * @param namespace the namespace 47 | * @param accessTokenName the accessTokenName 48 | * @return the AccessToken 49 | */ 50 | AccessToken getSecret(String namespace, String accessTokenName) { 51 | String caCertToken; 52 | String userToken; 53 | 54 | HashMap responseMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 55 | propertyService.getCaasMasterApiListSecretsGetUrl() 56 | .replace("{namespace}", namespace) 57 | .replace("{name}", accessTokenName), HttpMethod.GET, null, Map.class); 58 | 59 | Map map = (Map) responseMap.get("data"); 60 | 61 | caCertToken = map.get("ca.crt").toString(); 62 | userToken = map.get("token").toString(); 63 | 64 | Base64.Decoder decoder = Base64.getDecoder(); 65 | String caCertDecodeToken = new String(decoder.decode(caCertToken)); 66 | String userDecodeToken = new String(decoder.decode(userToken)); 67 | 68 | AccessToken accessToken = new AccessToken(); 69 | accessToken.setCaCertToken(caCertDecodeToken); 70 | accessToken.setUserAccessToken(userDecodeToken); 71 | 72 | return (AccessToken) commonService.setResultModel(accessToken, Constants.RESULT_STATUS_SUCCESS); 73 | } 74 | 75 | 76 | public Map createSecret(String namespace, Object secret){ 77 | return (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 78 | propertyService.getCaasMasterApiListSecretsCreateUrl() 79 | .replace("{namespace}", namespace), HttpMethod.POST, secret, Map.class); 80 | 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/authenticate/AuthenticateService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.authenticate; 2 | 3 | import org.paasta.caas.api.common.Constants; 4 | import org.paasta.caas.api.common.PropertyService; 5 | import org.paasta.caas.api.common.RestTemplateService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.HttpMethod; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.Map; 11 | 12 | /** 13 | * Authenticate Service 클래스. 14 | * 15 | * @author indra 16 | * @version 1.0 17 | * @since 2018.09.05 최초작성 18 | */ 19 | @Service 20 | public class AuthenticateService { 21 | 22 | private final RestTemplateService restTemplateService; 23 | private final PropertyService propertyService; 24 | 25 | /** 26 | * Instantiates a Authenticate service. 27 | * 28 | * @param restTemplateService the rest template service 29 | * @param propertyService the property service 30 | */ 31 | @Autowired 32 | public AuthenticateService(RestTemplateService restTemplateService, PropertyService propertyService) { 33 | this.restTemplateService = restTemplateService; 34 | this.propertyService = propertyService; 35 | } 36 | 37 | /** 38 | * 유저를 생성한다. 39 | * 40 | * @param namespace the namespace 41 | * @param yml the yml 42 | */ 43 | void createUser(String namespace, String yml) { 44 | restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 45 | propertyService.getCaasMasterApiListUsersCreateUrl() 46 | .replace("{namespace}", namespace), HttpMethod.POST, yml, Map.class, "application/json,application/yaml,text/html", "application/yaml;charset=UTF-8"); 47 | } 48 | 49 | /** 50 | * 롤을 생성한다. 51 | * 52 | * @param namespace the namespace 53 | * @param yml the yml 54 | */ 55 | void createRole(String namespace, String yml) { 56 | restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 57 | propertyService.getCaasMasterApiListRolesCreateUrl() 58 | .replace("{namespace}", namespace), HttpMethod.POST, yml, Map.class, "application/json,application/yaml,text/html", "application/yaml;charset=UTF-8"); 59 | } 60 | 61 | /** 62 | * 롤을 바인딩한다. 63 | * 64 | * @param namespace the namespace 65 | * @param yml the yml 66 | */ 67 | void createRoleBinding(String namespace, String yml) { 68 | restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 69 | propertyService.getCaasMasterApiListRoleBindingsCreateUrl() 70 | .replace("{namespace}", namespace), HttpMethod.POST, yml, Map.class, "application/json,application/yaml,text/html", "application/yaml;charset=UTF-8"); 71 | } 72 | 73 | /** 74 | * 토큰을 조회한다. 75 | * 76 | * @param namespace the namespace 77 | * @param userName the user name 78 | * @return the String 79 | */ 80 | String getToken(String namespace, String userName) { 81 | return restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 82 | propertyService.getCaasMasterApiListUsersGetUrl() 83 | .replace("{namespace}", namespace) 84 | .replace("{name}", userName), HttpMethod.GET, null, String.class, "application/json,application/yaml,text/html", "application/yaml;charset=UTF-8"); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/config/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.security.authentication.AuthenticationManager; 8 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 9 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 10 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 11 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 12 | import org.springframework.security.config.http.SessionCreationPolicy; 13 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 14 | import org.springframework.web.cors.CorsConfiguration; 15 | import org.springframework.web.cors.CorsConfigurationSource; 16 | 17 | import javax.servlet.http.HttpServletRequest; 18 | import java.util.Collections; 19 | 20 | /** 21 | * Spring Security WebSecurityConfigurer implements 22 | * 23 | * @author ciss 24 | * @version 1.0 25 | * @since 2018.11.14 26 | */ 27 | 28 | @Configuration 29 | @EnableWebSecurity 30 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 31 | 32 | @Value("${spring.security.username}") 33 | String username; 34 | 35 | @Value("${spring.security.password}") 36 | String password; 37 | 38 | @Bean 39 | public BCryptPasswordEncoder passwordEncoder() { 40 | return new BCryptPasswordEncoder(); 41 | } 42 | 43 | @Autowired 44 | protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 45 | auth 46 | .inMemoryAuthentication() 47 | .withUser(username) 48 | .password(passwordEncoder().encode(password)) 49 | .roles("USER"); 50 | } 51 | 52 | @Bean 53 | @Override 54 | public AuthenticationManager authenticationManagerBean() throws Exception { 55 | return super.authenticationManagerBean(); 56 | } 57 | 58 | @Override 59 | protected void configure(HttpSecurity http) throws Exception { 60 | http 61 | .csrf().disable() 62 | .sessionManagement() 63 | .sessionCreationPolicy(SessionCreationPolicy.STATELESS) 64 | .and() 65 | .authorizeRequests() 66 | .antMatchers("/**").hasRole("USER") 67 | .anyRequest().authenticated() 68 | .and() 69 | .httpBasic() 70 | .and() 71 | .cors().configurationSource(corsConfiguration()); 72 | 73 | } 74 | 75 | private CorsConfigurationSource corsConfiguration(){ 76 | return new CorsConfigurationSource() { 77 | @Override 78 | public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { 79 | CorsConfiguration config = new CorsConfiguration(); 80 | config.setAllowedHeaders(Collections.singletonList("*")); 81 | config.setAllowedMethods(Collections.singletonList("*")); 82 | config.addAllowedOrigin("*"); 83 | config.setAllowCredentials(true); 84 | return config; 85 | } 86 | }; 87 | } 88 | 89 | } -------------------------------------------------------------------------------- /src/test/java/org/paasta/caas/api/authenticate/AuthenticateServiceTest.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.authenticate; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.mockito.InjectMocks; 7 | import org.mockito.Mock; 8 | import org.paasta.caas.api.common.Constants; 9 | import org.paasta.caas.api.common.PropertyService; 10 | import org.paasta.caas.api.common.RestTemplateService; 11 | import org.springframework.http.HttpMethod; 12 | import org.springframework.test.context.TestPropertySource; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | import static org.mockito.Mockito.*; 20 | 21 | @RunWith(SpringRunner.class) 22 | @TestPropertySource("classpath:application.yml") 23 | public class AuthenticateServiceTest { 24 | 25 | private static final String NAMESPACE = "test-namespace"; 26 | private static final String USER_NAME = "test-userName"; 27 | private static final String YML = "test-yml"; 28 | private static final String ACCEPT_TYPE = "test-acceptType"; 29 | private static final String CONTENT_TYPE = "test-contentType"; 30 | private static final String GET_URL = "test-get-url"; 31 | 32 | private static HashMap resultMap = null; 33 | private static String resultString = ""; 34 | 35 | @Mock 36 | RestTemplateService restTemplateService; 37 | @Mock 38 | PropertyService propertyService; 39 | @InjectMocks 40 | AuthenticateService authenticateService; 41 | 42 | @Before 43 | public void setUp() { 44 | resultMap = new HashMap(); 45 | } 46 | 47 | @Test 48 | public void testCreateUser() { 49 | when(propertyService.getCaasMasterApiListUsersCreateUrl()).thenReturn(GET_URL); 50 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, GET_URL 51 | .replace("{namespace}", NAMESPACE), HttpMethod.POST, YML, Map.class, ACCEPT_TYPE, CONTENT_TYPE)).thenReturn(resultMap); 52 | 53 | authenticateService.createUser(NAMESPACE, YML); 54 | } 55 | 56 | @Test 57 | public void testCreateRole() { 58 | when(propertyService.getCaasMasterApiListRolesCreateUrl()).thenReturn(GET_URL); 59 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, GET_URL 60 | .replace("{namespace}", NAMESPACE), HttpMethod.POST, YML, Map.class, ACCEPT_TYPE, CONTENT_TYPE)).thenReturn(resultMap); 61 | 62 | authenticateService.createRole(NAMESPACE, YML); 63 | } 64 | 65 | @Test 66 | public void testCreateRoleBinding() { 67 | when(propertyService.getCaasMasterApiListRoleBindingsCreateUrl()).thenReturn(GET_URL); 68 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, GET_URL 69 | .replace("{namespace}", NAMESPACE), HttpMethod.POST, YML, Map.class, ACCEPT_TYPE, CONTENT_TYPE)).thenReturn(resultMap); 70 | 71 | authenticateService.createRoleBinding(NAMESPACE, YML); 72 | } 73 | 74 | @Test 75 | public void testGetToken() { 76 | when(propertyService.getCaasMasterApiListUsersGetUrl()).thenReturn(GET_URL); 77 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, GET_URL 78 | .replace("{namespace}", NAMESPACE) 79 | .replace("{name}", USER_NAME), HttpMethod.GET, null, String.class, ACCEPT_TYPE, CONTENT_TYPE)).thenReturn(resultString); 80 | 81 | String result = authenticateService.getToken(NAMESPACE, YML); 82 | 83 | assertEquals(null, result); 84 | } 85 | } -------------------------------------------------------------------------------- /src/test/java/org/paasta/caas/api/accessInfo/AccessTokenServiceTest.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.accessInfo; 2 | 3 | import org.junit.After; 4 | import org.junit.Before; 5 | import org.junit.FixMethodOrder; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.junit.runners.MethodSorters; 9 | import org.mockito.InjectMocks; 10 | import org.mockito.Mock; 11 | import org.paasta.caas.api.common.CommonService; 12 | import org.paasta.caas.api.common.Constants; 13 | import org.paasta.caas.api.common.PropertyService; 14 | import org.paasta.caas.api.common.RestTemplateService; 15 | import org.springframework.boot.test.context.SpringBootTest; 16 | import org.springframework.http.HttpMethod; 17 | import org.springframework.test.context.TestPropertySource; 18 | import org.springframework.test.context.junit4.SpringRunner; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | import static org.assertj.core.api.Assertions.assertThat; 24 | import static org.junit.Assert.assertEquals; 25 | import static org.mockito.Mockito.when; 26 | 27 | @RunWith(SpringRunner.class) 28 | @TestPropertySource("classpath:application.yml") 29 | 30 | public class AccessTokenServiceTest { 31 | private static final String NAMESPACE = "test-namespace"; 32 | private static final String GET_URL = "test-get-url"; 33 | private static final String ACCESS_TOKEN_NAME = "test-access-token-name"; 34 | private static final String ENCODE_TOKEN = "YWNjZXNzVG9rZW4="; 35 | private static final String DECODE_TOKEN = "accessToken"; 36 | 37 | private static final String ENCODE_CERT_TOKEN = "Y2VydEFjY2Vzc1Rva2Vu"; 38 | private static final String DECODE_CERT_TOKEN = "certAccessToken"; 39 | 40 | private static HashMap gResultMap = null; 41 | private static HashMap gResultDataMap = null; 42 | 43 | private static AccessToken gResultModel = null; 44 | private static AccessToken gFinalResultModel = null; 45 | 46 | @Mock 47 | private RestTemplateService restTemplateService; 48 | 49 | @Mock 50 | private PropertyService propertyService; 51 | 52 | @Mock 53 | private CommonService commonService; 54 | 55 | @InjectMocks 56 | AccessTokenService accessTokenService; 57 | 58 | @Before 59 | public void setUp() { 60 | 61 | gResultMap = new HashMap(); 62 | gResultDataMap = new HashMap<>(); 63 | gResultDataMap.put("token", ENCODE_TOKEN); 64 | gResultDataMap.put("ca.crt", ENCODE_CERT_TOKEN); 65 | gResultMap.put("data", gResultDataMap); 66 | 67 | gResultModel = new AccessToken(); 68 | gFinalResultModel = new AccessToken(); 69 | gFinalResultModel.setResultCode(Constants.RESULT_STATUS_SUCCESS); 70 | 71 | } 72 | 73 | @After 74 | public void tearDown() { 75 | } 76 | 77 | @Test 78 | public void getSecret_Valid_ReturnModel() { 79 | 80 | String token = "accessToken"; 81 | // CONDITION 82 | when(propertyService.getCaasMasterApiListSecretsGetUrl()).thenReturn(GET_URL); 83 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, GET_URL 84 | .replace("{namespace}", NAMESPACE) 85 | .replace("{accessTokenName}", ACCESS_TOKEN_NAME), HttpMethod.GET, null, Map.class)).thenReturn(gResultMap); 86 | gResultModel.setCaCertToken(DECODE_CERT_TOKEN); 87 | gResultModel.setUserAccessToken(DECODE_TOKEN); 88 | when(commonService.setResultModel(gResultModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultModel); 89 | 90 | // TEST 91 | AccessToken resultModel = accessTokenService.getSecret(NAMESPACE, ACCESS_TOKEN_NAME); 92 | 93 | // VERIFY 94 | assertThat(resultModel).isNotNull(); 95 | assertEquals(Constants.RESULT_STATUS_SUCCESS, resultModel.getResultCode()); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/test/java/org/paasta/caas/api/roles/RolesServiceTest.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.roles; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.mockito.InjectMocks; 7 | import org.mockito.Mock; 8 | import org.paasta.caas.api.common.CommonService; 9 | import org.paasta.caas.api.common.Constants; 10 | import org.paasta.caas.api.common.PropertyService; 11 | import org.paasta.caas.api.common.RestTemplateService; 12 | import org.springframework.http.HttpMethod; 13 | import org.springframework.test.context.TestPropertySource; 14 | import org.springframework.test.context.junit4.SpringRunner; 15 | 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | import static org.junit.Assert.assertEquals; 21 | import static org.mockito.Mockito.when; 22 | 23 | @RunWith(SpringRunner.class) 24 | @TestPropertySource("classpath:application.yml") 25 | public class RolesServiceTest { 26 | 27 | private static final String TEST_URL = "test-url"; 28 | private static final String NAMESPACE = "test-namespace"; 29 | private static final String ROLE_NAME = "test-role-name"; 30 | private static final String TEST_YML = "test-yml"; 31 | private static HashMap gResultMap = null; 32 | 33 | @Mock 34 | RestTemplateService restTemplateService; 35 | 36 | @Mock 37 | CommonService commonService; 38 | 39 | @Mock 40 | PropertyService propertyService; 41 | 42 | @InjectMocks 43 | RolesService rolesService; 44 | 45 | @Before 46 | public void setUp() { 47 | 48 | gResultMap = new HashMap(); 49 | } 50 | 51 | @Test 52 | public void deleteRole_Valid_ReturnModel() { 53 | 54 | when(propertyService.getCaasMasterApiListRolesDeleteUrl()).thenReturn(TEST_URL); 55 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, TEST_URL, HttpMethod.DELETE, null, Map.class)).thenReturn(gResultMap); 56 | String resultStr = rolesService.deleteRole(NAMESPACE, ROLE_NAME); 57 | 58 | assertThat(resultStr).isNotNull(); 59 | assertEquals(resultStr, Constants.RESULT_STATUS_SUCCESS); 60 | } 61 | 62 | @Test 63 | public void deleteRole_FAIL_ReturnModel() { 64 | 65 | when(propertyService.getCaasMasterApiListRolesDeleteUrl()).thenReturn(TEST_URL); 66 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, TEST_URL, HttpMethod.DELETE, null, Map.class)).thenReturn(null); 67 | String resultStr = rolesService.deleteRole(NAMESPACE, ROLE_NAME); 68 | 69 | assertThat(resultStr).isNotNull(); 70 | assertEquals(resultStr, Constants.RESULT_STATUS_FAIL); 71 | } 72 | 73 | @Test 74 | public void updateRole_Valid_ReturnModel() { 75 | when(propertyService.getCaasMasterApiListRolesUpdateUrl()).thenReturn(TEST_URL); 76 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, TEST_URL, HttpMethod.PUT, TEST_YML, String.class, Constants.ACCEPT_TYPE_YAML, Constants.ACCEPT_TYPE_YAML)).thenReturn("result"); 77 | String resultStr = rolesService.updateRole(NAMESPACE, ROLE_NAME, TEST_YML); 78 | 79 | assertThat(resultStr).isNotNull(); 80 | assertEquals(resultStr, Constants.RESULT_STATUS_SUCCESS); 81 | } 82 | 83 | @Test 84 | public void updateRole_Fail_ReturnModel() { 85 | when(propertyService.getCaasMasterApiListRolesUpdateUrl()).thenReturn(TEST_URL); 86 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, TEST_URL, HttpMethod.PUT, TEST_YML, String.class, Constants.ACCEPT_TYPE_YAML, Constants.ACCEPT_TYPE_YAML)).thenReturn(null); 87 | String resultStr = rolesService.updateRole(NAMESPACE, ROLE_NAME, TEST_YML); 88 | 89 | assertThat(resultStr).isNotNull(); 90 | assertEquals(resultStr, Constants.RESULT_STATUS_FAIL); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | application: 4 | name: caas-api 5 | security: 6 | username: admin 7 | password: PaaS-TA 8 | 9 | project: 10 | name: caas-api 11 | artifactId: caas-api 12 | description: caas-api management service 13 | 14 | management: 15 | security: 16 | #Actuator endpoint(health,info..)의 인증여부 17 | enabled: false 18 | 19 | caasMaster: 20 | api: 21 | token: TEST-ONLY-DUMMY-TOKEN 22 | url: TEST-ONLY.DUMMY.COM:6443 23 | list: 24 | services: 25 | list: "/api/v1/namespaces/{namespace}/services" 26 | get: "/api/v1/namespaces/{namespace}/services/{name}" 27 | create: "/api/v1/namespaces/{namespace}/services" 28 | delete: "/api/v1/namespaces/{namespace}/services/{name}" 29 | endpoints: 30 | list: "/api/v1/namespaces/{namespace}/endpoints" 31 | get: "/api/v1/namespaces/{namespace}/endpoints/{name}" 32 | pods: 33 | list: "/api/v1/namespaces/{namespace}/pods" 34 | get: "/api/v1/namespaces/{namespace}/pods/{name}" 35 | nodes: 36 | list: "/api/v1/nodes" 37 | get: "/api/v1/nodes/{name}" 38 | replicaSets: 39 | list: "/apis/apps/v1/namespaces/{namespace}/replicasets" 40 | get: "/apis/apps/v1/namespaces/{namespace}/replicasets/{name}" 41 | persistentvolumes: 42 | list: "/api/v1/persistentvolumes" 43 | get: "/api/v1/persistentvolumes/{name}" 44 | persistentVolumeClaims: 45 | list: "/api/v1/namespaces/{namespace}/persistentvolumeclaims" 46 | get: "/api/v1/namespaces/{namespace}/persistentvolumeclaims/{name}" 47 | events: 48 | list: "/api/v1/namespaces/{namespace}/events" 49 | roles: 50 | list: "/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/roles" 51 | get: "/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/roles/{name}" 52 | create: "/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/roles" 53 | delete: "/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/roles/{name}" 54 | update: "/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/roles/{name}" 55 | deployments: 56 | list: "/apis/apps/v1/namespaces/{namespace}/deployments" 57 | get: "/apis/apps/v1/namespaces/{namespace}/deployments/{name}" 58 | create: "/apis/apps/v1/namespaces/{namespace}/deployments" 59 | delete: "/apis/apps/v1/namespaces/{namespace}/deployments/{name}" 60 | roleBindings: 61 | list: "/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/rolebindings" 62 | get: "/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/rolebindings/{name}" 63 | create: "/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/rolebindings" 64 | delete: "/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/rolebindings/{name}" 65 | update: "/apis/rbac.authorization.k8s.io/v1/namespaces/{namespace}/rolebindings/{name}" 66 | users: 67 | get: "/api/v1/namespaces/{namespace}/serviceaccounts/{name}" 68 | create: "/api/v1/namespaces/{namespace}/serviceaccounts" 69 | delete: "/api/v1/namespaces/{namespace}/serviceaccounts/{name}" 70 | namespaces: 71 | get: "/api/v1/namespaces/{namespace}" 72 | create: "/api/v1/namespaces" 73 | resourceQuotas: 74 | list: "/api/v1/namespaces/{namespace}/resourcequotas" 75 | secrets: 76 | get: "/api/v1/namespaces/{namespace}/secrets/{name}" 77 | create: "/api/v1/namespaces/{namespace}/secrets" 78 | 79 | --- 80 | spring: 81 | profiles: 82 | active: local 83 | 84 | logging: 85 | level: 86 | ROOT: INFO 87 | path: classpath:logback-spring.xml 88 | file: logs/application.log 89 | 90 | server: 91 | port: ${PORT:3333} 92 | 93 | commonApi: 94 | url: http://localhost:3334 95 | authorization: 96 | id: admin 97 | password: PaaS-TA 98 | 99 | --- 100 | spring: 101 | profiles: dev 102 | 103 | logging: 104 | level: 105 | ROOT: INFO 106 | path: classpath:logback-spring.xml 107 | file: logs/application.log 108 | 109 | server: 110 | port: ${PORT:3333} 111 | 112 | commonApi: 113 | url: http://localhost:3334 114 | authorization: 115 | id: admin 116 | password: PaaS-TA 117 | 118 | -------------------------------------------------------------------------------- /src/test/java/org/paasta/caas/api/clusters/namespaces/NamespacesServiceTest.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.clusters.namespaces; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.mockito.InjectMocks; 7 | import org.mockito.Mock; 8 | import org.paasta.caas.api.common.CommonService; 9 | import org.paasta.caas.api.common.Constants; 10 | import org.paasta.caas.api.common.PropertyService; 11 | import org.paasta.caas.api.common.RestTemplateService; 12 | import org.springframework.http.HttpMethod; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | import static org.junit.Assert.assertEquals; 20 | import static org.mockito.Mockito.*; 21 | 22 | @RunWith(SpringRunner.class) 23 | public class NamespacesServiceTest { 24 | 25 | private static final String NAMESPACE = "test-namespace"; 26 | private static final String LIST_URL = "test-list-url"; 27 | private static final String GET_URL = "test-get-url"; 28 | 29 | private static HashMap resultMap = null; 30 | private static Namespaces nResultModel = null; 31 | private static Namespaces nFinalResultModel = null; 32 | private static Namespaces nFinalResultFailModel = null; 33 | 34 | private static ResourceQuotaList rqResultModel = null; 35 | private static ResourceQuotaList rqFinalResultModel = null; 36 | private static ResourceQuotaList rqFinalResultFailModel = null; 37 | 38 | @Mock 39 | RestTemplateService restTemplateService; 40 | @Mock 41 | CommonService commonService; 42 | @Mock 43 | PropertyService propertyService; 44 | @InjectMocks 45 | NamespacesService namespacesService; 46 | 47 | @Before 48 | public void setUp() { 49 | resultMap = new HashMap(); 50 | 51 | nResultModel = new Namespaces(); 52 | 53 | nFinalResultModel = new Namespaces(); 54 | nFinalResultModel.setResultCode(Constants.RESULT_STATUS_SUCCESS); 55 | 56 | nFinalResultFailModel = new Namespaces(); 57 | nFinalResultFailModel.setResultCode(Constants.RESULT_STATUS_FAIL); 58 | 59 | rqResultModel = new ResourceQuotaList(); 60 | 61 | rqFinalResultModel = new ResourceQuotaList(); 62 | rqFinalResultModel.setResultCode(Constants.RESULT_STATUS_SUCCESS); 63 | 64 | rqFinalResultFailModel = new ResourceQuotaList(); 65 | rqFinalResultFailModel.setResultCode(Constants.RESULT_STATUS_FAIL); 66 | } 67 | 68 | @Test 69 | public void testGetNamespaces() { 70 | // CONDITION 71 | when(propertyService.getCaasMasterApiListNamespaceGetUrl()).thenReturn(GET_URL); 72 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, GET_URL 73 | .replace("{namespace}", NAMESPACE), HttpMethod.GET, null, Map.class)).thenReturn(resultMap); 74 | when(commonService.setResultModel(nResultModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(nFinalResultModel); 75 | when(commonService.setResultObject(resultMap, Namespaces.class)).thenReturn(nResultModel); 76 | 77 | // TEST 78 | Namespaces result = namespacesService.getNamespaces(NAMESPACE); 79 | 80 | // VERIFY 81 | assertThat(result).isNotNull(); 82 | assertEquals(Constants.RESULT_STATUS_SUCCESS, result.getResultCode()); 83 | } 84 | 85 | @Test 86 | public void testGetResourceQuotaList() { 87 | //when 88 | when(propertyService.getCaasMasterApiListResourceQuotasListUrl()).thenReturn(LIST_URL); 89 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, LIST_URL 90 | .replace("{namespace}", NAMESPACE), HttpMethod.GET, null, Map.class)).thenReturn(resultMap); 91 | when(commonService.setResultModel(rqResultModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(rqFinalResultModel); 92 | when(commonService.setResultObject(resultMap, ResourceQuotaList.class)).thenReturn(rqResultModel); 93 | 94 | // TEST 95 | ResourceQuotaList result = namespacesService.getResourceQuotaList(NAMESPACE); 96 | 97 | // VERIFY 98 | assertThat(result).isNotNull(); 99 | assertEquals(Constants.RESULT_STATUS_SUCCESS, result.getResultCode()); 100 | } 101 | } -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/persistentVolumeClaims/PersistentVolumeClaimsService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.persistentVolumeClaims; 2 | 3 | import org.paasta.caas.api.common.CommonService; 4 | import org.paasta.caas.api.common.Constants; 5 | import org.paasta.caas.api.common.PropertyService; 6 | import org.paasta.caas.api.common.RestTemplateService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpMethod; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * PersistentVolumeClaims Service 클래스 16 | * 17 | * @author hrjin 18 | * @version 1.0 19 | * @since 2019-10-24 20 | */ 21 | @Service 22 | public class PersistentVolumeClaimsService { 23 | 24 | private final RestTemplateService restTemplateService; 25 | private final CommonService commonService; 26 | private final PropertyService propertyService; 27 | 28 | /** 29 | * Instantiates a new deployments service. 30 | * 31 | * @param restTemplateService the rest template service 32 | * @param commonService the common service 33 | * @param propertyService the property service 34 | */ 35 | @Autowired 36 | public PersistentVolumeClaimsService(RestTemplateService restTemplateService, CommonService commonService, PropertyService propertyService) { 37 | this.restTemplateService = restTemplateService; 38 | this.commonService = commonService; 39 | this.propertyService = propertyService; 40 | } 41 | 42 | 43 | /** 44 | * PersistentVolumeClaims 목록을 조회한다. 45 | * 46 | * @param namespace the namespace 47 | * @return the PersistentVolumeClaims List 48 | */ 49 | public PersistentVolumeClaimsList getPersistentVolumeClaimsList(String namespace) { 50 | HashMap responseMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 51 | propertyService.getCaasMasterApiListPersistentVolumeClaimsListUrl() 52 | .replace("{namespace}", namespace) 53 | , HttpMethod.GET, null, Map.class); 54 | 55 | return (PersistentVolumeClaimsList) commonService.setResultModel(commonService.setResultObject(responseMap, PersistentVolumeClaimsList.class), Constants.RESULT_STATUS_SUCCESS); 56 | 57 | } 58 | 59 | /** 60 | * PersistentVolumeClaims 상세 정보를 조회한다. 61 | * 62 | * @param namespace the namespace 63 | * @param persistentVolumeClaimName the PersistentVolumeClaim name 64 | * @return the PersistentVolumeClaims 65 | */ 66 | public PersistentVolumeClaims getPersistentVolumeClaims(String namespace, String persistentVolumeClaimName) { 67 | HashMap responseMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 68 | propertyService.getCaasMasterApiListPersistentVolumeClaimsGetUrl() 69 | .replace("{namespace}", namespace) 70 | .replace("{name}", persistentVolumeClaimName) 71 | , HttpMethod.GET, null, Map.class); 72 | 73 | return (PersistentVolumeClaims) commonService.setResultModel(commonService.setResultObject(responseMap, PersistentVolumeClaims.class), Constants.RESULT_STATUS_SUCCESS); 74 | } 75 | 76 | 77 | /** 78 | * PersistentVolumeClaims YAML 을 조회한다. 79 | * 80 | * @param namespace the namespace 81 | * @param persistentVolumeClaimName the PersistentVolumeClaim name 82 | * @param resultMap the result map 83 | * @return the PersistentVolumeClaims 84 | */ 85 | public PersistentVolumeClaims getPersistentVolumeClaimsYaml(String namespace, String persistentVolumeClaimName, HashMap resultMap) { 86 | String resultString = restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 87 | propertyService.getCaasMasterApiListPersistentVolumeClaimsGetUrl() 88 | .replace("{namespace}", namespace) 89 | .replace("{name}", persistentVolumeClaimName), HttpMethod.GET, null, String.class, Constants.ACCEPT_TYPE_YAML); 90 | 91 | //noinspection unchecked 92 | resultMap.put("sourceTypeYaml", resultString); 93 | 94 | return (PersistentVolumeClaims) commonService.setResultModel(commonService.setResultObject(resultMap, PersistentVolumeClaims.class), Constants.RESULT_STATUS_SUCCESS); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/test/java/org/paasta/caas/api/nodes/NodesServiceTest.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.nodes; 2 | 3 | import org.junit.After; 4 | import org.junit.Before; 5 | import org.junit.FixMethodOrder; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.junit.runners.MethodSorters; 9 | import org.mockito.InjectMocks; 10 | import org.mockito.Mock; 11 | import org.paasta.caas.api.common.CommonService; 12 | import org.paasta.caas.api.common.Constants; 13 | import org.paasta.caas.api.common.PropertyService; 14 | import org.paasta.caas.api.common.RestTemplateService; 15 | import org.springframework.boot.test.context.SpringBootTest; 16 | import org.springframework.http.HttpMethod; 17 | import org.springframework.test.context.TestPropertySource; 18 | import org.springframework.test.context.junit4.SpringRunner; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | import static org.assertj.core.api.Assertions.assertThat; 24 | import static org.junit.Assert.assertEquals; 25 | import static org.mockito.Mockito.when; 26 | 27 | /** 28 | * The type Nodes service test. 29 | */ 30 | @RunWith(SpringRunner.class) 31 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 32 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 33 | @TestPropertySource("classpath:application.yml") 34 | public class NodesServiceTest { 35 | private static final String NODE_NAME = "test-node-name"; 36 | private static final String LIST_URL = "test-list-url"; 37 | private static final String GET_URL = "test-get-url"; 38 | 39 | private static HashMap gResultMap = null; 40 | private static NodesList gResultListModel = null; 41 | private static NodesList gFinalResultListModel = null; 42 | private static Nodes gResultModel = null; 43 | private static Nodes gFinalResultModel = null; 44 | 45 | @Mock 46 | private RestTemplateService restTemplateService; 47 | 48 | @Mock 49 | private CommonService commonService; 50 | 51 | @Mock 52 | private PropertyService propertyService; 53 | 54 | @InjectMocks 55 | private NodesService nodesService; 56 | 57 | /** 58 | * Sets up 59 | */ 60 | @Before 61 | public void setUp() { 62 | gResultMap = new HashMap(); 63 | gResultListModel = new NodesList(); 64 | gFinalResultListModel = new NodesList(); 65 | gFinalResultListModel.setResultCode(Constants.RESULT_STATUS_SUCCESS); 66 | 67 | gResultModel = new Nodes(); 68 | gFinalResultModel = new Nodes(); 69 | gFinalResultModel.setResultCode(Constants.RESULT_STATUS_SUCCESS); 70 | } 71 | 72 | /** 73 | * Tear down. 74 | */ 75 | @After 76 | public void tearDown() { 77 | 78 | } 79 | 80 | /** 81 | * Nodes 목록을 조회할 때에 대한 테스트 케이스. 82 | */ 83 | @Test 84 | public void getNodesList_Valid_ReturnModel() { 85 | when(propertyService.getCaasMasterApiListNodesListUrl()).thenReturn(LIST_URL); 86 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 87 | LIST_URL, HttpMethod.GET, null, Map.class)).thenReturn(gResultMap); 88 | when(commonService.setResultObject(gResultMap, NodesList.class)).thenReturn(gResultListModel); 89 | when(commonService.setResultModel(gResultListModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultListModel); 90 | 91 | NodesList resultModel = nodesService.getNodeList(); 92 | 93 | assertThat(resultModel).isNotNull(); 94 | assertEquals(Constants.RESULT_STATUS_SUCCESS, resultModel.getResultCode()); 95 | } 96 | 97 | /** 98 | * Nodes를 조회할 때에 대한 테스트 케이스. 99 | */ 100 | @Test 101 | public void getNodes_Valid_ReturnModel() { 102 | when(propertyService.getCaasMasterApiListNodesGetUrl()).thenReturn(GET_URL); 103 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 104 | GET_URL, HttpMethod.GET, null, Map.class)).thenReturn(gResultMap); 105 | when(commonService.setResultObject(gResultMap, Nodes.class)).thenReturn(gResultModel); 106 | when(commonService.setResultModel(gResultModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultModel); 107 | 108 | Nodes resultModel = nodesService.getNode(NODE_NAME); 109 | 110 | assertThat(resultModel).isNotNull(); 111 | assertEquals(Constants.RESULT_STATUS_SUCCESS, resultModel.getResultCode()); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/replicaSets/ReplicaSetsService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.replicaSets; 2 | 3 | import org.paasta.caas.api.common.*; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.HttpMethod; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * ReplicaSets Service 클래스 14 | * 15 | * @author CISS 16 | * @version 1.0 17 | * @since 2018.8.01 18 | */ 19 | @Service 20 | public class ReplicaSetsService { 21 | 22 | private final RestTemplateService restTemplateService; 23 | private final CommonService commonService; 24 | private final PropertyService propertyService; 25 | 26 | /** 27 | * Instantiates a new ReplicaSet service. 28 | * 29 | * @param restTemplateService the rest template service 30 | * @param commonService the common service 31 | * @param propertyService the property service 32 | */ 33 | @Autowired 34 | public ReplicaSetsService(RestTemplateService restTemplateService, CommonService commonService, PropertyService propertyService) { 35 | this.restTemplateService = restTemplateService; 36 | this.commonService = commonService; 37 | this.propertyService = propertyService; 38 | } 39 | 40 | /** 41 | * ReplicaSets 목록을 조회한다. 42 | * 43 | * @param namespace the namespace 44 | * @return the replicaSets list 45 | */ 46 | public ReplicaSetsList getReplicaSetsList(String namespace) { 47 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 48 | propertyService.getCaasMasterApiListReplicaSetsListUrl() 49 | .replace("{namespace}", namespace), HttpMethod.GET, null, Map.class); 50 | 51 | return (ReplicaSetsList) commonService.setResultModel(commonService.setResultObject(resultMap, ReplicaSetsList.class), Constants.RESULT_STATUS_SUCCESS); 52 | } 53 | 54 | /** 55 | * ReplicaSets 상세 정보를 조회한다. 56 | * 57 | * @param namespace the namespace 58 | * @param replicaSetsName the replicaSets name 59 | * @return the custom services 60 | */ 61 | public ReplicaSets getReplicaSets(String namespace, String replicaSetsName) { 62 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 63 | propertyService.getCaasMasterApiListReplicaSetsGetUrl() 64 | .replace("{namespace}", namespace) 65 | .replace("{name}", replicaSetsName) 66 | , HttpMethod.GET, null, Map.class); 67 | 68 | return (ReplicaSets) commonService.setResultModel(commonService.setResultObject(resultMap, ReplicaSets.class), Constants.RESULT_STATUS_SUCCESS); 69 | } 70 | 71 | /** 72 | * ReplicaSets YAML을 조회한다. 73 | * 74 | * @param namespace the namespace 75 | * @param replicaSetsName the ReplicaSets name 76 | * @return the custom ReplicaSets yaml 77 | */ 78 | public ReplicaSets getReplicaSetsYaml(String namespace, String replicaSetsName) { 79 | String resultString = restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 80 | propertyService.getCaasMasterApiListReplicaSetsGetUrl() 81 | .replace("{namespace}", namespace) 82 | .replace("{name}", replicaSetsName), HttpMethod.GET, null, String.class, Constants.ACCEPT_TYPE_YAML); 83 | 84 | //noinspection unchecked 85 | HashMap resultMap = new HashMap<>(); 86 | resultMap.put("sourceTypeYaml", resultString); 87 | 88 | return (ReplicaSets) commonService.setResultModel(commonService.setResultObject(resultMap, ReplicaSets.class), Constants.RESULT_STATUS_SUCCESS); 89 | } 90 | 91 | /** 92 | * ReplicaSets 목록을 조회한다. (Label Selector) 93 | * 94 | * @param namespace the namespace 95 | * @param selectors the selectors 96 | * @return the replicaSets list 97 | */ 98 | public ReplicaSetsList getReplicaSetsListLabelSelector(String namespace, String selectors) { 99 | String requestSelector = "?labelSelector=" + selectors; 100 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 101 | propertyService.getCaasMasterApiListReplicaSetsListUrl() 102 | .replace("{namespace}", namespace) + requestSelector, HttpMethod.GET, null, Map.class); 103 | 104 | return (ReplicaSetsList) commonService.setResultModel(commonService.setResultObject(resultMap, ReplicaSetsList.class), Constants.RESULT_STATUS_SUCCESS); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/pods/PodsService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.pods; 2 | 3 | import org.paasta.caas.api.common.CommonService; 4 | import org.paasta.caas.api.common.Constants; 5 | import org.paasta.caas.api.common.PropertyService; 6 | import org.paasta.caas.api.common.RestTemplateService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpMethod; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | 15 | /** 16 | * Pods Service 클래스 17 | * 18 | * @author Hyungu Cho 19 | * @version 1.0 20 | * @since 2018.08.01 21 | */ 22 | @Service 23 | public class PodsService { 24 | private final RestTemplateService restTemplateService; 25 | private final CommonService commonService; 26 | private final PropertyService propertyService; 27 | 28 | /** 29 | * Instantiates a new Pods service. 30 | * 31 | * @param restTemplateService the rest template service 32 | * @param commonService the common service 33 | * @param propertyService the property service 34 | */ 35 | @Autowired 36 | public PodsService(RestTemplateService restTemplateService, CommonService commonService, PropertyService propertyService) { 37 | this.restTemplateService = restTemplateService; 38 | this.commonService = commonService; 39 | this.propertyService = propertyService; 40 | } 41 | 42 | /** 43 | * Pod 목록을 조회한다. 44 | * 45 | * @param namespace the namespace 46 | * @return the pod list 47 | */ 48 | PodsList getPodList(String namespace) { 49 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 50 | propertyService.getCaasMasterApiListPodsListUrl().replace("{namespace}", namespace), HttpMethod.GET, null, Map.class); 51 | 52 | return (PodsList) commonService.setResultModel(commonService.setResultObject(resultMap, PodsList.class), Constants.RESULT_STATUS_SUCCESS); 53 | } 54 | 55 | /** 56 | * Selector를 이용해 Pod 목록을 조회한다. 57 | * 58 | * @param namespace the namespace 59 | * @param selector the selector 60 | * @return the pod list 61 | */ 62 | PodsList getPodListWithLabelSelector(String namespace, String selector) { 63 | String requestSelector = "?labelSelector=" + selector; 64 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 65 | propertyService.getCaasMasterApiListPodsListUrl().replace("{namespace}", namespace) + requestSelector, HttpMethod.GET, null, Map.class); 66 | 67 | return (PodsList) commonService.setResultModel(commonService.setResultObject(resultMap, PodsList.class), Constants.RESULT_STATUS_SUCCESS); 68 | } 69 | 70 | /** 71 | * Node 이름을 이용해 Pod 목록을 조회한다. 72 | * 73 | * @param namespace the namespace 74 | * @param nodeName the node name 75 | * @return the pod list 76 | */ 77 | PodsList getPodListByNode(String namespace, String nodeName) { 78 | String requestURL = propertyService.getCaasMasterApiListPodsListUrl().replace("{namespace}", namespace) 79 | + "/?fieldSelector=spec.nodeName=" + nodeName; 80 | 81 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, requestURL, 82 | HttpMethod.GET, null, Map.class); 83 | return (PodsList) commonService.setResultModel(commonService.setResultObject(resultMap, PodsList.class), Constants.RESULT_STATUS_SUCCESS); 84 | } 85 | 86 | /** 87 | * Pod를 조회한다. 88 | * 89 | * @param namespace the namespace 90 | * @param podName the pod's name 91 | * @return the pod 92 | */ 93 | Pods getPod(String namespace, String podName) { 94 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 95 | propertyService.getCaasMasterApiListPodsGetUrl().replace("{namespace}", namespace).replace("{name}", podName), 96 | HttpMethod.GET, null, Map.class); 97 | 98 | return (Pods) commonService.setResultModel(commonService.setResultObject(resultMap, Pods.class), Constants.RESULT_STATUS_SUCCESS); 99 | } 100 | 101 | /** 102 | * Pod의 YAML을 조회한다. 103 | * 104 | * @param namespace the namespace 105 | * @param podName the pod's name 106 | * @return the pods 107 | */ 108 | Pods getPodYaml(String namespace, String podName) { 109 | String resultString = restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 110 | propertyService.getCaasMasterApiListPodsGetUrl().replace("{namespace}", namespace).replace("{name}", podName), 111 | HttpMethod.GET, null, String.class, Constants.ACCEPT_TYPE_YAML); 112 | //noinspection unchecked 113 | HashMap resultMap = new HashMap<>(); 114 | resultMap.put("sourceTypeYaml", resultString); 115 | 116 | return (Pods) commonService.setResultModel(commonService.setResultObject(resultMap, Pods.class), Constants.RESULT_STATUS_SUCCESS); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/PropertyService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common; 2 | 3 | import lombok.Data; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.stereotype.Service; 6 | 7 | /** 8 | * Property Service 클래스 9 | * 10 | * @author REX 11 | * @version 1.0 12 | * @since 2018.08.07 13 | */ 14 | @Service 15 | @Data 16 | public class PropertyService { 17 | 18 | @Value("${caasMaster.api.url}") 19 | private String caasMasterApiUrl; 20 | 21 | @Value("${commonApi.url}") 22 | private String commonApiUrl; 23 | 24 | @Value("${caasMaster.api.list.services.list}") 25 | private String caasMasterApiListServicesListUrl; 26 | 27 | @Value("${caasMaster.api.list.services.get}") 28 | private String caasMasterApiListServicesGetUrl; 29 | 30 | @Value("${caasMaster.api.list.services.create}") 31 | private String caasMasterApiListServicesCreate; 32 | 33 | @Value("${caasMaster.api.list.services.delete}") 34 | private String caasMasterApiListServicesDelete; 35 | 36 | @Value("${caasMaster.api.list.endpoints.list}") 37 | private String caasMasterApiListEndpointsListUrl; 38 | 39 | @Value("${caasMaster.api.list.endpoints.get}") 40 | private String caasMasterApiListEndpointsGetUrl; 41 | 42 | @Value("${caasMaster.api.list.pods.list}") 43 | private String caasMasterApiListPodsListUrl; 44 | 45 | @Value("${caasMaster.api.list.pods.get}") 46 | private String caasMasterApiListPodsGetUrl; 47 | 48 | @Value("${caasMaster.api.list.nodes.list}") 49 | private String caasMasterApiListNodesListUrl; 50 | 51 | @Value("${caasMaster.api.list.nodes.get}") 52 | private String caasMasterApiListNodesGetUrl; 53 | 54 | @Value("${caasMaster.api.list.replicaSets.list}") 55 | private String caasMasterApiListReplicaSetsListUrl; 56 | 57 | @Value("${caasMaster.api.list.replicaSets.get}") 58 | private String caasMasterApiListReplicaSetsGetUrl; 59 | 60 | @Value("${caasMaster.api.list.persistentvolumes.list}") 61 | private String caasMasterApiListPersistentvolumesListUrl; 62 | 63 | @Value("${caasMaster.api.list.persistentvolumes.get}") 64 | private String caasMasterApiListPersistentvolumesGetUrl; 65 | 66 | @Value("${caasMaster.api.list.persistentVolumeClaims.list}") 67 | private String caasMasterApiListPersistentVolumeClaimsListUrl; 68 | 69 | @Value("${caasMaster.api.list.persistentVolumeClaims.get}") 70 | private String caasMasterApiListPersistentVolumeClaimsGetUrl; 71 | 72 | @Value("${caasMaster.api.list.events.list}") 73 | private String caasMasterApiListEventsListUrl; 74 | 75 | @Value("${caasMaster.api.list.roles.list}") 76 | private String caasMasterApiListRolesListUrl; 77 | 78 | @Value("${caasMaster.api.list.roles.get}") 79 | private String caasMasterApiListRolesGetUrl; 80 | 81 | @Value("${caasMaster.api.list.roles.create}") 82 | private String caasMasterApiListRolesCreateUrl; 83 | 84 | @Value("${caasMaster.api.list.roles.delete}") 85 | private String caasMasterApiListRolesDeleteUrl; 86 | 87 | @Value("${caasMaster.api.list.roles.update}") 88 | private String caasMasterApiListRolesUpdateUrl; 89 | 90 | @Value("${caasMaster.api.list.deployments.list}") 91 | private String caasMasterApiListDeploymentsList; 92 | 93 | @Value("${caasMaster.api.list.deployments.get}") 94 | private String caasMasterApiListDeploymentsGet; 95 | 96 | @Value("${caasMaster.api.list.deployments.create}") 97 | private String caasMasterApiListDeploymentsCreate; 98 | 99 | @Value("${caasMaster.api.list.deployments.delete}") 100 | private String caasMasterApiListDeploymentsDelete; 101 | 102 | @Value("${caasMaster.api.list.roleBindings.list}") 103 | private String caasMasterApiListRoleBindingsListUrl; 104 | 105 | @Value("${caasMaster.api.list.roleBindings.get}") 106 | private String caasMasterApiListRoleBindingsGetUrl; 107 | 108 | @Value("${caasMaster.api.list.roleBindings.create}") 109 | private String caasMasterApiListRoleBindingsCreateUrl; 110 | 111 | @Value("${caasMaster.api.list.roleBindings.delete}") 112 | private String caasMasterApiListRoleBindingsDeleteUrl; 113 | 114 | @Value("${caasMaster.api.list.roleBindings.update}") 115 | private String caasMasterApiListRoleBindingsUpdateUrl; 116 | 117 | @Value("${caasMaster.api.list.users.get}") 118 | private String caasMasterApiListUsersGetUrl; 119 | 120 | @Value("${caasMaster.api.list.users.create}") 121 | private String caasMasterApiListUsersCreateUrl; 122 | 123 | @Value("${caasMaster.api.list.users.delete}") 124 | private String caasMasterApiListUsersDeleteUrl; 125 | 126 | @Value("${caasMaster.api.list.namespaces.get}") 127 | private String caasMasterApiListNamespaceGetUrl; 128 | 129 | @Value("${caasMaster.api.list.namespaces.create}") 130 | private String caasMasterApiListNamespaceCreateUrl; 131 | 132 | @Value("${caasMaster.api.list.resourceQuotas.list}") 133 | private String caasMasterApiListResourceQuotasListUrl; 134 | 135 | @Value("${caasMaster.api.list.secrets.get}") 136 | private String caasMasterApiListSecretsGetUrl; 137 | 138 | @Value("${caasMaster.api.list.secrets.create}") 139 | private String caasMasterApiListSecretsCreateUrl; 140 | } 141 | -------------------------------------------------------------------------------- /src/test/java/org/paasta/caas/api/endpoints/EndpointsServiceTest.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.endpoints; 2 | 3 | import org.assertj.core.api.Assertions; 4 | import org.junit.After; 5 | import org.junit.Before; 6 | import org.junit.FixMethodOrder; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.junit.runners.MethodSorters; 10 | import org.mockito.InjectMocks; 11 | import org.mockito.Mock; 12 | import org.paasta.caas.api.common.CommonService; 13 | import org.paasta.caas.api.common.Constants; 14 | import org.paasta.caas.api.common.PropertyService; 15 | import org.paasta.caas.api.common.RestTemplateService; 16 | import org.springframework.boot.test.context.SpringBootTest; 17 | import org.springframework.http.HttpMethod; 18 | import org.springframework.test.context.TestPropertySource; 19 | import org.springframework.test.context.junit4.SpringRunner; 20 | 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | import static org.assertj.core.api.AssertionsForClassTypes.assertThat; 25 | import static org.junit.Assert.assertEquals; 26 | import static org.mockito.Mockito.when; 27 | 28 | /** 29 | * The type Endpoints service test. 30 | */ 31 | @RunWith(SpringRunner.class) 32 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 33 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 34 | @TestPropertySource("classpath:application.yml") 35 | public class EndpointsServiceTest { 36 | 37 | private static final String NAMESPACE = "test-namespace"; 38 | private static final String SERVICE_NAME = "test-service-name"; 39 | private static final String LIST_URL = "test-list-url"; 40 | private static final String GET_URL = "test-get-url"; 41 | 42 | private static HashMap gResultMap = null; 43 | private static EndpointsList gResultListModel = null; 44 | private static EndpointsList gFinalResultListModel = null; 45 | private static Endpoints gResultModel = null; 46 | private static Endpoints gFinalResultModel = null; 47 | 48 | 49 | @Mock 50 | private RestTemplateService restTemplateService; 51 | 52 | @Mock 53 | private CommonService commonService; 54 | 55 | @Mock 56 | private PropertyService propertyService; 57 | 58 | @InjectMocks 59 | private EndpointsService endpointsService; 60 | 61 | 62 | /** 63 | * Sets up. 64 | */ 65 | @Before 66 | public void setUp() { 67 | gResultMap = new HashMap(); 68 | gResultListModel = new EndpointsList(); 69 | gFinalResultListModel = new EndpointsList(); 70 | gFinalResultListModel.setResultCode(Constants.RESULT_STATUS_SUCCESS); 71 | 72 | gResultModel = new Endpoints(); 73 | gFinalResultModel = new Endpoints(); 74 | gFinalResultModel.setResultCode(Constants.RESULT_STATUS_SUCCESS); 75 | } 76 | 77 | 78 | /** 79 | * Tear down. 80 | */ 81 | @After 82 | public void tearDown() { 83 | } 84 | 85 | 86 | //////////////////////////////////////////////////////////////////////////////////////////////////// 87 | //////////////////// MethodName_StateUnderTest_ExpectedBehavior 88 | //////////////////////////////////////////////////////////////////////////////////////////////////// 89 | 90 | 91 | /** 92 | * Gets endpoints list valid return model. 93 | */ 94 | @Test 95 | public void getEndpointsList_Valid_ReturnModel() { 96 | // CONDITION 97 | when(propertyService.getCaasMasterApiListEndpointsListUrl()).thenReturn(LIST_URL); 98 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, LIST_URL 99 | .replace("{namespace}", NAMESPACE), HttpMethod.GET, null, Map.class)).thenReturn(gResultMap); 100 | when(commonService.setResultObject(gResultMap, EndpointsList.class)).thenReturn(gResultListModel); 101 | when(commonService.setResultModel(gResultListModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultListModel); 102 | 103 | // TEST 104 | EndpointsList resultModel = endpointsService.getEndpointsList(NAMESPACE); 105 | 106 | // VERIFY 107 | assertThat(resultModel).isNotNull(); 108 | assertEquals(Constants.RESULT_STATUS_SUCCESS, resultModel.getResultCode()); 109 | } 110 | 111 | 112 | /** 113 | * Gets endpoints valid return model. 114 | */ 115 | @Test 116 | public void getEndpoints_Valid_ReturnModel() { 117 | // CONDITION 118 | when(propertyService.getCaasMasterApiListEndpointsGetUrl()).thenReturn(GET_URL); 119 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, GET_URL 120 | .replace("{namespace}", NAMESPACE) 121 | .replace("{name}", SERVICE_NAME), HttpMethod.GET, null, Map.class)).thenReturn(gResultMap); 122 | when(commonService.setResultObject(gResultMap, Endpoints.class)).thenReturn(gResultModel); 123 | when(commonService.setResultModel(gResultModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultModel); 124 | 125 | // TEST 126 | Endpoints resultModel = endpointsService.getEndpoints(NAMESPACE, SERVICE_NAME); 127 | 128 | // VERIFY 129 | Assertions.assertThat(resultModel).isNotNull(); 130 | assertEquals(Constants.RESULT_STATUS_SUCCESS, resultModel.getResultCode()); 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/roleBindings/RoleBindingsService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.roleBindings; 2 | 3 | import org.paasta.caas.api.common.CommonService; 4 | import org.paasta.caas.api.common.Constants; 5 | import org.paasta.caas.api.common.PropertyService; 6 | import org.paasta.caas.api.common.RestTemplateService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpMethod; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * RoleBinding Service 클래스 16 | * 17 | * @author hrjin 18 | * @version 1.0 19 | * @since 2018 -08-17 20 | */ 21 | @Service 22 | public class RoleBindingsService { 23 | 24 | private final RestTemplateService restTemplateService; 25 | private final CommonService commonService; 26 | private final PropertyService propertyService; 27 | 28 | /** 29 | * Instantiates a new RoleBinding service 30 | * 31 | * @param restTemplateService the rest template service 32 | * @param commonService the common service 33 | * @param propertyService the property service 34 | */ 35 | @Autowired 36 | public RoleBindingsService(RestTemplateService restTemplateService, CommonService commonService, PropertyService propertyService) { 37 | this.restTemplateService = restTemplateService; 38 | this.commonService = commonService; 39 | this.propertyService = propertyService; 40 | } 41 | 42 | 43 | /** 44 | * RoleBindingList 조회 (특정 네임스페이스에서 조회) 45 | * 46 | * @param namespace the namespace 47 | * @return the RoleBindingsList 48 | */ 49 | RoleBindingsList getRoleBindingList(String namespace) { 50 | String apiUrl = propertyService.getCaasMasterApiListRoleBindingsListUrl().replace("{namespace}", namespace); 51 | 52 | HashMap responseMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, apiUrl, HttpMethod.GET, null, Map.class); 53 | return (RoleBindingsList) commonService.setResultModel(commonService.setResultObject(responseMap, RoleBindingsList.class), Constants.RESULT_STATUS_SUCCESS); 54 | } 55 | 56 | /** 57 | * RoleBinding 객체를 조회한다. (특정 네임스페이스에서 조회) 58 | * 59 | * @param namespace the namespace 60 | * @param roleBindingName the roleBindingName 61 | * @return the RoleBindings 62 | */ 63 | RoleBindings getRoleBinding(String namespace, String roleBindingName) { 64 | String apiUrl = propertyService.getCaasMasterApiListRoleBindingsGetUrl() 65 | .replace("{namespace}", namespace) 66 | .replace("{name}", roleBindingName); 67 | 68 | HashMap responseMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, apiUrl, HttpMethod.GET, null, Map.class); 69 | return (RoleBindings) commonService.setResultModel(commonService.setResultObject(responseMap, RoleBindings.class), Constants.RESULT_STATUS_SUCCESS); 70 | } 71 | 72 | 73 | /** 74 | * RoleBinding 권한을 할당한다. (특정 네임스페이스에서 조회) 75 | * 76 | * @param namespace the namespace 77 | * @param roleBinding the roleBinding 78 | * @return the RoleBindings 79 | */ 80 | RoleBindings createRoleBinding(String namespace, RoleBindings roleBinding) { 81 | String apiUrl = propertyService.getCaasMasterApiListRoleBindingsCreateUrl().replace("{namespace}", namespace); 82 | 83 | HashMap responseMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, apiUrl, HttpMethod.POST, roleBinding, Map.class); 84 | return (RoleBindings) commonService.setResultModel(commonService.setResultObject(responseMap, RoleBindings.class), Constants.RESULT_STATUS_SUCCESS); 85 | } 86 | 87 | /** 88 | * RoleBinding 권한을 해지한다. (특정 네임스페이스에서 조회) 89 | * 90 | * @param namespace the namespace 91 | * @param roleBindingName the roleBindingName 92 | * @return String string 93 | */ 94 | String deleteRoleBinding(String namespace, String roleBindingName) { 95 | String apiUrl = propertyService.getCaasMasterApiListRoleBindingsDeleteUrl() 96 | .replace("{namespace}", namespace) 97 | .replace("{name}", roleBindingName); 98 | 99 | HashMap responseMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, apiUrl, HttpMethod.DELETE, null, Map.class); 100 | 101 | if (responseMap.get("status").equals("Success")) { 102 | return Constants.RESULT_STATUS_SUCCESS; 103 | } 104 | return Constants.RESULT_STATUS_FAIL; 105 | } 106 | 107 | /** 108 | * RoleBinding 권한을 수정한다. 109 | * 110 | * @param namespace the namespace 111 | * @param roleBindingName the roleBindingName 112 | * @param yml the yml 113 | * @return String string 114 | */ 115 | String updateRoleBinding(String namespace, String roleBindingName, String yml) { 116 | String apiUrl = propertyService.getCaasMasterApiListRoleBindingsUpdateUrl() 117 | .replace("{namespace}", namespace) 118 | .replace("{name}", roleBindingName); 119 | 120 | String resultString = restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, apiUrl, HttpMethod.PUT, yml, String.class, 121 | Constants.ACCEPT_TYPE_YAML, Constants.ACCEPT_TYPE_YAML); 122 | 123 | if (resultString != null) { 124 | return Constants.RESULT_STATUS_SUCCESS; 125 | } 126 | return Constants.RESULT_STATUS_FAIL; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/customServices/CustomServicesService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.customServices; 2 | 3 | import org.paasta.caas.api.common.CommonService; 4 | import org.paasta.caas.api.common.Constants; 5 | import org.paasta.caas.api.common.PropertyService; 6 | import org.paasta.caas.api.common.RestTemplateService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpMethod; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * Custom Services Service 클래스 16 | * 17 | * @author REX 18 | * @version 1.0 19 | * @since 2018.8.09 20 | */ 21 | @Service 22 | public class CustomServicesService { 23 | 24 | private final RestTemplateService restTemplateService; 25 | private final CommonService commonService; 26 | private final PropertyService propertyService; 27 | 28 | /** 29 | * Instantiates a new Custom services service. 30 | * 31 | * @param restTemplateService the rest template service 32 | * @param commonService the common service 33 | * @param propertyService the property service 34 | */ 35 | @Autowired 36 | public CustomServicesService(RestTemplateService restTemplateService, CommonService commonService, PropertyService propertyService) { 37 | this.restTemplateService = restTemplateService; 38 | this.commonService = commonService; 39 | this.propertyService = propertyService; 40 | } 41 | 42 | 43 | /** 44 | * Services 목록을 조회한다. 45 | * 46 | * @param namespace the namespace 47 | * @return the custom services list 48 | */ 49 | CustomServicesList getCustomServicesList(String namespace) { 50 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 51 | propertyService.getCaasMasterApiListServicesListUrl() 52 | .replace("{namespace}", namespace), HttpMethod.GET, null, Map.class); 53 | 54 | return (CustomServicesList) commonService.setResultModel(commonService.setResultObject(resultMap, CustomServicesList.class), Constants.RESULT_STATUS_SUCCESS); 55 | } 56 | 57 | 58 | /** 59 | * Services 상세 정보를 조회한다. 60 | * 61 | * @param namespace the namespace 62 | * @param serviceName the service name 63 | * @return the custom services 64 | */ 65 | CustomServices getCustomServices(String namespace, String serviceName) { 66 | HashMap resultMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 67 | propertyService.getCaasMasterApiListServicesGetUrl() 68 | .replace("{namespace}", namespace) 69 | .replace("{name}", serviceName), HttpMethod.GET, null, Map.class); 70 | 71 | return (CustomServices) commonService.setResultModel(commonService.setResultObject(resultMap, CustomServices.class), Constants.RESULT_STATUS_SUCCESS); 72 | } 73 | 74 | 75 | /** 76 | * Services YAML을 조회한다. 77 | * 78 | * @param namespace the namespace 79 | * @param serviceName the service name 80 | * @param resultMap the result map 81 | * @return the custom services yaml 82 | */ 83 | CustomServices getCustomServicesYaml(String namespace, String serviceName, HashMap resultMap) { 84 | String resultString = restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 85 | propertyService.getCaasMasterApiListServicesGetUrl() 86 | .replace("{namespace}", namespace) 87 | .replace("{name}", serviceName), HttpMethod.GET, null, String.class, Constants.ACCEPT_TYPE_YAML); 88 | 89 | //noinspection unchecked 90 | resultMap.put("sourceTypeYaml", resultString); 91 | 92 | return (CustomServices) commonService.setResultModel(commonService.setResultObject(resultMap, CustomServices.class), Constants.RESULT_STATUS_SUCCESS); 93 | } 94 | 95 | 96 | /** 97 | * Services를 생성한다. 98 | * 99 | * @param namespace the namespace 100 | * @param service the Services 101 | * @return return is succeeded 102 | */ 103 | public Map createServicesYaml(String namespace, Object service, HashMap resultMap) { 104 | System.out.println("namespace:::::" + namespace ); 105 | String resultString = restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 106 | propertyService.getCaasMasterApiListServicesCreate() 107 | .replace("{namespace}", namespace), HttpMethod.POST, service, String.class, Constants.ACCEPT_TYPE_YAML); 108 | resultMap.put("sourceTypeYaml", resultString); 109 | return resultMap; 110 | } 111 | 112 | /** 113 | * Services를 제거한다. 114 | * 115 | * @param namespace the namespace 116 | * @param name the Services name 117 | * @return return is succeeded 118 | */ 119 | public Map deleteServicesYaml(String namespace, String name, HashMap resultMap) { 120 | System.out.println("namespace:::::" + namespace ); 121 | String resultString = restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 122 | propertyService.getCaasMasterApiListServicesDelete() 123 | .replace("{namespace}", namespace).replace("{name}", name), HttpMethod.DELETE, null, String.class, Constants.ACCEPT_TYPE_YAML); 124 | resultMap.put("sourceTypeYaml", resultString); 125 | return resultMap; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/workloads/deployments/DeploymentsService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.deployments; 2 | 3 | import org.paasta.caas.api.common.CommonService; 4 | import org.paasta.caas.api.common.Constants; 5 | import org.paasta.caas.api.common.PropertyService; 6 | import org.paasta.caas.api.common.RestTemplateService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpMethod; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * Deployments Service 클래스 16 | * 17 | * @author PHR 18 | * @version 1.0 19 | * @since 2018.08.13 20 | */ 21 | @Service 22 | public class DeploymentsService { 23 | private final RestTemplateService restTemplateService; 24 | private final CommonService commonService; 25 | private final PropertyService propertyService; 26 | 27 | /** 28 | * Instantiates a new deployments service. 29 | * 30 | * @param restTemplateService the rest template service 31 | * @param commonService the common service 32 | * @param propertyService the property service 33 | */ 34 | @Autowired 35 | public DeploymentsService(RestTemplateService restTemplateService, CommonService commonService, PropertyService propertyService) { 36 | this.restTemplateService = restTemplateService; 37 | this.commonService = commonService; 38 | this.propertyService = propertyService; 39 | } 40 | 41 | /** 42 | * Deployments 목록을 조회한다. 43 | * 44 | * @param namespace the namespace 45 | * @return the deployments list 46 | */ 47 | public DeploymentsList getDeploymentsList(String namespace) { 48 | HashMap responseMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 49 | propertyService.getCaasMasterApiListDeploymentsList() 50 | .replace("{namespace}", namespace) 51 | , HttpMethod.GET, null, Map.class); 52 | 53 | return (DeploymentsList) commonService.setResultModel(commonService.setResultObject(responseMap, DeploymentsList.class), Constants.RESULT_STATUS_SUCCESS); 54 | } 55 | 56 | /** 57 | * Deployments 상세 정보를 조회한다. 58 | * 59 | * @param namespace the namespace 60 | * @param deploymentName the deployments name 61 | * @return the deployments 62 | */ 63 | public Deployments getDeployments(String namespace, String deploymentName) { 64 | HashMap responseMap = (HashMap) restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 65 | propertyService.getCaasMasterApiListDeploymentsGet() 66 | .replace("{namespace}", namespace) 67 | .replace("{name}", deploymentName) 68 | , HttpMethod.GET, null, Map.class); 69 | 70 | return (Deployments) commonService.setResultModel(commonService.setResultObject(responseMap, Deployments.class), Constants.RESULT_STATUS_SUCCESS); 71 | } 72 | 73 | /** 74 | * Deployments YAML을 조회한다. 75 | * 76 | * @param namespace the namespace 77 | * @param deploymentName the deployments name 78 | * @param resultMap the result map 79 | * @return the deployments yaml 80 | */ 81 | public Deployments getDeploymentsYaml(String namespace, String deploymentName, HashMap resultMap) { 82 | String resultString = restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 83 | propertyService.getCaasMasterApiListDeploymentsGet() 84 | .replace("{namespace}", namespace) 85 | .replace("{name}", deploymentName), HttpMethod.GET, null, String.class, Constants.ACCEPT_TYPE_YAML); 86 | 87 | //noinspection unchecked 88 | resultMap.put("sourceTypeYaml", resultString); 89 | 90 | return (Deployments) commonService.setResultModel(commonService.setResultObject(resultMap, Deployments.class), Constants.RESULT_STATUS_SUCCESS); 91 | } 92 | 93 | /** 94 | * Deployments 를 생성한다. 95 | * 96 | * @param namespace the namespace 97 | * @param deployments the deployments 98 | * @param resultMap the result map 99 | * @return the deployments yaml 100 | */ 101 | public Map createDeploymentsYaml(String namespace, Object deployments, HashMap resultMap) { 102 | System.out.println("namespace:::::" + namespace ); 103 | String resultString = restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 104 | propertyService.getCaasMasterApiListDeploymentsCreate() 105 | .replace("{namespace}", namespace), HttpMethod.POST, deployments, String.class, Constants.ACCEPT_TYPE_YAML); 106 | resultMap.put("sourceTypeYaml", resultString); 107 | 108 | return resultMap; 109 | } 110 | 111 | /** 112 | * Deployments 를 삭제한다. 113 | * 114 | * @param namespace the namespace 115 | * @param name the deployments name 116 | * @param resultMap the result map 117 | * @return the deployments yaml 118 | */ 119 | public Map deleteDeploymentsYaml(String namespace, String name, HashMap resultMap) { 120 | System.out.println("namespace:::::" + namespace ); 121 | String resultString = restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 122 | propertyService.getCaasMasterApiListDeploymentsDelete() 123 | .replace("{namespace}", namespace).replace("{name}", name), HttpMethod.DELETE, null, String.class, Constants.ACCEPT_TYPE_YAML); 124 | resultMap.put("sourceTypeYaml", resultString); 125 | 126 | return resultMap; 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /src/test/java/org/paasta/caas/api/persistentVolumeClaims/PersistentVolumeClaimsServiceTest.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.persistentVolumeClaims; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.mockito.InjectMocks; 7 | import org.mockito.Mock; 8 | import org.paasta.caas.api.common.CommonService; 9 | import org.paasta.caas.api.common.Constants; 10 | import org.paasta.caas.api.common.PropertyService; 11 | import org.paasta.caas.api.common.RestTemplateService; 12 | import org.springframework.http.HttpMethod; 13 | import org.springframework.test.context.TestPropertySource; 14 | import org.springframework.test.context.junit4.SpringRunner; 15 | 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | import static org.junit.Assert.assertEquals; 21 | import static org.mockito.Mockito.when; 22 | 23 | @RunWith(SpringRunner.class) 24 | @TestPropertySource("classpath:application.yml") 25 | public class PersistentVolumeClaimsServiceTest { 26 | private static final String NAMESPACE = "test-namespace"; 27 | private static final String PERSISTENT_VOLUME_CLAIM_NAME = "test-pvc-name"; 28 | private static final String YAML_STRING = "test-yaml-string"; 29 | 30 | private static HashMap gResultMap = null; 31 | 32 | private static PersistentVolumeClaimsList gResultListModel = null; 33 | private static PersistentVolumeClaimsList gFinalResultListModel = null; 34 | private static PersistentVolumeClaimsList gFinalResultListFailModel = null; 35 | 36 | private static PersistentVolumeClaims gResultModel = null; 37 | private static PersistentVolumeClaims gFinalResultModel = null; 38 | private static PersistentVolumeClaims gFinalResultFailModel = null; 39 | 40 | @Mock 41 | RestTemplateService restTemplateService; 42 | 43 | @Mock 44 | CommonService commonService; 45 | 46 | @Mock 47 | PropertyService propertyService; 48 | 49 | @InjectMocks 50 | PersistentVolumeClaimsService persistentVolumeClaimsService; 51 | 52 | @Before 53 | public void setUp() { 54 | 55 | // 리스트가져옴 56 | gResultMap = new HashMap(); 57 | gResultListModel = new PersistentVolumeClaimsList(); 58 | gFinalResultListModel = new PersistentVolumeClaimsList(); 59 | gFinalResultListModel.setResultCode(Constants.RESULT_STATUS_SUCCESS); 60 | 61 | gFinalResultListFailModel = new PersistentVolumeClaimsList(); 62 | gFinalResultListFailModel.setResultCode(Constants.RESULT_STATUS_FAIL); 63 | 64 | // 하나만 가져옴 65 | gResultModel = new PersistentVolumeClaims(); 66 | gFinalResultModel = new PersistentVolumeClaims(); 67 | gFinalResultModel.setSourceTypeYaml(YAML_STRING); 68 | gFinalResultModel.setResultCode(Constants.RESULT_STATUS_SUCCESS); 69 | 70 | gFinalResultFailModel = new PersistentVolumeClaims(); 71 | gFinalResultFailModel.setResultCode(Constants.RESULT_STATUS_FAIL); 72 | 73 | } 74 | 75 | @Test 76 | public void getPersistentVolumeClaimsList_Valid_ReturnModel() { 77 | 78 | //when 79 | when(propertyService.getCaasMasterApiListPersistentVolumeClaimsListUrl()).thenReturn("/api/v1/namespaces/{namespace}/persistentvolumeclaims"); 80 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, "/api/v1/namespaces/" + NAMESPACE +"/persistentvolumeclaims", HttpMethod.GET, null, Map.class)).thenReturn(gResultMap); 81 | when(commonService.setResultObject(gResultMap, PersistentVolumeClaimsList.class)).thenReturn(gResultListModel); 82 | when(commonService.setResultModel(gResultListModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultListModel); 83 | 84 | //call method 85 | PersistentVolumeClaimsList resultList = persistentVolumeClaimsService.getPersistentVolumeClaimsList(NAMESPACE); 86 | 87 | //compare result 88 | assertThat(resultList).isNotNull(); 89 | assertEquals(Constants.RESULT_STATUS_SUCCESS, resultList.getResultCode()); 90 | } 91 | 92 | 93 | @Test 94 | public void getPersistentVolumeClaim_Valid_ReturnModel() { 95 | 96 | //when 97 | when(propertyService.getCaasMasterApiListPersistentVolumeClaimsGetUrl()).thenReturn("/api/v1/namespaces/{namespace}/persistentvolumeclaims/{name}"); 98 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, "/api/v1/namespaces/" + NAMESPACE +"/persistentvolumeclaims/" + PERSISTENT_VOLUME_CLAIM_NAME, HttpMethod.GET, null, Map.class)).thenReturn(gResultMap); 99 | when(commonService.setResultObject(gResultMap, PersistentVolumeClaims.class)).thenReturn(gResultModel); 100 | when(commonService.setResultModel(gResultModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultModel); 101 | 102 | //call method 103 | PersistentVolumeClaims result = persistentVolumeClaimsService.getPersistentVolumeClaims(NAMESPACE, PERSISTENT_VOLUME_CLAIM_NAME); 104 | 105 | //compare result 106 | assertThat(result).isNotNull(); 107 | assertEquals(Constants.RESULT_STATUS_SUCCESS, result.getResultCode()); 108 | 109 | } 110 | 111 | @Test 112 | public void getPersistentVolumeClaim_Yaml_Valid_ReturnModel() { 113 | 114 | //when 115 | when(propertyService.getCaasMasterApiListPersistentVolumeClaimsGetUrl()).thenReturn("/apis/apps/v1/namespaces/{namespace}/persistentvolumeclaims/{name}"); 116 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, "/apis/apps/v1/namespaces/" + NAMESPACE +"/persistentvolumeclaims/" + PERSISTENT_VOLUME_CLAIM_NAME, HttpMethod.GET, null, String.class, Constants.ACCEPT_TYPE_YAML)).thenReturn(YAML_STRING); 117 | when(commonService.setResultObject(gResultMap, PersistentVolumeClaims.class)).thenReturn(gResultModel); 118 | when(commonService.setResultModel(gResultModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultModel); 119 | 120 | //call method 121 | PersistentVolumeClaims result = persistentVolumeClaimsService.getPersistentVolumeClaimsYaml(NAMESPACE, PERSISTENT_VOLUME_CLAIM_NAME, gResultMap); 122 | 123 | //compare result 124 | assertThat(result).isNotNull(); 125 | assertEquals(YAML_STRING, result.getSourceTypeYaml()); 126 | assertEquals(Constants.RESULT_STATUS_SUCCESS, result.getResultCode()); 127 | 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/main/java/org/paasta/caas/api/common/RestTemplateService.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.common; 2 | 3 | import org.paasta.caas.api.adminToken.AdminToken; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.http.*; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.util.Base64Utils; 11 | import org.springframework.web.client.RestTemplate; 12 | 13 | import java.nio.charset.StandardCharsets; 14 | 15 | import static org.paasta.caas.api.common.Constants.TARGET_COMMON_API; 16 | 17 | /** 18 | * RestTemplate Service 클래스 19 | * 20 | * @author REX 21 | * @version 1.0 22 | * @since 2018.08.07 23 | */ 24 | @Service 25 | public class RestTemplateService { 26 | 27 | private static final Logger LOGGER = LoggerFactory.getLogger(RestTemplateService.class); 28 | private static final String AUTHORIZATION_HEADER_KEY = "Authorization"; 29 | private static final String CONTENT_TYPE = "Content-Type"; 30 | private final String commonApiBase64Authorization; 31 | private final RestTemplate restTemplate; 32 | private final PropertyService propertyService; 33 | private String base64Authorization; 34 | private String baseUrl; 35 | 36 | /** 37 | * Instantiates a new Rest template service. 38 | * @param restTemplate the rest template 39 | * @param commonApiAuthorizationId the common api authorization id 40 | * @param commonApiAuthorizationPassword the common api authorization password 41 | * @param propertyService the property service 42 | // *@param adminTokenService 43 | */ 44 | @Autowired 45 | public RestTemplateService(RestTemplate restTemplate, 46 | @Value("${commonApi.authorization.id}") String commonApiAuthorizationId, 47 | @Value("${commonApi.authorization.password}") String commonApiAuthorizationPassword, 48 | PropertyService propertyService) { 49 | this.restTemplate = restTemplate; 50 | this.propertyService = propertyService; 51 | 52 | this.commonApiBase64Authorization = "Basic " 53 | + Base64Utils.encodeToString( 54 | (commonApiAuthorizationId + ":" + commonApiAuthorizationPassword).getBytes(StandardCharsets.UTF_8)); 55 | } 56 | 57 | 58 | /** 59 | * Send t. 60 | * 61 | * @param the type parameter 62 | * @param reqApi the req api 63 | * @param reqUrl the req url 64 | * @param httpMethod the http method 65 | * @param bodyObject the body object 66 | * @param responseType the response type 67 | * @return the t 68 | */ 69 | public T send(String reqApi, String reqUrl, HttpMethod httpMethod, Object bodyObject, Class responseType) { 70 | return send(reqApi, reqUrl, httpMethod, bodyObject, responseType, Constants.ACCEPT_TYPE_JSON, MediaType.APPLICATION_JSON_VALUE); 71 | } 72 | 73 | 74 | /** 75 | * Send t. 76 | * 77 | * @param the type parameter 78 | * @param reqApi the req api 79 | * @param reqUrl the req url 80 | * @param httpMethod the http method 81 | * @param bodyObject the body object 82 | * @param responseType the response type 83 | * @param acceptType the accept type 84 | * @return the t 85 | */ 86 | public T send(String reqApi, String reqUrl, HttpMethod httpMethod, Object bodyObject, Class responseType, String acceptType) { 87 | return send(reqApi, reqUrl, httpMethod, bodyObject, responseType, acceptType, MediaType.APPLICATION_JSON_VALUE); 88 | } 89 | 90 | 91 | /** 92 | * Send t. 93 | * 94 | * @param the type parameter 95 | * @param reqApi the req api 96 | * @param reqUrl the req url 97 | * @param httpMethod the http method 98 | * @param bodyObject the body object 99 | * @param responseType the response type 100 | * @param acceptType the accept type 101 | * @param contentType the content type 102 | * @return the t 103 | */ 104 | public T send(String reqApi, String reqUrl, HttpMethod httpMethod, Object bodyObject, Class responseType, String acceptType, String contentType) { 105 | 106 | setApiUrlAuthorization(reqApi); 107 | 108 | HttpHeaders reqHeaders = new HttpHeaders(); 109 | reqHeaders.add(AUTHORIZATION_HEADER_KEY, base64Authorization); 110 | reqHeaders.add(CONTENT_TYPE, contentType); 111 | reqHeaders.add("ACCEPT", acceptType); 112 | 113 | HttpEntity reqEntity; 114 | if (bodyObject == null) { 115 | reqEntity = new HttpEntity<>(reqHeaders); 116 | } else { 117 | reqEntity = new HttpEntity<>(bodyObject, reqHeaders); 118 | } 119 | 120 | LOGGER.info(" T SEND :: REQUEST: {} BASE-URL: {}, CONTENT-TYPE: {}", httpMethod, reqUrl, reqHeaders.get(CONTENT_TYPE)); 121 | ResponseEntity resEntity = restTemplate.exchange(baseUrl + reqUrl, httpMethod, reqEntity, responseType); 122 | 123 | if (resEntity.getBody() != null) { 124 | LOGGER.info("RESPONSE-TYPE: {}", resEntity.getBody().getClass()); 125 | } else { 126 | LOGGER.error("RESPONSE-TYPE: RESPONSE BODY IS NULL"); 127 | } 128 | 129 | return resEntity.getBody(); 130 | } 131 | 132 | 133 | private void setApiUrlAuthorization(String reqApi) { 134 | 135 | String apiUrl = ""; 136 | String authorization = ""; 137 | 138 | // CAAS MASTER API 139 | if (Constants.TARGET_CAAS_MASTER_API.equals(reqApi)) { 140 | apiUrl = propertyService.getCaasMasterApiUrl(); 141 | authorization = "Bearer " + this.getAdminToken().getTokenValue(); 142 | } 143 | 144 | // COMMON API 145 | if (TARGET_COMMON_API.equals(reqApi)) { 146 | apiUrl = propertyService.getCommonApiUrl(); 147 | authorization = commonApiBase64Authorization; 148 | } 149 | 150 | this.base64Authorization = authorization; 151 | this.baseUrl = apiUrl; 152 | } 153 | 154 | public AdminToken getAdminToken() { 155 | this.setApiUrlAuthorization(TARGET_COMMON_API); 156 | String reqUrl = Constants.URI_COMMON_API_ADMIN_TOKEN_DETAIL.replace("{tokenName:.+}",Constants.TOKEN_KEY); 157 | return this.send(TARGET_COMMON_API, reqUrl, HttpMethod.GET, null, AdminToken.class); 158 | } 159 | 160 | } 161 | -------------------------------------------------------------------------------- /src/test/java/org/paasta/caas/api/customServices/CustomServiceServicesTest.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.customServices; 2 | 3 | import org.junit.After; 4 | import org.junit.Before; 5 | import org.junit.FixMethodOrder; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.junit.runners.MethodSorters; 9 | import org.mockito.InjectMocks; 10 | import org.mockito.Mock; 11 | import org.paasta.caas.api.common.CommonService; 12 | import org.paasta.caas.api.common.Constants; 13 | import org.paasta.caas.api.common.PropertyService; 14 | import org.paasta.caas.api.common.RestTemplateService; 15 | import org.springframework.boot.test.context.SpringBootTest; 16 | import org.springframework.http.HttpMethod; 17 | import org.springframework.test.context.TestPropertySource; 18 | import org.springframework.test.context.junit4.SpringRunner; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | import static org.assertj.core.api.Assertions.assertThat; 24 | import static org.junit.Assert.assertEquals; 25 | import static org.mockito.Mockito.when; 26 | 27 | /** 28 | * The type Custom services service test. 29 | */ 30 | @RunWith(SpringRunner.class) 31 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 32 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 33 | @TestPropertySource("classpath:application.yml") 34 | public class CustomServiceServicesTest { 35 | 36 | private static final String NAMESPACE = "test-namespace"; 37 | private static final String SERVICE_NAME = "test-service-name"; 38 | private static final String LIST_URL = "test-list-url"; 39 | private static final String GET_URL = "test-get-url"; 40 | private static final String YAML_STRING = "test-yaml-string"; 41 | 42 | private static HashMap gResultMap = null; 43 | private static CustomServicesList gResultListModel = null; 44 | private static CustomServicesList gFinalResultListModel = null; 45 | private static CustomServices gResultModel = null; 46 | private static CustomServices gFinalResultModel = null; 47 | 48 | 49 | @Mock 50 | private RestTemplateService restTemplateService; 51 | 52 | @Mock 53 | private CommonService commonService; 54 | 55 | @Mock 56 | private PropertyService propertyService; 57 | 58 | @InjectMocks 59 | private CustomServicesService customServicesService; 60 | 61 | 62 | /** 63 | * Sets up. 64 | */ 65 | @Before 66 | public void setUp() { 67 | gResultMap = new HashMap(); 68 | gResultListModel = new CustomServicesList(); 69 | gFinalResultListModel = new CustomServicesList(); 70 | gFinalResultListModel.setResultCode(Constants.RESULT_STATUS_SUCCESS); 71 | 72 | gResultModel = new CustomServices(); 73 | gFinalResultModel = new CustomServices(); 74 | gFinalResultModel.setSourceTypeYaml(YAML_STRING); 75 | gFinalResultModel.setResultCode(Constants.RESULT_STATUS_SUCCESS); 76 | } 77 | 78 | 79 | /** 80 | * Tear down. 81 | */ 82 | @After 83 | public void tearDown() { 84 | } 85 | 86 | 87 | //////////////////////////////////////////////////////////////////////////////////////////////////// 88 | //////////////////// MethodName_StateUnderTest_ExpectedBehavior 89 | //////////////////////////////////////////////////////////////////////////////////////////////////// 90 | 91 | 92 | /** 93 | * Gets custom services list valid return model. 94 | */ 95 | @Test 96 | public void getCustomServicesList_Valid_ReturnModel() { 97 | // CONDITION 98 | when(propertyService.getCaasMasterApiListServicesListUrl()).thenReturn(LIST_URL); 99 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, LIST_URL 100 | .replace("{namespace}", NAMESPACE), HttpMethod.GET, null, Map.class)).thenReturn(gResultMap); 101 | when(commonService.setResultObject(gResultMap, CustomServicesList.class)).thenReturn(gResultListModel); 102 | when(commonService.setResultModel(gResultListModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultListModel); 103 | 104 | // TEST 105 | CustomServicesList resultModel = customServicesService.getCustomServicesList(NAMESPACE); 106 | 107 | // VERIFY 108 | assertThat(resultModel).isNotNull(); 109 | assertEquals(Constants.RESULT_STATUS_SUCCESS, resultModel.getResultCode()); 110 | } 111 | 112 | 113 | /** 114 | * Gets custom services valid return model. 115 | */ 116 | @Test 117 | public void getCustomServices_Valid_ReturnModel() { 118 | // CONDITION 119 | when(propertyService.getCaasMasterApiListServicesGetUrl()).thenReturn(GET_URL); 120 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, GET_URL 121 | .replace("{namespace}", NAMESPACE) 122 | .replace("{name}", SERVICE_NAME), HttpMethod.GET, null, Map.class)).thenReturn(gResultMap); 123 | when(commonService.setResultObject(gResultMap, CustomServices.class)).thenReturn(gResultModel); 124 | when(commonService.setResultModel(gResultModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultModel); 125 | 126 | // TEST 127 | CustomServices resultModel = customServicesService.getCustomServices(NAMESPACE, SERVICE_NAME); 128 | 129 | // VERIFY 130 | assertThat(resultModel).isNotNull(); 131 | assertEquals(Constants.RESULT_STATUS_SUCCESS, resultModel.getResultCode()); 132 | } 133 | 134 | 135 | /** 136 | * Gets custom services yaml valid return model. 137 | */ 138 | @Test 139 | public void getCustomServicesYaml_Valid_ReturnModel() { 140 | // CONDITION 141 | when(propertyService.getCaasMasterApiListServicesGetUrl()).thenReturn(GET_URL); 142 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, GET_URL 143 | .replace("{namespace}", NAMESPACE) 144 | .replace("{name}", SERVICE_NAME), HttpMethod.GET, null, String.class)).thenReturn(YAML_STRING); 145 | when(commonService.setResultObject(gResultMap, CustomServices.class)).thenReturn(gResultModel); 146 | when(commonService.setResultModel(gResultModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultModel); 147 | 148 | // TEST 149 | CustomServices resultModel = customServicesService.getCustomServicesYaml(NAMESPACE, SERVICE_NAME, gResultMap); 150 | 151 | // VERIFY 152 | assertThat(resultModel).isNotNull(); 153 | assertEquals(YAML_STRING, resultModel.getSourceTypeYaml()); 154 | assertEquals(Constants.RESULT_STATUS_SUCCESS, resultModel.getResultCode()); 155 | } 156 | 157 | } 158 | -------------------------------------------------------------------------------- /src/test/java/org/paasta/caas/api/events/EventsServiceTest.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.events; 2 | 3 | import org.junit.After; 4 | import org.junit.Before; 5 | import org.junit.FixMethodOrder; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.junit.runners.MethodSorters; 9 | import org.mockito.InjectMocks; 10 | import org.mockito.Mock; 11 | import org.paasta.caas.api.common.CommonService; 12 | import org.paasta.caas.api.common.Constants; 13 | import org.paasta.caas.api.common.PropertyService; 14 | import org.paasta.caas.api.common.RestTemplateService; 15 | import org.springframework.boot.test.context.SpringBootTest; 16 | import org.springframework.http.HttpMethod; 17 | import org.springframework.test.context.TestPropertySource; 18 | import org.springframework.test.context.junit4.SpringRunner; 19 | 20 | import java.util.HashMap; 21 | import java.util.LinkedList; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | import static org.assertj.core.api.Assertions.assertThat; 26 | import static org.junit.Assert.assertEquals; 27 | import static org.mockito.Mockito.when; 28 | 29 | /** 30 | * The type Nodes service test. 31 | */ 32 | @RunWith(SpringRunner.class) 33 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 34 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 35 | @TestPropertySource("classpath:application.yml") 36 | public class EventsServiceTest { 37 | private static final String NAMESPACE = "test-namespace"; 38 | private static final String ALL_NAMESPACE = "_all"; 39 | private static final String RESOURCE = "test-resource"; 40 | private static final String NODE_NAME = "test-node"; 41 | private static final String LIST_URL = "test-list-url"; 42 | private static final String EVENTLIST_RESULT_KEY = "items"; 43 | private static final String SOURCEHOST_METAKEY = "source"; 44 | private static final String SOURCEHOST_KEY = "host"; 45 | private static final String SOURCEHOST_VALUE = NODE_NAME; 46 | private static final String TYPE = "type"; 47 | 48 | private static HashMap gResultMap = null; 49 | private static EventsList gResultListModel = null; 50 | private static EventsList gFinalResultListModel = null; 51 | 52 | private static List> gOriginalMapList = null; 53 | private static List> gFilterMapList = null; 54 | private static Map gOriginalMap = null; 55 | private static Map gSource = null; 56 | 57 | private static Map gOriginalMapAnotherHost = null; 58 | private static Map gSourceAnotherHost = null; 59 | 60 | @Mock 61 | private RestTemplateService restTemplateService; 62 | 63 | @Mock 64 | private CommonService commonService; 65 | 66 | @Mock 67 | private PropertyService propertyService; 68 | 69 | @InjectMocks 70 | private EventsService eventsService; 71 | 72 | /** 73 | * Sets up 74 | */ 75 | @Before 76 | public void setUp() { 77 | gResultMap = new HashMap(); 78 | gResultListModel = new EventsList(); 79 | gFinalResultListModel = new EventsList(); 80 | gFinalResultListModel.setResultCode(Constants.RESULT_STATUS_SUCCESS); 81 | 82 | gOriginalMapList = new LinkedList<>(); 83 | gFilterMapList = new LinkedList<>(); 84 | 85 | // items 86 | gOriginalMap = new HashMap<>(); 87 | gOriginalMapAnotherHost = new HashMap<>(); 88 | gOriginalMapList.add(gOriginalMap); 89 | gOriginalMapList.add(gOriginalMapAnotherHost); 90 | 91 | // source 92 | gSource = new HashMap<>(); 93 | gSourceAnotherHost = new HashMap<>(); 94 | gSource.put(SOURCEHOST_KEY, SOURCEHOST_VALUE); 95 | gSourceAnotherHost.put(SOURCEHOST_KEY, SOURCEHOST_VALUE + "2"); 96 | } 97 | 98 | /** 99 | * Tear down. 100 | */ 101 | @After 102 | public void tearDown() { 103 | 104 | } 105 | 106 | @Test 107 | public void getEventList_Type_Null_Valid_ReturnModel() { 108 | // CONDITION 109 | when(propertyService.getCaasMasterApiListEventsListUrl()).thenReturn(LIST_URL); 110 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 111 | LIST_URL + "?fieldSelector=involvedObject.uid=" + RESOURCE, HttpMethod.GET, null, Map.class)).thenReturn(gResultMap); 112 | when(commonService.setResultObject(gResultMap, EventsList.class)).thenReturn(gResultListModel); 113 | when(commonService.setResultModel(gResultListModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultListModel); 114 | 115 | // TEST 116 | EventsList resultModel = eventsService.getEventsList(NAMESPACE, RESOURCE, null); 117 | 118 | // VERIFY 119 | assertThat(resultModel).isNotNull(); 120 | assertEquals(Constants.RESULT_STATUS_SUCCESS, resultModel.getResultCode()); 121 | } 122 | 123 | @Test 124 | public void getEventList_Type_Not_Null_Valid_ReturnModel() { 125 | // CONDITION 126 | when(propertyService.getCaasMasterApiListEventsListUrl()).thenReturn(LIST_URL); 127 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 128 | LIST_URL + "?fieldSelector=involvedObject.name=" + RESOURCE, HttpMethod.GET, null, Map.class)).thenReturn(gResultMap); 129 | when(commonService.setResultObject(gResultMap, EventsList.class)).thenReturn(gResultListModel); 130 | when(commonService.setResultModel(gResultListModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultListModel); 131 | 132 | // TEST 133 | EventsList resultModel = eventsService.getEventsList(NAMESPACE, RESOURCE, TYPE); 134 | 135 | // VERIFY 136 | assertThat(resultModel).isNotNull(); 137 | assertEquals(Constants.RESULT_STATUS_SUCCESS, resultModel.getResultCode()); 138 | } 139 | 140 | @Test 141 | public void getNamespaceEventList_Valid_ReturnModel() { 142 | // CONDITION 143 | when(propertyService.getCaasMasterApiListEventsListUrl()).thenReturn(LIST_URL); 144 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, 145 | LIST_URL, HttpMethod.GET, null, Map.class)).thenReturn(gResultMap); 146 | when(commonService.setResultObject(gResultMap, EventsList.class)).thenReturn(gResultListModel); 147 | when(commonService.setResultModel(gResultListModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultListModel); 148 | 149 | // TEST 150 | EventsList resultModel = eventsService.getNamespaceEventsList(NAMESPACE); 151 | 152 | // VERIFY 153 | assertThat(resultModel).isNotNull(); 154 | assertEquals(Constants.RESULT_STATUS_SUCCESS, resultModel.getResultCode()); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /src/test/java/org/paasta/caas/api/workloads/Deployments/DeploymentsServiceTest.java: -------------------------------------------------------------------------------- 1 | package org.paasta.caas.api.workloads.Deployments; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.junit.Assert.assertEquals; 5 | import static org.mockito.Mockito.when; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | import org.junit.Before; 11 | import org.junit.Test; 12 | import org.junit.runner.RunWith; 13 | import org.mockito.InjectMocks; 14 | import org.mockito.Mock; 15 | import org.paasta.caas.api.common.CommonService; 16 | import org.paasta.caas.api.common.Constants; 17 | import org.paasta.caas.api.common.PropertyService; 18 | import org.paasta.caas.api.common.RestTemplateService; 19 | import org.paasta.caas.api.workloads.deployments.Deployments; 20 | import org.paasta.caas.api.workloads.deployments.DeploymentsList; 21 | import org.paasta.caas.api.workloads.deployments.DeploymentsService; 22 | import org.springframework.http.HttpMethod; 23 | import org.springframework.test.context.TestPropertySource; 24 | import org.springframework.test.context.junit4.SpringRunner; 25 | 26 | @RunWith(SpringRunner.class) 27 | @TestPropertySource("classpath:application.yml") 28 | public class DeploymentsServiceTest { 29 | 30 | private static final String NAMESPACE = "test-namespace"; 31 | private static final String DEPLOYMENT_NAME = "test-deployment-name"; 32 | private static final String LABEL_SELECTOR = "test-label-selector"; 33 | private static final String YAML_STRING = "test-yaml-string"; 34 | 35 | private static HashMap gResultMap = null; 36 | 37 | private static DeploymentsList gResultListModel = null; 38 | private static DeploymentsList gFinalResultListModel = null; 39 | private static DeploymentsList gFinalResultListFailModel = null; 40 | 41 | private static Deployments gResultModel = null; 42 | private static Deployments gFinalResultModel = null; 43 | private static Deployments gFinalResultFailModel = null; 44 | 45 | @Mock 46 | RestTemplateService restTemplateService; 47 | 48 | @Mock 49 | CommonService commonService; 50 | 51 | @Mock 52 | PropertyService propertyService; 53 | 54 | @InjectMocks 55 | DeploymentsService deploymentsService; 56 | 57 | @Before 58 | public void setUp() { 59 | 60 | // 리스트가져옴 61 | gResultMap = new HashMap(); 62 | gResultListModel = new DeploymentsList(); 63 | gFinalResultListModel = new DeploymentsList(); 64 | gFinalResultListModel.setResultCode(Constants.RESULT_STATUS_SUCCESS); 65 | 66 | gFinalResultListFailModel = new DeploymentsList(); 67 | gFinalResultListFailModel.setResultCode(Constants.RESULT_STATUS_FAIL); 68 | 69 | // 하나만 가져옴 70 | gResultModel = new Deployments(); 71 | gFinalResultModel = new Deployments(); 72 | gFinalResultModel.setSourceTypeYaml(YAML_STRING); 73 | gFinalResultModel.setResultCode(Constants.RESULT_STATUS_SUCCESS); 74 | 75 | gFinalResultFailModel = new Deployments(); 76 | gFinalResultFailModel.setResultCode(Constants.RESULT_STATUS_FAIL); 77 | 78 | } 79 | 80 | @Test 81 | public void getDeploymentList_Valid_ReturnModel() { 82 | 83 | //when 84 | when(propertyService.getCaasMasterApiListDeploymentsList()).thenReturn("/apis/apps/v1/namespaces/{namespace}/deployments"); 85 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, "/apis/apps/v1/namespaces/" + NAMESPACE +"/deployments", HttpMethod.GET, null, Map.class)).thenReturn(gResultMap); 86 | when(commonService.setResultObject(gResultMap, DeploymentsList.class)).thenReturn(gResultListModel); 87 | when(commonService.setResultModel(gResultListModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultListModel); 88 | 89 | //call method 90 | DeploymentsList resultList = deploymentsService.getDeploymentsList(NAMESPACE); 91 | 92 | //compare result 93 | assertThat(resultList).isNotNull(); 94 | assertEquals(Constants.RESULT_STATUS_SUCCESS, resultList.getResultCode()); 95 | } 96 | 97 | @Test 98 | public void getDeployment_Valid_ReturnModel() { 99 | 100 | //when 101 | when(propertyService.getCaasMasterApiListDeploymentsGet()).thenReturn("/apis/apps/v1/namespaces/{namespace}/deployments/{name}"); 102 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, "/apis/apps/v1/namespaces/" + NAMESPACE +"/deployments/" + DEPLOYMENT_NAME, HttpMethod.GET, null, Map.class)).thenReturn(gResultMap); 103 | when(commonService.setResultObject(gResultMap, Deployments.class)).thenReturn(gResultModel); 104 | when(commonService.setResultModel(gResultModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultModel); 105 | 106 | //call method 107 | Deployments result = deploymentsService.getDeployments(NAMESPACE, DEPLOYMENT_NAME); 108 | 109 | //compare result 110 | assertThat(result).isNotNull(); 111 | assertEquals(Constants.RESULT_STATUS_SUCCESS, result.getResultCode()); 112 | 113 | } 114 | 115 | @Test 116 | public void getDeployment_Yaml_Valid_ReturnModel() { 117 | 118 | //when 119 | when(propertyService.getCaasMasterApiListDeploymentsGet()).thenReturn("/apis/apps/v1/namespaces/{namespace}/deployments/{name}"); 120 | when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, "/apis/apps/v1/namespaces/" + NAMESPACE +"/deployments/" + DEPLOYMENT_NAME, HttpMethod.GET, null, String.class, Constants.ACCEPT_TYPE_YAML)).thenReturn(YAML_STRING); 121 | when(commonService.setResultObject(gResultMap, Deployments.class)).thenReturn(gResultModel); 122 | when(commonService.setResultModel(gResultModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultModel); 123 | 124 | //call method 125 | Deployments result = deploymentsService.getDeploymentsYaml(NAMESPACE, DEPLOYMENT_NAME, gResultMap); 126 | 127 | //compare result 128 | assertThat(result).isNotNull(); 129 | assertEquals(YAML_STRING, result.getSourceTypeYaml()); 130 | assertEquals(Constants.RESULT_STATUS_SUCCESS, result.getResultCode()); 131 | 132 | } 133 | 134 | // @Test 135 | // public void getDeploymentsListLabelSelector_Valid_ReturnModel() { 136 | // 137 | // //when 138 | // when(propertyService.getCaasMasterApiListDeploymentsList()).thenReturn("/apis/apps/v1/namespaces/{namespace}/deployments"); 139 | // when(restTemplateService.send(Constants.TARGET_CAAS_MASTER_API, "/apis/apps/v1/namespaces/" + NAMESPACE +"/deployments?labelSelector="+LABEL_SELECTOR, HttpMethod.GET, null, Map.class)).thenReturn(gResultMap); 140 | // when(commonService.setResultObject(gResultMap, DeploymentsList.class)).thenReturn(gResultListModel); 141 | // when(commonService.setResultModel(gResultListModel, Constants.RESULT_STATUS_SUCCESS)).thenReturn(gFinalResultListModel); 142 | // 143 | // //call method 144 | // DeploymentsList resultList = deploymentsService.getDeploymentsListLabelSelector(NAMESPACE,LABEL_SELECTOR); 145 | // 146 | // //compare result 147 | // assertThat(resultList).isNotNull(); 148 | // assertEquals(Constants.RESULT_STATUS_SUCCESS, resultList.getResultCode()); 149 | // } 150 | 151 | } 152 | --------------------------------------------------------------------------------