2008-10-21 11:13:46 +02:00
package org.gcube.vremanagement.vremodeler.db ;
import java.rmi.RemoteException ;
import java.sql.SQLException ;
import java.util.ArrayList ;
import java.util.List ;
import org.apache.axis.components.uuid.UUIDGen ;
import org.apache.axis.components.uuid.UUIDGenFactory ;
import org.apache.axis.message.addressing.EndpointReferenceType ;
import org.gcube.common.core.contexts.GHNContext ;
import org.gcube.common.core.faults.GCUBEFault ;
import org.gcube.common.core.informationsystem.client.ISClient ;
2008-10-21 13:08:33 +02:00
import org.gcube.common.core.informationsystem.client.queries.GCUBECSQuery ;
2008-10-21 11:13:46 +02:00
import org.gcube.common.core.informationsystem.client.queries.GCUBECollectionQuery ;
2008-10-21 13:08:33 +02:00
import org.gcube.common.core.informationsystem.client.queries.GCUBEGHNQuery ;
import org.gcube.common.core.informationsystem.client.queries.GCUBEMCollectionQuery ;
2008-10-21 17:26:06 +02:00
import org.gcube.common.core.informationsystem.client.queries.GCUBERIQuery ;
import org.gcube.common.core.informationsystem.client.queries.GCUBEServiceQuery ;
2008-10-21 13:08:33 +02:00
import org.gcube.common.core.resources.GCUBECS ;
2008-10-21 11:13:46 +02:00
import org.gcube.common.core.resources.GCUBECollection ;
2008-10-21 13:08:33 +02:00
import org.gcube.common.core.resources.GCUBEHostingNode ;
import org.gcube.common.core.resources.GCUBEMCollection ;
2008-10-21 17:26:06 +02:00
import org.gcube.common.core.resources.GCUBERunningInstance ;
import org.gcube.common.core.resources.GCUBEService ;
2008-10-21 11:13:46 +02:00
import org.gcube.common.core.scope.GCUBEScope ;
import org.gcube.common.core.utils.logging.GCUBELog ;
2008-10-21 13:08:33 +02:00
/ * *
*
* @author lucio lelii CNR
*
* /
2008-10-21 11:13:46 +02:00
public class IStoDBUtil {
private static UUIDGen uuidMFGEN = UUIDGenFactory . getUUIDGen ( ) ;
private static GCUBELog logger = new GCUBELog ( IStoDBUtil . class . getName ( ) ) ;
private static ISClient queryClient ;
/ * *
2008-10-21 13:08:33 +02:00
* Initialize all database tables
2008-10-21 11:13:46 +02:00
*
2008-10-21 13:08:33 +02:00
* @param GCUBEScope the scope
2008-10-21 11:13:46 +02:00
* /
2008-10-21 13:08:33 +02:00
public static void initDB ( GCUBEScope scope ) throws GCUBEFault {
2008-10-21 11:13:46 +02:00
cleanDB ( ) ;
2008-10-21 13:08:33 +02:00
insertCollection ( scope ) ;
2008-10-21 11:13:46 +02:00
//logger.debug("initialization: collection");
2008-10-21 13:08:33 +02:00
insertMetadataCollection ( scope ) ;
2008-10-21 11:13:46 +02:00
//logger.debug("initialization: metadata");
2008-10-21 13:08:33 +02:00
insertCS ( scope ) ;
2008-10-21 11:13:46 +02:00
//logger.debug("initialization: cs");
2008-10-21 13:08:33 +02:00
insertServices ( scope ) ;
insertGHN ( scope ) ;
2008-10-21 11:13:46 +02:00
//logger.debug("initialization: DHN");
}
2008-10-21 13:08:33 +02:00
private static void cleanDB ( ) throws GCUBEFault
2008-10-21 11:13:46 +02:00
{
try {
DBInterface . connect ( ) ;
2008-10-21 13:08:33 +02:00
DBInterface . deleteAll ( " VRERELATEDCOLLECTION " ) ;
DBInterface . deleteAll ( " VRERELATEDCS " ) ;
DBInterface . deleteAll ( " VRERELATEDMETADATAFORMAT " ) ;
DBInterface . deleteAll ( " VRERELATEDFUNCT " ) ;
DBInterface . deleteAll ( " VRERELATEDDHN " ) ;
DBInterface . deleteAll ( " VRE " ) ;
2008-10-21 11:13:46 +02:00
DBInterface . deleteAll ( " nativemdf " ) ;
DBInterface . deleteAll ( " derivablemdf " ) ;
DBInterface . deleteAll ( " mdformat " ) ;
DBInterface . deleteAll ( " mdcollection " ) ;
DBInterface . deleteAll ( " collection " ) ;
DBInterface . deleteAll ( " relatedserviceid " ) ;
2008-10-21 17:26:06 +02:00
DBInterface . deleteAll ( " ghn " ) ;
2008-10-21 11:13:46 +02:00
DBInterface . deleteAll ( " runninginstance " ) ;
2008-10-21 17:26:06 +02:00
DBInterface . deleteAll ( " ghnrelatedri " ) ;
2008-10-21 11:13:46 +02:00
DBInterface . deleteAll ( " cs " ) ;
2008-10-21 17:26:06 +02:00
} catch ( SQLException e ) { logger . error ( " error cleaning sqlDB " ) ;
2008-10-21 13:08:33 +02:00
e . printStackTrace ( ) ; throw new GCUBEFault ( e ) ; }
2008-10-21 11:13:46 +02:00
}
2008-10-21 17:26:06 +02:00
/ *
private static String [ ] ParseTP ( String [ ] tp ) {
//logger.debug("ParseTP start");
String [ ] schemaNameURI = tp [ 1 ] . split ( " = " ) ;
String lng = " anylanguage " ;
//logger.debug("MetadataFormatParsed: "+schemaNameURI[0]+ ", "+schemaNameURI[1]+", "+lng);
return new String [ ] { tp [ 0 ] , schemaNameURI [ 0 ] , schemaNameURI [ 1 ] , lng } ;
}
private static String ContainsControl ( String [ ] item , ArrayList < String [ ] > container ) {
for ( String [ ] cont : container ) {
//logger.debug("MDFormat: "+cont[1]+" "+cont[2]);
//logger.debug("MDFormat: confr "+cont[1]+" "+cont[2]);
if ( ( cont [ 1 ] . compareTo ( item [ 1 ] ) = = 0 ) & & ( cont [ 2 ] . compareTo ( item [ 2 ] ) = = 0 ) ) //&& ((cont[3].compareTo("anylanguage")==0) || cont[3].compareTo(item[3])==0)
return cont [ 0 ] ;
}
//logger.debug("MDFormat: not yet present");
return null ;
}
* /
2008-10-21 11:13:46 +02:00
/ *
private static String [ ] [ ] parseResults ( String results , String tag ) throws RemoteException {
ArrayList < String [ ] > returnedValues = new ArrayList < String [ ] > ( ) ;
ArrayList < String > tempArray ;
DocumentBuilderFactory factory = DocumentBuilderFactory . newInstance ( ) ;
factory . setNamespaceAware ( true ) ;
DocumentBuilder builder ;
try {
builder = factory . newDocumentBuilder ( ) ;
StringReader reader = new StringReader ( results ) ;
InputSource source = new InputSource ( reader ) ;
Document domDoc ;
domDoc = builder . parse ( source ) ;
Element child , subChild ;
Element root = domDoc . getDocumentElement ( ) ;
NodeList childRoot = root . getElementsByTagName ( tag ) ;
if ( childRoot . getLength ( ) = = 0 ) return null ;
for ( int i = 0 ; i < childRoot . getLength ( ) ; i + + )
{
String textValue = null ;
child = ( Element ) childRoot . item ( i ) ;
NodeList subList = child . getChildNodes ( ) ;
tempArray = new ArrayList < String > ( ) ;
for ( int k = 0 ; k < subList . getLength ( ) ; k + + )
{
if ( ( subList . item ( k ) instanceof Element ) & & ( subList . item ( k ) ! = null ) ) {
//String tmp;
subChild = ( Element ) subList . item ( k ) ;
textValue = subChild . getTextContent ( ) . compareTo ( " " ) = = 0 ? " none " : subChild . getTextContent ( ) ;
tempArray . add ( textValue ) ;
//logger.info("VDLMOdel : child "+tmp);
}
}
returnedValues . add ( tempArray . toArray ( new String [ 0 ] ) ) ;
}
} catch ( Exception e ) {
//logger.error("VDL Model Service: parsing results error");
throw new RemoteException ( e . getMessage ( ) , e ) ;
}
return returnedValues . toArray ( new String [ 0 ] [ 0 ] ) ;
}
* /
private static void insertCollection ( GCUBEScope scope ) throws GCUBEFault {
List < GCUBECollection > collectionList = null ;
try {
if ( queryClient = = null ) queryClient = GHNContext . getImplementation ( ISClient . class ) ;
GCUBECollectionQuery query = queryClient . getQuery ( GCUBECollectionQuery . class ) ;
2008-10-21 13:08:33 +02:00
query . addGenericCondition ( " $result/Profile/IsUserCollection[string(@value) eq 'true'] " ) ;
2008-10-21 11:13:46 +02:00
collectionList = queryClient . execute ( query , scope ) ;
} catch ( Exception e ) { logger . error ( " Error queryng IS " ) ; throw new GCUBEFault ( e ) ; }
try {
if ( collectionList . size ( ) ! = 0 ) {
2008-10-21 13:08:33 +02:00
//preparing collectionList to insert
//table declaration:
//COLLECTION(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR,DESCRIPTION VARCHAR,MEMBERS VARCHAR,CREATION VARCHAR,LASTUPDATE VARCHAR)
2008-10-21 19:09:24 +02:00
List < List < String > > values = new ArrayList < List < String > > ( collectionList . size ( ) ) ;
2008-10-21 13:08:33 +02:00
List < String > row ;
for ( GCUBECollection col : collectionList ) {
2008-10-21 19:09:24 +02:00
row = new ArrayList < String > ( 6 ) ;
2008-10-21 13:08:33 +02:00
row . add ( col . getID ( ) ) ;
row . add ( col . getName ( ) ) ;
row . add ( col . getDescription ( ) ) ;
row . add ( col . getNumberOfMembers ( ) + " " ) ;
row . add ( col . getCreationTime ( ) . getTime ( ) . getTime ( ) + " " ) ;
row . add ( col . getLastUpdateTime ( ) . getTime ( ) . getTime ( ) + " " ) ;
values . add ( row ) ;
}
//insert the values in the database
2008-10-21 11:13:46 +02:00
DBInterface . connect ( ) ;
2008-10-21 13:08:33 +02:00
DBInterface . InsertInto ( " collection " , values ) ;
2008-10-21 11:13:46 +02:00
}
2008-10-21 13:08:33 +02:00
} catch ( SQLException e ) { logger . error ( " VDLModel: DB error " + e . getMessage ( ) ) ;
2008-10-21 11:13:46 +02:00
throw new GCUBEFault ( e ) ; }
}
2008-10-21 13:08:33 +02:00
2008-10-21 11:13:46 +02:00
/ * *
*
* @param epr
* @throws RemoteException
* /
2008-10-21 13:08:33 +02:00
private static void insertMetadataCollection ( GCUBEScope scope ) throws GCUBEFault {
2008-10-21 11:13:46 +02:00
2008-10-21 13:08:33 +02:00
List < GCUBEMCollection > collectionList ;
try {
if ( queryClient = = null ) queryClient = GHNContext . getImplementation ( ISClient . class ) ;
GCUBEMCollectionQuery query = queryClient . getQuery ( GCUBEMCollectionQuery . class ) ;
query . addGenericCondition ( " $result/Profile/IsUserCollection[string(@value) eq 'true'] " ) ;
collectionList = queryClient . execute ( query , scope ) ;
} catch ( Exception e ) { logger . error ( " Error queryng IS " ) ; throw new GCUBEFault ( e ) ; }
try {
if ( collectionList . size ( ) ! = 0 ) {
//preparing collectionList to insert
//table declaration:
//MDCOLLECTION(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR,DESCRIPTION VARCHAR,RELATEDCOLLECTIONID VARCHAR NOT NULL)
2008-10-21 19:09:24 +02:00
List < List < String > > values = new ArrayList < List < String > > ( collectionList . size ( ) ) ;
2008-10-21 13:08:33 +02:00
List < String > row ;
for ( GCUBEMCollection col : collectionList ) {
2008-10-21 19:09:24 +02:00
row = new ArrayList < String > ( 4 ) ;
2008-10-21 13:08:33 +02:00
row . add ( col . getID ( ) ) ;
row . add ( col . getName ( ) ) ;
row . add ( col . getDescription ( ) ) ;
row . add ( col . getRelCollection ( ) . getCollectionID ( ) ) ;
values . add ( row ) ;
}
//insert the values in the database
DBInterface . connect ( ) ;
DBInterface . InsertInto ( " mdcollection " , values ) ;
}
} catch ( SQLException e ) { logger . error ( " VDLModel: DB error " + e . getMessage ( ) ) ;
throw new GCUBEFault ( e ) ; }
/ *
2008-10-21 11:13:46 +02:00
ArrayList < String [ ] > MDFormatArray = new ArrayList < String [ ] > ( ) ;
ArrayList < String [ ] > MDNativeArray = new ArrayList < String [ ] > ( ) ;
ArrayList < String [ ] > MDDerivableArray = new ArrayList < String [ ] > ( ) ;
String [ ] [ ] resultsParsed = parseResults ( results , " r " ) ;
String uuid ;
String metadataFormatQuery ;
String [ ] singleNativeMDF ;
String [ ] singleDerivableMDF ;
/ *
MetadataBrokerPortType metadataBroker = null ;
MetadataBrokerServiceAddressingLocator mbLoc ;
boolean brokerConnected = true ;
//connecting to metadata broker service
try {
RunningInstanceManager ri = DISHLSClient . getRunningInstanceManager ( cred , epr ) ;
String [ ] eprs = ri . getEPRsRIFromClassAndName ( " MetadataManagement " , " MetadataBrokerService " , " diligentproject/metadatamanagement/metadatabrokerservice " , cred , epr ) ;
EndpointReferenceType eprTemp = new EndpointReferenceType ( ) ;
eprTemp . setAddress ( new AttributedURI ( eprs [ 0 ] ) ) ;
//metadata Broker Service connection
mbLoc = new MetadataBrokerServiceAddressingLocator ( ) ;
metadataBroker = mbLoc . getMetadataBrokerPortTypePort ( eprTemp ) ;
if ( ModelFactoryService . isSecurityEnabled ) {
ConfigureSecurity . setSecurity ( ( ( javax . xml . rpc . Stub ) metadataBroker ) , true , cred , GSIConstants . GSI_MODE_FULL_DELEG ) ;
}
} catch ( Exception e ) {
logger . error ( " error contacting metadata broker Service " + e . getMessage ( ) ) ;
//e.printStackTrace();
brokerConnected = false ;
}
2008-10-21 13:08:33 +02:00
2008-10-21 11:13:46 +02:00
for ( String [ ] singleColl : resultsParsed )
{
//generate the uid for MetadataFormat
uuid = uuidMFGEN . nextUUID ( ) ;
String existID ;
//retriving the metadataFormat for the current MDCollection
metadataFormatQuery = " for $MetadataFormat in collection( \" /db/Profiles/MetadataCollection \" )//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where $MetadataFormat/UniqueID/string() eq ' " + singleColl [ 0 ] + " ' return <r><id> " + uuid + " </id><Name>{$MetadataFormat/Profile/MetadataFormat/Name/string()}</Name><SchemaURI>{$MetadataFormat/Profile/MetadataFormat/SchemaURI/string()}</SchemaURI><lng>{$MetadataFormat/Profile/MetadataFormat/Language/string()}</lng></r> " ;
results = makeQueryDIS ( epr , cred , metadataFormatQuery ) ;
String [ ] [ ] resultsMDFParsed = parseResults ( results , " r " ) ;
if ( ( existID = ContainsControl ( resultsMDFParsed [ 0 ] , MDFormatArray ) ) = = null )
{
MDFormatArray . add ( resultsMDFParsed [ 0 ] ) ;
existID = uuid ;
}
//keep the CollectionID and the MDFID to insert into NAtiveMDF
singleNativeMDF = new String [ 3 ] ;
singleNativeMDF [ 0 ] = singleColl [ 0 ] ;
singleNativeMDF [ 1 ] = existID ;
singleNativeMDF [ 2 ] = singleColl [ 3 ] ; //i need it to evaluate doble results
MDNativeArray . add ( singleNativeMDF ) ;
/ *
//Retrive Derivable MDF
if ( brokerConnected ) {
try {
FindPossibleTransformationPrograms request = new FindPossibleTransformationPrograms ( ) ;
TPIOType tpin = TPIOType . fromParams ( " collection " , resultsMDFParsed [ 0 ] [ 3 ] , resultsMDFParsed [ 0 ] [ 1 ] + " = " + resultsMDFParsed [ 0 ] [ 2 ] , " " ) ;
request . setInputFormat ( tpin . toXMLString ( ) ) ;
request . setOutputFormat ( null ) ;
FindPossibleTransformationProgramsResponse response = metadataBroker . findPossibleTransformationPrograms ( request ) ;
String [ ] tp = response . getTransformationProgram ( ) ;
String [ ] parsedTP ;
logger . debug ( " VDLModel Derivable : " + tp . length ) ;
for ( String singleTP : tp ) {
try {
logger . debug ( " MDF Derivable : Single tp is parsing " ) ;
parsedTP = ParseTP ( singleTP ) ;
if ( parsedTP ! = null ) {
String temp ;
//temp will contains the MDF id if it exists
if ( ( temp = ContainsControl ( parsedTP , MDFormatArray ) ) = = null ) {
logger . debug ( " MDF Derivable : not exist " ) ;
// if it doesn't exists, insert it into database else
//add it only on DerivableMDF with MDFuid
uuid = uuidMFGEN . nextUUID ( ) ;
parsedTP [ 0 ] = uuid ;
MDFormatArray . add ( parsedTP ) ;
MDDerivableArray . add ( new String [ ] { singleColl [ 0 ] , uuid , " nothing " } ) ;
} else {
MDDerivableArray . add ( new String [ ] { singleColl [ 0 ] , temp , " nothing " } ) ;
logger . debug ( " MDF Derivable : exist " ) ;
}
}
} catch ( Exception e ) { logger . error ( " error in Derivable MDF parsing " + e . getMessage ( ) ) ; e . printStackTrace ( ) ; }
}
} catch ( Exception e1 ) { logger . error ( " error retreiving metadataBroker " + e1 . getMessage ( ) ) ;
e1 . printStackTrace ( ) ;
}
}
* /
2008-10-21 13:08:33 +02:00
/ *
2008-10-21 11:13:46 +02:00
//trying to parse TransformationProgram from DIS-IC
existID = null ;
String queryDerivableMDF = " " ;
try {
queryDerivableMDF = " for $tp in collection( \" /db/Profiles/TransformationProgram \" )//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where $tp/Profile/TransformationProgram/Input/Type/string() eq 'collection' and $tp/Profile/TransformationProgram/Input/Schema/string() eq ' " + resultsMDFParsed [ 0 ] [ 1 ] + " = " + resultsMDFParsed [ 0 ] [ 2 ] + " ' and $tp/Profile/TransformationProgram/Output/Type/string() eq 'collection' return " +
" <r><id>{$tp/UniqueID/string()}</id><SchemaName>{$tp/Profile/TransformationProgram/Output/Schema/string()}</SchemaName><lng>anylanguage</lng></r> " ;
results = makeQueryDIS ( epr , cred , queryDerivableMDF ) ;
String [ ] [ ] resultsDerivableMDFParsed = parseResults ( results , " r " ) ;
for ( String [ ] singleMDFDerived : resultsDerivableMDFParsed ) {
try {
String tpID = singleMDFDerived [ 0 ] ;
uuid = uuidMFGEN . nextUUID ( ) ;
singleMDFDerived [ 0 ] = uuid ;
String [ ] parsedTP = ParseTP ( singleMDFDerived ) ;
if ( ( existID = ContainsControl ( parsedTP , MDFormatArray ) ) = = null )
{
MDFormatArray . add ( parsedTP ) ;
existID = uuid ;
}
singleDerivableMDF = new String [ 4 ] ;
singleDerivableMDF [ 0 ] = singleColl [ 0 ] ;
singleDerivableMDF [ 1 ] = existID ;
singleDerivableMDF [ 2 ] = tpID ;
singleDerivableMDF [ 3 ] = singleColl [ 3 ] ;
MDDerivableArray . add ( singleDerivableMDF ) ;
} catch ( Exception e1 ) { //logger.error("VDLModel: error parsing derivable");
e1 . printStackTrace ( ) ; }
}
} catch ( Exception e ) { //logger.error("VDLModel: error retriving Derivable MDF for collection "+singleColl[0]);
e . printStackTrace ( ) ; }
}
//da cambiare (scandaloso)
ArrayList < String [ ] > tempRemove = new ArrayList < String [ ] > ( ) ;
for ( String [ ] tempDeriv : MDDerivableArray ) {
for ( String [ ] tempNative : MDNativeArray ) {
if ( tempDeriv [ 3 ] . compareTo ( tempNative [ 2 ] ) = = 0 & & ( tempDeriv [ 1 ] . compareTo ( tempNative [ 1 ] ) = = 0 ) ) {
tempRemove . add ( tempDeriv ) ;
//logger.debug("removed Doubled value");
}
}
}
for ( String [ ] toRemove : tempRemove ) MDDerivableArray . remove ( toRemove ) ;
try {
DBInterface . connect ( ) ;
DBInterface . InsertInto ( " mdcollection " , resultsParsed , false ) ;
DBInterface . InsertInto ( " mdformat " , MDFormatArray . toArray ( new String [ 0 ] [ 0 ] ) , false ) ;
DBInterface . InsertInto ( " nativemdf " , MDNativeArray . toArray ( new String [ 0 ] [ 0 ] ) , true ) ;
DBInterface . InsertInto ( " derivablemdf " , MDDerivableArray . toArray ( new String [ 0 ] [ 0 ] ) , true ) ;
} catch ( SQLException e ) { //logger.error("error DB");
e . printStackTrace ( ) ; throw new RemoteException ( e . getMessage ( ) , e ) ; }
2008-10-21 13:08:33 +02:00
* /
2008-10-21 11:13:46 +02:00
}
/ * *
*
* @param epr
* @throws RemoteException
* /
2008-10-21 13:08:33 +02:00
private static void insertCS ( GCUBEScope scope ) throws GCUBEFault {
List < GCUBECS > csList = null ;
try {
if ( queryClient = = null ) queryClient = GHNContext . getImplementation ( ISClient . class ) ;
GCUBECSQuery query = queryClient . getQuery ( GCUBECSQuery . class ) ;
csList = queryClient . execute ( query , scope ) ;
} catch ( Exception e ) { logger . error ( " Error queryng IS " ) ; throw new GCUBEFault ( e ) ; }
2008-10-21 11:13:46 +02:00
2008-10-21 13:08:33 +02:00
2008-10-21 11:13:46 +02:00
try {
2008-10-21 13:08:33 +02:00
if ( csList . size ( ) ! = 0 ) {
//preparing collectionList to insert
//table declaration:
//TABLE CS(ID VARCHAR NOT NULL PRIMARY KEY, NAME VARCHAR NOT NULL, DESCRIPTION VARCHAR NOT NULL)
2008-10-21 19:09:24 +02:00
List < List < String > > values = new ArrayList < List < String > > ( csList . size ( ) ) ;
2008-10-21 13:08:33 +02:00
List < String > row ;
for ( GCUBECS cs : csList ) {
2008-10-21 19:09:24 +02:00
row = new ArrayList < String > ( 3 ) ;
2008-10-21 13:08:33 +02:00
row . add ( cs . getID ( ) ) ;
row . add ( cs . getProcessName ( ) ) ;
row . add ( cs . getDescription ( ) ) ;
values . add ( row ) ;
}
//insert the values in the database
DBInterface . connect ( ) ;
DBInterface . InsertInto ( " cs " , values ) ;
}
} catch ( SQLException e ) { logger . error ( " error inserting cs " ) ;
throw new GCUBEFault ( e ) ; }
2008-10-21 11:13:46 +02:00
}
private static void insertQuality ( EndpointReferenceType epr ) throws RemoteException {
}
2008-10-21 13:08:33 +02:00
private static void insertGHN ( GCUBEScope scope ) throws GCUBEFault {
List < GCUBEHostingNode > ghnList = null ;
2008-10-21 19:09:24 +02:00
List < GCUBERunningInstance > riTotalList = new ArrayList < GCUBERunningInstance > ( ) ; ;
2008-10-21 13:08:33 +02:00
try {
if ( queryClient = = null ) queryClient = GHNContext . getImplementation ( ISClient . class ) ;
GCUBEGHNQuery query = queryClient . getQuery ( GCUBEGHNQuery . class ) ;
query . addGenericCondition ( " $result/Profile/GHNDescription/Type/string() eq 'Dynamic' " ) ;
ghnList = queryClient . execute ( query , scope ) ;
} catch ( Exception e ) { logger . error ( " Error queryng IS " ) ; throw new GCUBEFault ( e ) ; }
2008-10-21 11:13:46 +02:00
2008-10-21 17:26:06 +02:00
if ( ghnList . size ( ) ! = 0 ) {
List < List < String > > riValues = null ;
List < List < String > > riRelatedGHNvalues = null ;
//preparing collectionList to insert
//table declaration:
//TABLE DHN(ID VARCHAR NOT NULL PRIMARY KEY,HOST VARCHAR,SECURITY VARCHAR,UPTIME VARCHAR,MAINMEMORYVA VARCHAR,MAINMEMORYVS VARCHAR,LOCALAS VARCHAR,LOCATION VARCHAR,COUNTRY VARCHAR,DOMAIN VARCHAR)
2008-10-21 19:09:24 +02:00
List < List < String > > values = new ArrayList < List < String > > ( ghnList . size ( ) ) ;
2008-10-21 17:26:06 +02:00
List < String > row ;
for ( GCUBEHostingNode ghn : ghnList ) {
2008-10-21 19:09:24 +02:00
row = new ArrayList < String > ( 10 ) ;
2008-10-21 17:26:06 +02:00
String id = ghn . getID ( ) ;
row . add ( id ) ;
row . add ( ghn . getNodeDescription ( ) . getName ( ) ) ;
row . add ( ghn . getNodeDescription ( ) . isSecurityEnabled ( ) + " " ) ;
row . add ( ghn . getNodeDescription ( ) . getUptime ( ) ) ;
row . add ( ghn . getNodeDescription ( ) . getMemory ( ) . getVirtualAvailable ( ) + " " ) ;
row . add ( ghn . getNodeDescription ( ) . getMemory ( ) . getVirtualSize ( ) + " " ) ;
row . add ( ghn . getNodeDescription ( ) . getLocalAvailableSpace ( ) + " " ) ;
row . add ( ghn . getSite ( ) . getLocation ( ) ) ;
row . add ( ghn . getSite ( ) . getCountry ( ) ) ;
row . add ( ghn . getSite ( ) . getDomain ( ) ) ;
values . add ( row ) ;
//Retreiving relatedRI to this GHN
List < GCUBERunningInstance > riList = null ;
try {
GCUBERIQuery queryRI = queryClient . getQuery ( GCUBERIQuery . class ) ;
queryRI . addGenericCondition ( " $result/Profile/GHN[string(@UniqueID) eq ' " + id + " '] " ) ;
riList = queryClient . execute ( queryRI , scope ) ;
} catch ( Exception e ) { logger . warn ( " Error retrieving RIs for GHN " + id ) ; }
if ( riList ! = null & riList . size ( ) > 0 )
riTotalList . addAll ( riList ) ;
2008-10-21 11:13:46 +02:00
}
2008-10-21 17:26:06 +02:00
//inserting value for tables RI and RIRelatedGHN
//RUNNINGINSTANCE(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR NOT NULL, CLASS VARCHAR NOT NULL)
//GHNRELATEDRI(DHNID VARCHAR NOT NULL,RIID VARCHAR NOT NULL,PRIMARY KEY(DHNID,RIID))
if ( riTotalList ! = null & riTotalList . size ( ) > 0 ) {
2008-10-21 19:09:24 +02:00
riValues = new ArrayList < List < String > > ( ) ;
2008-10-21 17:26:06 +02:00
List < String > riRow ;
2008-10-21 19:09:24 +02:00
riRelatedGHNvalues = new ArrayList < List < String > > ( riTotalList . size ( ) ) ;
2008-10-21 17:26:06 +02:00
List < String > riRelatedGHNrow ;
for ( GCUBERunningInstance ri : riTotalList ) {
2008-10-21 19:09:24 +02:00
riRow = new ArrayList < String > ( 3 ) ;
2008-10-21 17:26:06 +02:00
riRow . add ( ri . getID ( ) ) ;
riRow . add ( ri . getServiceName ( ) ) ;
riRow . add ( ri . getServiceClass ( ) ) ;
riValues . add ( riRow ) ;
2008-10-21 19:09:24 +02:00
riRelatedGHNrow = new ArrayList < String > ( ) ;
2008-10-21 17:26:06 +02:00
riRelatedGHNrow . add ( ri . getGHNID ( ) ) ;
riRelatedGHNrow . add ( ri . getID ( ) ) ;
riRelatedGHNvalues . add ( riRelatedGHNrow ) ;
}
2008-10-21 11:13:46 +02:00
}
2008-10-21 17:26:06 +02:00
try {
//insert the values in the database
DBInterface . connect ( ) ;
DBInterface . InsertInto ( " ghn " , values ) ;
DBInterface . InsertInto ( " runninginstance " , riValues ) ;
DBInterface . InsertInto ( " GHNRELATEDRI " , riRelatedGHNvalues ) ;
} catch ( SQLException e ) { logger . error ( " error inserting cs " ) ;
throw new GCUBEFault ( e ) ; }
2008-10-21 11:13:46 +02:00
}
}
2008-10-21 13:08:33 +02:00
private static void insertServices ( GCUBEScope scope ) throws GCUBEFault {
2008-10-21 17:26:06 +02:00
List < GCUBEService > serviceList = null ;
try {
if ( queryClient = = null ) queryClient = GHNContext . getImplementation ( ISClient . class ) ;
GCUBEServiceQuery query = queryClient . getQuery ( GCUBEServiceQuery . class ) ;
serviceList = queryClient . execute ( query , scope ) ;
} catch ( Exception e ) { logger . error ( " Error queryng IS " ) ; throw new GCUBEFault ( e ) ; }
if ( serviceList . size ( ) > 0 ) {
//preparing collectionList to insert
//table declaration:
// RELATEDSERVICEID(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR NOT NULL,CLASS VARCHAR NOT NULL)
//this table represent the service available on the IS
2008-10-21 19:09:24 +02:00
List < List < String > > values = new ArrayList < List < String > > ( serviceList . size ( ) ) ;
2008-10-21 17:26:06 +02:00
List < String > row ;
for ( GCUBEService service : serviceList ) {
2008-10-21 19:09:24 +02:00
row = new ArrayList < String > ( 3 ) ;
2008-10-21 17:26:06 +02:00
row . add ( service . getID ( ) ) ;
row . add ( service . getServiceName ( ) ) ;
row . add ( service . getServiceClass ( ) ) ;
values . add ( row ) ;
}
2008-10-21 11:13:46 +02:00
2008-10-21 17:26:06 +02:00
try {
DBInterface . connect ( ) ;
DBInterface . InsertInto ( " relatedserviceid " , values ) ;
} catch ( SQLException e ) { //logger.error("error DB");
e . printStackTrace ( ) ; throw new GCUBEFault ( e ) ; }
}
2008-10-21 11:13:46 +02:00
}
2008-10-21 17:26:06 +02:00
/ *
2008-10-21 11:13:46 +02:00
public static void updateServices ( EndpointReferenceType epr , ExtendedGSSCredential cred , String resourceID , int op ) throws RemoteException {
switch ( op ) {
case 0 :
{
String serviceUpdateQuery = " for $SERVICE in collection( \" /db/Profiles/Service \" )//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where $SERVICE/UniqueID/string() eq ' " + op + " ' return <r><Id>{$SERVICE/UniqueID/string()}</Id><Name>{$SERVICE/Profile/Name/string()}</Name><Class>{$SERVICE/Profile/Class/string()}</Class></r> " ;
String results = makeQueryDIS ( epr , cred , serviceUpdateQuery ) ;
String [ ] [ ] resultsParsed = parseResults ( results , " r " ) ;
try {
DBInterface . connect ( ) ;
DBInterface . InsertInto ( " relatedserviceid " , resultsParsed , false ) ;
} catch ( SQLException e ) { //logger.error("error DB");
e . printStackTrace ( ) ; throw new RemoteException ( e . getMessage ( ) , e ) ; }
break ;
}
case 1 :
{
try {
DBInterface . connect ( ) ;
DBInterface . ExecuteUpdate ( " Delete from relatedserviceid where id=' " + resourceID + " ' " ) ;
} catch ( SQLException e ) { //logger.error("error DB");
e . printStackTrace ( ) ; throw new RemoteException ( e . getMessage ( ) , e ) ; }
break ;
}
}
}
public static void updateCollection ( EndpointReferenceType epr , ExtendedGSSCredential cred , String resourceID , int op ) throws RemoteException {
switch ( op ) {
case 0 :
{
String collectionQuery = " for $CollectionProfile in collection( \" /db/Profiles/Collection \" )//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where $CollectionProfile/Profile/IsUserCollection[string(@value) eq \" true \" ] and $CollectionProfile/UniqueID/string() eq ' " + resourceID + " ' return <r><Id>{$CollectionProfile/UniqueID/string()}</Id><Name>{$CollectionProfile/Profile/Name/string()}</Name><Description>{$CollectionProfile/Profile/Description/string()}</Description><NumberOfMembers>{$CollectionProfile/Profile/NumberOfMembers/string()}</NumberOfMembers><CreationTime>{$CollectionProfile/Profile/CreationTime/string()}</CreationTime><LastUpdateTime>{$CollectionProfile/Profile/LastUpdateTime/string()}</LastUpdateTime></r> " ;
String results = makeQueryDIS ( epr , cred , collectionQuery ) ;
String [ ] [ ] resultsParsed = parseResults ( results , " r " ) ;
try {
DBInterface . connect ( ) ;
DBInterface . InsertInto ( " collection " , resultsParsed , false ) ;
} catch ( SQLException e ) { //logger.error("error updating collection on DB");
e . printStackTrace ( ) ; throw new RemoteException ( e . getMessage ( ) , e ) ; }
break ;
}
case 1 :
{
try {
DBInterface . connect ( ) ;
DBInterface . ExecuteUpdate ( " Delete from collection where id=' " + resourceID + " ' " ) ;
} catch ( SQLException e ) { //logger.error("error updating collection on DB");
e . printStackTrace ( ) ; throw new RemoteException ( e . getMessage ( ) , e ) ; }
break ;
}
}
}
public static void updateDHN ( EndpointReferenceType epr , ExtendedGSSCredential cred , String resourceID , int op ) throws RemoteException {
switch ( op ) {
case 0 :
{
String dhnQuery = " for $DHN in collection( \" /db/Profiles/DHN \" )//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where ($DHN/Profile/DHNDescription/Type/string() eq 'Dynamic' or $DHN/Profile/DHNDescription/Type/string() eq 'SelfCleaning') and $DHN/UniqueID/string() eq ' " + resourceID + " ' return <r><Id>{$DHN/UniqueID/string()}</Id><Name>{$DHN/Profile/DHNDescription/Name/string()}</Name> " +
" <Security>{$DHN/Profile/DHNDescription/SecurityEnabled/string(@value)}</Security><UpTime>{$DHN/Profile/DHNDescription/Uptime/string()}</UpTime><VirtualAvailable>{$DHN/Profile/DHNDescription/MainMemory/string(@VirtualAvailable)}</VirtualAvailable><VirtualSize>{string($DHN/Profile/DHNDescription/MainMemory/string(@VirtualSize))}</VirtualSize> " +
" <LocalAvailableSpace>{$DHN/Profile/DHNDescription/LocalAvailableSpace/string()}</LocalAvailableSpace><Location>{$DHN/Profile/Site/Location/string()}</Location><Country>{$DHN/Profile/Site/Country/string()}</Country><Domain>{$DHN/Profile/Site/Domain/string()}</Domain></r> " ;
String results = makeQueryDIS ( epr , cred , dhnQuery ) ;
String [ ] [ ] resultsDHNParsed = parseResults ( results , " r " ) ;
ArrayList < String [ ] > DNHRelatedRIArray = new ArrayList < String [ ] > ( ) ;
String RIQuery = " for $RI in collection( \" /db/Profiles/RunningInstance \" )//Document/Data/child::*[local-name()='Profile']/DILIGENTResource return <r><id>{$RI/UniqueID/string()}</id><name>{$RI/Profile/ServiceName/string()}</name></r> " ;
results = makeQueryDIS ( epr , cred , RIQuery ) ;
String [ ] [ ] resultsRIParsed = parseResults ( results , " r " ) ;
String [ ] riID ;
/ *
try {
riID = DISHLSClient . getRunningInstanceManager ( cred , epr ) . getAllRunningInstancesOnDHN ( resourceID , cred , epr ) ;
} catch ( DISHLSClientException e ) {
//logger.error("VDLModel: Error initializing DB with DHN and RI (DISHLSClient error)");
throw new RemoteException ( " Error querying DIS-IP (DISHLSClient error) " , e ) ;
} catch ( DISHLSCredentialException e ) {
//logger.error("VDLModel: Error initializing DB with DHN and RI (Credential error)");
throw new RemoteException ( " Error querying DIS-IP (Credential error) " , e ) ;
}
2008-10-21 17:26:06 +02:00
2008-10-21 11:13:46 +02:00
//retreiving related RIID with DHNID
String [ ] temp ;
2008-10-21 17:26:06 +02:00
2008-10-21 11:13:46 +02:00
for ( String id : riID ) {
temp = new String [ 2 ] ;
temp [ 0 ] = resourceID ;
temp [ 1 ] = id ;
DNHRelatedRIArray . add ( temp ) ;
}
2008-10-21 17:26:06 +02:00
2008-10-21 11:13:46 +02:00
try {
DBInterface . connect ( ) ;
2008-10-21 13:08:33 +02:00
DBInterface . InsertInto ( " ghn " , resultsDHNParsed , false ) ;
2008-10-21 11:13:46 +02:00
DBInterface . InsertInto ( " runninginstance " , resultsRIParsed , false ) ;
2008-10-21 13:08:33 +02:00
DBInterface . InsertInto ( " ghnrelatedri " , DNHRelatedRIArray . toArray ( new String [ 0 ] [ 0 ] ) , false ) ;
2008-10-21 11:13:46 +02:00
} catch ( SQLException e ) { //logger.error("error updating DHN on DB");
e . printStackTrace ( ) ; throw new RemoteException ( e . getMessage ( ) , e ) ; }
break ;
}
case 1 :
{
try {
DBInterface . connect ( ) ;
DBInterface . ExecuteUpdate ( " Delete from dhn where id=' " + resourceID + " ' " ) ;
DBInterface . ExecuteUpdate ( " Delete from dhnrelatedri where DHNID=' " + resourceID + " ' " ) ;
} catch ( SQLException e ) { //logger.error("error updating DHN on DB");
e . printStackTrace ( ) ; throw new RemoteException ( e . getMessage ( ) , e ) ; }
break ;
}
}
}
public static void updateCS ( EndpointReferenceType epr , ExtendedGSSCredential cred , String resourceID , int op ) throws RemoteException {
switch ( op ) {
case 0 :
{
String csQuery = " for $CS in collection( \" /db/Profiles/CS \" )//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where $CS/UniqueID/string() eq ' " + resourceID + " ' return <r><Id>{$CS/UniqueID/string()}</Id><Name>{$CS/Profile/ProcessName/string()}</Name><Description>{$CS/Profile/Description/string()}</Description></r> " ;
String results = makeQueryDIS ( epr , cred , csQuery ) ;
String [ ] [ ] resultsParsed = parseResults ( results , " r " ) ;
try {
DBInterface . connect ( ) ;
DBInterface . InsertInto ( " cs " , resultsParsed , false ) ;
} catch ( SQLException e ) { //logger.error("error updating CS on DB");
e . printStackTrace ( ) ; throw new RemoteException ( e . getMessage ( ) , e ) ; }
break ;
}
case 1 :
{
try {
DBInterface . connect ( ) ;
DBInterface . ExecuteUpdate ( " Delete from cs where id=' " + resourceID + " ' " ) ;
} catch ( SQLException e ) { //logger.error("error updating CS on DB");
e . printStackTrace ( ) ; throw new RemoteException ( e . getMessage ( ) , e ) ; }
break ;
}
}
}
public static void updateRI ( EndpointReferenceType epr , ExtendedGSSCredential cred , String resourceID , int op ) throws RemoteException {
switch ( op ) {
case 0 :
{
String RIQuery = " for $RI in collection( \" /db/Profiles/RunningInstance \" )//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where $RI/UniqueID/string() eq ' " + resourceID + " ' return <r><id>{$RI/UniqueID/string()}</id><name>{$RI/Profile/ServiceName/string()}</name></r> " ;
String relatedDHNQuery = " for $RI in collection( \" /db/Profiles/RunningInstance \" )//Document/Data/child::*[local-name()='Profile']/DILIGENTResource where $RI/UniqueID/string() eq ' " + resourceID + " ' return <r><dhnRelated>{$RI/Profile/DHN/string(@UniqueID)}</dhnRelated><id>{$RI/UniqueID/string()}</id></r> " ;
String results = makeQueryDIS ( epr , cred , RIQuery ) ;
String resultsRelatedDhn = makeQueryDIS ( epr , cred , relatedDHNQuery ) ;
String [ ] [ ] resultsRIParsed = parseResults ( results , " r " ) ;
String [ ] [ ] resultRelatedDhn = parseResults ( resultsRelatedDhn , " r " ) ;
try {
DBInterface . connect ( ) ;
DBInterface . InsertInto ( " runninginstance " , resultsRIParsed , false ) ;
DBInterface . InsertInto ( " dhnrelatedri " , resultRelatedDhn , false ) ;
} catch ( SQLException e ) { //logger.error("error updating RI on DB");
e . printStackTrace ( ) ; throw new RemoteException ( e . getMessage ( ) , e ) ; }
break ;
}
case 1 :
{
try {
DBInterface . connect ( ) ;
DBInterface . ExecuteUpdate ( " Delete from runninginstance where id=' " + resourceID + " ' " ) ;
DBInterface . ExecuteUpdate ( " Delete from dhnrelatedri where RIID=' " + resourceID + " ' " ) ;
} catch ( SQLException e ) { //logger.error("error updating RI on DB");
e . printStackTrace ( ) ; throw new RemoteException ( e . getMessage ( ) , e ) ; }
break ;
}
}
}
2008-10-21 17:26:06 +02:00
* /
2008-10-21 11:13:46 +02:00
}