This commit is contained in:
jackdaw 2016-11-17 11:55:25 +09:00
parent 84bb955d2e
commit a33b84405f
3 changed files with 64 additions and 15 deletions

View File

@ -25,7 +25,7 @@ public class DiscoveryHistory
private Boolean result;
@JoinColumn
@OneToOne
@OneToOne(cascade = CascadeType.ALL)
private DiscoveryZone zone;
public DiscoveryZone getZone() {

View File

@ -2,11 +2,8 @@ package com.loafle.bridge.discoveryhost;
import com.loafle.bridge.discoveryport.DiscoveryPort;
import com.loafle.bridge.discoveryzone.DiscoveryZone;
import org.hibernate.annotations.*;
import org.hibernate.annotations.CascadeType;
import javax.persistence.*;
import javax.persistence.Entity;
import java.util.Date;
import java.util.List;
@ -49,8 +46,7 @@ public class DiscoveryHost {
this.histories = histories;
}
@OneToMany(mappedBy = "host")
@Cascade(CascadeType.ALL)
@OneToMany(mappedBy = "host",cascade = CascadeType.ALL)
private List<DiscoveryPort> ports;
public List<DiscoveryPort> getPorts() {

View File

@ -1,7 +1,11 @@
package com.loafle.bridge.discoveryport;
import com.loafle.bridge.discoveryhistory.DiscoveryHistory;
import com.loafle.bridge.discoveryhistory.DiscoveryHistoryRepository;
import com.loafle.bridge.discoveryhost.DiscoveryHost;
import com.loafle.bridge.discoveryport.type.PortType;
import com.loafle.bridge.discoveryservice.DiscoveryService;
import com.loafle.bridge.discoveryzone.DiscoveryZone;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@ -10,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@ -22,26 +27,74 @@ public class DiscoveryPortController {
@Autowired
DiscoveryPortRepository repository;
@Autowired
DiscoveryHistoryRepository repo;
@RequestMapping(value = "/discoveryPort/{id}", method = RequestMethod.GET)
public DiscoveryPort get(@PathVariable(value = "id") long id) {
return repository.findOne(id);
}
@RequestMapping(value ="/index")
@RequestMapping(value ="/jack")
@Transactional
public void index() {
DiscoveryPort p = new DiscoveryPort(PortType.TCP,(short)12786);
// DiscoveryPort p = new DiscoveryPort(PortType.TCP,(short)12786);
//
// List<DiscoveryService> ss = new ArrayList<>();
//
// repository.save(p);
//
// ss.add(new DiscoveryService(p,PortType.TCP,"DNS"));
// ss.add(new DiscoveryService(p,PortType.TCP,"TEST"));
// ss.add(new DiscoveryService(p,PortType.TCP,"ABB"));
//
// p.setServices(ss);
//
// repository.save(p);
List<DiscoveryService> ss = new ArrayList<>();
DiscoveryHistory d = new DiscoveryHistory();
d.setResult(true);
d.setStartDate(new Date());
d.setEndDate(new Date());
repository.save(p);
DiscoveryZone z = new DiscoveryZone();
String cidr = "827452358680";
String ip = "3232235983";
z.setCidr(Long.parseLong(cidr));
z.setIp(Long.parseLong(ip));
ss.add(new DiscoveryService(p,PortType.TCP,"DNS"));
ss.add(new DiscoveryService(p,PortType.TCP,"TEST"));
ss.add(new DiscoveryService(p,PortType.TCP,"ABB"));
d.setZone(z);
p.setServices(ss);
repository.save(p);
List<DiscoveryHost> hl = new ArrayList<>();
//add host
for (int i =0 ; i < 10 ; ++i) {
DiscoveryHost host = new DiscoveryHost(3232235986l,52242420297l);
host.setZone(z);
List<DiscoveryPort> p = new ArrayList<DiscoveryPort>();
host.setPorts(p);
//add port
for (int j =0 ; j < 10 ; ++j) {
DiscoveryPort port = new DiscoveryPort(host, PortType.TCP, 9840);
p.add(port);
List<DiscoveryService> ss = new ArrayList<>();
ss.add(new DiscoveryService(port,PortType.TCP,"DNS"));
ss.add(new DiscoveryService(port,PortType.TCP,"TEST"));
ss.add(new DiscoveryService(port,PortType.TCP,"ABB"));
port.setServices(ss);
}
hl.add(host);
}
z.setDiscoveryHosts(hl);
repo.save(d);
DiscoveryHistory find = repo.findOne(d.getId());
}
}