2008-04-22 14:11:53 +02:00
|
|
|
package org.gcube.vremanagement.vremodeler.impl;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.util.ArrayList;
|
2008-04-22 15:04:13 +02:00
|
|
|
import org.apache.axis.components.uuid.UUIDGen;
|
|
|
|
import org.apache.axis.components.uuid.UUIDGenFactory;
|
2008-04-22 14:11:53 +02:00
|
|
|
import org.apache.axis.message.addressing.EndpointReferenceType;
|
2008-04-22 15:04:13 +02:00
|
|
|
import org.gcube.common.core.faults.GCUBEFault;
|
2008-04-22 14:11:53 +02:00
|
|
|
import org.gcube.common.core.porttypes.GCUBEStartupPortType;
|
2008-11-07 18:45:29 +01:00
|
|
|
import org.gcube.common.core.types.VOID;
|
2008-04-22 15:04:13 +02:00
|
|
|
import org.gcube.common.core.utils.logging.GCUBELog;
|
2008-04-22 16:07:12 +02:00
|
|
|
import org.gcube.vremanagement.vremodeler.db.DBInterface;
|
2008-12-10 19:09:38 +01:00
|
|
|
import org.gcube.vremanagement.vremodeler.impl.util.XMLUtil;
|
2008-10-22 19:48:08 +02:00
|
|
|
import org.gcube.vremanagement.vremodeler.stubs.GetExistingNamesResponseMessage;
|
2008-04-22 14:11:53 +02:00
|
|
|
import org.globus.wsrf.tests.basic.CreateResource;
|
2009-01-14 12:11:12 +01:00
|
|
|
|
2008-04-22 14:11:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class ModelFactoryService extends GCUBEStartupPortType{
|
|
|
|
|
2008-11-07 18:45:29 +01:00
|
|
|
private GCUBELog logger = new GCUBELog(ModelFactoryService.class.getName());
|
2008-04-22 15:04:13 +02:00
|
|
|
private static final UUIDGen uuidGen = UUIDGenFactory.getUUIDGen();
|
|
|
|
|
2008-04-22 14:11:53 +02:00
|
|
|
@Override
|
2008-04-22 15:04:13 +02:00
|
|
|
protected ServiceContext getServiceContext() {
|
|
|
|
return ServiceContext.getContext();
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
|
2009-01-14 12:11:12 +01:00
|
|
|
/**
|
|
|
|
* implementation of createResource method
|
|
|
|
* @param request creation request
|
|
|
|
* @return the EndpointReference pointing to the resource
|
|
|
|
* @throws GCUBEFault if something fails
|
|
|
|
*/
|
2008-04-22 15:04:13 +02:00
|
|
|
public EndpointReferenceType createResource(CreateResource request) throws GCUBEFault {
|
|
|
|
String id=uuidGen.nextUUID();
|
2009-01-14 12:11:12 +01:00
|
|
|
logger.trace("resource "+id+" created");
|
2008-04-22 15:04:13 +02:00
|
|
|
ModelerResource mr;
|
|
|
|
try{
|
|
|
|
ModelerContext pctx= ModelerContext.getPortTypeContext();
|
|
|
|
mr=(ModelerResource)pctx.getWSHome().create(pctx.makeKey(id), id);
|
|
|
|
return mr.getEPR();
|
|
|
|
}catch (Exception e){logger.error("error creating resource",e); throw new GCUBEFault(e);}
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-07 18:45:29 +01:00
|
|
|
|
2008-04-22 14:11:53 +02:00
|
|
|
/**
|
|
|
|
* return the existing DL Name
|
|
|
|
*
|
|
|
|
* @param request void
|
2009-01-14 12:11:12 +01:00
|
|
|
* @return array of string with existing VRE names
|
2008-04-22 14:11:53 +02:00
|
|
|
* @throws RemoteException -
|
|
|
|
*/
|
2008-11-07 18:45:29 +01:00
|
|
|
public GetExistingNamesResponseMessage getExistingNamesVREs(VOID arg) throws GCUBEFault {
|
2008-04-22 14:11:53 +02:00
|
|
|
ArrayList<String> toReturn= new ArrayList<String>();
|
|
|
|
ResultSet res=null;
|
|
|
|
try{
|
|
|
|
DBInterface.connect();
|
2008-11-07 18:45:29 +01:00
|
|
|
res= DBInterface.queryDB("select VRE.name from VRE;");
|
|
|
|
while (res.next())
|
|
|
|
toReturn.add(res.getString(1));
|
|
|
|
}catch(Exception e) {logger.error("VRE Model: error on DB"); throw new GCUBEFault(e);}
|
2008-04-22 16:07:12 +02:00
|
|
|
GetExistingNamesResponseMessage response = new GetExistingNamesResponseMessage();
|
2008-04-22 14:11:53 +02:00
|
|
|
response.setNames(toReturn.toArray(new String[0]));
|
2008-11-07 18:45:29 +01:00
|
|
|
|
2008-04-22 14:11:53 +02:00
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the DB
|
|
|
|
*
|
|
|
|
* @param request void
|
|
|
|
* @return void
|
2009-02-13 20:04:00 +01:00
|
|
|
* @throws GCUBEFault thrown if something fails
|
2008-04-22 14:11:53 +02:00
|
|
|
*/
|
2008-11-07 18:45:29 +01:00
|
|
|
public void initDB(VOID arg) throws GCUBEFault {
|
2008-04-22 14:11:53 +02:00
|
|
|
logger.debug("initDB method");
|
2009-02-13 20:04:00 +01:00
|
|
|
|
|
|
|
Thread t= new Thread(){
|
|
|
|
public void run(){
|
|
|
|
try{
|
|
|
|
ServiceContext.getContext().intializeDB();
|
|
|
|
}catch(Exception e){
|
|
|
|
logger.error("DB inizialization failed"+e);
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
t.start();
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param request void
|
|
|
|
* @return String
|
|
|
|
* @throws RemoteException -
|
|
|
|
*/
|
2008-11-07 18:45:29 +01:00
|
|
|
public String getAllVREs(VOID arg) throws GCUBEFault{
|
2008-04-22 14:11:53 +02:00
|
|
|
String toReturn = null;
|
|
|
|
ResultSet res=null;
|
|
|
|
try{
|
|
|
|
DBInterface.connect();
|
2008-11-07 18:45:29 +01:00
|
|
|
res= DBInterface.queryDB("select VRE.name, VRE.description, VRE.status, VRE.epr from VRE;");
|
|
|
|
}catch(Exception e) {logger.error("VREModel: error on DB"); throw new GCUBEFault(e);}
|
2008-04-22 14:11:53 +02:00
|
|
|
try {
|
2008-10-21 19:09:24 +02:00
|
|
|
toReturn=XMLUtil.PrepareAllVREsXML(res);
|
2008-04-22 14:11:53 +02:00
|
|
|
} catch (Exception e) {
|
2008-11-07 18:45:29 +01:00
|
|
|
logger.error("VREModel parsing error in function getAllDLs "+e.getMessage());
|
2008-04-22 16:07:12 +02:00
|
|
|
throw new GCUBEFault(e);
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* remove the DL instance
|
|
|
|
*
|
|
|
|
* @param request the id of DL to remove
|
|
|
|
* @return void
|
|
|
|
* @throws RemoteException -
|
|
|
|
*/
|
2008-10-30 19:54:34 +01:00
|
|
|
public void removeVRE(String request) throws GCUBEFault{
|
2008-04-22 14:11:53 +02:00
|
|
|
try{
|
2009-01-14 12:11:12 +01:00
|
|
|
|
|
|
|
ResultSet res=DBInterface.queryDB("Select VRE.id from VRE where VRE.epr='"+request+"';");
|
|
|
|
String id;
|
2008-04-22 14:11:53 +02:00
|
|
|
if (res.next()){
|
2009-01-14 12:11:12 +01:00
|
|
|
try{
|
|
|
|
id= res.getString(1);
|
|
|
|
}catch(Exception e){logger.error("Error retrieving the VRE on DB "+e); throw e;}
|
2008-10-21 19:09:24 +02:00
|
|
|
}else throw new Exception("VRE not retreived in DB");
|
2008-04-22 14:11:53 +02:00
|
|
|
|
2009-01-14 12:11:12 +01:00
|
|
|
ModelerContext pctx= ModelerContext.getPortTypeContext();
|
|
|
|
ModelerResource mr= (ModelerResource) pctx.getWSHome().find(pctx.makeKey(id));
|
|
|
|
|
|
|
|
logger.trace("Deleting resource with id "+id);
|
|
|
|
System.out.println("Deleting resource "+id);
|
2008-04-22 16:07:12 +02:00
|
|
|
//destroy the resource;
|
2009-01-14 12:11:12 +01:00
|
|
|
DBInterface.ExecuteUpdate("DELETE FROM VRE where VRE.id='"+id+"';");
|
|
|
|
mr.remove();
|
2008-04-22 14:11:53 +02:00
|
|
|
|
|
|
|
}catch(Exception e){
|
|
|
|
logger.error("VDLModel: "+e.getMessage());
|
2009-01-14 12:11:12 +01:00
|
|
|
|
2008-04-22 16:07:12 +02:00
|
|
|
throw new GCUBEFault( e);
|
|
|
|
}
|
|
|
|
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|