Skip to content
Snippets Groups Projects
Commit e89bbad6 authored by Jiahang Chen's avatar Jiahang Chen
Browse files

update felling job

parent 1675d16b
No related branches found
No related tags found
1 merge request!4Dev chen
Pipeline #339817 passed
{"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
{"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
{
"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
{"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
<<<<<<< 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
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
""" """
dt_id = "s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03" dt_id = "s3i:b6d1cc6d-896c-40fe-9403-b5b7682b1d03"
dt_secret = "cd4d24d2-f702-4f51-b0cf-6b77a423b33a" 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", config_file_name = make_config_file(dt_id=dt_id, name=dt_name, roles="fml40::Harvester",
features=["fml40::ProvidesProductionData", "fml40::AcceptsFellingJobs"]) features=["fml40::ProvidesProductionData", "fml40::AcceptsFellingJobs"])
setup_logger(dt_name) setup_logger(dt_name)
...@@ -63,9 +63,8 @@ ...@@ -63,9 +63,8 @@
class AcceptsFellingJobsImpl(AcceptsFellingJobs): class AcceptsFellingJobsImpl(AcceptsFellingJobs):
def my_accept_job_func(self, job): 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) return self.add_to_job_list(job)
dt_proxy.add_function_impl(AcceptsFellingJobsImpl, "AcceptsFellingJobs") dt_proxy.add_function_impl(AcceptsFellingJobsImpl, "AcceptsFellingJobs")
...@@ -34,8 +34,8 @@ ...@@ -34,8 +34,8 @@
serv_req.fillServiceRequest( serv_req.fillServiceRequest(
senderUUID=hmi_id, receiverUUID=[receiver], sender_endpoint=hmi_endpoint, senderUUID=hmi_id, receiverUUID=[receiver], sender_endpoint=hmi_endpoint,
serviceType="AcceptsFellingJobs/queryJobStatus", serviceType="AcceptsFellingJobs/acceptJob",
parameters={"identifier": job_proxy.identifier.get()}, parameters={"job": job_proxy.to_json().get()},
msgUUID=str(uuid.uuid4()) msgUUID=str(uuid.uuid4())
) )
......
...@@ -127,20 +127,23 @@ def build_sub_featrues(thing_ref, feature_proxy, json_feature): ...@@ -127,20 +127,23 @@ def build_sub_featrues(thing_ref, feature_proxy, json_feature):
def build(thing_ref, attributes): def build(thing_ref, attributes):
thing_proxy = thing_ref.proxy() thing_proxy = thing_ref.proxy()
roles = attributes.get("roles", []) roles = attributes.get("roles", [])
if not roles:
APP_LOGGER.critical("Roles: %s is missing" % roles) for role in roles:
else: role_name = role.get("class", "")
APP_LOGGER.debug("Adding roles: %s" % roles) if not role:
thing_proxy.roles = roles 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", []) json_features = attributes.get("features", [])
for json_feature in json_features: for json_feature in json_features:
class_name = json_feature.get("class", "") feature_name = json_feature.get("class", "")
feature = DT_FACTORY.get(class_name, None) feature = DT_FACTORY.get(feature_name, None)
if not feature: if not feature:
APP_LOGGER.critical("Feature: %s is missing" % class_name) APP_LOGGER.critical("Feature: %s is missing" % feature_name)
else: else:
APP_LOGGER.debug("Adding feature: %s" % class_name) APP_LOGGER.debug("Adding feature: %s" % feature_name)
feature_ref = feature.start("", thing_ref) feature_ref = feature.start("", thing_ref)
feature_proxy = feature_ref.proxy() feature_proxy = feature_ref.proxy()
feature_proxy.from_json(json_feature).get() feature_proxy.from_json(json_feature).get()
...@@ -177,7 +180,7 @@ def create_dt_ref(model, grant_type, secret, username, password, is_broker_rest, ...@@ -177,7 +180,7 @@ def create_dt_ref(model, grant_type, secret, username, password, is_broker_rest,
sys.exit("Incomplete model: roles missing!") sys.exit("Incomplete model: roles missing!")
thing_name = attributes.get("name", "") 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) d_t = DT_FACTORY.get(thing_type, ManagingActor)
thing_ref = d_t.start( thing_ref = d_t.start(
model=model, model=model,
......
from ml.ml40.features.functionalities.accepts_jobs import AcceptsJobs 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.fml40.features.properties.values.documents.jobs.felling_job import FellingJob
from ml.app_logger import APP_LOGGER from ml.app_logger import APP_LOGGER
...@@ -12,19 +13,27 @@ def __init__(self, name, ref_managing_actor): ...@@ -12,19 +13,27 @@ def __init__(self, name, ref_managing_actor):
def acceptJob(self, job: FellingJob) -> bool: def acceptJob(self, job: FellingJob) -> bool:
APP_LOGGER.info("Checking if the felling job can be accepted.") 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) return self.add_to_job_list(job)
def queryJobStatus(self, identifier): def queryJobStatus(self, identifier):
APP_LOGGER.info("Checking the job status of job {}".format(identifier))
for job in self.job_list: for job in self.job_list:
if job.get("id") == identifier: 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")} return {"identifier": identifier, "status": job.get("status")}
APP_LOGGER.info("Job {} can not be queried".format(identifier))
return {"identifier": identifier, "status": "NOT FOUND"} return {"identifier": identifier, "status": "NOT FOUND"}
def removeJob(self, identifier): def removeJob(self, identifier):
APP_LOGGER.info("Checking if i can remove the job {}".format(identifier))
for job in self.job_list: for job in self.job_list:
if job.get("id") == identifier: if job.get("id") == identifier:
self.job_list.remove(job) self.job_list.remove(job)
APP_LOGGER.info("Job {} removed".format(identifier))
return True return True
APP_LOGGER.info("Job {} can not be found".format(identifier))
return False return False
def from_json(self, json_obj): def from_json(self, json_obj):
...@@ -32,8 +41,10 @@ def from_json(self, json_obj): ...@@ -32,8 +41,10 @@ def from_json(self, json_obj):
def add_to_job_list(self, job): def add_to_job_list(self, job):
if job not in self.job_list: if job not in self.job_list:
job["status"] = JobStatus.InProgress.name
self.job_list.append(job) self.job_list.append(job)
APP_LOGGER.info("Job accepted!")
return True return True
else: else:
APP_LOGGER.info("This felling job has been already added in job list") APP_LOGGER.info("Job has been already accepted!")
return False return False
\ No newline at end of file
...@@ -83,6 +83,14 @@ def features(self): ...@@ -83,6 +83,14 @@ def features(self):
def features(self, value): def features(self, value):
self.__features = value self.__features = value
@property
def roles(self):
return self.__roles
@roles.setter
def roles(self, value):
self.__roles = value
@property @property
def class_name(self): def class_name(self):
return self.__class_name return self.__class_name
...@@ -313,7 +321,7 @@ def on_service_request(self, body_json): ...@@ -313,7 +321,7 @@ def on_service_request(self, body_json):
senderUUID=self.thing_id, senderUUID=self.thing_id,
receiverUUID=body_json.get("sender", None), receiverUUID=body_json.get("sender", None),
serviceType=body_json.get("serviceType", None), serviceType=body_json.get("serviceType", None),
results=result, results=results,
replyingToUUID=body_json.get("identifier", None), replyingToUUID=body_json.get("identifier", None),
msgUUID="s3i:{}".format(uuid.uuid4()) msgUUID="s3i:{}".format(uuid.uuid4())
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment