git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/VREModeler@5217 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
6c8f513884
commit
20529f2353
|
@ -19,17 +19,22 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
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.ISQuery;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBECSQuery;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBECollectionQuery;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBEGHNQuery;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBEMCollectionQuery;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBERIQuery;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBEServiceQuery;
|
||||
import org.gcube.common.core.resources.GCUBECS;
|
||||
import org.gcube.common.core.resources.GCUBECollection;
|
||||
import org.gcube.common.core.resources.GCUBEHostingNode;
|
||||
import org.gcube.common.core.resources.GCUBEMCollection;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.core.resources.GCUBERunningInstance;
|
||||
import org.gcube.common.core.resources.GCUBEService;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.vremanagement.vremodeler.impl.ModelFactoryService;
|
||||
|
@ -87,21 +92,41 @@ public class IStoDBUtil {
|
|||
DBInterface.deleteAll("mdcollection");
|
||||
DBInterface.deleteAll("collection");
|
||||
DBInterface.deleteAll("relatedserviceid");
|
||||
DBInterface.deleteAll("dhn");
|
||||
DBInterface.deleteAll("ghn");
|
||||
DBInterface.deleteAll("runninginstance");
|
||||
DBInterface.deleteAll("dhnrelatedri");
|
||||
DBInterface.deleteAll("ghnrelatedri");
|
||||
DBInterface.deleteAll("cs");
|
||||
}catch (SQLException e){//logger.error("error cleaning DB");
|
||||
}catch (SQLException e){logger.error("error cleaning sqlDB");
|
||||
e.printStackTrace(); throw new GCUBEFault(e); }
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
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;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param results
|
||||
*/
|
||||
/*
|
||||
private static String[][] parseResults(String results, String tag) throws RemoteException{
|
||||
|
||||
|
@ -152,41 +177,7 @@ public class IStoDBUtil {
|
|||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param epr
|
||||
* @param query
|
||||
* @return
|
||||
* @throws RemoteException
|
||||
*/
|
||||
/*
|
||||
private static List<GCUBEResource> makeQueryDIS(GCUBEScope scope, ISQuery query) throws GCUBEFault{
|
||||
|
||||
try{
|
||||
if (queryClient==null) queryClient= GHNContext.getImplementation(ISClient.class);
|
||||
GCUBEResource
|
||||
|
||||
|
||||
}catch (Exception e ) {logger.error("error querying IS"); throw new GCUBEFault(e);}
|
||||
//GeneralQueryManager q;
|
||||
|
||||
|
||||
String results= null;
|
||||
/*
|
||||
try {
|
||||
DISHLSClient.init();
|
||||
q= DISHLSClient.getGeneralQueryManager(cred, epr);
|
||||
results= q.queryDISIC(query, cred, epr);
|
||||
} catch (Exception e1) {
|
||||
//logger.error("VDL Model Service: error initializing database");
|
||||
throw new RemoteException(e1.getMessage(), e1);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
private static void insertCollection(GCUBEScope scope) throws GCUBEFault {
|
||||
|
||||
List<GCUBECollection> collectionList= null;
|
||||
|
@ -224,31 +215,6 @@ public class IStoDBUtil {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
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;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param epr
|
||||
|
@ -498,6 +464,7 @@ public class IStoDBUtil {
|
|||
|
||||
private static void insertGHN(GCUBEScope scope) throws GCUBEFault {
|
||||
List<GCUBEHostingNode> ghnList= null;
|
||||
List<GCUBERunningInstance> riTotalList= new LinkedList<GCUBERunningInstance>();;
|
||||
try{
|
||||
if (queryClient==null) queryClient= GHNContext.getImplementation(ISClient.class);
|
||||
GCUBEGHNQuery query= queryClient.getQuery(GCUBEGHNQuery.class);
|
||||
|
@ -505,104 +472,114 @@ public class IStoDBUtil {
|
|||
ghnList= queryClient.execute(query, scope);
|
||||
}catch(Exception e ){logger.error("Error queryng IS"); throw new GCUBEFault(e); }
|
||||
|
||||
try{
|
||||
if (ghnList.size()!=0){
|
||||
//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)
|
||||
List<List<String>> values = new LinkedList<List<String>>();
|
||||
List<String> row;
|
||||
for (GCUBEHostingNode ghn: ghnList ){
|
||||
row= new LinkedList<String>();
|
||||
row.add(ghn.getID());
|
||||
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);
|
||||
|
||||
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)
|
||||
List<List<String>> values = new LinkedList<List<String>>();
|
||||
List<String> row;
|
||||
for (GCUBEHostingNode ghn: ghnList ){
|
||||
row= new LinkedList<String>();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
//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){
|
||||
riValues = new LinkedList<List<String>>();
|
||||
List<String> riRow;
|
||||
|
||||
riRelatedGHNvalues = new LinkedList<List<String>>();
|
||||
List<String> riRelatedGHNrow;
|
||||
|
||||
for (GCUBERunningInstance ri :riTotalList){
|
||||
riRow= new LinkedList<String>();
|
||||
riRow.add(ri.getID());
|
||||
riRow.add(ri.getServiceName());
|
||||
riRow.add(ri.getServiceClass());
|
||||
riValues.add(riRow);
|
||||
|
||||
riRelatedGHNrow= new LinkedList<String>();
|
||||
riRelatedGHNrow.add(ri.getGHNID());
|
||||
riRelatedGHNrow.add(ri.getID());
|
||||
riRelatedGHNvalues.add(riRelatedGHNrow);
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
//insert the values in the database
|
||||
DBInterface.connect();
|
||||
DBInterface.InsertInto("ghn", values);
|
||||
}
|
||||
}catch (SQLException e){logger.error("error inserting cs");
|
||||
throw new GCUBEFault(e); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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");
|
||||
|
||||
|
||||
ArrayList<String[]> DNHRelatedRIArray= new ArrayList<String[]>();
|
||||
for (String[] singleDHN:resultsDHNParsed)
|
||||
{
|
||||
String[] riID;
|
||||
|
||||
/*
|
||||
try {
|
||||
riID=DISHLSClient.getRunningInstanceManager(cred,epr).getAllRunningInstancesOnDHN(singleDHN[0], 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);
|
||||
}
|
||||
*/
|
||||
|
||||
//retreiving related RIID with DHNID
|
||||
/*
|
||||
String[] temp;
|
||||
for (String id: riID){
|
||||
temp=new String[2];
|
||||
temp[0]=singleDHN[0];
|
||||
temp[1]=id;
|
||||
DNHRelatedRIArray.add(temp);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
ArrayList<String[]> RIRelatedPKGArray= new ArrayList<String[]>();
|
||||
for (String[] singleRI: resultsRIParsed){
|
||||
DBInterface.InsertInto("runninginstance",riValues );
|
||||
DBInterface.InsertInto("GHNRELATEDRI",riRelatedGHNvalues );
|
||||
}catch (SQLException e){logger.error("error inserting cs");
|
||||
throw new GCUBEFault(e); }
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
try{
|
||||
DBInterface.connect();
|
||||
DBInterface.InsertInto("ghn", resultsDHNParsed, false);
|
||||
DBInterface.InsertInto("runninginstance", resultsRIParsed, false);
|
||||
DBInterface.InsertInto("dhnrelatedri", DNHRelatedRIArray.toArray(new String[0][0]), false);
|
||||
}catch (SQLException e){//logger.error("error DB");
|
||||
e.printStackTrace(); throw new RemoteException(e.getMessage(),e); }
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static void insertServices(GCUBEScope scope) throws GCUBEFault {
|
||||
|
||||
String csQuery= "for $SERVICE in collection(\"/db/Profiles/Service\")//Document/Data/child::*[local-name()='Profile']/DILIGENTResource 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, csQuery);
|
||||
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
|
||||
List<List<String>> values = new LinkedList<List<String>>();
|
||||
List<String> row;
|
||||
for (GCUBEService service: serviceList ){
|
||||
row = new LinkedList<String>();
|
||||
row.add(service.getID());
|
||||
row.add(service.getServiceName());
|
||||
row.add(service.getServiceClass());
|
||||
values.add(row);
|
||||
}
|
||||
|
||||
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); }
|
||||
try{
|
||||
DBInterface.connect();
|
||||
DBInterface.InsertInto("relatedserviceid", values);
|
||||
}catch (SQLException e){//logger.error("error DB");
|
||||
e.printStackTrace(); throw new GCUBEFault(e); }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public static void updateServices(EndpointReferenceType epr, ExtendedGSSCredential cred, String resourceID, int op) throws RemoteException {
|
||||
switch (op){
|
||||
case 0:
|
||||
|
@ -684,18 +661,18 @@ public class IStoDBUtil {
|
|||
//logger.error("VDLModel: Error initializing DB with DHN and RI (Credential error)");
|
||||
throw new RemoteException("Error querying DIS-IP (Credential error)", e);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
//retreiving related RIID with DHNID
|
||||
String[] temp;
|
||||
/*
|
||||
|
||||
for (String id: riID){
|
||||
temp=new String[2];
|
||||
temp[0]=resourceID;
|
||||
temp[1]=id;
|
||||
DNHRelatedRIArray.add(temp);
|
||||
}
|
||||
*/
|
||||
|
||||
try{
|
||||
DBInterface.connect();
|
||||
DBInterface.InsertInto("ghn", resultsDHNParsed, false);
|
||||
|
@ -776,6 +753,6 @@ public class IStoDBUtil {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue