bugfixes
This commit is contained in:
@@ -1,13 +1,31 @@
|
||||
package ch.unisg.executorpool;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
|
||||
import ch.unisg.executorpool.adapter.out.persistence.mongodb.ExecutorRepository;
|
||||
import ch.unisg.executorpool.application.port.out.LoadExecutorPort;
|
||||
import ch.unisg.executorpool.domain.ExecutorPool;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableMongoRepositories(basePackageClasses = ExecutorRepository.class)
|
||||
public class ExecutorPoolApplication {
|
||||
|
||||
@Autowired
|
||||
private LoadExecutorPort loadExecutorPort;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ExecutorPoolApplication.class, args);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void initializeExecutorPool() {
|
||||
// Is this allowed in main or does it need to be in a service?
|
||||
ExecutorPool.getExecutorPool().initExecutorPool(loadExecutorPort.loadAllExecutors());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,8 @@
|
||||
package ch.unisg.executorpool.adapter.out.persistence.mongodb;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -12,7 +15,7 @@ import lombok.RequiredArgsConstructor;
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ExecutorPersistenceAdapter implements AddExecutorPort, RemoveExecutorPort, LoadExecutorPort {
|
||||
|
||||
|
||||
@Autowired
|
||||
private final ExecutorRepository executorRepository;
|
||||
|
||||
@@ -26,8 +29,7 @@ public class ExecutorPersistenceAdapter implements AddExecutorPort, RemoveExecut
|
||||
|
||||
@Override
|
||||
public void removeExecutor(ExecutorClass executorClass) {
|
||||
MongoExecutorDocument mongoExecutorDocument = executorMapper.mapToMongoDocument(executorClass);
|
||||
executorRepository.delete(mongoExecutorDocument);
|
||||
executorRepository.deleteByExecutorUri(executorClass.getExecutorUri().getValue().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,4 +39,13 @@ public class ExecutorPersistenceAdapter implements AddExecutorPort, RemoveExecut
|
||||
return executorClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExecutorClass> loadAllExecutors() {
|
||||
List<ExecutorClass> executorClasses = new ArrayList<>();
|
||||
for (MongoExecutorDocument exe : executorRepository.findAll()) {
|
||||
executorClasses.add(executorMapper.mapToDomainEntity(exe));
|
||||
}
|
||||
return executorClasses;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,5 +11,7 @@ public interface ExecutorRepository extends MongoRepository<MongoExecutorDocumen
|
||||
public MongoExecutorDocument findByExecutorUri(String executorUri, String executorTaskType);
|
||||
|
||||
public List<MongoExecutorDocument> findByExecutorTaskType(String executorTaskType);
|
||||
|
||||
|
||||
public void deleteByExecutorUri(String executorUri);
|
||||
|
||||
}
|
||||
|
@@ -1,15 +1,18 @@
|
||||
package ch.unisg.executorpool.adapter.out.persistence.mongodb;
|
||||
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Document(collection = "executors")
|
||||
public class MongoExecutorDocument {
|
||||
|
||||
|
||||
public String executorUri;
|
||||
public String executorTaskType;
|
||||
|
||||
public MongoExecutorDocument(String executorUri, String executorTaskType) {
|
||||
|
||||
|
||||
this.executorUri = executorUri;
|
||||
this.executorTaskType = executorTaskType;
|
||||
}
|
||||
|
@@ -1,9 +1,13 @@
|
||||
package ch.unisg.executorpool.application.port.out;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ch.unisg.executorpool.domain.ExecutorClass;
|
||||
|
||||
public interface LoadExecutorPort {
|
||||
|
||||
|
||||
ExecutorClass loadExecutor(ExecutorClass.ExecutorUri executorUri, ExecutorClass.ExecutorTaskType executorTaskType);
|
||||
|
||||
List<ExecutorClass> loadAllExecutors();
|
||||
|
||||
}
|
||||
|
@@ -31,11 +31,10 @@ public class RemoveExecutorFromExecutorPoolService implements RemoveExecutorFrom
|
||||
|
||||
if(removedExecutor.isPresent()){
|
||||
var executorRemovedEvent = new ExecutorRemovedEvent(removedExecutor.get());
|
||||
removeExecutorFromRepositoryPort.removeExecutor(removedExecutor.get());
|
||||
executorRemovedEventPort.publishExecutorRemovedEvent(executorRemovedEvent);
|
||||
}
|
||||
|
||||
removeExecutorFromRepositoryPort.removeExecutor(removedExecutor);
|
||||
|
||||
return removedExecutor;
|
||||
}
|
||||
}
|
||||
|
@@ -67,6 +67,12 @@ public class ExecutorPool {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public void initExecutorPool(List<ExecutorClass> executors){
|
||||
for (ExecutorClass executor : executors) {
|
||||
listOfExecutors.value.add(executor);
|
||||
}
|
||||
}
|
||||
|
||||
@Value
|
||||
public static class ListOfExecutors {
|
||||
private List<ExecutorClass> value;
|
||||
|
@@ -1,3 +1,6 @@
|
||||
server.port=8083
|
||||
|
||||
mqtt.broker.uri=tcp://localhost:1883
|
||||
|
||||
spring.data.mongodb.uri=mongodb://root:password@localhost:27017
|
||||
spring.data.mongodb.database=tapas-executors
|
||||
|
Reference in New Issue
Block a user