Commit 2f71a532 authored by Jiahang Chen's avatar Jiahang Chen
Browse files

UPDATE some properties

parent 7dbabfcd
Pipeline #340637 passed with stage
in 14 seconds
{"thingId": "s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03", "policyId": "s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03", "attributes": {"class": "ml40::Thing", "name": "my_dt_harvester", "roles": [{"class": "fml40::Harvester"}], "features": [{"class": "fml40::ProvidesProductionData"}, {"class": "fml40::AcceptsFellingJobs"}, {"class": "ml40::Composite", "targets": [{"class": "ml40::Thing", "name": "my_engine", "roles": [{"class": "ml40::Engine"}], "features": [{"class": "ml40::RotationalSpeed"}]}, {"class": "ml40::Thing", "name": "my_bord_computer", "roles": [{"class": "ml40::MachineUI"}], "features": []}]}]}}
\ No newline at end of file
{"thingId": "s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03", "policyId": "s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03", "attributes": {"class": "ml40::Thing", "name": "my_dt_harvester", "roles": [{"class": "fml40::Harvester"}], "features": [{"class": "fml40::ProvidesProductionData"}, {"class": "fml40::AcceptsFellingJobs"}, {"class": "ml40::Composite", "targets": [{"class": "ml40::Thing", "name": "my_engine", "roles": [{"class": "ml40::Engine"}], "features": [{"class": "ml40::RotationalSpeed", "rpm": 5}]}, {"class": "ml40::Thing", "name": "my_bord_computer", "roles": [{"class": "ml40::MachineUI"}], "features": []}]}]}}
\ No newline at end of file
......@@ -2,7 +2,7 @@
import json
import jwt
import requests
from ml.tools import load_config, make_config_file, make_sub_thing
from ml.tools import load_config, make_thing_config, make_sub_thing
from ml.dt_factory import create_dt_ref
from ml.fml40.features.functionalities.accepts_felling_jobs import AcceptsFellingJobs
from ml.app_logger import APP_LOGGER, setup_logger
......@@ -27,38 +27,36 @@
parsed_username = jwt.decode(access_token, verify=False)["preferred_username"]
### create identity of digital twin
# TODO class for config api in master to merge
# create a thing identity for the dt
"""
create_thing_resp = requests.post(url="https://config.s3i.vswf.dev/things/",
headers={"Authorization": "Bearer {}".format(access_token),
"Content-Type": "application/json"},
data=json.dumps({}))
dt_id = create_thing_resp.json().get("identifier", None)
s3i_config = s3i.Config(access_token)
resp = s3i_config.create_thing()
dt_id = resp.json().get("identifier", None)
dt_secret = resp.json().get("secret", None)
s3i_config.create_broker_queue(thing_id=dt_id)
print(dt_id)
create_cloud_copy_resp = requests.post(url="https://config.s3i.vswf.dev/things/{}/repository".format(dt_id),
headers={"Authorization": "Bearer {}".format(access_token),
"Content-Type": "application/json"})
create_endpoint_resp = requests.post(url="https://config.s3i.vswf.dev/things/{}/broker".format(dt_id),
headers={"Authorization": "Bearer {}".format(access_token),
"Content-Type": "application/json"},
data=json.dumps({"encrypted": False})
)
dt_secret = create_thing_resp.json().get("secret", None)
"""
dt_id = "s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03"
dt_secret = "cd4d24d2-f702-4f51-b0cf-6b77a423b33a"
dt_name = "my_dt_harvester"
config_engine = make_sub_thing(name="my_engine", roles=["ml40::Engine"],
features=["ml40::RotationalSpeed"])
config_cran = make_sub_thing(name="my_bord_computer", roles=["ml40::MachineUI"])
config_engine = make_sub_thing(name="my_engine", roles=[{"class": "ml40::Engine"}],
features=[
{"class": "ml40::RotationalSpeed",
"rpm": 5}
])
config_cran = make_sub_thing(name="my_bord_computer", roles=[{"class": "ml40::MachineUI"}])
config_file_name = make_config_file(dt_id=dt_id, name=dt_name, roles=["fml40::Harvester"],
features=["fml40::ProvidesProductionData", "fml40::AcceptsFellingJobs",
{"ml40::Composite": [config_engine, config_cran]}])
config_file_name = make_thing_config(dt_id=dt_id, name=dt_name, roles=[{"class": "fml40::Harvester"}],
features=[{"class": "fml40::ProvidesProductionData"},
{"class": "fml40::AcceptsFellingJobs"},
{"class": "ml40::Composite",
"targets": [config_engine, config_cran]}])
setup_logger(dt_name)
dt_model = load_config('configs/{}'.format(config_file_name))
dt_ref = create_dt_ref(model=dt_model, grant_type="password", secret=dt_secret, username=username, password=password,
is_broker_rest=True,
is_broker=True, is_repo=False)
......@@ -72,9 +70,12 @@ def my_accept_job_func(self, job):
return self.add_to_job_list(job)
dt_proxy.add_function_impl(AcceptsFellingJobsImpl, "AcceptsFellingJobs")
print(dt_proxy.features.get())
#print(dt_proxy.features.get()["Composite"].targets.get())
dt_proxy.add_function_impl(AcceptsFellingJobsImpl, "fml40::AcceptsFellingJobs")
#print(dt_proxy.features.get())
print(dt_proxy.features.get()["ml40::Composite"].proxy().to_json().get())
#print(dt_proxy.features.get()["Composite"].proxy().targets.get()[0].proxy().features.get())
#print(dt_proxy.features.get()["Composite"].proxy().targets.get()[0].proxy().features.get()["RotationalSpeed"].proxy().rpm.get())
#print(dt_proxy.roles.get())
#print(dt_proxy.name.get())
......
import s3i
import jwt
import uuid
from ml.tools import find_broker_endpoint, make_config_file, load_config
from ml.dt_factory import create_dt_ref
from ml.tools import find_broker_endpoint, make_thing_config, load_config, make_feature_config
from ml.identifier import ID
from ml.dt_factory import create_dt_ref, create_feature_ref
from ml.fml40.features.properties.values.documents.jobs.felling_job import FellingJob
from ml.identifier import ID
from ml.app_logger import setup_logger
import requests
import json, time
......@@ -12,8 +14,10 @@
password = "8810515"
hmi_id = "s3i:b4f72a11-fb3d-47a3-b499-e7a88eaa5fe1"
hmi_secret = "84df6340-9d64-4ae6-9076-86c224ec484a"
setup_logger("my HMI")
config_file_name = make_config_file(dt_id=hmi_id, name="my HMI", roles="ml40::HMI")
config_file_name = make_thing_config(dt_id=hmi_id, name="my HMI", roles=[{"class": "ml40::HMI"}],
)
hmi_model = load_config('configs/{}'.format(config_file_name))
hmi_ref = create_dt_ref(model=hmi_model, grant_type="password", secret=hmi_secret,
username=username, password=password,
......@@ -25,19 +29,51 @@
hmi_endpoint = find_broker_endpoint(hmi_proxy.dir.get(), hmi_id)
serv_req = s3i.messages.ServiceRequest()
receiver = input("[S³I]: Please enter the id of your digital twin: ")
job_ref = FellingJob.start("ml40::FellingJob", hmi_ref)
job_proxy = job_ref.proxy()
job_proxy.identifier = "s3i:d53e84fd-432c-4e19-9008-546f296c2d5c"
print(job_proxy.to_json().get())
subFeatures = [{
"class": "fml40::Assortment",
"grade": "fl",
"name": "Stammholz Abschnitte",
"subFeatures": [
{
"class": "fml40::ThicknessClass",
"name": ">"
},
{
"class": "fml40::WoodQuality",
"name": "B-C"
},
{
"class": "fml40::HarvestingParameters",
"cuttingLengths": 20
},
{
"class": "fml40::TreeType",
"name": "Spruce",
"conifer": True
},
{
"class": "fml40::HarvestedVolume",
"volume": 140
}
]
}]
id = ID(identifier="s3i:721b1947-2807-4bc3-a6d3-fe9e97de90d0").ID
feature_config_json = make_feature_config(class_name="fml40::FellingJob", identifier=id, subFeatures=subFeatures)
felling_job_ref = create_feature_ref(model=feature_config_json, thing_ref=hmi_ref)
felling_job_proxy = felling_job_ref.proxy()
print(felling_job_proxy.to_json().get())
receiver = input("[S³I]: Please enter the id of your digital twin: ")
serv_req.fillServiceRequest(
senderUUID=hmi_id, receiverUUID=[receiver], sender_endpoint=hmi_endpoint,
serviceType="AcceptsFellingJobs/acceptJob",
parameters={"job": job_proxy.to_json().get()},
serviceType="fml40::AcceptsFellingJobs/removeJob",
parameters={"identifier": id},
#parameters={"job": felling_job_proxy.to_json().get()},
msgUUID=str(uuid.uuid4())
)
receiver_endpoint = find_broker_endpoint(hmi_proxy.dir.get(), thing_id=receiver)
resp = hmi_proxy.broker.get().send([receiver_endpoint], json.dumps(serv_req.msg))
""" Implements a factory for managing digital twins."""
import sys, json
from s3i import IdentityProvider
from s3i import TokenType
from ml.tools import get_idp
from ml.managing_actor import ManagingActor
from ml.tools import load_config
from ml.app_logger import APP_LOGGER
from ml.thing import Thing
from ml.tools import remove_namespace
from ml.thing import Thing
from ml.ml40.roles.servives.service import Service
from ml.ml40.roles.hmis.app import App
from ml.ml40.roles.hmis.dashboard import Dashboard
from ml.ml40.roles.hmis.machine_ui import MachineUI
from ml.ml40.roles.hmis.hmd import HMD
from ml.ml40.roles.hmis.hmi import HMI
from ml.ml40.roles.dts.handheld_devices.handheld_device import HandheldDevice
from ml.ml40.roles.dts.machines.machine import Machine
from ml.ml40.roles.dts.parts.crane import Crane
from ml.ml40.roles.dts.parts.part import Part
from ml.ml40.roles.dts.parts.engine import Engine
from ml.ml40.roles.dts.parts.scale import Scale
from ml.ml40.roles.dts.parts.tank import Tank
from ml.ml40.roles.dts.persons.machine_operator import MachineOperator
from ml.ml40.roles.dts.persons.person import Person
from ml.ml40.roles.dts.sensors.sensor import Sensor
from ml.ml40.roles.dts.sensors.air_sensor import AirSensor
from ml.ml40.roles.dts.sensors.soil_sensor import SoilSensor
from ml.ml40.roles.dts.sites.site import Site
from ml.ml40.roles.dts.ways.way import Way
from ml.fml40.roles.dts.handheld_devices.brushcutter import Brushcutter
from ml.fml40.roles.dts.handheld_devices.chainsaw import Chainsaw
from ml.fml40.roles.dts.machines.forest_machine import ForestMachine
from ml.fml40.roles.dts.machines.forwarder import Forwarder
from ml.fml40.roles.dts.machines.harvester import Harvester
from ml.fml40.roles.dts.machines.log_truck import LogTruck
from ml.ml40.features.functionalities.manages_jobs import ManagesJobs
from ml.ml40.features.properties.values.location import Location
from ml.ml40.features.properties.shared import Shared
from ml.fml40.roles.dts.machines.mini_tractor import MiniTractor
from ml.fml40.roles.dts.machines.skidder import Skidder
from ml.fml40.roles.dts.machines.wheel_loader import WheelLoader
from ml.fml40.roles.dts.parts.grabber import Grabber
from ml.fml40.roles.dts.parts.harvesting_head import HarvestingHead
from ml.fml40.roles.dts.parts.log_loading_area import LogLoadingArea
from ml.fml40.roles.dts.parts.saw import Saw
from ml.fml40.roles.dts.parts.winch import Winch
from ml.fml40.roles.dts.persons.forest_owner import ForestOwner
from ml.fml40.roles.dts.persons.forest_worker import ForestWorker
from ml.fml40.roles.dts.persons.mini_tractor_operator import MiniTractorOperator
from ml.fml40.roles.dts.persons.skidder_operator import SkidderOperator
from ml.fml40.roles.dts.sensors.vitality_sensor import VilalitySensor
from ml.fml40.roles.dts.sites.forest_enterprise import ForestEnterprise
from ml.fml40.roles.dts.sites.hauler import Hauler
from ml.fml40.roles.dts.sites.mill.mill import Mill
from ml.fml40.roles.dts.sites.mill.papermill import Papermill
from ml.fml40.roles.dts.sites.mill.sawmill import Sawmill
from ml.ml40.features.properties.association import Association
from ml.ml40.features.properties.composite import Composite
from ml.ml40.features.properties.values.weight import Weight
from ml.ml40.features.properties.property import Property
from ml.ml40.features.properties.shared import Shared
from ml.ml40.features.properties.values.address import Address
from ml.ml40.features.properties.values.dimensions import Dimensions
from ml.ml40.features.properties.values.generic_property import GenericProperty
from ml.ml40.features.properties.values.liquid_filling_level import LiquidFillingLevel
from ml.ml40.features.properties.values.location import Location
from ml.ml40.features.properties.values.moisture import Moisture
from ml.fml40.features.functionalities.accepts_proximity_alert import (
AcceptsProximityAlert,
)
from ml.ml40.features.properties.values.personal_name import PersonalName
from ml.ml40.features.properties.values.rotational_speed import RotationalSpeed
from ml.ml40.features.properties.values.route import Route
from ml.ml40.features.properties.values.temperature import Temperature
from ml.ml40.features.properties.values.time_slot import TimeSlot
from ml.ml40.features.properties.values.weight import Weight
from ml.ml40.features.properties.values.documents.jobs.generic_job import GenericJob
from ml.ml40.features.properties.values.documents.jobs.job import Job
from ml.ml40.features.properties.values.documents.jobs.job_list import JobList
from ml.ml40.features.properties.values.documents.jobs.job_status import JobStatus
from ml.ml40.features.properties.values.documents.reports.report import Report
from ml.fml40.features.properties.values.abstract_inventory import AbstractInventory
from ml.fml40.features.properties.values.assortment import Assortment
from ml.fml40.features.properties.values.dbh import DBH
from ml.fml40.features.properties.values.harvesting_parameter import HarvestingParameters
from ml.fml40.features.properties.values.harvested_volume import HarvestedVolume
from ml.fml40.features.properties.values.inventory_data import InventoryData
from ml.fml40.features.properties.values.stem_segment_properties import StemSegmentProperties
from ml.fml40.features.properties.values.thickness_class import ThicknessClass
from ml.fml40.features.properties.values.tilt import Tilt
from ml.fml40.features.properties.values.tree_data import TreeData
from ml.fml40.features.properties.values.tree_type import TreeType
from ml.fml40.features.properties.values.wood_quality import WoodQuality
from ml.fml40.features.properties.values.documents.jobs.felling_job import FellingJob
from ml.fml40.features.properties.values.documents.jobs.fellung_support_job import FellingSupportJob
from ml.fml40.features.properties.values.documents.jobs.forwarding_job import ForwardingJob
from ml.fml40.features.properties.values.documents.jobs.log_transportation_job import LogTransportationJob
from ml.fml40.features.properties.values.documents.jobs.safety_felling_job import SafetyFellingJob
from ml.fml40.features.properties.values.documents.jobs.single_tree_felling_job import SingleTreeFellingJob
from ml.fml40.features.properties.values.documents.jobs.transportation_job import TransportationJob
from ml.fml40.features.properties.values.documents.reports.afforestation_suggestion import AfforestationSuggestion
from ml.fml40.features.properties.values.documents.reports.felling_method_suggestion import FellingMethodSuggestion
from ml.fml40.features.properties.values.documents.reports.felling_support_suggestion import FellingSupportSuggestion
from ml.fml40.features.properties.values.documents.reports.felling_tool import FellingTool
from ml.fml40.features.properties.values.documents.reports.log_measurement import LogMeasurement
from ml.fml40.features.properties.values.documents.reports.log_transportation_report import LogTransportationReport
from ml.fml40.features.properties.values.documents.reports.map_data import MapData
from ml.fml40.features.properties.values.documents.reports.moisture_prediction_report import MoisturePredictionReport
from ml.fml40.features.properties.values.documents.reports.passability_report import PassabilityReport
from ml.fml40.features.properties.values.documents.reports.production_data import ProductionData
from ml.fml40.features.properties.values.documents.reports.soil_moisture_measurement import SoilMoistureMeasurement
from ml.ml40.features.functionalities.accepts_jobs import AcceptsJobs
from ml.ml40.features.functionalities.accepts_reports import AcceptsReports
from ml.ml40.features.functionalities.clears_jobs import ClearsJobs
from ml.ml40.features.functionalities.functionality import Functionality
from ml.ml40.features.functionalities.manages_jobs import ManagesJobs
from ml.ml40.features.functionalities.plans_routes import PlansRoutes
from ml.ml40.features.functionalities.provides_map_data import ProvidesMapData
from ml.ml40.features.functionalities.provides_operational_data import ProvidesOperationalData
from ml.ml40.features.functionalities.renders import Renders
from ml.fml40.features.functionalities.accepts_felling_jobs import AcceptsFellingJobs
from ml.fml40.features.functionalities.harvests import Harvests
from ml.fml40.features.functionalities.accepts_felling_support_jobs import AcceptFellingSupportJobs
from ml.fml40.features.functionalities.accepts_log_measurements import AcceptsLogMeasurements
from ml.fml40.features.functionalities.accepts_log_transportaition_jobs import AcceptsLogTransportationJobs
from ml.fml40.features.functionalities.accepts_moisture_measurement import AcceptsMoistureMeasurement
from ml.fml40.features.functionalities.accepts_move_commands import AcceptsMoveCommands
from ml.fml40.features.functionalities.accepts_passability_report import AcceptsPassabilityReport
from ml.fml40.features.functionalities.accepts_proximity_alert import AcceptsProximityAlert
from ml.fml40.features.functionalities.accepts_single_tree_felling_jobs import AcceptsSingleTreeFellingJobs
from ml.fml40.features.functionalities.classifies_tree_species import ClassifiesTreeSpecies
from ml.fml40.features.functionalities.cuts import Cuts
from ml.fml40.features.functionalities.determines_passability import DeterminesPassability
from ml.fml40.features.functionalities.displays_health_alarms import DisplaysHealthAlarms
from ml.fml40.features.functionalities.evaluates_stand_attributes import EvaluatesStandAttributes
from ml.fml40.features.functionalities.fells import Fells
from ml.fml40.features.functionalities.forest_planning_evaluation import ForestPlanningEvaluation
from ml.fml40.features.functionalities.forwards import Forwards
from ml.fml40.features.functionalities.provides_production_data import (
ProvidesProductionData,
)
from ml.fml40.features.functionalities.accepts_forwarding_jobs import (
AcceptsForwardingJobs,
)
from ml.fml40.features.functionalities.provides_passability_information import (
ProvidesPassabilityInformation,
)
from ml.fml40.features.functionalities.provides_moisture_prediction import (
ProvidesMoisturePrediction,
)
from ml.fml40.features.functionalities.accepts_passability_report import (
AcceptsPassabilityReport,
)
from ml.fml40.features.properties.values.documents.reports.moisture_prediction_report import (
MoisturePredictionReport,
)
from ml.fml40.features.functionalities.generates_afforestation_suggestions import GeneratesAfforestationSuggestions
from ml.fml40.features.functionalities.generates_felling_suggestions import GeneratesFellingSuggestions
from ml.fml40.features.functionalities.grabs import Grabs
from ml.fml40.features.functionalities.harvests import Harvests
from ml.fml40.features.functionalities.measure_wood import MeasuresWood
from ml.fml40.features.functionalities.monitor_health_status import MonitorsHealthStatus
from ml.fml40.features.functionalities.provides_moisture_prediction import ProvidesMoisturePrediction
from ml.fml40.features.functionalities.provides_passability_information import ProvidesPassabilityInformation
from ml.fml40.features.functionalities.provides_production_data import ProvidesProductionData
from ml.fml40.features.functionalities.provides_tree_data import ProvidesTreeData
from ml.fml40.features.functionalities.provides_weather_data import ProvidesWeatherData
from ml.fml40.features.functionalities.simulates_tree_growth import SimulatesTreeGrowth
from ml.fml40.features.functionalities.supports_felling import SupportsFelling
from ml.fml40.features.functionalities.transports_logs import TransportsLogs
# TODO: Get rid of this global variable
# TODO: automatically get all classes in modul
DT_FACTORY = {}
"""
DT_FACTORY["Thing"] = Thing
DT_FACTORY["Composite"] = Composite
......@@ -77,7 +180,13 @@
DT_FACTORY["ProvidesMoisturePrediction"] = ProvidesMoisturePrediction
DT_FACTORY["MoisturePredictionReport"] = MoisturePredictionReport
DT_FACTORY["AcceptsPassabilityReport"] = AcceptsPassabilityReport
"""
import sys, inspect
clsmembers = inspect.getmembers(sys.modules[__name__], inspect.isclass)
for member in clsmembers:
DT_FACTORY[member[0]] = member[1]
def get_dt_names():
"""Returns a list containg the names of all registered digital twins.
......@@ -115,26 +224,45 @@ def create_dt_with_idp(config, id_p):
# return d_t
###
#TODO: was passiert, wenn es unter subfeature noch ein subsubfeature gibt?
def build_sub_featrues(thing_ref, feature_proxy, json_feature):
json_sub_features = json_feature.get("subFeatures", [])
temp_dict = {}
for json_sub_feature in json_sub_features:
class_name = json_sub_feature.get("class", "")
sub_feature = DT_FACTORY.get(class_name, None)
if not sub_feature:
APP_LOGGER.critical("Subfeature: %s is missing" % class_name)
#str_sub_feature = json.dumps(json_sub_feature).replace("fml40::", "").replace("ml40::", "").replace("'", '"')
#json_sub_feature = json.loads(str_sub_feature)
sub_feature_name = json_sub_feature.get("class", "")
sub_feature = DT_FACTORY.get(remove_namespace(sub_feature_name), None)
if sub_feature is None:
APP_LOGGER.critical("Subfeature: %s is missing" % sub_feature_name)
else:
APP_LOGGER.debug("Adding subfeature: %s" % class_name)
sub_feature_ref = sub_feature.start("", thing_ref)
sub_feature_proxy = sub_feature_ref.proxy()
sub_feature_proxy.from_json(json_feature).get()
type_name = sub_feature_proxy.type_name.get()
sub_features = feature_proxy.subfeatures.get()
sub_features.append(sub_feature_ref)
APP_LOGGER.debug("Adding subfeature: %s" % sub_feature_name)
sub_feature_ref = sub_feature.start(sub_feature_name, thing_ref)
temp_dict[sub_feature_name] = sub_feature_ref
for key in json_sub_feature.keys():
if key == "targets":
build_sub_thing(feature_proxy, sub_feature)
elif key == "subFeatures":
build_sub_featrues(thing_ref, sub_feature_ref.proxy(), json_sub_feature)
else:
setattr(sub_feature_ref.proxy(), key, json_sub_feature[key])
feature_proxy.subFeatures = temp_dict
def build_sub_thing(feature_proxy, json_feature):
json_sub_things = json_feature.get("targets", [])
for json_sub_thing in json_sub_things:
sub_thing_ref = create_dt_ref(model={"attributes": json_sub_thing})
feature_proxy.targets.get().append(sub_thing_ref)
def build(thing_ref, attributes):
if not isinstance(attributes, dict):
APP_LOGGER.critical("Attributes is no valid json")
return
thing_proxy = thing_ref.proxy()
roles = attributes.get("roles", [])
__build_roles(thing_ref, thing_proxy, roles)
......@@ -142,21 +270,31 @@ def build(thing_ref, attributes):
json_features = attributes.get("features", [])
for json_feature in json_features:
feature_name = json_feature.get("class", "")
feature = DT_FACTORY.get(feature_name, None)
feature_pars = json_feature
feature = DT_FACTORY.get(remove_namespace(feature_name), None)
if feature is None:
APP_LOGGER.critical("Feature: %s is missing" % feature_name)
else:
APP_LOGGER.debug("Adding feature: %s" % feature_name)
feature_ref = feature.start(feature_name, thing_ref)
feature_proxy = feature_ref.proxy()
for key in feature_pars.keys():
if key == "targets":
build_sub_thing(feature_proxy, json_feature)
elif key == "subFeatures":
build_sub_featrues(thing_ref, feature_proxy, json_feature)
else:
setattr(feature_proxy, key, feature_pars[key])
thing_proxy.features.get()[feature_proxy.name.get()] = feature_ref
build_sub_featrues(thing_ref, feature_proxy, json_feature)
def __build_roles(thing_ref, thing_proxy, roles):
for role in roles:
role_name = role.get("class", "")
role = DT_FACTORY.get(role_name, None)
role = DT_FACTORY.get(remove_namespace(role_name), None)
if role is None:
APP_LOGGER.critical("Roles: %s is missing" % role_name)
else:
......@@ -165,7 +303,32 @@ def __build_roles(thing_ref, thing_proxy, roles):
thing_proxy.roles.get()[role_name] = role_ref
def create_dt_ref(model, grant_type, secret, username, password, is_broker_rest, is_broker, is_repo):
def create_feature_ref(model, thing_ref):
if not isinstance(model, dict):
APP_LOGGER.error("The input feature model is no valid json")
feature_class = model.get("class", None)
if feature_class is None:
APP_LOGGER.error("Incomplete model: class missing")
feature = DT_FACTORY.get(feature_class.replace("fml40::", "").replace("ml40::", ""), "")
feature_ref = feature.start(feature_class, thing_ref)
feature_proxy = feature_ref.proxy()
feature_id = model.get("identifier", None)
print(feature_id)
if feature_id is not None:
feature_proxy.identifier = feature_id
feature_sub_features = model.get("subFeatures", None)
if feature_sub_features is not None:
build_sub_featrues(thing_ref, feature_proxy, {"subFeatures": feature_sub_features})
return feature_ref
def create_dt_ref(model, grant_type="password",
secret="", username=None, password=None,
is_broker_rest=False, is_broker=False, is_repo=False):
"""Creates a ditigal twin, runs it in an own thread and returns a
reference to it.
......@@ -179,10 +342,9 @@ def create_dt_ref(model, grant_type, secret, username, password, is_broker_rest,
attributes = model.get("attributes", None)
if attributes is None:
sys.exit("Incomplete model: attributes missing!")
attributes = str(attributes).replace("fml40::", "").replace("ml40::", "").replace("'", '"')
attributes = json.loads(attributes)
thing_type = attributes.get("class", "")
#attributes = json.dumps(attributes).replace("fml40::", "").replace("ml40::", "").replace("'", '"')
#attributes = json.loads(attributes)
thing_type = remove_namespace(attributes.get("class", ""))
if thing_type == "":
print("Unknown type %s" % thing_type)
sys.exit()
......@@ -206,4 +368,3 @@ def create_dt_ref(model, grant_type, secret, username, password, is_broker_rest,
)
build(thing_ref, attributes)
return thing_ref
......@@ -20,7 +20,7 @@ def acceptJob(self, job: FellingJob) -> bool:
def queryJobStatus(self, identifier):
APP_LOGGER.info("Checking the job status of job {}".format(identifier))
for job in self.job_list:
if job.get("id") == identifier:
if job.get("identifier") == identifier:
APP_LOGGER.info("Job {} is now in status {}".format(identifier, job.get("status")))
return {"identifier": identifier, "status": job.get("status")}
APP_LOGGER.info("Job {} can not be queried".format(identifier))
......@@ -29,7 +29,7 @@ def queryJobStatus(self, identifier):
def removeJob(self, identifier):
APP_LOGGER.info("Checking if i can remove the job {}".format(identifier))
for job in self.job_list:
if job.get("id") == identifier:
if job.get("identifier") == identifier:
self.job_list.remove(job)
APP_LOGGER.info("Job {} removed".format(identifier))
return True
......@@ -40,11 +40,17 @@ def from_json(self, json_obj):
super().from_json(json_obj)
def add_to_job_list(self, job):
if job not in self.job_list:
if self.job_list:
if job.get("identifier", None) not in str(self.job_list):
job["status"] = JobStatus.InProgress.name
self.job_list.append(job)
APP_LOGGER.info("Job accepted!")
return True
else:
APP_LOGGER.info("Job has been already accepted!")
return False
else:
job["status"] = JobStatus.InProgress.name
self.job_list.append(job)
APP_LOGGER.info("Job accepted!")
return True
else:
APP_LOGGER.info("Job has been already accepted!")
return False
\ No newline at end of file
return True
\ No newline at end of file
from modelling_language.ml40.feature.functionality.AcceptsJob import AcceptsJobs
from modelling_language.fml40.feature.property.value.document.job.FellingSupportJob import FellingSupportJob
from ml.ml40.features.functionalities.accepts_jobs import AcceptsJobs
from ml.fml40.features.properties.values.documents.jobs.fellung_support_job import FellingSupportJob
class AcceptFellingSupportJobs(AcceptsJobs):
......
from modelling_language.ml40.feature.functionality import Functionality
from modelling_language.fml40.feature.property.value.document.report import LogMeasurement
from ml.ml40.features.functionalities.functionality import Functionality
from ml.fml40.features.properties.values.documents.reports.log_measurement import LogMeasurement
class AcceptsLogMeasurements(Functionality):
......
from modelling_language.ml40.feature.functionality import AcceptsJobs
from modelling_language.fml40.feature.property.value.document.job import LogTransportationJob
from ml.ml40.features.functionalities.accepts_jobs import AcceptsJobs
from ml.fml40.features.properties.values.documents.jobs.log_transportation_job import LogTransportationJob
class AcceptsLogTransportationJobs(AcceptsJobs):
......
from modelling_language.ml40.feature.functionality import Functionality
from modelling_language.fml40.feature.property.value.document.report import SoilMoistureMeasurement