use of com.vmware.flowgate.common.AssetStatus 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.common.AssetStatus in project flowgate by vmware.
the class SyncWiremapDataJobTest method filterServersTest4.
// PduMappingStatus and NetworkMappingStatus is not null
@Test
public void filterServersTest4() {
List<Asset> servers = new ArrayList<Asset>();
Asset asset1 = new Asset();
asset1.setId("5c778c598ecf859960e2c2a0");
asset1.setAssetName("w1-lil-c-016");
asset1.setAssetNumber(33503);
asset1.setAssetSource("5c74da749662e398e01f665f");
asset1.setCategory(AssetCategory.Server);
asset1.setModel("Dell");
asset1.setManufacturer("Dell");
AssetStatus assetstatus = new AssetStatus();
assetstatus.setStatus(AssetStatus.Status.Active);
assetstatus.setPduMapping(PduMapping.MAPPEDBYLABSDB);
assetstatus.setNetworkMapping(NetworkMapping.MAPPEDBYLABSDB);
asset1.setStatus(assetstatus);
Asset asset = new Asset();
asset.setId("5c778c598ecf859960e2d395");
asset.setAssetName("w1-eeqa-fas3250-01");
asset.setAssetNumber(53135);
asset.setAssetSource("5c74da749662e398e01f665f");
asset.setCategory(AssetCategory.Server);
asset.setModel("NetApp");
asset.setManufacturer("NetApp");
AssetStatus status = new AssetStatus();
status.setStatus(AssetStatus.Status.Active);
asset.setStatus(status);
servers.add(asset);
servers.add(asset1);
List<Asset> assetResult = labsdbService.filterServers(servers);
TestCase.assertEquals(1, assetResult.size());
for (Asset asset2 : assetResult) {
if (asset2.getAssetName().equals("w1-eeqa-fas3250-01")) {
TestCase.assertEquals("5c778c598ecf859960e2d395", asset2.getId());
}
}
}
use of com.vmware.flowgate.common.AssetStatus in project flowgate by vmware.
the class HandleAssetUtil method getAssetsFromNlyte.
/**
* @param nlyteAssets
* @return
*/
public List<Asset> getAssetsFromNlyte(String nlyteSource, List<NlyteAsset> nlyteAssets, HashMap<Integer, LocationGroup> locationMap, HashMap<Integer, Material> materialMap, HashMap<Integer, Manufacturer> manufacturerMap, HashMap<Long, String> chassisMountedAssetNumberAndChassisIdMap) {
List<Asset> assetsFromNlyte = new ArrayList<Asset>();
Asset asset;
for (NlyteAsset nlyteAsset : nlyteAssets) {
asset = new Asset();
asset.setAssetNumber(nlyteAsset.getAssetNumber());
asset.setCabinetAssetNumber(String.valueOf(nlyteAsset.getCabinetAssetID()));
asset.setCabinetName(nlyteAsset.getCabinetName());
asset.setTag(nlyteAsset.getTag());
asset.setSerialnumber(nlyteAsset.getSerialNumber());
asset.setAssetName(nlyteAsset.getAssetName());
asset.setRow(nlyteAsset.getGridReferenceRow());
asset.setCol(nlyteAsset.getGridReferenceColumn());
asset = supplementLocation(asset, nlyteAsset.getLocationGroupID(), locationMap);
asset = supplementMaterial(asset, nlyteAsset.getMaterialID(), manufacturerMap, materialMap);
// we need to refactor the code
if (asset.getCategory() == null) {
continue;
}
if (asset.getCategory() == AssetCategory.Server) {
if (chassisMountedAssetNumberAndChassisIdMap != null && chassisMountedAssetNumberAndChassisIdMap.containsKey(asset.getAssetNumber())) {
Parent parent = new Parent();
parent.setType(AssetCategory.Chassis.name());
parent.setParentId(chassisMountedAssetNumberAndChassisIdMap.get(asset.getAssetNumber()));
asset.setParent(parent);
}
// set the tenant information.
List<CustomField> fields = nlyteAsset.getCustomFields();
if (fields != null) {
Tenant tenant = new Tenant();
for (CustomField cf : fields) {
if (cf.getDataLabel().equals(CustomField.Owner)) {
String dataValue = cf.getDataValueString();
if (!StringUtils.isEmpty(dataValue)) {
tenant.setOwner(dataValue);
tenant.setTenant(dataValue);
}
} else if (cf.getDataLabel().equals(CustomField.Tenant_EndUser)) {
String dataValue = cf.getDataValueString();
if (!StringUtils.isEmpty(dataValue)) {
tenant.setTenant(dataValue);
}
} else if (cf.getDataLabel().equals(CustomField.HaaS_RequestedBy)) {
String dataValue = cf.getDataValueString();
if (!StringUtils.isEmpty(dataValue)) {
tenant.setTenant(dataValue);
}
} else if (cf.getDataLabel().equals(CustomField.Tenant_Manager)) {
String dataValue = cf.getDataValueString();
if (!StringUtils.isEmpty(dataValue)) {
tenant.setTenantManager(dataValue);
}
}
}
asset.setTenant(tenant);
}
}
if (asset.getCategory().equals(AssetCategory.Cabinet)) {
String contiguousUSpace = nlyteAsset.getContiguousUSpace();
if (contiguousUSpace != null) {
int freeSize = 0;
String[] contiguousUSpaces = contiguousUSpace.split(FlowgateConstant.SPILIT_FLAG);
for (String uSpace : contiguousUSpaces) {
freeSize += Integer.parseInt(uSpace);
}
asset.setFreeCapacity(freeSize);
}
List<CabinetU> cabinetus = nlyteAsset.getCabinetUs();
if (cabinetus != null && !cabinetus.isEmpty()) {
List<com.vmware.flowgate.common.model.CabinetU> flowgateCabinetUs = new ArrayList<com.vmware.flowgate.common.model.CabinetU>();
for (CabinetU cabinetu : cabinetus) {
com.vmware.flowgate.common.model.CabinetU flowgateCabinetU = new com.vmware.flowgate.common.model.CabinetU();
flowgateCabinetU.setAssetsOnUnit(cabinetu.getAssetsOnU());
flowgateCabinetU.setCabinetUNumber(cabinetu.getCabinetUNumber());
if (CabinetU_State_Full.equals(cabinetu.getCabinetUState())) {
flowgateCabinetU.setUsed(true);
} else if (CabinetU_State_Free.equals(cabinetu.getCabinetUState())) {
flowgateCabinetU.setUsed(false);
}
flowgateCabinetUs.add(flowgateCabinetU);
}
try {
String cabinetUsInfo = mapper.writeValueAsString(flowgateCabinetUs);
HashMap<String, String> justficationfields = new HashMap<String, String>();
justficationfields.put(FlowgateConstant.CABINETUNITS, cabinetUsInfo);
asset.setJustificationfields(justficationfields);
} catch (JsonProcessingException e) {
logger.error("Failed to get info of cabinetUs.");
}
}
}
if (asset.getCategory().equals(AssetCategory.Chassis)) {
handleChassisSolts(asset, nlyteAsset);
}
if (asset.getCategory().equals(AssetCategory.Networks)) {
if (chassisMountedAssetNumberAndChassisIdMap != null && chassisMountedAssetNumberAndChassisIdMap.containsKey(asset.getAssetNumber())) {
Parent parent = new Parent();
parent.setType(AssetCategory.Chassis.name());
parent.setParentId(chassisMountedAssetNumberAndChassisIdMap.get(asset.getAssetNumber()));
asset.setParent(parent);
}
}
asset.setAssetSource(nlyteSource);
AssetStatus status = new AssetStatus();
status.setNetworkMapping(NetworkMapping.UNMAPPED);
status.setPduMapping(PduMapping.UNMAPPED);
asset.setStatus(status);
UMounting uMounting = nlyteAsset.getuMounting();
if (uMounting != null) {
asset.setCabinetUnitPosition(uMounting.getCabinetUNumber());
switch(MountingSide.valueOf(uMounting.getMountingSide())) {
case Front:
asset.setMountingSide(MountingSide.Front);
break;
case Back:
asset.setMountingSide(MountingSide.Back);
break;
case Unmounted:
asset.setMountingSide(MountingSide.Unmounted);
break;
default:
break;
}
}
asset.setCreated(System.currentTimeMillis());
assetsFromNlyte.add(asset);
}
return assetsFromNlyte;
}
use of com.vmware.flowgate.common.AssetStatus in project flowgate by vmware.
the class SyncWiremapDataJobTest method filterServersTest3.
// PduMappingStatus and NetworkMappingStatus is null
@Test
public void filterServersTest3() {
List<Asset> servers = new ArrayList<Asset>();
Asset asset1 = new Asset();
asset1.setId("5c778c598ecf859960e2c2a0");
asset1.setAssetName("w1-lil-c-016");
asset1.setAssetNumber(33503);
asset1.setAssetSource("5c74da749662e398e01f665f");
asset1.setCategory(AssetCategory.Server);
asset1.setModel("Dell");
asset1.setManufacturer("Dell");
AssetStatus assetstatus = new AssetStatus();
assetstatus.setStatus(AssetStatus.Status.Active);
asset1.setStatus(assetstatus);
Asset asset = new Asset();
asset.setId("5c778c598ecf859960e2d395");
asset.setAssetName("w1-eeqa-fas3250-01");
asset.setAssetNumber(53135);
asset.setAssetSource("5c74da749662e398e01f665f");
asset.setCategory(AssetCategory.Server);
asset.setModel("NetApp");
asset.setManufacturer("NetApp");
AssetStatus status = new AssetStatus();
status.setStatus(AssetStatus.Status.Active);
asset.setStatus(status);
servers.add(asset);
servers.add(asset1);
List<Asset> assetResult = labsdbService.filterServers(servers);
TestCase.assertEquals(2, assetResult.size());
for (Asset asset2 : assetResult) {
if (asset2.getAssetName().equals("w1-eeqa-fas3250-01")) {
TestCase.assertEquals("5c778c598ecf859960e2d395", asset2.getId());
}
}
}
use of com.vmware.flowgate.common.AssetStatus in project flowgate by vmware.
the class SyncWiremapDataJobTest method filterServersTest2.
// PduMappingStatus and NetworkMappingStatus is null
@Test
public void filterServersTest2() {
List<Asset> servers = new ArrayList<Asset>();
Asset asset1 = new Asset();
asset1.setId("5c778c598ecf859960e2c2a0");
asset1.setAssetName("w1-lil-c-016");
asset1.setAssetNumber(33503);
asset1.setAssetSource("5c74da749662e398e01f665f");
asset1.setCategory(AssetCategory.Server);
asset1.setModel("Dell");
asset1.setManufacturer("Dell");
AssetStatus assetstatus = new AssetStatus();
assetstatus.setStatus(AssetStatus.Status.Active);
asset1.setStatus(assetstatus);
Asset asset = new Asset();
asset.setId("5c778c598ecf859960e2d395");
asset.setAssetName("w1-eeqa-fas3250-01");
asset.setAssetNumber(53135);
asset.setAssetSource("5c74da749662e398e01f665f");
asset.setCategory(AssetCategory.Server);
asset.setModel("NetApp");
asset.setManufacturer("NetApp");
servers.add(asset);
servers.add(asset1);
List<Asset> assetResult = labsdbService.filterServers(servers);
TestCase.assertEquals(2, assetResult.size());
for (Asset asset2 : assetResult) {
if (asset2.getAssetName().equals("w1-lil-c-016")) {
TestCase.assertEquals("5c778c598ecf859960e2c2a0", asset2.getId());
}
}
}
Aggregations