This commit is contained in:
Lucio Lelii 2008-04-22 14:07:12 +00:00
parent 9c5a324a3e
commit ef79154f75
1 changed files with 20 additions and 105 deletions

View File

@ -1,43 +1,19 @@
package org.gcube.vremanagement.vremodeler.impl;
import java.io.StringReader;
import java.net.URL;
import java.rmi.RemoteException;
import java.sql.ResultSet;
import java.util.ArrayList;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import javax.xml.namespace.QName;
import javax.xml.rpc.server.ServiceLifecycle;
import org.apache.axis.components.uuid.UUIDGen;
import org.apache.axis.components.uuid.UUIDGenFactory;
import org.apache.axis.message.addressing.AttributedURI;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.faults.GCUBEFault;
import org.gcube.common.core.porttypes.GCUBEStartupPortType;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.globus.wsrf.Constants;
import org.globus.wsrf.NoResourceHomeException;
import org.globus.wsrf.ResourceContext;
import org.globus.wsrf.ResourceContextException;
import org.globus.wsrf.ResourceHome;
import org.globus.wsrf.ResourceKey;
import org.globus.wsrf.container.ServiceHost;
import org.gcube.vremanagement.vremodeler.db.DBInterface;
import org.gcube.vremanagement.vremodeler.stubs.GetExistingNamesResponseMessage;
import org.globus.wsrf.encoding.ObjectDeserializer;
import org.globus.wsrf.impl.SimpleResourceKey;
import org.globus.wsrf.tests.basic.CreateResource;
import org.globus.wsrf.tests.basic.CreateResourceResponse;
import org.globus.wsrf.utils.AddressingUtils;
import org.gridforum.jgss.ExtendedGSSCredential;
import org.oasis.wsrf.lifetime.Destroy;
import org.xml.sax.InputSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -70,29 +46,18 @@ public class ModelFactoryService extends GCUBEStartupPortType{
* @return array of string qith exististin dl names
* @throws RemoteException -
*/
public GetExistingNamesResponseMessage getExistingNamesDLs(GetExistingNamesRequestMessage request) throws RemoteException {
GetExistingNamesResponseMessage response=new GetExistingNamesResponseMessage();
public GetExistingNamesResponseMessage getExistingNamesDLs() throws GCUBEFault {
ArrayList<String> toReturn= new ArrayList<String>();
ResultSet res=null;
ExtendedGSSCredential cred;
if (isSecurityEnabled){
try {
cred=credentialsListener.getCredentials(new NAL().getDefaultVO());
if (cred==null) logger.debug("null cerdentials");
logger.debug("VDLModel - initDB - with credential");
} catch (Exception e) {
logger.debug("VDLModel - initDB - null credential");
cred=null;
}
}else cred=null;
try{
DBInterface.connect();
res= DBInterface.queryDB("select DL.name from DL;");
while (res.next()) toReturn.add(res.getString(1));
String customXquery="for $query in collection(\"/db/Profiles/VDL\")//Document/Data/child::*[local-name()='Profile']/DILIGENTResource return <name>$query/Profile/Name/string()</name>";
String queryResult= DISHLSClient.getGeneralQueryManager(cred, factoryEPR).queryDISIC(customXquery,cred, factoryEPR);
logger.debug("VDL get Name QUERY: "+queryResult);
}catch(Exception e) {logger.error("VDL Model: error on DB"); throw new RemoteException("VDLModel: error on DB",e);}
//String customXquery="for $query in collection(\"/db/Profiles/VDL\")//Document/Data/child::*[local-name()='Profile']/DILIGENTResource return <name>$query/Profile/Name/string()</name>";
//String queryResult= DISHLSClient.getGeneralQueryManager(cred, factoryEPR).queryDISIC(customXquery,cred, factoryEPR);
//logger.debug("VDL get Name QUERY: "+queryResult);
}catch(Exception e) {logger.error("VDL Model: error on DB"); throw new GCUBEFault(e);}
GetExistingNamesResponseMessage response = new GetExistingNamesResponseMessage();
response.setNames(toReturn.toArray(new String[0]));
return response;
}
@ -107,23 +72,10 @@ public class ModelFactoryService extends GCUBEStartupPortType{
* @return void
* @throws RemoteException remote exception
*/
public VoidType initDB(VoidType request) throws RemoteException {
public void initDB() throws GCUBEFault {
logger.debug("initDB method");
ExtendedGSSCredential cred;
if (isSecurityEnabled){
try {
cred=credentialsListener.getCredentials(new NAL().getDefaultVO());
if (cred==null) logger.debug("null cerdentials");
logger.debug("VDLModel - initDB - with credential");
} catch (Exception e) {
logger.debug("VDLModel - initDB - null credential");
cred=null;
}
}else cred=null;
new InitThread(factoryEPR, cred).start();
return new VoidType();
//new InitThread(factoryEPR, cred).start();
}
@ -133,49 +85,24 @@ public class ModelFactoryService extends GCUBEStartupPortType{
* @return String
* @throws RemoteException -
*/
public String getAllDLs(GetAllDLsMessageRequest request) throws RemoteException{
public String getAllDLs() throws GCUBEFault{
String toReturn = null;
ResultSet res=null;
try{
DBInterface.connect();
res= DBInterface.queryDB("select DL.name, DL.description, DL.status, DL.epr from DL;");
}catch(Exception e) {logger.error("VDL Model: error on DB"); throw new RemoteException("VDLModel: error on DB",e);}
}catch(Exception e) {logger.error("VDL Model: error on DB"); throw new GCUBEFault(e);}
try {
toReturn=XMLUtil.PrepareAllDLsXML(res);
//toReturn=XMLUtil.PrepareAllDLsXML(res);
} catch (Exception e) {
logger.error("VDLModel parsing error in function getAllDLs "+e.getMessage());
throw new RemoteException("VDLModel parsing error in function getAllDLs",e);
throw new GCUBEFault(e);
}
return toReturn;
}
protected ResourceHome getInstanceResourceHome() throws NoResourceHomeException, ResourceContextException {
ResourceHome home;
ResourceContext ctx;
logger.debug("DILIGENT: getInstanceResourceHome on ModelFactoryService");
ctx = ResourceContext.getResourceContext();
logger.debug("DILIGENT: Resource Context = " + ctx.toString() + "on getInstanceResourceHome on ModelFactoryService");
String homeLoc = Constants.JNDI_SERVICES_BASE_NAME + ctx.getService() + "/instanceHome";
try {
Context initialContext = new InitialContext();
home = (ResourceHome) initialContext.lookup(homeLoc);
} catch (NameNotFoundException e) {
throw new NoResourceHomeException();
} catch (NamingException e) {
throw new ResourceContextException("", e);
}
return home;
}
/**
*
* remove the DL instance
@ -184,10 +111,7 @@ public class ModelFactoryService extends GCUBEStartupPortType{
* @return void
* @throws RemoteException -
*/
public RemoveDLResponseMessage removeDL(String request) throws RemoteException{
ResourceManager rMan;
public void removeDL(String request) throws GCUBEFault{
try{
ResultSet res=DBInterface.queryDB("Select DL.epr from DL where DL.id='"+request+"';");
EndpointReferenceType dlEpr;
@ -199,23 +123,14 @@ public class ModelFactoryService extends GCUBEStartupPortType{
dlEpr = (EndpointReferenceType) ObjectDeserializer.deserialize(inputSource, EndpointReferenceType.class);
}else throw new Exception("DL not retreived in DB");
ModelServiceAddressingLocator msal=new ModelServiceAddressingLocator();
ModelPortType vdlModelPT=msal.getModelPortTypePort(dlEpr);
if (ModelFactoryService.isSecurityEnabled){
ExtendedGSSCredential cred=org.gcube.vremanagement.vremodeler.impl.credentialsListener.getCredentials((new NAL()).getDefaultVO());
rMan= DISIP.getResourceManager(cred,dlEpr);
ConfigureSecurity.setSecurity(((javax.xml.rpc.Stub) vdlModelPT), cred);
}else rMan= DISIP.getResourceManager(null,dlEpr);
rMan.remove(dlEpr);
vdlModelPT.destroy(new Destroy());
//destroy the resource;
DBInterface.ExecuteUpdate("DELETE FROM DL where DL.id='"+request+"';");
}catch(Exception e){
logger.error("VDLModel: "+e.getMessage());
throw new RemoteException(e.getMessage(), e);}
return new RemoveDLResponseMessage();
throw new GCUBEFault( e);
}
}