-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
667 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,33 @@ | ||
import logging | ||
from urllib.parse import urlparse | ||
|
||
import aiohttp | ||
|
||
from sn_agent import ontology | ||
from sn_agent.job.job_descriptor import JobDescriptor | ||
from sn_agent.ontology.service_descriptor import ServiceDescriptor | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
async def submit_job(context=None): | ||
process_job(context) | ||
|
||
return 'pong' | ||
|
||
|
||
async def process_job(app): | ||
logger.debug("Job submission") | ||
|
||
blockchain = app['blockchain'] | ||
dht = app['dht'] | ||
|
||
ontology_id = ontology.DOCUMENT_SUMMARIZER_ID | ||
agent_ids = blockchain.get_agents_for_ontology(ontology_id) | ||
|
||
available_agents = [] | ||
for agent_id in agent_ids: | ||
|
||
connection_info = dht.get(agent_id) | ||
async def can_perform_service(app, service_descriptor: ServiceDescriptor): | ||
logger.debug("get_can_perform: %s", service_descriptor) | ||
|
||
for value in connection_info: | ||
logger.debug('received value: %s', value) | ||
service_manager = app['service_manager'] | ||
service_adapter = service_manager.get_service_adapter_for_id(service_descriptor.ontology_node_id) | ||
|
||
if isinstance(value, dict): | ||
if 'url' in value.keys(): | ||
url = urlparse(value['url']) | ||
url_str = url.geturl() | ||
if service_adapter is None: | ||
raise Exception('Service not available') | ||
|
||
logger.debug('Connection URL: %s', url_str) | ||
# if url.scheme == 'ws' or url.scheme == 'wss': | ||
return service_adapter.can_perform() | ||
|
||
try: | ||
session = aiohttp.ClientSession() | ||
async with session.ws_connect(url_str, heartbeat=10000) as ws: | ||
|
||
logger.debug("************** Successfully connected to %s", url) | ||
async for msg in ws: | ||
if msg.type == aiohttp.WSMsgType.TEXT: | ||
if msg.data == 'close cmd': | ||
await ws.close() | ||
break | ||
else: | ||
await ws.send_str(msg.data + '/answer') | ||
elif msg.type == aiohttp.WSMsgType.CLOSED: | ||
break | ||
elif msg.type == aiohttp.WSMsgType.ERROR: | ||
break | ||
async def perform_job(app, job_descriptor: JobDescriptor): | ||
logger.debug("perform_job: %s", job_descriptor) | ||
|
||
except aiohttp.ClientConnectorError: | ||
logger.error('Client Connector error for: %s', url_str) | ||
pass | ||
service_manager = app['service_manager'] | ||
|
||
except aiohttp.ServerDisconnectedError: | ||
logger.error('Server disconnected error for: %s', url_str) | ||
pass | ||
service_descriptor = job_descriptor.service | ||
|
||
except aiohttp.WSServerHandshakeError: | ||
logger.error('Incorrect WS handshake for: %s', url_str) | ||
pass | ||
service_adapter = service_manager.get_service_adapter_for_id(service_descriptor.ontology_node_id) | ||
|
||
except aiohttp.ClientOSError: | ||
logger.error('Client OS error for: %s', url_str) | ||
pass | ||
if service_adapter is None: | ||
raise Exception('Service not available') | ||
|
||
finally: | ||
session.close() | ||
return service_adapter.perform(job_descriptor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"contract_name": "AgentFactory", | ||
"abi": [ | ||
{ | ||
"constant": false, | ||
"inputs": [], | ||
"name": "create", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"payable": false, | ||
"type": "function" | ||
} | ||
], | ||
"unlinked_binary": "0x6060604052341561000f57600080fd5b5b61087a8061001f6000396000f300606060405263ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663efc81a8c811461003d575b600080fd5b341561004857600080fd5b610050610079565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390f35b600061008361009f565b604051809103906000f080151561009957600080fd5b90505b90565b60405161079f806100b083390190560060606040525b60008054600160a060020a03191633600160a060020a03161790555b5b61076e806100316000396000f300606060405236156100965763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631cc1e7bc811461009a5780632f54bf6e146100ba57806358e7ec3c146100ed5780636c0437731461011c5780638da5cb5b14610149578063a59455dc14610178578063a662031b14610206578063d0a9e0c014610241578063f2fde38b146102cf575b5b5b005b34156100a557600080fd5b61009660048035602481019101356102f0565b005b34156100c557600080fd5b6100d9600160a060020a0360043516610322565b604051901515815260200160405180910390f35b34156100f857600080fd5b610100610339565b604051600160a060020a03909116815260200160405180910390f35b341561012757600080fd5b61009660048035600160a060020a03169060248035908101910135610348565b005b341561015457600080fd5b6101006103f2565b604051600160a060020a03909116815260200160405180910390f35b341561018357600080fd5b61018e600435610401565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156101cb5780820151818401525b6020016101b2565b50505050905090810190601f1680156101f85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561021157600080fd5b610100600160a060020a03600435166104c7565b604051600160a060020a03909116815260200160405180910390f35b341561024c57600080fd5b61018e6004356104f7565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156101cb5780820151818401525b6020016101b2565b50505050905090810190601f1680156101f85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156102da57600080fd5b610096600160a060020a03600435166105b3565b005b6001805480820161030183826105f4565b916000526020600020900160005b5061031b90848461061e565b50505b5050565b600054600160a060020a038281169116145b919050565b600254600160a060020a031681565b61035133610322565b151561035c57600080fd5b82600160a060020a0316631cc1e7bc83836040517c010000000000000000000000000000000000000000000000000000000063ffffffff85160281526020600482019081526024820183905290819060440184848082843782019150509350505050600060405180830381600087803b15156103d757600080fd5b6102c65a03f115156103e857600080fd5b5050505b5b505050565b600054600160a060020a031681565b61040961069d565b600180548390811061041757fe5b906000526020600020900160005b508054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156104ba5780601f1061048f576101008083540402835291602001916104ba565b820191906000526020600020905b81548152906001019060200180831161049d57829003601f168201915b505050505090505b919050565b6002805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03831617905560005b919050565b600180548290811061050557fe5b906000526020600020900160005b915090508054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105ab5780601f10610580576101008083540402835291602001916105ab565b820191906000526020600020905b81548152906001019060200180831161058e57829003601f168201915b505050505081565b6105bc33610322565b15156105c757600080fd5b6000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790555b5b50565b8154818355818115116103ec576000838152602090206103ec9181019083016106af565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061065f5782800160ff1982351617855561068c565b8280016001018555821561068c579182015b8281111561068c578235825591602001919060010190610671565b5b506106999291506106d9565b5090565b60206040519081016040526000815290565b6106d691905b808211156106995760006106c982826106fa565b506001016106b5565b5090565b90565b6106d691905b8082111561069957600081556001016106df565b5090565b90565b50805460018160011615610100020316600290046000825580601f1061072057506105f0565b601f0160209004906000526020600020908101906105f091906106d9565b5b505600a165627a7a723058201057da26894506df11bde6d0821ed5926efce4fe5afccb7c0be1b2c3ba655d6c0029a165627a7a72305820b58b7e7739d32b54a3fdfd31bd302af676be79487f7d62a889c75caf502500a80029", | ||
"networks": { | ||
"1508470469290": { | ||
"events": {}, | ||
"links": {}, | ||
"address": "0x1cf4cb6d4f7672e352342300ecbc15ff0acd79d8", | ||
"updated_at": 1508470475336 | ||
}, | ||
"1508470589354": { | ||
"events": {}, | ||
"links": {}, | ||
"address": "0x60ddbd1f9f8c786e6f43e0470ed5a3498f6f4440", | ||
"updated_at": 1508470592733 | ||
}, | ||
"1508470632092": { | ||
"events": {}, | ||
"links": {}, | ||
"address": "0xb2eed4473b2e4107e7a43f79a23d3500acfe3ac2", | ||
"updated_at": 1508470635443 | ||
} | ||
}, | ||
"schema_version": "0.0.5", | ||
"updated_at": 1508470635443 | ||
} |
Oops, something went wrong.