示例#1
0
def _establish_connection(framework, config):
    properties = Properties()
    creds_id = config.credentialsId
    inst_nr = config.instance_number
    client_nr = config.connection_client
    properties.setProperty('credentialsId', creds_id)
    if inst_nr:
        properties.setProperty(Protocol.SAP_PROTOCOL_ATTRIBUTE_SYSNUMBER, inst_nr)
    if client_nr:
        properties.setProperty(Protocol.SAP_PROTOCOL_ATTRIBUTE_CLIENT, client_nr)
    try:
        return framework.createClient(properties)
    except (NoClassDefFoundError, MissingJarsException, ExceptionInInitializerError):
        errormsg = 'SAP JCo drivers are missing'
        logger.debugException(errormsg)
        raise flow.ConnectionException(errormsg)
    except JcoException, jco:
        errormsg = jco.getMessage()
        logger.debugException(errormsg)
        if config.ip_address and config.instance_number:
            cred_args = sap_flow.getCredentialId(framework)
            logger.debug('cred_args:', cred_args)
            if not cred_args:
                raise flow.ConnectionException(errormsg)
            for args in cred_args:
                logger.debug('args:', args)
                properties.setProperty('credentialsId', args[0])
                try:
                    return framework.createClient(properties)
                except:
                    logger.debugException('')
            raise flow.ConnectionException(errormsg)
示例#2
0
def _establishConnection(framework, config):
    '@types: Framework, DiscoveryConfigBuilder, str, str, str -> SapQueryClient'
    try:
        props = _buildConnectionProperties(config)
        return framework.createClient(props)
    except (NoClassDefFoundError, MissingJarsException,
            ExceptionInInitializerError), e:
        raise flow.ConnectionException('SAP drivers are missing')
示例#3
0
def _new_p4_client(framework, creds_id, port, version):
    try:
        properties = _create_client_properties(creds_id, port, version)
        client = framework.createClient(properties)
        client.connect()
        return client
    except (clients.MissingJarsException,
            FileNotFoundException, NoClassDefFoundError):
        raise flow.ConnectionException('SAP_JMX drivers are missing')
    except (Exception, JException):
        causeMessages = logger.getCauseMessagesFromJavaStacktrace(
            logger.prepareJavaStackTrace()
        )
        msg = (filter(_isNotAuthMsg, causeMessages)
                       and 'Failed due to authentication problem'
                       or 'Connection Failed')
        raise flow.ConnectionException(msg)
示例#4
0
def _new_ws_client(framework, creds_id, port):
    try:
        WEBSERVICES_CLIENT_TYPE = "sapwebservices"
        properites = _create_client_properties(creds_id, port)
        client = framework.createClient(WEBSERVICES_CLIENT_TYPE, properites)
        client.connect()
        return client
    except JException, je:
        raise flow.ConnectionException(je.getMessage())
示例#5
0
def _createClient(framework, protocol):
    '''
    @types: Framework, str -> Client
    @raise flow.ConnectionException
    '''

    codePage = framework.getCodePage()
    properties = Properties()
    properties.put(BaseAgent.ENCODING, codePage)

    LOCAL_SHELL = ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME
    try:
        client = (_isLocalShellRequired(protocol)
                  and framework.createClient(LOCAL_SHELL)
                  or framework.createClient(properties))
        return client
    except JException, je:
        raise flow.ConnectionException(je.getMessage())
示例#6
0
                             clientNr=clientNr).build())


def _establishConnection(framework, config):
    '@types: Framework, DiscoveryConfigBuilder, str, str, str -> SapQueryClient'
    try:
        props = _buildConnectionProperties(config)
        return framework.createClient(props)
    except (NoClassDefFoundError, MissingJarsException,
            ExceptionInInitializerError), e:
        raise flow.ConnectionException('SAP drivers are missing')
    except (JException, Exception), e:
        msg = e.getMessage()
        if msg and msg.lower().find('connect to sap gateway failed') != -1:
            msg = 'Connect to SAP gateway failed'
        raise flow.ConnectionException(msg)


def _buildConnectionProperties(config):
    '@types: DiscoveryConfigBuilder, str, str, str -> java.util.Properties'
    props = Properties()
    props.setProperty('ip_address', config.ip_address)
    props.setProperty('credentialsId', config.credsId)
    props.setProperty(Protocol.SAP_PROTOCOL_ATTRIBUTE_SYSNUMBER, config.instNr)
    props.setProperty(Protocol.SAP_PROTOCOL_ATTRIBUTE_CLIENT, config.clientNr)
    return props


def getSapSystemName(sapUtils):
    r'@types: saputils.SapUtils -> str'
    table = sapUtils.getSites()
示例#7
0
                try:
                    return framework.createClient(properties)
                except:
                    logger.debugException('')
            raise flow.ConnectionException(errormsg)
    except JException, e:
        strmsg = e.getMessage()
        errormsg = strmsg
        m = re.search('.RFC_.+?:\s*(.+)', strmsg)
        if m is not None:
            errMsg = m.group(1)
            errormsg = 'Connection failed: %s' % str(errMsg)
        else:
            errormsg = 'Connection failed:' + strmsg
        logger.debugException(errormsg)
        raise flow.ConnectionException(errormsg)


def _discoverAbapSystemTopology(client, config, framework):
    '''
    Discover ABAP SAP system and its topology

    @types: SapQueryClient, DiscoveryConfigBuilder, Framework -> iterable
    @return: iterable object of pairs of vector (oshv) and warning message
    '''
    sapUtils = saputils.SapUtils(client)

    system = sap.System(config.system_name)
    systemOsh = _discover_sap_system(sapUtils, system.getName())

    insts, instWarning = _discoverInstances(sapUtils, system, systemOsh, framework)
示例#8
0
def _create_client(framework):
    try:
        return framework.createClient()
    except JException, je:
        raise flow.ConnectionException(je.getMessage())