Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SO1S-482 ABN 테스트 개발 #65

Merged
merged 10 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public ResponseEntity<DeploymentResponseDto> updateDeployment(

return ResponseEntity.ok(deploymentService.updateDeployment(deploymentRequestDto));
}

@GetMapping
public ResponseEntity<List<DeploymentFindResponseDto>> findDeployments() {
return ResponseEntity.ok(deploymentService.findDeployments());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ScaleDto {

@Min(1)
private int minReplicas;

@Min(1)
private int maxReplicas;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.so1s.backend.domain.deployment.exception.DeploymentNotFoundException;
import io.so1s.backend.domain.deployment.exception.DeploymentUpdateFailedException;
import io.so1s.backend.domain.resource.entity.Resource;
import io.so1s.backend.domain.test.exception.ABTestExistsException;
import io.so1s.backend.domain.test.v1.exception.ABTestExistsException;
import io.so1s.backend.global.error.exception.NodeResourceExceededException;
import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import io.so1s.backend.domain.resource.entity.Resource;
import io.so1s.backend.domain.resource.repository.ResourceRepository;
import io.so1s.backend.domain.resource.service.ResourceService;
import io.so1s.backend.domain.test.entity.ABTest;
import io.so1s.backend.domain.test.exception.ABTestExistsException;
import io.so1s.backend.domain.test.repository.ABTestRepository;
import io.so1s.backend.domain.test.v1.entity.ABTest;
import io.so1s.backend.domain.test.v1.exception.ABTestExistsException;
import io.so1s.backend.domain.test.v1.repository.ABTestRepository;
import io.so1s.backend.global.error.exception.NodeResourceExceededException;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -80,7 +80,7 @@ public DeploymentDeleteResponseDto deleteDeployment(Long id)
throw new ABTestExistsException("해당 디플로이먼트를 사용하고 있는 AB 테스트가 존재합니다.\nAB 테스트를 먼저 삭제해 주세요.");
}

boolean result = kubernetesService.deleteDeployment(deployment);
boolean result = kubernetesService.deleteInferenceServer(deployment);

if (!result) {
return DeploymentDeleteResponseDto.builder()
Expand Down Expand Up @@ -129,7 +129,7 @@ public boolean updateInference(Deployment deployment) throws DeploymentUpdateFai
"AB Test is exist that use Deployment.\nPlease delete the AB Test first.");
}

kubernetesService.deleteDeployment(deployment);
kubernetesService.deleteInferenceServer(deployment);

return kubernetesService.deployInferenceServer(deployment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface DeploymentStrategyRepository extends JpaRepository<DeploymentStrategy, Long> {

Optional<DeploymentStrategy> findById(Long id);

List<DeploymentStrategy> findAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.so1s.backend.domain.deployment.entity.Deployment;
import io.so1s.backend.domain.model.entity.ModelMetadata;
import io.so1s.backend.domain.resource.entity.Resource;
import io.so1s.backend.domain.test.entity.ABTest;

public interface KubernetesService {

Expand All @@ -27,11 +26,7 @@ public interface KubernetesService {
boolean deployInferenceServer(
Deployment deployment);

boolean deployABTest(ABTest abTest);

boolean deleteDeployment(Deployment deployment);

boolean deleteABTest(ABTest abTest);
boolean deleteInferenceServer(Deployment deployment);

boolean createHPA(Deployment deployment,
String namespace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,14 @@
import io.so1s.backend.domain.model.entity.Model;
import io.so1s.backend.domain.model.entity.ModelMetadata;
import io.so1s.backend.domain.resource.entity.Resource;
import io.so1s.backend.domain.test.entity.ABTest;
import io.so1s.backend.global.utils.HashGenerator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.task.TaskRejectedException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -364,98 +361,10 @@ public boolean deployInferenceServer(
return true;
}

@Transactional(readOnly = true)
@Override
public boolean deployABTest(ABTest abTest) {

String namespace = getNamespace();
String abTestName = "ab-test-" + abTest.getName().toLowerCase();

String host = abTestName + ".so1s.io"; // TODO: Fix hard-coded root domain

String aName = abTest.getA().getName().toLowerCase();
String bName = abTest.getB().getName().toLowerCase();

Map<String, String> labels = new HashMap<>();
labels.put("app", "ab-test");
labels.put("name", abTestName);

VirtualService abTestVirtualService = new VirtualServiceBuilder()
.withNewMetadata()
.withName(abTestName)
.withNamespace(namespace)
.addToLabels(labels)
.endMetadata()
.withNewSpec()
.withHosts(host)
.withGateways(abTestName)
.addNewHttp()
.addNewMatch()
.withNewUri()
.withNewStringMatchPrefixType("/")
.endUri()
.endMatch()
.addNewRoute()
.withWeight(50)
.withNewDestination()
.withHost(aName)
.withNewPort()
.withNumber(3000)
.endPort()
.endDestination()
.endRoute()
.addNewRoute()
.withWeight(50)
.withNewDestination()
.withHost(bName)
.withNewPort()
.withNumber(3000)
.endPort()
.endDestination()
.endRoute()
.endHttp()
.endSpec()
.build();

Gateway abTestGateway = new GatewayBuilder()
.withNewMetadata()
.withName(abTestName)
.withNamespace(namespace)
.addToLabels(labels)
.endMetadata()
.withNewSpec()
.addNewServer()
.withNewPort()
.withNumber(80)
.withName("http")
.withProtocol("HTTP")
.endPort()
.withHosts(host)
.endServer()
.addNewServer()
.withNewPort()
.withNumber(9443)
.withName("http-dev")
.withProtocol("HTTP")
.endPort()
.withHosts(host)
.endServer()
.endSpec()
.build();

try {
istioClient.v1beta1().gateways().inNamespace(namespace).createOrReplace(abTestGateway);
istioClient.v1beta1().virtualServices().inNamespace(namespace)
.createOrReplace(abTestVirtualService);
} catch (KubernetesClientException ignored) {
return false;
}

return true;
}

@Override
public boolean deleteDeployment(io.so1s.backend.domain.deployment.entity.Deployment deployment) {
public boolean deleteInferenceServer(
io.so1s.backend.domain.deployment.entity.Deployment deployment) {
String namespace = getNamespace();
String deploymentName = deployment.getName().toLowerCase();

Expand All @@ -475,21 +384,6 @@ public boolean deleteDeployment(io.so1s.backend.domain.deployment.entity.Deploym
return true;
}

@Override
public boolean deleteABTest(ABTest abTest) {
String namespace = getNamespace();
String abTestName = "ab-test-" + abTest.getName().toLowerCase();

try {
istioClient.v1beta1().gateways().inNamespace(namespace).withName(abTestName).delete();
istioClient.v1beta1().virtualServices().inNamespace(namespace).withName(abTestName).delete();
} catch (KubernetesClientException ignored) {
return false;
}

return true;
}

public HasMetadata getDeploymentObject(String name) {
List<Deployment> deployments = client.apps().deployments().inNamespace(getNamespace())
.withLabel("app", "inference").list()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public class ModelMetadataDeleteResponseDto {

@Builder.Default
private String message = "";

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@NoArgsConstructor
@AllArgsConstructor
public class ModelMetadataFindResponseDto {

private Long id;
private LocalDateTime age;
private String version;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package io.so1s.backend.domain.test.controller;
package io.so1s.backend.domain.test.v1.controller;

import io.so1s.backend.domain.deployment.exception.DeploymentNotFoundException;
import io.so1s.backend.domain.deployment.service.DeploymentService;
import io.so1s.backend.domain.kubernetes.service.KubernetesService;
import io.so1s.backend.domain.test.dto.mapper.ABTestMapper;
import io.so1s.backend.domain.test.dto.request.ABTestRequestDto;
import io.so1s.backend.domain.test.dto.response.ABTestCreateResponseDto;
import io.so1s.backend.domain.test.dto.response.ABTestDeleteResponseDto;
import io.so1s.backend.domain.test.dto.response.ABTestReadResponseDto;
import io.so1s.backend.domain.test.dto.service.ABTestCreateDto;
import io.so1s.backend.domain.test.dto.service.ABTestUpdateDto;
import io.so1s.backend.domain.test.entity.ABTest;
import io.so1s.backend.domain.test.exception.ABTestNotFoundException;
import io.so1s.backend.domain.test.service.ABTestService;
import io.so1s.backend.domain.test.v1.dto.mapper.ABTestMapper;
import io.so1s.backend.domain.test.v1.dto.request.ABTestRequestDto;
import io.so1s.backend.domain.test.v1.dto.response.ABTestCreateResponseDto;
import io.so1s.backend.domain.test.v1.dto.response.ABTestDeleteResponseDto;
import io.so1s.backend.domain.test.v1.dto.response.ABTestReadResponseDto;
import io.so1s.backend.domain.test.v1.dto.service.derived.ABTestCreateDto;
import io.so1s.backend.domain.test.v1.dto.service.derived.ABTestUpdateDto;
import io.so1s.backend.domain.test.v1.entity.ABTest;
import io.so1s.backend.domain.test.v1.exception.ABTestNotFoundException;
import io.so1s.backend.domain.test.v1.service.ABTestService;
import java.util.List;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.so1s.backend.domain.test.dto.mapper;
package io.so1s.backend.domain.test.v1.dto.mapper;

import io.so1s.backend.domain.deployment.exception.DeploymentNotFoundException;
import io.so1s.backend.domain.test.dto.request.ABTestRequestDto;
import io.so1s.backend.domain.test.dto.response.ABTestCreateResponseDto;
import io.so1s.backend.domain.test.dto.response.ABTestReadResponseDto;
import io.so1s.backend.domain.test.entity.ABTest;
import io.so1s.backend.domain.test.v1.dto.request.ABTestRequestDto;
import io.so1s.backend.domain.test.v1.dto.response.ABTestCreateResponseDto;
import io.so1s.backend.domain.test.v1.dto.response.ABTestReadResponseDto;
import io.so1s.backend.domain.test.v1.entity.ABTest;
import org.springframework.dao.DataIntegrityViolationException;

public interface ABTestMapper {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.so1s.backend.domain.test.dto.mapper;
package io.so1s.backend.domain.test.v1.dto.mapper;

import io.so1s.backend.domain.deployment.entity.Deployment;
import io.so1s.backend.domain.deployment.exception.DeploymentNotFoundException;
import io.so1s.backend.domain.deployment.service.DeploymentService;
import io.so1s.backend.domain.test.dto.request.ABTestRequestDto;
import io.so1s.backend.domain.test.dto.response.ABTestCreateResponseDto;
import io.so1s.backend.domain.test.dto.response.ABTestReadResponseDto;
import io.so1s.backend.domain.test.entity.ABTest;
import io.so1s.backend.domain.test.v1.dto.request.ABTestRequestDto;
import io.so1s.backend.domain.test.v1.dto.response.ABTestCreateResponseDto;
import io.so1s.backend.domain.test.v1.dto.response.ABTestReadResponseDto;
import io.so1s.backend.domain.test.v1.entity.ABTest;
import lombok.RequiredArgsConstructor;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.so1s.backend.domain.test.dto.request;
package io.so1s.backend.domain.test.v1.dto.request;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.so1s.backend.domain.test.dto.response;
package io.so1s.backend.domain.test.v1.dto.response;


import lombok.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.so1s.backend.domain.test.dto.response;
package io.so1s.backend.domain.test.v1.dto.response;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package io.so1s.backend.domain.test.dto.response;

import lombok.*;
package io.so1s.backend.domain.test.v1.dto.response;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package io.so1s.backend.domain.test.dto.service;
package io.so1s.backend.domain.test.v1.dto.service.base;

import io.so1s.backend.domain.test.entity.ABTest;
import io.so1s.backend.domain.test.v1.entity.ABTest;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Getter
@Builder
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ABTestUpdateDto {
public abstract class ABTestBaseDto {

private ABTest entity;
private Boolean success;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.so1s.backend.domain.test.v1.dto.service.derived;

import io.so1s.backend.domain.test.v1.dto.service.base.ABTestBaseDto;
import lombok.Getter;
import lombok.experimental.SuperBuilder;

@Getter
@SuperBuilder
public class ABTestCreateDto extends ABTestBaseDto {

}
Loading