solved a bug in Service initialization
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/VREModeler@15671 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
72e0ca296a
commit
33e8f6fb61
|
@ -8,7 +8,7 @@ import java.sql.DriverManager;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.List;
|
||||
import java.util.Hashtable;
|
||||
import org.gcube.common.core.faults.GCUBEFault;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.vremanagement.vremodeler.impl.ServiceContext;
|
||||
|
@ -21,8 +21,7 @@ import org.gcube.vremanagement.vremodeler.impl.util.Listable;
|
|||
*/
|
||||
public class DBInterface {
|
||||
|
||||
|
||||
private static Connection conn;
|
||||
private static Hashtable< String, Connection> connectionMapping= new Hashtable<String, Connection>();
|
||||
|
||||
private static String dbFile = ServiceContext.getContext().getPersistenceRoot()+ File.separator + "vreModelerDB";
|
||||
|
||||
|
@ -34,14 +33,14 @@ public class DBInterface {
|
|||
*/
|
||||
|
||||
public static boolean dbAlreadyCreated(){
|
||||
File file= new File(dbFile+ServiceContext.getContext().getScope().toString().replace("/", "-")+".script");
|
||||
File file= new File(dbFile+ServiceContext.getContext().getScope().toString().replace("/", "-")+".data");
|
||||
logger.trace("the db "+file.getName()+" exists ?"+ file.exists());
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
public static Connection connect() throws SQLException{
|
||||
|
||||
if(conn==null)
|
||||
if(connectionMapping.get(ServiceContext.getContext().getScope().toString())==null)
|
||||
{
|
||||
// Load the HSQL Database Engine JDBC driver
|
||||
// hsqldb.jar should be in the class path or made part of the current jar
|
||||
|
@ -57,35 +56,36 @@ public class DBInterface {
|
|||
// It can contain directory names relative to the
|
||||
// current working directory
|
||||
|
||||
dbFile=dbFile+ServiceContext.getContext().getScope().toString().replace("/", "-");
|
||||
conn = DriverManager.getConnection("jdbc:hsqldb:file:"
|
||||
+ dbFile, // filenames
|
||||
|
||||
Connection conn = DriverManager.getConnection("jdbc:hsqldb:file:"
|
||||
+ dbFile+ServiceContext.getContext().getScope().toString().replace("/", "-"), // filenames
|
||||
"sa", // username
|
||||
""); // password
|
||||
|
||||
connectionMapping.put(ServiceContext.getContext().getScope().toString(), conn);
|
||||
|
||||
}
|
||||
return conn;
|
||||
return connectionMapping.get(ServiceContext.getContext().getScope().toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static Connection getConnection(){
|
||||
return conn;
|
||||
return connectionMapping.get(ServiceContext.getContext().getScope().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param query
|
||||
*/
|
||||
public static synchronized void ExecuteUpdate(String query) throws GCUBEFault{
|
||||
public static synchronized void ExecuteUpdate(String query) throws Exception{
|
||||
Statement st = null;
|
||||
|
||||
Connection conn= getConnection();
|
||||
try{
|
||||
st = conn.createStatement(); // statement objects can be reused with
|
||||
st.executeUpdate(query);
|
||||
st.close();
|
||||
}catch(SQLException e){//logger.error("error executing Query", e);
|
||||
throw new GCUBEFault(e);}
|
||||
}catch(SQLException e){throw e;}
|
||||
|
||||
}
|
||||
|
||||
|
@ -95,6 +95,8 @@ public class DBInterface {
|
|||
if (values==null) throw new GCUBEFault();
|
||||
Statement st = null;
|
||||
|
||||
Connection conn= getConnection();
|
||||
|
||||
try{
|
||||
st = conn.createStatement(); // statement objects can be reused with
|
||||
}catch(SQLException e){//logger.error("error creating SQL statement");
|
||||
|
@ -146,6 +148,7 @@ public class DBInterface {
|
|||
*/
|
||||
public static synchronized void insertInto(String table, String[]... rows) throws GCUBEFault {
|
||||
|
||||
Connection conn= getConnection();
|
||||
Statement st = null;
|
||||
|
||||
try{
|
||||
|
@ -198,6 +201,7 @@ public class DBInterface {
|
|||
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
Connection conn= getConnection();
|
||||
|
||||
st = conn.createStatement(); // statement objects can be reused with
|
||||
|
||||
|
@ -218,12 +222,14 @@ public class DBInterface {
|
|||
*/
|
||||
public static void deleteAll(String table) throws SQLException{
|
||||
String query="DELETE FROM "+table.toUpperCase();
|
||||
Connection conn= getConnection();
|
||||
Statement st=conn.createStatement();
|
||||
st.executeUpdate(query);
|
||||
st.close();
|
||||
}
|
||||
|
||||
public static void close() throws SQLException{
|
||||
Connection conn= getConnection();
|
||||
if (conn!=null){
|
||||
conn.close();
|
||||
conn=null;
|
||||
|
|
|
@ -71,7 +71,6 @@ public class IStoDBUtil {
|
|||
logger.trace(line);
|
||||
DBInterface.ExecuteUpdate(line);
|
||||
}
|
||||
DBInterface.close();
|
||||
}catch (Exception e){
|
||||
logger.error("error creating tables",e);
|
||||
throw new GCUBEFault(e); }
|
||||
|
@ -115,7 +114,6 @@ public class IStoDBUtil {
|
|||
DBInterface.deleteAll(FunctionalityHandler.portletTableName);
|
||||
DBInterface.deleteAll(FunctionalityHandler.serviceTableName);
|
||||
DBInterface.deleteAll(FunctionalityHandler.functionalityTableName);
|
||||
DBInterface.close();
|
||||
}catch (SQLException e){
|
||||
logger.error("error cleaning sqlDB",e);
|
||||
throw new GCUBEFault(e); }
|
||||
|
@ -145,9 +143,8 @@ public class IStoDBUtil {
|
|||
try{
|
||||
DBInterface.connect();
|
||||
DBInterface.insertInto("NEEDEDRESOURCES", values.toArray(new String[0][0]));
|
||||
DBInterface.close();
|
||||
}catch (SQLException e){
|
||||
logger.error("VDLModel: DB error ",e);
|
||||
logger.error("error inserting Generic resource in the DB ",e);
|
||||
throw new GCUBEFault(e);
|
||||
}
|
||||
|
||||
|
|
|
@ -518,8 +518,8 @@ public class ModelerService {
|
|||
|
||||
try{
|
||||
DBInterface.ExecuteUpdate("UPDATE VRE SET STATUS='"+DEPLOYING+"' WHERE VRE.id='"+resourceID+"';");
|
||||
} catch (GCUBEFault e) {
|
||||
logger.error("HSQLDB Error ",e);
|
||||
} catch (Exception e) {
|
||||
logger.error("DB Error ",e);
|
||||
throw new GCUBEUnrecoverableFault(e);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ public class ServiceContext extends GCUBEServiceContext{
|
|||
logger.info("ready event invoked on " + this.getName());
|
||||
this.intializeDB();
|
||||
}catch (Exception e){
|
||||
logger.error("error initializing VREModeler",e);
|
||||
this.setStatus(Status.FAILED);
|
||||
throw e;
|
||||
}
|
||||
|
@ -48,8 +49,7 @@ public class ServiceContext extends GCUBEServiceContext{
|
|||
|
||||
protected void intializeDB() throws Exception{
|
||||
ISNotifier notifier= GHNContext.getImplementation(ISNotifier.class);
|
||||
for (GCUBEScope scope : ServiceContext.getContext().getStartScopes()){
|
||||
if (scope.isInfrastructure()) continue;
|
||||
for (GCUBEScope scope : ServiceContext.getContext().getInstance().getScopes().values()){
|
||||
ServiceContext.getContext().setScope(scope);
|
||||
GCUBESecurityManager secMan= new GCUBESecurityManagerImpl(){
|
||||
@Override
|
||||
|
|
|
@ -115,7 +115,7 @@ public class DeployVRE extends Thread{
|
|||
}
|
||||
vreName= resGenericInfo.getString(1);
|
||||
|
||||
} catch (SQLException e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("HSQLDB Error "+e);
|
||||
throw new GCUBEFault(e);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.sql.PreparedStatement;
|
|||
import java.sql.Types;
|
||||
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.faults.GCUBEFault;
|
||||
import org.gcube.common.core.informationsystem.client.AtomicCondition;
|
||||
import org.gcube.common.core.informationsystem.client.ISClient;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery;
|
||||
|
@ -65,10 +64,11 @@ public class FunctionalityHandler implements ResourceHandler<KGCUBEGenericFuncti
|
|||
GCUBEGenericQuery genericQuery= queryClient.getQuery(GCUBEGenericQuery.class);
|
||||
genericQuery.setExpression(query.getExpression());
|
||||
resource.load(new StringReader(queryClient.execute(genericQuery, ServiceContext.getContext().getScope()).get(0).toString()));
|
||||
}catch(Exception e ){logger.error("Error queryng IS",e); throw new GCUBEFault(e); }
|
||||
this.functionalityResourceId= resource.getID();
|
||||
this.insert(resource);
|
||||
logger.debug("functionality initialized");
|
||||
}catch(Exception e ){logger.error("Functionality resource not found",e); logger.warn("the service will be initialized without functionalities"); }
|
||||
|
||||
}
|
||||
|
||||
private void insert( KGCUBEGenericFunctionalityResource resource) throws Exception{
|
||||
|
@ -90,6 +90,7 @@ public class FunctionalityHandler implements ResourceHandler<KGCUBEGenericFuncti
|
|||
psFunctionality.setInt(4, rootFunctionalityId);
|
||||
psFunctionality.setInt(5, 0);
|
||||
psFunctionality.execute();
|
||||
logger.trace("FUNCTIONALITY: "+functionality.getName()+" has "+functionality.getServices().size()+" services ");
|
||||
for (Service service: functionality.getServices()){
|
||||
psServices.setInt(1,id);
|
||||
psServices.setString(2, service.getServiceName());
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package org.gcube.vremanagement.vremodeler.resources.kxml;
|
||||
|
||||
import static org.gcube.common.resources.kxml.KGCUBEResource.NS;
|
||||
|
||||
import org.gcube.common.core.resources.service.Dependency;
|
||||
import org.gcube.common.resources.kxml.service.KServiceDependency;
|
||||
import org.gcube.common.resources.kxml.service.version.VersionSpecificationParser;
|
||||
import org.gcube.common.resources.kxml.utils.KStringList;
|
||||
import org.gcube.vremanagement.vremodeler.resources.Functionality;
|
||||
import org.gcube.vremanagement.vremodeler.resources.Service;
|
||||
|
@ -20,7 +16,7 @@ public class KFunctionality {
|
|||
case KXmlParser.START_TAG :
|
||||
if (parser.getName().equals("Name")) d.setName(parser.nextText().trim());
|
||||
if (parser.getName().equals("Description")) d.setDescription(parser.nextText().trim());
|
||||
if (parser.getName().equals("Services")) d.getServices().add(KService.load(parser));
|
||||
if (parser.getName().equals("Service")) d.getServices().add(KService.load(parser));
|
||||
if (parser.getName().equals("Portlets")) d.setPortlets((KStringList.load("Portlets", parser)));
|
||||
break;
|
||||
case KXmlParser.END_TAG:
|
||||
|
|
Loading…
Reference in New Issue