From 18271f631c3bbddae128e99e3eeb2260009765c4 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Thu, 4 Nov 2010 14:56:53 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/VREModeler@31159 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../impl/deploy/DeployGHNsOnCloud.java | 4 +- .../vremodeler/impl/deploy/DeployVRE.java | 39 ++--- .../vremodeler/impl/util/Pair.java | 18 --- .../vremodeler/impl/util/ReportFiller.java | 134 ++++++++++++++++++ .../vremodeler/impl/util/Util.java | 8 +- .../stubs/deployreport/DeployReport.java | 47 +++--- .../stubs/deployreport/Resource.java | 46 ++++++ .../deployreport/ResourceDeployingReport.java | 34 +++++ 8 files changed, 259 insertions(+), 71 deletions(-) delete mode 100644 src/org/gcube/vremanagement/vremodeler/impl/util/Pair.java create mode 100644 src/org/gcube/vremanagement/vremodeler/impl/util/ReportFiller.java create mode 100644 src/org/gcube/vremanagement/vremodeler/stubs/deployreport/Resource.java create mode 100644 src/org/gcube/vremanagement/vremodeler/stubs/deployreport/ResourceDeployingReport.java diff --git a/src/org/gcube/vremanagement/vremodeler/impl/deploy/DeployGHNsOnCloud.java b/src/org/gcube/vremanagement/vremodeler/impl/deploy/DeployGHNsOnCloud.java index 6a58130..ef0ec31 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/deploy/DeployGHNsOnCloud.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/deploy/DeployGHNsOnCloud.java @@ -30,7 +30,7 @@ public class DeployGHNsOnCloud{ this.numberOfVMs = numberOfVMs; this.vreName= vreName; this.report= new GHNonCloudReport(); - this.report.setState(State.Running); + this.report.setState(State.Waiting); } public GHNonCloudReport getReport() { @@ -43,7 +43,7 @@ public class DeployGHNsOnCloud{ * @throws Exception */ public GHNstoUse run() throws Exception{ - + this.report.setState(State.Running); String username = "gcube"; String password = "gcube.cloud.2010"; diff --git a/src/org/gcube/vremanagement/vremodeler/impl/deploy/DeployVRE.java b/src/org/gcube/vremanagement/vremodeler/impl/deploy/DeployVRE.java index 2530c6c..9bfe1ca 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/deploy/DeployVRE.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/deploy/DeployVRE.java @@ -43,13 +43,11 @@ import org.gcube.vremanagement.vremodeler.impl.ModelerContext; import org.gcube.vremanagement.vremodeler.impl.ModelerResource; import org.gcube.vremanagement.vremodeler.impl.ModelerService; import org.gcube.vremanagement.vremodeler.impl.ServiceContext; +import org.gcube.vremanagement.vremodeler.impl.util.ReportFiller; import org.gcube.vremanagement.vremodeler.impl.util.ResourceManagerServiceHandler; import org.gcube.vremanagement.vremodeler.portallayout.CollectionResourceCreation; import org.gcube.vremanagement.vremodeler.portallayout.GenericResourcePortlet; import org.gcube.vremanagement.vremodeler.stubs.deployreport.DeployReport; -import org.gcube.vremanagement.vremodeler.stubs.deployreport.FunctionalityDeployingReport; -import org.gcube.vremanagement.vremodeler.stubs.deployreport.FunctionalityReport; -import org.gcube.vremanagement.vremodeler.stubs.deployreport.ServiceReport; import org.globus.wsrf.ResourceException; import org.w3c.dom.Document; import org.w3c.dom.NodeList; @@ -93,7 +91,9 @@ public class DeployVRE extends Thread{ */ public void run(){ try { + //reports initialization getResource().getDeployReport().setState(org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Running); + getResource().store(); GHNstoUse ghnsToUse=null; if (getResource().isUseCloud()){ @@ -229,9 +229,12 @@ public class DeployVRE extends Thread{ @SuppressWarnings("static-access") private boolean createVRE(List ghnList) throws Exception{ - ResourceManagerPortType rmPortType=getResourceMangerPTinVRE(); + + //report initialization + ReportFiller.initizlizeFunctionalityForReport(getResource().getDeployReport().getFunctionalityDeployingReport(),this.resourceId); + ReportFiller.initializeResourcesForReport(getResource().getDeployReport().getResourceDeployingReport(), this.resourceId); - retrieveFunctionalityForReport(); + ResourceManagerPortType rmPortType=getResourceMangerPTinVRE(); CreateScopeParameters scopeParameter=getScopeParameters(); @@ -299,6 +302,7 @@ public class DeployVRE extends Thread{ report=rmPortType.getReport(reportId); reportAttempt++; getResource().getDeployReport().getFunctionalityDeployingReport().setResourceManagerReport(report); + ReportFiller.reportElaboration(getResource().getDeployReport()); getResource().store(); }while (!(isDeploymentStatusFinished(report)) && reportAttempt<40); @@ -526,29 +530,6 @@ public class DeployVRE extends Thread{ return listServices; } - private void retrieveFunctionalityForReport() throws Exception{ - ResultSet resService =DBInterface.queryDB("select func.id, func.name, s.name, s.class, s.version from FUNCTIONALITY as func, VRERELATEDFUNCT AS vrf, SERVICES AS s where vrf.vreid='"+this.resourceId+"' AND s.id=vrf.funcid AND vrf.funcid=func.id;"); - FunctionalityDeployingReport report = getResource().getDeployReport().getFunctionalityDeployingReport(); - while(resService.next()){ - FunctionalityReport funcReport= new FunctionalityReport(); - funcReport.setFunctionalityId(resService.getString(1)); - funcReport.setFunctionalityName(resService.getString(2)); - funcReport.setState(org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Running); - - ServiceReport servReport= new ServiceReport(); - servReport.setServiceName(resService.getString(3)); - servReport.setServiceClass(resService.getString(4)); - servReport.setServiceVersion(resService.getString(5)); - servReport.setState(org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Running); - - List listService; - if ((listService=report.getFunctionalityTable().get(funcReport))==null){ - listService= new ArrayList(); - listService.add(servReport); - report.getFunctionalityTable().put(funcReport, listService); - }else - listService.add(servReport); - } - } + } diff --git a/src/org/gcube/vremanagement/vremodeler/impl/util/Pair.java b/src/org/gcube/vremanagement/vremodeler/impl/util/Pair.java deleted file mode 100644 index a53396e..0000000 --- a/src/org/gcube/vremanagement/vremodeler/impl/util/Pair.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.gcube.vremanagement.vremodeler.impl.util; - -/** - * couple - * @author lucio - * - */ -public class Pair{ - - public F first; - public S second; - - public Pair(F first, S second){ - this.first=first; - this.second= second; - } - -} \ No newline at end of file diff --git a/src/org/gcube/vremanagement/vremodeler/impl/util/ReportFiller.java b/src/org/gcube/vremanagement/vremodeler/impl/util/ReportFiller.java new file mode 100644 index 0000000..2cd4052 --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/impl/util/ReportFiller.java @@ -0,0 +1,134 @@ +package org.gcube.vremanagement.vremodeler.impl.util; + +import java.io.ByteArrayInputStream; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.List; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathFactory; +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.utils.logging.GCUBELog; +import org.gcube.vremanagement.vremodeler.db.DBInterface; +import org.gcube.vremanagement.vremodeler.stubs.deployreport.DeployReport; +import org.gcube.vremanagement.vremodeler.stubs.deployreport.FunctionalityDeployingReport; +import org.gcube.vremanagement.vremodeler.stubs.deployreport.FunctionalityReport; +import org.gcube.vremanagement.vremodeler.stubs.deployreport.Resource; +import org.gcube.vremanagement.vremodeler.stubs.deployreport.ResourceDeployingReport; +import org.gcube.vremanagement.vremodeler.stubs.deployreport.ServiceReport; +import org.gcube.vremanagement.vremodeler.stubs.deployreport.State; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + +public class ReportFiller { + + public static GCUBELog logger= new GCUBELog(ReportFiller.class); + + /** + * + * @param report + * @param vreResourceId + * @throws Exception + */ + public static void initizlizeFunctionalityForReport(FunctionalityDeployingReport report, String vreResourceId) throws Exception{ + report.setState(State.Running); + ResultSet resService =DBInterface.queryDB("select func.id, func.name, s.name, s.class, s.version from FUNCTIONALITY as func, VRERELATEDFUNCT AS vrf, SERVICES AS s where vrf.vreid='"+vreResourceId+"' AND s.id=vrf.funcid AND vrf.funcid=func.id;"); + while(resService.next()){ + FunctionalityReport funcReport= new FunctionalityReport(); + funcReport.setFunctionalityId(resService.getString(1)); + funcReport.setFunctionalityName(resService.getString(2)); + funcReport.setState(org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Running); + + ServiceReport servReport= new ServiceReport(); + servReport.setServiceName(resService.getString(3)); + servReport.setServiceClass(resService.getString(4)); + servReport.setServiceVersion(resService.getString(5)); + servReport.setState(org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Running); + + List listService; + if ((listService=report.getFunctionalityTable().get(funcReport))==null){ + listService= new ArrayList(); + listService.add(servReport); + report.getFunctionalityTable().put(funcReport, listService); + }else + listService.add(servReport); + } + } + + /** + * + * @param report + * @param vreResourceId + * @throws Exception + */ + public static void initializeResourcesForReport(ResourceDeployingReport report, String vreResourceId) throws Exception{ + report.setState(State.Running); + ResultSet neededRes =DBInterface.queryDB("select n.id from NEEDEDRESOURCES AS n;"); + while (neededRes.next()) + report.getResources().add(new Resource(neededRes.getString(1), GCUBEGenericResource.TYPE)); + + ResultSet resRelatedCol =DBInterface.queryDB("select VRERELATEDCOLLECTION.collid from VRERELATEDCOLLECTION where VRERELATEDCOLLECTION.vreid='"+vreResourceId+"';"); + while (resRelatedCol.next()) + report.getResources().add(new Resource(resRelatedCol.getString(1), GCUBECollection.TYPE)); + + ResultSet resMdColNative =DBInterface.queryDB("select n.mdcollid from VRERELATEDMETADATAFORMAT AS s, NATIVEMDF as n where s.vreid='"+vreResourceId+"' and n.mdfid=s.mfid;"); + while (resMdColNative.next()) + report.getResources().add(new Resource(resRelatedCol.getString(1), GCUBEMCollection.TYPE)); + } + + /** + * + * @param report + */ + public static void reportElaboration(DeployReport report){ + String rmReport = report.getFunctionalityDeployingReport().getResourceManagerReport(); + if (rmReport==null) return; + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db; + try{ + db = dbf.newDocumentBuilder(); + Document document = db.parse(new ByteArrayInputStream(rmReport.getBytes())); + XPath xpath= XPathFactory.newInstance().newXPath(); + //first step: services retrieving + for (List serviceReportsList:report.getFunctionalityDeployingReport().getFunctionalityTable().values()){ + for (ServiceReport serviceReport: serviceReportsList){ + if (serviceReport.getState()==State.Finished || serviceReport.getState()==State.Failed) continue; + NodeList nResoulution = (NodeList)xpath.evaluate("/ResourceReport/Services/Service/DeploymentActivity/GHN/LastReportReceived/Packages/Package[/ServiceClass/text()='"+serviceReport.getServiceClass()+"' and /ServiceName/text()='"+serviceReport.getServiceName()+"' and /ServiceVersion/text()='"+serviceReport.getServiceVersion()+"']/Status",document,XPathConstants.NODESET); + boolean isServiceDeployed=true; + boolean isServiceFailed=false; + for (int i = 0; i < nResoulution.getLength(); i++) { + if(nResoulution.item(i).getFirstChild().getNodeValue().compareTo("FAILED")==0){ + isServiceFailed=true; + break; + }else if(!(nResoulution.item(i).getFirstChild().getNodeValue().compareTo("RUNNING")==0 || nResoulution.item(i).getFirstChild().getNodeValue().compareTo("ACTIVATED")==0)){ + isServiceDeployed=false; + } + } + + if (isServiceFailed) serviceReport.setState(State.Failed); + if (isServiceDeployed) serviceReport.setState(State.Finished); + } + } + + //second step: resources retrieving + for (Resource resource:report.getResourceDeployingReport().getResources()){ + if (resource.getState()==State.Finished || resource.getState()==State.Failed) continue; + NodeList nResoulution = (NodeList)xpath.evaluate("/ResourceReport/Resources/Resource[/ID/text()='"+resource.getResourceId()+"']/Status",document,XPathConstants.NODESET); + if (nResoulution.getLength()>0){ + if(nResoulution.item(0).getFirstChild().getNodeValue().compareTo("FAILED")==0) + resource.setState(State.Failed); + else resource.setState(State.Finished); + } + } + }catch (Exception e) { + logger.warn("cannot fill report",e); + } + + + } + +} diff --git a/src/org/gcube/vremanagement/vremodeler/impl/util/Util.java b/src/org/gcube/vremanagement/vremodeler/impl/util/Util.java index 4a551c0..a928c35 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/util/Util.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/util/Util.java @@ -330,6 +330,7 @@ public class Util { return returnEl; } + /** * * @param doc the root Document @@ -337,13 +338,8 @@ public class Util { * @param text the text to add at the element * @return the result element */ - public static Element createTextElement(Document doc, String tag, String text, Pair ... attributes ){ + public static Element createTextElement(Document doc, String tag, String text){ Element returnEl= doc.createElement(tag); - if (attributes!=null){ - for (Pair attribute : attributes){ - returnEl.setAttribute(attribute.first, attribute.second); - } - } if (text!=null) returnEl.appendChild(doc.createTextNode(text)); return returnEl; } diff --git a/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/DeployReport.java b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/DeployReport.java index 9a39701..19149b3 100644 --- a/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/DeployReport.java +++ b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/DeployReport.java @@ -12,21 +12,28 @@ public class DeployReport implements Serializable{ /** * */ - public DeployReport(){ - this.state= State.Waiting; - this.cloudDeployingReport= new GHNonCloudReport(); - this.functionalityDeployingReport= new FunctionalityDeployingReport(); - this.resourceMaangerDeployingReport= new ResourceManagerDeployingReport(); - } + private static final long serialVersionUID = 7295105471156172674L; + private State state; + private GHNonCloudReport cloudDeployingReport; + private ResourceManagerDeployingReport resourceManagerDeployingReport; + private FunctionalityDeployingReport functionalityDeployingReport; + private ResourceDeployingReport resourceDeployingReport; + /** * */ - private static final long serialVersionUID = 7295105471156172674L; - private State state; - private GHNonCloudReport cloudDeployingReport; - private ResourceManagerDeployingReport resourceMaangerDeployingReport; - private FunctionalityDeployingReport functionalityDeployingReport; + public DeployReport(){ + this.state= State.Waiting; + this.cloudDeployingReport= new GHNonCloudReport(); + this.cloudDeployingReport.setState(State.Waiting); + this.functionalityDeployingReport= new FunctionalityDeployingReport(); + this.functionalityDeployingReport.setState(State.Waiting); + this.resourceManagerDeployingReport= new ResourceManagerDeployingReport(); + this.resourceManagerDeployingReport.setState(State.Waiting); + this.resourceDeployingReport= new ResourceDeployingReport(); + this.resourceDeployingReport.setState(State.Waiting); + } /** * @@ -65,16 +72,16 @@ public class DeployReport implements Serializable{ * @return */ public ResourceManagerDeployingReport getResourceManagerDeployingReport() { - return resourceMaangerDeployingReport; + return resourceManagerDeployingReport; } /** * * @param resourceMaangerDeployingReport */ - public void setResourceMaangerDeployingReport( - ResourceManagerDeployingReport resourceMaangerDeployingReport) { - this.resourceMaangerDeployingReport = resourceMaangerDeployingReport; + public void setResourceManagerDeployingReport( + ResourceManagerDeployingReport resourceManagerDeployingReport) { + this.resourceManagerDeployingReport = resourceManagerDeployingReport; } /** @@ -93,5 +100,13 @@ public class DeployReport implements Serializable{ FunctionalityDeployingReport functionalityDeployingReport) { this.functionalityDeployingReport = functionalityDeployingReport; } - + + public ResourceDeployingReport getResourceDeployingReport() { + return resourceDeployingReport; + } + + public void setResourceDeployingReport( + ResourceDeployingReport resourceDeployingReport) { + this.resourceDeployingReport = resourceDeployingReport; + } } diff --git a/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/Resource.java b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/Resource.java new file mode 100644 index 0000000..03b3aee --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/Resource.java @@ -0,0 +1,46 @@ +package org.gcube.vremanagement.vremodeler.stubs.deployreport; + +import java.io.Serializable; + +public class Resource implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 4929870516367802531L; + private String resourceId; + private String resourceType; + private State state; + + public Resource(String resourceId, String resourceType) { + super(); + this.resourceId = resourceId; + this.resourceType = resourceType; + this.state=State.Running; + } + + public State getState() { + return state; + } + + public void setState(State state) { + this.state = state; + } + + public String getResourceId() { + return resourceId; + } + public void setResourceId(String resourceId) { + this.resourceId = resourceId; + } + public String getResourceType() { + return resourceType; + } + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public int hashCode(){ + return resourceId.hashCode(); + } +} diff --git a/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/ResourceDeployingReport.java b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/ResourceDeployingReport.java new file mode 100644 index 0000000..52e0f59 --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/ResourceDeployingReport.java @@ -0,0 +1,34 @@ +package org.gcube.vremanagement.vremodeler.stubs.deployreport; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public class ResourceDeployingReport implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 1692792289962987059L; + private State state; + private List resources; + + public ResourceDeployingReport(){ + this.resources=new ArrayList(); + } + + public State getState() { + return state; + } + public void setState(State state) { + this.state = state; + } + + public List getResources() { + return resources; + } + + public void setResources(List resources) { + this.resources = resources; + } +}