Commit d63592b5 authored by Jiahang Chen's avatar Jiahang Chen
Browse files

cleanup

parent 1036415a
Pipeline #358527 passed with stage
in 13 seconds
[Master]
init-hook = 'import sys; sys.path.append("./"); sys.path.append("/home/r2d2m/.pyenv/versions/3.6.6/envs/fml40-venv-3.6.6/lib/python3.6/site-packages/")'
\ No newline at end of file
{"thingId": "s3i:7f46a255-3245-439e-84f0-090f0b221965", "policyId": "s3i:7f46a255-3245-439e-84f0-090f0b221965", "attributes": {"class": "ml40::Thing", "name": "my_HMI", "roles": [{"class": "ml40::HMI"}], "features": []}}
\ No newline at end of file
{"identifier": "s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03", "secret": "cd4d24d2-f702-4f51-b0cf-6b77a423b33a"}
\ No newline at end of file
import s3i
import jwt
from ml.tools import load_config, make_thing_config, make_sub_thing
from ml.dt_factory import create_dt_ref, build_feature, add_function_impl_obj
from ml.dt_factory import create_thing, build_feature, add_function_impl_obj
from ml.fml40.features.functionalities.accepts_felling_jobs import AcceptsFellingJobs
from ml.ml40.features.properties.values.documents.jobs.job_status import JobStatus
from ml.app_logger import APP_LOGGER, setup_logger
import time
from config import *
import os
import json
from config import *
dt_creation_app_id = dt_creation_app_id
dt_creation_app_secret = dt_creation_app_secret
# username = input('[S3I]: Please enter your username:').strip('," ')
# password = input('[S3I]: Please enter your password:')
username = username
password = password
cred = chen
username = cred["username"]
password = cred["password"]
s3i_identity_provider = s3i.IdentityProvider(grant_type='password',
identity_provider_url="https://idp.s3i.vswf.dev/",
realm='KWH',
......@@ -30,7 +32,6 @@
parsed_username = jwt.decode(access_token, verify=False)["preferred_username"]
### create identity of digital twin
"""
s3i_config = s3i.Config(access_token)
resp = s3i_config.create_thing()
......@@ -38,33 +39,45 @@
dt_secret = resp.json().get("secret", None)
s3i_config.create_broker_queue(thing_id=dt_id)
res = s3i_config.create_cloud_copy(thing_id=dt_id)
print(dt_id)
"""
dt_id = dt_id
dt_secret = dt_secret
dt_cred = {
"identifier": dt_id,
"secret": dt_secret
}
dt_name = "my_dt_harvester"
config_path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, "configs"))
cred_filepath = os.path.join(config_path, "{}_cred.json".format(dt_name))
with open(cred_filepath, 'wb') as file:
file.write(json.dumps(dt_cred).encode('utf-8'))
config_engine = make_sub_thing(name="my_engine", roles=[{"class": "ml40::Engine"}],
features=[
{"class": "ml40::RotationalSpeed",
"rpm": 2001}
])
config_cran = make_sub_thing(name="my_bord_computer", roles=[{"class": "ml40::MachineUI"}])
config_path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, "configs"))
config_file_name = make_thing_config(dt_id=dt_id, name=dt_name, roles=[{"class": "fml40::Harvester"}],
config_file_name = make_thing_config(thing_id=dt_id, name=dt_name, roles=[{"class": "fml40::Harvester"}],
features=[{"class": "fml40::ProvidesProductionData"},
{"class": "fml40::AcceptsFellingJobs"},
{"class": "ml40::Location", "longitude": 6.45435, "latitude": 52.543534},
{"class": "ml40::Composite",
"targets": [config_engine, config_cran]}],
config_path=config_path)
config_path=config_path)
setup_logger(dt_name)
dt_model = load_config(config_filepath=os.path.join(config_path, config_file_name))
dt_model = load_config(config_filepath=os.path.join(config_path, "my_dt_harvester.json"))
with open(cred_filepath) as file:
dt_cred = json.load(file)
dt = create_dt_ref(model=dt_model, grant_type="client_credentials", secret=dt_secret,
dt = create_thing(model=dt_model, grant_type="client_credentials", secret=dt_cred.get("secret"),
is_broker_rest=True,
is_broker=True, is_repo=True)
......
......@@ -2,22 +2,28 @@
import jwt
import uuid
from ml.tools import find_broker_endpoint, make_thing_config, load_config, make_feature_config
from ml.dt_factory import create_dt_ref, build_feature
from ml.dt_factory import create_thing, build_feature
from ml.app_logger import setup_logger
import requests
import json
from config import *
#from config import *
import os
from config import *
root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))
config_path = os.path.join(root_path, "configs")
cred = chen
hmi_id = cred["application_id"]
hmi_secret = cred["application_secret"]
username = cred["username"]
password = cred["password"]
setup_logger("my HMI")
config_file_name = make_thing_config(dt_id=hmi_id, name="my HMI", roles=[{"class": "ml40::HMI"}],
root=root_path)
hmi_model = load_config(config_file_name, root=root_path)
hmi = create_dt_ref(model=hmi_model, grant_type="password", secret=hmi_secret,
config_file_name = make_thing_config(thing_id=hmi_id, name="my_HMI", roles=[{"class": "ml40::HMI"}],
config_path=config_path)
hmi_model = load_config(config_filepath=os.path.join(config_path, config_file_name))
hmi = create_thing(model=hmi_model, grant_type="password", secret=hmi_secret,
username=username, password=password,
is_broker_rest=True, is_broker=True, is_repo=False)
hmi.run_forever()
......@@ -27,8 +33,6 @@
"""
Print out thing entry from directory and repository
"""
print(hmi.dir.queryThingIDBased(thingID=receiver))
print(hmi.repo.queryThingIDBased(thingID=receiver))
serv_req = s3i.messages.ServiceRequest()
......@@ -82,4 +86,5 @@
)
receiver_endpoint = find_broker_endpoint(hmi.dir, thing_id=receiver)
resp = hmi.broker.send([receiver_endpoint], json.dumps(getv_req.msg))
resp = hmi.broker.send([receiver_endpoint], json.dumps(serv_req.msg))
print(resp.text)
\ No newline at end of file
[pylint]
max-line-length = 88
[pylint.Master]
init-hook = 'import sys; sys.path.append("./"); sys.path.append("/home/r2d2m/.pyenv/versions/3.6.6/envs/fml40-venv-3.6.6/lib/python3.6/site-packages/")'
[pylint.messages_control]
disable = C0330, C0326
[flake8]
max-line-length = 88
extend-ignore = E203, W503
[isort]
multi_line_output = 3
include_trailing_comma = True
force_grid_wrap = 0
use_parentheses = True
line_length = 88
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment