ticket 1126

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/VREModeler@8266 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Lucio Lelii 2009-01-12 17:35:50 +00:00
parent b0b57f87c5
commit 6afc48c727
3 changed files with 65 additions and 40 deletions

View File

@ -107,8 +107,10 @@ public class ModelerService {
res=DBInterface.queryDB("select * from VRE where VRE.id='"+ID+"';");
toReturn=XMLUtil.PrepareVREModelXML(res);
} catch (Exception e) {
//logger.error("VDLModel parsing error in function getDLModel "+e.getMessage());
logger.error("VDLModel parsing error in function getDLModel "+e);
e.printStackTrace();
throw new GCUBEFault(e);
}
return toReturn;
}
@ -150,22 +152,25 @@ public class ModelerService {
public void setGHNs(GHNArray request) throws GCUBEFault{
try{
String instanceID=(String) getResource().getId();
DBInterface.ExecuteUpdate("DELETE FROM VRERELATEDGHN WHERE VRERELATEDDHN.vreid='"+instanceID+"';");
DBInterface.ExecuteUpdate("DELETE FROM VRERELATEDGHN WHERE VRERELATEDGHN.vreid='"+instanceID+"';");
String dlKey=instanceID;
ArrayList<List<String>> values= new ArrayList<List<String>>(request.getGHNElement().length);
ArrayList<String> row=null;
for (int i=0; i<request.getGHNElement().length; i++)
for (String ghnId: request.getGHNElement())
{
row= new ArrayList<String>(2);
row.add(dlKey);
row.add(request.getGHNElement()[i]);
row.add(ghnId);
values.add(row);
}
DBInterface.InsertInto("VRERELATEDGHN", values);
}catch(Exception e){throw new GCUBEFault(e);}
}catch(Exception e){
logger.error("error setting GHNs "+e);
e.printStackTrace();
throw new GCUBEFault(e);}
}
@ -487,6 +492,7 @@ public class ModelerService {
Thread deployVREThread= new Thread(new DeployVRE(resourceID));
ServiceContext.getContext().setScope(deployVREThread, ServiceContext.getContext().getScope());
logger.trace("Deploy VRE thread started");
deployVREThread.start();

View File

@ -6,21 +6,24 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
//import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.faults.GCUBEFault;
import org.gcube.common.core.informationsystem.publisher.ISPublisher;
import org.gcube.common.core.resources.GCUBECollection;
import org.gcube.common.core.resources.GCUBEGenericResource;
import org.gcube.common.core.resources.GCUBEMCollection;
import org.gcube.common.core.resources.impl.kxml.KGCUBEResource;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.common.vremanagement.ghnmanager.impl.contexts.ServiceContext;
import org.gcube.metadatamanagement.metadatabrokerlibrary.util.GenericResourceRetriever;
import org.gcube.vremanagement.vremanager.stubs.vremanager.AddResourcesParameters;
import org.gcube.vremanagement.vremanager.stubs.vremanager.OptionsParameters;
import org.gcube.vremanagement.vremanager.stubs.vremanager.ResourceItem;
@ -39,6 +42,8 @@ import org.xml.sax.SAXException;
public class DeployVRE implements Runnable{
private static GCUBELog logger= new GCUBELog(DeployVRE.class);
private ISPublisher publisher;
private String resourceId;
private String vreName=null;
@ -74,7 +79,7 @@ public class DeployVRE implements Runnable{
if (!resRelatedGHN.next()){
DBInterface.ExecuteUpdate("UPDATE VRE SET STATUS='Failed' WHERE VRE.id='"+this.resourceId+"';");
}
firstGHNId= resRelatedGHN.getString("ghnid");
firstGHNId= resRelatedGHN.getString(1);
} catch (SQLException e) {
logger.error("HSQLDB Error "+e);
throw new GCUBEFault(e);
@ -86,24 +91,26 @@ public class DeployVRE implements Runnable{
@Override
protected String makeCall(VREManagerPortType mbportType)
throws Exception {
AddResourcesParameters arp= new AddResourcesParameters();
ServiceList services= new ServiceList();
ServiceItem[] service= new ServiceItem[1];
service[0].setServiceClass("VREManagement");
service[0].setServiceName("VREManager");
service[0].setServiceVersion("1.00.00");
services.setService(service);
services.setGHN(new String[]{this.getParameter().second});
arp.setServices(services);
arp.setTargetScope(ServiceContext.getContext().getScope().toString()+"/"+this.getParameter().first);
String reportId=mbportType.addResources(arp);
String report;
int attempt=0;
do{
this.wait(30000);
report=mbportType.getReport(reportId);
attempt++;
}while (!isDeploymentStatusFinished(report) && attempt<10);
try{
AddResourcesParameters arp= new AddResourcesParameters();
ServiceList services= new ServiceList();
ServiceItem[] service= new ServiceItem[1];
service[0].setServiceClass("VREManagement");
service[0].setServiceName("VREManager");
service[0].setServiceVersion("1.00.00");
services.setService(service);
services.setGHN(new String[]{this.getParameter().second});
arp.setServices(services);
arp.setTargetScope(ServiceContext.getContext().getScope().toString()+"/"+this.getParameter().first);
String reportId=mbportType.addResources(arp);
String report;
int attempt=0;
do{
this.wait(30000);
report=mbportType.getReport(reportId);
attempt++;
}while (!isDeploymentStatusFinished(report) && attempt<10);
}catch(Exception e){e.printStackTrace(); throw e;}
return null;
}
};
@ -113,6 +120,7 @@ public class DeployVRE implements Runnable{
try {
vreManagerHandler.run();
} catch (Exception e) {
logger.error("Error deploying the VRE "+e);
throw new GCUBEFault(e);
}
this.vreName= vreName;
@ -234,11 +242,24 @@ public class DeployVRE implements Runnable{
String reportId=vreManPortType.addResources(arp);
String report;
int attempt=0;
GCUBEGenericResource statusResource=null;
do{
this.wait(30000);
this.wait(20000);
report=vreManPortType.getReport(reportId);
attempt++;
}while (!isDeploymentStatusFinished(report) && attempt<10);
try {
publisher= GHNContext.getImplementation(ISPublisher.class);
if (statusResource==null){
statusResource= GHNContext.getImplementation(GCUBEGenericResource.class);
statusResource.setID(resourceId);
statusResource.setSecondaryType("VREDefinitionStatus");
statusResource.setDescription("VRE Status");
statusResource.setName(vreName);
}
statusResource.setBody(report);
publisher.registerGCUBEResource(statusResource, ServiceContext.getContext().getScope(), ServiceContext.getContext());
}catch(Exception e){logger.error("Error publishing the status");}
}while (!isDeploymentStatusFinished(report) && attempt<20);
return "FINISHED";
}
};

View File

@ -112,9 +112,8 @@ public class XMLUtil {
createTextElement(doc, "Location", res.getString(8)),
createTextElement(doc, "Country", res.getString(9)),
createTextElement(doc, "Domain", res.getString(10))}),
createTextElement(doc, "Libraries", null),
createTextElement(doc, "Selected", relatedGHNs.contains(res.getString("ID")) ? "true" : "false")
})
createTextElement(doc, "Libraries", null)}),
createTextElement(doc, "Selected", relatedGHNs.contains(res.getString("ID")) ? "true" : "false")
});
root.appendChild(ghnEl);
@ -363,12 +362,12 @@ public class XMLUtil {
if (res.next()){
root= addElements(doc, "Resultset", new Element[]{
createTextElement(doc, "Name",res.getString(1)),
createTextElement(doc, "Description",res.getString(2)),
createTextElement(doc, "VREDesigner",res.getString(3)),
createTextElement(doc, "VREManager",res.getString(4)),
createTextElement(doc, "StartTime",res.getString(5)),
createTextElement(doc, "EndTime",res.getString(6)),
createTextElement(doc, "Name",res.getString(2)),
createTextElement(doc, "Description",res.getString(3)),
createTextElement(doc, "VREDesigner",res.getString(4)),
createTextElement(doc, "VREManager",res.getString(5)),
createTextElement(doc, "StartTime",res.getDate(6).getTime()+""),
createTextElement(doc, "EndTime",res.getDate(7).getTime()+""),
});
}else{
@ -427,6 +426,7 @@ public class XMLUtil {
TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer = tf.newTransformer();
serializer.setOutputProperty("encoding", "UTF-8");
StringWriter sw= new StringWriter();
StreamResult sr= new StreamResult(sw);
serializer.transform(domSource, sr);
@ -435,11 +435,9 @@ public class XMLUtil {
logger.error("transformation to String Error");
e.printStackTrace();
}
System.out.println("----------------------------------------------------------------------");
System.out.println(temp);
System.out.println("----------------------------------------------------------------------");
return temp;
}
/**
*
* @param doc the root Document