git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/VREModeler@17450 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a6922cb335
commit
90e1b5d0a8
|
@ -21,6 +21,13 @@
|
|||
value="600000"
|
||||
type="java.lang.String"
|
||||
override="false" />
|
||||
|
||||
<environment
|
||||
name="GenericResourceToAdd"
|
||||
value="UserProfile,Schemas Searchable Fields,MetadataXSLT,PresentationXSLT"
|
||||
type="java.lang.String"
|
||||
override="false" />
|
||||
|
||||
</service>
|
||||
|
||||
<service name="gcube/vremanagement/vremodeler/ModelerFactoryService"/>
|
||||
|
|
|
@ -40,8 +40,9 @@ public class GHNConsumer extends BaseNotificationConsumer{
|
|||
query.addAtomicConditions(new AtomicCondition("/ID",id));
|
||||
Thread.sleep(60000);
|
||||
new GHNHandler().add(client.execute(query, this.scope).get(0));
|
||||
} else if (operation.compareTo("remove")==0){
|
||||
} else if (operation.compareTo("destroy")==0){
|
||||
logger.trace("removing a GHN from DB");
|
||||
new GHNHandler().drop(id);
|
||||
}
|
||||
|
||||
}catch(Exception e){logger.error("error in notification received",e);}
|
||||
|
|
|
@ -11,25 +11,27 @@ import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery;
|
|||
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericResourceQuery;
|
||||
import org.gcube.common.core.informationsystem.notifier.ISNotifier.BaseNotificationConsumer;
|
||||
import org.gcube.common.core.informationsystem.notifier.ISNotifier.NotificationEvent;
|
||||
import org.gcube.common.core.resources.GCUBEGenericResource;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.vremanagement.vremodeler.impl.ServiceContext;
|
||||
import org.gcube.vremanagement.vremodeler.resources.handlers.FunctionalityHandler;
|
||||
import org.gcube.vremanagement.vremodeler.resources.handlers.GenericResourceHandler;
|
||||
import org.gcube.vremanagement.vremodeler.resources.kxml.KGCUBEGenericFunctionalityResource;
|
||||
|
||||
public class FunctionalityConsumer extends BaseNotificationConsumer{
|
||||
public class GenericResourceConsumer extends BaseNotificationConsumer{
|
||||
|
||||
private GCUBELog logger= new GCUBELog(GHNConsumer.class);
|
||||
|
||||
public static final QName functionalityQName= new QName("http://gcube-system.org/namespaces/informationsystem/registry","GenericResource");
|
||||
|
||||
private String resourceId;
|
||||
private String functionalityResourceId;
|
||||
private GCUBEScope scope;
|
||||
|
||||
public FunctionalityConsumer(GCUBEScope scope, String resourceId){
|
||||
public GenericResourceConsumer(GCUBEScope scope, String resourceId){
|
||||
super();
|
||||
this.scope=scope;
|
||||
this.resourceId= resourceId;
|
||||
this.functionalityResourceId= resourceId;
|
||||
}
|
||||
|
||||
public void onNotificationReceived(NotificationEvent event){
|
||||
|
@ -38,7 +40,8 @@ private GCUBELog logger= new GCUBELog(GHNConsumer.class);
|
|||
String id= event.getPayload().getMessage()[0].getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
|
||||
String operation=event.getPayload().getMessage()[0].getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
|
||||
logger.info("notification received for genericResource "+id+" and operation "+operation);
|
||||
if (id.compareTo(this.resourceId)==0 && (operation.compareTo("update")==0 || operation.compareTo("create")==0)){
|
||||
|
||||
if (id.compareTo(this.functionalityResourceId)==0 && (operation.compareTo("update")==0 || operation.compareTo("create")==0)){
|
||||
logger.trace("notification received for functionalityResource with id "+id+" in scope "+scope.toString());
|
||||
KGCUBEGenericFunctionalityResource resource= new KGCUBEGenericFunctionalityResource();
|
||||
ISClient client=GHNContext.getImplementation(ISClient.class);
|
||||
|
@ -51,6 +54,17 @@ private GCUBELog logger= new GCUBELog(GHNConsumer.class);
|
|||
//FunctionalityHandler
|
||||
FunctionalityHandler functionalityHandler= new FunctionalityHandler();
|
||||
functionalityHandler.add(resource);
|
||||
}else if (operation.compareTo("create")==0){
|
||||
logger.trace("notification received for generic resource with operation create");
|
||||
ISClient client=GHNContext.getImplementation(ISClient.class);
|
||||
GCUBEGenericResourceQuery query= client.getQuery(GCUBEGenericResourceQuery.class);
|
||||
query.addAtomicConditions(new AtomicCondition("/ID",this.functionalityResourceId));
|
||||
GCUBEGenericResource resource =client.execute(query, ServiceContext.getContext().getScope()).get(0);
|
||||
if (ServiceContext.getContext().getSecondaryTypeGenericResourceRequired().contains(resource.getSecondaryType()))
|
||||
new GenericResourceHandler().add(resource);
|
||||
}else if (operation.compareTo("destroy")==0){
|
||||
logger.trace("notification received for generic resource with operation destroy");
|
||||
new GenericResourceHandler().drop(id);
|
||||
}
|
||||
|
||||
}catch(Exception e){logger.error("error in functionality notification",e);}
|
|
@ -43,12 +43,12 @@ public class RunningInstanceConsumer extends BaseNotificationConsumer{
|
|||
GCUBERunningInstance ri= client.execute(query, this.scope).get(0);
|
||||
|
||||
new RunningInstancesHandler(ri.getGHNID()).add(ri);
|
||||
} else if (operation.compareTo("remove")==0){
|
||||
logger.trace("removing a GHN from DB");
|
||||
} else if (operation.compareTo("destroy")==0){
|
||||
logger.trace("removing a RI from DB");
|
||||
new RunningInstancesHandler().drop(id);
|
||||
}
|
||||
|
||||
}catch(Exception e){logger.error("error in notification received",e);}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -228,6 +228,14 @@ public class DBInterface {
|
|||
st.close();
|
||||
}
|
||||
|
||||
public static void deleteElement(String table, String whereClause) throws SQLException{
|
||||
String query="DELETE FROM "+table.toUpperCase()+" WHERE "+whereClause;
|
||||
Connection conn= getConnection();
|
||||
Statement st=conn.createStatement();
|
||||
st.executeUpdate(query);
|
||||
st.close();
|
||||
}
|
||||
|
||||
public static void close() throws SQLException{
|
||||
Connection conn= getConnection();
|
||||
if (conn!=null){
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.gcube.vremanagement.vremodeler.resources.Service;
|
|||
import org.gcube.vremanagement.vremodeler.resources.handlers.CollectionHandler;
|
||||
import org.gcube.vremanagement.vremodeler.resources.handlers.FunctionalityHandler;
|
||||
import org.gcube.vremanagement.vremodeler.resources.handlers.GHNHandler;
|
||||
import org.gcube.vremanagement.vremodeler.resources.handlers.GenericResourceHandler;
|
||||
import org.gcube.vremanagement.vremodeler.resources.handlers.GhnRiRelationHandler;
|
||||
import org.gcube.vremanagement.vremodeler.resources.handlers.MCollectionHandler;
|
||||
import org.gcube.vremanagement.vremodeler.resources.handlers.MetadataFormatHandler;
|
||||
|
@ -56,10 +57,6 @@ public class IStoDBUtil {
|
|||
|
||||
private static GCUBELog logger = new GCUBELog(IStoDBUtil.class);
|
||||
|
||||
private static ISClient queryClient;
|
||||
|
||||
|
||||
|
||||
private static void createTables(GCUBEScope scope) throws GCUBEFault{
|
||||
try{
|
||||
DBInterface.connect();
|
||||
|
@ -87,7 +84,6 @@ public class IStoDBUtil {
|
|||
if (!DBInterface.dbAlreadyCreated())
|
||||
createTables(scope);
|
||||
cleanDB(scope);
|
||||
insertNeededResources(scope);
|
||||
}
|
||||
|
||||
private static void cleanDB(GCUBEScope scope) throws GCUBEFault
|
||||
|
@ -110,7 +106,7 @@ public class IStoDBUtil {
|
|||
DBInterface.deleteAll(RunningInstancesHandler.tableName);
|
||||
DBInterface.deleteAll(GhnRiRelationHandler.tableName);
|
||||
//DBInterface.deleteAll("cs");
|
||||
DBInterface.deleteAll("NEEDEDRESOURCES");
|
||||
DBInterface.deleteAll(GenericResourceHandler.tableName);
|
||||
DBInterface.deleteAll(FunctionalityHandler.portletTableName);
|
||||
DBInterface.deleteAll(FunctionalityHandler.serviceTableName);
|
||||
DBInterface.deleteAll(FunctionalityHandler.functionalityTableName);
|
||||
|
@ -120,6 +116,8 @@ public class IStoDBUtil {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
private static void insertNeededResources(GCUBEScope scope) throws GCUBEFault{
|
||||
List<GCUBEGenericResource> genericResourcesList= null;
|
||||
try{
|
||||
|
@ -149,6 +147,6 @@ public class IStoDBUtil {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -128,13 +128,11 @@ public class ModelFactoryService{
|
|||
*/
|
||||
public void removeVRE(String id) throws GCUBEFault{
|
||||
try{
|
||||
|
||||
ModelerContext pctx= ModelerContext.getPortTypeContext();
|
||||
logger.trace("Deleting resource with id "+id);
|
||||
//destroy the resource;
|
||||
DBInterface.ExecuteUpdate("DELETE FROM VRE where VRE.id='"+id+"';");
|
||||
pctx.getWSHome().remove(pctx.makeKey(id));
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("VDLModel: "+e.getMessage());
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.vremanagement.vremodeler.impl;
|
|||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
|
@ -13,14 +14,15 @@ import org.gcube.common.core.security.GCUBESecurityManager;
|
|||
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
|
||||
|
||||
import org.gcube.vremanagement.vremodeler.consumers.CollectionConsumer;
|
||||
import org.gcube.vremanagement.vremodeler.consumers.FunctionalityConsumer;
|
||||
import org.gcube.vremanagement.vremodeler.consumers.GHNConsumer;
|
||||
import org.gcube.vremanagement.vremodeler.consumers.GenericResourceConsumer;
|
||||
import org.gcube.vremanagement.vremodeler.consumers.MCollectionConsumer;
|
||||
import org.gcube.vremanagement.vremodeler.consumers.RunningInstanceConsumer;
|
||||
import org.gcube.vremanagement.vremodeler.db.IStoDBUtil;
|
||||
import org.gcube.vremanagement.vremodeler.resources.handlers.CollectionHandler;
|
||||
import org.gcube.vremanagement.vremodeler.resources.handlers.FunctionalityHandler;
|
||||
import org.gcube.vremanagement.vremodeler.resources.handlers.GHNHandler;
|
||||
import org.gcube.vremanagement.vremodeler.resources.handlers.GenericResourceHandler;
|
||||
|
||||
public class ServiceContext extends GCUBEServiceContext{
|
||||
|
||||
|
@ -36,6 +38,8 @@ public class ServiceContext extends GCUBEServiceContext{
|
|||
/** {@inheritDoc} */
|
||||
protected String getJNDIName() {return "gcube/vremanagement/vremodeler";}
|
||||
|
||||
private ArrayList<String> secondaryTypeGenericResourceRequired= new ArrayList<String>();
|
||||
|
||||
protected void onReady() throws Exception{
|
||||
try{
|
||||
logger.info("ready event invoked on " + this.getName());
|
||||
|
@ -51,10 +55,12 @@ public class ServiceContext extends GCUBEServiceContext{
|
|||
ISNotifier notifier= GHNContext.getImplementation(ISNotifier.class);
|
||||
for (GCUBEScope scope : ServiceContext.getContext().getInstance().getScopes().values()){
|
||||
ServiceContext.getContext().setScope(scope);
|
||||
|
||||
this.setSecondaryTypeGenericResourceRequired(((String)this.getProperty("GenericResourceToAdd", true)).split(","));
|
||||
|
||||
GCUBESecurityManager secMan= new GCUBESecurityManagerImpl(){
|
||||
@Override
|
||||
public boolean isSecurityEnabled() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}};
|
||||
|
||||
|
@ -63,6 +69,7 @@ public class ServiceContext extends GCUBEServiceContext{
|
|||
new CollectionHandler().initialize();
|
||||
FunctionalityHandler functionalityHandler= new FunctionalityHandler();
|
||||
functionalityHandler.initialize();
|
||||
new GenericResourceHandler().initialize();
|
||||
logger.debug("Service initialized!!");
|
||||
|
||||
//GHNNotification
|
||||
|
@ -83,10 +90,19 @@ public class ServiceContext extends GCUBEServiceContext{
|
|||
notifier.registerToISNotification(qnameList, new MCollectionConsumer(scope), secMan, scope);
|
||||
//FunctionalityResource
|
||||
qnameList= new ArrayList<QName>();
|
||||
qnameList.add(FunctionalityConsumer.functionalityQName);
|
||||
notifier.registerToISNotification(qnameList, new FunctionalityConsumer(scope,functionalityHandler.getFunctionalityResourceId()), secMan, scope);
|
||||
qnameList.add(GenericResourceConsumer.functionalityQName);
|
||||
notifier.registerToISNotification(qnameList, new GenericResourceConsumer(scope,functionalityHandler.getFunctionalityResourceId()), secMan, scope);
|
||||
|
||||
logger.debug("consumers registered");
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<String> getSecondaryTypeGenericResourceRequired() {
|
||||
return secondaryTypeGenericResourceRequired;
|
||||
}
|
||||
|
||||
public void setSecondaryTypeGenericResourceRequired(
|
||||
String[] secondaryTypeGenericResourceRequired) {
|
||||
Collections.addAll(this.secondaryTypeGenericResourceRequired,secondaryTypeGenericResourceRequired);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,9 @@ public class CollectionHandler implements ResourceHandler<GCUBECollection> {
|
|||
|
||||
}
|
||||
|
||||
public void drop(GCUBECollection resource) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
public void drop(String collectionId) throws Exception {
|
||||
DBInterface.connect();
|
||||
DBInterface.deleteElement(tableName, "ID='"+collectionId+"'");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public class FunctionalityHandler implements ResourceHandler<KGCUBEGenericFuncti
|
|||
logger.debug("functionality changed");
|
||||
}
|
||||
|
||||
public void drop(KGCUBEGenericFunctionalityResource resource)
|
||||
public void drop(String resourceId)
|
||||
throws Exception {}
|
||||
|
||||
public void initialize() throws Exception {
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.gcube.common.core.resources.GCUBEHostingNode;
|
|||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.vremanagement.vremodeler.db.DBInterface;
|
||||
import org.gcube.vremanagement.vremodeler.impl.ServiceContext;
|
||||
import org.gcube.vremanagement.vremodeler.resources.GhnRiRelationObject;
|
||||
|
||||
public class GHNHandler implements ResourceHandler<GCUBEHostingNode> {
|
||||
|
||||
|
@ -53,12 +54,11 @@ public class GHNHandler implements ResourceHandler<GCUBEHostingNode> {
|
|||
|
||||
public void add(GCUBEHostingNode resource) throws Exception {
|
||||
this.insert(resource);
|
||||
|
||||
}
|
||||
|
||||
public void drop(GCUBEHostingNode resource) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void drop(String ghnId) throws Exception {
|
||||
DBInterface.connect();
|
||||
DBInterface.deleteElement(tableName, "ID='"+ghnId+"'");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package org.gcube.vremanagement.vremodeler.resources.handlers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.informationsystem.client.ISClient;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericResourceQuery;
|
||||
import org.gcube.common.core.resources.GCUBEGenericResource;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.vremanagement.vremodeler.db.DBInterface;
|
||||
import org.gcube.vremanagement.vremodeler.impl.ServiceContext;
|
||||
|
||||
public class GenericResourceHandler implements ResourceHandler<GCUBEGenericResource> {
|
||||
|
||||
private static GCUBELog logger= new GCUBELog(GenericResourceHandler.class);
|
||||
|
||||
public static final String tableName="NEEDEDRESOURCES";
|
||||
|
||||
public void add(GCUBEGenericResource resource) throws Exception {
|
||||
ArrayList<String> row= new ArrayList<String>(2);
|
||||
row.add(resource.getID());
|
||||
row.add(resource.getType());
|
||||
DBInterface.connect();
|
||||
DBInterface.insertInto(tableName, row.toArray(new String[0]));
|
||||
}
|
||||
|
||||
public void drop(String resourceId) throws Exception {
|
||||
DBInterface.connect();
|
||||
try{
|
||||
DBInterface.deleteElement(tableName, "ID='"+resourceId+"'");
|
||||
}catch(Exception e){logger.warn("the generic resource with id "+resourceId+" is not in the DB");}
|
||||
}
|
||||
|
||||
public void initialize() throws Exception {
|
||||
StringBuilder temp= new StringBuilder();
|
||||
for (String secTypeResource:ServiceContext.getContext().getSecondaryTypeGenericResourceRequired())
|
||||
temp.append(" $result/Profile/SecondaryType/string() eq '"+secTypeResource.trim()+"' or");
|
||||
ISClient queryClient= GHNContext.getImplementation(ISClient.class);
|
||||
temp.delete(temp.length()-2,temp.length());
|
||||
logger.trace(temp);
|
||||
GCUBEGenericResourceQuery query= queryClient.getQuery(GCUBEGenericResourceQuery.class);
|
||||
query.addGenericCondition(temp.toString());
|
||||
List<GCUBEGenericResource> genericResourcesList= queryClient.execute(query, ServiceContext.getContext().getScope());
|
||||
for (GCUBEGenericResource genRes:genericResourcesList)
|
||||
this.add(genRes);
|
||||
}
|
||||
|
||||
}
|
|
@ -17,9 +17,9 @@ public class GhnRiRelationHandler implements ResourceHandler<GhnRiRelationObject
|
|||
DBInterface.insertInto(tableName, row.toArray(new String[0]));
|
||||
}
|
||||
|
||||
public void drop(GhnRiRelationObject resource) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void drop(String riId) throws Exception {
|
||||
DBInterface.connect();
|
||||
DBInterface.deleteElement(tableName, "RIID='"+riId+"'");
|
||||
}
|
||||
|
||||
public void initialize() throws Exception {}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class MCollectionHandler implements ResourceHandler<GCUBEMCollection> {
|
|||
this.insert(resource);
|
||||
}
|
||||
|
||||
public void drop(GCUBEMCollection resource) throws Exception {
|
||||
public void drop(String resourceId) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public class MetadataFormatHandler implements ResourceHandler<MetadataFormat> {
|
|||
}
|
||||
}
|
||||
|
||||
public void drop(MetadataFormat resource) throws Exception {
|
||||
public void drop(String resourceId) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ public class NativeMetadataFormatHandler implements ResourceHandler<MFRelationNa
|
|||
DBInterface.insertIntoListable(tableName, resource);
|
||||
}
|
||||
|
||||
public void drop(MFRelationNative resource) throws Exception {
|
||||
public void drop(String resourceId) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
|
|
|
@ -6,5 +6,5 @@ public interface ResourceHandler<T> {
|
|||
|
||||
public void add(T resource) throws Exception;
|
||||
|
||||
public void drop(T resource) throws Exception;
|
||||
public void drop(String resourceId) throws Exception;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,11 @@ public class RunningInstancesHandler implements ResourceHandler<GCUBERunningInst
|
|||
this.relatedGhn=ghnId;
|
||||
}
|
||||
|
||||
public RunningInstancesHandler() {
|
||||
this.relatedGhn=null;
|
||||
}
|
||||
|
||||
|
||||
public void initialize() throws Exception{
|
||||
//DBInterface.connect();
|
||||
//DBInterface.ExecuteUpdate(creationQuery);
|
||||
|
@ -36,7 +41,8 @@ public class RunningInstancesHandler implements ResourceHandler<GCUBERunningInst
|
|||
insert(ri);
|
||||
}catch(Exception e){logger.error("error insertin values in "+tableName, e);}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void insert(GCUBERunningInstance ri) throws Exception{
|
||||
ArrayList<String> row= new ArrayList<String>(3);
|
||||
|
@ -53,9 +59,10 @@ public class RunningInstancesHandler implements ResourceHandler<GCUBERunningInst
|
|||
|
||||
}
|
||||
|
||||
public void drop(GCUBERunningInstance resource) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void drop(String riId) throws Exception {
|
||||
DBInterface.connect();
|
||||
DBInterface.deleteElement(tableName, "ID='"+riId+"'");
|
||||
new GhnRiRelationHandler().drop(riId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue