diff --git a/.classpath b/.classpath index d29d7d9..c6332d0 100644 --- a/.classpath +++ b/.classpath @@ -4,5 +4,6 @@ + diff --git a/etc/hsqldb/vreModelerDBInitializer b/etc/hsqldb/vreModelerDBInitializer index edca113..24d5ef0 100644 --- a/etc/hsqldb/vreModelerDBInitializer +++ b/etc/hsqldb/vreModelerDBInitializer @@ -1,5 +1,5 @@ CREATE CACHED TABLE COLLECTION(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR,DESCRIPTION VARCHAR,MEMBERS VARCHAR,CREATION VARCHAR,LASTUPDATE VARCHAR) -CREATE CACHED TABLE GHN(ID VARCHAR NOT NULL PRIMARY KEY,HOST VARCHAR,SECURITY VARCHAR,UPTIME VARCHAR,MAINMEMORYVA VARCHAR,MAINMEMORYVS VARCHAR,LOCALAS VARCHAR,LOCATION VARCHAR,COUNTRY VARCHAR,DOMAIN VARCHAR) +CREATE CACHED TABLE GHN(ID VARCHAR NOT NULL PRIMARY KEY,HOST VARCHAR,SECURITY VARCHAR,UPTIME VARCHAR,MAINMEMORYVA VARCHAR,MAINMEMORYVS VARCHAR,LOCALAS VARCHAR,LOCATION VARCHAR,COUNTRY VARCHAR,DOMAIN VARCHAR, ISONCLOUD BOOLEAN) CREATE CACHED TABLE MCOLLECTION(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR,DESCRIPTION VARCHAR,RELATEDCOLLECTIONID VARCHAR NOT NULL,CONSTRAINT SYS_FK_50 FOREIGN KEY(RELATEDCOLLECTIONID) REFERENCES COLLECTION(ID)) CREATE CACHED TABLE VRE(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR NOT NULL,DESCRIPTION VARCHAR NOT NULL,VREDESIGNER VARCHAR NOT NULL,VREMANAGER VARCHAR NOT NULL,INTERVALFROM DATE,INTERVALTO DATE,STATUS VARCHAR) CREATE CACHED TABLE CS(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR NOT NULL,DESCRIPTION VARCHAR NOT NULL) @@ -17,4 +17,5 @@ CREATE CACHED TABLE SERVICES(ID INTEGER NOT NULL,NAME VARCHAR NOT NULL,CLASS VA CREATE CACHED TABLE VRERELATEDFUNCT(VREID VARCHAR NOT NULL,FUNCID VARCHAR NOT NULL,PRIMARY KEY(VREID,FUNCID)) CREATE CACHED TABLE RELATEDSERVICEID(ID VARCHAR NOT NULL PRIMARY KEY,NAME VARCHAR NOT NULL,CLASS VARCHAR NOT NULL) CREATE CACHED TABLE PORTLETRELTOFUNCT(FUNCID INTEGER NOT NULL,PORTLETCLASS VARCHAR NOT NULL, FOREIGN KEY(FUNCID) REFERENCES FUNCTIONALITY(ID) ) -CREATE CACHED TABLE NEEDEDRESOURCES(ID VARCHAR NOT NULL, TYPE VARCHAR NOT NULL, PRIMARY KEY(ID)) \ No newline at end of file +CREATE CACHED TABLE NEEDEDRESOURCES(ID VARCHAR NOT NULL, TYPE VARCHAR NOT NULL, PRIMARY KEY(ID)) +CREATE CACHED TABLE VRERELETEDCLOUD(VREID VARCHAR NOT NULL, VMNAME VARCHAR NOT NULL, HOSTNAME VARCHAR, PRIMARY KEY(VREID, VMNAME)) \ No newline at end of file diff --git a/schema/ModelerService.wsdl b/schema/ModelerService.wsdl index ac4fd60..c831500 100644 --- a/schema/ModelerService.wsdl +++ b/schema/ModelerService.wsdl @@ -130,20 +130,18 @@ - - - - - - - + + + + + @@ -151,15 +149,11 @@ - - - + - - @@ -239,6 +233,13 @@ + + + + + + + @@ -349,6 +350,11 @@ + + + + + diff --git a/src/org/gcube/vremanagement/vremodeler/consumers/CollectionConsumer.java b/src/org/gcube/vremanagement/vremodeler/consumers/CollectionConsumer.java index b5397e8..3fc37ec 100644 --- a/src/org/gcube/vremanagement/vremodeler/consumers/CollectionConsumer.java +++ b/src/org/gcube/vremanagement/vremodeler/consumers/CollectionConsumer.java @@ -4,6 +4,7 @@ import java.io.StringReader; import javax.xml.namespace.QName; import org.gcube.common.core.contexts.GHNContext; import org.gcube.common.core.informationsystem.notifier.ISNotifier.BaseNotificationConsumer; +import org.gcube.common.core.informationsystem.notifier.ISNotifier.GCUBENotificationTopic; import org.gcube.common.core.informationsystem.notifier.ISNotifier.NotificationEvent; import org.gcube.common.core.resources.GCUBECollection; import org.gcube.common.core.scope.GCUBEScope; @@ -15,7 +16,7 @@ public class CollectionConsumer extends BaseNotificationConsumer{ private GCUBELog logger= new GCUBELog(GHNConsumer.class); - public static final QName collectionQName= new QName("http://gcube-system.org/namespaces/informationsystem/registry","Collection"); + public static final GCUBENotificationTopic collectionTopic= new GCUBENotificationTopic(new QName("http://gcube-system.org/namespaces/informationsystem/registry","Collection")); private GCUBEScope scope; diff --git a/src/org/gcube/vremanagement/vremodeler/consumers/GHNConsumer.java b/src/org/gcube/vremanagement/vremodeler/consumers/GHNConsumer.java index a78bc0c..57bdb24 100644 --- a/src/org/gcube/vremanagement/vremodeler/consumers/GHNConsumer.java +++ b/src/org/gcube/vremanagement/vremodeler/consumers/GHNConsumer.java @@ -6,6 +6,7 @@ import javax.xml.namespace.QName; import org.gcube.common.core.contexts.GHNContext; import org.gcube.common.core.informationsystem.notifier.ISNotifier.BaseNotificationConsumer; +import org.gcube.common.core.informationsystem.notifier.ISNotifier.GCUBENotificationTopic; import org.gcube.common.core.informationsystem.notifier.ISNotifier.NotificationEvent; import org.gcube.common.core.resources.GCUBEHostingNode; import org.gcube.common.core.scope.GCUBEScope; @@ -16,10 +17,17 @@ import org.gcube.vremanagement.vremodeler.resources.handlers.GHNHandler; public class GHNConsumer extends BaseNotificationConsumer{ + public static GCUBENotificationTopic ghnTopic; + + static{ + ghnTopic= new GCUBENotificationTopic(new QName("http://gcube-system.org/namespaces/informationsystem/registry","GHN")); + ghnTopic.setPrecondition("(//operationType[text()='destroy']) or (//operationType[text()='create'])"); + } + private GCUBELog logger= new GCUBELog(GHNConsumer.class); - - public static final QName ghnQName= new QName("http://gcube-system.org/namespaces/informationsystem/registry","GHN"); - + + + private GCUBEScope scope; public GHNConsumer(GCUBEScope scope){ diff --git a/src/org/gcube/vremanagement/vremodeler/consumers/GenericResourceConsumer.java b/src/org/gcube/vremanagement/vremodeler/consumers/GenericResourceConsumer.java index 9d1882c..d94d214 100644 --- a/src/org/gcube/vremanagement/vremodeler/consumers/GenericResourceConsumer.java +++ b/src/org/gcube/vremanagement/vremodeler/consumers/GenericResourceConsumer.java @@ -4,6 +4,7 @@ import java.io.StringReader; import javax.xml.namespace.QName; import org.gcube.common.core.contexts.GHNContext; import org.gcube.common.core.informationsystem.notifier.ISNotifier.BaseNotificationConsumer; +import org.gcube.common.core.informationsystem.notifier.ISNotifier.GCUBENotificationTopic; import org.gcube.common.core.informationsystem.notifier.ISNotifier.NotificationEvent; import org.gcube.common.core.resources.GCUBEGenericResource; import org.gcube.common.core.scope.GCUBEScope; @@ -17,8 +18,8 @@ public class GenericResourceConsumer extends BaseNotificationConsumer{ private GCUBELog logger= new GCUBELog(GHNConsumer.class); - public static final QName functionalityQName= new QName("http://gcube-system.org/namespaces/informationsystem/registry","GenericResource"); - + public static final GCUBENotificationTopic functionalityTopic= new GCUBENotificationTopic(new QName("http://gcube-system.org/namespaces/informationsystem/registry","GenericResource")); + private String functionalityResourceId; private GCUBEScope scope; diff --git a/src/org/gcube/vremanagement/vremodeler/consumers/MCollectionConsumer.java b/src/org/gcube/vremanagement/vremodeler/consumers/MCollectionConsumer.java index f55ba10..a992cc1 100644 --- a/src/org/gcube/vremanagement/vremodeler/consumers/MCollectionConsumer.java +++ b/src/org/gcube/vremanagement/vremodeler/consumers/MCollectionConsumer.java @@ -6,6 +6,7 @@ import javax.xml.namespace.QName; import org.gcube.common.core.contexts.GHNContext; import org.gcube.common.core.informationsystem.notifier.ISNotifier.BaseNotificationConsumer; +import org.gcube.common.core.informationsystem.notifier.ISNotifier.GCUBENotificationTopic; import org.gcube.common.core.informationsystem.notifier.ISNotifier.NotificationEvent; import org.gcube.common.core.resources.GCUBEMCollection; import org.gcube.common.core.scope.GCUBEScope; @@ -15,7 +16,7 @@ import org.gcube.vremanagement.vremodeler.resources.handlers.MCollectionHandler; public class MCollectionConsumer extends BaseNotificationConsumer{ - public static final QName mCollectionQName= new QName("http://gcube-system.org/namespaces/informationsystem/registry","MetadataCollection"); + public static final GCUBENotificationTopic mCollectionTopic=new GCUBENotificationTopic(new QName("http://gcube-system.org/namespaces/informationsystem/registry","MetadataCollection")); private GCUBELog logger= new GCUBELog(MCollectionConsumer.class); diff --git a/src/org/gcube/vremanagement/vremodeler/consumers/RunningInstanceConsumer.java b/src/org/gcube/vremanagement/vremodeler/consumers/RunningInstanceConsumer.java index 31f63f8..01afe68 100644 --- a/src/org/gcube/vremanagement/vremodeler/consumers/RunningInstanceConsumer.java +++ b/src/org/gcube/vremanagement/vremodeler/consumers/RunningInstanceConsumer.java @@ -4,6 +4,7 @@ import java.io.StringReader; import javax.xml.namespace.QName; import org.gcube.common.core.contexts.GHNContext; import org.gcube.common.core.informationsystem.notifier.ISNotifier.BaseNotificationConsumer; +import org.gcube.common.core.informationsystem.notifier.ISNotifier.GCUBENotificationTopic; import org.gcube.common.core.informationsystem.notifier.ISNotifier.NotificationEvent; import org.gcube.common.core.resources.GCUBERunningInstance; import org.gcube.common.core.scope.GCUBEScope; @@ -15,7 +16,7 @@ public class RunningInstanceConsumer extends BaseNotificationConsumer{ private GCUBELog logger= new GCUBELog(RunningInstanceConsumer.class); - public static final QName riQName= new QName("http://gcube-system.org/namespaces/informationsystem/registry","RunningInstance"); + public static final GCUBENotificationTopic riTopic= new GCUBENotificationTopic(new QName("http://gcube-system.org/namespaces/informationsystem/registry","RunningInstance")); private GCUBEScope scope; diff --git a/src/org/gcube/vremanagement/vremodeler/impl/ModelerPersistenceDelegate.java b/src/org/gcube/vremanagement/vremodeler/impl/ModelerPersistenceDelegate.java index 7d74d8f..651bbbc 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/ModelerPersistenceDelegate.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/ModelerPersistenceDelegate.java @@ -4,6 +4,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import org.gcube.common.core.persistence.GCUBEWSFilePersistenceDelegate; +import org.gcube.vremanagement.vremodeler.stubs.deployreport.DeployReport; public class ModelerPersistenceDelegate extends GCUBEWSFilePersistenceDelegate{ @@ -12,8 +13,7 @@ public class ModelerPersistenceDelegate extends GCUBEWSFilePersistenceDelegate topicToRemove= new ArrayList(); + /** Returns cached instance */ public static ServiceContext getContext() {return cache;} @@ -78,30 +79,45 @@ public class ServiceContext extends GCUBEServiceContext{ logger.debug("Service initialized!!"); //GHNNotification - ArrayList qnameList= new ArrayList(); - qnameList.add(GHNConsumer.ghnQName); - notifier.registerToISNotification(qnameList, new GHNConsumer(scope), this, scope); + ArrayList qnameList= new ArrayList(); + qnameList.add(GHNConsumer.ghnTopic); + notifier.registerToISNotification(new GHNConsumer(scope),qnameList, this, scope); //RINotification - qnameList= new ArrayList(); - qnameList.add(RunningInstanceConsumer.riQName); - notifier.registerToISNotification(qnameList, new RunningInstanceConsumer(scope), this, scope); + qnameList= new ArrayList(); + qnameList.add(RunningInstanceConsumer.riTopic); + notifier.registerToISNotification(new RunningInstanceConsumer(scope), qnameList, this, scope); //CollectionNotification - qnameList= new ArrayList(); - qnameList.add(CollectionConsumer.collectionQName); - notifier.registerToISNotification(qnameList, new CollectionConsumer(scope), this, scope); + qnameList= new ArrayList(); + qnameList.add(CollectionConsumer.collectionTopic); + notifier.registerToISNotification(new CollectionConsumer(scope), qnameList, this, scope); //MCollectionNotification - qnameList= new ArrayList(); - qnameList.add(MCollectionConsumer.mCollectionQName); - notifier.registerToISNotification(qnameList, new MCollectionConsumer(scope), this, scope); + qnameList= new ArrayList(); + qnameList.add(MCollectionConsumer.mCollectionTopic); + notifier.registerToISNotification(new MCollectionConsumer(scope), qnameList, this, scope); //FunctionalityResource - qnameList= new ArrayList(); - qnameList.add(GenericResourceConsumer.functionalityQName); - notifier.registerToISNotification(qnameList, new GenericResourceConsumer(scope,functionalityHandler.getFunctionalityResourceId()), this, scope); + qnameList= new ArrayList(); + qnameList.add(GenericResourceConsumer.functionalityTopic); + notifier.registerToISNotification(new GenericResourceConsumer(scope,functionalityHandler.getFunctionalityResourceId()), qnameList, this, scope); logger.debug("consumers registered"); } + + //saving topic for removing + topicToRemove.add(GHNConsumer.ghnTopic); + topicToRemove.add(RunningInstanceConsumer.riTopic); + topicToRemove.add(CollectionConsumer.collectionTopic); + topicToRemove.add(MCollectionConsumer.mCollectionTopic); + topicToRemove.add(GenericResourceConsumer.functionalityTopic); } + public void onShutdown() throws Exception{ + ISNotifier notifier= GHNContext.getImplementation(ISNotifier.class); + for (GCUBEScope scope : ServiceContext.getContext().getInstance().getScopes().values()){ + ServiceContext.getContext().setScope(scope); + notifier.unregisterFromISNotification(this, topicToRemove, scope); + } + } + public ArrayList getSecondaryTypeGenericResourceRequired() { return secondaryTypeGenericResourceRequired; } diff --git a/src/org/gcube/vremanagement/vremodeler/impl/deploy/DeployGHNsOnCloud.java b/src/org/gcube/vremanagement/vremodeler/impl/deploy/DeployGHNsOnCloud.java new file mode 100644 index 0000000..6a58130 --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/impl/deploy/DeployGHNsOnCloud.java @@ -0,0 +1,198 @@ +package org.gcube.vremanagement.vremodeler.impl.deploy; + +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import net.java.dev.jaxb.array.StringArray; +import org.apache.axis.client.Call; +import org.apache.axis.client.Stub; +import org.gcube.common.core.utils.logging.GCUBELog; +import org.gcube.vremanagement.vremodeler.db.DBInterface; +import org.gcube.vremanagement.vremodeler.impl.ServiceContext; +import org.gcube.vremanagement.vremodeler.stubs.deployreport.GHNonCloudReport; +import org.gcube.vremanagement.vremodeler.stubs.deployreport.State; +import org.uoa.eolus.Eolus; +import org.uoa.eolus.EolusServiceLocator; + + +public class DeployGHNsOnCloud{ + + private static GCUBELog logger= new GCUBELog(DeployGHNsOnCloud.class); + + int numberOfVMs; + private String vreName; + private GHNonCloudReport report; + + public DeployGHNsOnCloud(int numberOfVMs, String vreName) { + super(); + this.numberOfVMs = numberOfVMs; + this.vreName= vreName; + this.report= new GHNonCloudReport(); + this.report.setState(State.Running); + } + + public GHNonCloudReport getReport() { + return report; + } + + /** + * + * @return + * @throws Exception + */ + public GHNstoUse run() throws Exception{ + + String username = "gcube"; + String password = "gcube.cloud.2010"; + + EolusServiceLocator servicelocator = new EolusServiceLocator(); + Eolus eolus = servicelocator.getEolusPort(); + + ((Stub) eolus)._setProperty(Call.USERNAME_PROPERTY, username); + ((Stub) eolus)._setProperty(Call.PASSWORD_PROPERTY, password); + + //filling the report + List ghnsStates=new ArrayList(numberOfVMs); + Collections.fill(ghnsStates, State.Running); + this.report.setDeployingState(ghnsStates); + + VM[] hostnames=createVMs(eolus); + configureAndStartContainers(eolus, hostnames); + + //waiting few seconds for GHN registration + Thread.sleep(30000); + checkGHNAvailability(hostnames); + + //now we can be sure that the GHNs are registered on the IS + //and the return type can be created + GHNstoUse ghnToUse= new GHNstoUse(); + ghnToUse.setCandidateForRM(hostnames[0].getGhnId()); + List ghns= new ArrayList(hostnames.length-1); + for (int i=1; i 2) + this.report.getDeployingState().set(i, State.Failed); + } + } + + private void checkGHNAvailability(VM[] hostnames) throws Exception{ + boolean[] arrayCheck= new boolean[hostnames.length]; + Arrays.fill(arrayCheck, false); + while (!and(arrayCheck)){ + ResultSet queryRes; + for (int i=0; i> GHNList= new ArrayList>(); - String candidateGHN=null; - boolean isCandidatePresent=false; - while (resRelatedGHN.next()) { - if(resRelatedGHN.getBoolean(3)){ - candidateGHN=resRelatedGHN.getString(1); - isCandidatePresent= true; - }else GHNList.add(new Pair(resRelatedGHN.getString(1),resRelatedGHN.getString(2))); + getResource().getDeployReport().setState(org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Running); + getResource().store(); + GHNstoUse ghnsToUse=null; + if (getResource().isUseCloud()){ + DeployGHNsOnCloud ghnOnCloud = new DeployGHNsOnCloud(getResource().getNumberOfVMsForCloud(), vreName); + this.report.setCloudDeployingReport(ghnOnCloud.getReport()); + try{ + ghnsToUse = ghnOnCloud.run(); + }catch (Exception e) { + logger.error("error creating VMs on cloud",e); + this.report.getCloudDeployingReport().setState(org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Failed); + } + }else { + this.report.getCloudDeployingReport().setState(org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Skipped); + ResultSet resRelatedGHN=DBInterface.queryDB("select VRERELATEDGHN.ghnid, GHN.domain, VRERELATEDGHN.ISCANDIDATE from VRERELATEDGHN, GHN where GHN.id=VRERELATEDGHN.ghnid and VRERELATEDGHN.vreid='"+this.resourceId+"' ORDER BY GHN.host; "); + ghnsToUse = new GHNstoUse(); + while (resRelatedGHN.next()) { + if(resRelatedGHN.getBoolean(3)){ + ghnsToUse.setCandidateForRM(resRelatedGHN.getString(1)); + }else ghnsToUse.getGhns().add(resRelatedGHN.getString(1)); + } } - - if (!(GHNList.size()>=2 || (GHNList.size()==1 && isCandidatePresent))){ - getResource().setFirstReport(VREState.FAILED.getValue()+": wrong ghn definition"); - getResource().store(); - logger.info("Deploying of the VRE with id "+this.resourceId+" FAILED for wrong ghn definition"); - throw new Exception("No ghn Selected (at least 2 GHNs have to be selected)"); - } - - - if (!deployManagerOnVRE(GHNList, candidateGHN)){ - //transforming the Pair to a ghnid List - List ghnEpuredList = new ArrayList(); - for (Pair cpl: GHNList) ghnEpuredList.add(cpl.first); - - if (!createVRE(ghnEpuredList)){ - DBInterface.ExecuteUpdate("UPDATE VRE SET STATUS='"+VREState.DEPLOYED+"' WHERE VRE.id='"+this.resourceId+"';"); + + if (!deployManagerOnVRE(ghnsToUse.candidateForRM)){ + + if (!createVRE(ghnsToUse.getGhns())){ + DBInterface.ExecuteUpdate("UPDATE VRE SET STATUS='"+org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Finished+"' WHERE VRE.id='"+this.resourceId+"';"); + getResource().getDeployReport().setState(org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Finished); + getResource().store(); logger.info("Deploying of the VRE with id "+this.resourceId+" FINISHED"); } else{ logger.info("Deploying of the VRE with id "+this.resourceId+" FAILED on second step"); - getResource().setSecondReport(VREState.FAILED.getValue()); + getResource().getDeployReport().setState(org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Failed); + getResource().store(); throw new Exception("Error Deployng the VRE failed on second step"); } }else{ - getResource().setFirstReport(VREState.FAILED.getValue()); + getResource().getDeployReport().setState(org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Failed); getResource().store(); logger.info("Deploying of the VRE with id "+this.resourceId+" FAILED on first step"); throw new Exception("Error Deployng the VRE filed on first step"); @@ -123,7 +139,9 @@ public class DeployVREonGHNs extends Thread{ }catch(Exception e){ try { - DBInterface.ExecuteUpdate("UPDATE VRE SET STATUS='"+VREState.FAILED+"' WHERE VRE.id='"+this.resourceId+"';"); + DBInterface.ExecuteUpdate("UPDATE VRE SET STATUS='"+org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Failed+"' WHERE VRE.id='"+this.resourceId+"';"); + getResource().getDeployReport().setState(org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Failed); + getResource().store(); } catch (Exception e1) { logger.error("impossible to update the VRE Status",e1); } @@ -132,23 +150,22 @@ public class DeployVREonGHNs extends Thread{ } - private boolean deployManagerOnVRE(List> ghnList, String candidateGHN) throws GCUBEFault{ + private boolean deployManagerOnVRE(String candidateGhnId) throws GCUBEFault, ResourceException{ 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+"'; "); - if (!resGenericInfo.next()) { - throw new GCUBEFault("The VRE with ID "+this.resourceId+" cannot be retrieved on the DB"); - } - vreName= resGenericInfo.getString(1); } catch (Exception e) { logger.error("HSQLDB Error "+e); throw new GCUBEFault(e); } + getResource().getDeployReport().getResourceManagerDeployingReport().setState(org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Running); + getResource().store(); + + ResourceManagerServiceHandler resourceManagerHandler= new ResourceManagerServiceHandler(){ - @SuppressWarnings({ "static-access", "unchecked" }) + @SuppressWarnings({ "static-access"}) @Override protected Boolean makeCall(ResourceManagerPortType resourceManagerPT) throws Exception { @@ -156,8 +173,7 @@ public class DeployVREonGHNs extends Thread{ try{ String vreName=(String) this.getParameter()[0]; - List> ghnList= (List>) this.getParameter()[1]; - String candidateGHN=(String) this.getParameter()[2]; + String candidateGHN=(String) this.getParameter()[1]; AddResourcesParameters arp= new AddResourcesParameters(); ServiceList services= new ServiceList(); @@ -168,21 +184,7 @@ public class DeployVREonGHNs extends Thread{ service[0].setServiceVersion("1.00.00"); services.setService(service); - //preparing the GHN where will be deployed the VREManager - if (candidateGHN==null){ - Pair ghnId=null; - for (Pair cpl: ghnList){ - if (this.usedhost.contains(cpl.second)){ - ghnId=cpl; - break; - } - } - if (ghnId==null) ghnId=ghnList.get(0); - logger.debug("deploying the ResourceManager for the vre on "+ ghnId.second); - services.setGHN(new String[]{ghnId.first}); - ghnList.remove(ghnId); - }else services.setGHN(new String[]{candidateGHN}); - + services.setGHN(new String[]{candidateGHN}); arp.setServices(services); arp.setTargetScope(this.scope+"/"+vreName); String reportId=resourceManagerPT.addResources(arp); @@ -192,7 +194,7 @@ public class DeployVREonGHNs extends Thread{ Thread.currentThread().sleep(20000); report=resourceManagerPT.getReport(reportId); attempt++; - getResource().setFirstReport(report); + getResource().getDeployReport().getResourceManagerDeployingReport().setResourceManagerReport(report); getResource().store(); }while (!isDeploymentStatusFinished(report) && attempt<10); @@ -205,108 +207,38 @@ public class DeployVREonGHNs extends Thread{ resourceManagerHandler.clearBlackboard(); resourceManagerHandler.setHandled(new GCUBEServiceClientImpl()); - resourceManagerHandler.setParameter(new Object[]{vreName,ghnList,candidateGHN}); + resourceManagerHandler.setParameter(new Object[]{vreName,candidateGhnId}); resourceManagerHandler.scope=this.startingScope; try { resourceManagerHandler.run(); } catch (Exception e) { + getResource().getDeployReport().getResourceManagerDeployingReport().setState(org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Failed); + getResource().store(); logger.error("DeployingVRE step 1 -- failed "+e); return false; } this.vreName= vreName; collectionResourceCreation= new CollectionResourceCreation(this.resourceId, this.vreName); + getResource().getDeployReport().getResourceManagerDeployingReport().setState(org.gcube.vremanagement.vremodeler.stubs.deployreport.State.Finished); + getResource().store(); return resourceManagerHandler.getReturnValue(); } - - - - - + @SuppressWarnings("static-access") private boolean createVRE(List ghnList) throws Exception{ - ResourceManagerPortType rmPortType=null; - int attempt=0; - do{ - try{ - try{ - Thread.currentThread().sleep(30000); - }catch (Exception et){} - - ISClient client = GHNContext.getImplementation(ISClient.class); - GCUBERIQuery query = client.getQuery(GCUBERIQuery.class); - - query.setExpression("declare namespace is = 'http://gcube-system.org/namespaces/informationsystem/registry';" + - " for $outer in collection(\"/db/Profiles/RunningInstance\")//Document/Data/is:Profile/Resource " + - " let $scope:= $outer/Scopes/Scope[string() eq '"+GCUBEScope.getScope(this.startingScope+"/"+this.vreName).toString()+"'] " + - " where count($scope)>0 " + - " and $outer/Profile/ServiceName/string() eq 'ResourceManager' " + - " return $outer"); - - List eprs = new ArrayList(); - for (GCUBERunningInstance instance : client.execute(query, GCUBEScope.getScope(this.startingScope+"/"+this.vreName))) - eprs.add(instance.getAccessPoint().getEndpoint("gcube/vremanagement/ResourceManager")); - if(eprs.size()==0) throw new NoQueryResultException(); - ResourceManagerServiceAddressingLocator vmsal= new ResourceManagerServiceAddressingLocator(); - rmPortType= vmsal.getResourceManagerPortTypePort(eprs.get(0)); - rmPortType = GCUBERemotePortTypeContext.getProxy(rmPortType,GCUBEScope.getScope(this.startingScope+"/"+this.vreName), Integer.parseInt((String)ServiceContext.getContext().getProperty("resourceManagerTimeout", true))); - }catch(Exception e){ - logger.warn(e); - logger.warn("the query for resourceManager returned no result, re-trying in 30 secs ("+attempt+")"); - }finally {attempt++;} - }while(rmPortType==null && attempt<10); + ResourceManagerPortType rmPortType=getResourceMangerPTinVRE(); - if (attempt>=10) throw new Exception("no ResourceMaanger can be retrieved for scope "+GCUBEScope.getScope(this.startingScope+"/"+this.vreName).toString()); + retrieveFunctionalityForReport(); - ResultSet resGenericInfo = DBInterface.queryDB("select VRE.name, VRE.vredesigner, VRE.vremanager, VRE.IntervalTo, VRE.IntervalFrom, VRE.description from VRE where VRE.id='"+this.resourceId+"'; "); - if (!resGenericInfo.next()) throw new GCUBEFault("The VRE with ID "+this.resourceId+" cannot be retrieved"); - - CreateScopeParameters scopeParameter=new CreateScopeParameters(); - OptionsParameters optPar= new OptionsParameters(); - ScopeOption[] scopeOptionList= new ScopeOption[6]; - ScopeOption soDesigner= new ScopeOption(); - soDesigner.setName("DESIGNER"); - soDesigner.setValue(resGenericInfo.getString("vredesigner")); - scopeOptionList[0]= soDesigner; - - ScopeOption soCreator= new ScopeOption(); - soCreator.setName("CREATOR"); - soCreator.setValue(resGenericInfo.getString("vremanager")); - scopeOptionList[1]= soCreator; - - ScopeOption soEndtime= new ScopeOption(); - soEndtime.setName("ENDTIME"); - soEndtime.setValue(KGCUBEResource.toXMLDateAndTime(resGenericInfo.getDate("IntervalTo"))); - scopeOptionList[2]= soEndtime; - - ScopeOption soStarttime= new ScopeOption(); - soStarttime.setName("STARTTIME"); - soStarttime.setValue(KGCUBEResource.toXMLDateAndTime(resGenericInfo.getDate("IntervalFrom"))); - scopeOptionList[3]= soStarttime; - - ScopeOption soDescription= new ScopeOption(); - soDescription.setName("DESCRIPTION"); - soDescription.setValue(resGenericInfo.getString("description")); - scopeOptionList[4]= soDescription; - - ScopeOption soDisplayname= new ScopeOption(); - soDisplayname.setName("DISPLAYNAME"); - soDisplayname.setValue(resGenericInfo.getString("name")); - scopeOptionList[5]= soDisplayname; - - optPar.setScopeOptionList(scopeOptionList); - - scopeParameter.setOptionsParameters(optPar); + CreateScopeParameters scopeParameter=getScopeParameters(); //creating the GenericResources for Portlets and Collection GenericResourcePortlet.createResource(getResource().getId(), vreName); collectionResourceCreation.createAndPublish(); - LayoutCreation createdlayout= new LayoutCreation(getResource().getId(), vreName); - createdlayout.createAndPublishLayout(); - //waiting few seconds to be sure that generic resources will be published Thread.currentThread().sleep(120000); @@ -316,29 +248,12 @@ public class DeployVREonGHNs extends Thread{ List resItemList= new ArrayList(); //retrieving Collection try{ - - ResourceItem resItem; - ResultSet resRelatedCol =DBInterface.queryDB("select VRERELATEDCOLLECTION.collid from VRERELATEDCOLLECTION where VRERELATEDCOLLECTION.vreid='"+this.resourceId+"';"); - while (resRelatedCol.next()){ - resItem= new ResourceItem(); - resItem.setID(resRelatedCol.getString(1)); - logger.debug("selected collection:"+ resItem.getID()); - resItem.setType(GCUBECollection.TYPE); - resItemList.add(resItem); - } + resItemList.addAll(addCollections()); }catch(SQLException sqle){logger.error("Error contacting HSQLDB "+sqle);} //retrieving MDCollection with native MDFormat try{ - ResourceItem resItem; - ResultSet resMdColNative =DBInterface.queryDB("select n.mdcollid from VRERELATEDMETADATAFORMAT AS s, NATIVEMDF as n where s.vreid='"+this.resourceId+"' and n.mdfid=s.mfid;"); - while (resMdColNative.next()){ - resItem= new ResourceItem(); - resItem.setID(resMdColNative.getString(1)); - logger.debug("selected MetadataCollection:"+ resItem.getID()); - resItem.setType(GCUBEMCollection.TYPE); - resItemList.add(resItem); - } + resItemList.addAll(addMetadataFormats()); }catch(SQLException sqle){ logger.error("Error contacting HSQLDB ",sqle); } @@ -349,45 +264,20 @@ public class DeployVREonGHNs extends Thread{ genResItem.setType(GCUBEGenericResource.TYPE); resItemList.add(genResItem); - genResItem= new ResourceItem(); - genResItem.setID(createdlayout.getCreatedResourceId()); - genResItem.setType(GCUBEGenericResource.TYPE); - resItemList.add(genResItem); - //adding the other needed resources try{ - ResourceItem resItem; - ResultSet neededRes =DBInterface.queryDB("select n.id, n.type from NEEDEDRESOURCES AS n;"); - while (neededRes.next()){ - resItem= new ResourceItem(); - resItem.setID(neededRes.getString(1)); - resItem.setType(neededRes.getString(2)); - logger.debug("Needed GenericResources:"+ resItem.getID()); - resItemList.add(resItem); - } + resItemList.addAll(addGenericResources()); }catch(SQLException sqle){ logger.error("Error contacting HSQLDB "+sqle); } - rl.setResource(resItemList.toArray(new ResourceItem[0])); arp.setResources(rl); //retrieve services ServiceList serviceList= new ServiceList(); try{ - ServiceItem servItem; - List listService= new ArrayList(); - ResultSet resService =DBInterface.queryDB("select DISTINCT s.name, s.class, s.version from VRERELATEDFUNCT AS vrf, SERVICES AS s where vrf.vreid='"+this.resourceId+"' AND s.id=vrf.funcid;"); - while (resService.next()){ - servItem= new ServiceItem(); - servItem.setServiceClass(resService.getString("class")); - servItem.setServiceName(resService.getString("name")); - servItem.setServiceVersion(resService.getString("version")); - logger.debug("selected services:"+ servItem.getServiceClass()+" "+servItem.getServiceName()+" "+servItem.getServiceVersion()); - listService.add(servItem); - } - serviceList.setService(listService.toArray(new ServiceItem[0])); + serviceList.setService(addServices().toArray(new ServiceItem[0])); }catch(SQLException sqle){logger.error("Error contacting HSQLDB "+sqle);} //sets the GHNs @@ -398,7 +288,7 @@ public class DeployVREonGHNs extends Thread{ scopeParameter.setAddResourcesParameters(arp); scopeParameter.setName(GCUBEScope.getScope(this.startingScope+"/"+this.vreName).toString()); - String report= "starting"; + String report=null; String reportId=rmPortType.createScope(scopeParameter); int reportAttempt=0; @@ -408,16 +298,14 @@ public class DeployVREonGHNs extends Thread{ }catch (Exception e) {} report=rmPortType.getReport(reportId); reportAttempt++; - getResource().setSecondReport(report); + getResource().getDeployReport().getFunctionalityDeployingReport().setResourceManagerReport(report); getResource().store(); - }while (!isDeploymentStatusFinished(report) && reportAttempt<40); - - + }while (!(isDeploymentStatusFinished(report)) && reportAttempt<40); + logger.info("is something failed in the second step?"+isSomethingFailed(report)); logger.trace("report step 2: "+report); return isSomethingFailed(report); - } @@ -426,7 +314,7 @@ public class DeployVREonGHNs extends Thread{ * @param report the VRE deployment report * @return true if Failed, else false */ - private boolean isSomethingFailed(String report){ + private static boolean isSomethingFailed(String report){ boolean ret = false; String deploymentXpath = "/ResourceReport/DeploymentPlanCreation/Status"; String dependenciesResolutionXpath ="/ResourceReport/Services/Service/DependenciesResolutionStatus"; @@ -470,7 +358,7 @@ public class DeployVREonGHNs extends Thread{ return ret; } - private boolean isDeploymentStatusFinished(String report) { + private static boolean isDeploymentStatusFinished(String report) { boolean ret = false; String xpath = "/ResourceReport/Services/Service/DeploymentActivity/GHN/LastReportReceived/Status"; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); @@ -501,4 +389,166 @@ public class DeployVREonGHNs extends Thread{ return ret; } + private ResourceManagerPortType getResourceMangerPTinVRE() throws Exception{ + ResourceManagerPortType rmPortType = null; + int attempt=0; + do{ + try{ + try{ + Thread.sleep(30000); + }catch (Exception et){} + + ISClient client = GHNContext.getImplementation(ISClient.class); + GCUBERIQuery query = client.getQuery(GCUBERIQuery.class); + + query.setExpression("declare namespace is = 'http://gcube-system.org/namespaces/informationsystem/registry';" + + " for $outer in collection(\"/db/Profiles/RunningInstance\")//Document/Data/is:Profile/Resource " + + " let $scope:= $outer/Scopes/Scope[string() eq '"+GCUBEScope.getScope(this.startingScope+"/"+this.vreName).toString()+"'] " + + " where count($scope)>0 " + + " and $outer/Profile/ServiceName/string() eq 'ResourceManager' " + + " return $outer"); + + List eprs = new ArrayList(); + for (GCUBERunningInstance instance : client.execute(query, GCUBEScope.getScope(this.startingScope+"/"+this.vreName))) + eprs.add(instance.getAccessPoint().getEndpoint("gcube/vremanagement/ResourceManager")); + if(eprs.size()==0) throw new NoQueryResultException(); + ResourceManagerServiceAddressingLocator vmsal= new ResourceManagerServiceAddressingLocator(); + rmPortType= vmsal.getResourceManagerPortTypePort(eprs.get(0)); + rmPortType = GCUBERemotePortTypeContext.getProxy(rmPortType,GCUBEScope.getScope(this.startingScope+"/"+this.vreName), Integer.parseInt((String)ServiceContext.getContext().getProperty("resourceManagerTimeout", true))); + }catch(Exception e){ + logger.warn(e); + logger.warn("the query for resourceManager returned no result, re-trying in 30 secs ("+attempt+")"); + }finally {attempt++;} + }while(rmPortType==null && attempt<10); + + if (attempt>=10) throw new Exception("no ResourceMaanger can be retrieved for scope "+GCUBEScope.getScope(this.startingScope+"/"+this.vreName).toString()); + + return rmPortType; + } + + private CreateScopeParameters getScopeParameters() throws Exception{ + ResultSet resGenericInfo = DBInterface.queryDB("select VRE.name, VRE.vredesigner, VRE.vremanager, VRE.IntervalTo, VRE.IntervalFrom, VRE.description from VRE where VRE.id='"+this.resourceId+"'; "); + if (!resGenericInfo.next()) throw new GCUBEFault("The VRE with ID "+this.resourceId+" cannot be retrieved"); + + CreateScopeParameters scopeParameter=new CreateScopeParameters(); + OptionsParameters optPar= new OptionsParameters(); + ScopeOption[] scopeOptionList= new ScopeOption[6]; + ScopeOption soDesigner= new ScopeOption(); + soDesigner.setName("DESIGNER"); + soDesigner.setValue(resGenericInfo.getString("vredesigner")); + scopeOptionList[0]= soDesigner; + + ScopeOption soCreator= new ScopeOption(); + soCreator.setName("CREATOR"); + soCreator.setValue(resGenericInfo.getString("vremanager")); + scopeOptionList[1]= soCreator; + + ScopeOption soEndtime= new ScopeOption(); + soEndtime.setName("ENDTIME"); + soEndtime.setValue(KGCUBEResource.toXMLDateAndTime(resGenericInfo.getDate("IntervalTo"))); + scopeOptionList[2]= soEndtime; + + ScopeOption soStarttime= new ScopeOption(); + soStarttime.setName("STARTTIME"); + soStarttime.setValue(KGCUBEResource.toXMLDateAndTime(resGenericInfo.getDate("IntervalFrom"))); + scopeOptionList[3]= soStarttime; + + ScopeOption soDescription= new ScopeOption(); + soDescription.setName("DESCRIPTION"); + soDescription.setValue(resGenericInfo.getString("description")); + scopeOptionList[4]= soDescription; + + ScopeOption soDisplayname= new ScopeOption(); + soDisplayname.setName("DISPLAYNAME"); + soDisplayname.setValue(resGenericInfo.getString("name")); + scopeOptionList[5]= soDisplayname; + + optPar.setScopeOptionList(scopeOptionList); + + scopeParameter.setOptionsParameters(optPar); + return scopeParameter; + } + + private List addCollections() throws Exception{ + List resItemList= new ArrayList(); + ResourceItem resItem; + ResultSet resRelatedCol =DBInterface.queryDB("select VRERELATEDCOLLECTION.collid from VRERELATEDCOLLECTION where VRERELATEDCOLLECTION.vreid='"+this.resourceId+"';"); + while (resRelatedCol.next()){ + resItem= new ResourceItem(); + resItem.setID(resRelatedCol.getString(1)); + logger.trace("selected collection:"+ resItem.getID()); + resItem.setType(GCUBECollection.TYPE); + resItemList.add(resItem); + } + return resItemList; + } + + private List addMetadataFormats() throws Exception{ + List resItemList= new ArrayList(); + ResourceItem resItem; + ResultSet resMdColNative =DBInterface.queryDB("select n.mdcollid from VRERELATEDMETADATAFORMAT AS s, NATIVEMDF as n where s.vreid='"+this.resourceId+"' and n.mdfid=s.mfid;"); + while (resMdColNative.next()){ + resItem= new ResourceItem(); + resItem.setID(resMdColNative.getString(1)); + logger.trace("selected MetadataCollection:"+ resItem.getID()); + resItem.setType(GCUBEMCollection.TYPE); + resItemList.add(resItem); + } + return resItemList; + } + + private List addGenericResources() throws Exception{ + List resItemList= new ArrayList(); + ResourceItem resItem; + ResultSet neededRes =DBInterface.queryDB("select n.id, n.type from NEEDEDRESOURCES AS n;"); + while (neededRes.next()){ + resItem= new ResourceItem(); + resItem.setID(neededRes.getString(1)); + resItem.setType(neededRes.getString(2)); + logger.trace("Needed GenericResources:"+ resItem.getID()); + resItemList.add(resItem); + } + return resItemList; + } + + private List addServices() throws Exception{ + ServiceItem servItem; + List listServices= new ArrayList(); + ResultSet resService =DBInterface.queryDB("select DISTINCT s.name, s.class, s.version from VRERELATEDFUNCT AS vrf, SERVICES AS s where vrf.vreid='"+this.resourceId+"' AND s.id=vrf.funcid;"); + while (resService.next()){ + servItem= new ServiceItem(); + servItem.setServiceClass(resService.getString("class")); + servItem.setServiceName(resService.getString("name")); + servItem.setServiceVersion(resService.getString("version")); + logger.trace("selected services:"+ servItem.getServiceClass()+" "+servItem.getServiceName()+" "+servItem.getServiceVersion()); + listServices.add(servItem); + } + 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/deploy/GHNstoUse.java b/src/org/gcube/vremanagement/vremodeler/impl/deploy/GHNstoUse.java new file mode 100644 index 0000000..86f1795 --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/impl/deploy/GHNstoUse.java @@ -0,0 +1,36 @@ +package org.gcube.vremanagement.vremodeler.impl.deploy; + +import java.util.ArrayList; +import java.util.List; + +public class GHNstoUse{ + String candidateForRM; + List ghns= new ArrayList(); + + public GHNstoUse(){} + + public GHNstoUse(String candidateForRM, List ghns) { + super(); + this.candidateForRM = candidateForRM; + this.ghns = ghns; + } + + public String getCandidateForRM() { + return candidateForRM; + } + + public void setCandidateForRM(String candidateForRM) { + this.candidateForRM = candidateForRM; + } + + public List getGhns() { + return ghns; + } + + public void setGhns(List ghns) { + this.ghns = ghns; + } + + + +} \ No newline at end of file diff --git a/src/org/gcube/vremanagement/vremodeler/portallayout/LayoutCreation.java b/src/org/gcube/vremanagement/vremodeler/portallayout/LayoutCreation.java deleted file mode 100644 index 6ca2337..0000000 --- a/src/org/gcube/vremanagement/vremodeler/portallayout/LayoutCreation.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.gcube.vremanagement.vremodeler.portallayout; - -import java.io.StringReader; -import java.util.List; -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.common.core.scope.GCUBEScope; -import org.gcube.common.core.utils.logging.GCUBELog; -import org.gcube.vremanagement.vremodeler.impl.ServiceContext; - -public class LayoutCreation { - - private GCUBELog logger= new GCUBELog(LayoutCreation.class); - - private GCUBEGenericResource resource; - private String vreName; - private String createdResourceId= null; - - public String getCreatedResourceId(){ - return this.createdResourceId; - } - - private void publish(String body) throws Exception{ - resource.setBody(body); - resource.setDescription("the gridsphere layout for vre: "+ServiceContext.getContext().getScope()+"/"+this.vreName); - String[] splitScope=ServiceContext.getContext().getScope().toString().split("/"); - resource.setName("Layout_"+splitScope[1]+"_"+splitScope[2]+"_"+this.vreName); - resource.setSecondaryType("LayoutResource"); - resource.addScope(GCUBEScope.getScope(ServiceContext.getContext().getScope()+"/"+this.vreName)); - ISPublisher publisher= GHNContext.getImplementation(ISPublisher.class); - resource.load(new StringReader(publisher.registerGCUBEResource(resource, GCUBEScope.getScope(ServiceContext.getContext().getScope()+"/"+this.vreName), ServiceContext.getContext()))); - this.createdResourceId= resource.getID(); - } - - - public LayoutCreation(String vreId, String vreName){ - this.vreName= vreName; - try{ - this.resource= GHNContext.getImplementation(GCUBEGenericResource.class); - }catch(Exception e){e.printStackTrace();} - } - - public GCUBEGenericResource createAndPublishLayout() throws Exception{ - ISClient client= GHNContext.getImplementation(ISClient.class); - GCUBEGenericResourceQuery query= client.getQuery(GCUBEGenericResourceQuery.class); - query.addAtomicConditions(new AtomicCondition("/Profile/SecondaryType","VREModelerResource"), new AtomicCondition("/Profile/Name","DefaultLayout")); - List defaultLayoutResourceList= client.execute(query, ServiceContext.getContext().getScope()); - if (defaultLayoutResourceList.size()>0) - this.publish(defaultLayoutResourceList.get(0).getBody()); - else{ - logger.debug("no DefaultLayout resource found, creating the VRE with an empty one"); - this.publish("VREManagementLayoutCreatorlayoutcreator#LayoutcreatorPortlet
"); - - } - return resource; - } - -} diff --git a/src/org/gcube/vremanagement/vremodeler/resources/handlers/GHNHandler.java b/src/org/gcube/vremanagement/vremodeler/resources/handlers/GHNHandler.java index 6a54f58..c9efcde 100644 --- a/src/org/gcube/vremanagement/vremodeler/resources/handlers/GHNHandler.java +++ b/src/org/gcube/vremanagement/vremodeler/resources/handlers/GHNHandler.java @@ -29,7 +29,7 @@ public class GHNHandler implements ResourceHandler { for (GCUBEHostingNode ghn:ghnList) try{ insert(ghn); - }catch(Exception e){logger.error("error insertin values in "+tableName, e);} + }catch(Exception e){logger.error("error inserting values in "+tableName, e);} } private void insert(GCUBEHostingNode ghn) throws Exception { @@ -45,6 +45,7 @@ public class GHNHandler implements ResourceHandler { row.add(ghn.getSite().getLocation()); row.add(ghn.getSite().getCountry()); row.add(ghn.getSite().getDomain()); + row.add("false"); DBInterface.connect(); DBInterface.insertInto(tableName, row.toArray(new String[0])); RunningInstancesHandler riHandler= new RunningInstancesHandler(ghn.getID()); diff --git a/src/org/gcube/vremanagement/vremodeler/resources/handlers/NativeMetadataFormatHandler.java b/src/org/gcube/vremanagement/vremodeler/resources/handlers/NativeMetadataFormatHandler.java index 45a33c5..6693b8f 100644 --- a/src/org/gcube/vremanagement/vremodeler/resources/handlers/NativeMetadataFormatHandler.java +++ b/src/org/gcube/vremanagement/vremodeler/resources/handlers/NativeMetadataFormatHandler.java @@ -1,12 +1,12 @@ package org.gcube.vremanagement.vremodeler.resources.handlers; -import org.gcube.common.core.utils.logging.GCUBELog; +//import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.vremanagement.vremodeler.db.DBInterface; import org.gcube.vremanagement.vremodeler.resources.MFRelationNative; public class NativeMetadataFormatHandler implements ResourceHandler { - private static GCUBELog logger= new GCUBELog(NativeMetadataFormatHandler.class); + //private static GCUBELog logger= new GCUBELog(NativeMetadataFormatHandler.class); public static final String tableName="NATIVEMDF"; diff --git a/src/org/gcube/vremanagement/vremodeler/resources/kxml/KBody.java b/src/org/gcube/vremanagement/vremodeler/resources/kxml/KBody.java index 8f82287..e7c6169 100644 --- a/src/org/gcube/vremanagement/vremodeler/resources/kxml/KBody.java +++ b/src/org/gcube/vremanagement/vremodeler/resources/kxml/KBody.java @@ -2,19 +2,6 @@ package org.gcube.vremanagement.vremodeler.resources.kxml; import static org.gcube.common.resources.kxml.KGCUBEResource.NS; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.Reader; -import java.io.Writer; -import java.text.SimpleDateFormat; - -import org.gcube.common.core.resources.GCUBEGenericResource; -import org.gcube.common.core.resources.service.Dependency; -import org.gcube.common.core.resources.service.Dependency.Service; -import org.gcube.common.core.resources.service.Package.ScopeLevel; -import org.gcube.common.resources.kxml.GCUBEResourceImpl; -import org.gcube.common.resources.kxml.KGCUBEResource; -import org.gcube.common.resources.kxml.service.version.VersionSpecificationParser; import org.gcube.vremanagement.vremodeler.resources.Body; import org.gcube.vremanagement.vremodeler.resources.MainFunctionality; import org.kxml2.io.KXmlParser; diff --git a/src/org/gcube/vremanagement/vremodeler/stubs/Utils.java b/src/org/gcube/vremanagement/vremodeler/stubs/Utils.java new file mode 100644 index 0000000..e8e5a0e --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/stubs/Utils.java @@ -0,0 +1,19 @@ +package org.gcube.vremanagement.vremodeler.stubs; + +import java.io.StringReader; + +import org.gcube.vremanagement.vremodeler.stubs.deployreport.DeployReport; + +import com.thoughtworks.xstream.XStream; + +public class Utils { + + public static String toXML(DeployReport report){ + return new XStream().toXML(report); + } + + public static DeployReport fromXML(String report){ + return (DeployReport) new XStream().fromXML(new StringReader(report)); + } + +} diff --git a/src/org/gcube/vremanagement/vremodeler/stubs/VREState.java b/src/org/gcube/vremanagement/vremodeler/stubs/VREState.java deleted file mode 100644 index 925ac91..0000000 --- a/src/org/gcube/vremanagement/vremodeler/stubs/VREState.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.gcube.vremanagement.vremodeler.stubs; - -public enum VREState { - - DEPLOYED("Deployed"), - IN_PROGRESS("In Progress"), - FAILED("Failed"), - PENDING("Pending"), - DEPLOYING("Deploying"); - - private String value; - - VREState(String value){ - this.value= value; - } - - public String getValue(){ - return this.value; - } -} diff --git a/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/DeployReport.java b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/DeployReport.java new file mode 100644 index 0000000..9a39701 --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/DeployReport.java @@ -0,0 +1,97 @@ +package org.gcube.vremanagement.vremodeler.stubs.deployreport; + +import java.io.Serializable; + +/** + * + * @author lucio + * + */ +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 resourceMaangerDeployingReport; + private FunctionalityDeployingReport functionalityDeployingReport; + + /** + * + * @return + */ + public State getState() { + return state; + } + + /** + * + * @param state + */ + public void setState(State state) { + this.state = state; + } + + /** + * + * @return + */ + public GHNonCloudReport getCloudDeployingReport() { + return cloudDeployingReport; + } + + /** + * + * @param cloudDeployingReport + */ + public void setCloudDeployingReport(GHNonCloudReport cloudDeployingReport) { + this.cloudDeployingReport = cloudDeployingReport; + } + + /** + * + * @return + */ + public ResourceManagerDeployingReport getResourceManagerDeployingReport() { + return resourceMaangerDeployingReport; + } + + /** + * + * @param resourceMaangerDeployingReport + */ + public void setResourceMaangerDeployingReport( + ResourceManagerDeployingReport resourceMaangerDeployingReport) { + this.resourceMaangerDeployingReport = resourceMaangerDeployingReport; + } + + /** + * + * @return + */ + public FunctionalityDeployingReport getFunctionalityDeployingReport() { + return functionalityDeployingReport; + } + + /** + * + * @param functionalityDeployingReport + */ + public void setFunctionalityDeployingReport( + FunctionalityDeployingReport functionalityDeployingReport) { + this.functionalityDeployingReport = functionalityDeployingReport; + } + +} diff --git a/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/FunctionalityDeployingReport.java b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/FunctionalityDeployingReport.java new file mode 100644 index 0000000..40ca748 --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/FunctionalityDeployingReport.java @@ -0,0 +1,51 @@ +package org.gcube.vremanagement.vremodeler.stubs.deployreport; + +import java.io.Serializable; +import java.util.Hashtable; +import java.util.List; + +public class FunctionalityDeployingReport implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -5667226186772008010L; + + private Hashtable> functionalityTable= new Hashtable>(); + + private String resourceManagerReport; + private State state; + + public FunctionalityDeployingReport(){ + this.state= State.Waiting; + this.functionalityTable= new Hashtable>(); + } + + + + public State getState() { + return state; + } + + public void setState(State state) { + this.state = state; + } + + public Hashtable> getFunctionalityTable() { + return functionalityTable; + } + + public void setFunctionalityTable( + Hashtable> functionalityTable) { + this.functionalityTable = functionalityTable; + } + + public String getResourceManagerReport() { + return resourceManagerReport; + } + + public void setResourceManagerReport(String resourceManagerReport) { + this.resourceManagerReport = resourceManagerReport; + } + +} diff --git a/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/FunctionalityReport.java b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/FunctionalityReport.java new file mode 100644 index 0000000..f592c7b --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/FunctionalityReport.java @@ -0,0 +1,60 @@ +package org.gcube.vremanagement.vremodeler.stubs.deployreport; + +import java.io.Serializable; + +public class FunctionalityReport implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 1104477953274508866L; + + private State state; + + private String functionalityId; + private String functionalityName; + + public FunctionalityReport(){ + this.state=State.Waiting; + } + + public State getState() { + return state; + } + + + + public void setState(State state) { + this.state = state; + } + + + + public String getFunctionalityId() { + return functionalityId; + } + + + + public void setFunctionalityId(String functionalityId) { + this.functionalityId = functionalityId; + } + + + + public String getFunctionalityName() { + return functionalityName; + } + + + + public void setFunctionalityName(String functioanlityName) { + this.functionalityName = functioanlityName; + } + + + + public int hashCode(){ + return functionalityId.hashCode(); + } +} \ No newline at end of file diff --git a/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/GHNonCloudReport.java b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/GHNonCloudReport.java new file mode 100644 index 0000000..d53e974 --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/GHNonCloudReport.java @@ -0,0 +1,39 @@ +package org.gcube.vremanagement.vremodeler.stubs.deployreport; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class GHNonCloudReport implements Serializable { + /** + * + */ + private static final long serialVersionUID = -1418965279876312220L; + + private State state; + + private List deployingState= new ArrayList(); + + public GHNonCloudReport() { + this.state= State.Waiting; + Collections.fill(this.deployingState, State.Waiting); + } + + + public State getState() { + return state; + } + + public void setState(State state) { + this.state = state; + } + + public List getDeployingState() { + return deployingState; + } + + public void setDeployingState(List deployingState) { + this.deployingState = deployingState; + } +} diff --git a/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/ResourceManagerDeployingReport.java b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/ResourceManagerDeployingReport.java new file mode 100644 index 0000000..37ead65 --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/ResourceManagerDeployingReport.java @@ -0,0 +1,39 @@ +package org.gcube.vremanagement.vremodeler.stubs.deployreport; + +import java.io.Serializable; + +public class ResourceManagerDeployingReport implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 8076338857724950353L; + + State state; + + private String resourceManagerReport; + + public ResourceManagerDeployingReport(){ + this.state= State.Waiting; + this.resourceManagerReport=null; + } + + + public State getState() { + return state; + } + + public void setState(State state) { + this.state = state; + } + + public String getResourceManagerReport() { + return resourceManagerReport; + } + + public void setResourceManagerReport(String resourceManagerReport) { + this.resourceManagerReport = resourceManagerReport; + } + + +} diff --git a/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/ServiceReport.java b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/ServiceReport.java new file mode 100644 index 0000000..7922863 --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/ServiceReport.java @@ -0,0 +1,47 @@ +package org.gcube.vremanagement.vremodeler.stubs.deployreport; + +import java.io.Serializable; + +public class ServiceReport implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -6061025649581168168L; + + private State state; + + private String serviceClass; + private String serviceName; + private String serviceVersion; + + public ServiceReport(){ + this.state= State.Waiting; + } + + public State getState() { + return state; + } + public void setState(State state) { + this.state = state; + } + public String getServiceClass() { + return serviceClass; + } + public void setServiceClass(String serviceClass) { + this.serviceClass = serviceClass; + } + public String getServiceName() { + return serviceName; + } + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + public String getServiceVersion() { + return serviceVersion; + } + public void setServiceVersion(String serviceVersion) { + this.serviceVersion = serviceVersion; + } + +} \ No newline at end of file diff --git a/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/State.java b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/State.java new file mode 100644 index 0000000..917006a --- /dev/null +++ b/src/org/gcube/vremanagement/vremodeler/stubs/deployreport/State.java @@ -0,0 +1,12 @@ +package org.gcube.vremanagement.vremodeler.stubs.deployreport; + +import java.io.Serializable; + +public enum State implements Serializable { + Running, + Failed, + Finished, + Skipped, + Pending, + Waiting +}