commit
c9046a0fb4
|
@ -5,7 +5,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = 'inc.sdt.controlcentermanagement'
|
||||
version = '0.0.4'
|
||||
version = '0.0.5'
|
||||
|
||||
java {
|
||||
sourceCompatibility = '17'
|
||||
|
|
|
@ -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
|
||||
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 push 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.5
|
|
@ -9,10 +9,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author sunae.jang (sa.jang@sdt.inc)
|
||||
|
@ -44,57 +41,51 @@ class DefaultTubeService implements TubeService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void controlByTubeCode(String authorization, Slot request) {
|
||||
log.info("[controlByTubeCode] request: {}", request);
|
||||
public void controlByTubeCode(String authorization, Slot slot) {
|
||||
log.info("[controlByTubeCode] slot: {}", slot);
|
||||
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();
|
||||
int tubeOffset = tubeOffsetMap.getOrDefault(tube.getSlotNumber(), 1);
|
||||
int tubeKey = Integer.parseInt(tube.getCode()) + tubeOffset;
|
||||
tubeMap.put(String.valueOf(tubeKey), String.valueOf(request.getCommand().ordinal()));
|
||||
int tubeOffset = tubeOffsetMap.getOrDefault(request.getSlotNumber(), 1);
|
||||
int tubeKey = Integer.parseInt(request.getTube().get(Integer.parseInt(tube.getCode())).getCode()) + tubeOffset;
|
||||
tubeMap.put(String.valueOf(tubeKey), String.valueOf(slot.getCommand().ordinal()));
|
||||
}
|
||||
|
||||
DeployRequest deployRequest = DeployRequest.builder()
|
||||
.assetCode(request.getAssetCode())
|
||||
.appName("awx_collector")
|
||||
.assetCode(slot.getAssetCode())
|
||||
.appName("awx_collector") // TODO: appName 픽스되면 수정 필요
|
||||
.commandType(CommandType.JSON)
|
||||
.fileName("config.json")
|
||||
.parameters(tubeMap)
|
||||
.build();
|
||||
|
||||
this.invokeDeployer(request.getAssetCode(), authorization, deployRequest);
|
||||
log.info("deployRequest: {}", deployRequest);
|
||||
this.invokeDeployer(slot.getAssetCode(), authorization, deployRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void controlAll(String authorization, List<Slot> slots, Command command) {
|
||||
log.info("[controlAll] chamberNumber: {}, command: {}", slots.get(0).getChamberNumber(), command);
|
||||
|
||||
Map<String, Map<String, Map<String, String>>> resultMap = new LinkedHashMap<>();
|
||||
Set<String> assets = new HashSet<>();
|
||||
for (Slot slot : slots) {
|
||||
String assetCode = 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.add(slot.getAssetCode());
|
||||
}
|
||||
|
||||
resultMap.forEach((assetCode, slot) -> slot.forEach((slotNumber, tube) -> {
|
||||
DeployRequest deployRequest = DeployRequest.builder()
|
||||
.assetCode(assetCode)
|
||||
.appName("awx_collector")
|
||||
.commandType(CommandType.JSON)
|
||||
.parameters(tube)
|
||||
.build();
|
||||
|
||||
this.invokeDeployer(assetCode, authorization, deployRequest);
|
||||
}));
|
||||
assets.forEach(assetCode -> {
|
||||
Map<String, String> parameterMap = new LinkedHashMap<>();
|
||||
parameterMap.put("total", String.valueOf(command.ordinal()));
|
||||
for (int i = 1; i <= 2; i++) {
|
||||
DeployRequest deployRequest = DeployRequest.builder()
|
||||
.assetCode(assetCode)
|
||||
.appName("awx_collector") // TODO
|
||||
.commandType(CommandType.JSON)
|
||||
.fileName("config.json")
|
||||
.parameters(parameterMap)
|
||||
.build();
|
||||
log.info("deployRequest: {}", deployRequest);
|
||||
this.invokeDeployer(assetCode, authorization, deployRequest);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,13 +9,15 @@ public class DeployRequest {
|
|||
private String assetCode;
|
||||
private String appName;
|
||||
private String commandType;
|
||||
private String fileName;
|
||||
private String name;
|
||||
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.appName = appName;
|
||||
this.commandType = commandType;
|
||||
this.fileName = fileName;
|
||||
this.name = name;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
@ -37,6 +39,10 @@ public class DeployRequest {
|
|||
return commandType;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -51,6 +57,7 @@ public class DeployRequest {
|
|||
"assetCode='" + assetCode + '\'' +
|
||||
", appName='" + appName + '\'' +
|
||||
", commandType='" + commandType + '\'' +
|
||||
", fileName='" + fileName + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", parameters=" + parameters +
|
||||
'}';
|
||||
|
@ -61,6 +68,7 @@ public class DeployRequest {
|
|||
private String appName;
|
||||
private String commandType;
|
||||
private String name;
|
||||
private String fileName;
|
||||
private Map<String, String> parameters;
|
||||
|
||||
private Builder() {
|
||||
|
@ -86,13 +94,18 @@ public class DeployRequest {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder fileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder parameters(Map<String, String> parameters) {
|
||||
this.parameters = parameters;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeployRequest build() {
|
||||
return new DeployRequest(assetCode, appName, commandType, name, parameters);
|
||||
return new DeployRequest(assetCode, appName, commandType, name, fileName, parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,12 +30,12 @@ public class TubeController {
|
|||
@PatchMapping("/chambers/{chamberNumber}/tube/toggle")
|
||||
public void toggle(@RequestHeader("Authorization") String authorization, @PathVariable String chamberNumber, @RequestBody Slot slot) {
|
||||
log.info("[toggle] chamberNumber: {}, slot: {}", chamberNumber, slot);
|
||||
List<Slot> slots = tubeService.get(chamberNumber);
|
||||
if (slots.isEmpty()) throw new NoSuchElementException(chamberNumber);
|
||||
slot.setChamberNumber(chamberNumber);
|
||||
if (slot.getTube() != null) {
|
||||
tubeService.controlByTubeCode(authorization, slot);
|
||||
} else {
|
||||
List<Slot> slots = tubeService.get(chamberNumber);
|
||||
if (slots.isEmpty()) throw new NoSuchElementException(chamberNumber);
|
||||
tubeService.controlAll(authorization, slots, slot.getCommand());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue