- 앱 배포 DB Entity 변경

This commit is contained in:
hyunjujeong 2023-09-07 16:52:51 +09:00
parent 15be9161f3
commit 2aa1f0c225
13 changed files with 52 additions and 57 deletions

View File

@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import inc.sdt.blokworks.devicedeployer.domain.*; import inc.sdt.blokworks.devicedeployer.domain.*;
import inc.sdt.blokworks.devicedeployer.infrastructure.mqtt.InboundDeployMessagePayload; import inc.sdt.blokworks.devicedeployer.infrastructure.mqtt.InboundDeployMessagePayload;
import inc.sdt.blokworks.devicedeployer.infrastructure.mqtt.OutboundMessagePayload; import inc.sdt.blokworks.devicedeployer.infrastructure.mqtt.OutboundMessagePayload;
import inc.sdt.blokworks.devicedeployer.presentation.GiteaApiRequestHandler;
import org.eclipse.paho.client.mqttv3.IMqttClient; import org.eclipse.paho.client.mqttv3.IMqttClient;
import org.eclipse.paho.client.mqttv3.MqttException; import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage; import org.eclipse.paho.client.mqttv3.MqttMessage;
@ -15,7 +14,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.LinkedHashMap;
import java.util.Optional; import java.util.Optional;
@Service @Service

View File

@ -12,6 +12,7 @@ public class JsonCommand implements CommandInfo {
LinkedHashMap<String, Object> map = new LinkedHashMap<>(); LinkedHashMap<String, Object> map = new LinkedHashMap<>();
map.put("cmd", String.valueOf(message.getCommandType())); map.put("cmd", String.valueOf(message.getCommandType()));
map.put("appName", message.getAppName()); map.put("appName", message.getAppName());
map.put("filename", message.getName());
map.put("parameter", message.getParameters()); map.put("parameter", message.getParameters());
return map; return map;
} }

View File

