use of com.vmware.flowgate.nlyteworker.model.LocationGroup in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testGenerateNewAsset2.
@Test
public void testGenerateNewAsset2() {
List<NlyteAsset> nlyteAssets = getNlyteAsset();
HashMap<Integer, LocationGroup> locationMap = getLocationMap();
HashMap<Integer, Material> materialMap = new HashMap<Integer, Material>();
Material material = new Material();
material.setMaterialID(6251);
material.setManufacturerID(14);
material.setMaterialName("Cisco 1721 Modular Access Router");
material.setMaterialType(AssetCategory.Networks);
materialMap.put(6251, material);
HashMap<Integer, Manufacturer> manufacturerMap = new HashMap<Integer, Manufacturer>();
Manufacturer manufacturer = new Manufacturer();
manufacturer.setManufacturerID(14);
manufacturer.setDetail("Cisco");
manufacturerMap.put(14, manufacturer);
Mockito.when(this.wormholeAPIClient.getAllAssetsBySourceAndType("l9i8728d55368540fcba1692", AssetCategory.Server)).thenReturn(new ArrayList<Asset>());
HashMap<Long, String> chassisMountedAssetNumberAndChassisIDMap = new HashMap<Long, String>();
chassisMountedAssetNumberAndChassisIDMap.put(197L, "asdqe945kjsdf09uw45ms");
List<Asset> assets = nlyteDataService.generateAssets("l9i8728d55368540fcba1692", nlyteAssets, locationMap, manufacturerMap, materialMap, AssetCategory.Networks, chassisMountedAssetNumberAndChassisIDMap);
for (Asset asset : assets) {
if ("sin2-blrqeops-esxstress024".equals(asset.getAssetName())) {
TestCase.assertEquals(197, asset.getAssetNumber());
TestCase.assertEquals("SG-07-04", asset.getRoom());
TestCase.assertEquals("Cisco 1721 Modular Access Router", asset.getModel());
TestCase.assertEquals("Cisco", asset.getManufacturer());
TestCase.assertEquals("asdqe945kjsdf09uw45ms", asset.getParent().getParentId());
}
}
}
use of com.vmware.flowgate.nlyteworker.model.LocationGroup 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.model.LocationGroup in project flowgate by vmware.
the class HandleAssetUtil method initLocationGroupMap.
/**
* initLocationGroupMap information
*/
public HashMap<Integer, LocationGroup> initLocationGroupMap(NlyteAPIClient nlyteAPIclient) {
List<LocationGroup> locationGroups = nlyteAPIclient.getLocationGroups(true);
HashMap<Integer, LocationGroup> LocationMap = null;
if (locationGroups.isEmpty()) {
return null;
}
LocationMap = new HashMap<Integer, LocationGroup>();
for (LocationGroup locationGroup : locationGroups) {
LocationMap.put(locationGroup.getLocationGroupID(), locationGroup);
}
return LocationMap;
}
use of com.vmware.flowgate.nlyteworker.model.LocationGroup in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testGetAssetsFromNlytePdu.
@Test
public void testGetAssetsFromNlytePdu() {
String nlyteSource = "3cf0f5daff8e448da449ac88d5aa9428";
List<NlyteAsset> nlyteAssets = getNlyteAsset();
HashMap<Integer, LocationGroup> locationMap = getLocationMap();
HashMap<Integer, Material> materialMap = getMaterialMap();
Material material = new Material();
material.setMaterialID(6251);
material.setManufacturerID(14);
material.setMaterialName("Cisco 1721 Modular Access Router");
material.setMaterialType(AssetCategory.Server);
materialMap.put(6251, material);
HashMap<Integer, Manufacturer> manufacturerMap = getManufacturerMap();
Manufacturer manufacturer = new Manufacturer();
manufacturer.setManufacturerID(14);
manufacturer.setDetail("Cisco");
manufacturerMap.put(14, manufacturer);
HashMap<Long, String> chassisMountedAssetNumberAndChassisIdMap = null;
HandleAssetUtil util = new HandleAssetUtil();
List<Asset> assets = util.getAssetsFromNlyte(nlyteSource, nlyteAssets, locationMap, materialMap, manufacturerMap, chassisMountedAssetNumberAndChassisIdMap);
}
use of com.vmware.flowgate.nlyteworker.model.LocationGroup in project flowgate by vmware.
the class SycnRealTimeDataJobTest method testGenerateNewAsset.
@Test
public void testGenerateNewAsset() {
List<NlyteAsset> nlyteAssets = getNlyteAsset();
HashMap<Integer, LocationGroup> locationMap = getLocationMap();
HashMap<Integer, Material> materialMap = new HashMap<Integer, Material>();
Material material = new Material();
material.setMaterialID(6251);
material.setManufacturerID(14);
material.setMaterialName("Cisco 1721 Modular Access Router");
material.setMaterialType(AssetCategory.Server);
material.setMaterialSubtype(AssetSubCategory.Blade);
materialMap.put(6251, material);
HashMap<Integer, Manufacturer> manufacturerMap = new HashMap<Integer, Manufacturer>();
Manufacturer manufacturer = new Manufacturer();
manufacturer.setManufacturerID(14);
manufacturer.setDetail("Cisco");
manufacturerMap.put(14, manufacturer);
Mockito.when(this.wormholeAPIClient.getAllAssetsBySourceAndType("l9i8728d55368540fcba1692", AssetCategory.Server)).thenReturn(new ArrayList<Asset>());
HashMap<Long, String> chassisMountedAssetNumberAndChassisIDMap = new HashMap<Long, String>();
chassisMountedAssetNumberAndChassisIDMap.put(197L, "asdqe945kjsdf09uw45ms");
List<Asset> assets = nlyteDataService.generateAssets("l9i8728d55368540fcba1692", nlyteAssets, locationMap, manufacturerMap, materialMap, AssetCategory.Server, chassisMountedAssetNumberAndChassisIDMap);
for (Asset asset : assets) {
if ("sin2-blrqeops-esxstress024".equals(asset.getAssetName())) {
TestCase.assertEquals(197, asset.getAssetNumber());
TestCase.assertEquals("SG-07-04", asset.getRoom());
TestCase.assertEquals("Cisco 1721 Modular Access Router", asset.getModel());
TestCase.assertEquals("Cisco", asset.getManufacturer());
TestCase.assertEquals("asdqe945kjsdf09uw45ms", asset.getParent().getParentId());
}
}
}
Aggregations