Ejemplo n.º 1
0
 def _getDistinationInfo(self, connection):
     # Make sure we only have one slash in the url path. More than one 
     #confuses pylons routing libary.
     destinationURL = urlparse.urljoin(connection.destination_node_url.strip(),
                                                             "destination")
     
     request = urllib2.Request(destinationURL)
     credential = sourceLRNode.getDistributeCredentialFor(destinationURL)
     
     if credential is not None:
         base64string = base64.encodestring('%s:%s' % (credential['username'],credential['password'])).replace("\n", "")
         request.add_header("Authorization", "Basic %s" % base64string)
     
     log.info("\n\nAccess destination node at: "+pprint.pformat(request.__dict__))
     return json.load(urllib2.urlopen(request))
Ejemplo n.º 2
0
 def _make_geoserver_rest_request(self, path, data=None):
     url = config['mapclient.geoserver.api_url'] + 'rest/' + path
     username = config['mapclient.geoserver.username']
     password = config['mapclient.geoserver.password']
     
     request = urllib2.Request(url = url)
     
     #TODO Check POST case
     if data:
         request.add_data(data.encode('utf-8'))
     
     request.add_header('Authorization', 
                        'Basic ' + ((username + ':' + password).encode('base64').rstrip()))
     try:
         response = urllib2.urlopen(request)
     except urllib2.HTTPError as ex:
         try:
             detail = ex.read()
         except:
             detail = 'n/a'
         raise RuntimeError('GeoServer REST Request \'%s\' failed with '
                            'exception: \'%s\'. Details: %s' % (path, ex, detail))
     return response.read()   
Ejemplo n.º 3
0
    def _getDistributeDestinations(self):
        """"Method to test the connections and returns a list of destionation node
             if the connections are valid"""
        nodeDestinationList = []
        gatewayConnectionList = []
        for connection in sourceLRNode.connections:
            # Make sure that the connection is active
            if connection.active == False:
                continue
            destinationLRNode = None

            if connection.gateway_connection == True:
                gatewayConnectionList.append(connection)
            try:
                # Make sure we only have one slash in the url path. More than one
                #confuses pylons routing libary.
                destinationURL = urlparse.urljoin(
                    connection.destination_node_url.strip(), "distribute")

                request = urllib2.Request(destinationURL)
                credential = sourceLRNode.getDistributeCredentialFor(
                    destinationURL)

                if credential is not None:
                    base64string = base64.encodestring(
                        '%s:%s' % (credential['username'],
                                   credential['password'])).replace("\n", "")
                    request.add_header("Authorization",
                                       "Basic %s" % base64string)

                log.info("\n\nAccess destination node at: " +
                         pprint.pformat(request.__dict__))
                distributeInfo = json.load(urllib2.urlopen(request))
                destinationLRNode = LRNodeModel(distributeInfo['node_config'])
            except Exception as ex:
                log.exception(ex)
                continue
            # Use of local variable to store if  the connection is gateway connection. It is
            # done this way to deal with mismatch between node de and connection
            # description.
            isGatewayConnection = (
                (sourceLRNode.nodeDescription.gateway_node == True)
                and (destinationLRNode.nodeDescription.gateway_node == True))
            # Skip the connection if there is any mismatch between the connection and
            # the node data.
            if isGatewayConnection != connection.gateway_connection:
                log.info(
                    "Skip connection. 'gateway_connection' mismatch between node and connection data"
                )
                continue

            # Only one gateway  connection is allowed, faulty network description
            if len(gatewayConnectionList) > 1:
                log.info(
                    "***Abort distribution. More than one gateway node connection"
                )
                #Clear the node destination list no distribution is network description
                # is faulty
                nodeDestinationList = []
                break
            #Calcuate if the connection is gateway one, if so
            #cannot distribute across non social communities
            if ((sourceLRNode.communityDescription.community_id !=
                 destinationLRNode.communityDescription.community_id) and
                ((sourceLRNode.communityDescription.social_community == False)
                 or (destinationLRNode.communityDescription.social_community
                     == False))):
                log.info("Cannot distribute across non social communities")
                continue
            # Cannot distribute across networks (or communities) unless gateway
            if ((isGatewayConnection == False) and
                ((sourceLRNode.communityDescription.community_id !=
                  destinationLRNode.communityDescription.community_id) or
                 (sourceLRNode.networkDescription.network_id !=
                  destinationLRNode.networkDescription.network_id))):
                log.info(
                    "Different Network. Cannot distribute across networks (or communities) unless gateway"
                )
                continue
            # Gateway must only distribute across different networks.
            if ((isGatewayConnection == True)
                    and (sourceLRNode.networkDescription.network_id
                         == destinationLRNode.networkDescription.network_id)):
                log.info(
                    "Gateway must only distribute across different networks")
                continue
            # Only gateways can distribute on gateway connection. This is really for
            # catching mismatch in the data where a connection says it is between
            # gateways when the nodes are not both gateways.
            if ((connection.gateway_connection == True) and
                ((sourceLRNode.nodeDescription.gateway_node == False) or
                 (destinationLRNode.nodeDescription.gateway_node == False))):
                log.info("Only gateways can distribute on gateway connection")
                continue
            nodeInfo = {
                "distributeInfo": distributeInfo,
                "distribute_sink_url": distributeInfo["distribute_sink_url"],
                "destinationNode": destinationLRNode
            }
            nodeDestinationList.append(nodeInfo)

        return nodeDestinationList
