From 39940b5d73f66fdaacd58d19309201db553eb9e4 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Thu, 22 Jan 2009 18:56:16 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/VREModeler@8817 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../vremodeler/db/IStoDBUtil.java | 3 +- .../vremodeler/impl/thread/DeployVRE.java | 16 +-- .../vremodeler/impl/util/XMLUtil.java | 9 +- .../CollectionResourceCreation.java | 131 ++++++++++++++++++ .../portallayout/util/TreeLeaf.java | 1 + .../ScenarioCollectionInfoTransformer.xsl | 15 ++ .../vremodeler/test/ModelerTest.java | 4 +- 7 files changed, 163 insertions(+), 16 deletions(-) create mode 100644 src/org/gcube/vremanagement/vremodeler/portallayout/CollectionResourceCreation.java create mode 100644 src/org/gcube/vremanagement/vremodeler/portallayout/xslt/ScenarioCollectionInfoTransformer.xsl diff --git a/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java b/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java index 0c91057..6f0dd53 100644 --- a/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java +++ b/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java @@ -439,10 +439,11 @@ public class IStoDBUtil { List> values = new ArrayList>(serviceList.size()); List row; for (GCUBEService service: serviceList ){ - row = new ArrayList(3); + row = new ArrayList(4); row.add(service.getID()); row.add(service.getServiceName()); row.add(service.getServiceClass()); + row.add(service.getVersion()); values.add(row); } diff --git a/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java b/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java index 53eaa63..014aece 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java @@ -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 listService= new ArrayList(); - 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])); diff --git a/src/org/gcube/vremanagement/vremodeler/impl/util/XMLUtil.java b/src/org/gcube/vremanagement/vremodeler/impl/util/XMLUtil.java index 4416ead..64345f9 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/util/XMLUtil.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/util/XMLUtil.java @@ -77,7 +77,6 @@ public class XMLUtil { - @SuppressWarnings("unchecked") public static String PrepareGHNsXML(ResultSet res, ArrayList 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("id", riRes.getString(1)), new Couple("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[]{ diff --git a/src/org/gcube/vremanagement/vremodeler/portallayout/CollectionResourceCreation.java b/src/org/gcube/vremanagement/vremodeler/portallayout/CollectionResourceCreation.java new file mode 100644 index 0000000..75a79a3 --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/portallayout/CollectionResourceCreation.java @@ -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 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(); + } + +} diff --git a/src/org/gcube/vremanagement/vremodeler/portallayout/util/TreeLeaf.java b/src/org/gcube/vremanagement/vremodeler/portallayout/util/TreeLeaf.java index f7786fc..e51894b 100644 --- a/src/org/gcube/vremanagement/vremodeler/portallayout/util/TreeLeaf.java +++ b/src/org/gcube/vremanagement/vremodeler/portallayout/util/TreeLeaf.java @@ -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){ diff --git a/src/org/gcube/vremanagement/vremodeler/portallayout/xslt/ScenarioCollectionInfoTransformer.xsl b/src/org/gcube/vremanagement/vremodeler/portallayout/xslt/ScenarioCollectionInfoTransformer.xsl new file mode 100644 index 0000000..f28b0ca --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/portallayout/xslt/ScenarioCollectionInfoTransformer.xsl @@ -0,0 +1,15 @@ + + + + %%VRENAME%% + + + + + + + + + + + \ No newline at end of file diff --git a/src/org/gcube/vremanagement/vremodeler/test/ModelerTest.java b/src/org/gcube/vremanagement/vremodeler/test/ModelerTest.java index d0949ba..24e325f 100644 --- a/src/org/gcube/vremanagement/vremodeler/test/ModelerTest.java +++ b/src/org/gcube/vremanagement/vremodeler/test/ModelerTest.java @@ -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)+"-");