From be24ebf19f3b44e3a2c679a9f29312cb04334a6d Mon Sep 17 00:00:00 2001 From: snoop Date: Mon, 21 Aug 2017 13:59:36 +0900 Subject: [PATCH] fixed infra series model --- .../overflow/module/infra/dao/InfraDAO.java | 4 +- .../overflow/module/infra/model/Infra.java | 151 +++++++++----- .../module/infra/model/InfraHost.java | 35 ++-- .../module/infra/model/InfraMachine.java | 27 +-- .../overflow/module/infra/model/InfraOS.java | 33 +-- .../infra/model/InfraOSApplication.java | 31 +-- .../module/infra/model/InfraOSDaemon.java | 31 +-- .../module/infra/model/InfraOSPort.java | 37 ++-- .../module/infra/model/InfraService.java | 37 ++-- .../module/infra/service/InfraService.java | 3 +- .../service/TargetDiscoveryService.java | 194 +++++++++--------- src/main/resources/init.sql | 51 ----- .../infra/service/InfraHostServiceTest.java | 2 +- .../service/InfraMachineServiceTest.java | 13 +- .../infra/service/InfraOSServiceTest.java | 11 +- .../infra/service/InfraServiceTest.java | 101 ++++++--- .../service/TargetDiscoveryServiceTest.java | 2 +- 17 files changed, 422 insertions(+), 341 deletions(-) diff --git a/src/main/java/com/loafle/overflow/module/infra/dao/InfraDAO.java b/src/main/java/com/loafle/overflow/module/infra/dao/InfraDAO.java index 23df2ae..256ce49 100644 --- a/src/main/java/com/loafle/overflow/module/infra/dao/InfraDAO.java +++ b/src/main/java/com/loafle/overflow/module/infra/dao/InfraDAO.java @@ -21,8 +21,8 @@ public interface InfraDAO extends JpaRepository { List findAllByProbe(List probeList); - @Query("SELECT DISTINCT i.target FROM Infra i WHERE i.probe IN (:probeList)") - List findAllTargetByProbeList(@Param("probeList") List probeList); +// @Query("SELECT DISTINCT i.target FROM Infra i WHERE i.probe IN (:probeList)") +// List findAllTargetByProbeList(@Param("probeList") List probeList); // List findAllByProbe(List probeList); } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/infra/model/Infra.java b/src/main/java/com/loafle/overflow/module/infra/model/Infra.java index f096692..700fa12 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/Infra.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/Infra.java @@ -11,16 +11,24 @@ import java.util.Date; /** * Created by root on 17. 6. 22. */ -@Entity -@Table(name = "INFRA", schema = "public", catalog = "postgres") -public class Infra { +@Entity(name = "INFRA") +//@Table(name = "INFRA", schema = "public", catalog = "postgres") +@Inheritance(strategy = InheritanceType.JOINED) +@DiscriminatorColumn(name = "INFRA_TYPE") +public abstract class Infra { private long id; private MetaInfraType infraType; - private long childId; +// private long childId; private Date createDate; private Probe probe; private Target target; +// private InfraChild infraChild; + +// private InfraHost infraHost; +// private InfraMachine infraMachine; +// private InfraOS infraOS; + /* private long id; private MetaInfraType infraType; @@ -29,6 +37,55 @@ public class Infra { private Probe probeId; private Target targetId; */ +// @ManyToOne +// @JoinColumn(name = "CHILD_ID", nullable = false, insertable = false, updatable = false) +// public InfraHost getInfraChild() { +// return infraChild; +// } +// +// public void setInfraChild(InfraChild infraChild) { +// this.infraChild = infraChild; +// } + +// @OneToOne +// @JoinColumn(name = "CHILD_ID") +// public InfraChild getInfraChild() { +// return infraChild; +// } +// +// public void setInfraChild(InfraChild infraChild) { +// this.infraChild = infraChild; +// } + +// @ManyToOne +// @JoinColumn(name = "HOST_ID") +// public InfraHost getInfraHost() { +// return infraHost; +// } +// +// public void setInfraHost(InfraHost infraHost) { +// this.infraHost = infraHost; +// } + +// @ManyToOne +// @JoinColumn(name = "MACHINE_ID") +// public InfraMachine getInfraMachine() { +// return infraMachine; +// } +// +// public void setInfraMachine(InfraMachine infraMachine) { +// this.infraMachine = infraMachine; +// } +// +// @ManyToOne +// @JoinColumn(name = "OS_ID") +// public InfraOS getInfraOS() { +// return infraOS; +// } +// +// public void setInfraOS(InfraOS infraOS) { +// this.infraOS = infraOS; +// } @Id @GeneratedValue(strategy= GenerationType.IDENTITY) @@ -50,15 +107,15 @@ public class Infra { this.infraType = infraType; } - @Basic - @Column(name = "CHILD_ID", nullable = false) - public long getChildId() { - return childId; - } - - public void setChildId(long childId) { - this.childId = childId; - } +// @Basic +// @Column(name = "CHILD_ID", nullable = false) +// public long getChildId() { +// return childId; +// } +// +// public void setChildId(long childId) { +// this.childId = childId; +// } @Temporal(TemporalType.TIMESTAMP) @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) @@ -71,7 +128,7 @@ public class Infra { } @ManyToOne - @JoinColumn(name = "PROBE_ID", nullable = false) + @JoinColumn(name = "PROBE_ID", nullable = true) public Probe getProbe() { return probe; } @@ -81,7 +138,7 @@ public class Infra { } @ManyToOne - @JoinColumn(name = "TARGET_ID", nullable = false) + @JoinColumn(name = "TARGET_ID", nullable = true) public Target getTarget() { return target; } @@ -90,37 +147,37 @@ public class Infra { this.target = target; } - public static Infra CreateInfraByType(long id, Class c) { - - Infra infra = new Infra(); - infra.setChildId(id); - - MetaInfraType infraType = new MetaInfraType(); - if(c == InfraMachine.class) { - infraType.setId(1); - } - else if(c == InfraHost.class) { - infraType.setId(2); - } - else if(c == InfraOS.class) { - infraType.setId(3); - } - else if(c == InfraOSApplication.class) { - infraType.setId(4); - } - else if(c == InfraOSDaemon.class) { - infraType.setId(5); - } - else if(c == InfraOSPort.class) { - infraType.setId(6); - } - else if(c == InfraService.class) { - infraType.setId(7); - } - - infra.setInfraType(infraType); - - return infra; - } +// public static Infra CreateInfraByType(long id, Class c) { +// +// Infra infra = new Infra(); +//// infra.setChildId(id); +// +// MetaInfraType infraType = new MetaInfraType(); +// if(c == InfraMachine.class) { +// infraType.setId(1); +// } +// else if(c == InfraHost.class) { +// infraType.setId(2); +// } +// else if(c == InfraOS.class) { +// infraType.setId(3); +// } +// else if(c == InfraOSApplication.class) { +// infraType.setId(4); +// } +// else if(c == InfraOSDaemon.class) { +// infraType.setId(5); +// } +// else if(c == InfraOSPort.class) { +// infraType.setId(6); +// } +// else if(c == InfraService.class) { +// infraType.setId(7); +// } +// +// infra.setInfraType(infraType); +// +// return infra; +// } } diff --git a/src/main/java/com/loafle/overflow/module/infra/model/InfraHost.java b/src/main/java/com/loafle/overflow/module/infra/model/InfraHost.java index b6dac64..fe6fbeb 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/InfraHost.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/InfraHost.java @@ -6,27 +6,28 @@ import java.util.Date; /** * Created by root on 17. 6. 22. */ -@Entity -@Table(name = "INFRA_HOST", schema = "public", catalog = "postgres") -public class InfraHost { - private long id; +@Entity(name = "INFRA_HOST") +//@Table(name = "INFRA_HOST", schema = "public", catalog = "postgres") +@DiscriminatorValue("INFRA_HOST") +public class InfraHost extends Infra { +// private long id; private InfraOS os; private long ip; private long mac; private Date createDate; - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } +// @Id +// @GeneratedValue(strategy= GenerationType.IDENTITY) +// public long getId() { +// return id; +// } +// +// public void setId(long id) { +// this.id = id; +// } @ManyToOne - @JoinColumn(name = "OS_ID", nullable = false) + @JoinColumn(name = "OS_ID", nullable = true) public InfraOS getOs() { return os; } @@ -36,7 +37,7 @@ public class InfraHost { } @Basic - @Column(name = "IP", nullable = false) + @Column(name = "IP", nullable = true) public long getIp() { return ip; } @@ -46,7 +47,7 @@ public class InfraHost { } @Basic - @Column(name = "MAC", nullable = false) + @Column(name = "MAC", nullable = true) public long getMac() { return mac; } @@ -56,7 +57,7 @@ public class InfraHost { } @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + @Column(name = "CREATE_DATE", nullable = true, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) public Date getCreateDate() { return createDate; } diff --git a/src/main/java/com/loafle/overflow/module/infra/model/InfraMachine.java b/src/main/java/com/loafle/overflow/module/infra/model/InfraMachine.java index 101fbf6..3fcd8e4 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/InfraMachine.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/InfraMachine.java @@ -8,10 +8,11 @@ import java.util.Date; /** * Created by root on 17. 6. 22. */ -@Entity -@Table(name = "INFRA_MACHINE", schema = "public", catalog = "postgres") -public class InfraMachine { - private long id; +@Entity(name = "INFRA_MACHINE") +//@Table(name = "INFRA_MACHINE", schema = "public", catalog = "postgres") +@DiscriminatorValue("INFRA_MACHINE") +public class InfraMachine extends Infra { +// private long id; private String meta; private Date createDate; @@ -22,15 +23,15 @@ public class InfraMachine { private Date createDate; */ - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } +// @Id +// @GeneratedValue(strategy= GenerationType.IDENTITY) +// public long getId() { +// return id; +// } +// +// public void setId(long id) { +// this.id = id; +// } @Basic @Column(name = "META", nullable = true, length = 255) diff --git a/src/main/java/com/loafle/overflow/module/infra/model/InfraOS.java b/src/main/java/com/loafle/overflow/module/infra/model/InfraOS.java index 557310f..e416f9a 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/InfraOS.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/InfraOS.java @@ -9,27 +9,28 @@ import java.util.Date; /** * Created by root on 17. 6. 22. */ -@Entity -@Table(name = "INFRA_OS", schema = "public", catalog = "postgres") -public class InfraOS { - private long id; +@Entity(name = "INFRA_OS") +//@Table(name = "INFRA_OS", schema = "public", catalog = "postgres") +@DiscriminatorValue("INFRA_OS") +public class InfraOS extends Infra { +// private long id; private InfraMachine machine; private String meta; private Date createDate; private MetaInfraVendor vendor; - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } +// @Id +// @GeneratedValue(strategy= GenerationType.IDENTITY) +// public long getId() { +// return id; +// } +// +// public void setId(long id) { +// this.id = id; +// } @ManyToOne - @JoinColumn(name = "MACHINE_ID", nullable = false) + @JoinColumn(name = "MACHINE_ID", nullable = true) public InfraMachine getMachine() { return machine; } @@ -49,7 +50,7 @@ public class InfraOS { } @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + @Column(name = "CREATE_DATE", nullable = true, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) public Date getCreateDate() { return createDate; } @@ -59,7 +60,7 @@ public class InfraOS { } @ManyToOne - @JoinColumn(name = "VENDOR_ID", nullable = false) + @JoinColumn(name = "VENDOR_ID", nullable = true) public MetaInfraVendor getVendor() { return vendor; } diff --git a/src/main/java/com/loafle/overflow/module/infra/model/InfraOSApplication.java b/src/main/java/com/loafle/overflow/module/infra/model/InfraOSApplication.java index 034e340..865cfcf 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/InfraOSApplication.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/InfraOSApplication.java @@ -6,26 +6,27 @@ import java.util.Date; /** * Created by root on 17. 6. 22. */ -@Entity -@Table(name = "INFRA_OS_APPLICATION", schema = "public", catalog = "postgres") -public class InfraOSApplication { - private long id; +@Entity(name = "INFRA_OS_APPLICATION") +//@Table(name = "INFRA_OS_APPLICATION", schema = "public", catalog = "postgres") +@DiscriminatorValue("INFRA_OS_APPLICATION") +public class InfraOSApplication extends Infra { +// private long id; private InfraOS os; private String name; private Date createDate; - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } +// @Id +// @GeneratedValue(strategy= GenerationType.IDENTITY) +// public long getId() { +// return id; +// } +// +// public void setId(long id) { +// this.id = id; +// } @ManyToOne - @JoinColumn(name = "OS_ID", nullable = false) + @JoinColumn(name = "OS_ID", nullable = true) public InfraOS getOs() { return os; } @@ -45,7 +46,7 @@ public class InfraOSApplication { } @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + @Column(name = "CREATE_DATE", nullable = true, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) public Date getCreateDate() { return createDate; } diff --git a/src/main/java/com/loafle/overflow/module/infra/model/InfraOSDaemon.java b/src/main/java/com/loafle/overflow/module/infra/model/InfraOSDaemon.java index 77d06ef..c176633 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/InfraOSDaemon.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/InfraOSDaemon.java @@ -6,26 +6,27 @@ import java.util.Date; /** * Created by root on 17. 6. 22. */ -@Entity -@Table(name = "INFRA_OS_DAEMON", schema = "public", catalog = "postgres") -public class InfraOSDaemon { - private long id; +@Entity(name = "INFRA_OS_DAEMON") +//@Table(name = "INFRA_OS_DAEMON", schema = "public", catalog = "postgres") +@DiscriminatorValue("INFRA_OS_DAEMON") +public class InfraOSDaemon extends Infra { +// private long id; private InfraOS os; private String name; private Date createDate; - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } +// @Id +// @GeneratedValue(strategy= GenerationType.IDENTITY) +// public long getId() { +// return id; +// } +// +// public void setId(long id) { +// this.id = id; +// } @ManyToOne - @JoinColumn(name = "OS_ID", nullable = false) + @JoinColumn(name = "OS_ID", nullable = true) public InfraOS getOs() { return os; } @@ -45,7 +46,7 @@ public class InfraOSDaemon { } @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + @Column(name = "CREATE_DATE", nullable = true, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) public Date getCreateDate() { return createDate; } diff --git a/src/main/java/com/loafle/overflow/module/infra/model/InfraOSPort.java b/src/main/java/com/loafle/overflow/module/infra/model/InfraOSPort.java index 6876e54..3d4291e 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/InfraOSPort.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/InfraOSPort.java @@ -9,29 +9,30 @@ import java.util.Date; /** * Created by root on 17. 6. 22. */ -@Entity -@Table(name = "INFRA_OS_PORT", schema = "public", catalog = "postgres") -public class InfraOSPort { - private long id; +@Entity(name = "INFRA_OS_PORT") +//@Table(name = "INFRA_OS_PORT", schema = "public", catalog = "postgres") +@DiscriminatorValue("INFRA_OS_PORT") +public class InfraOSPort extends Infra { +// private long id; private InfraOS os; private Date createDate; private Integer port; private String portType; private MetaInfraVendor vendor; private boolean tlsType; - - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } +// +// @Id +// @GeneratedValue(strategy= GenerationType.IDENTITY) +// public long getId() { +// return id; +// } +// +// public void setId(long id) { +// this.id = id; +// } @ManyToOne - @JoinColumn(name = "OS_ID", nullable = false) + @JoinColumn(name = "OS_ID", nullable = true) public InfraOS getOs() { return this.os; } @@ -41,7 +42,7 @@ public class InfraOSPort { } @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + @Column(name = "CREATE_DATE", nullable = true, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) public Date getCreateDate() { return createDate; } @@ -61,7 +62,7 @@ public class InfraOSPort { } @Basic - @Column(name = "PORT_TYPE", nullable = false) + @Column(name = "PORT_TYPE", nullable = true) public String getPortType() { return portType; } @@ -81,7 +82,7 @@ public class InfraOSPort { } @Basic - @Column(name = "TLS_TYPE", nullable = false) + @Column(name = "TLS_TYPE", nullable = true) public boolean isTlsType() { return tlsType; } diff --git a/src/main/java/com/loafle/overflow/module/infra/model/InfraService.java b/src/main/java/com/loafle/overflow/module/infra/model/InfraService.java index 912a821..eaf689a 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/InfraService.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/InfraService.java @@ -9,10 +9,11 @@ import java.util.Date; /** * Created by root on 17. 6. 22. */ -@Entity -@Table(name = "INFRA_SERVICE", schema = "public", catalog = "postgres") -public class InfraService { - private long id; +@Entity(name = "INFRA_SERVICE") +//@Table(name = "INFRA_SERVICE", schema = "public", catalog = "postgres") +@DiscriminatorValue("INFRA_SERVICE") +public class InfraService extends Infra{ +// private long id; private InfraHost host; private String portType; private Integer port; @@ -20,18 +21,18 @@ public class InfraService { private Date createDate; private boolean tlsType; - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } +// @Id +// @GeneratedValue(strategy= GenerationType.IDENTITY) +// public long getId() { +// return id; +// } +// +// public void setId(long id) { +// this.id = id; +// } @ManyToOne - @JoinColumn(name = "HOST_ID", nullable = false) + @JoinColumn(name = "HOST_ID", nullable = true) public InfraHost getHost() { return host; } @@ -41,7 +42,7 @@ public class InfraService { } @Basic - @Column(name = "PORT_TYPE", nullable = false) + @Column(name = "PORT_TYPE", nullable = true) public String getPortType() { return portType; } @@ -61,7 +62,7 @@ public class InfraService { } @ManyToOne - @JoinColumn(name = "VENDOR_ID", nullable = false) + @JoinColumn(name = "VENDOR_ID", nullable = true) public MetaInfraVendor getVendor() { return vendor; } @@ -71,7 +72,7 @@ public class InfraService { } @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + @Column(name = "CREATE_DATE", nullable = true, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) public Date getCreateDate() { return createDate; } @@ -81,7 +82,7 @@ public class InfraService { } @Basic - @Column(name = "TLS_TYPE", nullable = false) + @Column(name = "TLS_TYPE", nullable = true) public boolean isTlsType() { return tlsType; } diff --git a/src/main/java/com/loafle/overflow/module/infra/service/InfraService.java b/src/main/java/com/loafle/overflow/module/infra/service/InfraService.java index 90c2955..4a0eb2c 100644 --- a/src/main/java/com/loafle/overflow/module/infra/service/InfraService.java +++ b/src/main/java/com/loafle/overflow/module/infra/service/InfraService.java @@ -48,6 +48,7 @@ public class InfraService { } public List readAllTargetByProbeList(List probeList) { - return this.infraDAO.findAllTargetByProbeList(probeList); +// return this.infraDAO.findAllTargetByProbeList(probeList); + return null; } } diff --git a/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java b/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java index a54e0b5..f8e4ad3 100644 --- a/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java +++ b/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java @@ -42,101 +42,101 @@ public class TargetDiscoveryService { @Autowired private InfraServiceDAO infraServiceDAO; - @Transactional - public void saveAllTarget(List hosts, Probe probe) { - - for(Host host : hosts) { - - InfraMachine infraMachine = new InfraMachine(); -// infraMachine.setProbe(probe); - this.infraMachineDAO.save(infraMachine); - - Infra infraByMachine = Infra.CreateInfraByType(infraMachine.getId(), InfraMachine.class); - this.infraDAO.save(infraByMachine); - - - InfraOS infraOS = new InfraOS(); - infraOS.setMachine(infraMachine); - infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs())); - this.infraOSDAO.save(infraOS); - - Infra infraByOS = Infra.CreateInfraByType(infraOS.getId(), InfraOS.class); - this.infraDAO.save(infraByOS); - - - InfraHost infraHost = new InfraHost(); - infraHost.setIp(host.getIp()); - infraHost.setMac(host.getMac()); - infraHost.setOs(infraOS); - this.infraHostDAO.save(infraHost); - - Infra infraByHost = Infra.CreateInfraByType(infraHost.getId(), InfraHost.class); - this.infraDAO.save(infraByHost); - - if(host.isTarget()) { - Target targetHost = new Target(); -// targetHost.setInfra(infraByHost); -// targetHost.setProbe(probe); - this.targetDAO.save(targetHost); - } - - if(host.getPorts() == null) { - continue; - } - - for(Port port : host.getPorts()) { - - InfraOSPort infraOSPort = new InfraOSPort(); - infraOSPort.setOs(infraOS); - infraOSPort.setPort(port.getPortNumber()); - infraOSPort.setPortType("UDP"); - if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { - infraOSPort.setPortType("TCP"); - } - if (port.getPortType() == PortType.TLS) { - infraOSPort.setTlsType(true); - } - infraOSPort.setVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber())); - this.infraOSPortDAO.save(infraOSPort); - - Infra infraByPort = Infra.CreateInfraByType(infraOSPort.getId(), InfraOSPort.class); - this.infraDAO.save(infraByPort); - - if(port.getServices() == null) { - continue; - } - - for(com.loafle.overflow.module.discovery.model.Service service : port.getServices()) { - - InfraService infraService = new InfraService(); - infraService.setHost(infraHost); - infraService.setPort(port.getPortNumber()); - infraService.setPortType("UDP"); - if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { - infraService.setPortType("TCP"); - } - if (port.getPortType() == PortType.TLS) { - infraService.setTlsType(true); - } - infraService.setVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); - this.infraServiceDAO.save(infraService); - - Infra infraByService = Infra.CreateInfraByType(infraService.getId(), InfraService.class); - this.infraDAO.save(infraByService); - - if(service.isTarget()) { - Target targetService = new Target(); -// targetService.setInfra(infraByService); -// targetService.setProbe(probe); - this.targetDAO.save(targetService); - } - - } - - } - - - } - - } +// @Transactional +// public void saveAllTarget(List hosts, Probe probe) { +// +// for(Host host : hosts) { +// +// InfraMachine infraMachine = new InfraMachine(); +//// infraMachine.setProbe(probe); +// this.infraMachineDAO.save(infraMachine); +// +// Infra infraByMachine = Infra.CreateInfraByType(infraMachine.getId(), InfraMachine.class); +// this.infraDAO.save(infraByMachine); +// +// +// InfraOS infraOS = new InfraOS(); +//// infraOS.setMachine(infraMachine); +//// infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs())); +// this.infraOSDAO.save(infraOS); +// +// Infra infraByOS = Infra.CreateInfraByType(infraOS.getId(), InfraOS.class); +// this.infraDAO.save(infraByOS); +// +// +// InfraHost infraHost = new InfraHost(); +// infraHost.setIp(host.getIp()); +// infraHost.setMac(host.getMac()); +//// infraHost.setOs(infraOS); +// this.infraHostDAO.save(infraHost); +// +// Infra infraByHost = Infra.CreateInfraByType(infraHost.getId(), InfraHost.class); +// this.infraDAO.save(infraByHost); +// +// if(host.isTarget()) { +// Target targetHost = new Target(); +//// targetHost.setInfra(infraByHost); +//// targetHost.setProbe(probe); +// this.targetDAO.save(targetHost); +// } +// +// if(host.getPorts() == null) { +// continue; +// } +// +// for(Port port : host.getPorts()) { +// +// InfraOSPort infraOSPort = new InfraOSPort(); +// infraOSPort.setOs(infraOS); +// infraOSPort.setPort(port.getPortNumber()); +// infraOSPort.setPortType("UDP"); +// if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { +// infraOSPort.setPortType("TCP"); +// } +// if (port.getPortType() == PortType.TLS) { +// infraOSPort.setTlsType(true); +// } +// infraOSPort.setVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber())); +// this.infraOSPortDAO.save(infraOSPort); +// +// Infra infraByPort = Infra.CreateInfraByType(infraOSPort.getId(), InfraOSPort.class); +// this.infraDAO.save(infraByPort); +// +// if(port.getServices() == null) { +// continue; +// } +// +// for(com.loafle.overflow.module.discovery.model.Service service : port.getServices()) { +// +// InfraService infraService = new InfraService(); +// infraService.setHost(infraHost); +// infraService.setPort(port.getPortNumber()); +// infraService.setPortType("UDP"); +// if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { +// infraService.setPortType("TCP"); +// } +// if (port.getPortType() == PortType.TLS) { +// infraService.setTlsType(true); +// } +// infraService.setVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); +// this.infraServiceDAO.save(infraService); +// +// Infra infraByService = Infra.CreateInfraByType(infraService.getId(), InfraService.class); +// this.infraDAO.save(infraByService); +// +// if(service.isTarget()) { +// Target targetService = new Target(); +//// targetService.setInfra(infraByService); +//// targetService.setProbe(probe); +// this.targetDAO.save(targetService); +// } +// +// } +// +// } +// +// +// } +// +// } } diff --git a/src/main/resources/init.sql b/src/main/resources/init.sql index f795b03..f4a1717 100644 --- a/src/main/resources/init.sql +++ b/src/main/resources/init.sql @@ -397,54 +397,3 @@ INSERT INTO public.domain_member (create_date,domain_id,member_id) VALUES ( INSERT INTO public.api_key (api_key,create_date,domain_id) VALUES ( '52abd6fd57e511e7ac52080027658d13','2017-06-26 13:02:28.347',1); -INSERT INTO public.noauth_probe (api_key,create_date,host_name,ip_address,mac_address,temp_probe_key,domain_id,probe_id,status) VALUES ( -'52abd6fd57e511e7ac52080027658d13','2017-06-26 12:43:46.877','snoop',3232235980,8796753988883,'1cf2555c57d511e79714080027658d13',1,NULL,3); - -INSERT INTO public.noauth_probe (api_key,create_date,host_name,ip_address,mac_address,temp_probe_key,domain_id,probe_id,status) VALUES ( -'52abd6fd57e511e7ac52080027658d14','2017-08-11 12:43:46.877','geek',3232235980,8796753988883,'1cf2555c57d511e79714080027658d14',1,NULL,3); - -INSERT INTO public.noauth_probe (api_key,create_date,host_name,ip_address,mac_address,temp_probe_key,domain_id,probe_id,status) VALUES ( -'52abd6fd57e511e7ac52080027658d15','2017-08-11 12:43:46.877','insanity',3232235980,8796753988883,'1cf2555c57d511e79714080027658d15',1,NULL,3); - -INSERT INTO public.infra_machine (create_date,meta) VALUES ( -'2017-07-27 19:54:26.677',''); - -INSERT INTO public.infra_os (create_date,meta,machine_id,vendor_id) VALUES ( -'2017-07-27 19:55:47.326','',1,26); - -INSERT INTO public.infra_host (create_date,ip,mac,os_id) VALUES ( -'2017-07-27 19:57:10.607',3232235980,8796753988883,1); - -INSERT INTO public.infra_service (create_date,port,port_type,tls_type,host_id,vendor_id) VALUES ( -'2017-07-28 16:36:33.906',80,'TCP',false,1,45); - -INSERT INTO public.infra_os_application (create_date,name,os_id) VALUES ( -'2017-07-28 16:54:11.646','Apache',1); - -INSERT INTO public.infra_os_daemon (create_date,name,os_id) VALUES ( -'2017-07-28 17:00:35.186','Apache',1); - -INSERT INTO public.probe (authorize_date,cidr,create_date,description,display_name,encryption_key,probe_key,sensor_count,target_count,authorize_member_id,domain_id,host_id,status) VALUES ( -'2017-07-27 20:01:28.513','192.168.1.0/24','2017-07-27 20:01:28.513','snoop probe','test probe','8c51fa9c5bcc11e7980a080027658d13','899fdd145bcc11e7b611080027658d13',0,0,1,1,1,1); - -INSERT INTO public.target (create_date,description,display_name) VALUES ( -'2017-07-27 20:18:09.555','i am target','ghost target'); - -INSERT INTO public.infra (child_id,create_date,probe_id,target_id,type_id) VALUES ( -1,'2017-07-28 11:08:50.803',1,1,1); -INSERT INTO public.infra (child_id,create_date,probe_id,target_id,type_id) VALUES ( -1,'2017-07-28 11:08:50.832',1,1,3); -INSERT INTO public.infra (child_id,create_date,probe_id,target_id,type_id) VALUES ( -1,'2017-07-28 11:08:50.841',1,1,2); -INSERT INTO public.infra (child_id,create_date,type_id,probe_id,target_id) VALUES ( -1,'2017-07-28 16:52:30.391',7,1,1); - -INSERT INTO public.sensor (crawler_input_items,create_date,description,crawler_id,status,target_id) VALUES ( -NULL,'2017-06-26 20:19:07.009','My sensor',1,1,1); -INSERT INTO public.sensor (crawler_input_items,create_date,description,crawler_id,status,target_id) VALUES ( -NULL,'2017-06-26 20:19:07.074','My sensor',1,1,1); - -INSERT INTO public.sensor_item (create_date,item_id,sensor_id) VALUES ( -'2017-06-26 20:21:16.626',1,1); -INSERT INTO public.sensor_item (create_date,item_id,sensor_id) VALUES ( -'2017-06-26 20:21:50.988',2,2); \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/module/infra/service/InfraHostServiceTest.java b/src/test/java/com/loafle/overflow/module/infra/service/InfraHostServiceTest.java index 6bf4993..5942192 100644 --- a/src/test/java/com/loafle/overflow/module/infra/service/InfraHostServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/infra/service/InfraHostServiceTest.java @@ -36,7 +36,7 @@ public class InfraHostServiceTest { InfraOS infraOS = new InfraOS(); infraOS.setId(1); - infraHost.setOs(infraOS); +// infraHost.setOs(infraOS); this.infraHostService.regist(infraHost); diff --git a/src/test/java/com/loafle/overflow/module/infra/service/InfraMachineServiceTest.java b/src/test/java/com/loafle/overflow/module/infra/service/InfraMachineServiceTest.java index ac58a0f..e3a22c9 100644 --- a/src/test/java/com/loafle/overflow/module/infra/service/InfraMachineServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/infra/service/InfraMachineServiceTest.java @@ -2,6 +2,8 @@ package com.loafle.overflow.module.infra.service; import com.loafle.overflow.module.infra.model.InfraMachine; +import com.loafle.overflow.module.meta.model.MetaInfraType; +import com.loafle.overflow.module.meta.model.MetaInfraVendor; import com.loafle.overflow.spring.AppConfigTest; import org.codehaus.jackson.map.ObjectMapper; import org.junit.Assert; @@ -23,13 +25,18 @@ public class InfraMachineServiceTest { @Autowired private InfraMachineService infraMachineService; - @Ignore +// @Ignore @Test public void regist() throws Exception { InfraMachine infraMachine = new InfraMachine(); - infraMachine.setMeta(""); + infraMachine.setMeta("i am a infra machine"); + + MetaInfraType metaInfraType = new MetaInfraType(); + metaInfraType.setId(1); + + infraMachine.setInfraType(metaInfraType); this.infraMachineService.regist(infraMachine); @@ -40,6 +47,8 @@ public class InfraMachineServiceTest { @Test public void read() throws Exception { + regist(); + InfraMachine infraMachine = this.infraMachineService.read(1); ObjectMapper objectMapper = new ObjectMapper(); diff --git a/src/test/java/com/loafle/overflow/module/infra/service/InfraOSServiceTest.java b/src/test/java/com/loafle/overflow/module/infra/service/InfraOSServiceTest.java index 3cf829b..f39c7f1 100644 --- a/src/test/java/com/loafle/overflow/module/infra/service/InfraOSServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/infra/service/InfraOSServiceTest.java @@ -2,6 +2,7 @@ package com.loafle.overflow.module.infra.service; import com.loafle.overflow.module.infra.model.InfraMachine; import com.loafle.overflow.module.infra.model.InfraOS; +import com.loafle.overflow.module.meta.model.MetaInfraType; import com.loafle.overflow.module.meta.model.MetaInfraVendor; import com.loafle.overflow.spring.AppConfigTest; import org.codehaus.jackson.map.ObjectMapper; @@ -23,8 +24,8 @@ public class InfraOSServiceTest { private InfraOSService infraOSService; @Test - @Ignore - public void regist() throws Exception { +// @Ignore + public void registOS() throws Exception { InfraOS infraOS = new InfraOS(); @@ -37,8 +38,14 @@ public class InfraOSServiceTest { InfraMachine infraMachine = new InfraMachine(); infraMachine.setId(1); + MetaInfraType metaInfraType = new MetaInfraType(); + metaInfraType.setId(3); + + infraOS.setInfraType(metaInfraType); infraOS.setMachine(infraMachine); + + this.infraOSService.regist(infraOS); } diff --git a/src/test/java/com/loafle/overflow/module/infra/service/InfraServiceTest.java b/src/test/java/com/loafle/overflow/module/infra/service/InfraServiceTest.java index 16a8ae6..f52ec4e 100644 --- a/src/test/java/com/loafle/overflow/module/infra/service/InfraServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/infra/service/InfraServiceTest.java @@ -2,6 +2,7 @@ package com.loafle.overflow.module.infra.service; import com.loafle.overflow.module.domain.model.Domain; import com.loafle.overflow.module.infra.model.Infra; +import com.loafle.overflow.module.infra.model.InfraMachine; import com.loafle.overflow.module.meta.model.MetaInfraType; import com.loafle.overflow.module.probe.model.Probe; import com.loafle.overflow.module.probe.service.ProbeService; @@ -31,52 +32,102 @@ public class InfraServiceTest { @Autowired private ProbeService probeService; - @Ignore - @Test - public void regist() throws Exception { + @Autowired + private InfraMachineService infraMachineService; - long id =registInfra(7,1); - Assert.assertNotEquals(id, 0); -// id =registInfra(3,1); +// public void regist() throws Exception { +// +// long id =registInfra(7,1); // Assert.assertNotEquals(id, 0); // -// id =registInfra(2,1); -// Assert.assertNotEquals(id, 0); - +//// id =registInfra(3,1); +//// Assert.assertNotEquals(id, 0); +//// +//// id =registInfra(2,1); +//// Assert.assertNotEquals(id, 0); +// +// +// +// } + @Test + public void tttt() { } -// @Ignore - public long registInfra(int type, int childId) { + @Test + public void registInfraMachine() { + + InfraMachine infraMachine = new InfraMachine(); + infraMachine.setMeta("i am a inframachine"); + + + +// Assert.assertNotEquals(infraMachine.getId(), 0); + +// Probe probe = new Probe(); +// probe.setId(1); +// +// Target target = new Target(); +// target.setId(1); + +// Infra infra = new Infra(); +// infra.setTarget(target); + MetaInfraType metaInfraType = new MetaInfraType(); - metaInfraType.setId(type); + metaInfraType.setId(1); - Infra infra = new Infra(); - infra.setInfraType(metaInfraType); - infra.setChildId(childId); +// infraMachine.setInfraType(metaInfraType); +// infra.setProbe(probe); +// infra.setInfraChild(infraMachine); - Probe probe = new Probe(); - probe.setId(1); + this.infraMachineService.regist(infraMachine); - Target target = new Target(); - target.setId(1); +// this.infraService.regist(infra); - infra.setProbe(probe); - infra.setTarget(target); +// Assert.assertNotEquals(infra.getId(), 0); - this.infraService.regist(infra); - - return infra.getId(); } + @Test + public void registInfraOS() { + registInfraMachine(); + } + +//// @Ignore +// public long registInfra(int type, int childId) { +// MetaInfraType metaInfraType = new MetaInfraType(); +// metaInfraType.setId(type); +// +// Infra infra = new Infra(); +// infra.setInfraType(metaInfraType); +//// infra.setChildId(childId); +// +// +// +// Probe probe = new Probe(); +// probe.setId(1); +// +// Target target = new Target(); +// target.setId(1); +// +// infra.setProbe(probe); +// infra.setTarget(target); +// +// this.infraService.regist(infra); +// +// return infra.getId(); +// } + @Test public void read() throws Exception { - Infra infra = this.infraService.read(3); +// registInfraMachine(); + + Infra infra = this.infraService.read(1); ObjectMapper objectMapper = new ObjectMapper(); String json = objectMapper.writeValueAsString(infra); diff --git a/src/test/java/com/loafle/overflow/module/target/service/TargetDiscoveryServiceTest.java b/src/test/java/com/loafle/overflow/module/target/service/TargetDiscoveryServiceTest.java index c868bcf..ba27202 100644 --- a/src/test/java/com/loafle/overflow/module/target/service/TargetDiscoveryServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/target/service/TargetDiscoveryServiceTest.java @@ -51,7 +51,7 @@ public class TargetDiscoveryServiceTest { Probe probe = new Probe(); probe.setId(1); - this.targetDiscoveryService.saveAllTarget(hosts, probe); +// this.targetDiscoveryService.saveAllTarget(hosts, probe); } private String readFileAsString(String filePath) throws IOException {