This commit is contained in:
Lucio Lelii 2010-11-04 14:56:53 +00:00
parent 7b998911c3
commit 18271f631c
8 changed files with 259 additions and 71 deletions

View File

@ -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";

View File

@ -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<String> 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<ServiceReport> listService;
if ((listService=report.getFunctionalityTable().get(funcReport))==null){
listService= new ArrayList<ServiceReport>();
listService.add(servReport);
report.getFunctionalityTable().put(funcReport, listService);
}else
listService.add(servReport);
}
}
}

View File

@ -1,18 +0,0 @@
package org.gcube.vremanagement.vremodeler.impl.util;
/**
* couple
* @author lucio
*
*/
public class Pair<F,S>{
public F first;
public S second;
public Pair(F first, S second){
this.first=first;
this.second= second;
}
}

View File

@ -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<ServiceReport> listService;
if ((listService=report.getFunctionalityTable().get(funcReport))==null){
listService= new ArrayList<ServiceReport>();
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<ServiceReport> 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);
}
}
}

View File

@ -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<String, String> ... attributes ){
public static Element createTextElement(Document doc, String tag, String text){
Element returnEl= doc.createElement(tag);
if (attributes!=null){
for (Pair<String, String> attribute : attributes){
returnEl.setAttribute(attribute.first, attribute.second);
}
}
if (text!=null) returnEl.appendChild(doc.createTextNode(text));
return returnEl;
}

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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<Resource> resources;
public ResourceDeployingReport(){
this.resources=new ArrayList<Resource>();
}
public State getState() {
return state;
}
public void setState(State state) {
this.state = state;
}
public List<Resource> getResources() {
return resources;
}
public void setResources(List<Resource> resources) {
this.resources = resources;
}
}