@ -5,17 +5,19 @@ public class AssetApp {
private String name; private String name;
private int size; private int size;
private int pid; private int pid;
private String message;
private Long releaseAt; private Long releaseAt;
private Long updatedAt; private Long updatedAt;
private Status status; private Status status;
protected AssetApp() {} protected AssetApp() {}
public AssetApp(String assetCode, String name, int size, int pid, Long releaseAt, Long updatedAt, Status status) { public AssetApp(String assetCode, String name, int size, int pid, String message, Long releaseAt, Long updatedAt, Status status) {
this.assetCode = assetCode; this.assetCode = assetCode;
this.name = name; this.name = name;
this.size = size; this.size = size;
this.pid = pid; this.pid = pid;
this.message = message;
this.releaseAt = releaseAt; this.releaseAt = releaseAt;
this.updatedAt = updatedAt; this.updatedAt = updatedAt;
this.status = status; this.status = status;
@ -37,6 +39,10 @@ public class AssetApp {
return pid; return pid;
} }
public String getMessage() {
return message;
}
public Long getReleaseAt() { public Long getReleaseAt() {
return releaseAt; return releaseAt;
} }
@ -56,6 +62,7 @@ public class AssetApp {
", name='" + name + '\'' + ", name='" + name + '\'' +
", size=" + size + ", size=" + size +
", pid=" + pid + ", pid=" + pid +
", message='" + message + '\'' +
", releaseAt=" + releaseAt + ", releaseAt=" + releaseAt +
", updatedAt=" + updatedAt + ", updatedAt=" + updatedAt +
", status=" + status + ", status=" + status +
@ -71,6 +78,7 @@ public class AssetApp {
private String name; private String name;
private int size; private int size;
private int pid; private int pid;
private String message;
private Long releasedAt; private Long releasedAt;
private Long updatedAt; private Long updatedAt;
private Status status; private Status status;
@ -95,6 +103,11 @@ public class AssetApp {
return this; return this;
} }
public Builder message(String message) {
this.message = message;
return this;
}
public Builder releasedAt(Long releasedAt) { public Builder releasedAt(Long releasedAt) {
this.releasedAt = releasedAt; this.releasedAt = releasedAt;
return this; return this;
@ -116,6 +129,7 @@ public class AssetApp {
assetApp.name = this.name; assetApp.name = this.name;
assetApp.size = this.size; assetApp.size = this.size;
assetApp.pid = this.pid; assetApp.pid = this.pid;
assetApp.message = this.message;
assetApp.releaseAt = this.releasedAt; assetApp.releaseAt = this.releasedAt;
assetApp.updatedAt = this.updatedAt; assetApp.updatedAt = this.updatedAt;
assetApp.status = this.status; assetApp.status = this.status;

View File

@ -24,12 +24,14 @@ class AssetAppEntity {
private int succeed; private int succeed;
@Column(name = "statusCode") @Column(name = "statusCode")
private int statusCode; private int statusCode;
@Column(name = "error_message") @Column(name = "message", columnDefinition = "TEXT")
private String message;
@Column(name = "error_message", columnDefinition = "TEXT")
private String errorMessage; private String errorMessage;
protected AssetAppEntity() {} protected AssetAppEntity() {}
public AssetAppEntity(String assetCode, String name, int size, Long releasedAt, Long updatedAt, int pid, int succeed, int statusCode, String errorMessage) { public AssetAppEntity(String assetCode, String name, int size, Long releasedAt, Long updatedAt, int pid, int succeed, int statusCode, String message, String errorMessage) {
this.assetCode = assetCode; this.assetCode = assetCode;
this.name = name; this.name = name;
this.size = size; this.size = size;
@ -38,6 +40,7 @@ class AssetAppEntity {
this.pid = pid; this.pid = pid;
this.succeed = succeed; this.succeed = succeed;
this.statusCode = statusCode; this.statusCode = statusCode;
this.message = message;
this.errorMessage = errorMessage; this.errorMessage = errorMessage;
} }
@ -77,6 +80,10 @@ class AssetAppEntity {
return statusCode; return statusCode;
} }
public String getMessage() {
return message;
}
public String getErrorMessage() { public String getErrorMessage() {
return errorMessage; return errorMessage;
} }

View File

@ -55,6 +55,7 @@ public class AssetAppRelationalRepository implements DeployerRepositoryDelegate
assetApp.getPid(), assetApp.getPid(),
assetApp.getStatus().succeed(), assetApp.getStatus().succeed(),
assetApp.getStatus().statusCode(), assetApp.getStatus().statusCode(),
assetApp.getMessage(),
assetApp.getStatus().errMsg() assetApp.getStatus().errMsg()
); );
} }
@ -65,6 +66,7 @@ public class AssetAppRelationalRepository implements DeployerRepositoryDelegate
.name(entity.getName()) .name(entity.getName())
.size(entity.getSize()) .size(entity.getSize())
.pid(entity.getPid()) .pid(entity.getPid())
.message(entity.getMessage())
.releasedAt(entity.getReleasedAt()) .releasedAt(entity.getReleasedAt())
.updatedAt(entity.getUpdatedAt()) .updatedAt(entity.getUpdatedAt())
.status(new Status(entity.getSucceed(), entity.getStatusCode(), entity.getErrorMessage())) .status(new Status(entity.getSucceed(), entity.getStatusCode(), entity.getErrorMessage()))
@ -77,6 +79,7 @@ public class AssetAppRelationalRepository implements DeployerRepositoryDelegate
.name(payload.result().name()) .name(payload.result().name())
.size(payload.result().size()) .size(payload.result().size())
.pid(payload.result().pid()) .pid(payload.result().pid())
.message(payload.result().message())
.releasedAt(payload.result().releasedAt()) .releasedAt(payload.result().releasedAt())
.updatedAt(payload.result().updatedAt()) .updatedAt(payload.result().updatedAt())
.status(payload.status()) .status(payload.status())

View File

@ -1,7 +1,6 @@
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.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 inc.sdt.blokworks.devicedeployer.domain.SubCommandType;
import jakarta.persistence.*; import jakarta.persistence.*;

View File

@ -30,7 +30,6 @@ public class DeployRequestRelationalRepository implements DeployRequestRepositor
public Optional<DeployRequest> findByRequestId(String requestId) { public Optional<DeployRequest> findByRequestId(String requestId) {
log.info("[findByRequestId] requestId = {}", requestId); log.info("[findByRequestId] requestId = {}", requestId);
DeployRequestEntity entity = deployRequestJpaRepository.findByRequestId(requestId); DeployRequestEntity entity = deployRequestJpaRepository.findByRequestId(requestId);
log.info("[findByRequestId] entity = {}", entity);
return Optional.of(this.fromEntity(entity)); return Optional.of(this.fromEntity(entity));
} }

View File

@ -1,10 +1,15 @@
package inc.sdt.blokworks.devicedeployer.presentation; package inc.sdt.blokworks.devicedeployer.presentation;
import inc.sdt.blokworks.devicedeployer.domain.Status;
record AssetAppResource( record AssetAppResource(
String assetCode, String assetCode,
String name, String name,
int size, int size,
int pid,
String message,
Long releaseAt, Long releaseAt,
Long updatedAt Long updatedAt,
Status status
) { ) {
} }

View File

@ -11,8 +11,11 @@ public class AssetAppResourceConverter {
assetApp.getAssetCode(), assetApp.getAssetCode(),
assetApp.getName(), assetApp.getName(),
assetApp.getSize(), assetApp.getSize(),
assetApp.getPid(),
assetApp.getMessage(),
assetApp.getReleaseAt(), assetApp.getReleaseAt(),
assetApp.getUpdatedAt() assetApp.getUpdatedAt(),
assetApp.getStatus()
); );
} }
} }

