diff --git a/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java b/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java index 2ae7932..f641a43 100644 --- a/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java +++ b/src/org/gcube/informationsystem/registry/impl/contexts/ServiceContext.java @@ -23,6 +23,7 @@ import org.gcube.common.core.resources.GCUBERunningInstance; import org.gcube.common.core.scope.GCUBEScope; import org.gcube.common.core.utils.handlers.GCUBEHandler; import org.gcube.common.core.utils.handlers.GCUBEScheduledHandler; +import org.gcube.common.vremanagement.ghnmanager.impl.GHNManager; import org.gcube.informationsystem.registry.impl.RegistryFactory; import org.gcube.informationsystem.registry.impl.core.RegistryConfiguration.ROOT_SERVICES; import org.gcube.informationsystem.registry.impl.state.RegistryFactoryResource; @@ -115,23 +116,35 @@ public class ServiceContext extends GCUBEServiceContext { 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", this.getName())); - if (ServiceContext.getContext().client.execute(query, ServiceContext.getContext().getScope()).size() == 0) - registerProfile(RegistryRIProfile, GCUBERunningInstance.TYPE); - + 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); - throw e; } + + + - ServiceContext.getContext().setScope(ServiceContext.getContext().getInstance().getScopes().values().toArray(new GCUBEScope[0])[0]); - RegistryFactoryResource resource = (RegistryFactoryResource) FactoryContext.getContext().getWSHome().create( - FactoryContext.getContext().makeKey(RegistryFactory.NOTIFICATOR_RESOURCE_KEY)); - resource.getPersistenceDelegate().store(resource ); } }); @@ -158,17 +171,16 @@ public class ServiceContext extends GCUBEServiceContext { * @throws Exception * @throws ISPublisherException */ - private void registerProfile(GCUBEResource resource, String type) + 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, ServiceContext.getContext().getScope(), - ServiceContext.getContext()); + resource, scope, ServiceContext.getContext()); } private void checkCodeployedServices () throws Exception { - + this.client = GHNContext.getImplementation(ISClient.class); GCUBERunningInstance NotifierRIProfile = null; GCUBERunningInstance ISICRIProfile = null; @@ -197,21 +209,27 @@ public class ServiceContext extends GCUBEServiceContext { // registers the local IS-Notifier profile if (isNotifierCodeployed) { GCUBERIQuery query = client.getQuery(GCUBERIQuery.class); - query.addAtomicConditions(new AtomicCondition( - "//Endpoint@EntryName","gcube/informationsystem/notifier/Notifier"),new AtomicCondition("//ServiceName", ROOT_SERVICES.ISNOTIFIER.getName())); + query.addGenericCondition("$result/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint[string(@EntryName) eq 'gcube/informationsystem/notifier/Notifier'] "); + query.addAtomicConditions(new AtomicCondition("//ServiceName", ROOT_SERVICES.ISNOTIFIER.getName())); - if (client.execute(query, ServiceContext.getContext().getScope()).size() == 0) - registerProfile(NotifierRIProfile, GCUBERunningInstance.TYPE); + + 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.addAtomicConditions(new AtomicCondition( - "//Endpoint@EntryName","gcube/informationsystem/isic/ISICFactoryService"),new AtomicCondition("//ServiceName", ROOT_SERVICES.ISIC.getName())); - - if (client.execute(query, ServiceContext.getContext().getScope()).size() == 0) - registerProfile(ISICRIProfile, GCUBERunningInstance.TYPE); + 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 @@ -220,9 +238,11 @@ public class ServiceContext extends GCUBEServiceContext { GCUBEHostingNode ghnProfile = GHNContext.getContext().getGHN(); GCUBEGHNQuery node = client.getQuery(GCUBEGHNQuery.class); node.addAtomicConditions(new AtomicCondition("/GHNDescription/Name", ghnProfile.getNodeDescription().getName())); - - if (client.execute(node, ServiceContext.getContext().getScope()).size() == 0) - registerProfile(ghnProfile, GCUBEHostingNode.TYPE); + + for (GCUBEScope scope: ServiceContext.getContext().getInstance().getScopes().values()) + if (ServiceContext.getContext().client.execute(node,scope ).size() == 0) + registerProfile(ghnProfile, GCUBEHostingNode.TYPE, scope); + } diff --git a/src/org/gcube/informationsystem/registry/impl/state/ProfileResource.java b/src/org/gcube/informationsystem/registry/impl/state/ProfileResource.java index b5707f3..722f8ba 100644 --- a/src/org/gcube/informationsystem/registry/impl/state/ProfileResource.java +++ b/src/org/gcube/informationsystem/registry/impl/state/ProfileResource.java @@ -99,19 +99,8 @@ public class ProfileResource extends GCUBEWSResource { if (!(RegistryFactory.notificationMap.contains(this.getID()))) { try { notifier = GHNContext.getImplementation(ISNotifier.class); - System.out.println("i'm here ---------------"); - for (SimpleTopic s : listQname) - System.out.println(s); - System.out.println(listQname); - System.out.println(listQname.getClass()); - try { notifier.registerISNotification(this.getEPR(), listQname, ServiceContext.getContext()); - } catch (ArrayStoreException e) { - System.out.println(e); - e.printStackTrace(); - System.out.println("end stack trace"); - } - System.out.println("i'm there xxx---------------"); + } catch (Exception e){ e.printStackTrace(); throw new ResourceException(e);