Search in sources :

Example 1 with CabinetU

use of com.vmware.flowgate.nlyteworker.model.CabinetU in project flowgate by vmware.

the class HandleAssetUtil method getAssetsFromNlyte.

/**
 * @param nlyteAssets
 * @return
 */
public List<Asset> getAssetsFromNlyte(String nlyteSource, List<NlyteAsset> nlyteAssets, HashMap<Integer, LocationGroup> locationMap, HashMap<Integer, Material> materialMap, HashMap<Integer, Manufacturer> manufacturerMap, HashMap<Long, String> chassisMountedAssetNumberAndChassisIdMap) {
    List<Asset> assetsFromNlyte = new ArrayList<Asset>();
    Asset asset;
    for (NlyteAsset nlyteAsset : nlyteAssets) {
        asset = new Asset();
        asset.setAssetNumber(nlyteAsset.getAssetNumber());
        asset.setCabinetAssetNumber(String.valueOf(nlyteAsset.getCabinetAssetID()));
        asset.setCabinetName(nlyteAsset.getCabinetName());
        asset.setTag(nlyteAsset.getTag());
        asset.setSerialnumber(nlyteAsset.getSerialNumber());
        asset.setAssetName(nlyteAsset.getAssetName());
        asset.setRow(nlyteAsset.getGridReferenceRow());
        asset.setCol(nlyteAsset.getGridReferenceColumn());
        asset = supplementLocation(asset, nlyteAsset.getLocationGroupID(), locationMap);
        asset = supplementMaterial(asset, nlyteAsset.getMaterialID(), manufacturerMap, materialMap);
        // we need to refactor the code
        if (asset.getCategory() == null) {
            continue;
        }
        if (asset.getCategory() == AssetCategory.Server) {
            if (chassisMountedAssetNumberAndChassisIdMap != null && chassisMountedAssetNumberAndChassisIdMap.containsKey(asset.getAssetNumber())) {
                Parent parent = new Parent();
                parent.setType(AssetCategory.Chassis.name());
                parent.setParentId(chassisMountedAssetNumberAndChassisIdMap.get(asset.getAssetNumber()));
                asset.setParent(parent);
            }
            // set the tenant information.
            List<CustomField> fields = nlyteAsset.getCustomFields();
            if (fields != null) {
                Tenant tenant = new Tenant();
                for (CustomField cf : fields) {
                    if (cf.getDataLabel().equals(CustomField.Owner)) {
                        String dataValue = cf.getDataValueString();
                        if (!StringUtils.isEmpty(dataValue)) {
                            tenant.setOwner(dataValue);
                            tenant.setTenant(dataValue);
                        }
                    } else if (cf.getDataLabel().equals(CustomField.Tenant_EndUser)) {
                        String dataValue = cf.getDataValueString();
                        if (!StringUtils.isEmpty(dataValue)) {
                            tenant.setTenant(dataValue);
                        }
                    } else if (cf.getDataLabel().equals(CustomField.HaaS_RequestedBy)) {
                        String dataValue = cf.getDataValueString();
                        if (!StringUtils.isEmpty(dataValue)) {
                            tenant.setTenant(dataValue);
                        }
                    } else if (cf.getDataLabel().equals(CustomField.Tenant_Manager)) {
                        String dataValue = cf.getDataValueString();
                        if (!StringUtils.isEmpty(dataValue)) {
                            tenant.setTenantManager(dataValue);
                        }
                    }
                }
                asset.setTenant(tenant);
            }
        }
        if (asset.getCategory().equals(AssetCategory.Cabinet)) {
            String contiguousUSpace = nlyteAsset.getContiguousUSpace();
            if (contiguousUSpace != null) {
                int freeSize = 0;
                String[] contiguousUSpaces = contiguousUSpace.split(FlowgateConstant.SPILIT_FLAG);
                for (String uSpace : contiguousUSpaces) {
                    freeSize += Integer.parseInt(uSpace);
                }
                asset.setFreeCapacity(freeSize);
            }
            List<CabinetU> cabinetus = nlyteAsset.getCabinetUs();
            if (cabinetus != null && !cabinetus.isEmpty()) {
                List<com.vmware.flowgate.common.model.CabinetU> flowgateCabinetUs = new ArrayList<com.vmware.flowgate.common.model.CabinetU>();
                for (CabinetU cabinetu : cabinetus) {
                    com.vmware.flowgate.common.model.CabinetU flowgateCabinetU = new com.vmware.flowgate.common.model.CabinetU();
                    flowgateCabinetU.setAssetsOnUnit(cabinetu.getAssetsOnU());
                    flowgateCabinetU.setCabinetUNumber(cabinetu.getCabinetUNumber());
                    if (CabinetU_State_Full.equals(cabinetu.getCabinetUState())) {
                        flowgateCabinetU.setUsed(true);
                    } else if (CabinetU_State_Free.equals(cabinetu.getCabinetUState())) {
                        flowgateCabinetU.setUsed(false);
                    }
                    flowgateCabinetUs.add(flowgateCabinetU);
                }
                try {
                    String cabinetUsInfo = mapper.writeValueAsString(flowgateCabinetUs);
                    HashMap<String, String> justficationfields = new HashMap<String, String>();
                    justficationfields.put(FlowgateConstant.CABINETUNITS, cabinetUsInfo);
                    asset.setJustificationfields(justficationfields);
                } catch (JsonProcessingException e) {
                    logger.error("Failed to get info of cabinetUs.");
                }
            }
        }
        if (asset.getCategory().equals(AssetCategory.Chassis)) {
            handleChassisSolts(asset, nlyteAsset);
        }
        if (asset.getCategory().equals(AssetCategory.Networks)) {
            if (chassisMountedAssetNumberAndChassisIdMap != null && chassisMountedAssetNumberAndChassisIdMap.containsKey(asset.getAssetNumber())) {
                Parent parent = new Parent();
                parent.setType(AssetCategory.Chassis.name());
                parent.setParentId(chassisMountedAssetNumberAndChassisIdMap.get(asset.getAssetNumber()));
                asset.setParent(parent);
            }
        }
        asset.setAssetSource(nlyteSource);
        AssetStatus status = new AssetStatus();
        status.setNetworkMapping(NetworkMapping.UNMAPPED);
        status.setPduMapping(PduMapping.UNMAPPED);
        asset.setStatus(status);
        UMounting uMounting = nlyteAsset.getuMounting();
        if (uMounting != null) {
            asset.setCabinetUnitPosition(uMounting.getCabinetUNumber());
            switch(MountingSide.valueOf(uMounting.getMountingSide())) {
                case Front:
                    asset.setMountingSide(MountingSide.Front);
                    break;
                case Back:
                    asset.setMountingSide(MountingSide.Back);
                    break;
                case Unmounted:
                    asset.setMountingSide(MountingSide.Unmounted);
                    break;
                default:
                    break;
            }
        }
        asset.setCreated(System.currentTimeMillis());
        assetsFromNlyte.add(asset);
    }
    return assetsFromNlyte;
}
Also used : Parent(com.vmware.flowgate.common.model.Parent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AssetStatus(com.vmware.flowgate.common.AssetStatus) Tenant(com.vmware.flowgate.common.model.Tenant) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) UMounting(com.vmware.flowgate.nlyteworker.model.UMounting) CustomField(com.vmware.flowgate.nlyteworker.model.CustomField) CabinetU(com.vmware.flowgate.nlyteworker.model.CabinetU)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 AssetStatus (com.vmware.flowgate.common.AssetStatus)1 Asset (com.vmware.flowgate.common.model.Asset)1 Parent (com.vmware.flowgate.common.model.Parent)1 Tenant (com.vmware.flowgate.common.model.Tenant)1 CabinetU (com.vmware.flowgate.nlyteworker.model.CabinetU)1 CustomField (com.vmware.flowgate.nlyteworker.model.CustomField)1 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)1 UMounting (com.vmware.flowgate.nlyteworker.model.UMounting)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1