View File

@ -1,25 +1,17 @@
package inc.sdt.blokworks.devicedeployer.presentation; package inc.sdt.blokworks.devicedeployer.presentation;
import inc.sdt.blokworks.devicedeployer.application.CommandInvoker; import inc.sdt.blokworks.devicedeployer.application.CommandInvoker;
import inc.sdt.blokworks.devicedeployer.application.DeployCommandInvoker;
import inc.sdt.blokworks.devicedeployer.application.DeployerService; import inc.sdt.blokworks.devicedeployer.application.DeployerService;
import inc.sdt.blokworks.devicedeployer.domain.*; import inc.sdt.blokworks.devicedeployer.domain.*;
import inc.sdt.blokworks.devicedeployer.infrastructure.amqp.ResourceMapping; import inc.sdt.blokworks.devicedeployer.infrastructure.amqp.ResourceMapping;
import inc.sdt.blokworks.devicedeployer.presentation.exception.NotFoundException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer;
@RestController @RestController
public class DeployerController { public class DeployerController {
@ -49,7 +41,7 @@ public class DeployerController {
* @param resource * @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.OK)
@PostMapping("/assets/{assetCode}/apps") @PostMapping("/assets/{assetCode}/apps")
public void deploy(@PathVariable String assetCode, public void deploy(@PathVariable String assetCode,
@RequestBody OutboundMessageResource resource, @RequestBody OutboundMessageResource resource,

View File

@ -16,8 +16,7 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Arrays; import java.util.*;
import java.util.List;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
@ -33,7 +32,7 @@ public class GiteaApiRequestHandler {
this.log = LoggerFactory.getLogger(this.getClass()); this.log = LoggerFactory.getLogger(this.getClass());
this.restTemplate = restTemplate; this.restTemplate = restTemplate;
this.url = url; this.url = url;
this.extensions = Arrays.asList(".py", ".jar", ".sh", ".service", ".json", ".yaml"); this.extensions = Arrays.asList(".py", ".jar", ".sh", ".service");
} }
public void get(String authorization, OutboundMessage message) { public void get(String authorization, OutboundMessage message) {
@ -64,17 +63,23 @@ public class GiteaApiRequestHandler {
fos.write(bytes); fos.write(bytes);
} }
Set<String> entries = new HashSet<>();
try(ZipInputStream zis = new ZipInputStream(Files.newInputStream(Path.of(tempFile.getAbsolutePath())))) { try(ZipInputStream zis = new ZipInputStream(Files.newInputStream(Path.of(tempFile.getAbsolutePath())))) {
ZipEntry zipEntry; ZipEntry zipEntry;
while((zipEntry = zis.getNextEntry()) != null) { while((zipEntry = zis.getNextEntry()) != null) {
if(!zipEntry.isDirectory()) { if(!zipEntry.isDirectory()) {
String extension = zipEntry.getName().split("\\.")[1]; for(String ext : extensions) {
if(!extensions.toString().contains(extension)) { if(zipEntry.getName().contains(ext)) {
throw new NotFoundException("Executable file not found."); entries.add(ext);
}
} }
} }
} }
} }
if(entries.size() < 3) {
throw new NotFoundException("Executable file not found");
}
}
}
} }

