- 앱 배포 docker MQTT 메시지 페이로드 수정

This commit is contained in:
hyunjujeong 2023-08-31 13:20:52 +09:00
parent f9af91c688
commit f30f914283
6 changed files with 26 additions and 42 deletions

View File

@ -16,7 +16,7 @@ import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import java.util.HashMap;
import java.util.List;
import java.util.LinkedHashMap;
import java.util.Optional;
@Service
@ -46,7 +46,7 @@ public class DefaultDeployerService implements DeployerService{
log.info("[publish] deployMessage = {}, assetCode = {}", deployMessage, assetCode);
final String url = filePath + deployMessage.getFileId();
final String deviceType = "ecn";
HashMap<String, String> cmdInfo = new HashMap<>();
HashMap<String, Object> cmdInfo = new HashMap<>();
String cmdType = "";
try {
@ -62,18 +62,17 @@ public class DefaultDeployerService implements DeployerService{
}*/
if(!deployMessage.getCommand().isEmpty()) {
cmdInfo.put("Cmd", deployMessage.getCommand());
cmdInfo.put("FileUrl", url);
cmdInfo.put("FileType", "python");
cmdInfo.put("cmd", deployMessage.getCommand());
cmdInfo.put("fileUrl", url);
cmdInfo.put("fileType", "python");
cmdType = String.valueOf(CommandType.deploy);
}
if(!deployMessage.getEnv().isEmpty()) {
cmdInfo.put("Cmd", "run");
cmdInfo.put("Image", url);
cmdInfo.put("Name", deployMessage.getName());
cmdInfo.put("Env", convertToJson(deployMessage.getEnv()));
cmdInfo.put("Ports", convertToJson(deployMessage.getPorts()));
cmdInfo.put("cmd", "run");
cmdInfo.put("image", url);
cmdInfo.put("name", deployMessage.getName());
cmdInfo.put("options", deployMessage.getEnv());
cmdType = String.valueOf(CommandType.docker);
}

View File

@ -1,13 +1,11 @@
package inc.sdt.blokworks.devicedeployer.domain;
import java.util.List;
import java.util.Map;
import java.util.LinkedHashMap;
public class OutboundMessage {
private String fileId;
private String name;
private Map<String, Object> env;
private List<Map<String, String>> ports;
private LinkedHashMap<String, Object> env;
private String command;
private String requestId;
private String deviceType;
@ -23,14 +21,10 @@ public class OutboundMessage {
return name;
}
public Map<String, Object> getEnv() {
public LinkedHashMap<String, Object> getEnv() {
return env;
}
public List<Map<String, String>> getPorts() {
return ports;
}
public String getCommand() {
return command;
}
@ -57,7 +51,6 @@ public class OutboundMessage {
"fileId='" + fileId + '\'' +
", name='" + name + '\'' +
", env=" + env +
", ports=" + ports +
", command='" + command + '\'' +
", requestId='" + requestId + '\'' +
", deviceType='" + deviceType + '\'' +
@ -72,8 +65,7 @@ public class OutboundMessage {
public static final class Builder {
private String fileId;
private String name;
private Map<String, Object> env;
private List<Map<String, String>> ports;
private LinkedHashMap<String, Object> env;
private String command;
private String requestId;
private String deviceType;
@ -89,16 +81,11 @@ public class OutboundMessage {
return this;
}
public Builder env(Map<String, Object> env) {
public Builder env(LinkedHashMap<String, Object> env) {
this.env = env;
return this;
}
public Builder ports(List<Map<String, String>> ports) {
this.ports = ports;
return this;
}
public Builder command(String command) {
this.command = command;
return this;
@ -126,7 +113,6 @@ public class OutboundMessage {
deployMessage.env = this.env;
deployMessage.command = this.command;
deployMessage.requestId = this.requestId;
deployMessage.ports = this.ports;
deployMessage.deviceType = this.deviceType;
deployMessage.commandType = this.commandType;
return deployMessage;

View File

@ -3,11 +3,11 @@ package inc.sdt.blokworks.devicedeployer.infrastructure.mqtt;
import java.util.HashMap;
public record OutboundMessagePayload(
HashMap<String, String> CmdInfo,
String CmdType,
HashMap<String, Object> cmdInfo,
String cmdType,
String AssetCode,
String DeviceType,
String RequestId
String assetCode,
String deviceType,
String requestId
) {
}

View File

@ -6,10 +6,12 @@ import inc.sdt.blokworks.devicedeployer.infrastructure.amqp.ResourceMapping;
import jakarta.validation.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.LinkedHashMap;
import java.util.UUID;
@RestController

View File

@ -4,6 +4,7 @@ import inc.sdt.blokworks.devicedeployer.domain.CommandType;
import org.wildfly.common.annotation.NotNull;
import java.util.HashMap;
import java.util.LinkedHashMap;
record OutboundMessageResource(
@NotNull
@ -11,7 +12,7 @@ record OutboundMessageResource(
@NotNull
String name,
String command,
String env,
LinkedHashMap<String, Object> env,
String deviceType,
CommandType commandType
) {

View File

@ -9,10 +9,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Component
public class OutboundMessageResourceConverter {
@ -23,14 +20,13 @@ public class OutboundMessageResourceConverter {
}
public OutboundMessage fromResource(OutboundMessageResource resource) {
final Map<String, Object> cmdInfo = resource.env().isEmpty() ? new HashMap<>() : convertToMap(resource.env());
//final Map<String, Object> cmdInfo = resource.env().isEmpty() ? new HashMap<>() : convertToMap(resource.env());
return OutboundMessage.builder()
.fileId(resource.fileId())
.name(resource.name())
.command(resource.command())
.env(cmdInfo.isEmpty() ? new HashMap<>() : (Map<String, Object>) cmdInfo.get("env"))
.ports(cmdInfo.isEmpty() ? new ArrayList<>() : (List<Map<String, String>>) cmdInfo.get("ports"))
.env(resource.env() != null ? resource.env() : new LinkedHashMap<>())
.deviceType(resource.deviceType())
.commandType(resource.commandType() == null ? CommandType.deploy : resource.commandType())
.build();