This commit is contained in:
insanity 2016-11-16 17:20:13 +09:00
commit 091fc901de
12 changed files with 344 additions and 22 deletions

2
.gitignore vendored
View File

@ -70,3 +70,5 @@ fabric.properties
.gitignore 제거할 예정 .gitignore 제거할 예정
.idea/ 제거할 예정 .idea/ 제거할 예정
.idea/
bridge.iml

View File

@ -1,7 +1,114 @@
package com.loafle.bridge.discoveryhost.entity; 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. * Created by root on 16. 11. 15.
*/ */
@Entity
public class DiscoveryHost { 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<PortScanHistory> histories;
public List<PortScanHistory> getHistories() {
return histories;
}
public void setHistories(List<PortScanHistory> histories) {
this.histories = histories;
}
// @OneToMany(mappedBy = "host")
// private List<DiscoveryPort> ports;
//
// public List<DiscoveryPort> getPorts() {
// return ports;
// }
//
// public void setPorts(List<DiscoveryPort> 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;
}
} }

View File

@ -0,0 +1,130 @@
package com.loafle.bridge.discoveryhost.entity;
import com.loafle.bridge.discoveryport.type.DirectionType;
import com.loafle.bridge.discoveryport.type.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;
}
}

View File

@ -1,7 +1,12 @@
package com.loafle.bridge.discoveryhost.repository; 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. * Created by root on 16. 11. 15.
*/ */
public class DiscoveryHostRepository { @RepositoryRestResource(collectionResourceRel = "discoveryHost", path = "discoveryHost")
public interface DiscoveryHostRepository extends JpaRepository<DiscoveryHost,Long> {
} }

View File

@ -1,7 +1,8 @@
package com.loafle.bridge.discoveryport; package com.loafle.bridge.discoveryport;
import com.loafle.bridge.discoveryhost.entity.DiscoveryHost;
import com.loafle.bridge.discoveryport.type.PortType; import com.loafle.bridge.discoveryport.type.PortType;
import com.loafle.bridge.discoveryservice.entity.DiscoveryService; import com.loafle.bridge.discoveryservice.DiscoveryService;
import javax.persistence.*; import javax.persistence.*;
import java.util.Date; import java.util.Date;
@ -14,16 +15,16 @@ public class DiscoveryPort {
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
private long id; private long id;
// @ManyToOne @ManyToOne
// @JoinColumn(name = "HOST_ID", nullable = false) @JoinColumn(name = "HOST_ID", nullable = false)
// private DiscoveryHost host; private DiscoveryHost host;
//public DiscoveryHost getHost() { public DiscoveryHost getHost() {
// return host; return host;
//} }
//
// public void setHost(DiscoveryHost host) { public void setHost(DiscoveryHost host) {
// this.host = host; this.host = host;
// } }
@Column(nullable = false) @Column(nullable = false)
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private PortType portType; private PortType portType;
@ -51,7 +52,6 @@ public class DiscoveryPort {
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false) @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", nullable = false, insertable = false)
private Date updateDate; private Date updateDate;
public DiscoveryPort() {} public DiscoveryPort() {}
public DiscoveryPort(PortType type, short portNumber) { public DiscoveryPort(PortType type, short portNumber) {

View File

@ -1,7 +1,7 @@
package com.loafle.bridge.discoveryport; package com.loafle.bridge.discoveryport;
import com.loafle.bridge.discoveryport.type.PortType; 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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;

View File

@ -16,7 +16,8 @@ public class ServiceScanHistory {
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
private long id; 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; private Date createDate;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)

View File

@ -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.DiscoveryPort;
import com.loafle.bridge.discoveryport.type.PortType; import com.loafle.bridge.discoveryport.type.PortType;

View File

@ -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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;

View File

@ -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.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RepositoryRestResource;

View File

@ -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.type.DirectionType;
import com.loafle.bridge.discoveryport.type.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<DiscoveryHost> list = repository.findAll();
DiscoveryHost h = list.get(0);
List<PortScanHistory> p = new ArrayList<PortScanHistory>();
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());
}
}

View File

@ -4,7 +4,7 @@ import com.loafle.bridge.Application;
import com.loafle.bridge.discoveryport.DiscoveryPort; import com.loafle.bridge.discoveryport.DiscoveryPort;
import com.loafle.bridge.discoveryport.DiscoveryPortRepository; import com.loafle.bridge.discoveryport.DiscoveryPortRepository;
import com.loafle.bridge.discoveryport.type.PortType; 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.apache.log4j.Logger;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;