-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
M057: Integrates preloading of External DataSources as meta data resouces for use in Geonetwork #2120
Merged
Merged
M057: Integrates preloading of External DataSources as meta data resouces for use in Geonetwork #2120
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
ion/processes/data/registration/eoi_registration_process.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/usr/bin/env python | ||
from pyon.ion.process import SimpleProcess | ||
from pyon.ion.event import EventSubscriber | ||
from pyon.public import OT, RT | ||
import requests | ||
from pyon.public import CFG | ||
from pyon.util.log import log | ||
from pyon.util.breakpoint import breakpoint | ||
|
||
# GeoNetwork | ||
# TODO should maybe go in the yml file | ||
REQUEST_HARVESTER = "requestharvester" | ||
CREATE_HARVESTER = "createharvester" | ||
UPDATE_HARVESTER = "updateharvester" | ||
REMOVE_HARVESTER = "removeharvester" | ||
RESET_HARVESTER = "resetharvester" | ||
START_HARVESTER = "startharvester" | ||
STOP_HARVESTER = "stopharvester" | ||
RUN_HARVESTER = "runharvester" | ||
|
||
class EOIRegistrationProcess(SimpleProcess): | ||
|
||
def on_start(self): | ||
self.data_source_subscriber = EventSubscriber(event_type=OT.ResourceModifiedEvent, | ||
origin_type=RT.DataSource, | ||
callback=self._register_data_source) | ||
self.provider_subscriber = EventSubscriber(event_type=OT.ResourceModifiedEvent, | ||
origin_type=RT.ExternalDataProvider, | ||
callback=self._register_provider) | ||
self.data_source_subscriber.start() | ||
self.provider_subscriber.start() | ||
|
||
self.rr = self.container.resource_registry | ||
|
||
self.using_eoi_services = CFG.get_safe('eoi.meta.use_eoi_services', False) | ||
self.server = CFG.get_safe('eoi.importer_service.server', "localhost")+":"+str(CFG.get_safe('eoi.importer_service.port', 8844)) | ||
|
||
log.info("Using geoservices="+str(self.using_eoi_services)) | ||
if not self.using_eoi_services: | ||
log.warn("not using geoservices...") | ||
|
||
self.importer_service_available = self.check_for_importer_service() | ||
if not self.importer_service_available: | ||
log.warn("not using importer service...") | ||
|
||
def check_for_importer_service(self): | ||
''' | ||
only gets run on start, used to identify if importer service is available | ||
''' | ||
try: | ||
r = requests.get(self.server+'/service=alive&name=ooi&id=ooi') | ||
log.info("importer service available, status code: %s", str(r.status_code)) | ||
#alive service returned ok | ||
if r.status_code == 200: | ||
return True | ||
else: | ||
return False | ||
except Exception as e: | ||
#SERVICE IS REALLY NOT AVAILABLE | ||
log.warn("importer service is really not available...%s", e) | ||
return False | ||
|
||
|
||
def _register_data_source(self, event, *args, **kwargs): | ||
''' | ||
used to create a harvester | ||
''' | ||
if self.importer_service_available: | ||
obj = self.rr.read(event.origin) | ||
data_fields = [] | ||
for attrname, value in vars(obj).iteritems(): | ||
#generate th param list to pass to importer service using field names | ||
if attrname is not "contact": | ||
f = attrname.replace("_", "")+"="+str(obj[attrname]) | ||
data_fields.append(f) | ||
|
||
param_list = '&'.join(data_fields) | ||
|
||
request_string = self.server+'/service='+CREATE_HARVESTER+"&"+param_list | ||
r = requests.get(request_string) | ||
|
||
|
||
def _register_provider(self, event, *args, **kwargs): | ||
if self.importer_service_available: | ||
#print "provider id:", event.origin | ||
pass | ||
|
||
|
||
def on_quit(self): | ||
self.data_source_subscriber.stop() | ||
self.provider_subscriber.stop() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should place a general try-except Exception block around the main threads. These are long running and you cannot afford to lose them to some random exception