Exemplo n.º 1
0
def submitWorkOrder(
        workOrder_id,
        worker_id,
        requester_id,
        workOrder_request,
        workOrderResponse,
        ):
    eth_conn = QuorumWorkInvocationImpl(config)
    workOrder_id = workOrder_id[:8].encode('utf-8')
    worker_id = worker_id[:8].encode('utf-8')
    requester_id = requester_id[:8].encode('utf-8')  # Gateway ID
    workOrder_request = str(workOrder_request)
    logging.info('''Calling work Order Submit contract ...
 workOrder_id: %s
 worker_id: %s
 requester_id: %s
 workOrder_request: %s
''',
                 hex_to_utf8(workOrder_id), hex_to_utf8(worker_id),
                 hex_to_utf8(requester_id), workOrder_request)
    try:
        result = eth_conn.workOrder_submit(workOrder_id, worker_id,
                                           requester_id, workOrder_request)
        logging.info('##############################################')
        logging.info("""workOrder_submit status
                    {'status': %s',
                    'txn_receipt': %s}""",
                     result['status'],
                     json.dumps(json.loads(Web3.toJSON(result['txn_receipt'])),
                                indent=4))
        res = json.loads(Web3.toJSON(result['txn_receipt']))
        workorderStatus = 0
        logging.info("""Calling workOrder conmplete..
 workOrder_id: %s
 workOrder_status: %d
 \
                WorkOrder Response %s""",
                     hex_to_utf8(workOrder_id), workorderStatus,
                     workOrderResponse)
        try:
            result = eth_conn.workOrder_complete(workOrder_id,
                                                 workorderStatus,
                                                 workOrderResponse)
            logging.info('--------------Result------------- %s \n',
                         result)
            res = json.loads(Web3.toJSON(result['txn_receipt']))
            return res
        except Exception as e2:
            logging.info(e2)
            return e2
    except Exception as e:
        logging.info(e)
        return e
Exemplo n.º 2
0
def registerWorker():
    input = json.loads(request.data)
    eth_conn = QuorumWorkerRegistryImpl(config)
    worker_id = (input['workerId'])[:8].encode('utf-8')
    logging.info('Worker Id in bytes')
    logging.info(worker_id)
    logging.info('type of workerId object')
    logging.info(type(worker_id))
    org_id = input['orgId'].encode('utf-8')
    logging.info('Organization Id in Bytes')
    logging.info(org_id)
    logging.info('Type of orgId Object')
    logging.info(type(org_id))
    application_ids = [input['applicationId1'].encode('utf-8'),
                       input['applicationId2'].encode('utf-8')]
    worker_type = WorkerType.TEE_SGX
    worker_api_url = input['workerUrl']
    details = input['details']
    logging.info('Type of details Object')
    logging.info(type(details))
    detailsInPythonStringFormat = \
        json.dumps({'workOrderSyncUri': details})
    logging.info(
        """Calling worker_register contract..
 worker_id: %s
 worker_type: %d
 \
        orgId: %s
 applicationIds %s
 details %s""",
        hex_to_utf8(worker_id),
        worker_type.value,
        hex_to_utf8(org_id),
        pretty_ids(application_ids),
        detailsInPythonStringFormat,
        )
    result = eth_conn.worker_register(worker_id,
                                      worker_type,
                                      org_id,
                                      application_ids,
                                      detailsInPythonStringFormat)
    logging.info('Result')
    logging.info(result)
    logging.info("""worker_register status
                {'status': %s',
                'txn_receipt': %s}""",
                 result['status'],
                 json.dumps(json.loads(Web3.toJSON(result['txn_receipt'])),
                            indent=4))
    res = json.loads(Web3.toJSON(result['txn_receipt']))
    return res
Exemplo n.º 3
0
def getWorkerDetails():
    worker_id = request.args.get('workerId')
    eth_conn = QuorumWorkerRegistryImpl(config)
    logging.info('Calling worker_retrieve..\n worker_id: %s',
                 hex_to_utf8(worker_id.encode('utf-8')))
    result = eth_conn.worker_retrieve(worker_id.encode('utf-8'))
    logging.info(
        'worker_retrieve status [%d, %s, %s, %s, %s]',
        result[0],
        result[1],
        pretty_ids(result[2]),
        result[3],
        result[4],
        )
    logging.info('Type of details')
    logging.info(type(result[4]))
    result[1] = hex_to_utf8(result[1])
    result[2] = pretty_ids(result[2])
    return json.dumps(result)
Exemplo n.º 4
0
def getResult():
    workOrderId = request.args.get('workOrderId').encode('utf-8')
    eth_conn = QuorumWorkInvocationImpl(config)
    logging.info('''Calling WorkOrder Contract workOrder_id : %s ''',
                 hex_to_utf8(workOrderId))
    result = eth_conn.workOrder_getResult(workOrderId)
    logging.info('''
WorkOrder data {'status': % d',
'WorkOrder Response' : %s}''',
                 result[0],
                 result[1])
    return json.dumps(result)
Exemplo n.º 5
0
def getWorker():
    logging.info(request)
    org_id = request.args.get('org_id')
    application_id = request.args.get('applicationId')
    logging.info(type(org_id))
    eth_conn = QuorumWorkerRegistryImpl(config)
    worker_type = WorkerType.TEE_SGX
    logging.info('''Calling worker_lookup..
                    worker_type: %d
                    orgId: %s
                    applicationId: %s''',
                 worker_type.value,
                 hex_to_utf8(org_id.encode('utf-8')),
                 hex_to_utf8(application_id.encode('utf-8')))
    result = eth_conn.worker_lookup(worker_type, org_id.encode('utf-8'),
                                    application_id.encode('utf-8'))
    logging.info('worker_lookup status [%d, %s, %s]', result[0],
                 result[1], pretty_ids(result[2]))
    pretty_list = []
    for id in result[2]:
        pretty_list.append(id.decode('utf-8').rstrip("\u0000"))
    res = json.dumps(pretty_list)
    return res