def __getMirrorsToBuildFromConfigFile(self, gpArray): # create fileData object from config file # filename = self.__options.mirrorConfigFile rows = [] with open(filename) as f: for lineno, line in line_reader(f): fixed, flexible = parse_gpaddmirrors_line(filename, lineno, line) rows.append(ParsedConfigFileRow(fixed, flexible, line)) fileData = ParsedConfigFile([], rows) # validate fileData # allAddresses = [row.getFixedValuesMap()["address"] for row in fileData.getRows()] allNoneArr = [None for a in allAddresses] interfaceLookup = GpInterfaceToHostNameCache(self.__pool, allAddresses, allNoneArr) # # build up the output now # toBuild = [] primaries = [seg for seg in gpArray.getDbList() if seg.isSegmentPrimary(current_role=False)] segsByContentId = GpArray.getSegmentsByContentId(primaries) # note: passed port offset in this call should not matter calc = GpMirrorBuildCalculator(gpArray, [], self.__options) for row in fileData.getRows(): fixedValues = row.getFixedValuesMap() flexibleValues = row.getFlexibleValuesMap() contentId = int(fixedValues['contentId']) address = fixedValues['address'] # # read the rest and add the mirror # port = int(fixedValues['port']) dataDir = normalizeAndValidateInputPath(fixedValues['dataDirectory'], "in config file", row.getLine()) hostName = interfaceLookup.getHostName(address) if hostName is None: raise Exception("Segment Host Address %s is unreachable" % address) primary = segsByContentId[contentId] if primary is None: raise Exception("Invalid content %d specified in input file" % contentId) primary = primary[0] calc.addMirror(toBuild, primary, hostName, address, port, dataDir) if len(toBuild) != len(primaries): raise Exception("Wrong number of mirrors specified (specified %s mirror(s) for %s primarie(s))" % \ (len(toBuild), len(primaries))) return GpMirrorListToBuild(toBuild, self.__pool, self.__options.quiet, self.__options.parallelDegree)
def __getMirrorsToBuildFromConfigFile(self, gpArray): # create fileData object from config file # filename = self.__options.mirrorConfigFile fslist = None rows = [] with open(filename) as f: for lineno, line in line_reader(f): if fslist is None: fslist = parse_filespace_order(filename, lineno, line) else: fixed, flexible = parse_gpaddmirrors_line(filename, lineno, line, fslist) rows.append(ParsedConfigFileRow(fixed, flexible, line)) fileData = ParsedConfigFile(fslist, rows) # validate fileData # validateFlexibleHeadersListAllFilespaces("Mirror config", gpArray, fileData) filespaceNameToFilespace = dict([(fs.getName(), fs) for fs in gpArray.getFilespaces(False)]) allAddresses = [row.getFixedValuesMap()["address"] for row in fileData.getRows()] allNoneArr = [None for a in allAddresses] interfaceLookup = GpInterfaceToHostNameCache(self.__pool, allAddresses, allNoneArr) # # build up the output now # toBuild = [] primaries = [seg for seg in gpArray.getDbList() if seg.isSegmentPrimary(current_role=False)] segsByContentId = GpArray.getSegmentsByContentId(primaries) # note: passed port offset in this call should not matter calc = GpMirrorBuildCalculator(gpArray, self.__options.mirrorOffset, [], []) for row in fileData.getRows(): fixedValues = row.getFixedValuesMap() flexibleValues = row.getFlexibleValuesMap() contentId = int(fixedValues["contentId"]) address = fixedValues["address"] # # read the rest and add the mirror # port = int(fixedValues["port"]) replicationPort = int(fixedValues["replicationPort"]) primarySegmentReplicationPort = int(fixedValues["primarySegmentReplicationPort"]) dataDir = normalizeAndValidateInputPath(fixedValues["dataDirectory"], "in config file", row.getLine()) hostName = interfaceLookup.getHostName(address) if hostName is None: raise Exception("Segment Host Address %s is unreachable" % address) filespaceOidToPathMap = {} for fsName, path in flexibleValues.iteritems(): path = normalizeAndValidateInputPath(path, "in config file", row.getLine()) filespaceOidToPathMap[filespaceNameToFilespace[fsName].getOid()] = path primary = segsByContentId[contentId] if primary is None: raise Exception("Invalid content %d specified in input file" % contentId) primary = primary[0] calc.addMirror( toBuild, primary, hostName, address, port, dataDir, replicationPort, primarySegmentReplicationPort, filespaceOidToPathMap, ) if len(toBuild) != len(primaries): raise Exception( "Wrong number of mirrors specified (specified %s mirror(s) for %s primarie(s))" % (len(toBuild), len(primaries)) ) return GpMirrorListToBuild(toBuild, self.__pool, self.__options.quiet, self.__options.parallelDegree)