View File

@ -1,61 +1,30 @@
package inc.sdt.blokworks.devicedeployer.presentation; package inc.sdt.blokworks.devicedeployer.presentation;
import inc.sdt.blokworks.devicedeployer.application.DeployerService; import inc.sdt.blokworks.devicedeployer.application.DeployerService;
import inc.sdt.blokworks.devicedeployer.application.ProcessService;
import inc.sdt.blokworks.devicedeployer.infrastructure.mqtt.InboundDeployMessagePayload; import inc.sdt.blokworks.devicedeployer.infrastructure.mqtt.InboundDeployMessagePayload;
import inc.sdt.blokworks.devicedeployer.infrastructure.mqtt.InboundProcessMessagePayload;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.ServiceActivator; import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.mqtt.support.MqttHeaders;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
@MessageEndpoint @MessageEndpoint
public class MqttMessageHandler { public class MqttMessageHandler {
private final Logger log; private final Logger log;
private final DeployerService deployerService; private final DeployerService deployerService;
private final ProcessService processService;
private final MqttMessageConverter<InboundDeployMessagePayload> deployMessagePayloadConverter; private final MqttMessageConverter<InboundDeployMessagePayload> deployMessagePayloadConverter;
private final MqttMessageConverter<InboundProcessMessagePayload> processMessagePayloadConverter;
public MqttMessageHandler(DeployerService deployerService, public MqttMessageHandler(DeployerService deployerService,
ProcessService processService, MqttMessageConverter<InboundDeployMessagePayload> deployMessagePayloadConverter) {
MqttMessageConverter<InboundDeployMessagePayload> deployMessagePayloadConverter,
MqttMessageConverter<InboundProcessMessagePayload> processMessagePayloadConverter) {
this.log = LoggerFactory.getLogger(this.getClass()); this.log = LoggerFactory.getLogger(this.getClass());
this.deployerService = deployerService; this.deployerService = deployerService;
this.processService = processService;
this.deployMessagePayloadConverter = deployMessagePayloadConverter; this.deployMessagePayloadConverter = deployMessagePayloadConverter;
this.processMessagePayloadConverter = processMessagePayloadConverter;
} }
@ServiceActivator(inputChannel = "mqttInboundChannel") @ServiceActivator(inputChannel = "mqttInboundChannel")
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")) {
//String topic = String.valueOf(message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC));
//String id = topic.split("/")[4];
//log.info("[handleMessage] topic = {}, id = {}", topic, id);
deployMessagePayloadConverter.convertFromByte(message.getPayload(), InboundDeployMessagePayload.class)
.map(p -> new InboundDeployMessagePayload(
p.assetCode(),
p.deviceType(),
p.status(),
p.result(),
p.requestId()
))
.flatMap(deployerService)
.subscribe();
}else {
processMessagePayloadConverter.convertFromByte(message.getPayload(), InboundProcessMessagePayload.class)
.flatMap(processService)
.subscribe();
}*/
deployMessagePayloadConverter.convertFromByte(message.getPayload(), InboundDeployMessagePayload.class) deployMessagePayloadConverter.convertFromByte(message.getPayload(), InboundDeployMessagePayload.class)
.map(p -> new InboundDeployMessagePayload( .map(p -> new InboundDeployMessagePayload(
p.assetCode(), p.assetCode(),

View File

@ -19,7 +19,7 @@ public class OutboundMessageResourceConverter {
.command(resource.command()) .command(resource.command())
.options(resource.options() == null ? new LinkedHashMap<>() : resource.options()) .options(resource.options() == null ? new LinkedHashMap<>() : resource.options())
.commandType(resource.commandType() == null ? CommandType.deploy : resource.commandType()) .commandType(resource.commandType() == null ? CommandType.deploy : resource.commandType())
.subCommandType(resource.subCommandType() == null ? SubCommandType.single : resource.subCommandType()) .subCommandType(resource.subCommandType())
.parameters(resource.parameters() == null ? new LinkedHashMap<>() : resource.parameters()) .parameters(resource.parameters() == null ? new LinkedHashMap<>() : resource.parameters())
.build(); .build();