def getPublications(self, publisherName, publisherSqlServer, publisher, oshv, sqlServerId): logger.debug('going to get publisher: ', publisherName) query = Util.replace(Queries.PUBLICATION_FROM_DISTRIBUTOR, publisherName) rs = self.connection.doCall(query) publications = ArrayList() #we connect the publication to the database using container_f while (rs.next()): databaseName = rs.getString('publisher_db') publicationName = rs.getString('publication') type = rs.getInt('publication_type') publication = ObjectStateHolder('sqlserverpublication') db = self.getDatabase(publisherSqlServer, databaseName) publication.setAttribute(Queries.DATA_NAME, publicationName) publication.setContainer(db) publication.setAttribute('publicationType', PUBLICATION_TYPE[int(type)]) oshv.add(db) oshv.add(publication) publications.add(publication) rs.close() logger.debug('got publications: ', publications.toString()) #after we finished with the publication, we should get the subscription, this could be very very tricky!!! itr = publications.iterator() while (itr.hasNext()): publication = itr.next() publicationDbName = publication.getAttribute( Queries.DATA_NAME).getValue() values = [ publisherName, publicationDbName, publication.getAttribute(Queries.DATA_NAME).getValue() ] query = Util.replaceAllByArray( Queries.SUBSCRIPTIONS_FROM_DISRIBUTOR_BY_PUBLICATION, values) rs = self.connection.doCall(query) while (rs.next()): subscriberName = rs.getString('subscriber') sqlServer = self.createSqlServer(subscriberName, oshv, sqlServerId) #create the subscriber object and the subscription: databaseName = rs.getString('subscriber_db') subscription = ObjectStateHolder('sqlserversubscription') subscription.setAttribute(Queries.DATA_NAME, databaseName) sd = self.getDatabase(sqlServer, databaseName) subscription.setContainer(sd) logger.debug('got subscription: ', subscriberName, " : ", 'databaseName') oshv.add(sqlServer) oshv.add(sd) oshv.add(subscription) #create the database and the links: #let try the replicated link pd = self.getDatabase(publisherSqlServer, publicationDbName) oshv.add(modeling.createLinkOSH('replicated', pd, sd)) rs.close()
def getPublications(self,publisherName,publisherSqlServer,publisher,oshv,sqlServerId): logger.debug('going to get publisher: ', publisherName) query = Util.replace(Queries.PUBLICATION_FROM_DISTRIBUTOR,publisherName) rs = self.connection.doCall(query) publications = ArrayList() #we connect the publication to the database using container_f while(rs.next()): databaseName = rs.getString('publisher_db') publicationName = rs.getString('publication') type = rs.getInt('publication_type') publication = ObjectStateHolder('sqlserverpublication') db = self.getDatabase(publisherSqlServer,databaseName) publication.setAttribute(Queries.DATA_NAME,publicationName) publication.setContainer(db) publication.setAttribute('publicationType',PUBLICATION_TYPE[int(type)]) oshv.add(db) oshv.add(publication) publications.add(publication) rs.close() logger.debug('got publications: ', publications.toString()) #after we finished with the publication, we should get the subscription, this could be very very tricky!!! itr = publications.iterator() while (itr.hasNext()): publication = itr.next() publicationDbName = publication.getAttribute(Queries.DATA_NAME).getValue() values = [publisherName,publicationDbName,publication.getAttribute(Queries.DATA_NAME).getValue()] query = Util.replaceAllByArray(Queries.SUBSCRIPTIONS_FROM_DISRIBUTOR_BY_PUBLICATION,values) rs = self.connection.doCall(query) while (rs.next()): subscriberName = rs.getString('subscriber') sqlServer = self.createSqlServer(subscriberName,oshv,sqlServerId) #create the subscriber object and the subscription: databaseName = rs.getString('subscriber_db') subscription = ObjectStateHolder('sqlserversubscription') subscription.setAttribute(Queries.DATA_NAME,databaseName) sd = self.getDatabase(sqlServer,databaseName) subscription.setContainer(sd) logger.debug('got subscription: ', subscriberName, " : ", 'databaseName') oshv.add(sqlServer) oshv.add(sd) oshv.add(subscription) #create the database and the links: #let try the replicated link pd = self.getDatabase(publisherSqlServer,publicationDbName) oshv.add(modeling.createLinkOSH('replicated',pd,sd)) rs.close()
def mainFunction(resBuffer, cfPath, shUtils, OSHVResult, protocol, Framework, lastUpdateTime): # Parsing the main.cf file by a reg exp that returns (Element type, name and properties) reg = '(\w+)\s([^\s]+)\s\(([^\)]+)\)' compiled = re.compile(reg) matches = compiled.findall(resBuffer) clusterName = None groupName = None veritasclusterOSH = None vcsGroupOSH = None clusterDeviceOSH = None resourceNameToOSH = {} nodeNameToOSH = {} nodeNameToFSSWOSH = {} for match in matches: element_type = match[0].strip() element_name = match[1].strip() element_prop = match[2].strip() # Handle the cluster element if element_type == 'cluster': clusterName = element_name veritasclusterOSH = ObjectStateHolder('veritascluster') veritasclusterOSH.setAttribute('data_name', clusterName) modeling.setAppSystemVendor(veritasclusterOSH) OSHVResult.add(veritasclusterOSH) # Create configuration file object containing the zipped main.cf configFileOsh = modeling.createConfigurationDocumentOSH("main.cf.properties", "NA", resBuffer, veritasclusterOSH, modeling.MIME_TEXT_PLAIN, lastUpdateTime, 'main.cf') OSHVResult.add(configFileOsh) # Handle the system element (Cluster nodes) elif element_type == 'system': nodeName = element_name hostOSH = shUtils.resolveHost(nodeName.strip()) if hostOSH == None: continue hostOSH.setAttribute('host_hostname', nodeName) OSHVResult.add(hostOSH) clusterSoftware = modeling.createClusterSoftwareOSH(hostOSH, 'Veritas Cluster SW') memberOSH = modeling.createLinkOSH('member', veritasclusterOSH, clusterSoftware) OSHVResult.add(clusterSoftware) OSHVResult.add(memberOSH) element_prop = element_prop.strip() if (element_prop != '') and (len(element_prop) > 3): # create config file object containing the zipped cf file and link it to host configFileName = "%s.properties" % nodeName configFileOsh = modeling.createConfigurationDocumentOSH(configFileName, "NA", element_prop, clusterSoftware, modeling.MIME_TEXT_PLAIN, lastUpdateTime, nodeName) OSHVResult.add(configFileOsh) # add hostosh to nodenames map so it will be easy to access later based on nodename nodeNameToOSH[nodeName] = hostOSH nodeNameToFSSWOSH[nodeName] = clusterSoftware # Handle the group element elif element_type == 'group': groupName = element_name clusterDeviceOSH = ObjectStateHolder('clusteredservice') clusterDeviceOSH.setAttribute('data_name', groupName) clusterName = veritasclusterOSH.getAttribute('data_name').getValue() clusterDeviceOSH.setAttribute('host_key', '%s:%s' % (clusterName, groupName)) clusterDeviceOSH.setBoolAttribute('host_iscomplete', 1) containsOSH = modeling.createLinkOSH('contained', veritasclusterOSH, clusterDeviceOSH) OSHVResult.add(clusterDeviceOSH) OSHVResult.add(containsOSH) # for clusterSoftware in clusterSoftwares: # runOSH = modeling.createLinkOSH('run', clusterSoftware, clusterDeviceOSH) # OSHVResult.add(runOSH) # create group object and link it to the cluster vcsGroupOSH = ObjectStateHolder('vcsgroup') vcsGroupOSH.setAttribute('data_name', groupName) vcsGroupOSH.setContainer(clusterDeviceOSH) OSHVResult.add(vcsGroupOSH) element_prop = element_prop.strip() if (element_prop != '') and (len(element_prop) > 3): # create config file object containing the current group related section in cf file, zipped and link it to cluster configFileName = "%s.properties" % groupName configFileOsh = modeling.createConfigurationDocumentOSH(configFileName, "NA", element_prop, vcsGroupOSH, modeling.MIME_TEXT_PLAIN, lastUpdateTime, groupName) OSHVResult.add(configFileOsh) m = re.search('SystemList\s*\=\s*\{(.*)\}', element_prop, re.M) if m: systemList = m.group(1) systemsWithPriorities = getSystemsWithPriorities(systemList) for nodeName, priority in systemsWithPriorities.items(): if nodeNameToFSSWOSH.has_key(nodeName): clusterSoftware = nodeNameToFSSWOSH[nodeName] ownerOSH = modeling.createLinkOSH('potentially_run', clusterSoftware, clusterDeviceOSH) if priority == 0: ownerOSH.setAttribute('data_name', 'Preferred Owner') ownerOSH.setBoolAttribute('is_owner', 1) else: ownerOSH.setAttribute('data_name', 'Alternate Owner') ownerOSH.setBoolAttribute('is_owner', 0) OSHVResult.add(ownerOSH) # Handle the resource element elif element_type != None: if vcsGroupOSH == None: continue resourceName = element_name vcsresourceOSH = ObjectStateHolder('vcsresource') vcsresourceOSH.setAttribute('data_name', resourceName) vcsresourceOSH.setAttribute('type', element_type) vcsresourceOSH.setContainer(vcsGroupOSH) OSHVResult.add(vcsresourceOSH) element_prop = element_prop.strip() if (element_prop != '') and (len(element_prop) > 3): (zippedBytes, checksumValue, dataLength) = modeling.processBytesAttribute(element_prop) vcsresourceOSH.setBytesAttribute('resource_properties', zippedBytes) resourceNameToOSH[resourceName] = vcsresourceOSH # Create the real resource element behine the vcs resource and link the two objects with a depend link handleResource(element_name, element_type, element_prop, vcsresourceOSH, nodeNameToOSH, OSHVResult, clusterDeviceOSH) # Handle the resources dependencies reg = '([\w-]+)\srequires\s([\w-]+)' compiled = re.compile(reg) matches = compiled.findall(resBuffer) for match in matches: depended = match[0].strip() master = match[1].strip() # link each resource with the resource it depends on dependOSH = modeling.createLinkOSH('depend', resourceNameToOSH[depended], resourceNameToOSH[master]) OSHVResult.add(dependOSH) # Handle the CF included files reg = 'include\s\"(.*)\"' compiled = re.compile(reg) matches = compiled.findall(resBuffer) for match in matches: cfFileName = match.strip() try: includeFilePath = cfPath + cfFileName currCFBuffer = shUtils.safecat(includeFilePath) except: errorMessage = 'Failed to handle include file %s' % includeFilePath logger.debugException(errorMessage) errobj = errorobject.createError(errorcodes.FAILED_HANDLING_INCLUDE_FILE, [includeFilePath], errorMessage) logger.reportWarningObject(errobj) if not shUtils.getLastCmdReturnCode(): currCFBuffer = currCFBuffer.strip() if (currCFBuffer != None) and (currCFBuffer != ''): # create configuration file object with the included cf file zipped configFileName = "%s.properties" % cfFileName configFileOsh = modeling.createConfigurationDocumentOSH(configFileName, "NA", currCFBuffer, veritasclusterOSH, modeling.MIME_TEXT_PLAIN, lastUpdateTime, cfFileName) OSHVResult.add(configFileOsh)
def mainFunction(resBuffer, cfPath, shUtils, OSHVResult, protocol, Framework, lastUpdateTime): # Parsing the main.cf file by a reg exp that returns (Element type, name and properties) reg = '(\w+)\s([^\s]+)\s\(([^\)]+)\)' compiled = re.compile(reg) matches = compiled.findall(resBuffer) clusterName = None groupName = None veritasclusterOSH = None vcsGroupOSH = None clusterDeviceOSH = None resourceNameToOSH = {} nodeNameToOSH = {} nodeNameToFSSWOSH = {} for match in matches: element_type = match[0].strip() element_name = match[1].strip() element_prop = match[2].strip() # Handle the cluster element if element_type == 'cluster': clusterName = element_name veritasclusterOSH = ObjectStateHolder('veritascluster') veritasclusterOSH.setAttribute('data_name', clusterName) modeling.setAppSystemVendor(veritasclusterOSH) OSHVResult.add(veritasclusterOSH) # Create configuration file object containing the zipped main.cf configFileOsh = modeling.createConfigurationDocumentOSH( "main.cf.properties", "NA", resBuffer, veritasclusterOSH, modeling.MIME_TEXT_PLAIN, lastUpdateTime, 'main.cf') OSHVResult.add(configFileOsh) # Handle the system element (Cluster nodes) elif element_type == 'system': nodeName = element_name hostOSH = shUtils.resolveHost(nodeName.strip()) if hostOSH == None: continue hostOSH.setAttribute('host_hostname', nodeName) OSHVResult.add(hostOSH) clusterSoftware = modeling.createClusterSoftwareOSH( hostOSH, 'Veritas Cluster SW') memberOSH = modeling.createLinkOSH('member', veritasclusterOSH, clusterSoftware) OSHVResult.add(clusterSoftware) OSHVResult.add(memberOSH) element_prop = element_prop.strip() if (element_prop != '') and (len(element_prop) > 3): # create config file object containing the zipped cf file and link it to host configFileName = "%s.properties" % nodeName configFileOsh = modeling.createConfigurationDocumentOSH( configFileName, "NA", element_prop, clusterSoftware, modeling.MIME_TEXT_PLAIN, lastUpdateTime, nodeName) OSHVResult.add(configFileOsh) # add hostosh to nodenames map so it will be easy to access later based on nodename nodeNameToOSH[nodeName] = hostOSH nodeNameToFSSWOSH[nodeName] = clusterSoftware # Handle the group element elif element_type == 'group': groupName = element_name clusterDeviceOSH = ObjectStateHolder('clusteredservice') clusterDeviceOSH.setAttribute('data_name', groupName) clusterName = veritasclusterOSH.getAttribute( 'data_name').getValue() clusterDeviceOSH.setAttribute('host_key', '%s:%s' % (clusterName, groupName)) clusterDeviceOSH.setBoolAttribute('host_iscomplete', 1) containsOSH = modeling.createLinkOSH('contained', veritasclusterOSH, clusterDeviceOSH) OSHVResult.add(clusterDeviceOSH) OSHVResult.add(containsOSH) # for clusterSoftware in clusterSoftwares: # runOSH = modeling.createLinkOSH('run', clusterSoftware, clusterDeviceOSH) # OSHVResult.add(runOSH) # create group object and link it to the cluster vcsGroupOSH = ObjectStateHolder('vcsgroup') vcsGroupOSH.setAttribute('data_name', groupName) vcsGroupOSH.setContainer(clusterDeviceOSH) OSHVResult.add(vcsGroupOSH) element_prop = element_prop.strip() if (element_prop != '') and (len(element_prop) > 3): # create config file object containing the current group related section in cf file, zipped and link it to cluster configFileName = "%s.properties" % groupName configFileOsh = modeling.createConfigurationDocumentOSH( configFileName, "NA", element_prop, vcsGroupOSH, modeling.MIME_TEXT_PLAIN, lastUpdateTime, groupName) OSHVResult.add(configFileOsh) m = re.search('SystemList\s*\=\s*\{(.*)\}', element_prop, re.M) if m: systemList = m.group(1) systemsWithPriorities = getSystemsWithPriorities(systemList) for nodeName, priority in systemsWithPriorities.items(): if nodeNameToFSSWOSH.has_key(nodeName): clusterSoftware = nodeNameToFSSWOSH[nodeName] ownerOSH = modeling.createLinkOSH( 'potentially_run', clusterSoftware, clusterDeviceOSH) if priority == 0: ownerOSH.setAttribute('data_name', 'Preferred Owner') ownerOSH.setBoolAttribute('is_owner', 1) else: ownerOSH.setAttribute('data_name', 'Alternate Owner') ownerOSH.setBoolAttribute('is_owner', 0) OSHVResult.add(ownerOSH) # Handle the resource element elif element_type != None: if vcsGroupOSH == None: continue resourceName = element_name vcsresourceOSH = ObjectStateHolder('vcsresource') vcsresourceOSH.setAttribute('data_name', resourceName) vcsresourceOSH.setAttribute('type', element_type) vcsresourceOSH.setContainer(vcsGroupOSH) OSHVResult.add(vcsresourceOSH) element_prop = element_prop.strip() if (element_prop != '') and (len(element_prop) > 3): (zippedBytes, checksumValue, dataLength) = modeling.processBytesAttribute(element_prop) vcsresourceOSH.setBytesAttribute('resource_properties', zippedBytes) resourceNameToOSH[resourceName] = vcsresourceOSH # Create the real resource element behine the vcs resource and link the two objects with a depend link handleResource(element_name, element_type, element_prop, vcsresourceOSH, nodeNameToOSH, OSHVResult, clusterDeviceOSH) # Handle the resources dependencies reg = '([\w-]+)\srequires\s([\w-]+)' compiled = re.compile(reg) matches = compiled.findall(resBuffer) for match in matches: depended = match[0].strip() master = match[1].strip() # link each resource with the resource it depends on dependOSH = modeling.createLinkOSH('depend', resourceNameToOSH[depended], resourceNameToOSH[master]) OSHVResult.add(dependOSH) # Handle the CF included files reg = 'include\s\"(.*)\"' compiled = re.compile(reg) matches = compiled.findall(resBuffer) for match in matches: cfFileName = match.strip() try: includeFilePath = cfPath + cfFileName currCFBuffer = shUtils.safecat(includeFilePath) except: errorMessage = 'Failed to handle include file %s' % includeFilePath logger.debugException(errorMessage) errobj = errorobject.createError( errorcodes.FAILED_HANDLING_INCLUDE_FILE, [includeFilePath], errorMessage) logger.reportWarningObject(errobj) if not shUtils.getLastCmdReturnCode(): currCFBuffer = currCFBuffer.strip() if (currCFBuffer != None) and (currCFBuffer != ''): # create configuration file object with the included cf file zipped configFileName = "%s.properties" % cfFileName configFileOsh = modeling.createConfigurationDocumentOSH( configFileName, "NA", currCFBuffer, veritasclusterOSH, modeling.MIME_TEXT_PLAIN, lastUpdateTime, cfFileName) OSHVResult.add(configFileOsh)