- 앱 배포 DB Entity 변경
This commit is contained in:
parent
15be9161f3
commit
2aa1f0c225
|
@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import inc.sdt.blokworks.devicedeployer.domain.*;
|
||||
import inc.sdt.blokworks.devicedeployer.infrastructure.mqtt.InboundDeployMessagePayload;
|
||||
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.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
|
@ -15,7 +14,6 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
|
|
|
@ -12,6 +12,7 @@ public class JsonCommand implements CommandInfo {
|
|||
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("cmd", String.valueOf(message.getCommandType()));
|
||||
map.put("appName", message.getAppName());
|
||||
map.put("filename", message.getName());
|
||||
map.put("parameter", message.getParameters());
|
||||
return map;
|
||||
}
|
||||
|
|
|
@ -5,17 +5,19 @@ public class AssetApp {
|
|||
private String name;
|
||||
private int size;
|
||||
private int pid;
|
||||
private String message;
|
||||
private Long releaseAt;
|
||||
private Long updatedAt;
|
||||
private Status status;
|
||||
|
||||
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.name = name;
|
||||
this.size = size;
|
||||
this.pid = pid;
|
||||
this.message = message;
|
||||
this.releaseAt = releaseAt;
|
||||
this.updatedAt = updatedAt;
|
||||
this.status = status;
|
||||
|
@ -37,6 +39,10 @@ public class AssetApp {
|
|||
return pid;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public Long getReleaseAt() {
|
||||
return releaseAt;
|
||||
}
|
||||
|
@ -56,6 +62,7 @@ public class AssetApp {
|
|||
", name='" + name + '\'' +
|
||||
", size=" + size +
|
||||
", pid=" + pid +
|
||||
", message='" + message + '\'' +
|
||||
", releaseAt=" + releaseAt +
|
||||
", updatedAt=" + updatedAt +
|
||||
", status=" + status +
|
||||
|
@ -71,6 +78,7 @@ public class AssetApp {
|
|||
private String name;
|
||||
private int size;
|
||||
private int pid;
|
||||
private String message;
|
||||
private Long releasedAt;
|
||||
private Long updatedAt;
|
||||
private Status status;
|
||||
|
@ -95,6 +103,11 @@ public class AssetApp {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder message(String message) {
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder releasedAt(Long releasedAt) {
|
||||
this.releasedAt = releasedAt;
|
||||
return this;
|
||||
|
@ -116,6 +129,7 @@ public class AssetApp {
|
|||
assetApp.name = this.name;
|
||||
assetApp.size = this.size;
|
||||
assetApp.pid = this.pid;
|
||||
assetApp.message = this.message;
|
||||
assetApp.releaseAt = this.releasedAt;
|
||||
assetApp.updatedAt = this.updatedAt;
|
||||
assetApp.status = this.status;
|
||||
|
|
|
@ -24,12 +24,14 @@ class AssetAppEntity {
|
|||
private int succeed;
|
||||
@Column(name = "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;
|
||||
|
||||
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.name = name;
|
||||
this.size = size;
|
||||
|
@ -38,6 +40,7 @@ class AssetAppEntity {
|
|||
this.pid = pid;
|
||||
this.succeed = succeed;
|
||||
this.statusCode = statusCode;
|
||||
this.message = message;
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
|
@ -77,6 +80,10 @@ class AssetAppEntity {
|
|||
return statusCode;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ public class AssetAppRelationalRepository implements DeployerRepositoryDelegate
|
|||
assetApp.getPid(),
|
||||
assetApp.getStatus().succeed(),
|
||||
assetApp.getStatus().statusCode(),
|
||||
assetApp.getMessage(),
|
||||
assetApp.getStatus().errMsg()
|
||||
);
|
||||
}
|
||||
|
@ -65,6 +66,7 @@ public class AssetAppRelationalRepository implements DeployerRepositoryDelegate
|
|||
.name(entity.getName())
|
||||
.size(entity.getSize())
|
||||
.pid(entity.getPid())
|
||||
.message(entity.getMessage())
|
||||
.releasedAt(entity.getReleasedAt())
|
||||
.updatedAt(entity.getUpdatedAt())
|
||||
.status(new Status(entity.getSucceed(), entity.getStatusCode(), entity.getErrorMessage()))
|
||||
|
@ -77,6 +79,7 @@ public class AssetAppRelationalRepository implements DeployerRepositoryDelegate
|
|||
.name(payload.result().name())
|
||||
.size(payload.result().size())
|
||||
.pid(payload.result().pid())
|
||||
.message(payload.result().message())
|
||||
.releasedAt(payload.result().releasedAt())
|
||||
.updatedAt(payload.result().updatedAt())
|
||||
.status(payload.status())
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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.SubCommandType;
|
||||
import jakarta.persistence.*;
|
||||
|
|
|
@ -30,7 +30,6 @@ public class DeployRequestRelationalRepository implements DeployRequestRepositor
|
|||
public Optional<DeployRequest> findByRequestId(String requestId) {
|
||||
log.info("[findByRequestId] requestId = {}", requestId);
|
||||
DeployRequestEntity entity = deployRequestJpaRepository.findByRequestId(requestId);
|
||||
log.info("[findByRequestId] entity = {}", entity);
|
||||
return Optional.of(this.fromEntity(entity));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
package inc.sdt.blokworks.devicedeployer.presentation;
|
||||
|
||||
import inc.sdt.blokworks.devicedeployer.domain.Status;
|
||||
|
||||
record AssetAppResource(
|
||||
String assetCode,
|
||||
String name,
|
||||
int size,
|
||||
int pid,
|
||||
String message,
|
||||
Long releaseAt,
|
||||
Long updatedAt
|
||||
Long updatedAt,
|
||||
Status status
|
||||
) {
|
||||
}
|
||||
|
|
|
@ -11,8 +11,11 @@ public class AssetAppResourceConverter {
|
|||
assetApp.getAssetCode(),
|
||||
assetApp.getName(),
|
||||
assetApp.getSize(),
|
||||
assetApp.getPid(),
|
||||
assetApp.getMessage(),
|
||||
assetApp.getReleaseAt(),
|
||||
assetApp.getUpdatedAt()
|
||||
assetApp.getUpdatedAt(),
|
||||
assetApp.getStatus()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,17 @@
|
|||
package inc.sdt.blokworks.devicedeployer.presentation;
|
||||
|
||||
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.domain.*;
|
||||
import inc.sdt.blokworks.devicedeployer.infrastructure.amqp.ResourceMapping;
|
||||
import inc.sdt.blokworks.devicedeployer.presentation.exception.NotFoundException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
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.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@RestController
|
||||
public class DeployerController {
|
||||
|
@ -49,7 +41,7 @@ public class DeployerController {
|
|||
* @param resource 배포하려는 앱의 정보
|
||||
*/
|
||||
@ResourceMapping(name = "Deploy_App", method = "POST", uri = "/assets/{code}/apps", description = "앱 배포 명령")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
@PostMapping("/assets/{assetCode}/apps")
|
||||
public void deploy(@PathVariable String assetCode,
|
||||
@RequestBody OutboundMessageResource resource,
|
||||
|
|
|
@ -16,8 +16,7 @@ import java.io.IOException;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
|
@ -33,7 +32,7 @@ public class GiteaApiRequestHandler {
|
|||
this.log = LoggerFactory.getLogger(this.getClass());
|
||||
this.restTemplate = restTemplate;
|
||||
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) {
|
||||
|
@ -64,16 +63,22 @@ public class GiteaApiRequestHandler {
|
|||
fos.write(bytes);
|
||||
}
|
||||
|
||||
Set<String> entries = new HashSet<>();
|
||||
try(ZipInputStream zis = new ZipInputStream(Files.newInputStream(Path.of(tempFile.getAbsolutePath())))) {
|
||||
ZipEntry zipEntry;
|
||||
while((zipEntry = zis.getNextEntry()) != null) {
|
||||
if(!zipEntry.isDirectory()) {
|
||||
String extension = zipEntry.getName().split("\\.")[1];
|
||||
if(!extensions.toString().contains(extension)) {
|
||||
throw new NotFoundException("Executable file not found.");
|
||||
for(String ext : extensions) {
|
||||
if(zipEntry.getName().contains(ext)) {
|
||||
entries.add(ext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(entries.size() < 3) {
|
||||
throw new NotFoundException("Executable file not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,61 +1,30 @@
|
|||
package inc.sdt.blokworks.devicedeployer.presentation;
|
||||
|
||||
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.InboundProcessMessagePayload;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.mqtt.support.MqttHeaders;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
@MessageEndpoint
|
||||
public class MqttMessageHandler {
|
||||
private final Logger log;
|
||||
private final DeployerService deployerService;
|
||||
private final ProcessService processService;
|
||||
private final MqttMessageConverter<InboundDeployMessagePayload> deployMessagePayloadConverter;
|
||||
private final MqttMessageConverter<InboundProcessMessagePayload> processMessagePayloadConverter;
|
||||
|
||||
public MqttMessageHandler(DeployerService deployerService,
|
||||
ProcessService processService,
|
||||
MqttMessageConverter<InboundDeployMessagePayload> deployMessagePayloadConverter,
|
||||
MqttMessageConverter<InboundProcessMessagePayload> processMessagePayloadConverter) {
|
||||
MqttMessageConverter<InboundDeployMessagePayload> deployMessagePayloadConverter) {
|
||||
this.log = LoggerFactory.getLogger(this.getClass());
|
||||
this.deployerService = deployerService;
|
||||
this.processService = processService;
|
||||
this.deployMessagePayloadConverter = deployMessagePayloadConverter;
|
||||
this.processMessagePayloadConverter = processMessagePayloadConverter;
|
||||
}
|
||||
|
||||
@ServiceActivator(inputChannel = "mqttInboundChannel")
|
||||
void handleMessage(Message<String> 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)
|
||||
.map(p -> new InboundDeployMessagePayload(
|
||||
p.assetCode(),
|
||||
|
|
|
@ -19,7 +19,7 @@ public class OutboundMessageResourceConverter {
|
|||
.command(resource.command())
|
||||
.options(resource.options() == null ? new LinkedHashMap<>() : resource.options())
|
||||
.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())
|
||||
.build();
|
||||
|
||||
|
|
Loading…
Reference in New Issue