Fix modal displaying and add image to application entity.
This commit is contained in:
@@ -3,6 +3,7 @@ package org.takiguchi.cerberus.cerberusapp.controller;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.takiguchi.cerberus.cerberusapp.model.Application;
|
||||
import org.takiguchi.cerberus.cerberusapp.model.ApplicationStatus;
|
||||
import org.takiguchi.cerberus.cerberusapp.model.ServiceStatus;
|
||||
import org.takiguchi.cerberus.cerberusapp.service.ApplicationService;
|
||||
|
||||
@@ -37,6 +38,7 @@ public class ApplicationController {
|
||||
.withName(application.getName())
|
||||
.withServiceName(application.getServiceName())
|
||||
.withServiceType(application.getServiceType())
|
||||
.withImage(application.getImage())
|
||||
.build();
|
||||
return service.add(applicationToAdd);
|
||||
}
|
||||
@@ -80,4 +82,9 @@ public class ApplicationController {
|
||||
public void restart(@PathVariable("applicationId") UUID applicationId) {
|
||||
service.restart(applicationId);
|
||||
}
|
||||
|
||||
@GetMapping("/status")
|
||||
public List<ApplicationStatus> getAllApplicationStatus() {
|
||||
return service.checkAllStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,16 +9,18 @@ public class Application {
|
||||
/** The technical service name, like a docker container name or a system V service name. */
|
||||
private final String serviceName;
|
||||
private final ServiceType serviceType;
|
||||
private final String image;
|
||||
|
||||
public static Builder anApplication() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
private Application(UUID id, String name, String serviceName, ServiceType serviceType) {
|
||||
private Application(UUID id, String name, String serviceName, ServiceType serviceType, String image) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.serviceName = serviceName;
|
||||
this.serviceType = serviceType;
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
@@ -37,11 +39,16 @@ public class Application {
|
||||
return serviceType;
|
||||
}
|
||||
|
||||
public String getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private UUID id;
|
||||
private String name;
|
||||
private String serviceName;
|
||||
private ServiceType serviceType;
|
||||
private String image;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
@@ -66,8 +73,13 @@ public class Application {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withImage(String image) {
|
||||
this.image = image;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Application build() {
|
||||
return new Application(id, name, serviceName, serviceType);
|
||||
return new Application(id, name, serviceName, serviceType, image);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.takiguchi.cerberus.cerberusapp.model;
|
||||
|
||||
public class ApplicationStatus {
|
||||
private final Application application;
|
||||
private final ServiceStatus status;
|
||||
|
||||
public static Builder anApplicationStatus() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public ApplicationStatus(Application application, ServiceStatus status) {
|
||||
this.application = application;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Application getApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
public ServiceStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private Application application;
|
||||
private ServiceStatus status;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder withApplication(Application application) {
|
||||
this.application = application;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withStatus(ServiceStatus status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApplicationStatus build() {
|
||||
return new ApplicationStatus(application, status);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ public class ApplicationEntityMapper {
|
||||
.withName(entity.getName())
|
||||
.withServiceName(entity.getServiceName())
|
||||
.withServiceType(entity.getServiceType())
|
||||
.withImage(entity.getImage())
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -23,7 +24,8 @@ public class ApplicationEntityMapper {
|
||||
application.getId(),
|
||||
application.getName(),
|
||||
application.getServiceName(),
|
||||
application.getServiceType()
|
||||
application.getServiceType(),
|
||||
application.getImage()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package org.takiguchi.cerberus.cerberusapp.persistence.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import org.takiguchi.cerberus.cerberusapp.model.ServiceType;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.UUID;
|
||||
|
||||
import static javax.persistence.EnumType.ORDINAL;
|
||||
|
||||
@Entity
|
||||
@Table(name = "application")
|
||||
public class ApplicationEntity {
|
||||
@@ -18,15 +15,17 @@ public class ApplicationEntity {
|
||||
private String serviceName;
|
||||
@Enumerated
|
||||
private ServiceType serviceType;
|
||||
private String image;
|
||||
|
||||
public ApplicationEntity() {
|
||||
}
|
||||
|
||||
public ApplicationEntity(UUID id, String name, String serviceName, ServiceType serviceType) {
|
||||
public ApplicationEntity(UUID id, String name, String serviceName, ServiceType serviceType, String image) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.serviceName = serviceName;
|
||||
this.serviceType = serviceType;
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
@@ -57,6 +56,14 @@ public class ApplicationEntity {
|
||||
return serviceType;
|
||||
}
|
||||
|
||||
public String getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(String image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public void setServiceType(ServiceType serviceType) {
|
||||
this.serviceType = serviceType;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.takiguchi.cerberus.cerberusapp.service;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.takiguchi.cerberus.cerberusapp.exception.NotFoundException;
|
||||
import org.takiguchi.cerberus.cerberusapp.model.Application;
|
||||
import org.takiguchi.cerberus.cerberusapp.model.ApplicationStatus;
|
||||
import org.takiguchi.cerberus.cerberusapp.model.ServiceStatus;
|
||||
import org.takiguchi.cerberus.cerberusapp.service.servicemanager.ServiceManagerProvider;
|
||||
import org.takiguchi.cerberus.cerberusapp.service.validator.ApplicationValidator;
|
||||
@@ -10,8 +11,10 @@ import org.takiguchi.cerberus.cerberusapp.service.validator.ApplicationValidator
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.takiguchi.cerberus.cerberusapp.model.Application.anApplication;
|
||||
import static org.takiguchi.cerberus.cerberusapp.model.ApplicationStatus.anApplicationStatus;
|
||||
|
||||
@Service
|
||||
public class ApplicationService {
|
||||
@@ -94,4 +97,16 @@ public class ApplicationService {
|
||||
NotFoundException::new
|
||||
);
|
||||
}
|
||||
|
||||
public List<ApplicationStatus> checkAllStatus() {
|
||||
return getAll().stream()
|
||||
.map(application -> {
|
||||
ServiceStatus status = checkStatus(application.getId());
|
||||
return anApplicationStatus()
|
||||
.withApplication(application)
|
||||
.withStatus(status)
|
||||
.build();
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,5 +5,6 @@ CREATE TABLE IF NOT EXISTS application (
|
||||
name VARCHAR NOT NULL,
|
||||
service_name VARCHAR NOT NULL,
|
||||
service_type SMALLINT NOT NULL,
|
||||
image VARCHAR NOT NULL,
|
||||
CONSTRAINT application_pk PRIMARY KEY (id)
|
||||
);
|
||||
Reference in New Issue
Block a user