use of com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testChassisSlotsIsChanged2.
@Test
public void testChassisSlotsIsChanged2() {
List<FlowgateChassisSlot> oldFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
FlowgateChassisSlot slot = createFlowgateChassisSlot();
oldFlowgateChassisSlots.add(slot);
HandleAssetUtil util = new HandleAssetUtil();
TestCase.assertEquals(true, util.chassisSlotsIsChanged(oldFlowgateChassisSlots, new ArrayList<FlowgateChassisSlot>()));
}
use of com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testHandleAssets2.
@Test
public void testHandleAssets2() {
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.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");
HashMap<String, String> oldjustficationMap = new HashMap<String, String>();
List<FlowgateChassisSlot> oldslots = new ArrayList<FlowgateChassisSlot>();
FlowgateChassisSlot oldslot1 = createFlowgateChassisSlot();
oldslot1.setMountingSide("Back");
oldslot1.setMountedAssetNumber(5523);
oldslots.add(oldslot1);
Map<String, String> oldChassisInfoMap = new HashMap<String, String>();
oldChassisInfoMap.put(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE, "frontToBack");
try {
String oldSlotsString = mapper.writeValueAsString(oldslots);
oldChassisInfoMap.put(FlowgateConstant.CHASSISSLOTS, oldSlotsString);
String oldChassisInfo = mapper.writeValueAsString(oldChassisInfoMap);
oldjustficationMap.put(FlowgateConstant.CHASSIS, oldChassisInfo);
oldAsset2.setJustificationfields(oldjustficationMap);
} catch (JsonProcessingException e) {
TestCase.fail(e.getMessage());
}
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());
} else {
TestCase.fail("Invalid assetNumber");
}
}
}
use of com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testChassisSlotsIsChanged.
@Test
public void testChassisSlotsIsChanged() {
List<FlowgateChassisSlot> oldFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
FlowgateChassisSlot slot = createFlowgateChassisSlot();
oldFlowgateChassisSlots.add(slot);
List<FlowgateChassisSlot> newFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
FlowgateChassisSlot slot1 = createFlowgateChassisSlot();
newFlowgateChassisSlots.add(slot1);
HandleAssetUtil util = new HandleAssetUtil();
TestCase.assertEquals(false, util.chassisSlotsIsChanged(oldFlowgateChassisSlots, newFlowgateChassisSlots));
}
use of com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil in project flowgate by vmware.
the class NlyteDataService method SyncAlldata.
private void SyncAlldata(FacilitySoftwareConfig nlyte) {
NlyteAPIClient nlyteAPIclient = createClient(nlyte);
restClient.setServiceKey(serviceKeyConfig.getServiceKey());
HandleAssetUtil assetUtil = new HandleAssetUtil();
List<NlyteAsset> nlyteAssets = null;
try {
nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.Cabinet);
} catch (HttpClientErrorException e) {
logger.error("Failed to query data from Nlyte", e);
IntegrationStatus integrationStatus = nlyte.getIntegrationStatus();
if (integrationStatus == null) {
integrationStatus = new IntegrationStatus();
}
integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
integrationStatus.setDetail(e.getMessage());
integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
updateIntegrationStatus(nlyte);
return;
} catch (ResourceAccessException e1) {
if (e1.getCause().getCause() instanceof ConnectException) {
checkAndUpdateIntegrationStatus(nlyte, e1.getMessage());
return;
}
}
HashMap<Long, String> chassisMountedAssetNumberAndChassisIdMap = null;
HashMap<Integer, LocationGroup> locationMap = assetUtil.initLocationGroupMap(nlyteAPIclient);
HashMap<Integer, Manufacturer> manufacturerMap = assetUtil.initManufacturersMap(nlyteAPIclient);
HashMap<Integer, Material> cabinetMaterialMap = new HashMap<Integer, Material>();
List<Material> cabinetMaterials = nlyteAPIclient.getMaterials(true, HandleAssetUtil.cabinetMaterials);
for (Material material : cabinetMaterials) {
material.setMaterialType(AssetCategory.Cabinet);
cabinetMaterialMap.put(material.getMaterialID(), material);
}
List<Asset> cabinetsNeedToSaveOrUpdate = generateAssets(nlyte.getId(), nlyteAssets, locationMap, manufacturerMap, cabinetMaterialMap, AssetCategory.Cabinet, chassisMountedAssetNumberAndChassisIdMap);
if (cabinetsNeedToSaveOrUpdate.isEmpty()) {
logger.info("No cabinet asset need to save");
} else {
restClient.saveAssets(cabinetsNeedToSaveOrUpdate);
logger.info("Finish sync the cabinets data for: " + nlyte.getName() + ", size: " + cabinetsNeedToSaveOrUpdate.size());
}
// init cabinetIdAndNameMap
HashMap<Integer, String> cabinetIdAndNameMap = getCabinetIdAndNameMap(nlyteAssets);
nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.Chassis);
nlyteAssets = supplementCabinetName(cabinetIdAndNameMap, nlyteAssets);
List<Material> chassisMaterials = nlyteAPIclient.getMaterials(true, HandleAssetUtil.chassisMaterials);
HashMap<Integer, Material> chassisMaterialMap = new HashMap<Integer, Material>();
for (Material material : chassisMaterials) {
material.setMaterialType(AssetCategory.Chassis);
chassisMaterialMap.put(material.getMaterialID(), material);
}
List<Asset> chassisNeedToSaveOrUpdate = generateAssets(nlyte.getId(), nlyteAssets, locationMap, manufacturerMap, chassisMaterialMap, AssetCategory.Chassis, chassisMountedAssetNumberAndChassisIdMap);
if (chassisNeedToSaveOrUpdate.isEmpty()) {
logger.info("No chassis asset need to save");
} else {
restClient.saveAssets(chassisNeedToSaveOrUpdate);
logger.info("Finish sync the chassis data for: " + nlyte.getName() + ", size: " + chassisNeedToSaveOrUpdate.size());
}
List<Asset> chassisFromFlowgate = restClient.getAllAssetsBySourceAndType(nlyte.getId(), AssetCategory.Chassis);
chassisMountedAssetNumberAndChassisIdMap = generateMountedAssetNumberAndChassisAssetIdMap(chassisFromFlowgate);
nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.Server);
nlyteAssets = supplementCabinetName(cabinetIdAndNameMap, nlyteAssets);
HashMap<Integer, Material> materialMap = assetUtil.initServerMaterialsMap(nlyteAPIclient);
List<Asset> serversNeedToSaveOrUpdate = generateAssets(nlyte.getId(), nlyteAssets, locationMap, manufacturerMap, materialMap, AssetCategory.Server, chassisMountedAssetNumberAndChassisIdMap);
if (serversNeedToSaveOrUpdate.isEmpty()) {
logger.info("No server asset need to save");
} else {
restClient.saveAssets(serversNeedToSaveOrUpdate);
logger.info("Finish sync the servers data for: " + nlyte.getName() + ", size: " + serversNeedToSaveOrUpdate.size());
}
HashMap<Integer, Material> pduMaterialMap = new HashMap<Integer, Material>();
nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.PDU);
nlyteAssets = supplementCabinetName(cabinetIdAndNameMap, nlyteAssets);
List<Material> powerStripMaterials = nlyteAPIclient.getMaterials(true, HandleAssetUtil.powerStripMaterial);
for (Material material : powerStripMaterials) {
material.setMaterialType(AssetCategory.PDU);
pduMaterialMap.put(material.getMaterialID(), material);
}
List<Asset> pDUsNeedToSaveOrUpdate = generateAssets(nlyte.getId(), nlyteAssets, locationMap, manufacturerMap, pduMaterialMap, AssetCategory.PDU, chassisMountedAssetNumberAndChassisIdMap);
if (pDUsNeedToSaveOrUpdate.isEmpty()) {
logger.info("No pdu asset need to save");
} else {
savePduAssetAndUpdatePduUsageFormula(pDUsNeedToSaveOrUpdate);
logger.info("Finish sync the pdus data for: " + nlyte.getName() + ", size: " + pDUsNeedToSaveOrUpdate.size());
}
HashMap<Integer, Material> networkMaterialMap = new HashMap<Integer, Material>();
nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.Networks);
nlyteAssets = supplementCabinetName(cabinetIdAndNameMap, nlyteAssets);
List<Material> networkMaterials = nlyteAPIclient.getMaterials(true, HandleAssetUtil.networkMaterials);
for (Material material : networkMaterials) {
material.setMaterialType(AssetCategory.Networks);
networkMaterialMap.put(material.getMaterialID(), material);
}
List<Asset> networkersNeedToSaveOrUpdate = generateAssets(nlyte.getId(), nlyteAssets, locationMap, manufacturerMap, networkMaterialMap, AssetCategory.Networks, chassisMountedAssetNumberAndChassisIdMap);
if (networkersNeedToSaveOrUpdate.isEmpty()) {
logger.info("No network asset need to save");
} else {
restClient.saveAssets(networkersNeedToSaveOrUpdate);
logger.info("Finish sync the networks data for: " + nlyte.getName() + ", size: " + networkersNeedToSaveOrUpdate.size());
}
}
use of com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil in project flowgate by vmware.
the class NlyteDataService method saveAssetForMappedData.
public void saveAssetForMappedData(String nlyteSource, List<NlyteAsset> nlyteAssets, HashMap<Integer, LocationGroup> locationMap, HashMap<Integer, Material> materialMap, HashMap<Integer, Manufacturer> manufacturerMap, AssetCategory category) {
HandleAssetUtil assetUtil = new HandleAssetUtil();
restClient.setServiceKey(serviceKeyConfig.getServiceKey());
List<Asset> allMappedAssets = Arrays.asList(restClient.getMappedAsset(category).getBody());
if (allMappedAssets.isEmpty()) {
return;
}
assetUtil.filterAssetBySourceAndCategory(allMappedAssets, nlyteSource, category);
List<Asset> assetsFromNlyte = assetUtil.getAssetsFromNlyte(nlyteSource, nlyteAssets, locationMap, materialMap, manufacturerMap, null);
Map<Long, Asset> assetsFromNlyteMap = assetUtil.generateAssetsMap(assetsFromNlyte);
List<Asset> updateAssets = new ArrayList<Asset>();
for (Asset asset : allMappedAssets) {
if (assetsFromNlyteMap.containsKey(asset.getAssetNumber())) {
Asset assetFromNlyte = assetsFromNlyteMap.get(asset.getAssetNumber());
asset.setTag(assetFromNlyte.getTag());
asset.setSerialnumber(assetFromNlyte.getSerialnumber());
asset.setAssetName(assetFromNlyte.getAssetName());
asset.setRegion(assetFromNlyte.getRegion());
asset.setCountry(assetFromNlyte.getCountry());
asset.setCity(assetFromNlyte.getCity());
asset.setBuilding(assetFromNlyte.getBuilding());
asset.setFloor(assetFromNlyte.getFloor());
asset.setRoom(assetFromNlyte.getRoom());
asset.setModel(assetFromNlyte.getModel());
asset.setManufacturer(assetFromNlyte.getManufacturer());
asset.setCategory(assetFromNlyte.getCategory());
asset.setSubCategory(assetFromNlyte.getSubCategory());
asset.setLastupdate(System.currentTimeMillis());
asset.setMountingSide(assetFromNlyte.getMountingSide());
asset.setTenant(assetFromNlyte.getTenant());
updateAssets.add(asset);
}
}
if (!updateAssets.isEmpty()) {
restClient.saveAssets(updateAssets);
}
}
Aggregations