def printTopicInfo()

in aios/apps/facility/swift/py_tools/swift_tools/topic_cmd.py [0:0]


    def printTopicInfo(self):
        ret, response, errMsg = self.adminDelegate.getTopicInfo(self.topicName,
                                                                self.requestTimeout)
        if self.fromApi:
            return ret, response, errMsg
        if not ret:
            print "Get topic info failed!"
            print errMsg
            return "", "", 1

        if not response.HasField(swift_common_define.PROTO_TOPIC_INFO):
            print "ERROR: response does not have topicInfo field!"
            return "", "", 1

        topicInfo = response.topicInfo
        if self.cmdType == "summary" or self.cmdType == 'verbose':
            topicInfoAnalyzer = status_analyzer.TopicInfoAnalyzer()
            partCount = topicInfoAnalyzer.getPartitionCount(topicInfo)
            print "TopicName: %s" % topicInfo.name
            if topicInfo.topicMode == TOPIC_MODE_NORMAL:
                print "TopicMode: normal_mode"
            elif topicInfo.topicMode == TOPIC_MODE_SECURITY:
                print "TopicMode: security_mode"
                print "MaxCommitTime: %d" % topicInfo.maxWaitTimeForSecurityCommit
                print "MaxCommitSize: %d" % topicInfo.maxDataSizeForSecurityCommit
            elif topicInfo.topicMode == TOPIC_MODE_MEMORY_ONLY:
                print "TopicMode: memory_only_mode "
            elif topicInfo.topicMode == TOPIC_MODE_MEMORY_PREFER:
                print "TopicMode: memory_prefer_mode "
            if topicInfo.needFieldFilter:
                print "NeedFieldFilter: true"
            else:
                print "NeedFieldFilter: false"

            if topicInfo.needSchema:
                print "NeedSchema: true"
            else:
                print "NeedSchema: false"
            print "SchemaVersions: %s" % ','.join([str(x) for x in topicInfo.schemaVersions])
            print "TopicStatus: %s" % (
                swift_util.SwiftUtil.protoEnumToString(topicInfo, "status")[13:])
            print "PartitionCount: %d" % topicInfo.partitionCount
            print "RangeCountInPartition: %d" % topicInfo.rangeCountInPartition
            print "PartitionMaxBufferSize: %d" % topicInfo.partitionMaxBufferSize
            print "PartitionMinBufferSize: %d" % topicInfo.partitionMinBufferSize
            print "PartitionBufferSize: %d" % topicInfo.partitionBufferSize
            print "PartitionFileBufferSize: %d" % topicInfo.partitionFileBufferSize
            print "PartitionResource: %d" % topicInfo.resource
            print "PartitionLimit: %d" % topicInfo.partitionLimit
            print "ObsoleteFileTimeInterval: %d" % topicInfo.obsoleteFileTimeInterval
            print "ReservedFileCount: %d" % topicInfo.reservedFileCount
            if topicInfo.deleteTopicData:
                print "DeleteTopicData: true"
            else:
                print "DeleteTopicData: false"
            print "TopicGroup: %s" % topicInfo.topicGroup
            print "TopicExpiredTime: %d" % topicInfo.topicExpiredTime
            if 0 == len(topicInfo.owners):
                print "owners: %s" % 'NONE'
            else:
                print "owners: %s" % ','.join(topicInfo.owners)
            if topicInfo.topicType == TOPIC_TYPE_NORMAL:
                print "TopicType: TOPIC_TYPE_NORMAL"
            elif topicInfo.topicType == TOPIC_TYPE_PHYSIC:
                print "TopicType: TOPIC_TYPE_PHYSIC"
            elif topicInfo.topicType == TOPIC_TYPE_LOGIC:
                print "TopicType: TOPIC_TYPE_LOGIC"
            elif topicInfo.topicType == TOPIC_TYPE_LOGIC_PHYSIC:
                print "TopicType: TOPIC_TYPE_LOGIC_PHYSIC"
            if 0 == len(topicInfo.physicTopicLst):
                print "physicTopicLst: []"
            else:
                print "physicTopicLst: %s" % ','.join(topicInfo.physicTopicLst)
            if topicInfo.sealed:
                print "Sealed: true"
            else:
                print "Sealed: false"
            if topicInfo.enableTTLDel:
                print "enableTTLDel: true"
            else:
                print "enableTTLDel: false"
            print "readSizeLimitSec: %d" % topicInfo.readSizeLimitSec
            if topicInfo.enableLongPolling:
                print "enableLongPolling: true"
            else:
                print "enableLongPolling: false"
            if topicInfo.versionControl:
                print "versionControl: true"
            else:
                print "versionControl: false"
            if topicInfo.enableMergeData:
                print "enableMergeData: true"
            else:
                print "enableMergeData: false"
            if 0 == len(topicInfo.permitUser):
                print "permitUser: NONE"
            else:
                print "permitUser: %s" % ','.join(topicInfo.permitUser)
            if topicInfo.readNotCommittedMsg:
                print "readNotCommittedMsg: true"
            else:
                print "readNotCommittedMsg: false"
            print("Partition(waiting/starting/running/stopping/recovering/none): "
                  "%d/%d/%d/%d/%d/%d ") % (
                partCount.partWaiting,
                partCount.partStarting,
                partCount.partRunning,
                partCount.partStopping,
                partCount.partRecovering,
                partCount.partNone)

            if self.cmdType == "verbose":
                partInfos = topicInfoAnalyzer.getSortedPartitionInfo(
                    topicInfo, self.sortType)
                if len(partInfos) > 0:
                    print ""
                    print "Partition Detailed Infos:"
                    print '%-8s %-13s %-40s' % (
                        swift_common_define.PART_SORT_PART_ID,
                        swift_common_define.PART_SORT_PART_STATUS,
                        swift_common_define.PART_SORT_BROKER_ADDRESS)
                    for partInfo in partInfos:
                        print '%-8d %-13s %-40s' % (
                            partInfo.id,
                            swift_util.SwiftUtil.protoEnumToString(partInfo, "status")[17:],
                            partInfo.brokerAddress)
        elif self.cmdType == "message":
            print topicInfo

        return "", "", 0