2008-04-22 14:11:53 +02:00
|
|
|
package org.gcube.vremanagement.vremodeler.impl;
|
|
|
|
|
2009-07-06 19:36:03 +02:00
|
|
|
|
2009-09-30 11:29:45 +02:00
|
|
|
import java.util.ArrayList;
|
2009-11-27 17:20:12 +01:00
|
|
|
import java.util.Collections;
|
2010-11-03 19:32:06 +01:00
|
|
|
import java.util.List;
|
2008-04-22 14:11:53 +02:00
|
|
|
import org.gcube.common.core.contexts.GCUBEServiceContext;
|
2009-09-30 11:29:45 +02:00
|
|
|
import org.gcube.common.core.contexts.GHNContext;
|
|
|
|
import org.gcube.common.core.informationsystem.notifier.ISNotifier;
|
2010-11-03 19:32:06 +01:00
|
|
|
import org.gcube.common.core.informationsystem.notifier.ISNotifier.GCUBENotificationTopic;
|
2009-09-30 11:29:45 +02:00
|
|
|
import org.gcube.common.core.scope.GCUBEScope;
|
|
|
|
import org.gcube.vremanagement.vremodeler.consumers.CollectionConsumer;
|
|
|
|
import org.gcube.vremanagement.vremodeler.consumers.GHNConsumer;
|
2009-11-27 17:20:12 +01:00
|
|
|
import org.gcube.vremanagement.vremodeler.consumers.GenericResourceConsumer;
|
2009-09-30 11:29:45 +02:00
|
|
|
import org.gcube.vremanagement.vremodeler.consumers.RunningInstanceConsumer;
|
2010-11-09 19:58:58 +01:00
|
|
|
import org.gcube.vremanagement.vremodeler.db.DBInterface;
|
2008-10-21 19:09:24 +02:00
|
|
|
import org.gcube.vremanagement.vremodeler.db.IStoDBUtil;
|
2010-02-23 18:04:28 +01:00
|
|
|
import org.gcube.vremanagement.vremodeler.impl.util.ServicePair;
|
2009-09-30 11:29:45 +02:00
|
|
|
import org.gcube.vremanagement.vremodeler.resources.handlers.CollectionHandler;
|
|
|
|
import org.gcube.vremanagement.vremodeler.resources.handlers.FunctionalityHandler;
|
|
|
|
import org.gcube.vremanagement.vremodeler.resources.handlers.GHNHandler;
|
2009-11-27 17:20:12 +01:00
|
|
|
import org.gcube.vremanagement.vremodeler.resources.handlers.GenericResourceHandler;
|
2008-04-22 14:11:53 +02:00
|
|
|
|
|
|
|
public class ServiceContext extends GCUBEServiceContext{
|
|
|
|
|
2008-04-22 15:04:13 +02:00
|
|
|
/** Single context instance, created eagerly */
|
|
|
|
private static ServiceContext cache = new ServiceContext();
|
|
|
|
|
2010-11-03 19:32:06 +01:00
|
|
|
private static List<GCUBENotificationTopic> topicToRemove= new ArrayList<ISNotifier.GCUBENotificationTopic>();
|
|
|
|
|
2008-04-22 15:04:13 +02:00
|
|
|
/** Returns cached instance */
|
|
|
|
public static ServiceContext getContext() {return cache;}
|
|
|
|
|
|
|
|
/** Prevents accidental creation of more instances */
|
|
|
|
private ServiceContext(){};
|
|
|
|
|
|
|
|
/** {@inheritDoc} */
|
2008-10-30 19:54:34 +01:00
|
|
|
protected String getJNDIName() {return "gcube/vremanagement/vremodeler";}
|
2008-04-22 15:04:13 +02:00
|
|
|
|
2009-11-27 17:20:12 +01:00
|
|
|
private ArrayList<String> secondaryTypeGenericResourceRequired= new ArrayList<String>();
|
|
|
|
|
2010-02-23 18:04:28 +01:00
|
|
|
private ArrayList<ServicePair> baseServiceForGhn= new ArrayList<ServicePair>();
|
|
|
|
|
2008-04-22 15:04:13 +02:00
|
|
|
protected void onReady() throws Exception{
|
2009-04-01 01:05:14 +02:00
|
|
|
try{
|
2009-02-10 19:54:48 +01:00
|
|
|
logger.info("ready event invoked on " + this.getName());
|
2009-02-13 20:04:00 +01:00
|
|
|
this.intializeDB();
|
2009-02-10 19:54:48 +01:00
|
|
|
}catch (Exception e){
|
2009-10-01 16:59:26 +02:00
|
|
|
logger.error("error initializing VREModeler",e);
|
2009-05-08 19:58:31 +02:00
|
|
|
this.setStatus(Status.FAILED);
|
2009-02-10 19:54:48 +01:00
|
|
|
throw e;
|
|
|
|
}
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
|
2009-02-13 20:04:00 +01:00
|
|
|
protected void intializeDB() throws Exception{
|
2010-02-23 18:04:28 +01:00
|
|
|
ArrayList<ServicePair> baseServiceGhn= new ArrayList<ServicePair>();
|
|
|
|
for (String gen:((String)this.getProperty("BaseRisForSelectableGHN", true)).split(";")){
|
|
|
|
String[] serviceString=gen.split(",");
|
|
|
|
new ServicePair(serviceString[0], serviceString[1]);
|
|
|
|
}
|
|
|
|
this.setBaseServiceForGhn(baseServiceGhn);
|
|
|
|
|
2009-09-30 11:29:45 +02:00
|
|
|
ISNotifier notifier= GHNContext.getImplementation(ISNotifier.class);
|
2009-10-01 16:59:26 +02:00
|
|
|
for (GCUBEScope scope : ServiceContext.getContext().getInstance().getScopes().values()){
|
2010-11-08 20:02:22 +01:00
|
|
|
if (scope.isInfrastructure()) continue;
|
2009-09-30 11:29:45 +02:00
|
|
|
ServiceContext.getContext().setScope(scope);
|
2009-11-27 17:20:12 +01:00
|
|
|
|
2009-12-21 16:28:25 +01:00
|
|
|
ArrayList<String> genResList= new ArrayList<String>();
|
|
|
|
for (String gen:((String)this.getProperty("GenericResourceToAdd", true)).split(","))
|
|
|
|
genResList.add(gen.trim());
|
|
|
|
this.setSecondaryTypeGenericResourceRequired(genResList.toArray(new String[0]));
|
2009-11-27 17:20:12 +01:00
|
|
|
|
2009-12-21 16:28:25 +01:00
|
|
|
|
2009-09-30 11:29:45 +02:00
|
|
|
IStoDBUtil.initDB(scope);
|
|
|
|
new GHNHandler().initialize();
|
|
|
|
new CollectionHandler().initialize();
|
|
|
|
FunctionalityHandler functionalityHandler= new FunctionalityHandler();
|
|
|
|
functionalityHandler.initialize();
|
2009-11-27 17:20:12 +01:00
|
|
|
new GenericResourceHandler().initialize();
|
2009-09-30 11:29:45 +02:00
|
|
|
logger.debug("Service initialized!!");
|
|
|
|
|
|
|
|
//GHNNotification
|
2010-11-03 19:32:06 +01:00
|
|
|
ArrayList<GCUBENotificationTopic> qnameList= new ArrayList<GCUBENotificationTopic>();
|
|
|
|
qnameList.add(GHNConsumer.ghnTopic);
|
|
|
|
notifier.registerToISNotification(new GHNConsumer(scope),qnameList, this, scope);
|
2009-09-30 11:29:45 +02:00
|
|
|
//RINotification
|
2010-11-03 19:32:06 +01:00
|
|
|
qnameList= new ArrayList<GCUBENotificationTopic>();
|
|
|
|
qnameList.add(RunningInstanceConsumer.riTopic);
|
|
|
|
notifier.registerToISNotification(new RunningInstanceConsumer(scope), qnameList, this, scope);
|
2009-09-30 11:29:45 +02:00
|
|
|
//CollectionNotification
|
2010-11-03 19:32:06 +01:00
|
|
|
qnameList= new ArrayList<GCUBENotificationTopic>();
|
|
|
|
qnameList.add(CollectionConsumer.collectionTopic);
|
|
|
|
notifier.registerToISNotification(new CollectionConsumer(scope), qnameList, this, scope);
|
2009-09-30 11:29:45 +02:00
|
|
|
//FunctionalityResource
|
2010-11-03 19:32:06 +01:00
|
|
|
qnameList= new ArrayList<GCUBENotificationTopic>();
|
|
|
|
qnameList.add(GenericResourceConsumer.functionalityTopic);
|
|
|
|
notifier.registerToISNotification(new GenericResourceConsumer(scope,functionalityHandler.getFunctionalityResourceId()), qnameList, this, scope);
|
2009-09-30 11:29:45 +02:00
|
|
|
|
|
|
|
logger.debug("consumers registered");
|
|
|
|
}
|
2010-11-03 19:32:06 +01:00
|
|
|
|
|
|
|
//saving topic for removing
|
|
|
|
topicToRemove.add(GHNConsumer.ghnTopic);
|
|
|
|
topicToRemove.add(RunningInstanceConsumer.riTopic);
|
|
|
|
topicToRemove.add(CollectionConsumer.collectionTopic);
|
|
|
|
topicToRemove.add(GenericResourceConsumer.functionalityTopic);
|
2009-02-13 20:04:00 +01:00
|
|
|
}
|
2009-11-27 17:20:12 +01:00
|
|
|
|
2010-11-03 19:32:06 +01:00
|
|
|
public void onShutdown() throws Exception{
|
|
|
|
ISNotifier notifier= GHNContext.getImplementation(ISNotifier.class);
|
|
|
|
for (GCUBEScope scope : ServiceContext.getContext().getInstance().getScopes().values()){
|
|
|
|
ServiceContext.getContext().setScope(scope);
|
|
|
|
notifier.unregisterFromISNotification(this, topicToRemove, scope);
|
2010-11-09 19:58:58 +01:00
|
|
|
if (!scope.isInfrastructure()) DBInterface.close();
|
2010-11-03 19:32:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-27 17:20:12 +01:00
|
|
|
public ArrayList<String> getSecondaryTypeGenericResourceRequired() {
|
|
|
|
return secondaryTypeGenericResourceRequired;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSecondaryTypeGenericResourceRequired(
|
|
|
|
String[] secondaryTypeGenericResourceRequired) {
|
|
|
|
Collections.addAll(this.secondaryTypeGenericResourceRequired,secondaryTypeGenericResourceRequired);
|
|
|
|
}
|
2010-02-23 18:04:28 +01:00
|
|
|
|
|
|
|
public ArrayList<ServicePair> getBaseServiceForGhn() {
|
|
|
|
return baseServiceForGhn;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBaseServiceForGhn(ArrayList<ServicePair> baseServiceForGhn) {
|
|
|
|
this.baseServiceForGhn = baseServiceForGhn;
|
|
|
|
}
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|