use of com.vmware.flowgate.common.model.FlowgateChassisSlot in project flowgate by vmware.
the class HandleAssetUtil method handleAssets.
public List<Asset> handleAssets(List<Asset> toUpdateAssets, Map<Long, Asset> exsitingaAssetMap) {
List<Asset> resultAsset = new ArrayList<Asset>();
List<Asset> updateAsset = new ArrayList<Asset>();
Asset exsitingAsset = null;
if (exsitingaAssetMap == null) {
return toUpdateAssets;
}
for (Asset asset : toUpdateAssets) {
boolean isUpdated = false;
if (exsitingaAssetMap.containsKey(asset.getAssetNumber())) {
exsitingAsset = exsitingaAssetMap.get(asset.getAssetNumber());
if (valueIsChanged(exsitingAsset.getCabinetName(), asset.getCabinetName())) {
exsitingAsset.setCabinetName(asset.getCabinetName());
isUpdated = true;
}
if (valueIsChanged(exsitingAsset.getTag(), asset.getTag())) {
exsitingAsset.setTag(asset.getTag());
isUpdated = true;
}
if (valueIsChanged(exsitingAsset.getCapacity(), asset.getCapacity())) {
exsitingAsset.setCapacity(asset.getCapacity());
isUpdated = true;
}
if (valueIsChanged(exsitingAsset.getFreeCapacity(), asset.getFreeCapacity())) {
exsitingAsset.setFreeCapacity(asset.getFreeCapacity());
}
exsitingAsset.setSerialnumber(asset.getSerialnumber());
exsitingAsset.setAssetName(asset.getAssetName());
exsitingAsset.setRegion(asset.getRegion());
exsitingAsset.setCountry(asset.getCountry());
exsitingAsset.setCity(asset.getCity());
exsitingAsset.setBuilding(asset.getBuilding());
exsitingAsset.setFloor(asset.getFloor());
if (valueIsChanged(exsitingAsset.getRoom(), asset.getRoom())) {
exsitingAsset.setRoom(asset.getRoom());
isUpdated = true;
}
exsitingAsset.setModel(asset.getModel());
exsitingAsset.setManufacturer(asset.getManufacturer());
exsitingAsset.setCategory(asset.getCategory());
exsitingAsset.setSubCategory(asset.getSubCategory());
exsitingAsset.setLastupdate(System.currentTimeMillis());
if (valueIsChanged(exsitingAsset.getRow(), asset.getRow())) {
exsitingAsset.setRow(asset.getRow());
isUpdated = true;
}
if (valueIsChanged(exsitingAsset.getCol(), asset.getCol())) {
exsitingAsset.setCol(asset.getCol());
isUpdated = true;
}
if (exsitingAsset.getMountingSide() != asset.getMountingSide()) {
exsitingAsset.setMountingSide(asset.getMountingSide());
isUpdated = true;
}
String oldOwner = null;
String newOwner = null;
String oldTenantValue = null;
String newTenantValue = null;
String oldTenantManager = null;
String newTenantManager = null;
Tenant oldTenant = exsitingAsset.getTenant();
Tenant newTenant = asset.getTenant();
if (oldTenant != null) {
oldOwner = oldTenant.getOwner();
oldTenantValue = oldTenant.getTenant();
oldTenantManager = oldTenant.getTenantManager();
}
if (newTenant != null) {
newOwner = newTenant.getOwner();
newTenantValue = newTenant.getTenant();
newTenantManager = newTenant.getTenantManager();
}
if (valueIsChanged(oldOwner, newOwner) || valueIsChanged(oldTenantValue, newTenantValue) || valueIsChanged(oldTenantManager, newTenantManager)) {
exsitingAsset.setTenant(asset.getTenant());
isUpdated = true;
}
if (exsitingAsset.getCategory().equals(AssetCategory.Cabinet)) {
if (asset.getJustificationfields() != null && asset.getJustificationfields().get(FlowgateConstant.CABINETUNITS) != null) {
exsitingAsset.getJustificationfields().put(FlowgateConstant.CABINETUNITS, asset.getJustificationfields().get(FlowgateConstant.CABINETUNITS));
isUpdated = true;
}
}
if (exsitingAsset.getCategory().equals(AssetCategory.Chassis)) {
if (asset.getJustificationfields() != null && asset.getJustificationfields().get(FlowgateConstant.CHASSIS) != null) {
HashMap<String, String> newJustficationMap = asset.getJustificationfields();
HashMap<String, String> oldJustficationMap = exsitingAsset.getJustificationfields();
String newChassisInfo = newJustficationMap.get(FlowgateConstant.CHASSIS);
String oldChassisInfo = oldJustficationMap.get(FlowgateConstant.CHASSIS);
Map<String, String> newChassisInfoMap = null;
Map<String, String> oldChassisInfoMap = null;
try {
if (newChassisInfo != null) {
newChassisInfoMap = mapper.readValue(newChassisInfo, new TypeReference<Map<String, String>>() {
});
}
if (oldChassisInfo != null) {
oldChassisInfoMap = mapper.readValue(oldChassisInfo, new TypeReference<Map<String, String>>() {
});
}
} catch (Exception e) {
logger.error("Failed to read the data of chassis");
}
if (oldChassisInfoMap == null) {
if (newChassisInfoMap != null) {
oldJustficationMap.put(FlowgateConstant.CHASSIS, newChassisInfo);
exsitingAsset.setJustificationfields(oldJustficationMap);
isUpdated = true;
}
} else {
if (newChassisInfoMap != null) {
if (valueIsChanged(oldChassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE), newChassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE))) {
oldJustficationMap.put(FlowgateConstant.CHASSIS, newChassisInfo);
exsitingAsset.setJustificationfields(oldJustficationMap);
isUpdated = true;
} else {
String newChassisSlots = newChassisInfoMap.get(FlowgateConstant.CHASSISSLOTS);
String oldChassisSlots = oldChassisInfoMap.get(FlowgateConstant.CHASSISSLOTS);
List<FlowgateChassisSlot> newFlowgateChassisSlots = null;
List<FlowgateChassisSlot> oldFlowgateChassisSlots = null;
if (newChassisSlots != null) {
if (oldChassisSlots != null) {
try {
newFlowgateChassisSlots = mapper.readValue(newChassisSlots, new TypeReference<List<FlowgateChassisSlot>>() {
});
oldFlowgateChassisSlots = mapper.readValue(oldChassisSlots, new TypeReference<List<FlowgateChassisSlot>>() {
});
} catch (Exception e) {
logger.error("Failed to read the data of chassis");
}
if (chassisSlotsIsChanged(oldFlowgateChassisSlots, newFlowgateChassisSlots)) {
oldJustficationMap.put(FlowgateConstant.CHASSIS, newChassisInfo);
exsitingAsset.setJustificationfields(oldJustficationMap);
isUpdated = true;
}
} else {
oldJustficationMap.put(FlowgateConstant.CHASSIS, newChassisInfo);
exsitingAsset.setJustificationfields(oldJustficationMap);
isUpdated = true;
}
}
}
}
}
}
}
if (exsitingAsset.getCategory().equals(AssetCategory.Server) || exsitingAsset.getCategory().equals(AssetCategory.Networks)) {
Parent oldParent = exsitingAsset.getParent();
String oldParentId = null;
String oldParentType = null;
if (oldParent != null) {
oldParentId = oldParent.getParentId();
oldParentType = oldParent.getType();
}
Parent newParent = asset.getParent();
String newParentId = null;
String newParentType = null;
if (newParent != null) {
newParentId = newParent.getParentId();
newParentType = newParent.getType();
}
if (valueIsChanged(oldParentId, newParentId) || valueIsChanged(oldParentType, newParentType)) {
exsitingAsset.setParent(newParent);
isUpdated = true;
}
}
if (isUpdated) {
updateAsset.add(exsitingAsset);
}
} else {
asset.setCreated(System.currentTimeMillis());
resultAsset.add(asset);
}
}
resultAsset.addAll(updateAsset);
return resultAsset;
}
use of com.vmware.flowgate.common.model.FlowgateChassisSlot in project flowgate by vmware.
the class HandleAssetUtil method chassisSlotsIsChanged.
public boolean chassisSlotsIsChanged(List<FlowgateChassisSlot> oldFlowgateChassisSlots, List<FlowgateChassisSlot> newFlowgateChassisSlots) {
Map<String, FlowgateChassisSlot> oldSlotsMap = new HashMap<String, FlowgateChassisSlot>();
if (oldFlowgateChassisSlots != null) {
for (FlowgateChassisSlot slot : oldFlowgateChassisSlots) {
oldSlotsMap.put(slot.getMountingSide() + slot.getSlotName(), slot);
}
}
Map<String, FlowgateChassisSlot> newSlotsMap = new HashMap<String, FlowgateChassisSlot>();
if (newFlowgateChassisSlots != null) {
for (FlowgateChassisSlot slot : newFlowgateChassisSlots) {
newSlotsMap.put(slot.getMountingSide() + slot.getSlotName(), slot);
}
}
if (oldSlotsMap.size() != newSlotsMap.size()) {
return true;
}
for (Map.Entry<String, FlowgateChassisSlot> newSlotMap : newSlotsMap.entrySet()) {
String key = newSlotMap.getKey();
if (!oldSlotsMap.containsKey(key)) {
return true;
} else {
FlowgateChassisSlot newSlot = newSlotMap.getValue();
FlowgateChassisSlot oldSlot = oldSlotsMap.get(key);
if (valueIsChanged(oldSlot.getMountedAssetNumber(), newSlot.getMountedAssetNumber())) {
return true;
}
if (valueIsChanged(oldSlot.getColumnPosition(), newSlot.getColumnPosition())) {
return true;
}
if (valueIsChanged(oldSlot.getRowPosition(), newSlot.getRowPosition())) {
return true;
}
}
}
return false;
}
use of com.vmware.flowgate.common.model.FlowgateChassisSlot in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testHandleChassisSolts2.
@Test
public void testHandleChassisSolts2() {
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);
List<ChassisMountedAssetMap> cmAssets = new ArrayList<ChassisMountedAssetMap>();
ChassisMountedAssetMap cmAsset = new ChassisMountedAssetMap();
cmAsset.setMountedAssetID(197);
cmAsset.setMountingSide("Front");
cmAsset.setSlotName("1");
cmAssets.add(cmAsset);
ChassisMountedAssetMap cmAsset2 = new ChassisMountedAssetMap();
cmAsset2.setMountedAssetID(198);
cmAsset2.setMountingSide("Back");
cmAsset2.setSlotName("2");
cmAssets.add(cmAsset2);
NlyteAsset nlyteAsset = getNlyteAsset().get(0);
nlyteAsset.setChassisSlots(chassisSolts);
nlyteAsset.setChassisMountedAssetMaps(cmAssets);
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(197), 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.FlowgateChassisSlot in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testChassisSlotsIsChanged5.
@Test
public void testChassisSlotsIsChanged5() {
List<FlowgateChassisSlot> oldFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
FlowgateChassisSlot slot = createFlowgateChassisSlot();
oldFlowgateChassisSlots.add(slot);
List<FlowgateChassisSlot> newFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
FlowgateChassisSlot slot1 = createFlowgateChassisSlot();
slot1.setColumnPosition(2);
newFlowgateChassisSlots.add(slot1);
HandleAssetUtil util = new HandleAssetUtil();
TestCase.assertEquals(true, util.chassisSlotsIsChanged(oldFlowgateChassisSlots, newFlowgateChassisSlots));
}
use of com.vmware.flowgate.common.model.FlowgateChassisSlot in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testChassisSlotsIsChanged6.
@Test
public void testChassisSlotsIsChanged6() {
List<FlowgateChassisSlot> oldFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
FlowgateChassisSlot slot = createFlowgateChassisSlot();
oldFlowgateChassisSlots.add(slot);
List<FlowgateChassisSlot> newFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
FlowgateChassisSlot slot1 = createFlowgateChassisSlot();
slot1.setRowPosition(2);
newFlowgateChassisSlots.add(slot1);
HandleAssetUtil util = new HandleAssetUtil();
TestCase.assertEquals(true, util.chassisSlotsIsChanged(oldFlowgateChassisSlots, newFlowgateChassisSlots));
}
Aggregations