From a8c2aef1699b65eadeaed7a600be0f5b1dd07fb2 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Mon, 15 Dec 2008 15:38:53 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@7883 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../impl/contexts/ServiceContext.java | 171 ++---------------- 1 file changed, 18 insertions(+), 153 deletions(-) diff --git a/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java b/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java index bd1556b..fbf168d 100644 --- a/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java +++ b/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java @@ -115,9 +115,7 @@ public class ServiceContext extends GCUBEServiceContext { @SuppressWarnings("unchecked") @Override protected void onReady() throws Exception { - - - + //switch to the production mode if needed if (GHNContext.getContext().getMode() == Mode.ROOT) GHNContext.getContext().setMode(Mode.CONNECTED); @@ -125,7 +123,7 @@ public class ServiceContext extends GCUBEServiceContext { //creates the single RegistryResource used to raise notifications about profiles' changes logger.info("Scheduling IS-Registry notification resource..."); - for (GCUBEScope scope: ServiceContext.getContext().getStartScopes()){ + for (GCUBEScope scope: ServiceContext.getContext().getInstance().getScopes().values()){ EliminatePoolingThread ept= new EliminatePoolingThread(); ServiceContext.getContext().setScope(ept, scope); ept.start(); @@ -134,172 +132,39 @@ public class ServiceContext extends GCUBEServiceContext { NotificationResourceScheduler scheduler = new NotificationResourceScheduler(20, GCUBEScheduledHandler.Mode.LAZY); scheduler.setHandled(new GCUBEHandler(){ - public void run() throws Exception { - - List pt = GHNContext.getContext().getActivePortTypes(); - if ( (pt == null) || (pt.size() < 1)) - throw new Exception(); - - - - try { - // register my profile - GCUBERunningInstance RegistryRIProfile = ServiceContext.getContext().getInstance(); - client = GHNContext.getImplementation(ISClient.class); - GCUBERIQuery query = ServiceContext.getContext().client.getQuery(GCUBERIQuery.class); - query.addAtomicConditions(new AtomicCondition("//ServiceClass", ServiceContext.this.getServiceClass()),new AtomicCondition("//ServiceName", ServiceContext.this.getInstance().getServiceName())); - - for (GCUBEScope scope: ServiceContext.getContext().getInstance().getScopes().values()) - { - ServiceContext.getContext().setScope(scope); - logger.trace("current scope: "+scope); - if (ServiceContext.getContext().client.execute(query,scope ).size() == 0) - registerProfile(RegistryRIProfile, GCUBERunningInstance.TYPE, scope); - - RegistryFactoryResource resource = (RegistryFactoryResource) FactoryContext.getContext().getWSHome().create(FactoryContext.getContext().makeKey(RegistryFactory.NOTIFICATOR_RESOURCE_KEY)); - resource.store(); - } - - ServiceContext.getContext().checkCodeployedServices(); - - - - - - } catch (Exception e) { - logger.error("Failed to register co-deployed services", e); - } - + public void run() throws Exception { - - - - + try { + for (GCUBEScope scope: ServiceContext.getContext().getInstance().getScopes().values()) + { + ServiceContext.getContext().setScope(scope); + RegistryFactoryResource resource = (RegistryFactoryResource) FactoryContext.getContext().getWSHome().create(FactoryContext.getContext().makeKey(RegistryFactory.NOTIFICATOR_RESOURCE_KEY)); + resource.store(); + } + + } catch (Exception e) { + logger.error("Failed to create the resource", e); } + + } }); - - scheduler.run(); - + scheduler.run(); this.subscribeToLocalRegistrationEvents(); - - } + @Override protected void onInitialisation() throws Exception { - //get the needed implementation classes - //this.queryRI = this.client.getQuery(GCUBERIQuery.class); - //this.queryGHN = this.client.getQuery(GCUBEResourceXPathQuery.class); this.client = GHNContext.getImplementation(ISClient.class); - topicProducer= new GCUBEProducer(); topicProducer.registerTopics(RegistryTopic.CREATE, RegistryTopic.UPDATE, RegistryTopic.REMOVE); } + - /** - * Register the Profile - * - * @param resource the GCUBEResource to register - * @param type the profile Type - * @throws Exception - * @throws ISPublisherException - */ - private void registerProfile(GCUBEResource resource, String type, GCUBEScope scope) - throws ISPublisherException, Exception { - if (GHNContext.getContext().getMode() == GHNContext.Mode.ROOT) - GHNContext.getImplementation(ISPublisher.class).registerGCUBEResource( - resource, scope, ServiceContext.getContext()); - - } - - private void checkCodeployedServices () throws Exception { - this.client = GHNContext.getImplementation(ISClient.class); - GCUBERunningInstance NotifierRIProfile = null; - GCUBERunningInstance ISICRIProfile = null; - - try { - NotifierRIProfile = GHNContext.getContext().getServiceContext( - ROOT_SERVICES.ISNOTIFIER.getClazz(), ROOT_SERVICES.ISNOTIFIER.getName()).getInstance(); - isNotifierCodeployed = true; - } catch (Exception e) { - logger.warn("Unable to detect if the " + ROOT_SERVICES.ISNOTIFIER.getName() + " is co-deployed"); - } - - /*try { - ManagerRIProfile = GHNContext.getContext().getServiceContext(ROOT_SERVICES.GHNMANAGER.getClazz(), ROOT_SERVICES.GHNMANAGER.getName()).getInstance(); - } catch (Exception e) { - logger.warn("Unable to detect if the " + ROOT_SERVICES.GHNMANAGER.getName() + " is co-deployed"); - }*/ - - try { - ISICRIProfile = GHNContext.getContext().getServiceContext( ROOT_SERVICES.ISIC.getClazz(), ROOT_SERVICES.ISIC.getName()).getInstance(); - isICCodeployed = true; - } catch (Exception e) { - logger.warn("Unable to detect if the " + ROOT_SERVICES.ISIC.getName() + " is co-deployed"); - } - - - // registers the local IS-Notifier profile - if (isNotifierCodeployed) { - GCUBERIQuery query = client.getQuery(GCUBERIQuery.class); - query.addGenericCondition("$result/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint[string(@EntryName) eq 'gcube/informationsystem/notifier/Notifier'] "); - query.addAtomicConditions(new AtomicCondition("//ServiceName", ROOT_SERVICES.ISNOTIFIER.getName())); - - - for (GCUBEScope scope: ServiceContext.getContext().getInstance().getScopes().values()) - if (ServiceContext.getContext().client.execute(query,scope ).size() == 0) - registerProfile(NotifierRIProfile, GCUBERunningInstance.TYPE, scope); - - - } - - // registers the local IS-IC profile - if (isICCodeployed) { - GCUBERIQuery query = client.getQuery(GCUBERIQuery.class); - query.addGenericCondition("$result/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint[string(@EntryName) eq 'gcube/informationsystem/isic/ISICFactoryService'] "); - query.addAtomicConditions(new AtomicCondition("//ServiceName", ROOT_SERVICES.ISIC.getName())); - - for (GCUBEScope scope: ServiceContext.getContext().getInstance().getScopes().values()) - if (ServiceContext.getContext().client.execute(query,scope ).size() == 0) - registerProfile(ISICRIProfile, GCUBERunningInstance.TYPE, scope); - - } - // registers the local GHNManager profile - - - //registers the GHN profile - GCUBEHostingNode ghnProfile = GHNContext.getContext().getGHN(); - GCUBEGHNQuery node = client.getQuery(GCUBEGHNQuery.class); - node.addAtomicConditions(new AtomicCondition("/GHNDescription/Name", ghnProfile.getNodeDescription().getName())); - - for (GCUBEScope scope: ServiceContext.getContext().getInstance().getScopes().values()) - if (ServiceContext.getContext().client.execute(node,scope ).size() == 0) - registerProfile(ghnProfile, GCUBEHostingNode.TYPE, scope); - - - } - - /** - * - * @return true if the IS-Notifier service is co-deployed on the node - */ - protected boolean isNotifierCodeployed() { - return isNotifierCodeployed; - } - - /** - * - * @return true if the IS-IC service is co-deployed on the node - */ - protected boolean isICCodeployed() { - return isICCodeployed; - } - private void subscribeToLocalRegistrationEvents() throws Exception{ ISLocalPublisher pub = GHNContext.getImplementation(ISLocalPublisher.class); - LocalProfileConsumer cons = new LocalProfileConsumer() { /* (non-Javadoc)