Search in sources :

Example 1 with DataCenter

use of com.vmware.flowgate.poweriqworker.model.DataCenter in project flowgate by vmware.

the class PowerIQService method getDataCentersMap.

public Map<Long, DataCenter> getDataCentersMap(PowerIQAPIClient client) {
    Map<Long, DataCenter> dataCentersMap = new HashMap<Long, DataCenter>();
    List<DataCenter> dataCenters = new ArrayList<DataCenter>();
    try {
        dataCenters = client.getDataCenters();
        if (dataCenters != null && !dataCenters.isEmpty()) {
            for (DataCenter dataCenter : dataCenters) {
                dataCentersMap.put(dataCenter.getId(), dataCenter);
            }
        }
    } catch (Exception e) {
        logger.error("Failed to get DataCenters information", e);
    }
    return dataCentersMap;
}
Also used : DataCenter(com.vmware.flowgate.poweriqworker.model.DataCenter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WormholeException(com.vmware.flowgate.common.exception.WormholeException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ResourceAccessException(org.springframework.web.client.ResourceAccessException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException)

Example 2 with DataCenter

use of com.vmware.flowgate.poweriqworker.model.DataCenter in project flowgate by vmware.

the class PowerIQService method fillLocation.

public Asset fillLocation(Parent parent, LocationInfo location) {
    Asset asset = null;
    StringBuilder extraLocation = new StringBuilder();
    asset = new Asset();
    if (parent == null) {
        return asset;
    }
    Map<Long, Rack> racksMap = location.getRacksMap();
    Map<Long, Row> rowsMap = location.getRowsMap();
    Map<Long, Aisle> aislesMap = location.getAislesMap();
    Map<Long, Room> roomsMap = location.getRoomsMap();
    Map<Long, Floor> floorsMap = location.getFloorsMap();
    Map<Long, DataCenter> dataCentersMap = location.getDataCentersMap();
    boolean rackMapisEmpty = racksMap == null || racksMap.isEmpty();
    boolean rowMapisEmpty = rowsMap == null || rowsMap.isEmpty();
    boolean aislesMapIsEmpty = aislesMap == null || aislesMap.isEmpty();
    boolean roomsMapIsEmpty = roomsMap == null || roomsMap.isEmpty();
    boolean floorMapIsEmpty = floorsMap == null || floorsMap.isEmpty();
    boolean dataCenterMapIsEmpty = dataCentersMap == null || dataCentersMap.isEmpty();
    while (parent != null) {
        // TO enhancement, we should record the wrong items for later usage.
        if (parent.getType() == null) {
            parent = null;
            break;
        }
        switch(parent.getType()) {
            case rack_type:
                if (rackMapisEmpty) {
                    parent = null;
                    break;
                }
                Rack rack = racksMap.get(parent.getId());
                if (rack == null) {
                    logger.info("Invalid rack id : " + parent.getId());
                    parent = null;
                    break;
                }
                extraLocation.append(rack_type + ":" + rack.getName() + "" + ";");
                parent = rack.getParent();
                break;
            case row_type:
                if (rowMapisEmpty) {
                    parent = null;
                    break;
                }
                Row row = rowsMap.get(parent.getId());
                if (row == null) {
                    logger.info("Invalid row id : " + parent.getId());
                    parent = null;
                    break;
                }
                asset.setRow(row.getName());
                parent = row.getParent();
                break;
            case aisle_type:
                if (aislesMapIsEmpty) {
                    parent = null;
                    break;
                }
                Aisle ailse = aislesMap.get(parent.getId());
                if (ailse == null) {
                    logger.info("Invalid ailse id : " + parent.getId());
                    parent = null;
                    break;
                }
                extraLocation.append(aisle_type + ":" + ailse.getName() + "");
                parent = ailse.getParent();
                break;
            case room_type:
                if (roomsMapIsEmpty) {
                    parent = null;
                    break;
                }
                Room room = roomsMap.get(parent.getId());
                if (room == null) {
                    logger.info("Invalid room id : " + parent.getId());
                    parent = null;
                    break;
                }
                asset.setRoom(room.getName());
                parent = room.getParent();
                break;
            case floor_type:
                if (floorMapIsEmpty) {
                    parent = null;
                    break;
                }
                Floor floor = floorsMap.get(parent.getId());
                if (floor == null) {
                    logger.info("Invalid floor id : " + parent.getId());
                    parent = null;
                    break;
                }
                asset.setFloor(floor.getName());
                parent = floor.getParent();
                break;
            case dataCenter_type:
                if (dataCenterMapIsEmpty) {
                    parent = null;
                    break;
                }
                DataCenter dataCenter = dataCentersMap.get(parent.getId());
                if (dataCenter == null) {
                    logger.info("Invalid dataCenter id : " + parent.getId());
                    parent = null;
                    break;
                }
                asset.setCity(dataCenter.getCity());
                asset.setCountry(dataCenter.getCountry());
                parent = dataCenter.getParent();
                break;
            default:
                logger.error(String.format("Unkown type %s", parent.getType()));
                parent = null;
                break;
        }
    }
    asset.setExtraLocation(extraLocation.toString());
    return asset;
}
Also used : Aisle(com.vmware.flowgate.poweriqworker.model.Aisle) Floor(com.vmware.flowgate.poweriqworker.model.Floor) Rack(com.vmware.flowgate.poweriqworker.model.Rack) DataCenter(com.vmware.flowgate.poweriqworker.model.DataCenter) Asset(com.vmware.flowgate.common.model.Asset) Row(com.vmware.flowgate.poweriqworker.model.Row) Room(com.vmware.flowgate.poweriqworker.model.Room)

Example 3 with DataCenter

use of com.vmware.flowgate.poweriqworker.model.DataCenter in project flowgate by vmware.

the class SyncSensorMetaDataJobTest method getDataCenters.

List<DataCenter> getDataCenters() {
    List<DataCenter> dataCenters = new ArrayList<DataCenter>();
    DataCenter dataCenter = new DataCenter();
    dataCenter.setName("DataCenter");
    dataCenter.setId(7);
    dataCenter.setCity("Yerevan");
    dataCenter.setCountry("Armenia");
    dataCenters.add(dataCenter);
    return dataCenters;
}
Also used : DataCenter(com.vmware.flowgate.poweriqworker.model.DataCenter) ArrayList(java.util.ArrayList)

Aggregations

DataCenter (com.vmware.flowgate.poweriqworker.model.DataCenter)3 ArrayList (java.util.ArrayList)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 WormholeException (com.vmware.flowgate.common.exception.WormholeException)1 Asset (com.vmware.flowgate.common.model.Asset)1 Aisle (com.vmware.flowgate.poweriqworker.model.Aisle)1 Floor (com.vmware.flowgate.poweriqworker.model.Floor)1 Rack (com.vmware.flowgate.poweriqworker.model.Rack)1 Room (com.vmware.flowgate.poweriqworker.model.Room)1 Row (com.vmware.flowgate.poweriqworker.model.Row)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 HashMap (java.util.HashMap)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1 ResourceAccessException (org.springframework.web.client.ResourceAccessException)1