Search in sources :

Example 21 with HandleAssetUtil

use of com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil in project flowgate by vmware.

the class SycnRealTimeDataJobTest method testSupplementChassisInfo.

@Test
public void testSupplementChassisInfo() {
    Asset asset = createAsset();
    HandleAssetUtil util = new HandleAssetUtil();
    util.supplementChassisInfo(asset, FlowgateConstant.CHASSIS_AIR_FLOW_TYPE, null);
    TestCase.assertEquals(true, asset.getJustificationfields().isEmpty());
}
Also used : HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 22 with HandleAssetUtil

use of com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil in project flowgate by vmware.

the class SycnRealTimeDataJobTest method testHandleAssets1.

/**
 * CHASSIS_AIR_FLOW_TYPE changed
 */
@Test
public void testHandleAssets1() {
    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, "leftToRight");
    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");
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) FlowgateChassisSlot(com.vmware.flowgate.common.model.FlowgateChassisSlot) Tenant(com.vmware.flowgate.common.model.Tenant) HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Map(java.util.Map) HashMap(java.util.HashMap) ChassisMountedAssetMap(com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 23 with HandleAssetUtil

use of com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil in project flowgate by vmware.

the class SycnRealTimeDataJobTest method testChassisSlotsIsChanged4.

@Test
public void testChassisSlotsIsChanged4() {
    List<FlowgateChassisSlot> oldFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
    FlowgateChassisSlot slot = createFlowgateChassisSlot();
    oldFlowgateChassisSlots.add(slot);
    List<FlowgateChassisSlot> newFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
    FlowgateChassisSlot slot1 = createFlowgateChassisSlot();
    slot1.setMountedAssetNumber(125);
    newFlowgateChassisSlots.add(slot1);
    HandleAssetUtil util = new HandleAssetUtil();
    TestCase.assertEquals(true, util.chassisSlotsIsChanged(oldFlowgateChassisSlots, newFlowgateChassisSlots));
}
Also used : FlowgateChassisSlot(com.vmware.flowgate.common.model.FlowgateChassisSlot) HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) ArrayList(java.util.ArrayList) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 24 with HandleAssetUtil

use of com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil in project flowgate by vmware.

the class NlyteAPIClient method getAssets.

public List<NlyteAsset> getAssets(boolean isAllData, AssetCategory category) {
    initAuthenticationWebToken();
    String getAssetsUrl = null;
    switch(category) {
        case Server:
            getAssetsUrl = getNlyteServiceEndpoint() + GetServerAssetsURL;
            break;
        case PDU:
            getAssetsUrl = getNlyteServiceEndpoint() + GetPowerStripAssetsURL;
            break;
        case Cabinet:
            getAssetsUrl = getNlyteServiceEndpoint() + GetCabinetsURL;
            break;
        case Networks:
            getAssetsUrl = getNlyteServiceEndpoint() + GetNetworksURL;
            break;
        case Chassis:
            getAssetsUrl = getNlyteServiceEndpoint() + GetChassisURL;
            break;
        default:
            throw new NlyteWorkerException("no such assets of the category ");
    }
    JsonResultForAsset nlyteAssetResult = this.restTemplate.exchange(getAssetsUrl, HttpMethod.GET, getDefaultEntity(), JsonResultForAsset.class).getBody();
    List<NlyteAsset> nlyteAssets = new LinkedList<NlyteAsset>();
    nlyteAssets = nlyteAssetResult.getValue();
    if (!isAllData) {
        return nlyteAssets;
    }
    URLDecoder decoder = new URLDecoder();
    List<NlyteAsset> nextPageNlyteAssets = null;
    String nextLink = nlyteAssetResult.getOdatanextLink();
    while (nextLink != null && !nextLink.equals("")) {
        nextLink = decoder.decode(nextLink);
        nextPageNlyteAssets = new ArrayList<NlyteAsset>();
        nlyteAssetResult = this.restTemplate.exchange(nextLink, HttpMethod.GET, getDefaultEntity(), JsonResultForAsset.class).getBody();
        nextPageNlyteAssets = nlyteAssetResult.getValue();
        nlyteAssets.addAll(nextPageNlyteAssets);
        nextLink = nlyteAssetResult.getOdatanextLink();
    }
    HandleAssetUtil util = new HandleAssetUtil();
    nlyteAssets = util.filterUnActivedAsset(nlyteAssets, category);
    return nlyteAssets;
}
Also used : HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) JsonResultForAsset(com.vmware.flowgate.nlyteworker.model.JsonResultForAsset) URLDecoder(java.net.URLDecoder) NlyteWorkerException(com.vmware.flowgate.nlyteworker.exception.NlyteWorkerException) LinkedList(java.util.LinkedList)

