use of com.vmware.flowgate.common.model.Asset 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.model.Asset in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testHandleChassisSolts3.
@Test
public void testHandleChassisSolts3() {
Asset asset = createAsset();
List<ChassisMountedAssetMap> chassisMaps = new ArrayList<ChassisMountedAssetMap>();
ChassisMountedAssetMap cMap1 = new ChassisMountedAssetMap();
cMap1.setMountedAssetID(105);
cMap1.setColumnPosition(1);
cMap1.setRowPosition(1);
cMap1.setMountingSide("Front");
cMap1.setSlotName("1");
chassisMaps.add(cMap1);
ChassisMountedAssetMap cMap2 = new ChassisMountedAssetMap();
cMap2.setMountedAssetID(198);
cMap2.setColumnPosition(1);
cMap2.setRowPosition(2);
cMap2.setMountingSide("Back");
cMap2.setSlotName("2");
chassisMaps.add(cMap2);
NlyteAsset nlyteAsset = getNlyteAsset().get(0);
nlyteAsset.setChassisMountedAssetMaps(chassisMaps);
HandleAssetUtil util = new HandleAssetUtil();
util.handleChassisSolts(asset, nlyteAsset);
String chassisInfo = asset.getJustificationfields().get(FlowgateConstant.CHASSIS);
ObjectMapper mapper = new ObjectMapper();
try {
Map<String, String> chassisInfoMap = mapper.readValue(chassisInfo, new TypeReference<Map<String, String>>() {
});
List<FlowgateChassisSlot> slots = mapper.readValue(chassisInfoMap.get(FlowgateConstant.CHASSISSLOTS), new TypeReference<List<FlowgateChassisSlot>>() {
});
for (FlowgateChassisSlot chassisslot : slots) {
if (chassisslot.getSlotName().equals("1")) {
TestCase.assertEquals("Front", chassisslot.getMountingSide());
TestCase.assertEquals(Integer.valueOf(105), chassisslot.getMountedAssetNumber());
} else if (chassisslot.getSlotName().equals("2")) {
TestCase.assertEquals("Back", chassisslot.getMountingSide());
TestCase.assertEquals(Integer.valueOf(198), chassisslot.getMountedAssetNumber());
} else {
TestCase.fail();
}
}
} catch (JsonProcessingException e) {
TestCase.fail(e.getMessage());
}
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testHandleAssets3.
@Test
public void testHandleAssets3() {
List<Asset> toUpdateAssets = new ArrayList<Asset>();
Map<Long, Asset> exsitingaAssetMap = new HashMap<Long, Asset>();
Asset asset = createAsset();
asset.setAssetNumber(127);
asset.setTag("tag1");
toUpdateAssets.add(asset);
Asset asset2 = createAsset();
asset2.setAssetNumber(128);
asset2.setTag("tag2");
asset2.setCabinetName("cabinet1");
Tenant tenant = new Tenant();
tenant.setOwner("admin");
tenant.setTenant("tenant");
tenant.setTenantManager("manager");
asset2.setTenant(tenant);
asset2.setRoom("room1");
asset2.setRow("r2");
asset2.setCol("c2");
asset2.setMountingSide(MountingSide.Front);
asset2.setCategory(AssetCategory.Server);
Parent parent = new Parent();
parent.setParentId("ouqwenkja72hoas9034a");
parent.setType("Chassis");
asset2.setParent(parent);
toUpdateAssets.add(asset2);
Asset oldAsset1 = createAsset();
oldAsset1.setAssetNumber(127);
oldAsset1.setTag("oldtag1");
exsitingaAssetMap.put(oldAsset1.getAssetNumber(), oldAsset1);
Asset oldAsset2 = createAsset();
oldAsset2.setAssetNumber(128);
oldAsset2.setTag("oldtag2");
exsitingaAssetMap.put(oldAsset2.getAssetNumber(), oldAsset2);
HandleAssetUtil util = new HandleAssetUtil();
List<Asset> assets = util.handleAssets(toUpdateAssets, exsitingaAssetMap);
for (Asset assetTosave : assets) {
if (assetTosave.getAssetNumber() == 128) {
TestCase.assertEquals(asset2.getTag(), assetTosave.getTag());
TestCase.assertEquals(asset2.getRoom(), assetTosave.getRoom());
TestCase.assertEquals(asset2.getRow(), assetTosave.getRow());
TestCase.assertEquals(asset2.getCol(), assetTosave.getCol());
TestCase.assertEquals(asset2.getMountingSide(), assetTosave.getMountingSide());
TestCase.assertEquals(asset2.getTenant().getOwner(), assetTosave.getTenant().getOwner());
HashMap<String, String> justfications = assetTosave.getJustificationfields();
TestCase.assertEquals("ouqwenkja72hoas9034a", assetTosave.getParent().getParentId());
} else if (assetTosave.getAssetNumber() == 127) {
TestCase.assertEquals(asset.getTag(), assetTosave.getTag());
} else {
TestCase.fail("Invalid assetNumber");
}
}
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testHandleChassisSolts1.
@Test
public void testHandleChassisSolts1() {
Asset asset = createAsset();
List<ChassisSlot> chassisSolts = new ArrayList<ChassisSlot>();
ChassisSlot slot = new ChassisSlot();
slot.setChassisAssetID(105);
slot.setColumnPosition(1);
slot.setRowPosition(1);
slot.setMountingSide("Front");
slot.setSlotName("1");
slot.setId(78);
chassisSolts.add(slot);
ChassisSlot slot2 = new ChassisSlot();
slot2.setChassisAssetID(105);
slot2.setColumnPosition(1);
slot2.setRowPosition(2);
slot2.setMountingSide("Back");
slot2.setSlotName("2");
slot2.setId(79);
chassisSolts.add(slot2);
NlyteAsset nlyteAsset = getNlyteAsset().get(0);
nlyteAsset.setChassisSlots(chassisSolts);
HandleAssetUtil util = new HandleAssetUtil();
util.handleChassisSolts(asset, nlyteAsset);
String chassisInfo = asset.getJustificationfields().get(FlowgateConstant.CHASSIS);
ObjectMapper mapper = new ObjectMapper();
try {
Map<String, String> chassisInfoMap = mapper.readValue(chassisInfo, new TypeReference<Map<String, String>>() {
});
List<FlowgateChassisSlot> slots = mapper.readValue(chassisInfoMap.get(FlowgateConstant.CHASSISSLOTS), new TypeReference<List<FlowgateChassisSlot>>() {
});
for (FlowgateChassisSlot chassisslot : slots) {
if (chassisslot.getSlotName().equals("1")) {
TestCase.assertEquals("Front", chassisslot.getMountingSide());
} else if (chassisslot.getSlotName().equals("2")) {
TestCase.assertEquals("Back", chassisslot.getMountingSide());
} else {
TestCase.fail();
}
}
} catch (JsonProcessingException e) {
TestCase.fail(e.getMessage());
}
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testHandleAssets.
/**
* New asset have chassis info but old assets none
*/
@Test
public void testHandleAssets() {
List<Asset> toUpdateAssets = new ArrayList<Asset>();
Map<Long, Asset> exsitingaAssetMap = new HashMap<Long, Asset>();
Asset asset = createAsset();
asset.setAssetNumber(127);
asset.setTag("tag1");
asset.setCapacity(8);
asset.setFreeCapacity(2);
toUpdateAssets.add(asset);
Asset asset2 = createAsset();
asset2.setAssetNumber(128);
asset2.setTag("tag2");
asset2.setCabinetName("cabinet1");
Tenant tenant = new Tenant();
tenant.setOwner("admin");
tenant.setTenant("tenant");
tenant.setTenantManager("manager");
asset2.setTenant(tenant);
asset2.setRoom("room1");
asset2.setRow("r2");
asset2.setCol("c2");
asset2.setMountingSide(MountingSide.Front);
asset2.setCategory(AssetCategory.Chassis);
HashMap<String, String> justficationMap = new HashMap<String, String>();
List<FlowgateChassisSlot> slots = new ArrayList<FlowgateChassisSlot>();
FlowgateChassisSlot slot1 = createFlowgateChassisSlot();
slots.add(slot1);
Map<String, String> chassisInfoMap = new HashMap<String, String>();
chassisInfoMap.put(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE, "frontToBack");
ObjectMapper mapper = new ObjectMapper();
try {
String slotsString = mapper.writeValueAsString(slots);
chassisInfoMap.put(FlowgateConstant.CHASSISSLOTS, slotsString);
String chassisInfo = mapper.writeValueAsString(chassisInfoMap);
justficationMap.put(FlowgateConstant.CHASSIS, chassisInfo);
asset2.setJustificationfields(justficationMap);
} catch (JsonProcessingException e) {
TestCase.fail(e.getMessage());
}
toUpdateAssets.add(asset2);
Asset oldAsset1 = createAsset();
oldAsset1.setAssetNumber(127);
oldAsset1.setTag("oldtag1");
exsitingaAssetMap.put(oldAsset1.getAssetNumber(), oldAsset1);
Asset oldAsset2 = createAsset();
oldAsset2.setAssetNumber(128);
oldAsset2.setTag("oldtag2");
exsitingaAssetMap.put(oldAsset2.getAssetNumber(), oldAsset2);
HandleAssetUtil util = new HandleAssetUtil();
List<Asset> assets = util.handleAssets(toUpdateAssets, exsitingaAssetMap);
for (Asset assetTosave : assets) {
if (assetTosave.getAssetNumber() == 128) {
TestCase.assertEquals(asset2.getTag(), assetTosave.getTag());
TestCase.assertEquals(asset2.getRoom(), assetTosave.getRoom());
TestCase.assertEquals(asset2.getRow(), assetTosave.getRow());
TestCase.assertEquals(asset2.getCol(), assetTosave.getCol());
TestCase.assertEquals(asset2.getMountingSide(), assetTosave.getMountingSide());
TestCase.assertEquals(asset2.getTenant().getOwner(), assetTosave.getTenant().getOwner());
HashMap<String, String> justfications = assetTosave.getJustificationfields();
String chassisInfo = justfications.get(FlowgateConstant.CHASSIS);
try {
Map<String, String> newChassisInfoMap = mapper.readValue(chassisInfo, new TypeReference<Map<String, String>>() {
});
TestCase.assertEquals(chassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE), newChassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE));
String chassisSlots = newChassisInfoMap.get(FlowgateConstant.CHASSISSLOTS);
List<FlowgateChassisSlot> flowgateSlots = mapper.readValue(chassisSlots, new TypeReference<List<FlowgateChassisSlot>>() {
});
TestCase.assertEquals(slot1.getMountingSide(), flowgateSlots.get(0).getMountingSide());
TestCase.assertEquals(slot1.getMountedAssetNumber(), flowgateSlots.get(0).getMountedAssetNumber());
TestCase.assertEquals(slot1.getColumnPosition(), flowgateSlots.get(0).getColumnPosition());
TestCase.assertEquals(slot1.getRowPosition(), flowgateSlots.get(0).getRowPosition());
TestCase.assertEquals(slot1.getSlotName(), flowgateSlots.get(0).getSlotName());
} catch (Exception e) {
TestCase.fail(e.getMessage());
}
} else if (assetTosave.getAssetNumber() == 127) {
TestCase.assertEquals(asset.getTag(), assetTosave.getTag());
TestCase.assertEquals(asset.getCapacity(), assetTosave.getCapacity());
TestCase.assertEquals(asset.getFreeCapacity(), assetTosave.getFreeCapacity());
} else {
TestCase.fail("Invalid assetNumber");
}
}
}
Aggregations