This commit is contained in:
Lucio Lelii 2009-01-22 18:56:16 +00:00
parent 86dfb0f005
commit 39940b5d73
7 changed files with 163 additions and 16 deletions

View File

@ -439,10 +439,11 @@ public class IStoDBUtil {
List<List<String>> values = new ArrayList<List<String>>(serviceList.size());
List<String> row;
for (GCUBEService service: serviceList ){
row = new ArrayList<String>(3);
row = new ArrayList<String>(4);
row.add(service.getID());
row.add(service.getServiceName());
row.add(service.getServiceClass());
row.add(service.getVersion());
values.add(row);
}

View File

@ -2,7 +2,6 @@ package org.gcube.vremanagement.vremodeler.impl.thread;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
@ -14,7 +13,6 @@ import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.faults.GCUBEFault;
@ -82,9 +80,8 @@ public class DeployVRE extends Thread{
if (!createVRE(GHNList, firstGHNId)){
DBInterface.ExecuteUpdate("UPDATE VRE SET STATUS='"+ModelerService.DEPLOYED+"' WHERE VRE.id='"+this.resourceId+"';");
LayoutCreation lc= new LayoutCreation(this.resourceId, this.vreName);
StringWriter s= new StringWriter();
try {
lc.createAndPublishLayout().store(s);
lc.createAndPublishLayout();
} catch (Exception e) {
throw new Exception("Cannot create and publish the Layout Generic Resource",e);
}
@ -132,7 +129,6 @@ public class DeployVRE extends Thread{
@Override
protected Boolean makeCall(VREManagerPortType mbportType)
throws Exception {
//System.out.println("makeCall called");
String report;
try{
AddResourcesParameters arp= new AddResourcesParameters();
@ -283,12 +279,12 @@ public class DeployVRE extends Thread{
try{
ServiceItem servItem;
List<ServiceItem> listService= new ArrayList<ServiceItem>();
ResultSet resMdColNative =DBInterface.queryDB("select s.name, s.class from VRERELATEDFUNCT AS vrf, SERVICES AS s where vrf.vreid='"+this.getParameter().second+"' AND s.id=vrf.funcid;");
while (resMdColNative.next()){
ResultSet resService =DBInterface.queryDB("select s.name, s.class, s.version from VRERELATEDFUNCT AS vrf, SERVICES AS s where vrf.vreid='"+this.getParameter().second+"' AND s.id=vrf.funcid;");
while (resService.next()){
servItem= new ServiceItem();
servItem.setServiceClass(resMdColNative.getString("class"));
servItem.setServiceName(resMdColNative.getString("name"));
servItem.setServiceVersion("1.00.00");
servItem.setServiceClass(resService.getString("class"));
servItem.setServiceName(resService.getString("name"));
servItem.setServiceVersion(resService.getString("version"));
listService.add(servItem);
}
serviceList.setService(listService.toArray(new ServiceItem[0]));

View File

@ -77,7 +77,6 @@ public class XMLUtil {
@SuppressWarnings("unchecked")
public static String PrepareGHNsXML(ResultSet res, ArrayList<String> relatedGHNs){
Document doc= null;
try {
@ -92,10 +91,13 @@ public class XMLUtil {
try{
while (res.next()){
riRes= DBInterface.queryDB("select RI.id, RI.name from RUNNINGINSTANCE as RI, GHNRELATEDRI as REL where REL.GHNID='"+res.getString("ID")+"' and REL.RIID=RI.ID");
riRes= DBInterface.queryDB("select RI.id, RI.name, RI.class from RUNNINGINSTANCE as RI, GHNRELATEDRI as REL where REL.GHNID='"+res.getString("ID")+"' and REL.RIID=RI.ID");
Element risElement=doc.createElement("RunningInstances");
while (riRes.next()){
Element riElement= createTextElement(doc, "RunningInstances", null, new Couple<String, String>("id", riRes.getString(1)), new Couple<String, String>("name", riRes.getString(2)));
Element riElement=addElements(doc, "RunningInstance", new Element[]{
createTextElement(doc, "Name",riRes.getString(2)),
createTextElement(doc, "Class",riRes.getString(3))
});
risElement.appendChild(riElement);
}
@ -103,6 +105,7 @@ public class XMLUtil {
createTextElement(doc, "ID",res.getString(1)),
createTextElement(doc, "Host",res.getString(2)),
addElements(doc, "Info", new Element[]{
risElement,
createTextElement(doc, "Security", res.getString(3)),
createTextElement(doc, "UpTime", res.getString(4)),
addElements(doc, "Memory", new Element[]{

View File

@ -0,0 +1,131 @@
package org.gcube.vremanagement.vremodeler.portallayout;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.sql.ResultSet;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.informationsystem.client.AtomicCondition;
import org.gcube.common.core.informationsystem.client.ISClient;
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericResourceQuery;
import org.gcube.common.core.informationsystem.publisher.ISPublisher;
import org.gcube.common.core.resources.GCUBEGenericResource;
import org.gcube.vremanagement.vremodeler.db.DBInterface;
import org.gcube.vremanagement.vremodeler.impl.ServiceContext;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class CollectionResourceCreation {
private String vreId;
private String vreName;
public CollectionResourceCreation(String vreId, String vreName){
this.vreId= vreId;
this.vreName= vreName;
}
/**
* create and publish the GenericResource corresponding to the scenario collection
*
* @throws Exception
*/
public void createAndPublish() throws Exception{
GCUBEGenericResource res= GHNContext.getImplementation(GCUBEGenericResource.class);
res.load(new StringReader(this.transformCollectionResource()));
ISPublisher pub= GHNContext.getImplementation(ISPublisher.class);
res.setID("");
pub.registerGCUBEResource(res, ServiceContext.getContext().getScope(), ServiceContext.getContext());
}
private StringBuilder getCollections() throws Exception {
ResultSet rs= DBInterface.queryDB("SELECT c.name FROM COLLECTION c, VRERELATEDCOLLECTION vc WHERE c.id=vc.vreid AND vc.vreid='"+this.vreId+"';");
StringBuilder collectionToMaintain=new StringBuilder();
while (rs.next()){
if (rs.isLast())
collectionToMaintain.append("@name='"+rs.getString(1)+"'");
else collectionToMaintain.append("@name='"+rs.getString(1)+"' or ");
}
return collectionToMaintain;
}
private String transformCollectionResource() throws Exception{
ISClient client= GHNContext.getImplementation(ISClient.class);
GCUBEGenericResourceQuery query= client.getQuery(GCUBEGenericResourceQuery.class);
query.addAtomicConditions(new AtomicCondition("/Resource/Profile/Name","ScenarioCollectionInfo"), new AtomicCondition("/Resource/Profile/Body/DL/@name",ServiceContext.getContext().getScope().toString()));
List<GCUBEGenericResource> list= client.execute(query, ServiceContext.getContext().getScope()) ;
if (list.size()==0) throw new Exception("No GenericResource founded in IS");
StringWriter sw= new StringWriter();
list.get(0).store(sw);
InputStream is=InputSource.class.getResourceAsStream("org/gcube/vremanagement/vremodeler/portallayout/xslt/ScenarioCollectionInfoTransformer.xsl");
StringBuffer out = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = is.read(b)) != -1;) {
out.append(new String(b, 0, n));
}
String xsltCollectionTransformer=out.toString().replace("%%COLLECATIONCOMPARISON%%", this.getCollections()).replace("%%VRENAME%%", ServiceContext.getContext().getScope()+"/"+this.vreName );
return doXSLTrasformation(sw.toString(),xsltCollectionTransformer );
}
private String doXSLTrasformation(String profile, String xsl) {
StreamSource stylesource = new StreamSource(new StringReader(xsl));
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = null;
try {
transformer = tFactory.newTransformer(stylesource);
} catch (TransformerConfigurationException e) {
e.printStackTrace();
return "";
}
Document document = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
return "";
}
StringReader reader = new StringReader(profile);
InputSource inputSource = new InputSource(reader);
try {
document = builder.parse(inputSource);
} catch (SAXException e) {
e.printStackTrace();
return "";
} catch (IOException e) {
e.printStackTrace();
return "";
}
DOMSource source = new DOMSource(document);
ByteArrayOutputStream resultStream = new ByteArrayOutputStream();
StreamResult result = new StreamResult(resultStream);
try {
transformer.transform(source, result);
} catch (TransformerException e) {
e.printStackTrace();
return "";
}
return resultStream.toString();
}
}

View File

@ -5,6 +5,7 @@ import org.w3c.dom.Element;
public class TreeLeaf extends AbstractTree{
@SuppressWarnings("unused")
private String nodeName;
private String portletClass;
public TreeLeaf(String name, String portletClass){

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" >
<xsl:template match="DL" mode="modifyAttributes">
<xsl:attribute name="name">%%VRENAME%%</xsl:attribute>
</xsl:template>
<xsl:template match="*" mode="modifyAttributes"/>
<xsl:template match="collection[not(%%COLLECATIONCOMPARISON%%)]"/>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="." mode="modifyAttributes"/>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

View File

@ -53,7 +53,7 @@ public class ModelerTest {
vreReq.setVREDescription("desc");
vreReq.setVREDesigner("Lucio");
vreReq.setVREManager("Lucio");
vreReq.setVREName("VRETEST");
vreReq.setVREName("testLayoutVRE");
msptp.setVREModel(vreReq);
CollectionArray ca= new CollectionArray();
@ -65,7 +65,7 @@ public class ModelerTest {
msptp.setFunctionality(fida);
GHNArray ghnArray= new GHNArray();
ghnArray.setGHNElement(new String[]{"e0ca7650-e58c-11dd-88eb-b3e5d13cd008","8579e2d0-e58d-11dd-b8e3-9f571c6c1426"});
ghnArray.setGHNElement(new String[]{"4a157200-e875-11dd-ba22-839fe736d16e","eb592ad0-e875-11dd-ae2a-d4505fbcd02a"});
msptp.setGHNs(ghnArray);
System.out.println("-"+msptp.checkStatus(new VOID()).getReports(0)+"-");