parent
a3a7ce77cf
commit
b74398813e
|
@ -8,8 +8,6 @@ import inc.sdt.blokworks.devicedeployer.domain.OutboundMessage;
|
|||
import inc.sdt.blokworks.devicedeployer.domain.OperationType;
|
||||
import inc.sdt.blokworks.devicedeployer.infrastructure.mqtt.InboundDeployMessagePayload;
|
||||
import inc.sdt.blokworks.devicedeployer.infrastructure.mqtt.OutboundMessagePayload;
|
||||
import inc.sdt.blokworks.devicedeployer.presentation.exception.ConflictException;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
package inc.sdt.blokworks.devicedeployer.infrastructure.mqtt;
|
||||
|
||||
import inc.sdt.blokworks.devicedeployer.domain.OperationType;
|
||||
import inc.sdt.blokworks.devicedeployer.domain.Port;
|
||||
import inc.sdt.blokworks.devicedeployer.presentation.PortResource;
|
||||
import inc.sdt.blokworks.devicedeployer.presentation.PortResourceConverter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
public record OutboundMessagePayload(
|
||||
String url,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package inc.sdt.blokworks.devicedeployer.infrastructure.relational;
|
||||
|
||||
import inc.sdt.blokworks.devicedeployer.domain.OperationType;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity(name = "app_process")
|
||||
|
@ -22,10 +23,13 @@ class ProcessEntity {
|
|||
private Integer network;
|
||||
@Column(name = "processed_at")
|
||||
private Long processedAt;
|
||||
@Column(name = "operation_type")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private OperationType operationType;
|
||||
|
||||
protected ProcessEntity() {}
|
||||
|
||||
public ProcessEntity(String assetCode, Integer pid, String appName, Integer cpu, Integer memory, Integer network, Long processedAt) {
|
||||
public ProcessEntity(String assetCode, Integer pid, String appName, Integer cpu, Integer memory, Integer network, Long processedAt, OperationType operationType) {
|
||||
this.assetCode = assetCode;
|
||||
this.pid = pid;
|
||||
this.appName = appName;
|
||||
|
@ -33,6 +37,7 @@ class ProcessEntity {
|
|||
this.memory = memory;
|
||||
this.network = network;
|
||||
this.processedAt = processedAt;
|
||||
this.operationType = operationType;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
@ -66,4 +71,8 @@ class ProcessEntity {
|
|||
public Long getProcessedAt() {
|
||||
return processedAt;
|
||||
}
|
||||
|
||||
public OperationType getOperationType() {
|
||||
return operationType;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package inc.sdt.blokworks.devicedeployer.infrastructure.relational;
|
||||
|
||||
import inc.sdt.blokworks.devicedeployer.application.ProcessRepositoryDelegate;
|
||||
import inc.sdt.blokworks.devicedeployer.domain.OperationType;
|
||||
import inc.sdt.blokworks.devicedeployer.domain.Process;
|
||||
import inc.sdt.blokworks.devicedeployer.infrastructure.mqtt.InboundProcessMessagePayload;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -50,7 +51,8 @@ public class ProcessRelationalRepository implements ProcessRepositoryDelegate {
|
|||
process.getCpu(),
|
||||
process.getMemory(),
|
||||
process.getNetwork(),
|
||||
process.getProcessedAt()
|
||||
process.getProcessedAt(),
|
||||
OperationType.START
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -63,6 +65,7 @@ public class ProcessRelationalRepository implements ProcessRepositoryDelegate {
|
|||
.memory(entity.getMemory())
|
||||
.network(entity.getNetwork())
|
||||
.processedAt(entity.getProcessedAt())
|
||||
.operationType(entity.getOperationType())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -75,6 +78,7 @@ public class ProcessRelationalRepository implements ProcessRepositoryDelegate {
|
|||
.memory(payload.memory())
|
||||
.network(payload.network())
|
||||
.processedAt(payload.processedAt())
|
||||
.operationType(OperationType.START)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
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.domain.*;
|
||||
import inc.sdt.blokworks.devicedeployer.domain.Process;
|
||||
import inc.sdt.blokworks.devicedeployer.infrastructure.amqp.ResourceMapping;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
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.*;
|
||||
|
|
|
@ -10,7 +10,7 @@ record OutboundMessageResource(
|
|||
@NotNull
|
||||
String name,
|
||||
String command,
|
||||
HashMap<String, String> env
|
||||
String env
|
||||
) {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,23 @@
|
|||
package inc.sdt.blokworks.devicedeployer.presentation;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import inc.sdt.blokworks.devicedeployer.domain.OutboundMessage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class OutboundMessageResourceConverter {
|
||||
private final ObjectMapper objectMapper;
|
||||
private final Logger log;
|
||||
|
||||
public OutboundMessageResource toResource(OutboundMessage outboundMessage) {
|
||||
return new OutboundMessageResource(
|
||||
outboundMessage.getFileId(),
|
||||
outboundMessage.getName(),
|
||||
outboundMessage.getCommand(),
|
||||
outboundMessage.getEnv()
|
||||
);
|
||||
public OutboundMessageResourceConverter() {
|
||||
this.objectMapper = new ObjectMapper();
|
||||
this.log = LoggerFactory.getLogger(this.getClass());
|
||||
}
|
||||
|
||||
public OutboundMessage fromResource(OutboundMessageResource resource) {
|
||||
|
@ -20,8 +25,17 @@ public class OutboundMessageResourceConverter {
|
|||
.fileId(resource.fileId())
|
||||
.name(resource.name())
|
||||
.command(resource.command())
|
||||
.env(resource.env())
|
||||
.env(resource.env().isEmpty() ? new HashMap<>() : (HashMap<String, String>) convertToMap(resource.env()))
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
private Map convertToMap(String env) {
|
||||
try {
|
||||
return objectMapper.readValue(env, Map.class);
|
||||
}catch (IOException e) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,21 +25,21 @@ class PageableResourceImpl implements PageableResource {
|
|||
|
||||
@Override
|
||||
public long getTotalElements() {
|
||||
return 0;
|
||||
return totalElements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalPages() {
|
||||
return 0;
|
||||
return totalPages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return 0;
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPage() {
|
||||
return 0;
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ spring:
|
|||
|
||||
inbound:
|
||||
mqtt:
|
||||
url: tcp://localhost:1883
|
||||
#url: tcp://13.209.39.139:32259
|
||||
#url: tcp://localhost:1883
|
||||
url: tcp://13.209.39.139:32259
|
||||
username: sdt
|
||||
password: 251327
|
||||
topics:
|
||||
|
|
Loading…
Reference in New Issue