public void getTableAndRoleLists()

in holo-shipper/src/main/java/com/alibaba/hologres/shipper/HoloShipper.java [159:231]


    public void getTableAndRoleLists() throws Exception{
        //find all tables need to ship and their owners
        JSONArray shipListJson = null;
        try
        {
            String shipListContent = new String(Files.readAllBytes(Paths.get(this.shipListPath)));
            shipListJson = JSON.parseArray(shipListContent);
        }
        catch (IOException e)
        {
            LOGGER.error("Failed reading ship list info from " + shipListPath, e);
            throw e;
        }
        List<String> dbList = source.getDBList();
        Set<String> roleSet = new HashSet<String>();
        for(int i=0; i<shipListJson.size(); i++) {
            JSONObject dbShipList = shipListJson.getJSONObject(i);
            String dbName = dbShipList.getString("dbName");
            if(dbName == null)
                throw new Exception("Invalid ship list json format, no database name");
            if(!dbList.contains(dbName)) {
                LOGGER.warn(String.format("Database %s does not exist, skipping", dbName));
                continue;
            }
            String sinkDb = dbShipList.getString("sinkDB");
            if(sinkDb == null) sinkDb = dbName;
            sinkDbNames.put(dbName, sinkDb);
            JSONObject shipList = dbShipList.getJSONObject("shipList");
            if(shipList == null)
                throw new Exception("Invalid ship list json format, no shipList");
            JSONObject blackList = dbShipList.getJSONObject("blackList");
            dbsToShip.add(dbName);
            AbstractDB db = source.getDB(dbName);
            TablesMeta tableListMeta = db.getMetadata(shipList, blackList, restoreOwner, restorePriv, restoreForeign, restoreView);
            Map<String, String> owners = tableListMeta.ownerInfo;
            if(restoreOwner && owners != null) {
                roleSet.addAll(owners.values());
            }
            Map<String, List<String>> grantees = tableListMeta.granteesInfo;
            if(restorePriv && grantees != null){
                for(List<String> tableGrantees: grantees.values())
                    roleSet.addAll(tableGrantees);
            }
            Map<String, List<String>> spm = tableListMeta.spmInfo;
            if(restorePriv && spm != null){
                for(List<String> spmUsers: spm.values())
                    roleSet.addAll(spmUsers);
            }
            Map<String, List<String>> slpm = tableListMeta.slpmInfo;
            if(restorePriv && slpm != null){
                for(List<String> slpmUsers: slpm.values())
                    roleSet.addAll(slpmUsers);
            }
            dbsMeta.put(dbName, tableListMeta);
            shipTableCount+= tableListMeta.tableInfoList.size();
            JSONObject schemaMappingJson = dbShipList.getJSONObject("schemaMapping");
            Map<String, String> schemaMapping = new HashMap<>();
            if(schemaMappingJson != null) {
                for(String oldSchema : schemaMappingJson.keySet())
                    schemaMapping.put(oldSchema, schemaMappingJson.getString(oldSchema));
            }
            schemaMappings.put(dbName, schemaMapping);

            JSONObject tgMappingJson = dbShipList.getJSONObject("tgMapping");
            Map<String, String> tgMapping = new HashMap<>();
            if(tgMappingJson != null) {
                for (String srcTG : tgMappingJson.keySet())
                    tgMapping.put(srcTG, tgMappingJson.getString(srcTG));
            }
            tgMappings.put(dbName, tgMapping);
        }
        roleList = new ArrayList<>(roleSet);
    }