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