1
1
import json
2
2
import pickle
3
3
import subprocess
4
- from copy import copy , deepcopy
4
+ from copy import deepcopy
5
5
from pprint import pprint
6
6
7
7
from cats .service .utils import executeCMD
@@ -64,12 +64,15 @@ def initBOMcar(self, function_cid, init_data_cid, init_bom_filename='bom.car', s
64
64
return self .init_bom_car_cid , self .init_bom_json_cid
65
65
66
66
def catSubmit (self , bom ):
67
+ order = json .loads (self .meshClient .cat (bom ["order_cid" ]))
68
+ pprint (order )
67
69
ppost = lambda args , endpoint : \
68
70
f'curl -X POST -H "Content-Type: application/json" -d \\ \n \' { json .dumps (** args )} \' { endpoint } '
69
71
post = lambda args , endpoint : \
70
72
'curl -X POST -H "Content-Type: application/json" -d \' ' + json .dumps (** args ) + f'\' { endpoint } '
71
- post_cmd = post ({'obj' : bom }, bom ["order" ]["endpoint" ])
72
- print (ppost ({'obj' : bom , 'indent' : 4 }, bom ["order" ]["endpoint" ]))
73
+
74
+ post_cmd = post ({'obj' : bom }, order ["endpoint" ])
75
+ print (ppost ({'obj' : bom , 'indent' : 4 }, order ["endpoint" ]))
73
76
response_str = subprocess .check_output (post_cmd , shell = True )
74
77
output_bom = json .loads (response_str )
75
78
# pprint(output_bom)
@@ -78,8 +81,27 @@ def catSubmit(self, bom):
78
81
output_bom ['POST' ] = post_cmd
79
82
return output_bom
80
83
84
+ def flatten_bom (self , bom_response ):
85
+ invoice = json .loads (
86
+ self .meshClient .cat (bom_response ["bom" ]["invoice_cid" ])
87
+ )
88
+ invoice ['order' ] = json .loads (
89
+ self .meshClient .cat (invoice ['order_cid' ]),
90
+ )
91
+ invoice ['order' ]['flat' ] = {
92
+ 'function' : json .loads (self .meshClient .cat (invoice ['order' ]["function_cid" ])),
93
+ 'invoice' : json .loads (self .meshClient .cat (invoice ['order' ]["invoice_cid" ]))
94
+ }
95
+ bom_response ["flat_bom" ] = {
96
+ 'invoice' : invoice ,
97
+ 'log' : json .loads (
98
+ self .meshClient .cat (bom_response ["bom" ]["log_cid" ])
99
+ )
100
+ }
101
+ return bom_response
102
+
81
103
def resubmit_bom (self ,
82
- bom , endpoint = 'http://127.0.0.1:5000/cat/node/postproc '
104
+ bom , endpoint = 'http://127.0.0.1:5000/cat/node/process '
83
105
):
84
106
def f (
85
107
process_obj , invoice_bom = bom ,
@@ -94,56 +116,97 @@ def f(
94
116
95
117
return f
96
118
97
- def create_order (self ,
119
+ def create_order_request (self ,
98
120
process_obj , data_dirpath , structure_filepath ,
99
- endpoint = 'http://127.0.0.1:5000/cat/node/preproc '
121
+ endpoint = 'http://127.0.0.1:5000/cat/node/execute '
100
122
):
101
123
structure_cid , structure_name = self .meshClient .cidFile (structure_filepath )
102
124
function = {
103
125
'process_cid' : self .ipfsClient .add_pyobj (process_obj ),
104
126
'infrafunction_cid' : None
105
127
}
106
- order_bom = {
107
- "invoice" : {
108
- "data_cid" : self .meshClient .cidDir (data_dirpath )
109
- },
110
- "order" : {
111
- "function_cid" : self .ipfsClient .add_str (json .dumps (function )),
112
- "structure_cid" : structure_cid ,
113
- "structure_filepath" : structure_name ,
114
- "endpoint" : endpoint
115
- },
116
- "function" : function
128
+ invoice = {
129
+ "data_cid" : self .meshClient .cidDir (data_dirpath )
130
+ }
131
+ order = {
132
+ "function_cid" : self .ipfsClient .add_str (json .dumps (function )),
133
+ "structure_cid" : structure_cid ,
134
+ "invoice_cid" : self .ipfsClient .add_str (json .dumps (invoice )),
135
+ "structure_filepath" : structure_name ,
136
+ "endpoint" : endpoint
137
+ }
138
+ self .order = {
139
+ 'order_cid' : self .ipfsClient .add_str (json .dumps (order ))
117
140
}
118
- self .order = order_bom
119
141
return self .order
120
142
143
+ def process_loader (self , process_obj , invoice_bom , endpoint ):
144
+ new_order_bom = {}
145
+ new_order_bom ["order" ] = json .loads (self .meshClient .cat (invoice_bom ["order_cid" ]))
146
+ new_order_bom ["order" ]["endpoint" ] = endpoint
147
+ new_order_bom ["function" ] = json .loads (self .meshClient .cat (new_order_bom ["order" ]["function_cid" ]))
148
+ new_order_bom ["function" ]['process_cid' ] = self .ipfsClient .add_pyobj (process_obj )
149
+ new_order_bom ["order" ]["function_cid" ] = self .ipfsClient .add_str (json .dumps (new_order_bom ["function" ]))
150
+ new_order_bom ["order_cid" ] = self .ipfsClient .add_str (json .dumps (new_order_bom ["order" ]))
151
+ # new_order_bom["order"] = json.loads(self.meshClient.cat(new_order_bom["order_cid"]))
152
+ del new_order_bom ["function" ]
153
+ # next_invoice = {
154
+ # 'data_cid': invoice_bom['data_cid']
155
+ # }
156
+ #
157
+ # new_order_bom["order"]['invoice'] = next_invoice
158
+ # new_order_bom["order"]['invoice']['invoice_cid'] = self.ipfsClient.add_str(json.dumps(next_invoice))
159
+ new_order_bom ["invoice" ] = invoice_bom
160
+ del new_order_bom ['invoice' ]['order_cid' ]
161
+ del new_order_bom ['invoice' ]['seed_cid' ]
162
+ new_order_bom ['order' ]['invoice_cid' ] = self .ipfsClient .add_str (json .dumps (new_order_bom ['invoice' ]))
163
+ new_order_bom ['invoice' ] = new_order_bom ['invoice' ]
164
+ return new_order_bom
165
+
121
166
def catJob_repl (self ,
122
- previous_invoice_bom , modify_bom ,
123
- endpoint = 'http://127.0.0.1:5000/cat/node/postproc '
124
- ):
125
- def resubmit_catJob (
167
+ previous_invoice , structured_function ,
168
+ endpoint = 'http://127.0.0.1:5000/cat/node/process '
169
+ ):
170
+ def resubmit_order (
126
171
process_obj
127
172
):
128
- def resubmit_order (process_obj = process_obj ):
129
- order_bom = modify_bom (process_obj , previous_invoice_bom , endpoint )
130
- return order_bom , self .catSubmit (order_bom )
131
-
132
- order_bom , invoice_bom = resubmit_order (process_obj )
133
- return order_bom , invoice_bom , resubmit_order
134
-
135
- return resubmit_catJob
173
+ def f (process_obj = process_obj ):
174
+ order_request = structured_function (
175
+ service = self ,
176
+ process_obj = process_obj ,
177
+ invoice = previous_invoice ,
178
+ endpoint = endpoint
179
+ )
180
+ # del order_request['order']
181
+ # del order_request['invoice']
182
+ pprint (order_request )
183
+ print ()
184
+ cat_response = self .catSubmit (order_request )
185
+ pprint (cat_response )
186
+ # exit()
187
+ return self .flatten_bom (cat_response )
188
+ flat_cat_response = f (process_obj )
189
+ flat_cat_response ['cat_processor' ] = f
190
+ return flat_cat_response
191
+
192
+ return resubmit_order
136
193
137
194
def cat_repl (self ,
138
- order_bom , bom_function ,
195
+ order_bom , structured_function ,
139
196
endpoint = 'http://127.0.0.1:5000/cat/node'
140
197
):
141
- preproc_endpoint = f'{ endpoint } /preproc '
198
+ # preproc_endpoint = f'{endpoint}/execute '
142
199
# order_bom["order"]['endpoint'] = preproc_endpoint
143
- pprint (order_bom )
144
- invoice_bom = self .catSubmit (order_bom )
145
-
146
- postproc_endpoint = f'{ endpoint } /postproc'
147
- catJobRepl = self .catJob_repl (invoice_bom , bom_function , postproc_endpoint )
148
- return order_bom , invoice_bom , catJobRepl
200
+ cat_response = self .catSubmit (order_bom )
201
+ flat_cat_response = self .flatten_bom (cat_response )
202
+
203
+ postproc_endpoint = f'{ endpoint } /process'
204
+ # invoice = flat_cat_response['flat_bom']['invoice']
205
+ invoice = json .loads (self .meshClient .cat (flat_cat_response ['bom' ]["invoice_cid" ]))
206
+ # pprint(invoice)
207
+ # print()
208
+ # exit()
209
+ catJobRepl = self .catJob_repl (invoice , structured_function , postproc_endpoint )
210
+ flat_cat_response ['cat_processor' ] = catJobRepl
211
+ return flat_cat_response
149
212
0 commit comments