2008-04-22 15:55:32 +02:00
package org.gcube.vremanagement.vremodeler.impl ;
2009-02-11 19:31:11 +01:00
import java.net.URI ;
2008-04-22 16:54:47 +02:00
import java.rmi.RemoteException ;
2010-06-04 17:03:10 +02:00
import java.sql.Date ;
2008-04-22 16:54:47 +02:00
import java.sql.ResultSet ;
import java.util.ArrayList ;
import java.util.Hashtable ;
2008-10-21 19:09:24 +02:00
import java.util.List ;
2008-04-22 16:54:47 +02:00
import org.gcube.common.core.faults.GCUBEFault ;
2008-12-18 20:08:50 +01:00
import org.gcube.common.core.faults.GCUBEUnrecoverableFault ;
2008-10-30 19:54:34 +01:00
import org.gcube.common.core.types.VOID ;
2008-10-31 15:26:06 +01:00
import org.gcube.common.core.utils.logging.GCUBELog ;
2008-04-22 16:54:47 +02:00
import org.gcube.vremanagement.vremodeler.db.DBInterface ;
2010-11-03 19:32:06 +01:00
import org.gcube.vremanagement.vremodeler.impl.deploy.DeployVRE ;
2009-02-12 19:17:37 +01:00
import org.gcube.vremanagement.vremodeler.impl.util.ModelerCollection ;
2010-05-13 18:20:41 +02:00
import org.gcube.vremanagement.vremodeler.impl.util.Util ;
2009-09-30 11:29:45 +02:00
import org.gcube.vremanagement.vremodeler.resources.MetadataFormat ;
2008-04-22 16:54:47 +02:00
import org.gcube.vremanagement.vremodeler.stubs.CollectionArray ;
2010-05-13 18:20:41 +02:00
import org.gcube.vremanagement.vremodeler.stubs.CollectionList ;
import org.gcube.vremanagement.vremodeler.stubs.CollectionType ;
2008-04-22 16:54:47 +02:00
import org.gcube.vremanagement.vremodeler.stubs.FunctionalityIDArray ;
2010-05-13 18:20:41 +02:00
import org.gcube.vremanagement.vremodeler.stubs.FunctionalityItem ;
import org.gcube.vremanagement.vremodeler.stubs.FunctionalityList ;
2008-10-21 19:09:24 +02:00
import org.gcube.vremanagement.vremodeler.stubs.GHNArray ;
2010-05-13 18:20:41 +02:00
import org.gcube.vremanagement.vremodeler.stubs.GHNList ;
import org.gcube.vremanagement.vremodeler.stubs.GHNType ;
import org.gcube.vremanagement.vremodeler.stubs.MetadataFormatResponse ;
2008-04-22 16:54:47 +02:00
import org.gcube.vremanagement.vremodeler.stubs.SetMDFormatArgs ;
2010-11-03 19:32:06 +01:00
import org.gcube.vremanagement.vremodeler.stubs.Utils ;
2010-05-13 18:20:41 +02:00
import org.gcube.vremanagement.vremodeler.stubs.VREDescription ;
2010-11-03 19:32:06 +01:00
import org.gcube.vremanagement.vremodeler.stubs.deployreport.State ;
2008-04-22 16:54:47 +02:00
import org.globus.wsrf.ResourceException ;
2010-05-13 18:20:41 +02:00
public class ModelerService {
2008-12-18 20:08:50 +01:00
2010-02-23 18:04:28 +01:00
private static final GCUBELog logger = new GCUBELog ( ModelerService . class ) ;
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
protected ModelerResource getResource ( ) throws ResourceException {
return ( ModelerResource ) ModelerContext . getPortTypeContext ( ) . getWSHome ( ) . find ( ) ;
}
2008-11-13 18:50:41 +01:00
2008-12-18 20:08:50 +01:00
2008-04-22 16:54:47 +02:00
/ * *
*
* @param request void
* @return VoidType
* @throws RemoteException -
*
* /
2010-05-13 18:20:41 +02:00
public void setDescription ( VREDescription request ) throws GCUBEFault {
2010-06-04 17:03:10 +02:00
Date dateFrom = null , dateTo = null ;
2008-04-22 16:54:47 +02:00
ResultSet res = null ;
try {
2008-11-07 18:45:29 +01:00
res = DBInterface . queryDB ( " select * from VRE where VRE.id=' " + getResource ( ) . getId ( ) + " '; " ) ;
2010-06-04 17:03:10 +02:00
dateFrom = new Date ( request . getStartTime ( ) . getTimeInMillis ( ) ) ;
dateTo = new Date ( request . getEndTime ( ) . getTimeInMillis ( ) ) ;
2008-04-22 16:54:47 +02:00
if ( res . next ( ) )
2010-06-04 17:03:10 +02:00
DBInterface . queryDB ( " update VRE set name=' " + request . getName ( ) + " ', description=' " + request . getDescription ( ) + " ', vredesigner=' " + request . getDesigner ( ) + " ', vremanager= ' " + request . getManager ( ) + " ', intervalfrom=' " + dateFrom + " ', intervalto=' " + dateTo + " ' where VRE.id=' " + getResource ( ) . getId ( ) + " '; " ) ;
else {
2010-11-03 19:32:06 +01:00
logger . debug ( " insert into VRE values(' " + getResource ( ) . getId ( ) + " ',' " + request . getName ( ) + " ',' " + request . getDescription ( ) + " ',' " + request . getDesigner ( ) + " ',' " + request . getManager ( ) + " ',' " + dateFrom + " ',' " + dateTo + " ',' " + State . Running + " '); " ) ;
DBInterface . ExecuteUpdate ( " insert into VRE values(' " + getResource ( ) . getId ( ) + " ',' " + request . getName ( ) + " ',' " + request . getDescription ( ) + " ',' " + request . getDesigner ( ) + " ',' " + request . getManager ( ) + " ',' " + dateFrom + " ',' " + dateTo + " ',' " + State . Running + " '); " ) ;
2008-04-22 16:54:47 +02:00
}
} catch ( Exception e ) {
2010-06-04 17:03:10 +02:00
logger . error ( " an error occurs setting the VRE Description " , e ) ;
2008-04-22 16:54:47 +02:00
throw new GCUBEFault ( e ) ;
}
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
}
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
/ * *
*
*
* @param request void
* @return VoidType
* @throws RemoteException -
* /
2010-05-13 18:20:41 +02:00
public VREDescription getDescription ( VOID var ) throws GCUBEFault {
2008-04-22 16:54:47 +02:00
//logger.debug("Request DL with ID "+ID);
try {
DBInterface . connect ( ) ;
2010-05-13 18:20:41 +02:00
return Util . prepareVREDescription ( DBInterface . queryDB ( " select * from VRE where VRE.id=' " + getResource ( ) . getId ( ) + " '; " ) ) ;
2008-04-22 16:54:47 +02:00
} catch ( Exception e ) {
2010-05-13 18:20:41 +02:00
logger . error ( " error getting VRE informations " , e ) ;
2008-04-22 16:54:47 +02:00
throw new GCUBEFault ( e ) ;
}
}
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
/ * *
2010-05-13 18:20:41 +02:00
* return an XML containing the GHN list
2008-04-22 16:54:47 +02:00
*
* @param request void
2010-10-29 19:36:10 +02:00
* @return List of GHNs on the system
* @throws @throws GCUBEFault - if the clud is selected as Architecture or something fails on db
2008-04-22 16:54:47 +02:00
* /
2010-05-13 18:20:41 +02:00
public GHNList getGHNs ( VOID var ) throws GCUBEFault {
logger . trace ( " getGHNs method " ) ;
2008-04-22 16:54:47 +02:00
ResultSet res ;
2008-10-21 19:09:24 +02:00
ArrayList < String > relatedGHN = new ArrayList < String > ( ) ;
2008-04-22 16:54:47 +02:00
try {
DBInterface . connect ( ) ;
2009-02-23 16:08:27 +01:00
res = DBInterface . queryDB ( " select * from GHN ORDER BY GHN.host; " ) ;
2008-11-13 18:50:41 +01:00
2010-02-22 14:17:57 +01:00
ResultSet resRelated = DBInterface . queryDB ( " select ghnid, ISCANDIDATE from VRERELATEDGHN where VRERELATEDGHN.vreid=' " + getResource ( ) . getId ( ) + " '; " ) ;
2010-02-23 18:04:28 +01:00
2010-02-22 14:17:57 +01:00
String candidatedGHN = " " ;
while ( resRelated . next ( ) ) {
2008-10-21 19:09:24 +02:00
relatedGHN . add ( resRelated . getString ( 1 ) ) ;
2010-02-22 14:17:57 +01:00
if ( resRelated . getBoolean ( 2 ) ) candidatedGHN = resRelated . getString ( 1 ) ;
}
2010-05-13 18:20:41 +02:00
return new GHNList ( Util . prepareGHNs ( res , relatedGHN , candidatedGHN ) . toArray ( new GHNType [ 0 ] ) ) ;
2008-10-31 15:26:06 +01:00
} catch ( Exception e ) {
2010-05-13 18:20:41 +02:00
logger . error ( " error retreiving GHNs " , e ) ;
2008-04-22 16:54:47 +02:00
throw new GCUBEFault ( e ) ; }
}
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
/ * *
2010-10-29 19:36:10 +02:00
* Set the GHNs for deploying
2008-04-22 16:54:47 +02:00
*
2010-10-29 19:36:10 +02:00
* @param request array of GHNs ids
2009-01-14 18:30:25 +01:00
* @return VoidType -
2010-10-29 19:36:10 +02:00
* @throws GCUBEFault - if the clud is selected as Architecture or something fails on db
2008-04-22 16:54:47 +02:00
* /
2008-10-21 19:09:24 +02:00
public void setGHNs ( GHNArray request ) throws GCUBEFault {
2010-10-29 19:36:10 +02:00
try {
if ( getResource ( ) . isUseCloud ( ) ) throw new GCUBEFault ( " deploy on cloud is selected, the ghns cannot be set " ) ;
} catch ( ResourceException e1 ) {
throw new GCUBEFault ( e1 ) ;
}
2008-04-22 16:54:47 +02:00
try {
String instanceID = ( String ) getResource ( ) . getId ( ) ;
2009-01-12 18:35:50 +01:00
DBInterface . ExecuteUpdate ( " DELETE FROM VRERELATEDGHN WHERE VRERELATEDGHN.vreid=' " + instanceID + " '; " ) ;
2010-02-22 14:17:57 +01:00
2008-04-22 16:54:47 +02:00
String dlKey = instanceID ;
2008-11-13 18:50:41 +01:00
2009-09-30 11:29:45 +02:00
ArrayList < String [ ] > values = new ArrayList < String [ ] > ( request . getGHNElement ( ) . length ) ;
2008-10-21 19:09:24 +02:00
ArrayList < String > row = null ;
2009-01-12 18:35:50 +01:00
for ( String ghnId : request . getGHNElement ( ) )
2008-04-22 16:54:47 +02:00
{
2010-02-22 14:17:57 +01:00
row = new ArrayList < String > ( 3 ) ;
2008-10-21 19:09:24 +02:00
row . add ( dlKey ) ;
2009-01-12 18:35:50 +01:00
row . add ( ghnId ) ;
2010-06-04 17:03:10 +02:00
if ( request . getCandidateGHN ( ) ! = null & & request . getCandidateGHN ( ) . compareTo ( ghnId ) = = 0 ) row . add ( " true " ) ;
2010-02-22 14:17:57 +01:00
else row . add ( " false " ) ;
values . add ( row . toArray ( new String [ 3 ] ) ) ;
2008-04-22 16:54:47 +02:00
}
2008-11-13 18:50:41 +01:00
2009-09-30 11:29:45 +02:00
DBInterface . insertInto ( " VRERELATEDGHN " , values . toArray ( new String [ 0 ] [ 0 ] ) ) ;
2009-01-12 18:35:50 +01:00
} catch ( Exception e ) {
2009-09-30 15:35:26 +02:00
logger . error ( " error setting GHNs " , e ) ;
2009-01-12 18:35:50 +01:00
throw new GCUBEFault ( e ) ; }
2008-04-22 16:54:47 +02:00
}
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
/ * *
*
2009-01-14 18:30:25 +01:00
* Return an XML with all the collection selectable
2008-04-22 16:54:47 +02:00
*
* @param request void
2009-01-14 18:30:25 +01:00
* @return the collection retrieved from the database
2010-10-29 19:36:10 +02:00
* @throws GCUBEFault -
2008-04-22 16:54:47 +02:00
* /
2010-05-13 18:20:41 +02:00
public CollectionList getCollection ( VOID var ) throws GCUBEFault {
2008-04-22 16:54:47 +02:00
ResultSet res ;
ArrayList < String > relatedCollection = new ArrayList < String > ( ) ;
try {
DBInterface . connect ( ) ;
res = DBInterface . queryDB ( " select * from COLLECTION; " ) ;
2008-11-13 18:50:41 +01:00
2008-12-01 17:52:34 +01:00
2008-12-01 17:10:49 +01:00
ResultSet resRelated = DBInterface . queryDB ( " select collid from VRERELATEDCOLLECTION where VRERELATEDCOLLECTION.vreid=' " + getResource ( ) . getId ( ) + " '; " ) ;
2008-04-22 16:54:47 +02:00
while ( resRelated . next ( ) ) {
relatedCollection . add ( resRelated . getString ( 1 ) ) ;
}
2008-11-13 18:50:41 +01:00
2008-12-01 17:06:16 +01:00
} catch ( Exception e ) {
2009-09-30 15:35:26 +02:00
logger . error ( " error getting collections " , e ) ;
2008-04-22 16:54:47 +02:00
throw new GCUBEFault ( e ) ; }
2008-11-13 18:50:41 +01:00
2008-12-04 02:28:24 +01:00
2010-05-13 18:20:41 +02:00
return new CollectionList ( Util . prepareCollections ( res , relatedCollection ) . toArray ( new CollectionType [ 0 ] ) ) ;
2008-04-22 16:54:47 +02:00
}
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
/ * *
*
* Insert in the DB the selected collection
*
* @param request An Array that contains the selected collections ids
* @return void
2010-10-29 19:36:10 +02:00
* @throws GCUBEFault -
2008-04-22 16:54:47 +02:00
* /
public void setCollection ( CollectionArray request ) throws GCUBEFault {
try {
2008-12-02 17:57:43 +01:00
logger . trace ( " method setCollection Called " ) ;
2008-10-21 19:09:24 +02:00
DBInterface . connect ( ) ;
2008-12-02 18:20:42 +01:00
DBInterface . ExecuteUpdate ( " DELETE FROM VRERELATEDCOLLECTION WHERE VRERELATEDCOLLECTION.vreid=' " + getResource ( ) . getId ( ) + " '; " ) ;
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
String dlKey = ( String ) getResource ( ) . getId ( ) ;
2008-11-13 18:50:41 +01:00
2009-09-30 11:29:45 +02:00
ArrayList < String [ ] > values = new ArrayList < String [ ] > ( request . getCollectionElement ( ) . length ) ;
2008-10-21 19:09:24 +02:00
ArrayList < String > row = null ;
2008-12-02 18:41:58 +01:00
logger . trace ( " the collection set for " + dlKey + " are " + request . getCollectionElement ( ) . length ) ;
2008-04-22 16:54:47 +02:00
for ( int i = 0 ; i < request . getCollectionElement ( ) . length ; i + + )
{
2008-10-21 19:09:24 +02:00
row = new ArrayList < String > ( 2 ) ;
row . add ( dlKey ) ;
row . add ( request . getCollectionElement ( ) [ i ] ) ;
2009-09-30 11:29:45 +02:00
values . add ( row . toArray ( new String [ 2 ] ) ) ;
2008-04-22 16:54:47 +02:00
}
2008-10-21 19:09:24 +02:00
DBInterface . connect ( ) ;
2009-09-30 11:29:45 +02:00
DBInterface . insertInto ( " VRERELATEDCOLLECTION " , values . toArray ( new String [ 0 ] [ 0 ] ) ) ;
2008-12-02 17:57:43 +01:00
} catch ( Exception e ) {
2009-09-30 15:35:26 +02:00
logger . error ( " error setting collection " , e ) ;
2008-12-02 17:57:43 +01:00
throw new GCUBEFault ( e ) ;
}
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
}
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
/ * *
* Return the possibles metadata format for selected collection
*
* @param request void
2010-10-29 19:36:10 +02:00
* @return a list of MetadataFormat
* @throws GCUBEFault -
2008-04-22 16:54:47 +02:00
* /
2010-05-13 18:20:41 +02:00
public MetadataFormatResponse getMetadataRelatedToCollection ( VOID var ) throws GCUBEFault {
2009-02-11 23:55:55 +01:00
2009-02-12 19:17:37 +01:00
Hashtable < ModelerCollection , List < MetadataFormat > > nativeMetadataFormat ;
Hashtable < ModelerCollection , List < MetadataFormat > > selectedMetadataFormat ;
2009-02-11 23:55:55 +01:00
2008-04-22 16:54:47 +02:00
try {
DBInterface . connect ( ) ;
2008-11-13 18:50:41 +01:00
2009-02-11 23:55:55 +01:00
//retrieve all possible metadataformat for the selected collection
2009-02-12 19:17:37 +01:00
nativeMetadataFormat = new Hashtable < ModelerCollection , List < MetadataFormat > > ( ) ;
2009-09-30 15:35:26 +02:00
ResultSet allPossibleMDF = DBInterface . queryDB ( " select rel.collid, mdf.id, mdf.name, mdf.schemauri, mdf.language, coll.name, coll.description from COLLECTION as coll, VRERELATEDCOLLECTION as rel, MCOLLECTION as mcoll, METADATAFORMAT as mdf, NATIVEMDF as native where rel.vreid=' " + getResource ( ) . getId ( ) + " ' and mcoll.relatedcollectionid=rel.collid and mdf.id=native.mdfid and native.mdcollid=mcoll.id and coll.id=rel.collid; " ) ;
2009-02-11 23:55:55 +01:00
while ( allPossibleMDF . next ( ) ) {
2009-02-12 19:17:37 +01:00
ModelerCollection collection = new ModelerCollection ( allPossibleMDF . getString ( 1 ) , allPossibleMDF . getString ( 7 ) , allPossibleMDF . getString ( 6 ) ) ;
2009-02-11 23:55:55 +01:00
MetadataFormat mf = new MetadataFormat ( allPossibleMDF . getString ( 2 ) , allPossibleMDF . getString ( 3 ) , new URI ( allPossibleMDF . getString ( 4 ) ) , allPossibleMDF . getString ( 5 ) ) ;
2009-02-12 19:17:37 +01:00
if ( nativeMetadataFormat . containsKey ( collection ) ) {
2009-02-11 23:55:55 +01:00
nativeMetadataFormat . get ( collection ) . add ( mf ) ;
2009-02-12 19:17:37 +01:00
} else {
2009-02-11 23:55:55 +01:00
ArrayList < MetadataFormat > keyList = new ArrayList < MetadataFormat > ( ) ;
keyList . add ( mf ) ;
nativeMetadataFormat . put ( collection , keyList ) ;
}
2008-04-22 16:54:47 +02:00
}
2009-02-11 23:55:55 +01:00
//retrieving selected metadaformat
//hashtable <collectionId, MetadataFormat>
2009-02-12 19:17:37 +01:00
selectedMetadataFormat = new Hashtable < ModelerCollection , List < MetadataFormat > > ( ) ;
2009-09-30 15:35:26 +02:00
ResultSet selectedFormat = DBInterface . queryDB ( " select rel.collid, mf.id, mf.name, mf.schemauri, mf.language , coll.name, coll.description from COLLECTION as coll, VRERELATEDMETADATAFORMAT as rel, METADATAFORMAT as mf where mf.id=rel.mfid and rel.vreid=' " + getResource ( ) . getId ( ) + " ' and coll.id=rel.collid; " ) ;
2009-02-11 23:55:55 +01:00
while ( selectedFormat . next ( ) ) {
2009-02-12 19:17:37 +01:00
ModelerCollection collection = new ModelerCollection ( selectedFormat . getString ( 1 ) , selectedFormat . getString ( 7 ) , selectedFormat . getString ( 6 ) ) ;
2009-09-30 11:29:45 +02:00
MetadataFormat mf = new MetadataFormat ( selectedFormat . getString ( 2 ) , selectedFormat . getString ( 3 ) , new URI ( selectedFormat . getString ( 4 ) ) , selectedFormat . getString ( 5 ) ) ;
2009-02-11 23:55:55 +01:00
if ( selectedMetadataFormat . containsKey ( collection ) )
selectedMetadataFormat . get ( collection ) . add ( mf ) ;
else {
ArrayList < MetadataFormat > keyList = new ArrayList < MetadataFormat > ( ) ;
keyList . add ( mf ) ;
selectedMetadataFormat . put ( collection , keyList ) ;
}
}
2010-05-13 18:20:41 +02:00
2008-12-02 16:16:55 +01:00
} catch ( Exception e ) {
2010-05-13 18:20:41 +02:00
logger . error ( " getMEtadataRelatedToCollection Error " , e ) ;
2008-04-22 16:54:47 +02:00
throw new GCUBEFault ( e ) ;
}
2008-11-13 18:50:41 +01:00
2010-05-13 18:20:41 +02:00
return Util . prepareMCFormat ( nativeMetadataFormat , selectedMetadataFormat ) ;
2008-04-22 16:54:47 +02:00
}
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
/ * *
*
* Sets selected Metadata Format
*
* @param request
* @return void
2010-10-29 19:36:10 +02:00
* @throws GCUBEFault -
2008-04-22 16:54:47 +02:00
* /
public void setMetadataRelatedToCollection ( SetMDFormatArgs request ) throws GCUBEFault {
try {
2008-11-07 18:45:29 +01:00
DBInterface . ExecuteUpdate ( " DELETE FROM VRERELATEDMETADATAFORMAT WHERE VRERELATEDMETADATAFORMAT.vreid=' " + getResource ( ) . getId ( ) + " '; " ) ;
2008-10-30 19:54:34 +01:00
//String[] singleElement;
2008-04-22 16:54:47 +02:00
String key = ( String ) getResource ( ) . getId ( ) ;
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
//logger.debug(request.getCollectionIDArray().length+" "+request.getMdFormatIDArray().length+" "+request.getCheckedArray().length+" "+request.getCheckedArray(0).getCheckedRowElement().length);
2009-09-30 11:29:45 +02:00
ArrayList < String [ ] > values = new ArrayList < String [ ] > ( request . getCollectionIDArray ( ) . length ) ;
2008-10-21 19:09:24 +02:00
ArrayList < String > row = null ;
2008-04-22 16:54:47 +02:00
for ( int i = 0 ; i < request . getCollectionIDArray ( ) . length ; i + + )
for ( int j = 0 ; j < request . getMdFormatIDArray ( ) . length ; j + + )
{
if ( request . getCheckedArray ( i ) . getCheckedRowElement ( j ) ) {
2008-10-21 19:09:24 +02:00
row = new ArrayList < String > ( 3 ) ;
row . add ( key ) ;
row . add ( request . getCollectionIDArray ( i ) ) ;
row . add ( request . getMdFormatIDArray ( j ) ) ;
2009-09-30 11:29:45 +02:00
values . add ( row . toArray ( new String [ 3 ] ) ) ;
2008-04-22 16:54:47 +02:00
}
}
2008-11-13 18:50:41 +01:00
2009-09-30 11:29:45 +02:00
DBInterface . insertInto ( " VRERELATEDMETADATAFORMAT " , values . toArray ( new String [ 0 ] [ 0 ] ) ) ;
2008-12-04 10:19:56 +01:00
} catch ( Exception e ) {
2009-09-30 15:35:26 +02:00
logger . error ( " setMetadataRelateToCollection failed " , e ) ;
2008-12-04 10:23:43 +01:00
throw new GCUBEFault ( e ) ;
2008-12-04 10:19:56 +01:00
}
2008-04-22 16:54:47 +02:00
}
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
/ * *
* Return an xml with the selectable functionalities
* String
*
* @param request void
* @return an xml String containing selectable functionalities
2010-10-29 19:36:10 +02:00
* @throws GCUBEFault -
2008-04-22 16:54:47 +02:00
* /
2010-05-13 18:20:41 +02:00
public FunctionalityList getFunctionality ( VOID var ) throws GCUBEFault {
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
ResultSet resFunct = null ;
ResultSet selectedFuncRes = null ;
ResultSet selectedCSRes = null ;
ArrayList < Integer > selectedFunctionality = new ArrayList < Integer > ( ) ;
ArrayList < String > selectedCS = new ArrayList < String > ( ) ;
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
try {
DBInterface . connect ( ) ;
resFunct = DBInterface . queryDB ( " select * from functionality where father is null; " ) ;
2008-12-18 20:08:50 +01:00
selectedFuncRes = DBInterface . queryDB ( " select funcid from VRERELATEDFUNCT where vreid=' " + getResource ( ) . getId ( ) + " '; " ) ;
2008-04-22 16:54:47 +02:00
while ( selectedFuncRes . next ( ) )
selectedFunctionality . add ( selectedFuncRes . getInt ( 1 ) ) ;
2008-12-18 20:08:50 +01:00
selectedCSRes = DBInterface . queryDB ( " select csid from VRERELATEDCS where vreid=' " + getResource ( ) . getId ( ) + " '; " ) ;
2008-04-22 16:54:47 +02:00
while ( selectedCSRes . next ( ) )
selectedCS . add ( selectedCSRes . getString ( 1 ) ) ;
} catch ( Exception e ) {
2009-09-30 15:35:26 +02:00
logger . error ( " VDLModel Service: error retrieving functionality " , e ) ;
2008-04-22 16:54:47 +02:00
throw new GCUBEFault ( e ) ;
}
2008-11-13 18:50:41 +01:00
2010-05-13 18:20:41 +02:00
return new FunctionalityList ( Util . prepareFunctionalities ( resFunct , selectedFunctionality , selectedCS ) . toArray ( new FunctionalityItem [ 0 ] ) ) ;
2008-04-22 16:54:47 +02:00
}
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
/ * *
*
*
*
* @return void
2010-10-29 19:36:10 +02:00
* @throws GCUBEFault -
2008-04-22 16:54:47 +02:00
* /
public void setFunctionality ( FunctionalityIDArray request ) throws GCUBEFault {
2009-10-01 17:33:18 +02:00
logger . trace ( " Set Functionality called " ) ;
2008-12-18 20:08:50 +01:00
2008-04-22 16:54:47 +02:00
try {
2008-10-21 19:09:24 +02:00
DBInterface . ExecuteUpdate ( " DELETE FROM VRERELATEDFUNCT WHERE VRERELATEDFUNCT.vreid=' " + getResource ( ) . getId ( ) + " '; " ) ;
DBInterface . ExecuteUpdate ( " DELETE FROM VRERELATEDCS WHERE VRERELATEDCS.vreid=' " + getResource ( ) . getId ( ) + " '; " ) ;
2008-12-18 20:08:50 +01:00
2008-11-13 18:50:41 +01:00
2008-12-18 20:08:50 +01:00
String vreKey = ( String ) getResource ( ) . getId ( ) ;
2008-04-22 16:54:47 +02:00
//logger.debug("KEY: "+dlKey);
2008-12-18 20:08:50 +01:00
2008-04-22 16:54:47 +02:00
if ( request . getFunctionalityIDElement ( ) ! = null ) {
2009-09-30 11:29:45 +02:00
ArrayList < String [ ] > values = new ArrayList < String [ ] > ( request . getFunctionalityIDElement ( ) . length ) ;
2008-10-21 19:09:24 +02:00
ArrayList < String > row = null ;
2008-12-18 20:08:50 +01:00
for ( String funct : request . getFunctionalityIDElement ( ) )
2008-04-22 16:54:47 +02:00
{
2008-10-21 19:09:24 +02:00
row = new ArrayList < String > ( 2 ) ;
2008-12-18 20:08:50 +01:00
row . add ( vreKey ) ;
row . add ( funct ) ;
2009-09-30 11:29:45 +02:00
values . add ( row . toArray ( new String [ 2 ] ) ) ;
2008-04-22 16:54:47 +02:00
}
2008-11-13 18:50:41 +01:00
2009-09-30 11:29:45 +02:00
DBInterface . insertInto ( " VRERELATEDFUNCT " , values . toArray ( new String [ 0 ] [ 0 ] ) ) ;
2009-10-01 17:33:18 +02:00
} else logger . warn ( " requestFunciotnality is null " ) ;
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
if ( request . getCsIDElement ( ) ! = null )
{
2009-09-30 11:29:45 +02:00
ArrayList < String [ ] > values = new ArrayList < String [ ] > ( request . getCsIDElement ( ) . length ) ;
2008-10-21 19:09:24 +02:00
ArrayList < String > row = null ;
2008-11-13 18:50:41 +01:00
2008-12-18 20:08:50 +01:00
for ( String css : request . getCsIDElement ( ) )
2008-04-22 16:54:47 +02:00
{
2008-10-21 19:09:24 +02:00
row = new ArrayList < String > ( 2 ) ;
2008-12-18 20:08:50 +01:00
row . add ( vreKey ) ;
row . add ( css ) ;
2009-09-30 11:29:45 +02:00
values . add ( row . toArray ( new String [ 2 ] ) ) ;
2008-04-22 16:54:47 +02:00
}
2008-11-13 18:50:41 +01:00
2009-09-30 11:29:45 +02:00
DBInterface . insertInto ( " VRERELATEDCS " , values . toArray ( new String [ 0 ] [ 0 ] ) ) ;
2008-04-22 16:54:47 +02:00
}
2008-12-18 20:08:50 +01:00
} catch ( Exception e ) {
2009-09-30 18:50:59 +02:00
logger . error ( " error setting functionality " , e ) ;
2008-12-18 20:08:50 +01:00
throw new GCUBEFault ( e ) ; }
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
}
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
/ * *
* Return an XML with Quality parameter to insert
*
* @param request void
* @return a XML format String
2010-10-29 19:36:10 +02:00
* @throws GCUBEFault -
2008-04-22 16:54:47 +02:00
* /
2008-10-30 19:54:34 +01:00
public String getQuality ( VOID var ) throws GCUBEFault {
2010-05-13 18:20:41 +02:00
return Util . prepareQualityXML ( ) ;
2008-04-22 16:54:47 +02:00
}
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
/ * *
* Sets Quality parameters
*
* @param request
2010-10-29 19:36:10 +02:00
* @throws GCUBEFault -
2008-04-22 16:54:47 +02:00
* /
public void setQuality ( String request ) throws GCUBEFault {
2010-10-29 19:36:10 +02:00
//TODO
2008-04-22 16:54:47 +02:00
}
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
/ * *
*
* set the DL state to Pending
*
* @param request
* @return
2010-10-29 19:36:10 +02:00
* @throws GCUBEFault -
2008-04-22 16:54:47 +02:00
* /
2008-10-30 19:54:34 +01:00
public void setVREtoPendingState ( VOID var ) throws GCUBEFault {
2008-04-22 16:54:47 +02:00
try {
2010-11-03 19:32:06 +01:00
DBInterface . ExecuteUpdate ( " UPDATE VRE SET STATUS=' " + State . Pending + " ' WHERE VRE.id=' " + getResource ( ) . getId ( ) + " '; " ) ;
2008-12-14 20:32:33 +01:00
2008-04-22 16:54:47 +02:00
} catch ( Exception e ) { throw new GCUBEFault ( e ) ; }
}
2008-11-13 18:50:41 +01:00
2008-04-22 16:54:47 +02:00
/ * *
*
* @param request
* @return
2010-10-29 19:36:10 +02:00
* @throws GCUBEFault -
2008-04-22 16:54:47 +02:00
* /
2008-10-30 19:54:34 +01:00
public void deployVRE ( VOID var ) throws GCUBEFault {
2008-12-18 20:08:50 +01:00
String resourceID ;
2010-10-29 19:36:10 +02:00
ModelerResource resource ;
2008-12-18 20:08:50 +01:00
try {
2010-10-29 19:36:10 +02:00
resource = getResource ( ) ;
resourceID = resource . getId ( ) ;
2008-12-18 20:08:50 +01:00
} catch ( ResourceException e ) {
2009-09-30 15:35:26 +02:00
logger . error ( " Error retrieving the Resource Requested " , e ) ; throw new GCUBEUnrecoverableFault ( e ) ;
2008-12-18 20:08:50 +01:00
}
try {
2010-11-03 19:32:06 +01:00
DBInterface . ExecuteUpdate ( " UPDATE VRE SET STATUS=' " + State . Running + " ' WHERE VRE.id=' " + resourceID + " '; " ) ;
2009-10-01 16:59:26 +02:00
} catch ( Exception e ) {
logger . error ( " DB Error " , e ) ;
2008-12-18 20:08:50 +01:00
throw new GCUBEUnrecoverableFault ( e ) ;
}
2010-11-03 19:32:06 +01:00
try {
DeployVRE deployVREThread = new DeployVRE ( resourceID , ServiceContext . getContext ( ) . getScope ( ) ) ;
2010-10-29 19:36:10 +02:00
ServiceContext . getContext ( ) . setScope ( deployVREThread , ServiceContext . getContext ( ) . getScope ( ) ) ;
logger . trace ( " Deploy VRE thread started " ) ;
deployVREThread . start ( ) ;
2010-11-03 19:32:06 +01:00
} catch ( Exception e ) {
throw new GCUBEFault ( e ) ;
2010-10-29 19:36:10 +02:00
}
2008-12-14 20:32:33 +01:00
}
2008-11-13 18:50:41 +01:00
2010-10-29 19:36:10 +02:00
/ * *
*
* @param var
* @return
* @throws Exception
* /
2010-11-03 19:32:06 +01:00
public String checkStatus ( VOID var ) throws Exception {
return Utils . toXML ( getResource ( ) . getDeployReport ( ) ) ;
2009-01-14 12:11:12 +01:00
}
2008-12-18 20:08:50 +01:00
2010-10-29 19:36:10 +02:00
/ * *
*
* @param request
* @return
* @throws RemoteException -
* /
public void undeployVRE ( VOID var ) throws GCUBEFault {
//TODO: implement this method
}
/ * *
*
* @param val boolean
* /
public void setUseCloud ( boolean val ) throws Exception {
getResource ( ) . setUseCloud ( val ) ;
getResource ( ) . store ( ) ;
}
2008-11-13 18:50:41 +01:00
2010-11-08 20:02:22 +01:00
/ * *
*
* @param r VOID
* @return
* @throws Exception
* /
public boolean isUseCloud ( VOID r ) throws Exception {
2010-10-29 19:36:10 +02:00
return getResource ( ) . isUseCloud ( ) ;
}
2010-11-08 20:02:22 +01:00
/ * *
*
* @param numberOfVMs
* @throws Exception
* /
2010-11-03 19:32:06 +01:00
public void setCloudVMs ( int numberOfVMs ) throws Exception {
ModelerResource resource = getResource ( ) ;
if ( ! resource . isUseCloud ( ) ) throw new Exception ( " the number of VMs cannot be set, you are not using cloud deployement " ) ;
resource . setNumberOfVMsForCloud ( numberOfVMs ) ;
resource . store ( ) ;
}
2010-11-08 20:02:22 +01:00
/ * *
*
* @param r VOID
* @return
* @throws Exception
* /
public int getCloudVMs ( VOID r ) throws Exception {
ModelerResource resource = getResource ( ) ;
if ( ! resource . isUseCloud ( ) ) throw new Exception ( " the number of VMs cannot be returned, you are not using cloud deployement " ) ;
return resource . getNumberOfVMsForCloud ( ) ;
}
2008-04-22 15:55:32 +02:00
}