- Config 파일 변경 command 추가
This commit is contained in:
parent
f30f914283
commit
5401b6687f
|
@ -0,0 +1,10 @@
|
||||||
|
package inc.sdt.blokworks.devicedeployer.application;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
public class BashCommand implements CommandInfo{
|
||||||
|
@Override
|
||||||
|
public LinkedHashMap<String, Object> put() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package inc.sdt.blokworks.devicedeployer.application;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
public interface CommandInfo {
|
||||||
|
LinkedHashMap<String, Object> put();
|
||||||
|
}
|
|
@ -15,7 +15,6 @@ import org.springframework.data.domain.Page;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@ -42,46 +41,47 @@ public class DefaultDeployerService implements DeployerService{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void publish(OutboundMessage deployMessage, String assetCode) {
|
public void publish(OutboundMessage outboundMessage, String assetCode) {
|
||||||
log.info("[publish] deployMessage = {}, assetCode = {}", deployMessage, assetCode);
|
log.info("[publish] deployMessage = {}, assetCode = {}", outboundMessage, assetCode);
|
||||||
final String url = filePath + deployMessage.getFileId();
|
final String url = filePath + outboundMessage.getFileId();
|
||||||
final String deviceType = "ecn";
|
final DeviceType deviceType = outboundMessage.getDeviceType();
|
||||||
HashMap<String, Object> cmdInfo = new HashMap<>();
|
LinkedHashMap<String, Object> commandInfo = new LinkedHashMap<>();
|
||||||
String cmdType = "";
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
/*switch (deployMessage.getCommandType()) {
|
switch (outboundMessage.getCommandType()) {
|
||||||
case bash:
|
case bash -> commandInfo.put("cmd", outboundMessage.getCommand());
|
||||||
break;
|
case systemd -> {
|
||||||
case systemd:
|
commandInfo.put("cmd", outboundMessage.getCommand());
|
||||||
break;
|
commandInfo.put("service", outboundMessage.getName());
|
||||||
case docker:
|
}
|
||||||
break;
|
case docker -> {
|
||||||
case deploy:
|
commandInfo.put("cmd", "run");
|
||||||
break;
|
commandInfo.put("appName", "");
|
||||||
}*/
|
commandInfo.put("name", outboundMessage.getName());
|
||||||
|
commandInfo.put("image", outboundMessage.getImage());
|
||||||
if(!deployMessage.getCommand().isEmpty()) {
|
commandInfo.put("options", outboundMessage.getOptions());
|
||||||
cmdInfo.put("cmd", deployMessage.getCommand());
|
}
|
||||||
cmdInfo.put("fileUrl", url);
|
case deploy -> {
|
||||||
cmdInfo.put("fileType", "python");
|
commandInfo.put("cmd", outboundMessage.getCommand());
|
||||||
cmdType = String.valueOf(CommandType.deploy);
|
commandInfo.put("appName", outboundMessage.getName());
|
||||||
|
commandInfo.put("fileUrl", url);
|
||||||
|
commandInfo.put("fileType", outboundMessage.getFileType());
|
||||||
|
}
|
||||||
|
case json -> {
|
||||||
|
commandInfo.put("cmd", String.valueOf(outboundMessage.getCommandType()));
|
||||||
|
commandInfo.put("appName", outboundMessage.getName());
|
||||||
|
commandInfo.put("parameter", outboundMessage.getParameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!deployMessage.getEnv().isEmpty()) {
|
|
||||||
cmdInfo.put("cmd", "run");
|
|
||||||
cmdInfo.put("image", url);
|
|
||||||
cmdInfo.put("name", deployMessage.getName());
|
|
||||||
cmdInfo.put("options", deployMessage.getEnv());
|
|
||||||
cmdType = String.valueOf(CommandType.docker);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OutboundMessagePayload payload = new OutboundMessagePayload(
|
OutboundMessagePayload payload = new OutboundMessagePayload(
|
||||||
cmdInfo,
|
commandInfo,
|
||||||
cmdType,
|
outboundMessage.getCommandType(),
|
||||||
assetCode,
|
outboundMessage.getSubCommandType(),
|
||||||
deviceType,
|
deviceType,
|
||||||
deployMessage.getRequestId()
|
assetCode,
|
||||||
|
outboundMessage.getRequestId()
|
||||||
);
|
);
|
||||||
|
|
||||||
byte[] bytes = objectMapper.writeValueAsBytes(payload);
|
byte[] bytes = objectMapper.writeValueAsBytes(payload);
|
||||||
|
|
|
@ -4,5 +4,6 @@ public enum CommandType {
|
||||||
bash,
|
bash,
|
||||||
systemd,
|
systemd,
|
||||||
docker,
|
docker,
|
||||||
deploy
|
deploy,
|
||||||
|
json
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,20 @@ public class DeployRequest {
|
||||||
private String assetCode;
|
private String assetCode;
|
||||||
private String appName;
|
private String appName;
|
||||||
private OperationType operationType;
|
private OperationType operationType;
|
||||||
|
private DeviceType deviceType;
|
||||||
|
private CommandType commandType;
|
||||||
|
private SubCommandType subCommandType;
|
||||||
|
|
||||||
protected DeployRequest() {}
|
protected DeployRequest() {}
|
||||||
|
|
||||||
public DeployRequest(String requestId, String assetCode, String appName, OperationType operationType) {
|
public DeployRequest(String requestId, String assetCode, String appName, OperationType operationType, DeviceType deviceType, CommandType commandType, SubCommandType subCommandType) {
|
||||||
this.requestId = requestId;
|
this.requestId = requestId;
|
||||||
this.assetCode = assetCode;
|
this.assetCode = assetCode;
|
||||||
this.appName = appName;
|
this.appName = appName;
|
||||||
this.operationType = operationType;
|
this.operationType = operationType;
|
||||||
|
this.deviceType = deviceType;
|
||||||
|
this.commandType = commandType;
|
||||||
|
this.subCommandType = subCommandType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRequestId() {
|
public String getRequestId() {
|
||||||
|
@ -31,13 +37,28 @@ public class DeployRequest {
|
||||||
return operationType;
|
return operationType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DeviceType getDeviceType() {
|
||||||
|
return deviceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandType getCommandType() {
|
||||||
|
return commandType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SubCommandType getSubCommandType() {
|
||||||
|
return subCommandType;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "DeployRequest{" +
|
return "DeployRequest{" +
|
||||||
"requestId='" + requestId + '\'' +
|
"requestId='" + requestId + '\'' +
|
||||||
", assetCode='" + assetCode + '\'' +
|
", assetCode='" + assetCode + '\'' +
|
||||||
", appName='" + appName + '\'' +
|
", appName='" + appName + '\'' +
|
||||||
", operationType='" + operationType + '\'' +
|
", operationType=" + operationType +
|
||||||
|
", deviceType=" + deviceType +
|
||||||
|
", commandType=" + commandType +
|
||||||
|
", subCommandType=" + subCommandType +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +71,9 @@ public class DeployRequest {
|
||||||
private String assetCode;
|
private String assetCode;
|
||||||
private String appName;
|
private String appName;
|
||||||
private OperationType operationType;
|
private OperationType operationType;
|
||||||
|
private DeviceType deviceType;
|
||||||
|
private CommandType commandType;
|
||||||
|
private SubCommandType subCommandType;
|
||||||
|
|
||||||
public Builder requestId(String requestId) {
|
public Builder requestId(String requestId) {
|
||||||
this.requestId = requestId;
|
this.requestId = requestId;
|
||||||
|
@ -71,12 +95,30 @@ public class DeployRequest {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder deviceType(DeviceType deviceType) {
|
||||||
|
this.deviceType = deviceType;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder commandType(CommandType commandType) {
|
||||||
|
this.commandType = commandType;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder subCommandType(SubCommandType subCommandType) {
|
||||||
|
this.subCommandType = subCommandType;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public DeployRequest build() {
|
public DeployRequest build() {
|
||||||
DeployRequest deployRequest = new DeployRequest();
|
DeployRequest deployRequest = new DeployRequest();
|
||||||
deployRequest.requestId = this.requestId;
|
deployRequest.requestId = this.requestId;
|
||||||
deployRequest.assetCode = this.assetCode;
|
deployRequest.assetCode = this.assetCode;
|
||||||
deployRequest.appName = this.appName;
|
deployRequest.appName = this.appName;
|
||||||
deployRequest.operationType = this.operationType;
|
deployRequest.operationType = this.operationType;
|
||||||
|
deployRequest.deviceType = this.deviceType;
|
||||||
|
deployRequest.commandType = this.commandType;
|
||||||
|
deployRequest.subCommandType = this.subCommandType;
|
||||||
return deployRequest;
|
return deployRequest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package inc.sdt.blokworks.devicedeployer.domain;
|
||||||
|
|
||||||
|
public enum DeviceType {
|
||||||
|
ecn,
|
||||||
|
nodeq
|
||||||
|
}
|
|
@ -4,12 +4,17 @@ import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class OutboundMessage {
|
public class OutboundMessage {
|
||||||
private String fileId;
|
private String fileId;
|
||||||
|
private String fileType;
|
||||||
|
private String appName;
|
||||||
private String name;
|
private String name;
|
||||||
private LinkedHashMap<String, Object> env;
|
private String image;
|
||||||
|
private LinkedHashMap<String, Object> options;
|
||||||
private String command;
|
private String command;
|
||||||
private String requestId;
|
private String requestId;
|
||||||
private String deviceType;
|
private DeviceType deviceType;
|
||||||
private CommandType commandType;
|
private CommandType commandType;
|
||||||
|
private SubCommandType subCommandType;
|
||||||
|
private LinkedHashMap<String, String> parameters;
|
||||||
|
|
||||||
protected OutboundMessage() {}
|
protected OutboundMessage() {}
|
||||||
|
|
||||||
|
@ -17,12 +22,24 @@ public class OutboundMessage {
|
||||||
return fileId;
|
return fileId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFileType() {
|
||||||
|
return fileType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppName() {
|
||||||
|
return appName;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinkedHashMap<String, Object> getEnv() {
|
public String getImage() {
|
||||||
return env;
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedHashMap<String, Object> getOptions() {
|
||||||
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCommand() {
|
public String getCommand() {
|
||||||
|
@ -37,7 +54,7 @@ public class OutboundMessage {
|
||||||
return requestId;
|
return requestId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDeviceType() {
|
public DeviceType getDeviceType() {
|
||||||
return deviceType;
|
return deviceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,16 +62,29 @@ public class OutboundMessage {
|
||||||
return commandType;
|
return commandType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SubCommandType getSubCommandType() {
|
||||||
|
return subCommandType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedHashMap<String, String> getParameters() {
|
||||||
|
return parameters;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "OutboundMessage{" +
|
return "OutboundMessage{" +
|
||||||
"fileId='" + fileId + '\'' +
|
"fileId='" + fileId + '\'' +
|
||||||
|
", fileType='" + fileType + '\'' +
|
||||||
|
", appName='" + appName + '\'' +
|
||||||
", name='" + name + '\'' +
|
", name='" + name + '\'' +
|
||||||
", env=" + env +
|
", image='" + image + '\'' +
|
||||||
|
", options=" + options +
|
||||||
", command='" + command + '\'' +
|
", command='" + command + '\'' +
|
||||||
", requestId='" + requestId + '\'' +
|
", requestId='" + requestId + '\'' +
|
||||||
", deviceType='" + deviceType + '\'' +
|
", deviceType=" + deviceType +
|
||||||
", commandType=" + commandType +
|
", commandType=" + commandType +
|
||||||
|
", subCommandType=" + subCommandType +
|
||||||
|
", parameters=" + parameters +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,25 +94,45 @@ public class OutboundMessage {
|
||||||
|
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
private String fileId;
|
private String fileId;
|
||||||
|
private String fileType;
|
||||||
|
private String appName;
|
||||||
private String name;
|
private String name;
|
||||||
private LinkedHashMap<String, Object> env;
|
private String image;
|
||||||
|
private LinkedHashMap<String, Object> options;
|
||||||
private String command;
|
private String command;
|
||||||
private String requestId;
|
private String requestId;
|
||||||
private String deviceType;
|
private DeviceType deviceType;
|
||||||
private CommandType commandType;
|
private CommandType commandType;
|
||||||
|
private SubCommandType subCommandType;
|
||||||
|
private LinkedHashMap<String, String> parameters;
|
||||||
|
|
||||||
public Builder fileId(String fileId) {
|
public Builder fileId(String fileId) {
|
||||||
this.fileId = fileId;
|
this.fileId = fileId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder fileType(String fileType) {
|
||||||
|
this.fileType = fileType;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder appName(String appName) {
|
||||||
|
this.appName = appName;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Builder name(String name) {
|
public Builder name(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder env(LinkedHashMap<String, Object> env) {
|
public Builder image(String image) {
|
||||||
this.env = env;
|
this.image = image;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder options(LinkedHashMap<String, Object> options) {
|
||||||
|
this.options = options;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +146,7 @@ public class OutboundMessage {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder deviceType(String deviceType) {
|
public Builder deviceType(DeviceType deviceType) {
|
||||||
this.deviceType = deviceType;
|
this.deviceType = deviceType;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -106,15 +156,30 @@ public class OutboundMessage {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder subCommandType(SubCommandType subCommandType) {
|
||||||
|
this.subCommandType = subCommandType;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder parameters(LinkedHashMap<String, String> parameters) {
|
||||||
|
this.parameters = parameters;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public OutboundMessage build() {
|
public OutboundMessage build() {
|
||||||
OutboundMessage deployMessage = new OutboundMessage();
|
OutboundMessage deployMessage = new OutboundMessage();
|
||||||
deployMessage.fileId = this.fileId;
|
deployMessage.fileId = this.fileId;
|
||||||
|
deployMessage.fileType = this.fileType;
|
||||||
|
deployMessage.appName = this.appName;
|
||||||
deployMessage.name = this.name;
|
deployMessage.name = this.name;
|
||||||
deployMessage.env = this.env;
|
deployMessage.image = this.image;
|
||||||
|
deployMessage.options = this.options;
|
||||||
deployMessage.command = this.command;
|
deployMessage.command = this.command;
|
||||||
deployMessage.requestId = this.requestId;
|
deployMessage.requestId = this.requestId;
|
||||||
deployMessage.deviceType = this.deviceType;
|
deployMessage.deviceType = this.deviceType;
|
||||||
deployMessage.commandType = this.commandType;
|
deployMessage.commandType = this.commandType;
|
||||||
|
deployMessage.subCommandType = this.subCommandType;
|
||||||
|
deployMessage.parameters = this.parameters;
|
||||||
return deployMessage;
|
return deployMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package inc.sdt.blokworks.devicedeployer.domain;
|
||||||
|
|
||||||
|
public enum SubCommandType {
|
||||||
|
systemd,
|
||||||
|
docker
|
||||||
|
}
|
|
@ -1,13 +1,17 @@
|
||||||
package inc.sdt.blokworks.devicedeployer.infrastructure.mqtt;
|
package inc.sdt.blokworks.devicedeployer.infrastructure.mqtt;
|
||||||
|
|
||||||
|
import inc.sdt.blokworks.devicedeployer.domain.CommandType;
|
||||||
|
import inc.sdt.blokworks.devicedeployer.domain.DeviceType;
|
||||||
|
import inc.sdt.blokworks.devicedeployer.domain.SubCommandType;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public record OutboundMessagePayload(
|
public record OutboundMessagePayload(
|
||||||
HashMap<String, Object> cmdInfo,
|
HashMap<String, Object> cmdInfo,
|
||||||
String cmdType,
|
CommandType cmdType,
|
||||||
|
SubCommandType subCmdType,
|
||||||
|
DeviceType deviceType,
|
||||||
String assetCode,
|
String assetCode,
|
||||||
String deviceType,
|
|
||||||
String requestId
|
String requestId
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package inc.sdt.blokworks.devicedeployer.infrastructure.relational;
|
package inc.sdt.blokworks.devicedeployer.infrastructure.relational;
|
||||||
|
|
||||||
|
import inc.sdt.blokworks.devicedeployer.domain.CommandType;
|
||||||
|
import inc.sdt.blokworks.devicedeployer.domain.DeviceType;
|
||||||
import inc.sdt.blokworks.devicedeployer.domain.OperationType;
|
import inc.sdt.blokworks.devicedeployer.domain.OperationType;
|
||||||
|
import inc.sdt.blokworks.devicedeployer.domain.SubCommandType;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
@Entity(name = "deploy_request")
|
@Entity(name = "deploy_request")
|
||||||
|
@ -18,14 +21,26 @@ public class DeployRequestEntity {
|
||||||
@Enumerated(EnumType.STRING)
|
@Enumerated(EnumType.STRING)
|
||||||
@Column(name = "operation_type", length = 255)
|
@Column(name = "operation_type", length = 255)
|
||||||
private OperationType operationType;
|
private OperationType operationType;
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
@Column(name = "device_type", length = 255)
|
||||||
|
private DeviceType deviceType;
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
@Column(name = "command_type", length = 255)
|
||||||
|
private CommandType commandType;
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
@Column(name = "sub_command_type", length = 255)
|
||||||
|
private SubCommandType subCommandType;
|
||||||
|
|
||||||
protected DeployRequestEntity() {}
|
protected DeployRequestEntity() {}
|
||||||
|
|
||||||
public DeployRequestEntity(String requestId, String assetCode, String appName, OperationType operationType) {
|
public DeployRequestEntity(String requestId, String assetCode, String appName, OperationType operationType, DeviceType deviceType, CommandType commandType, SubCommandType subCommandType) {
|
||||||
this.requestId = requestId;
|
this.requestId = requestId;
|
||||||
this.assetCode = assetCode;
|
this.assetCode = assetCode;
|
||||||
this.appName = appName;
|
this.appName = appName;
|
||||||
this.operationType = operationType;
|
this.operationType = operationType;
|
||||||
|
this.deviceType = deviceType;
|
||||||
|
this.commandType = commandType;
|
||||||
|
this.subCommandType = subCommandType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
@ -47,4 +62,16 @@ public class DeployRequestEntity {
|
||||||
public OperationType getOperationType() {
|
public OperationType getOperationType() {
|
||||||
return operationType;
|
return operationType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DeviceType getDeviceType() {
|
||||||
|
return deviceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandType getCommandType() {
|
||||||
|
return commandType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SubCommandType getSubCommandType() {
|
||||||
|
return subCommandType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,10 @@ public class DeployRequestRelationalRepository implements DeployRequestRepositor
|
||||||
deployRequest.getRequestId(),
|
deployRequest.getRequestId(),
|
||||||
deployRequest.getAssetCode(),
|
deployRequest.getAssetCode(),
|
||||||
deployRequest.getAppName(),
|
deployRequest.getAppName(),
|
||||||
deployRequest.getOperationType()
|
deployRequest.getOperationType(),
|
||||||
|
deployRequest.getDeviceType(),
|
||||||
|
deployRequest.getCommandType(),
|
||||||
|
deployRequest.getSubCommandType()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +52,9 @@ public class DeployRequestRelationalRepository implements DeployRequestRepositor
|
||||||
.assetCode(entity.getAssetCode())
|
.assetCode(entity.getAssetCode())
|
||||||
.appName(entity.getAppName())
|
.appName(entity.getAppName())
|
||||||
.operationType(entity.getOperationType())
|
.operationType(entity.getOperationType())
|
||||||
|
.deviceType(entity.getDeviceType())
|
||||||
|
.commandType(entity.getCommandType())
|
||||||
|
.subCommandType(entity.getSubCommandType())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,16 +33,16 @@ public class DeployerController {
|
||||||
/**
|
/**
|
||||||
* 앱 배포 명령
|
* 앱 배포 명령
|
||||||
* @param assetCode 자산 코드
|
* @param assetCode 자산 코드
|
||||||
* @param assetAppResource 배포하려는 앱의 정보
|
* @param resource 배포하려는 앱의 정보
|
||||||
*/
|
*/
|
||||||
@ResourceMapping(name = "Deploy_App", method = "POST", uri = "/assets/{code}/apps", description = "앱 배포 명령")
|
@ResourceMapping(name = "Deploy_App", method = "POST", uri = "/assets/{code}/apps", description = "앱 배포 명령")
|
||||||
@ResponseStatus(HttpStatus.CREATED)
|
@ResponseStatus(HttpStatus.CREATED)
|
||||||
@PostMapping("/assets/{assetCode}/apps")
|
@PostMapping("/assets/{assetCode}/apps")
|
||||||
public void deploy(@PathVariable String assetCode,
|
public void deploy(@PathVariable String assetCode,
|
||||||
@Valid @RequestBody OutboundMessageResource assetAppResource) {
|
@Valid @RequestBody OutboundMessageResource resource) {
|
||||||
log.info("[deploy] assetCode = {}, assetAppResource = {}", assetCode, assetAppResource);
|
log.info("[deploy] assetCode = {}, resource = {}", assetCode, resource);
|
||||||
String requestId = UUID.randomUUID().toString();
|
String requestId = UUID.randomUUID().toString();
|
||||||
OutboundMessage outboundMessage = outboundMessageResourceConverter.fromResource(assetAppResource);
|
OutboundMessage outboundMessage = outboundMessageResourceConverter.fromResource(resource);
|
||||||
outboundMessage.setRequestId(requestId);
|
outboundMessage.setRequestId(requestId);
|
||||||
|
|
||||||
DeployRequest deployRequest = DeployRequest.builder()
|
DeployRequest deployRequest = DeployRequest.builder()
|
||||||
|
@ -50,6 +50,9 @@ public class DeployerController {
|
||||||
.assetCode(assetCode)
|
.assetCode(assetCode)
|
||||||
.appName(outboundMessage.getName())
|
.appName(outboundMessage.getName())
|
||||||
.operationType(OperationType.DEPLOY)
|
.operationType(OperationType.DEPLOY)
|
||||||
|
.deviceType(resource.deviceType())
|
||||||
|
.commandType(resource.commandType())
|
||||||
|
.subCommandType(resource.subCommandType())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
DeployRequest request = deployerService.save(deployRequest);
|
DeployRequest request = deployerService.save(deployRequest);
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class MqttMessageHandler {
|
||||||
void handleMessage(Message<String> message) {
|
void handleMessage(Message<String> message) {
|
||||||
log.info("[handleMessage] message={}", message);
|
log.info("[handleMessage] message={}", message);
|
||||||
|
|
||||||
if(!message.getPayload().contains("pid")) {
|
/*if(!message.getPayload().contains("pid")) {
|
||||||
//String topic = String.valueOf(message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC));
|
//String topic = String.valueOf(message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC));
|
||||||
//String id = topic.split("/")[4];
|
//String id = topic.split("/")[4];
|
||||||
|
|
||||||
|
@ -54,8 +54,18 @@ public class MqttMessageHandler {
|
||||||
processMessagePayloadConverter.convertFromByte(message.getPayload(), InboundProcessMessagePayload.class)
|
processMessagePayloadConverter.convertFromByte(message.getPayload(), InboundProcessMessagePayload.class)
|
||||||
.flatMap(processService)
|
.flatMap(processService)
|
||||||
.subscribe();
|
.subscribe();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
deployMessagePayloadConverter.convertFromByte(message.getPayload(), InboundDeployMessagePayload.class)
|
||||||
|
.map(p -> new InboundDeployMessagePayload(
|
||||||
|
p.assetCode(),
|
||||||
|
p.deviceType(),
|
||||||
|
p.status(),
|
||||||
|
p.result(),
|
||||||
|
p.requestId()
|
||||||
|
))
|
||||||
|
.flatMap(deployerService)
|
||||||
|
.subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,25 @@
|
||||||
package inc.sdt.blokworks.devicedeployer.presentation;
|
package inc.sdt.blokworks.devicedeployer.presentation;
|
||||||
|
|
||||||
import inc.sdt.blokworks.devicedeployer.domain.CommandType;
|
import inc.sdt.blokworks.devicedeployer.domain.CommandType;
|
||||||
|
import inc.sdt.blokworks.devicedeployer.domain.DeviceType;
|
||||||
|
import inc.sdt.blokworks.devicedeployer.domain.SubCommandType;
|
||||||
import org.wildfly.common.annotation.NotNull;
|
import org.wildfly.common.annotation.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
record OutboundMessageResource(
|
record OutboundMessageResource(
|
||||||
@NotNull
|
@NotNull
|
||||||
String fileId,
|
String fileId,
|
||||||
|
String fileType,
|
||||||
@NotNull
|
@NotNull
|
||||||
String name,
|
String name,
|
||||||
|
String image,
|
||||||
String command,
|
String command,
|
||||||
LinkedHashMap<String, Object> env,
|
DeviceType deviceType,
|
||||||
String deviceType,
|
CommandType commandType,
|
||||||
CommandType commandType
|
SubCommandType subCommandType,
|
||||||
|
LinkedHashMap<String, Object> options,
|
||||||
|
LinkedHashMap<String, String> parameters
|
||||||
) {
|
) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,44 +1,27 @@
|
||||||
package inc.sdt.blokworks.devicedeployer.presentation;
|
package inc.sdt.blokworks.devicedeployer.presentation;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import inc.sdt.blokworks.devicedeployer.domain.CommandType;
|
import inc.sdt.blokworks.devicedeployer.domain.CommandType;
|
||||||
|
import inc.sdt.blokworks.devicedeployer.domain.DeviceType;
|
||||||
import inc.sdt.blokworks.devicedeployer.domain.OutboundMessage;
|
import inc.sdt.blokworks.devicedeployer.domain.OutboundMessage;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class OutboundMessageResourceConverter {
|
public class OutboundMessageResourceConverter {
|
||||||
private final ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
public OutboundMessageResourceConverter() {
|
|
||||||
this.objectMapper = new ObjectMapper();
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutboundMessage fromResource(OutboundMessageResource resource) {
|
public OutboundMessage fromResource(OutboundMessageResource resource) {
|
||||||
//final Map<String, Object> cmdInfo = resource.env().isEmpty() ? new HashMap<>() : convertToMap(resource.env());
|
|
||||||
|
|
||||||
return OutboundMessage.builder()
|
return OutboundMessage.builder()
|
||||||
.fileId(resource.fileId())
|
.fileId(resource.fileId())
|
||||||
|
.fileType(resource.fileType())
|
||||||
.name(resource.name())
|
.name(resource.name())
|
||||||
|
.image(resource.image() == null ? "" : resource.image())
|
||||||
.command(resource.command())
|
.command(resource.command())
|
||||||
.env(resource.env() != null ? resource.env() : new LinkedHashMap<>())
|
.options(resource.options() == null ? new LinkedHashMap<>() : resource.options())
|
||||||
.deviceType(resource.deviceType())
|
.deviceType(resource.deviceType() == null ? DeviceType.ecn : resource.deviceType())
|
||||||
.commandType(resource.commandType() == null ? CommandType.deploy : resource.commandType())
|
.commandType(resource.commandType() == null ? CommandType.deploy : resource.commandType())
|
||||||
|
.parameters(resource.parameters() == null ? new LinkedHashMap<>() : resource.parameters())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Object> convertToMap(String env) {
|
|
||||||
try {
|
|
||||||
return objectMapper.readValue(env, new TypeReference<>() {});
|
|
||||||
}catch (IOException e) {
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue