Ejemplo n.º 1
0
def processLinks(allLinksChildren, client, ciDictionary, objectMappings, linkMappings, action, updateStatus):
    iter = allLinksChildren.iterator()
    while iter.hasNext():
        linkElement = iter.next()
        end1Id = None
        end2Id = None
        table = linkElement.getAttributeValue("targetRelationshipClass")
        attributesMap = HashMap()
        fieldChildren = linkElement.getChildren("field")
        if fieldChildren is not None:
            iter2 = fieldChildren.iterator()
            while iter2.hasNext():
                fieldElement = iter2.next()
                fieldName = fieldElement.getAttributeValue("name")
                fieldValue = fieldElement.getText()
                if fieldName == "end1Id":
                    end1Id = fieldValue
                    attributesMap.put("END1", ciDictionary.get(fieldValue))
                elif fieldName == "end2Id":
                    end2Id = fieldValue
                    attributesMap.put("END2", ciDictionary.get(fieldValue))
                elif fieldName != "DiscoveryID1" and fieldName != "DiscoveryID2":
                    attributesMap.put(fieldName, fieldValue)
                isKey = fieldElement.getAttributeValue("key")
        end1ExternalId = CmdbObjectID.Factory.restoreObjectID(end1Id)
        newId1 = end1ExternalId.getPropertyValue("ID")
        if newId1 is None:
            cmdb1Id = end1ExternalId.getPropertyValue("internal_id")
            end1ExternalId = objectMappings.get(cmdb1Id)
        end2ExternalId = CmdbObjectID.Factory.restoreObjectID(end2Id)
        newId2 = end2ExternalId.getPropertyValue("ID")
        if newId2 is None:
            cmdb2Id = end2ExternalId.getPropertyValue("internal_id")
            end2ExternalId = objectMappings.get(cmdb2Id)
        id = linkElement.getAttributeValue("id")
        linkObjId = CmdbLinkID.Factory.restoreLinkID(id)
        newId = linkObjId.getPropertyValue("ID")
        externalId = None
        if newId is None:
            cmdbId = linkObjId.getPropertyValue("internal_id")
            className = linkObjId.getType()
            newId = str(client.getNextCounter())
            attributesMap.put("ID", newId)
            propArray = [TypesFactory.createProperty("ID", attributesMap.get("ID"))]
            externalId = ExternalIdFactory.createExternalRelationId(
                className, end1ExternalId, end2ExternalId, propArray
            )
            linkMappings.put(cmdbId, externalId)
        else:
            logger.info("linkObjId is ", linkObjId.getPropertyValue("ID"), " newId: ", newId)
            externalId = ExternalIdUtil.restoreExternalRelationId(linkObjId.toString())
            attributesMap.put("ID", newId)
        if action == ADD:
            client.executeInsert(table, attributesMap, updateStatus, externalId)
        elif action == UPDATE:
            client.executeUpdate(table, attributesMap, newId, updateStatus, externalId)
        elif action == DELETE:
            client.executeDelete(table, attributesMap, newId, updateStatus, externalId)
Ejemplo n.º 2
0
def processLinks(allLinksChildren, client, ciDictionary, objectMappings, linkMappings, action, updateStatus):
    iter = allLinksChildren.iterator()
    while iter.hasNext():
        linkElement = iter.next()
        end1Id = None
        end2Id = None
        table = linkElement.getAttributeValue('targetRelationshipClass')
        attributesMap = HashMap()
        fieldChildren  = linkElement.getChildren('field')
        if fieldChildren is not None:
            iter2 = fieldChildren.iterator()
            while iter2.hasNext():
                fieldElement = iter2.next()
                fieldName = fieldElement.getAttributeValue('name')
                fieldValue = fieldElement.getText()
                if (fieldName == 'end1Id'):
                    end1Id = fieldValue
                    attributesMap.put('END1',ciDictionary.get(fieldValue))
                elif (fieldName == 'end2Id'):
                    end2Id = fieldValue
                    attributesMap.put('END2',ciDictionary.get(fieldValue))
                elif (fieldName != 'DiscoveryID1' and fieldName != 'DiscoveryID2'):
                    attributesMap.put(fieldName,fieldValue)
                isKey = fieldElement.getAttributeValue('key')
        end1ExternalId = CmdbObjectID.Factory.restoreObjectID(end1Id)
        newId1 = end1ExternalId.getPropertyValue('ID')
        if (newId1 is None):
            cmdb1Id = end1ExternalId.getPropertyValue('internal_id')
            end1ExternalId = objectMappings.get(cmdb1Id)
        end2ExternalId = CmdbObjectID.Factory.restoreObjectID(end2Id)
        newId2 = end2ExternalId.getPropertyValue('ID')
        if (newId2 is None):
            cmdb2Id = end2ExternalId.getPropertyValue('internal_id')
            end2ExternalId = objectMappings.get(cmdb2Id)
        id = linkElement.getAttributeValue('id')
        linkObjId = CmdbLinkID.Factory.restoreLinkID(id)
        newId = linkObjId.getPropertyValue('ID')
        externalId = None
        if (newId is None):
            cmdbId = linkObjId.getPropertyValue('internal_id')
            className = linkObjId.getType()
            newId = str(client.getNextCounter())
            attributesMap.put('ID', newId)
            propArray = [TypesFactory.createProperty('ID', attributesMap.get('ID'))]
            externalId = ExternalIdFactory.createExternalRelationId(className, end1ExternalId, end2ExternalId, propArray)
            linkMappings.put(cmdbId, externalId)
        else:
            logger.info('linkObjId is ', linkObjId.getPropertyValue('ID'), ' newId: ', newId)
            externalId = ExternalIdUtil.restoreExternalRelationId(linkObjId.toString())
            attributesMap.put('ID', newId)
        if(action == ADD):
            client.executeInsert(table, attributesMap, updateStatus, externalId)
        elif (action == UPDATE):
           client.executeUpdate(table, attributesMap, newId, updateStatus, externalId)
        elif (action == DELETE):
            client.executeDelete(table, attributesMap, newId, updateStatus, externalId)
Ejemplo n.º 3
0
def createExternalCiId(theId, serviceNowId):
    try:
        extI = CmdbObjectID.Factory.restoreObjectID(theId)
        propArray = [TypesFactory.createProperty('serviceNowID', 'obj_' + serviceNowId)]
        className = extI.getType()
        externalId = ExternalIdFactory.createExternalCiId(className, propArray)
        debugPrint(4, '[createExternalCiId] Created external ID <%s> for CI with CIT <%s>' % (externalId, className))
        return externalId
    except:
        excInfo = logger.prepareJythonStackTrace('')
        logger.warn('[createExternalCiId] Exception: <%s>' % excInfo)
        pass
Ejemplo n.º 4
0
def createExternalRelationId(theId, serviceNowId, externalCiId1, externalCiId2):
    try:
        extI = CmdbLinkID.Factory.restoreLinkID(theId)
        propArray = [TypesFactory.createProperty('serviceNowID', 'link_' + serviceNowId)]
        className = extI.getType()
        externalId = ExternalIdFactory.createExternalRelationId(className, externalCiId1, externalCiId2, propArray)
        debugPrint(4, '[createExternalRelationId] Created external ID <%s> for Relationship of type <%s>' % (externalId, className))
        return externalId
    except:
        excInfo = logger.prepareJythonStackTrace('')
        logger.warn('[createExternalRelationId] Exception: <%s>' % excInfo)
        pass
Ejemplo n.º 5
0
def processCis(allObjectChildren, client, ciDictionary, objectMappings, action, updateStatus):
    iter = allObjectChildren.iterator()
    while iter.hasNext():
        objectElement = iter.next()
        table = objectElement.getAttributeValue('name')
        id = objectElement.getAttributeValue('id')
        mode = objectElement.getAttributeValue('mode')
        operation = objectElement.getAttributeValue('operation')
        attributesMap = HashMap()
        fieldChildren  = objectElement.getChildren('field')
        if fieldChildren is not None:
            iter2 = fieldChildren.iterator()
            while iter2.hasNext():
                fieldElement = iter2.next()
                fieldName = fieldElement.getAttributeValue('name')
                fieldValue = fieldElement.getText()
                attributesMap.put(fieldName,fieldValue)
                isKey = fieldElement.getAttributeValue('key')
        objId = CmdbObjectID.Factory.restoreObjectID(id)
        newId = objId.getPropertyValue(ID_KEY)
        externalId = None
        if (newId is None):
            #if this is CMDB id
            cmdbId = objId.getPropertyValue('internal_id')
            newId = str(client.getNextCounter())
            attributesMap.put('ID', newId)
            propArray = [TypesFactory.createProperty(ID_KEY, attributesMap.get(ID_KEY))]
            className = objId.getType()
            externalId = ExternalIdFactory.createExternalCiId(className, propArray)
            objectMappings.put(cmdbId, externalId)
        else:
            logger.info('objId is external and objId.getPropertyValue is ', newId)
            externalId = ExternalIdUtil.restoreExternalCiId(objId.toString())
            attributesMap.put('ID', newId)
        ciDictionary.put(id, newId)
        if (action == ADD):
           client.executeInsert(table, attributesMap, updateStatus, externalId)
        elif (action == UPDATE):
           client.executeUpdate(table, attributesMap, newId, updateStatus, externalId)
        elif (action == DELETE):
            client.executeDelete(table, attributesMap, newId, updateStatus, externalId)
Ejemplo n.º 6
0
def processCis(allObjectChildren, client, ciDictionary, objectMappings, action, updateStatus):
    iter = allObjectChildren.iterator()
    while iter.hasNext():
        objectElement = iter.next()
        table = objectElement.getAttributeValue("name")
        id = objectElement.getAttributeValue("id")
        mode = objectElement.getAttributeValue("mode")
        operation = objectElement.getAttributeValue("operation")
        attributesMap = HashMap()
        fieldChildren = objectElement.getChildren("field")
        if fieldChildren is not None:
            iter2 = fieldChildren.iterator()
            while iter2.hasNext():
                fieldElement = iter2.next()
                fieldName = fieldElement.getAttributeValue("name")
                fieldValue = fieldElement.getText()
                attributesMap.put(fieldName, fieldValue)
                isKey = fieldElement.getAttributeValue("key")
        objId = CmdbObjectID.Factory.restoreObjectID(id)
        newId = objId.getPropertyValue(ID_KEY)
        externalId = None
        if newId is None:
            # if this is CMDB id
            cmdbId = objId.getPropertyValue("internal_id")
            newId = str(client.getNextCounter())
            attributesMap.put("ID", newId)
            propArray = [TypesFactory.createProperty(ID_KEY, attributesMap.get(ID_KEY))]
            className = objId.getType()
            externalId = ExternalIdFactory.createExternalCiId(className, propArray)
            objectMappings.put(cmdbId, externalId)
        else:
            logger.info("objId is external and objId.getPropertyValue is ", newId)
            externalId = ExternalIdUtil.restoreExternalCiId(objId.toString())
            attributesMap.put("ID", newId)
        ciDictionary.put(id, newId)
        if action == ADD:
            client.executeInsert(table, attributesMap, updateStatus, externalId)
        elif action == UPDATE:
            client.executeUpdate(table, attributesMap, newId, updateStatus, externalId)
        elif action == DELETE:
            client.executeDelete(table, attributesMap, newId, updateStatus, externalId)