Example 25 with HandleAssetUtil

use of com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil in project flowgate by vmware.

the class NlyteDataService method syncMappedData.

private void syncMappedData(FacilitySoftwareConfig nlyte) {
    NlyteAPIClient nlyteAPIclient = new NlyteAPIClient(nlyte);
    HandleAssetUtil assetUtil = new HandleAssetUtil();
    List<NlyteAsset> nlyteAssets = null;
    try {
        nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.Server);
    } 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<Integer, LocationGroup> locationMap = assetUtil.initLocationGroupMap(nlyteAPIclient);
    HashMap<Integer, Material> materialMap = assetUtil.initServerMaterialsMap(nlyteAPIclient);
    HashMap<Integer, Manufacturer> manufacturerMap = assetUtil.initManufacturersMap(nlyteAPIclient);
    saveAssetForMappedData(nlyte.getId(), nlyteAssets, locationMap, materialMap, manufacturerMap, AssetCategory.Server);
    HashMap<Integer, Material> pduMaterialMap = new HashMap<Integer, Material>();
    nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.PDU);
    List<Material> powerStripMaterials = nlyteAPIclient.getMaterials(true, HandleAssetUtil.powerStripMaterial);
    for (Material material : powerStripMaterials) {
        material.setMaterialType(AssetCategory.PDU);
        pduMaterialMap.put(material.getMaterialID(), material);
    }
    saveAssetForMappedData(nlyte.getId(), nlyteAssets, locationMap, pduMaterialMap, manufacturerMap, AssetCategory.PDU);
    HashMap<Integer, Material> networksMaterialMap = new HashMap<Integer, Material>();
    nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.Networks);
    List<Material> networkMaterials = nlyteAPIclient.getMaterials(true, HandleAssetUtil.networkMaterials);
    for (Material material : networkMaterials) {
        material.setMaterialType(AssetCategory.Networks);
        networksMaterialMap.put(material.getMaterialID(), material);
    }
    saveAssetForMappedData(nlyte.getId(), nlyteAssets, locationMap, networksMaterialMap, manufacturerMap, AssetCategory.Networks);
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HashMap(java.util.HashMap) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Material(com.vmware.flowgate.nlyteworker.model.Material) ResourceAccessException(org.springframework.web.client.ResourceAccessException) NlyteAPIClient(com.vmware.flowgate.nlyteworker.restclient.NlyteAPIClient) HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) Manufacturer(com.vmware.flowgate.nlyteworker.model.Manufacturer) LocationGroup(com.vmware.flowgate.nlyteworker.model.LocationGroup) ConnectException(java.net.ConnectException)

Aggregations

HandleAssetUtil (com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil)26 Test (org.junit.Test)21 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)21 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)18 ArrayList (java.util.ArrayList)17 Asset (com.vmware.flowgate.common.model.Asset)16 FlowgateChassisSlot (com.vmware.flowgate.common.model.FlowgateChassisSlot)13 HashMap (java.util.HashMap)12 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 ChassisMountedAssetMap (com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap)6 List (java.util.List)6 Map (java.util.Map)6 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)6 Tenant (com.vmware.flowgate.common.model.Tenant)5 ChassisSlot (com.vmware.flowgate.nlyteworker.model.ChassisSlot)3 LocationGroup (com.vmware.flowgate.nlyteworker.model.LocationGroup)3 Manufacturer (com.vmware.flowgate.nlyteworker.model.Manufacturer)3 Material (com.vmware.flowgate.nlyteworker.model.Material)3 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)2