git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/VREModeler@8520 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
78a6bd674b
commit
0cd084b2fb
|
@ -31,7 +31,7 @@ import org.gcube.vremanagement.vremanager.stubs.vremanager.VREManagerPortType;
|
|||
import org.gcube.vremanagement.vremodeler.db.DBInterface;
|
||||
import org.gcube.vremanagement.vremodeler.impl.ModelerContext;
|
||||
import org.gcube.vremanagement.vremodeler.impl.ModelerResource;
|
||||
import org.gcube.vremanagement.vremodeler.impl.ServiceContext;
|
||||
import org.gcube.vremanagement.vremodeler.impl.ModelerService;
|
||||
import org.gcube.vremanagement.vremodeler.impl.util.Couple;
|
||||
import org.gcube.vremanagement.vremodeler.impl.util.VREManagerServiceHandler;
|
||||
import org.globus.wsrf.ResourceException;
|
||||
|
@ -41,7 +41,7 @@ import org.xml.sax.SAXException;
|
|||
|
||||
public class DeployVRE extends Thread{
|
||||
|
||||
private static GCUBELog logger= new GCUBELog(DeployVRE.class);
|
||||
private static GCUBELog logger= new GCUBELog(ModelerService.class);
|
||||
|
||||
private ModelerResource wsResource= null;
|
||||
private String resourceId;
|
||||
|
@ -60,9 +60,17 @@ public class DeployVRE extends Thread{
|
|||
|
||||
public void run() {
|
||||
try {
|
||||
deployManagerOnVRE();
|
||||
createVRE();
|
||||
logger.info("Dploying of the VRE with id "+this.resourceId+" FINISHED");
|
||||
ResultSet resRelatedGHN=DBInterface.queryDB("select VRERELATEDGHN.ghnid from VRERELATEDGHN where VRERELATEDGHN.vreid='"+this.resourceId+"'; ");
|
||||
if (!resRelatedGHN.next()){
|
||||
DBInterface.ExecuteUpdate("UPDATE VRE SET STATUS='Failed' WHERE VRE.id='"+this.resourceId+"';");
|
||||
}
|
||||
String firstGHNId= resRelatedGHN.getString(1);
|
||||
List<String> GHNList= new ArrayList<String>();
|
||||
while (resRelatedGHN.next()) GHNList.add(resRelatedGHN.getString(1));
|
||||
|
||||
deployManagerOnVRE(firstGHNId);
|
||||
createVRE(GHNList);
|
||||
logger.info("Deploying of the VRE with id "+this.resourceId+" FINISHED");
|
||||
}catch(Exception e){
|
||||
logger.error("Error deploying the VRE with id "+this.resourceId+" "+e);
|
||||
e.printStackTrace();
|
||||
|
@ -70,8 +78,8 @@ public class DeployVRE extends Thread{
|
|||
}
|
||||
|
||||
|
||||
private void deployManagerOnVRE() throws GCUBEFault{
|
||||
String firstGHNId= null, vreName= null;
|
||||
private void deployManagerOnVRE(String firstGHNId) throws GCUBEFault{
|
||||
String vreName= null;
|
||||
try {
|
||||
DBInterface.ExecuteUpdate("UPDATE VRE SET STATUS='Deploying' WHERE VRE.id='"+this.resourceId+"';");
|
||||
ResultSet resGenericInfo = DBInterface.queryDB("select VRE.name from VRE where VRE.id='"+this.resourceId+"'; ");
|
||||
|
@ -79,11 +87,7 @@ public class DeployVRE extends Thread{
|
|||
throw new GCUBEFault("The VRE with ID "+this.resourceId+" cannot be retrieved on the DB");
|
||||
}
|
||||
vreName= resGenericInfo.getString(1);
|
||||
ResultSet resRelatedGHN=DBInterface.queryDB("select VRERELATEDGHN.ghnid from VRERELATEDGHN where VRERELATEDGHN.vreid='"+this.resourceId+"'; ");
|
||||
if (!resRelatedGHN.next()){
|
||||
DBInterface.ExecuteUpdate("UPDATE VRE SET STATUS='Failed' WHERE VRE.id='"+this.resourceId+"';");
|
||||
}
|
||||
firstGHNId= resRelatedGHN.getString(1);
|
||||
|
||||
} catch (SQLException e) {
|
||||
logger.error("HSQLDB Error "+e);
|
||||
throw new GCUBEFault(e);
|
||||
|
@ -143,18 +147,18 @@ public class DeployVRE extends Thread{
|
|||
}
|
||||
|
||||
|
||||
private void createVRE() throws GCUBEFault{
|
||||
VREManagerServiceHandler<String, String> vreManagerHandler= new VREManagerServiceHandler<String,String>(){
|
||||
private void createVRE(List<String> ghnList) throws GCUBEFault{
|
||||
VREManagerServiceHandler<Boolean, Couple<List<String>, String>> vreManagerHandler= new VREManagerServiceHandler<Boolean,Couple<List<String>, String>>(){
|
||||
|
||||
//the parameter is resourceID
|
||||
@SuppressWarnings("static-access")
|
||||
@Override
|
||||
protected String makeCall(VREManagerPortType vreManPortType)
|
||||
protected Boolean makeCall(VREManagerPortType vreManPortType)
|
||||
throws Exception {
|
||||
|
||||
OptionsParameters ops;
|
||||
|
||||
ResultSet resGenericInfo = DBInterface.queryDB("select VRE.name, VRE.vredesigner, VRE.vremanager, VRE.IntervalTo, VRE.IntervalFrom, VRE.description from VRE where VRE.id='"+this.getParameter()+"'; ");
|
||||
ResultSet resGenericInfo = DBInterface.queryDB("select VRE.name, VRE.vredesigner, VRE.vremanager, VRE.IntervalTo, VRE.IntervalFrom, VRE.description from VRE where VRE.id='"+this.getParameter().second+"'; ");
|
||||
if (!resGenericInfo.next()) throw new GCUBEFault("The VRE with ID "+this.getParameter()+" cannot be retrieved");
|
||||
|
||||
ops=new OptionsParameters();
|
||||
|
@ -200,7 +204,7 @@ public class DeployVRE extends Thread{
|
|||
try{
|
||||
|
||||
ResourceItem resItem;
|
||||
ResultSet resRelatedCol =DBInterface.queryDB("select VRERELATEDCOLLECTION.collid from VRERELATEDCOLLECTION where VRERELATEDCOLLECTION.vreid='"+this.getParameter()+"';");
|
||||
ResultSet resRelatedCol =DBInterface.queryDB("select VRERELATEDCOLLECTION.collid from VRERELATEDCOLLECTION where VRERELATEDCOLLECTION.vreid='"+this.getParameter().second+"';");
|
||||
while (resRelatedCol.next()){
|
||||
resItem= new ResourceItem();
|
||||
resItem.setID(resRelatedCol.getString(1));
|
||||
|
@ -212,7 +216,7 @@ public class DeployVRE extends Thread{
|
|||
//retrieving MDCollection with native MDFormat
|
||||
try{
|
||||
ResourceItem resItem;
|
||||
ResultSet resMdColNative =DBInterface.queryDB("select s.mdcollid from SELECTEDNATIVEMDFORMAT AS s where s.vreid='"+this.getParameter()+"';");
|
||||
ResultSet resMdColNative =DBInterface.queryDB("select s.mdcollid from SELECTEDNATIVEMDFORMAT AS s where s.vreid='"+this.getParameter().second+"';");
|
||||
while (resMdColNative.next()){
|
||||
resItem= new ResourceItem();
|
||||
resItem.setID(resMdColNative.getString(1));
|
||||
|
@ -230,27 +234,20 @@ 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()+"' AND s.id=vrf.funcid;");
|
||||
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()){
|
||||
servItem= new ServiceItem();
|
||||
servItem.setServiceClass(resMdColNative.getString("class"));
|
||||
servItem.setServiceName(resMdColNative.getString("name"));
|
||||
servItem.setServiceVersion("1.00.00");
|
||||
listService.add(servItem);
|
||||
}
|
||||
serviceList.setService(listService.toArray(new ServiceItem[0]));
|
||||
}catch(SQLException sqle){logger.error("Error contacting HSQLDB "+sqle);}
|
||||
|
||||
//retrieve the GHN
|
||||
try{
|
||||
List<String> listGHN= new ArrayList<String>();
|
||||
ResultSet resGHN =DBInterface.queryDB("select VRERELATEDGHN.ghnid from VRERELATEDGHN where VRERELATEDGHN.vreid='"+this.getParameter()+"';");
|
||||
//eliminating the First GHN used for VREManager Deployment
|
||||
resGHN.next();
|
||||
while (resGHN.next()){
|
||||
listGHN.add(resGHN.getString(1));
|
||||
}
|
||||
serviceList.setGHN(listGHN.toArray(new String[0]));
|
||||
}catch(SQLException sqle){logger.error("Error contacting HSQLDB "+sqle);}
|
||||
//sets the GHNs
|
||||
serviceList.setGHN(this.getParameter().first.toArray(new String[0]));
|
||||
|
||||
|
||||
arp.setServices(serviceList);
|
||||
|
||||
|
@ -267,13 +264,13 @@ public class DeployVRE extends Thread{
|
|||
getResource().setReportSecondStep(report);
|
||||
|
||||
}while (!isDeploymentStatusFinished(report) && attempt<20);
|
||||
return "";
|
||||
return isSomethingFailed(report);
|
||||
}
|
||||
};
|
||||
|
||||
vreManagerHandler.clearState();
|
||||
vreManagerHandler.setHandled(new GCUBEServiceClientImpl());
|
||||
vreManagerHandler.setParameter(this.resourceId);
|
||||
vreManagerHandler.setParameter(new Couple<List<String>, String>(ghnList,this.resourceId));
|
||||
vreManagerHandler.scope=GCUBEScope.getScope(this.startingScope+"/"+this.vreName);
|
||||
try {
|
||||
vreManagerHandler.run();
|
||||
|
@ -285,7 +282,38 @@ public class DeployVRE extends Thread{
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* controls if something is failed deploying
|
||||
* @param report the VRE deployment report
|
||||
* @return true if Failed, else false
|
||||
*/
|
||||
private boolean isSomethingFailed(String report){
|
||||
boolean ret = false;
|
||||
String xpath = "/ResourceReport/DeploymentActivity/GHN/LastReportReceived/Packages/Package/Status";
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db;
|
||||
try {
|
||||
db = dbf.newDocumentBuilder();
|
||||
Document document = db.parse(new ByteArrayInputStream(report.getBytes()));
|
||||
XPath engine = XPathFactory.newInstance().newXPath();
|
||||
NodeList nl = (NodeList) engine.evaluate(xpath,document, XPathConstants.NODESET);
|
||||
for (int i = 0; i < nl.getLength(); i++) {
|
||||
if(nl.item(i).getFirstChild().getNodeValue().compareTo("FAILED")==0){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (ParserConfigurationException e) {
|
||||
return true;
|
||||
} catch (SAXException e) {
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return true;
|
||||
} catch (XPathExpressionException e) {
|
||||
return true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private boolean isDeploymentStatusFinished(String report) {
|
||||
boolean ret = false;
|
||||
String xpath = "/ResourceReport/DeploymentActivity/GHN/LastReportReceived/Status";
|
||||
|
|
|
@ -53,19 +53,19 @@ public class ModelerTest {
|
|||
vreReq.setVREDescription("desc");
|
||||
vreReq.setVREDesigner("Lucio");
|
||||
vreReq.setVREManager("Lucio");
|
||||
vreReq.setVREName("TestSuiteVRECReation");
|
||||
vreReq.setVREName("VRETEST");
|
||||
msptp.setVREModel(vreReq);
|
||||
|
||||
CollectionArray ca= new CollectionArray();
|
||||
ca.setCollectionElement(new String[]{"16fb9de0-bcc9-11dd-99fe-ab7448de6437"});
|
||||
ca.setCollectionElement(new String[]{"7adf44f0-e3f8-11dd-8998-8404ac58d67d"});
|
||||
msptp.setCollection(ca);
|
||||
|
||||
FunctionalityIDArray fida= new FunctionalityIDArray();
|
||||
fida.setFunctionalityIDElement(new String[]{"3", "4"});
|
||||
fida.setFunctionalityIDElement(new String[]{"5"});
|
||||
msptp.setFunctionality(fida);
|
||||
|
||||
GHNArray ghnArray= new GHNArray();
|
||||
ghnArray.setGHNElement(new String[]{"fbd4db10-e268-11dd-bf95-b9ea85be7470","8abb9f20-e355-11dd-b772-ce6307daf8f3"});
|
||||
ghnArray.setGHNElement(new String[]{"fbd4db10-e268-11dd-bf95-b9ea85be7470","fe602770-e3f5-11dd-a0e9-fe3a60cbc58d"});
|
||||
msptp.setGHNs(ghnArray);
|
||||
|
||||
System.out.println("-"+msptp.checkStatus(new VOID()).getReports(0)+"-");
|
||||
|
|
Loading…
Reference in New Issue