Merged in feature/SCDD-224 (pull request #2)

feature/SCDD-224
This commit is contained in:
Sunae Jang 2023-09-11 08:59:04 +00:00
commit c9046a0fb4
5 changed files with 50 additions and 46 deletions

View File

@ -5,7 +5,7 @@ plugins {
} }
group = 'inc.sdt.controlcentermanagement' group = 'inc.sdt.controlcentermanagement'
version = '0.0.4' version = '0.0.5'
java { java {
sourceCompatibility = '17' sourceCompatibility = '17'

View File

@ -1,4 +1,4 @@
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin 003960268191.dkr.ecr.ap-northeast-2.amazonaws.com aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin 003960268191.dkr.ecr.ap-northeast-2.amazonaws.com
docker build --platform linux/amd64 -t control-center-management ../../ docker build --platform linux/amd64 -t control-center-management ../../
docker tag control-center-management:latest 003960268191.dkr.ecr.ap-northeast-2.amazonaws.com/sdt-cloud/control-center-management:0.0.4 docker tag control-center-management:latest 003960268191.dkr.ecr.ap-northeast-2.amazonaws.com/sdt-cloud/control-center-management:0.0.5
docker push 003960268191.dkr.ecr.ap-northeast-2.amazonaws.com/sdt-cloud/control-center-management:0.0.4 docker push 003960268191.dkr.ecr.ap-northeast-2.amazonaws.com/sdt-cloud/control-center-management:0.0.5

View File

@ -9,10 +9,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
import java.util.HashMap; import java.util.*;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/** /**
* @author sunae.jang (sa.jang@sdt.inc) * @author sunae.jang (sa.jang@sdt.inc)
@ -44,57 +41,51 @@ class DefaultTubeService implements TubeService {
} }
@Override @Override
public void controlByTubeCode(String authorization, Slot request) { public void controlByTubeCode(String authorization, Slot slot) {
log.info("[controlByTubeCode] request: {}", request); log.info("[controlByTubeCode] slot: {}", slot);
Map<String, String> tubeMap = new LinkedHashMap<>(); Map<String, String> tubeMap = new LinkedHashMap<>();
for (Tube tube : request.getTube()) { Slot request = this.get(slot.getChamberNumber(), slot.getTube().get(0).getSlotNumber()); // TODO: 현재 단건 컨트롤, 추후 변경 필요
for (Tube tube : slot.getTube()) {
Map<String, Integer> tubeOffsetMap = this.tubeOffset(); Map<String, Integer> tubeOffsetMap = this.tubeOffset();
int tubeOffset = tubeOffsetMap.getOrDefault(tube.getSlotNumber(), 1); int tubeOffset = tubeOffsetMap.getOrDefault(request.getSlotNumber(), 1);
int tubeKey = Integer.parseInt(tube.getCode()) + tubeOffset; int tubeKey = Integer.parseInt(request.getTube().get(Integer.parseInt(tube.getCode())).getCode()) + tubeOffset;
tubeMap.put(String.valueOf(tubeKey), String.valueOf(request.getCommand().ordinal())); tubeMap.put(String.valueOf(tubeKey), String.valueOf(slot.getCommand().ordinal()));
} }
DeployRequest deployRequest = DeployRequest.builder() DeployRequest deployRequest = DeployRequest.builder()
.assetCode(request.getAssetCode()) .assetCode(slot.getAssetCode())
.appName("awx_collector") .appName("awx_collector") // TODO: appName 픽스되면 수정 필요
.commandType(CommandType.JSON) .commandType(CommandType.JSON)
.fileName("config.json")
.parameters(tubeMap) .parameters(tubeMap)
.build(); .build();
this.invokeDeployer(request.getAssetCode(), authorization, deployRequest); log.info("deployRequest: {}", deployRequest);
this.invokeDeployer(slot.getAssetCode(), authorization, deployRequest);
} }
@Override @Override
public void controlAll(String authorization, List<Slot> slots, Command command) { public void controlAll(String authorization, List<Slot> slots, Command command) {
log.info("[controlAll] chamberNumber: {}, command: {}", slots.get(0).getChamberNumber(), command); log.info("[controlAll] chamberNumber: {}, command: {}", slots.get(0).getChamberNumber(), command);
Set<String> assets = new HashSet<>();
Map<String, Map<String, Map<String, String>>> resultMap = new LinkedHashMap<>();
for (Slot slot : slots) { for (Slot slot : slots) {
String assetCode = slot.getAssetCode(); assets.add(slot.getAssetCode());
String slotNumber = slot.getSlotNumber();
List<Tube> tubes = slot.getTube();
Map<String, Map<String, String>> assetMap = resultMap.computeIfAbsent(assetCode, k -> new HashMap<>());
Map<String, String> slotMap = assetMap.computeIfAbsent(slotNumber, k -> new HashMap<>());
for (Tube tube : tubes) {
Map<String, Integer> tubeOffsetMap = this.tubeOffset();
int tubeOffset = tubeOffsetMap.getOrDefault(slotNumber, 1);
int offsetResult = Integer.parseInt(tube.getCode()) + tubeOffset;
slotMap.put(String.valueOf(offsetResult), String.valueOf(command.ordinal()));
} }
} assets.forEach(assetCode -> {
Map<String, String> parameterMap = new LinkedHashMap<>();
resultMap.forEach((assetCode, slot) -> slot.forEach((slotNumber, tube) -> { parameterMap.put("total", String.valueOf(command.ordinal()));
for (int i = 1; i <= 2; i++) {
DeployRequest deployRequest = DeployRequest.builder() DeployRequest deployRequest = DeployRequest.builder()
.assetCode(assetCode) .assetCode(assetCode)
.appName("awx_collector") .appName("awx_collector") // TODO
.commandType(CommandType.JSON) .commandType(CommandType.JSON)
.parameters(tube) .fileName("config.json")
.parameters(parameterMap)
.build(); .build();
log.info("deployRequest: {}", deployRequest);
this.invokeDeployer(assetCode, authorization, deployRequest); this.invokeDeployer(assetCode, authorization, deployRequest);
})); }
});
} }
@Override @Override

View File

@ -9,13 +9,15 @@ public class DeployRequest {
private String assetCode; private String assetCode;
private String appName; private String appName;
private String commandType; private String commandType;
private String fileName;
private String name; private String name;
private Map<String, String> parameters; private Map<String, String> parameters;
public DeployRequest(String assetCode, String appName, String commandType, String name, Map<String, String> parameters) { public DeployRequest(String assetCode, String appName, String commandType, String fileName, String name, Map<String, String> parameters) {
this.assetCode = assetCode; this.assetCode = assetCode;
this.appName = appName; this.appName = appName;
this.commandType = commandType; this.commandType = commandType;
this.fileName = fileName;
this.name = name; this.name = name;
this.parameters = parameters; this.parameters = parameters;
} }
@ -37,6 +39,10 @@ public class DeployRequest {
return commandType; return commandType;
} }
public String getFileName() {
return fileName;
}
public String getName() { public String getName() {
return name; return name;
} }
@ -51,6 +57,7 @@ public class DeployRequest {
"assetCode='" + assetCode + '\'' + "assetCode='" + assetCode + '\'' +
", appName='" + appName + '\'' + ", appName='" + appName + '\'' +
", commandType='" + commandType + '\'' + ", commandType='" + commandType + '\'' +
", fileName='" + fileName + '\'' +
", name='" + name + '\'' + ", name='" + name + '\'' +
", parameters=" + parameters + ", parameters=" + parameters +
'}'; '}';
@ -61,6 +68,7 @@ public class DeployRequest {
private String appName; private String appName;
private String commandType; private String commandType;
private String name; private String name;
private String fileName;
private Map<String, String> parameters; private Map<String, String> parameters;
private Builder() { private Builder() {
@ -86,13 +94,18 @@ public class DeployRequest {
return this; return this;
} }
public Builder fileName(String fileName) {
this.fileName = fileName;
return this;
}
public Builder parameters(Map<String, String> parameters) { public Builder parameters(Map<String, String> parameters) {
this.parameters = parameters; this.parameters = parameters;
return this; return this;
} }
public DeployRequest build() { public DeployRequest build() {
return new DeployRequest(assetCode, appName, commandType, name, parameters); return new DeployRequest(assetCode, appName, commandType, name, fileName, parameters);
} }
} }
} }

View File

@ -30,12 +30,12 @@ public class TubeController {
@PatchMapping("/chambers/{chamberNumber}/tube/toggle") @PatchMapping("/chambers/{chamberNumber}/tube/toggle")
public void toggle(@RequestHeader("Authorization") String authorization, @PathVariable String chamberNumber, @RequestBody Slot slot) { public void toggle(@RequestHeader("Authorization") String authorization, @PathVariable String chamberNumber, @RequestBody Slot slot) {
log.info("[toggle] chamberNumber: {}, slot: {}", chamberNumber, slot); log.info("[toggle] chamberNumber: {}, slot: {}", chamberNumber, slot);
List<Slot> slots = tubeService.get(chamberNumber);
if (slots.isEmpty()) throw new NoSuchElementException(chamberNumber);
slot.setChamberNumber(chamberNumber); slot.setChamberNumber(chamberNumber);
if (slot.getTube() != null) { if (slot.getTube() != null) {
tubeService.controlByTubeCode(authorization, slot); tubeService.controlByTubeCode(authorization, slot);
} else { } else {
List<Slot> slots = tubeService.get(chamberNumber);
if (slots.isEmpty()) throw new NoSuchElementException(chamberNumber);
tubeService.controlAll(authorization, slots, slot.getCommand()); tubeService.controlAll(authorization, slots, slot.getCommand());
} }
} }