diff --git a/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java b/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java index d6e0188..f4c17be 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java @@ -13,16 +13,10 @@ 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; -import org.gcube.common.core.informationsystem.client.AtomicCondition; -import org.gcube.common.core.informationsystem.client.ISClient; -import org.gcube.common.core.informationsystem.client.queries.GCUBERIQuery; 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.resources.GCUBERunningInstance; import org.gcube.common.core.resources.impl.kxml.KGCUBEResource; import org.gcube.common.core.scope.GCUBEScope; import org.gcube.common.core.utils.handlers.GCUBEServiceClientImpl; @@ -43,7 +37,6 @@ import org.gcube.vremanagement.vremodeler.impl.util.Couple; import org.gcube.vremanagement.vremodeler.impl.util.VREManagerServiceHandler; import org.gcube.vremanagement.vremodeler.portallayout.CollectionResourceCreation; import org.gcube.vremanagement.vremodeler.portallayout.GenericResourcePortlet; -import org.gcube.vremanagement.vremodeler.portallayout.LayoutCreation; import org.globus.wsrf.ResourceException; import org.w3c.dom.Document; import org.w3c.dom.NodeList; @@ -72,17 +65,20 @@ public class DeployVRE extends Thread{ public void run() { try { ResultSet resRelatedGHN=DBInterface.queryDB("select VRERELATEDGHN.ghnid, GHN.domain from VRERELATEDGHN, GHN where GHN.id=VRERELATEDGHN.ghnid and VRERELATEDGHN.vreid='"+this.resourceId+"'; "); - if (!resRelatedGHN.next()){ - throw new Exception("No ghn Selected"); - } - String firstGHNId= resRelatedGHN.getString(1); - List GHNList= new ArrayList(); - while (resRelatedGHN.next()) GHNList.add(resRelatedGHN.getString(1)); + List> GHNList= new ArrayList>(); + while (resRelatedGHN.next()) GHNList.add(new Couple(resRelatedGHN.getString(1),resRelatedGHN.getString(2))); + if (GHNList.size()<2){ + throw new Exception("No ghn Selected (at least 2 GHNs have to be selcted)"); + } - if (!deployManagerOnVRE(firstGHNId)){ - if (!createVRE(GHNList)){ + if (!deployManagerOnVRE(GHNList)){ + //transforming the Couple to a ghnid List + List ghnEpuredList = new ArrayList(); + for (Couple cpl: GHNList) ghnEpuredList.add(cpl.first); + + if (!createVRE(ghnEpuredList)){ DBInterface.ExecuteUpdate("UPDATE VRE SET STATUS='"+ModelerService.DEPLOYED+"' WHERE VRE.id='"+this.resourceId+"';"); logger.info("Deploying of the VRE with id "+this.resourceId+" FINISHED"); } @@ -108,7 +104,7 @@ public class DeployVRE extends Thread{ } - private boolean deployManagerOnVRE(String firstGHNId) throws GCUBEFault{ + private boolean deployManagerOnVRE(List> GHNList) throws GCUBEFault{ String vreName= null; try { DBInterface.ExecuteUpdate("UPDATE VRE SET STATUS='Deploying' WHERE VRE.id='"+this.resourceId+"';"); @@ -124,7 +120,7 @@ public class DeployVRE extends Thread{ } // Couple>> is a triple with first GCUBEScope, second couple: first String is the VREName, second string is the GHNId - VREManagerServiceHandler> vreManagerHandler= new VREManagerServiceHandler>(){ + VREManagerServiceHandler>>> vreManagerHandler= new VREManagerServiceHandler>>>(){ @SuppressWarnings("static-access") @Override @@ -140,10 +136,21 @@ public class DeployVRE extends Thread{ service[0].setServiceName("VREManager"); service[0].setServiceVersion("1.00.00"); services.setService(service); - services.setGHN(new String[]{this.getParameter().second}); + + Couple ghnId=null; + for (Couple cpl: getParameter().second){ + if (this.getCachedEPR().getAddress().getHost().contains(cpl.second)){ + ghnId=cpl; + break; + } + } + if (ghnId==null) ghnId=getParameter().second.get(0); + + services.setGHN(new String[]{ghnId.first}); arp.setServices(services); arp.setTargetScope(this.scope+"/"+this.getParameter().first); String reportId=mbportType.addResources(arp); + getParameter().second.remove(ghnId); int attempt=0; do{ @@ -162,7 +169,7 @@ public class DeployVRE extends Thread{ vreManagerHandler.clearState(); vreManagerHandler.setHandled(new GCUBEServiceClientImpl()); - Couple coupleParams= new Couple(vreName, firstGHNId); + Couple>> coupleParams= new Couple>>(vreName, GHNList); vreManagerHandler.setParameter(coupleParams); vreManagerHandler.scope=this.startingScope;