Search in sources :

Example 6 with Tenant

use of com.vmware.flowgate.common.model.Tenant in project flowgate by vmware.

the class SycnRealTimeDataJobTest method testHandleAssets4.

@Test
public void testHandleAssets4() {
    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.Networks);
    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");
        }
    }
}
Also used : Tenant(com.vmware.flowgate.common.model.Tenant) HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) HashMap(java.util.HashMap) Parent(com.vmware.flowgate.common.model.Parent) ArrayList(java.util.ArrayList) 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 7 with Tenant

use of com.vmware.flowgate.common.model.Tenant 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 8 with Tenant

use of com.vmware.flowgate.common.model.Tenant in project flowgate by vmware.

the class AssetControllerTest method createAnAssetExample.

@Test
public void createAnAssetExample() throws JsonProcessingException, Exception {
    Asset asset = createAsset();
    this.mockMvc.perform(post("/v1/assets").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(asset))).andExpect(status().isCreated()).andExpect(header().string("Location", notNullValue())).andDo(document("assets-create-example", requestFields(fieldWithPath("id").description("ID of the asset, created by flowgate"), fieldWithPath("assetNumber").description("A unique number that can identify an asset from third part DCIM/CMDB systems.").type(long.class), fieldWithPath("assetName").description("The name of the asset in the third part DCIM/CMDB systems. Usually it will be a unique identifier of an asset"), fieldWithPath("assetSource").description("From which third part systems does this asset comes from. It will refer to a source collection which contains all the thirdpart systems"), fieldWithPath("category").description("The category of the asset. Can only be one of :Server, PDU, Cabinet, Networks, Sensors, UPS").type(AssetCategory.class), fieldWithPath("subCategory").description("The subcategory of the asset. Only apply to some systems.").type(AssetSubCategory.class).optional(), fieldWithPath("manufacturer").description("The manufacture name"), fieldWithPath("model").description("The model of the asset"), fieldWithPath("serialnumber").description("The SN number of the asset, this number can be used to identify an asset. But only some systems have this number.").optional(), fieldWithPath("tag").description("Some system will use tag to identify an asset. It can be either an number or a string.").type(String.class).optional(), fieldWithPath("assetAddress").description("The access address of the asset").type(AssetAddress.class).optional(), fieldWithPath("region").description("The location region of the asset").optional(), fieldWithPath("country").description("The location country of the asset").optional(), fieldWithPath("city").description("The location city of the asset").optional(), fieldWithPath("building").description("The location building of the asset").optional(), fieldWithPath("floor").description("The location floor of the asset").optional(), fieldWithPath("room").description("The location room of the asset"), fieldWithPath("row").description("The location row of the asset").optional(), fieldWithPath("col").description("The location col of the asset").optional(), fieldWithPath("extraLocation").description("Extra location information. Only valid for some system.").optional(), fieldWithPath("cabinetName").description("The cabinet name where this asset is located. If the asset is cabinet then this filed is empty.").optional(), fieldWithPath("cabinetUnitPosition").description("The cabinet unit number").type(int.class).optional(), fieldWithPath("mountingSide").description("The cabinet unit number").type(MountingSide.class).optional(), fieldWithPath("cabinetAssetNumber").description("The asset number of the cabinet. Will be used to search more detail information about the cabinet.").type(long.class).optional(), fieldWithPath("assetRealtimeDataSpec").description("Only valid for sensor type of asset.").type(AssetRealtimeDataSpec.class).optional(), subsectionWithPath("justificationfields").ignored(), subsectionWithPath("metricsformulars").ignored(), fieldWithPath("lastupdate").ignored(), fieldWithPath("created").ignored(), fieldWithPath("capacity").description("The capacity of asset.").type(int.class).optional(), fieldWithPath("freeCapacity").description("The free capacity of asset.").type(int.class).optional(), subsectionWithPath("parent").description("The parent of asset,it will be null unless the asset's category is Sensors").type(Parent.class).optional(), fieldWithPath("pdus").description("Possible PDUs that this server connected with"), fieldWithPath("switches").description("Physical switchs that this host connected with"), fieldWithPath("tenant").description("Tenant information for the asset").type(Tenant.class).optional(), subsectionWithPath("status").description("This is a collection of states, including the state of the asset, " + "the state of the pdu mapping, and the state of the switch mapping.")))).andReturn().getResponse().getHeader("Location");
    assetRepository.deleteById(asset.getId());
}
Also used : AssetRealtimeDataSpec(com.vmware.flowgate.common.model.AssetRealtimeDataSpec) Tenant(com.vmware.flowgate.common.model.Tenant) Parent(com.vmware.flowgate.common.model.Parent) Asset(com.vmware.flowgate.common.model.Asset) AssetAddress(com.vmware.flowgate.common.model.AssetAddress) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AssetSubCategory(com.vmware.flowgate.common.AssetSubCategory) MountingSide(com.vmware.flowgate.common.MountingSide) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

Asset (com.vmware.flowgate.common.model.Asset)8 Tenant (com.vmware.flowgate.common.model.Tenant)8 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 Parent (com.vmware.flowgate.common.model.Parent)5 HandleAssetUtil (com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil)5 FlowgateChassisSlot (com.vmware.flowgate.common.model.FlowgateChassisSlot)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ChassisMountedAssetMap (com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap)3 List (java.util.List)3 Map (java.util.Map)3 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 AssetStatus (com.vmware.flowgate.common.AssetStatus)1 AssetSubCategory (com.vmware.flowgate.common.AssetSubCategory)1 MountingSide (com.vmware.flowgate.common.MountingSide)1