Host PortScanHistory added

This commit is contained in:
geek 2016-11-16 17:13:30 +09:00
parent 9ff1e84a8c
commit 3da6624478
5 changed files with 325 additions and 1 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.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;
}
}

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

@ -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<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());
}
}