This commit is contained in:
Lucio Lelii 2008-12-15 15:38:53 +00:00
parent 6209c85f84
commit a8c2aef169
1 changed files with 18 additions and 153 deletions

View File

@ -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<String> 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<RegistryTopic, GCUBEResource>();
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)