From 3da6624478c9d2e42616ad5c39475437318c5708 Mon Sep 17 00:00:00 2001 From: geek Date: Wed, 16 Nov 2016 17:13:30 +0900 Subject: [PATCH 1/4] Host PortScanHistory added --- .gitignore | 2 + .../discoveryhost/entity/DiscoveryHost.java | 107 ++++++++++++++ .../discoveryhost/entity/PortScanHistory.java | 130 ++++++++++++++++++ .../repository/DiscoveryHostRepository.java | 7 +- .../DiscoveryHostRepositoryTest.java | 80 +++++++++++ 5 files changed, 325 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/loafle/bridge/discoveryhost/entity/PortScanHistory.java create mode 100644 src/test/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepositoryTest.java diff --git a/.gitignore b/.gitignore index 45f0edd..ca26b00 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,5 @@ fabric.properties .gitignore 제거할 예정 .idea/ 제거할 예정 +.idea/ +bridge.iml diff --git a/src/main/java/com/loafle/bridge/discoveryhost/entity/DiscoveryHost.java b/src/main/java/com/loafle/bridge/discoveryhost/entity/DiscoveryHost.java index 0d46681..460c4f3 100644 --- a/src/main/java/com/loafle/bridge/discoveryhost/entity/DiscoveryHost.java +++ b/src/main/java/com/loafle/bridge/discoveryhost/entity/DiscoveryHost.java @@ -1,7 +1,114 @@ package com.loafle.bridge.discoveryhost.entity; +import com.loafle.bridge.discoveryport.entity.DiscoveryPort; +import com.loafle.bridge.discoveryzone.DiscoveryZone; + +import javax.persistence.*; +import java.util.Date; +import java.util.List; + /** * Created by root on 16. 11. 15. */ +@Entity public class DiscoveryHost { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + @Column(name = "IP_ADDRESS",nullable = false) + private long ipAddress; + + @Column(name = "MAC_ADDRESS",nullable = false) + private long macAddress; + +// @ManyToOne +// @JoinColumn(name = "ZONE_ID", nullable = false) +// private DiscoveryZone zone; + +// public DiscoveryZone getZone() { +// return zone; +// } +// +// public void setZone(DiscoveryZone zone) { +// this.zone = zone; +// } + + @OneToMany(mappedBy = "host") + private List histories; + + public List getHistories() { + return histories; + } + + public void setHistories(List histories) { + this.histories = histories; + } + +// @OneToMany(mappedBy = "host") +// private List ports; +// +// public List getPorts() { +// return ports; +// } +// +// public void setPorts(List ports) { +// this.ports = ports; +// } + + @Column(name = "CREATE_DATE", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) + private Date createDate; + + @Column(name = "UPDATE_DATE", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false) + private Date updateDate; + + + public DiscoveryHost(){} + public DiscoveryHost(long ip, long mac){ + this.ipAddress = ip; + this.macAddress = mac; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public long getIpAddress() { + return ipAddress; + } + + public void setIpAddress(long ipAddress) { + this.ipAddress = ipAddress; + } + + public long getMacAddress() { + return macAddress; + } + + public void setMacAddress(long macAddress) { + this.macAddress = macAddress; + } + + + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public Date getUpdateDate() { + return updateDate; + } + + public void setUpdateDate(Date updateDate) { + this.updateDate = updateDate; + } } diff --git a/src/main/java/com/loafle/bridge/discoveryhost/entity/PortScanHistory.java b/src/main/java/com/loafle/bridge/discoveryhost/entity/PortScanHistory.java new file mode 100644 index 0000000..4dee0a6 --- /dev/null +++ b/src/main/java/com/loafle/bridge/discoveryhost/entity/PortScanHistory.java @@ -0,0 +1,130 @@ +package com.loafle.bridge.discoveryhost.entity; + +import com.loafle.bridge.discoveryport.constant.DirectionType; +import com.loafle.bridge.discoveryport.constant.PortType; + +import javax.persistence.*; +import java.util.Date; + +/** + * Created by root on 11/16/16. + */ +@Entity +public class PortScanHistory { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn + private DiscoveryHost host; + + public DiscoveryHost getHost() { + return host; + } + + public void setHost(DiscoveryHost host) { + this.host = host; + } + + @Column(nullable = false) + private short portNumber; + + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private PortType portType; + + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private DirectionType directionType; + + @Column(nullable = true) + private String description; + + @Column(nullable = true) + private Date sendTime; + + @Column(nullable = true) + private Date resultTime; + + @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) + private Date createDate; + + + public PortScanHistory(){} + + public PortScanHistory(DiscoveryHost host, short portNumber, + PortType portType, DirectionType directionType, + String description) { + this.host = host; + this.portNumber = portNumber; + this.portType = portType; + this.directionType = directionType; + this.description = description; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public short getPortNumber() { + return portNumber; + } + + public void setPortNumber(short portNumber) { + this.portNumber = portNumber; + } + + public PortType getPortType() { + return portType; + } + + public void setPortType(PortType portType) { + this.portType = portType; + } + + public DirectionType getDirectionType() { + return directionType; + } + + public void setDirectionType(DirectionType directionType) { + this.directionType = directionType; + } + + public Date getSendTime() { + return sendTime; + } + + public void setSendTime(Date sendTime) { + this.sendTime = sendTime; + } + + public Date getResultTime() { + return resultTime; + } + + public void setResultTime(Date resultTime) { + this.resultTime = resultTime; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/src/main/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepository.java b/src/main/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepository.java index 927db2c..9b7cf08 100644 --- a/src/main/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepository.java +++ b/src/main/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepository.java @@ -1,7 +1,12 @@ package com.loafle.bridge.discoveryhost.repository; +import com.loafle.bridge.discoveryhost.entity.DiscoveryHost; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + /** * Created by root on 16. 11. 15. */ -public class DiscoveryHostRepository { +@RepositoryRestResource(collectionResourceRel = "discoveryHost", path = "discoveryHost") +public interface DiscoveryHostRepository extends JpaRepository { } diff --git a/src/test/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepositoryTest.java b/src/test/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepositoryTest.java new file mode 100644 index 0000000..9cdee24 --- /dev/null +++ b/src/test/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepositoryTest.java @@ -0,0 +1,80 @@ +package com.loafle.bridge.discoveryhost.repository; + +import com.loafle.bridge.Application; +import com.loafle.bridge.discoveryhost.entity.DiscoveryHost; +import com.loafle.bridge.discoveryhost.entity.PortScanHistory; +import com.loafle.bridge.discoveryport.constant.DirectionType; +import com.loafle.bridge.discoveryport.constant.PortType; +import org.apache.log4j.Logger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Created by root on 11/16/16. + */ + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = Application.class) +public class DiscoveryHostRepositoryTest { + + @Autowired + private DiscoveryHostRepository repository; + + Logger l = Logger.getLogger(this.getClass()); + + @Before + public void Before() { + repository.save(new DiscoveryHost(3232235986l,52242420297l)); + } + + @After + public void After() { + repository.deleteAll(); + } + + @Test + public void TestHost() { + DiscoveryHost host = new DiscoveryHost(3232235986l,52242420297l); + repository.save(host); + + DiscoveryHost c = repository.findOne(host.getId()); + + assertEquals(host.getId(), c.getId()); + + l.debug(c.getId()); + l.debug(c.getIpAddress()); + l.debug(c.getMacAddress()); + l.debug(c.getCreateDate()); + l.debug(c.getUpdateDate()); + + } + + @Test + public void TestPortHistory() { + List list = repository.findAll(); + + DiscoveryHost h = list.get(0); + + List p = new ArrayList(); + p.add(new PortScanHistory(h, (short)9840, PortType.TCP, DirectionType.Send,"DDDDDD")); + + h.setHistories(p); + + repository.flush(); + + DiscoveryHost ff = repository.findOne(h.getId()); + + System.out.println("ddddd"+ff.getId()); + + } +} \ No newline at end of file From 60468bdc8f447938b335d0e23fbcdbddb50fbec6 Mon Sep 17 00:00:00 2001 From: jackdaw Date: Wed, 16 Nov 2016 17:15:13 +0900 Subject: [PATCH 2/4] . --- .../bridge/discoveryport/DiscoveryPort.java | 22 +++++++++---------- .../discoveryport/ServiceScanHistory.java | 3 ++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java index a0033f4..3284eb7 100644 --- a/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java +++ b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java @@ -1,5 +1,6 @@ package com.loafle.bridge.discoveryport; +import com.loafle.bridge.discoveryhost.entity.DiscoveryHost; import com.loafle.bridge.discoveryport.type.PortType; import com.loafle.bridge.discoveryservice.entity.DiscoveryService; @@ -14,16 +15,16 @@ public class DiscoveryPort { @GeneratedValue(strategy = GenerationType.AUTO) private long id; -// @ManyToOne -// @JoinColumn(name = "HOST_ID", nullable = false) -// private DiscoveryHost host; -//public DiscoveryHost getHost() { -// return host; -//} -// -// public void setHost(DiscoveryHost host) { -// this.host = host; -// } + @ManyToOne + @JoinColumn(name = "HOST_ID", nullable = false) + private DiscoveryHost host; + public DiscoveryHost getHost() { + return host; + } + + public void setHost(DiscoveryHost host) { + this.host = host; + } @Column(nullable = false) @Enumerated(EnumType.STRING) private PortType portType; @@ -51,7 +52,6 @@ public class DiscoveryPort { @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false) private Date updateDate; - public DiscoveryPort() {} public DiscoveryPort(PortType type, short portNumber) { diff --git a/src/main/java/com/loafle/bridge/discoveryport/ServiceScanHistory.java b/src/main/java/com/loafle/bridge/discoveryport/ServiceScanHistory.java index 57b61a0..fc6554d 100644 --- a/src/main/java/com/loafle/bridge/discoveryport/ServiceScanHistory.java +++ b/src/main/java/com/loafle/bridge/discoveryport/ServiceScanHistory.java @@ -16,7 +16,8 @@ public class ServiceScanHistory { @GeneratedValue(strategy = GenerationType.AUTO) private long id; - @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false, updatable = false) + @Column(nullable = false, insertable = false, updatable = false) + @Temporal(TemporalType.TIMESTAMP) private Date createDate; @ManyToOne(fetch = FetchType.LAZY) From 5d5bf2899c92a7b11280b00abf6a55c09a904f50 Mon Sep 17 00:00:00 2001 From: geek Date: Wed, 16 Nov 2016 17:17:29 +0900 Subject: [PATCH 3/4] Host PortScanHistory added --- .../loafle/bridge/discoveryhost/entity/PortScanHistory.java | 4 ++-- .../discoveryhost/repository/DiscoveryHostRepositoryTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/loafle/bridge/discoveryhost/entity/PortScanHistory.java b/src/main/java/com/loafle/bridge/discoveryhost/entity/PortScanHistory.java index 4dee0a6..0eaa4bd 100644 --- a/src/main/java/com/loafle/bridge/discoveryhost/entity/PortScanHistory.java +++ b/src/main/java/com/loafle/bridge/discoveryhost/entity/PortScanHistory.java @@ -1,7 +1,7 @@ package com.loafle.bridge.discoveryhost.entity; -import com.loafle.bridge.discoveryport.constant.DirectionType; -import com.loafle.bridge.discoveryport.constant.PortType; +import com.loafle.bridge.discoveryport.type.DirectionType; +import com.loafle.bridge.discoveryport.type.PortType; import javax.persistence.*; import java.util.Date; diff --git a/src/test/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepositoryTest.java b/src/test/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepositoryTest.java index 9cdee24..624c498 100644 --- a/src/test/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepositoryTest.java +++ b/src/test/java/com/loafle/bridge/discoveryhost/repository/DiscoveryHostRepositoryTest.java @@ -3,8 +3,8 @@ package com.loafle.bridge.discoveryhost.repository; import com.loafle.bridge.Application; import com.loafle.bridge.discoveryhost.entity.DiscoveryHost; import com.loafle.bridge.discoveryhost.entity.PortScanHistory; -import com.loafle.bridge.discoveryport.constant.DirectionType; -import com.loafle.bridge.discoveryport.constant.PortType; +import com.loafle.bridge.discoveryport.type.DirectionType; +import com.loafle.bridge.discoveryport.type.PortType; import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; From 3d250cef2b99f42f8b65725eb64d87275e2df17b Mon Sep 17 00:00:00 2001 From: jackdaw Date: Wed, 16 Nov 2016 17:17:41 +0900 Subject: [PATCH 4/4] . --- .../java/com/loafle/bridge/discoveryport/DiscoveryPort.java | 2 +- .../loafle/bridge/discoveryport/DiscoveryPortController.java | 2 +- .../discoveryservice/{entity => }/DiscoveryService.java | 2 +- .../{controller => }/DiscoveryServiceController.java | 4 +--- .../{repository => }/DiscoveryServiceRepository.java | 3 +-- .../repository/DiscoveryServiceRepositoryTest.java | 2 +- 6 files changed, 6 insertions(+), 9 deletions(-) rename src/main/java/com/loafle/bridge/discoveryservice/{entity => }/DiscoveryService.java (97%) rename src/main/java/com/loafle/bridge/discoveryservice/{controller => }/DiscoveryServiceController.java (76%) rename src/main/java/com/loafle/bridge/discoveryservice/{repository => }/DiscoveryServiceRepository.java (75%) diff --git a/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java index 3284eb7..02e9a53 100644 --- a/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java +++ b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPort.java @@ -2,7 +2,7 @@ package com.loafle.bridge.discoveryport; import com.loafle.bridge.discoveryhost.entity.DiscoveryHost; import com.loafle.bridge.discoveryport.type.PortType; -import com.loafle.bridge.discoveryservice.entity.DiscoveryService; +import com.loafle.bridge.discoveryservice.DiscoveryService; import javax.persistence.*; import java.util.Date; diff --git a/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java index 7cbff39..9de889d 100644 --- a/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java +++ b/src/main/java/com/loafle/bridge/discoveryport/DiscoveryPortController.java @@ -1,7 +1,7 @@ package com.loafle.bridge.discoveryport; import com.loafle.bridge.discoveryport.type.PortType; -import com.loafle.bridge.discoveryservice.entity.DiscoveryService; +import com.loafle.bridge.discoveryservice.DiscoveryService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/src/main/java/com/loafle/bridge/discoveryservice/entity/DiscoveryService.java b/src/main/java/com/loafle/bridge/discoveryservice/DiscoveryService.java similarity index 97% rename from src/main/java/com/loafle/bridge/discoveryservice/entity/DiscoveryService.java rename to src/main/java/com/loafle/bridge/discoveryservice/DiscoveryService.java index b7c65ea..a110544 100644 --- a/src/main/java/com/loafle/bridge/discoveryservice/entity/DiscoveryService.java +++ b/src/main/java/com/loafle/bridge/discoveryservice/DiscoveryService.java @@ -1,4 +1,4 @@ -package com.loafle.bridge.discoveryservice.entity; +package com.loafle.bridge.discoveryservice; import com.loafle.bridge.discoveryport.DiscoveryPort; import com.loafle.bridge.discoveryport.type.PortType; diff --git a/src/main/java/com/loafle/bridge/discoveryservice/controller/DiscoveryServiceController.java b/src/main/java/com/loafle/bridge/discoveryservice/DiscoveryServiceController.java similarity index 76% rename from src/main/java/com/loafle/bridge/discoveryservice/controller/DiscoveryServiceController.java rename to src/main/java/com/loafle/bridge/discoveryservice/DiscoveryServiceController.java index ccee053..90b6bac 100644 --- a/src/main/java/com/loafle/bridge/discoveryservice/controller/DiscoveryServiceController.java +++ b/src/main/java/com/loafle/bridge/discoveryservice/DiscoveryServiceController.java @@ -1,7 +1,5 @@ -package com.loafle.bridge.discoveryservice.controller; +package com.loafle.bridge.discoveryservice; -import com.loafle.bridge.discoveryservice.entity.DiscoveryService; -import com.loafle.bridge.discoveryservice.repository.DiscoveryServiceRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/src/main/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepository.java b/src/main/java/com/loafle/bridge/discoveryservice/DiscoveryServiceRepository.java similarity index 75% rename from src/main/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepository.java rename to src/main/java/com/loafle/bridge/discoveryservice/DiscoveryServiceRepository.java index fb1427b..6b1eb2e 100644 --- a/src/main/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepository.java +++ b/src/main/java/com/loafle/bridge/discoveryservice/DiscoveryServiceRepository.java @@ -1,6 +1,5 @@ -package com.loafle.bridge.discoveryservice.repository; +package com.loafle.bridge.discoveryservice; -import com.loafle.bridge.discoveryservice.entity.DiscoveryService; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; diff --git a/src/test/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepositoryTest.java b/src/test/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepositoryTest.java index e306abb..2c0b404 100644 --- a/src/test/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepositoryTest.java +++ b/src/test/java/com/loafle/bridge/discoveryservice/repository/DiscoveryServiceRepositoryTest.java @@ -4,7 +4,7 @@ import com.loafle.bridge.Application; import com.loafle.bridge.discoveryport.DiscoveryPort; import com.loafle.bridge.discoveryport.DiscoveryPortRepository; import com.loafle.bridge.discoveryport.type.PortType; -import com.loafle.bridge.discoveryservice.entity.DiscoveryService; +import com.loafle.bridge.discoveryservice.DiscoveryService; import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before;