diff --git a/configs/config.json b/configs/config.json deleted file mode 100644 index e59d1d45855cd2ebe48127e5f140723d8521af76..0000000000000000000000000000000000000000 --- a/configs/config.json +++ /dev/null @@ -1 +0,0 @@ -{"thingId": "s3i:feb857f1-3058-4ed4-8826-bbf182cbb16e", "policyId": "s3i:feb857f1-3058-4ed4-8826-bbf182cbb16e", "attributes": {"class": "ml40::Thing", "name": "dt test", "roles": [{"class": "fml40::Harvester"}], "features": [{"class": "fml40::ProvidesProductionData"}, {"class": "fml40::AcceptsFellingJobs"}]}} \ No newline at end of file diff --git a/configs/config_dt test.json b/configs/config_dt test.json deleted file mode 100644 index 231c19107379174f114659b6c1e9b1b20a0a2fcf..0000000000000000000000000000000000000000 --- a/configs/config_dt test.json +++ /dev/null @@ -1 +0,0 @@ -{"thingId": "s3i:b4a0ec9b-66be-4390-b786-9c70b1c017e6", "policyId": "s3i:b4a0ec9b-66be-4390-b786-9c70b1c017e6", "attributes": {"class": "ml40::Thing", "name": "dt test", "roles": [{"class": "fml40::Harvester"}], "features": [{"class": "fml40::ProvidesProductionData"}, {"class": "fml40::AcceptsFellingJobs"}]}} \ No newline at end of file diff --git a/configs/config_dt.json b/configs/config_dt.json deleted file mode 100644 index 18878854800e58f12c052fb8619e70d57ca3c240..0000000000000000000000000000000000000000 --- a/configs/config_dt.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "thingId": "s3i:bea74f50-fa6c-4aba-b7f8-90153b401ffc", - "policyId": "s3i:bea74f50-fa6c-4aba-b7f8-90153b401ffc", - "attributes": { - "class": "ml40::Thing", - "name": "created DT Harvester for workshop", - "roles": [ - { - "class": "fml40::Harvester" - } - ], - "features": [ - { - "class": "fml40::ProvidesProductionData" - }, - { - "class": "fml40::AcceptsFellingJobs" - }, - { - "class": "ml40::ManagesJobs" - } - ] - } -} \ No newline at end of file diff --git a/configs/config_my_dt_harvester.json b/configs/config_my_dt_harvester.json new file mode 100644 index 0000000000000000000000000000000000000000..31a77746490de932c3d049a289c552bfe8f4440d --- /dev/null +++ b/configs/config_my_dt_harvester.json @@ -0,0 +1 @@ +{"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"}]}} \ No newline at end of file diff --git a/configs/config_test.json b/configs/config_test.json deleted file mode 100644 index 9a9f1f9460079dda0572c21a059430c748a7c28c..0000000000000000000000000000000000000000 --- a/configs/config_test.json +++ /dev/null @@ -1,5 +0,0 @@ -<<<<<<< HEAD -{"thingId": "s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03", "policyId": "s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03", "attributes": {"class": "ml40::Thing", "name": "test", "roles": [{"class": "fml40::Harvester"}], "features": [{"class": "fml40::ProvidesProductionData"}, {"class": "fml40::AcceptsFellingJobs"}]}} -======= -{"thingId": "s3i:af86ad33-63a4-427b-9914-3f199cd025c4", "policyId": "s3i:af86ad33-63a4-427b-9914-3f199cd025c4", "attributes": {"class": "ml40::Thing", "name": "test", "roles": [{"class": "fml40::Harvester"}], "features": [{"class": "fml40::ProvidesProductionData"}, {"class": "fml40::AcceptsFellingJobs"}]}} ->>>>>>> 0d577bac3a3ae43fd629d56880417b19316cd9c0 diff --git a/dt_creation.py b/dt_creation.py index 11a68101433b38db68acfe3b552ffc2030413928..9a3f329eba73dbc08c6edbf40b672c5489f8af4f 100644 --- a/dt_creation.py +++ b/dt_creation.py @@ -49,7 +49,7 @@ """ dt_id = "s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03" dt_secret = "cd4d24d2-f702-4f51-b0cf-6b77a423b33a" -dt_name = "test" +dt_name = "my_dt_harvester" config_file_name = make_config_file(dt_id=dt_id, name=dt_name, roles="fml40::Harvester", features=["fml40::ProvidesProductionData", "fml40::AcceptsFellingJobs"]) setup_logger(dt_name) @@ -63,9 +63,8 @@ class AcceptsFellingJobsImpl(AcceptsFellingJobs): def my_accept_job_func(self, job): - APP_LOGGER.info("I am checking if the felling job can be accepted.") + APP_LOGGER.info("Checking job with my impl function.") return self.add_to_job_list(job) dt_proxy.add_function_impl(AcceptsFellingJobsImpl, "AcceptsFellingJobs") - diff --git a/dt_creation_hmi.py b/dt_creation_hmi.py index 1242d590446025e240e4c78b67eb20c96462709c..f4f99e101edc0e15ba8194ad1dce5ebdd2b28782 100644 --- a/dt_creation_hmi.py +++ b/dt_creation_hmi.py @@ -34,8 +34,8 @@ serv_req.fillServiceRequest( senderUUID=hmi_id, receiverUUID=[receiver], sender_endpoint=hmi_endpoint, - serviceType="AcceptsFellingJobs/queryJobStatus", - parameters={"identifier": job_proxy.identifier.get()}, + serviceType="AcceptsFellingJobs/acceptJob", + parameters={"job": job_proxy.to_json().get()}, msgUUID=str(uuid.uuid4()) ) diff --git a/ml/dt_factory.py b/ml/dt_factory.py index aa7f79a2e0d93df7c6d266cdeafed6952a4e2cb4..d5c90e65db80868b76742accebce5ea4199dcad9 100644 --- a/ml/dt_factory.py +++ b/ml/dt_factory.py @@ -127,20 +127,23 @@ def build_sub_featrues(thing_ref, feature_proxy, json_feature): def build(thing_ref, attributes): thing_proxy = thing_ref.proxy() roles = attributes.get("roles", []) - if not roles: - APP_LOGGER.critical("Roles: %s is missing" % roles) - else: - APP_LOGGER.debug("Adding roles: %s" % roles) - thing_proxy.roles = roles + + for role in roles: + role_name = role.get("class", "") + if not role: + APP_LOGGER.critical("Roles: %s is missing" % role_name) + else: + APP_LOGGER.debug("Adding roles: %s" % role_name) + thing_proxy.roles.get().append(role_name) json_features = attributes.get("features", []) for json_feature in json_features: - class_name = json_feature.get("class", "") - feature = DT_FACTORY.get(class_name, None) + feature_name = json_feature.get("class", "") + feature = DT_FACTORY.get(feature_name, None) if not feature: - APP_LOGGER.critical("Feature: %s is missing" % class_name) + APP_LOGGER.critical("Feature: %s is missing" % feature_name) else: - APP_LOGGER.debug("Adding feature: %s" % class_name) + APP_LOGGER.debug("Adding feature: %s" % feature_name) feature_ref = feature.start("", thing_ref) feature_proxy = feature_ref.proxy() feature_proxy.from_json(json_feature).get() @@ -177,7 +180,7 @@ def create_dt_ref(model, grant_type, secret, username, password, is_broker_rest, sys.exit("Incomplete model: roles missing!") thing_name = attributes.get("name", "") - APP_LOGGER.debug("Creating ditigtal twin %s" % thing_name) + APP_LOGGER.debug("Creating ditigtal twin {} with id {}".format(thing_name, model.get("thingId", ""))) d_t = DT_FACTORY.get(thing_type, ManagingActor) thing_ref = d_t.start( model=model, diff --git a/ml/fml40/features/functionalities/accepts_felling_jobs.py b/ml/fml40/features/functionalities/accepts_felling_jobs.py index 11bbfce64691629cfad69980866856043d57cdf5..230e208ec4cda497f6e07d0538461f488e37f3ff 100644 --- a/ml/fml40/features/functionalities/accepts_felling_jobs.py +++ b/ml/fml40/features/functionalities/accepts_felling_jobs.py @@ -1,4 +1,5 @@ from ml.ml40.features.functionalities.accepts_jobs import AcceptsJobs +from ml.ml40.features.properties.values.documents.jobs.job_status import JobStatus from ml.fml40.features.properties.values.documents.jobs.felling_job import FellingJob from ml.app_logger import APP_LOGGER @@ -12,19 +13,27 @@ def __init__(self, name, ref_managing_actor): def acceptJob(self, job: FellingJob) -> bool: APP_LOGGER.info("Checking if the felling job can be accepted.") + if job.get("id") is None or job.get("status") is None: + return False return self.add_to_job_list(job) 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: + 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)) return {"identifier": identifier, "status": "NOT FOUND"} 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: self.job_list.remove(job) + APP_LOGGER.info("Job {} removed".format(identifier)) return True + APP_LOGGER.info("Job {} can not be found".format(identifier)) return False def from_json(self, json_obj): @@ -32,8 +41,10 @@ def from_json(self, json_obj): def add_to_job_list(self, job): if job not in self.job_list: + job["status"] = JobStatus.InProgress.name self.job_list.append(job) + APP_LOGGER.info("Job accepted!") return True else: - APP_LOGGER.info("This felling job has been already added in job list") + APP_LOGGER.info("Job has been already accepted!") return False \ No newline at end of file diff --git a/ml/thing.py b/ml/thing.py index c7fb9aa66154c56e50c79c596ef14f2e0c68040b..6d29980fb00efd9aacbcd9e2498a703fa892da8d 100644 --- a/ml/thing.py +++ b/ml/thing.py @@ -83,6 +83,14 @@ def features(self): def features(self, value): self.__features = value + @property + def roles(self): + return self.__roles + + @roles.setter + def roles(self, value): + self.__roles = value + @property def class_name(self): return self.__class_name @@ -313,7 +321,7 @@ def on_service_request(self, body_json): senderUUID=self.thing_id, receiverUUID=body_json.get("sender", None), serviceType=body_json.get("serviceType", None), - results=result, + results=results, replyingToUUID=body_json.get("identifier", None), msgUUID="s3i:{}".format(uuid.uuid4()) )