Ejemplo n.º 4
0
 def _getDistributeDestinations(self):
     """"Method to test the connections and returns a list of destionation node
          if the connections are valid"""
     nodeDestinationList =[]
     gatewayConnectionList = []
     for connection in sourceLRNode.connections:
         # Make sure that the connection is active 
         if connection.active == False:
             continue
         destinationLRNode = None
        
         if connection.gateway_connection == True:
             gatewayConnectionList.append(connection)
         try:
             # Make sure we only have one slash in the url path. More than one 
             #confuses pylons routing libary.
             destinationURL = urlparse.urljoin(connection.destination_node_url.strip(),
                                                                     "distribute")
             
             request = urllib2.Request(destinationURL)
             credential = sourceLRNode.getDistributeCredentialFor(destinationURL)
             
             if credential is not None:
                 base64string = base64.encodestring('%s:%s' % (credential['username'],credential['password'])).replace("\n", "")
                 request.add_header("Authorization", "Basic %s" % base64string)
             
             log.info("\n\nAccess destination node at: "+pprint.pformat(request.__dict__))
             distributeInfo = json.load(urllib2.urlopen(request))
             destinationLRNode = LRNodeModel(distributeInfo['node_config'])
         except Exception as ex:
             log.exception(ex)
             continue
          # Use of local variable to store if  the connection is gateway connection. It is
         # done this way to deal with mismatch between node de and connection
         # description.
         isGatewayConnection = (
                     (sourceLRNode.nodeDescription.gateway_node == True) and
                     (destinationLRNode.nodeDescription.gateway_node ==True))
         # Skip the connection if there is any mismatch between the connection and
         # the node data.
         if isGatewayConnection != connection.gateway_connection:
             log.info("Skip connection. 'gateway_connection' mismatch between node and connection data")
             continue
     
         # Only one gateway  connection is allowed, faulty network description
         if len(gatewayConnectionList) > 1:
             log.info("***Abort distribution. More than one gateway node connection")
             #Clear the node destination list no distribution is network description 
             # is faulty
             nodeDestinationList = []
             break
         #Calcuate if the connection is gateway one, if so 
         #cannot distribute across non social communities
         if ((sourceLRNode.communityDescription.community_id != 
              destinationLRNode.communityDescription.community_id) and
              ((sourceLRNode.communityDescription.social_community == False) or
               (destinationLRNode.communityDescription.social_community == False))):
                   log.info("Cannot distribute across non social communities")
                   continue
         # Cannot distribute across networks (or communities) unless gateway
         if((isGatewayConnection == False) and
             ((sourceLRNode.communityDescription.community_id != 
              destinationLRNode.communityDescription.community_id) or
             (sourceLRNode.networkDescription.network_id != 
               destinationLRNode.networkDescription.network_id))):
                   log.info("Different Network. Cannot distribute across networks (or communities) unless gateway")
                   continue
         # Gateway must only distribute across different networks.
         if((isGatewayConnection ==True) and
                (sourceLRNode.networkDescription.network_id == 
                 destinationLRNode.networkDescription.network_id)):
                     log.info("Gateway must only distribute across different networks")
                     continue
         # Only gateways can distribute on gateway connection. This is really for 
         # catching mismatch in the data where a connection says it is between 
         # gateways when the nodes are not both gateways.
         if((connection.gateway_connection == True) and 
             ((sourceLRNode.nodeDescription.gateway_node == False) or
             (destinationLRNode.nodeDescription.gateway_node == False))):
                 log.info("Only gateways can distribute on gateway connection")
                 continue
         nodeInfo = { "distributeInfo": distributeInfo,
                               "destinationBaseUrl":connection.destination_node_url,
                               "destinationNode":destinationLRNode}
         nodeDestinationList.append(nodeInfo)
         
     return nodeDestinationList