use of com.vmware.flowgate.labsdb.common.EndDevice in project flowgate by vmware.
the class LabsdbService method generatorWiremapData.
public Asset generatorWiremapData(Asset asset, Map<String, String> pduNameAndIdMap, List<EndDevice> devices, Map<String, String> networkNameAndIdMap) {
Set<String> pduIDList = null;
Set<String> networkIDList = null;
pduIDList = new HashSet<String>();
networkIDList = new HashSet<String>();
HashMap<String, String> justficationfields = asset.getJustificationfields();
String pduPortString = null;
String networkPortString = null;
Set<String> pduDevices = new HashSet<String>();
Set<String> networkDevices = new HashSet<String>();
if (justficationfields != null) {
pduPortString = justficationfields.get(FlowgateConstant.PDU_PORT_FOR_SERVER);
networkPortString = justficationfields.get(FlowgateConstant.NETWORK_PORT_FOR_SERVER);
}
if (pduPortString != null) {
String[] pdus = pduPortString.split(FlowgateConstant.SPILIT_FLAG);
Collections.addAll(pduDevices, pdus);
}
if (networkPortString != null) {
String[] networks = networkPortString.split(FlowgateConstant.SPILIT_FLAG);
Collections.addAll(networkDevices, networks);
}
// Use the device name to find it, and if it exists, record it's number and port information.
for (EndDevice device : devices) {
if (device.getStartPort() == null || device.getEndPort() == null || device.getEndDeviceName() == null) {
continue;
}
String pduId = pduNameAndIdMap.get(device.getEndDeviceName());
if (pduId != null) {
pduIDList.add(pduId);
device.setEndDeviceAssetId(pduId);
device.setEndPort(FlowgateConstant.OUTLET_NAME_PREFIX + device.getEndPort());
String pduDevice = device.toString();
pduDevices.add(pduDevice);
} else {
String networkId = networkNameAndIdMap.get(device.getEndDeviceName());
if (networkId != null) {
networkIDList.add(networkId);
device.setEndDeviceAssetId(networkId);
String networkDevice = device.toString();
networkDevices.add(networkDevice);
} else {
continue;
}
}
}
if (!pduDevices.isEmpty()) {
pduPortString = String.join(FlowgateConstant.SPILIT_FLAG, pduDevices);
justficationfields.put(FlowgateConstant.PDU_PORT_FOR_SERVER, pduPortString);
}
if (!networkDevices.isEmpty()) {
networkPortString = String.join(FlowgateConstant.SPILIT_FLAG, networkDevices);
justficationfields.put(FlowgateConstant.NETWORK_PORT_FOR_SERVER, networkPortString);
}
asset.setJustificationfields(justficationfields);
// update the mapping status,from UNPPED or MAPPEDBYAGGREGATOR to MAPPEDBYLABSDB
AssetStatus status = asset.getStatus();
if (status == null) {
status = new AssetStatus();
}
if (!pduIDList.isEmpty()) {
status.setPduMapping(PduMapping.MAPPEDBYLABSDB);
asset.setPdus(new ArrayList<String>(pduIDList));
}
if (!networkIDList.isEmpty()) {
status.setNetworkMapping(NetworkMapping.MAPPEDBYLABSDB);
asset.setSwitches(new ArrayList<String>(networkIDList));
}
asset.setStatus(status);
return asset;
}
use of com.vmware.flowgate.labsdb.common.EndDevice in project flowgate by vmware.
the class WiremapSaxHandler method startElement.
@Override
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
super.startElement(uri, localName, name, attributes);
if (name.equals(nodeName)) {
endDevice = new EndDevice();
for (int i = 0; i < attributes.getLength(); i++) {
if (attributeName.equals(attributes.getLocalName(i))) {
endDevice.setStartPort(attributes.getValue(i));
}
}
}
currentTag = name;
currentValue = new StringBuilder();
}
use of com.vmware.flowgate.labsdb.common.EndDevice in project flowgate by vmware.
the class SyncWiremapDataJobTest method getDevices.
List<EndDevice> getDevices() {
EndDevice device1 = new EndDevice();
device1.setEndDeviceName("sin2-build-rdev1");
device1.setEndPort("onboard-1");
device1.setStartPort("01");
device1.setWireMapType(WireMapType.net);
List<EndDevice> devices = new ArrayList<EndDevice>();
devices.add(device1);
EndDevice device2 = new EndDevice();
device2.setEndDeviceName("w3r17c05-pdu4");
device2.setEndPort("onboard-5");
device2.setStartPort("02");
device1.setWireMapType(WireMapType.power);
return devices;
}
use of com.vmware.flowgate.labsdb.common.EndDevice in project flowgate by vmware.
the class SyncWiremapDataJobTest method generatorWiremapDataTest1.
@Test
public void generatorWiremapDataTest1() {
Asset assetFromflowgate = createServer();
EndDevice net1 = new EndDevice();
net1.setEndDeviceAssetId("5c8749469662e32e2470d654");
net1.setEndDeviceName("w4-pek2");
net1.setEndPort("onboard-1");
net1.setStartPort("03");
EndDevice net2 = new EndDevice();
net2.setEndDeviceAssetId("5c778c598ecf859960e2be30");
net2.setEndDeviceName("sin2-build-rdev1");
net2.setEndPort("onboard-1");
net2.setStartPort("01");
HashSet<String> nets = new HashSet<String>();
HashMap<String, String> fileds = new HashMap<String, String>();
nets.add(net1.toString());
nets.add(net2.toString());
fileds.put(FlowgateConstant.NETWORK_PORT_FOR_SERVER, String.join(FlowgateConstant.SPILIT_FLAG, nets));
assetFromflowgate.setJustificationfields(fileds);
Map<String, String> network = new HashMap<String, String>();
network.put("sin2-build-rdev1", "5c778c598ecf859960e2be30");
Map<String, String> pdu = new HashMap<String, String>();
pdu.put("w3r17c05-pdu4", "wertbhukloiup5996q23df530");
List<EndDevice> devices = getDevices();
Asset asset = labsdbService.generatorWiremapData(assetFromflowgate, pdu, devices, network);
List<String> networks = asset.getSwitches();
TestCase.assertEquals("5c778c598ecf859960e2be30", networks.get(0));
String networkdevices = asset.getJustificationfields().get(FlowgateConstant.NETWORK_PORT_FOR_SERVER);
String expectValue = String.join(FlowgateConstant.SPILIT_FLAG, nets);
TestCase.assertEquals(expectValue, networkdevices);
}
use of com.vmware.flowgate.labsdb.common.EndDevice in project flowgate by vmware.
the class SyncWiremapDataJobTest method generatorWiremapDataTest.
@Test
public void generatorWiremapDataTest() {
Asset assetFromflowgate = createServer();
Map<String, String> network = new HashMap<String, String>();
network.put("sin2-build-rdev1", "5c778c598ecf859960e2be30");
Map<String, String> pdu = new HashMap<String, String>();
pdu.put("w3r17c05-pdu4", "wertbhukloiup5996q23df530");
List<EndDevice> devices = getDevices();
Asset asset = labsdbService.generatorWiremapData(assetFromflowgate, pdu, devices, network);
List<String> networks = asset.getSwitches();
TestCase.assertEquals("5c778c598ecf859960e2be30", networks.get(0));
String device = asset.getJustificationfields().get(FlowgateConstant.NETWORK_PORT_FOR_SERVER);
TestCase.assertEquals("01" + FlowgateConstant.SEPARATOR + "sin2-build-rdev1" + FlowgateConstant.SEPARATOR + "onboard-1" + FlowgateConstant.SEPARATOR + "" + "5c778c598ecf859960e2be30", device);
}
Aggregations