diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..61a75fa --- /dev/null +++ b/.classpath @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..f952e19 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + applicationSupportLayerVREManagement + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..bf0aaeb --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,4 @@ +#Thu May 02 12:29:42 CEST 2013 +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..8d6150f --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,6 @@ +#Thu May 02 12:28:02 CEST 2013 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..b2940b3 --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,5 @@ +#Thu May 02 12:23:01 CEST 2013 +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/distro/INSTALL b/distro/INSTALL new file mode 100644 index 0000000..9bcbb15 --- /dev/null +++ b/distro/INSTALL @@ -0,0 +1 @@ +Used as a library in the gCube Framework \ No newline at end of file diff --git a/distro/LICENSE b/distro/LICENSE new file mode 100644 index 0000000..cc51139 --- /dev/null +++ b/distro/LICENSE @@ -0,0 +1,6 @@ +gCube System - License +------------------------------------------------------------ + +The gCube/gCore software is licensed as Free Open Source software conveying to the EUPL (http://ec.europa.eu/idabc/eupl). +The software and documentation is provided by its authors/distributors "as is" and no expressed or +implied warranty is given for its use, quality or fitness for a particular case. \ No newline at end of file diff --git a/distro/MAINTAINERS b/distro/MAINTAINERS new file mode 100644 index 0000000..17d3dd2 --- /dev/null +++ b/distro/MAINTAINERS @@ -0,0 +1,2 @@ +Rena Tsantouli (e.tsantoylh@di.uoa.gr), + National Kapodistrian University of Athens, Department Informatics. \ No newline at end of file diff --git a/distro/README b/distro/README new file mode 100644 index 0000000..c5b3433 --- /dev/null +++ b/distro/README @@ -0,0 +1,50 @@ +The gCube System - Process Optimisation - Planner Service +------------------------------------------------------------ + +This work is partially funded by the European Commission in the +context of the D4Science project (www.d4science.eu), under the 1st call of FP7 IST priority. + + +Authors +------- + +* Valia Tsagkalidou (v.tsagkalidou@di.uoa.gr), + National Kapodistrian University of Athens, Department Informatics. + +* Rena Tsantouli (e.tsantoylh@di.uoa.gr), + National Kapodistrian University of Athens, Department Informatics. + +* Massimiliano Assante + Institute of Information Science and Technologies (ISTI), CNR , Italy + +Version and Release Date +------------------------ + +v. 3.0.0, 17/05/2010 + + +Description +----------- +Provides functionality that helps presentation layer to use gCube services + + +Download information +-------------------- +Source code is available from SVN: +https://svn.d4science.research-infrastructures.eu/gcube/trunk/application-support-layer/applicationSupportLayerVREManagement/ + +Binaries can be downloaded from: +http://software.d4science.research-infrastructures.eu/ + + +Documentation +------------- +Documentation is available on-line from the Projects Documentation Wiki: + +https://gcube.wiki.gcube-system.org/gcube/index.php/ASL + + +Licensing +--------- + +This software is licensed under the terms you may find in the file named "LICENSE" in this directory. \ No newline at end of file diff --git a/distro/changelog.xml b/distro/changelog.xml new file mode 100644 index 0000000..3704e33 --- /dev/null +++ b/distro/changelog.xml @@ -0,0 +1,6 @@ + + +Added support to the new VRE Deployer portlet +Added support to the new VRE Manager service + + \ No newline at end of file diff --git a/distro/descriptor.xml b/distro/descriptor.xml new file mode 100644 index 0000000..c468f13 --- /dev/null +++ b/distro/descriptor.xml @@ -0,0 +1,48 @@ + + servicearchive + + tar.gz + + / + + + ${distroDirectory} + / + true + + README + LICENSE + INSTALL + MAINTAINERS + changelog.xml + + 755 + true + + + target/apidocs + /${artifactId}/doc/api + true + 755 + + + + + ${distroDirectory}/profile.xml + ./ + true + + + target/${build.finalName}.jar + /${artifactId} + + + ${distroDirectory}/svnpath.txt + /${artifactId} + true + + + \ No newline at end of file diff --git a/distro/profile.xml b/distro/profile.xml new file mode 100644 index 0000000..cbf4804 --- /dev/null +++ b/distro/profile.xml @@ -0,0 +1,25 @@ + + + + Library + + ASL Social Library + ApplicationSupportLayer + ${artifactId} + 1.0.0 + + + ${artifactId} + ${version} + + ${groupId} + ${artifactId} + ${version} + + + ${build.finalName}.jar + + + + + diff --git a/distro/svnpath.txt b/distro/svnpath.txt new file mode 100644 index 0000000..edacb04 --- /dev/null +++ b/distro/svnpath.txt @@ -0,0 +1 @@ +${scm.url} \ No newline at end of file diff --git a/etc/ehcache.xml b/etc/ehcache.xml new file mode 100644 index 0000000..38fbfe7 --- /dev/null +++ b/etc/ehcache.xml @@ -0,0 +1,538 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/etc/profile.xml b/etc/profile.xml new file mode 100644 index 0000000..f570de2 --- /dev/null +++ b/etc/profile.xml @@ -0,0 +1,67 @@ + + + + Library + + ASLVRE + ApplicationSupportLayer + ASLVRE + 1.0.0 + + + ASLVRE + ASLVRE + 2.0.3 + + + + ApplicationSupportLayer + ASLCore + 1.0.0 + + ASLCore + [2.0.0,3.0.0) + + false + + + + InformationSystem + ISCache + 1.0.0 + + ISCache + [1.0.0,2.0.0) + + false + + + + VREManagement + SoftwareRepository + 1.0.0 + + SoftwareRepository-stubs + [1.0.0,2.0.0) + + false + + + + VREManagement + VREModeler + 1.0.0 + + VREModeler-stubs + [1.0.0,2.0.0) + + false + + + + ApplicationSupportLibraryVRE.jar + + + + + diff --git a/etc/settings.properties b/etc/settings.properties new file mode 100644 index 0000000..8ce600a --- /dev/null +++ b/etc/settings.properties @@ -0,0 +1 @@ +sharedDir=${catalina.home}/shared/d4s \ No newline at end of file diff --git a/etc/vomsAPI.properties b/etc/vomsAPI.properties new file mode 100644 index 0000000..0c7bd2f --- /dev/null +++ b/etc/vomsAPI.properties @@ -0,0 +1,18 @@ +MYPROXY_HOST=grids04.eng.it +MYPROXY_PORT=7512 +PROXIES_DIR=#path to dir where the proxy files will be storeed# +HOST_CERT=#myproxy certificate# +HOST_KEY=#myproxy key# + +NEW_SERVLET_HOST=dl14.di.uoa.gr #hostname for voms servlet# +NEW_SERVLET_PORT=8888 #port where voms servlet is listening# +NEW_SERVLET_PATH=/VOMSServlet/VOMSServlet #voms servlet path# +NEW_SERVLET_PROTOCOL=http # protocol: http/https# + +KEY_STORE=#path to *.p12 key file# +KEY_STORE_TYPE=PKCS12 +KEY_STORE_PWD=#password for the *.p12 key file# + +TRUST_STORE=#path to trust store file# +TRUST_STORE_PWD=#password for the trust store file# +TRUST_STORE_TYPE=JKS \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..9c8a57a --- /dev/null +++ b/pom.xml @@ -0,0 +1,173 @@ + + 4.0.0 + + maven-parent + org.gcube.tools + 1.0.0 + + + + org.gcube.applicationsupportlayer + aslvre + 3.2.0-SNAPSHOT + jar + VRE Management ASL Extension + + VRE Management + + + scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/application-support-layer/${project.artifactId} + scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/trunk/application-support-layer/${project.artifactId} + http://svn.d4science.research-infrastructures.eu/gcube/trunk/application-support-layer/${project.artifactId} + + + distro + 1.6 + 1.6 + + UTF-8 + UTF-8 + + + + org.gcube.core + gcf + [1.5.0-SNAPSHOT, 2.0.0-SNAPSHOT) + provided + + + org.gcube.applicationsupportlayer + aslcore + [3.2.1-SNAPSHOT, 4.0.0-SNAPSHOT) + provided + + + org.gcube.resourcemanagement + vremodeler-stubs + [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) + provided + + + org.gcube.resourcemanagement + ghnmanager-stubs + [1.5.0-SNAPSHOT, 2.0.0-SNAPSHOT) + provided + + + com.liferay.portal + portal-service + 6.0.6 + + + log4j + log4j + 1.2.6 + + + javax.portlet + portlet-api + 2.0 + provided + + + junit + junit + 3.8.1 + test + + + + + + src/main/java + + **/*.* + + + + + + maven-compiler-plugin + 3.0 + + 1.6 + 1.6 + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.2 + + + + test-jar + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12 + + true + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + copy-profile + install + + copy-resources + + + target + + + ${distroDirectory} + true + + profile.xml + + + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.2 + + + ${distroDirectory}/descriptor.xml + + + + fully.qualified.MainClass + + + + + + servicearchive + install + + single + + + + + + + diff --git a/src/main/java/org/gcube/application/framework/vremanagement/vremanagement/ISInfoI.java b/src/main/java/org/gcube/application/framework/vremanagement/vremanagement/ISInfoI.java new file mode 100644 index 0000000..826b80a --- /dev/null +++ b/src/main/java/org/gcube/application/framework/vremanagement/vremanagement/ISInfoI.java @@ -0,0 +1,121 @@ +package org.gcube.application.framework.vremanagement.vremanagement; + +import java.io.File; +import java.util.List; + +import org.gcube.common.core.informationsystem.client.RPDocument; +import org.gcube.common.core.informationsystem.client.XMLResult; +import org.gcube.common.core.resources.GCUBECollection; +import org.gcube.common.core.resources.GCUBEMCollection; +import org.gcube.common.core.scope.GCUBEScope; + +/** + * @author valia + * + */ +public interface ISInfoI { + + /** + * @param query an XQuery to be submitted on IS + * @return a list of XMLResults that represent resources form IS (like RIs, Generic Resources, Collections, etc) + */ + public List queryIS(String query); + + /** + * @param type the of the WSs to be retrieved + * @return a list of RPDocuments + */ + public List getWS(String type); + + /** + * Adds a GHN to the active VRE + * @param url the GHN url + */ + public void addGHNToScope(String url); + + /** + * Adds a service to the active VRE + * @param url the Running Instance url + * @param className the name of the class where the RI will belong + * @param name the name of teh service it provides + */ + public void addRIToScope(String url, String className, String name); + + /** + * @param namePort GHN name:port + * @return true if GHN exists, otherwise false + */ + public boolean existsGHN(String namePort); + + + /** + * @param id the id of the external running instance to be removed + */ + public void removeExternalRIToVRE(String id); + + /** + * @param file the file that contains the external running instance to be added + */ + public void addExternalRIToVRE(File file); + + /** + * @param url server:port of the GHN to be removed + */ + public void removeGHNToScope(String url); + + /** + * @param scope the scope of the collections. + * @return a list of collections profile. + * @throws Exception + */ + public List getCollections(GCUBEScope scope)throws Exception; + + /** + * @param scope the scope of the metadata collections. + * @param collectionID the associated collection. + * @return a list of metadata collections profile. + * @throws Exception + */ + public List getMCollections(GCUBEScope scope, String collectionID)throws Exception; + + + /** + * @param scope the indices scope. + * @param mcollectionID the metadata collection id. + * @return a list of Resource document. + * @throws Exception + */ + public List getXMLIndices(GCUBEScope scope, String mcollectionID) throws Exception; + + + + /** + * Return all indices associated with a given metadata collection. + * @param scope the indices scope. + * @param mcollectionID the metadata collection id. + * @return a list of Resource document. + * @throws Exception + */ + public List getIndices(GCUBEScope scope, String mcollectionID) throws Exception; + + + + /** + * @param scope the indices scope. + * @param collectionID the collection id. + * @return a list of Resource document. + * @throws Exception + */ + public List getCollectionIndices(GCUBEScope scope, String collectionID) throws Exception; + + + + /** + * @param scope the collection scope. + * @param collectionID the collection id. + * @return a collection profile. + * @throws Exception + */ + public GCUBECollection getCollection(GCUBEScope scope, String collectionID) throws Exception; +} + diff --git a/src/main/java/org/gcube/application/framework/vremanagement/vremanagement/VREGeneratorInterface.java b/src/main/java/org/gcube/application/framework/vremanagement/vremanagement/VREGeneratorInterface.java new file mode 100644 index 0000000..35a9cd7 --- /dev/null +++ b/src/main/java/org/gcube/application/framework/vremanagement/vremanagement/VREGeneratorInterface.java @@ -0,0 +1,97 @@ +package org.gcube.application.framework.vremanagement.vremanagement; + +import java.rmi.RemoteException; +import java.util.List; + +import org.gcube.vremanagement.vremodeler.stubs.FunctionalityList; +import org.gcube.vremanagement.vremodeler.stubs.FunctionalityNodes; +import org.gcube.vremanagement.vremodeler.stubs.GHNType; +import org.gcube.vremanagement.vremodeler.stubs.GHNsPerFunctionality; +import org.gcube.vremanagement.vremodeler.stubs.SelectedResourceDescriptionType; +import org.gcube.vremanagement.vremodeler.stubs.VREDescription; + +public interface VREGeneratorInterface { + + + /** + * @return what the vVRE modeler returns + * @throws RemoteException + */ + String checkVREStatus() + throws RemoteException; + + /** + * @throws RemoteException + */ + void deployVRE() throws RemoteException; + + /** + * @return what the vVRE modeler returns + * @throws RemoteException + */ + List getGHNs() throws RemoteException; + + /** + * @return what the vVRE modeler returns + * @throws RemoteException + */ + VREDescription getVREModel() throws RemoteException; + + /** + * @return what the vVRE modeler returns + * @throws RemoteException + */ + FunctionalityList getFunctionality() throws Exception; + + + FunctionalityNodes getSelectedFunctionality() throws Exception; + + + /** + * @param selectedGHNIds the GHNs selected + * @throws RemoteException + */ + void setGHNs(String[] selectedGHNIds) throws RemoteException; + + /** + * + * @return GHNsPerFunctionality + */ + GHNsPerFunctionality[] getGHNsPerFunctionality() throws RemoteException; + /** + * @param VREName the VRE name + * @param VREDescription a description for the VRE + * @param VREDesigner the VRE designer + * @param VREManager the VRE manager + * @param startTime start time + * @param endTime end time + * @throws RemoteException + */ + void setVREModel(String VREName, String VREDescription, String VREDesigner, String VREManager, long startTime, long endTime) throws RemoteException; + + /** + * @throws RemoteException + */ + void setVREtoPendingState() + throws RemoteException; + + /** + * @param csIDElement + * @param functionalityIDElement + * @throws RemoteException + */ + void setFunctionality(int[] funcIds, SelectedResourceDescriptionType[] selResDesc) throws RemoteException; + + /** + * @return + */ + String getVREepr(); + + boolean isCloudAvailable(); + + boolean setCloudDeploy(int virtualMachines); + + boolean isCloudSelected(); + + int getCloudVMSelected(); +} diff --git a/src/main/java/org/gcube/application/framework/vremanagement/vremanagement/impl/ISInfo.java b/src/main/java/org/gcube/application/framework/vremanagement/vremanagement/impl/ISInfo.java new file mode 100644 index 0000000..06d68bb --- /dev/null +++ b/src/main/java/org/gcube/application/framework/vremanagement/vremanagement/impl/ISInfo.java @@ -0,0 +1,413 @@ +package org.gcube.application.framework.vremanagement.vremanagement.impl; + +import java.io.File; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.List; + +import org.apache.axis.message.addressing.Address; +import org.apache.axis.message.addressing.EndpointReferenceType; +import org.gcube.application.framework.core.security.PortalSecurityManager; +import org.gcube.application.framework.core.security.ServiceContextManager; +import org.gcube.application.framework.core.session.ASLSession; +import org.gcube.application.framework.vremanagement.vremanagement.ISInfoI; +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.RPDocument; +import org.gcube.common.core.informationsystem.client.XMLResult; +import org.gcube.common.core.informationsystem.client.queries.GCUBECollectionQuery; +import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery; +import org.gcube.common.core.informationsystem.client.queries.GCUBEMCollectionQuery; +import org.gcube.common.core.informationsystem.client.queries.WSResourceQuery; +import org.gcube.common.core.informationsystem.publisher.ISPublisher; +import org.gcube.common.core.informationsystem.publisher.ISPublisherException; +import org.gcube.common.core.resources.GCUBECollection; +import org.gcube.common.core.resources.GCUBEExternalRunningInstance; +import org.gcube.common.core.resources.GCUBEMCollection; +import org.gcube.common.core.scope.GCUBEScope; +import org.gcube.common.vremanagement.ghnmanager.stubs.AddScopeInputParams; +import org.gcube.common.vremanagement.ghnmanager.stubs.GHNManagerPortType; +import org.gcube.common.vremanagement.ghnmanager.stubs.ScopeRIParams; +import org.gcube.common.vremanagement.ghnmanager.stubs.service.GHNManagerServiceAddressingLocator; + +/** + * @author Valia Tsaqgkalidou (NKUA) + */ +public class ISInfo implements ISInfoI { + + /** + * ASLSession to be used + */ + protected ASLSession session; + /** + * is client in order to query IS + */ + protected static ISClient client = null; + + protected static ISPublisher publisher = null; + + /** + * Constructs a ISInfo object + * @param session the D4Science session to be used for retrieving information needed + */ + public ISInfo(ASLSession session) + { + this.session = session; + try { + publisher = GHNContext.getImplementation(ISPublisher.class); + } catch (Exception e) { + e.printStackTrace(); + } + if(client == null) + { + try { + client = GHNContext.getImplementation(ISClient.class); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + client = null; + } + } + } + + /** {@inheritDoc}*/ + public List queryIS(String query) { + try { + GCUBEGenericQuery queryMan = client.getQuery(GCUBEGenericQuery.class); + + queryMan.setExpression(query); + System.out.println(session.getOriginalScopeName()); + return client.execute(queryMan, session.getScope()); + } catch (Exception e) { + e.printStackTrace(); + } + return new ArrayList(); + } + + /** {@inheritDoc}*/ + public List getWS(String type) + { + WSResourceQuery query = null; + try { + query = client.getQuery(WSResourceQuery.class); + query.addAtomicConditions(new AtomicCondition("/gc:ServiceClass", type)); + return client.execute(query, session.getScope()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return new ArrayList(); + + } + + + /** {@inheritDoc}*/ + public void addGHNToScope(String url) { + //TODO: this will probably change... + + EndpointReferenceType endpoint = new EndpointReferenceType(); + try { + url = "http://" + url + "/wsrf/services/gcube/common/vremanagement/GHNManager"; + String[] vos = session.getOriginalScopeName().split("/"); + System.out.println("querying for vo: /" + vos[1]); + + endpoint.setAddress(new Address(url)); + GHNManagerServiceAddressingLocator locator = new GHNManagerServiceAddressingLocator(); + GHNManagerPortType pt = locator.getGHNManagerPortTypePort(endpoint); + pt = (GHNManagerPortType) ServiceContextManager.applySecurity(pt, GCUBEScope.getScope("/" + vos[1]), session.getCredential()); + AddScopeInputParams params = new AddScopeInputParams(); + params.setScope(session.getOriginalScopeName()); + params.setMap(""); //eventually, set here the new Service Map + pt.addScope(params); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** {@inheritDoc}*/ + public void removeGHNToScope(String url) { + //TODO: this will probably change... + + EndpointReferenceType endpoint = new EndpointReferenceType(); + try { + url = "http://" + url + "/wsrf/services/gcube/common/vremanagement/GHNManager"; + + String[] vos = session.getOriginalScopeName().split("/"); + System.out.println("querying for vo: /" + vos[1]); + + endpoint.setAddress(new Address(url)); + GHNManagerServiceAddressingLocator locator = new GHNManagerServiceAddressingLocator(); + GHNManagerPortType pt = locator.getGHNManagerPortTypePort(endpoint); + pt = (GHNManagerPortType) ServiceContextManager.applySecurity(pt, GCUBEScope.getScope("/" + vos[1]), session.getCredential()); + pt.removeScope(session.getOriginalScopeName()); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** {@inheritDoc}*/ + public void addRIToScope(String url, String className, String name) { + //TODO: this will probably change... + + EndpointReferenceType endpoint = new EndpointReferenceType(); + try { + endpoint.setAddress(new Address(url)); + GHNManagerServiceAddressingLocator locator = new GHNManagerServiceAddressingLocator(); + GHNManagerPortType pt = locator.getGHNManagerPortTypePort(endpoint); + pt = (GHNManagerPortType) ServiceContextManager.applySecurity(pt, session); + ScopeRIParams params = new ScopeRIParams(); + params.setClazz(className); + params.setName(name); + params.setScope(session.getOriginalScopeName()); + pt.addRIToScope(params); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** {@inheritDoc}*/ + public void addExternalRIToVRE(File file) + { + GCUBEExternalRunningInstance ri = null; + try { + ri = GHNContext.getImplementation(GCUBEExternalRunningInstance.class); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + String ret = ""; + if(file.exists()){ + try { + ri.load(new FileReader(file)); + } catch (Exception e) { + String message = "Error while loading profile for the External Running Instance with id=" + ri.getID() + "\n"; + System.out.println(message); + e.printStackTrace(); + ret += message; + } + }else{ + String message = "An error occur during the approval of the External Running Instance with id=" + ri.getID() + "\n"; + System.out.println(message); + ret += message; + } + + + + try { + // TODO Change this + + publisher.registerGCUBEResource(ri, session.getScope(), new PortalSecurityManager(session)); + } catch (ISPublisherException e) { + String message = "Registration error for the External Running Instance with id=" + ri.getID() + "\n"; + System.out.println(message); + e.printStackTrace(); + ret += message; + } + + } + + /** {@inheritDoc}*/ + public void removeExternalRIToVRE(String id) + { + try { + // TODO Change this + + publisher.removeGCUBEResource(id, GCUBEExternalRunningInstance.TYPE, session.getScope(), new PortalSecurityManager(session)); + } catch (ISPublisherException e) { + String message = "Registration error for the External Running Instance with id=" +id + "\n"; + System.out.println(message); + e.printStackTrace(); + } + + } + + /** {@inheritDoc}*/ + public boolean existsGHN(String namePort) + { + GCUBEGenericQuery query; + try { + System.out.println("GHN: " + namePort); + query = client.getQuery(GCUBEGenericQuery.class);query.setExpression("for $ghn in collection(\"/db/Profiles/GHN\")//Document/Data/child::*[local-name()='Profile']/Resource where $ghn/Profile/GHNDescription/Name/string() eq '" + namePort + "' return $ghn"); + String[] vos = session.getOriginalScopeName().split("/"); + System.out.println("querying for vo: /" + vos[1]); + List resources = client.execute(query, GCUBEScope.getScope("/" + vos[1])); + if(resources == null || resources.size() == 0) + { + System.out.println("Resources are null or empty"); + return false; + } + else + { + System.out.println("Found resources!!!!"); + return true; + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return false; + } + + + /** + * Returns all profiles of collections present in the given scope. + * @param scope the scope of the collections. + * @return a list of collections profile. + * @throws Exception when an error occurs. + */ + public List getCollections(GCUBEScope scope) throws Exception + { + + + try { + GCUBECollectionQuery collectionquery = client.getQuery(GCUBECollectionQuery.class); + + return client.execute(collectionquery,scope); + + } catch (Exception e) { + System.out.println("Error during Collections retrieving in scope "+scope.getName()); + e.printStackTrace(); + throw new Exception("Error during Collections retrieving in scope "+scope.getName(), e); + } + } + + + /** + * Return all metadata-collections associated with the given collection. + * @param scope the scope of the metadata collections. + * @param collectionID the associated collection. + * @return a list of metadata collections profile. + * @throws Exception + */ + public List getMCollections(GCUBEScope scope, String collectionID) throws Exception + { + + try { + GCUBEMCollectionQuery mcolQuery = client.getQuery(GCUBEMCollectionQuery.class); + + mcolQuery.addGenericCondition("$result/child::*[local-name()='Profile']/RelatedCollection/CollectionID/string() eq '"+collectionID+"'"); + + return client.execute(mcolQuery,scope); + + } catch (Exception e) { + System.out.println("Error during MCollections retrieving in scope "+scope.getName()); + e.printStackTrace(); + throw new Exception("Error during MCollections retrieving in scope "+scope.getName(), e); + } + + } + + + /** + * Return all XML indices associated with the given metadata collection. + * @param scope the indices scope. + * @param mcollectionID the metadata collection id. + * @return a list of Resource document. + * @throws Exception + */ + public List getXMLIndices(GCUBEScope scope, String mcollectionID) throws Exception + { + try { + + WSResourceQuery queryXMLIndices = client.getQuery(WSResourceQuery.class); + + queryXMLIndices.addAtomicConditions(new AtomicCondition("//gc:ServiceClass", "MetadataManagement"), + new AtomicCondition("//gc:ServiceName","XMLIndexer"), + new AtomicCondition("/child::*[local-name()='Id']", mcollectionID), + new AtomicCondition("/child::*[local-name()='AccessType']", "GCUBEDaix")); + + + return client.execute(queryXMLIndices, scope); + + } catch (Exception e) { + System.out.println("Error during Indices retrieving in scope "+scope.getName()); + e.printStackTrace(); + throw new Exception("Error during Indices retrieving in scope "+scope.getName(), e); + } + + } + + /** + * Return all indices associated with a given metadata collection. + * @param scope the indices scope. + * @param mcollectionID the metadata collection id. + * @return a list of Resource document. + * @throws Exception + */ + public List getIndices(GCUBEScope scope, String mcollectionID) throws Exception + { + + try { + + WSResourceQuery queryXMLIndices = client.getQuery(WSResourceQuery.class); + + queryXMLIndices.addAtomicConditions(new AtomicCondition("//gc:ServiceClass", "Index"), + new AtomicCondition("/child::*[local-name()='CollectionID']",mcollectionID)); + + return client.execute(queryXMLIndices, scope); + + } catch (Exception e) { + System.out.println("Error during Indices retrieving in scope "+scope.getName()); + e.printStackTrace(); + throw new Exception("Error during Indices retrieving in scope "+scope.getName(), e); + } + + } + + + /** + * Return all indices associated with a given collection. + * @param scope the indices scope. + * @param collectionID the collection id. + * @return a list of Resource document. + * @throws Exception + */ + public List getCollectionIndices(GCUBEScope scope, String collectionID) throws Exception + { + try { + + WSResourceQuery queryXMLIndices = client.getQuery(WSResourceQuery.class); + + queryXMLIndices.addAtomicConditions(new AtomicCondition("//gc:ServiceClass", "Index"), + new AtomicCondition("/child::*[local-name()='CollectionID']",collectionID)); + + return client.execute(queryXMLIndices, scope); + + } catch (Exception e) { + System.out.println("Error during collection Indices retrieving in scope "+scope.getName()); + e.printStackTrace(); + throw new Exception("Error during collection Indices retrieving in scope "+scope.getName(), e); + } + + } + + + + /** + * Return a collection profile. + * @param scope the collection scope. + * @param collectionID the collection id. + * @return a collection profile. + * @throws Exception + */ + public GCUBECollection getCollection(GCUBEScope scope, String collectionID) throws Exception + { + try { + GCUBECollectionQuery Collectionquery = client.getQuery(GCUBECollectionQuery.class); + Collectionquery.addAtomicConditions(new AtomicCondition("//ID",collectionID)); + return client.execute(Collectionquery,scope).get(0); + + } catch (Exception e) { + System.out.println("Error during Collection (by ID "+collectionID+") retrieving in scope "+scope.getName()); + e.printStackTrace(); + throw new Exception("Error during Collection (by ID "+collectionID+") retrieving in scope "+scope.getName(), e); + } + + } +} + diff --git a/src/main/java/org/gcube/application/framework/vremanagement/vremanagement/impl/VREGeneratorEvo.java b/src/main/java/org/gcube/application/framework/vremanagement/vremanagement/impl/VREGeneratorEvo.java new file mode 100644 index 0000000..4ca2fbe --- /dev/null +++ b/src/main/java/org/gcube/application/framework/vremanagement/vremanagement/impl/VREGeneratorEvo.java @@ -0,0 +1,452 @@ +package org.gcube.application.framework.vremanagement.vremanagement.impl; + +import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.Random; +import java.util.concurrent.atomic.AtomicInteger; + +import javax.xml.rpc.ServiceException; + +import org.apache.axis.message.addressing.Address; +import org.apache.axis.message.addressing.EndpointReference; +import org.apache.axis.message.addressing.EndpointReferenceType; +import org.gcube.application.framework.core.cache.RIsManager; +import org.gcube.application.framework.core.security.ServiceContextManager; +import org.gcube.application.framework.core.session.ASLSession; +import org.gcube.application.framework.vremanagement.vremanagement.VREGeneratorInterface; +import org.gcube.common.core.scope.GCUBEScope; +import org.gcube.common.core.types.VOID; +import org.gcube.common.core.utils.logging.GCUBEClientLog; +import org.gcube.informationsystem.cache.SrvType; +import org.gcube.vremanagement.vremodeler.stubs.FunctionalityList; +import org.gcube.vremanagement.vremodeler.stubs.FunctionalityNodes; +import org.gcube.vremanagement.vremodeler.stubs.GHNArray; +import org.gcube.vremanagement.vremodeler.stubs.GHNList; +import org.gcube.vremanagement.vremodeler.stubs.GHNType; +import org.gcube.vremanagement.vremodeler.stubs.GHNsPerFunctionality; +import org.gcube.vremanagement.vremodeler.stubs.ModelerFactoryPortType; +import org.gcube.vremanagement.vremodeler.stubs.ModelerServicePortType; +import org.gcube.vremanagement.vremodeler.stubs.ReportList; +import org.gcube.vremanagement.vremodeler.stubs.RunningInstanceMessage; +import org.gcube.vremanagement.vremodeler.stubs.SelectedResourceDescriptionType; +import org.gcube.vremanagement.vremodeler.stubs.SetFunctionality; +import org.gcube.vremanagement.vremodeler.stubs.VREDescription; +import org.gcube.vremanagement.vremodeler.stubs.service.ModelerFactoryServiceAddressingLocator; +import org.gcube.vremanagement.vremodeler.stubs.service.ModelerServiceAddressingLocator; + + +/** + * + * @author Massimiliano Assante - ISTI-CNR + * + */ +public class VREGeneratorEvo implements VREGeneratorInterface { + + GCUBEClientLog log = new GCUBEClientLog("ASL_VRE"); + + String scope; + ASLSession session; + ModelerServicePortType modelPortType; + + private final static String MODELERS_NO = "MODELERS_NO"; + + protected static AtomicInteger vreId = new AtomicInteger(0); + + /** + * @param session the d4s session + * @param epr the epr + */ + public VREGeneratorEvo(ASLSession session, String id) { + this(session); + + EndpointReferenceType epr = getEprGivenID(id); + log.info("VREGeneratorEvo called on VRE id (epr)" + epr + " scope: " + session.getScope().toString()); + this.scope = session.getScopeName(); + this.session = session; + modelPortType = applySecurityEPR(epr); + + } + + public boolean isVreModelerServiceUp() { + return Integer.parseInt(session.getAttribute(MODELERS_NO).toString()) > 0; + } + + /** + * @param session the d4s session + */ + public VREGeneratorEvo(ASLSession session) { + super(); + log.info("VREGeneratorEvo scope: " + session.getScope().toString()); + this.scope = session.getScopeName(); + this.session = session; + modelPortType = null; + getModelPortType(); + } + /** + * @param session the d4s session + * @return the VRE names + * + */ + public ReportList getAllVREs(ASLSession session) { + EndpointReferenceType serviceEPR = new EndpointReferenceType(); + ModelerFactoryPortType mFPType = null; + ModelerFactoryServiceAddressingLocator mFSLocator = new ModelerFactoryServiceAddressingLocator(); + EndpointReference[] modelerURIs; + try { + modelerURIs = RIsManager.getInstance().getISCache(GCUBEScope.getScope(scope)).getEPRsFor("VREManagement", "VREModeler", SrvType.FACTORY.name()); + } catch (Exception e1) { + e1.printStackTrace(); + return null; + } + for (int i = 0; i < modelerURIs.length; i++) { + try { + System.out.println("getModelFactoryPortTypePort(epr)"); + session.setScope(scope); + serviceEPR.setAddress(new Address(modelerURIs[vreId.getAndIncrement() % modelerURIs.length].getAddress().toString())); + mFPType = (ModelerFactoryPortType) ServiceContextManager.applySecurity(mFSLocator.getModelerFactoryPortTypePort(serviceEPR), session); + return mFPType.getAllVREs(new VOID()); + + } catch (ServiceException e) { + e.printStackTrace(); + } catch (RemoteException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } + + /** + * @param session the d4s session + * @param id the id of the VRE to be removed + */ + public void removeVRE(ASLSession session, String id) { + + + EndpointReferenceType serviceEPR = new EndpointReferenceType(); + ModelerFactoryPortType mFPType = null; + ModelerFactoryServiceAddressingLocator mFSLocator = new ModelerFactoryServiceAddressingLocator(); + EndpointReference[] modelerURIs; + try { + modelerURIs = RIsManager.getInstance().getISCache(GCUBEScope.getScope(scope)).getEPRsFor("VREManagement", "VREModeler", SrvType.FACTORY.name()); + } catch (Exception e1) { + e1.printStackTrace(); + return; + } + for (int i = 0; i < modelerURIs.length; i++) { + try { + System.out.println("getModelFactoryPortTypePort(epr)"); + + serviceEPR.setAddress(new Address(modelerURIs[vreId.getAndIncrement() % modelerURIs.length].getAddress().toString())); + session.setScope(scope); + mFPType = (ModelerFactoryPortType) ServiceContextManager.applySecurity(mFSLocator.getModelerFactoryPortTypePort(serviceEPR), session); + + System.out.println("ID RECEIVED TO REMOVE:" + id); + + mFPType.removeVRE(id); + break; + + } catch (ServiceException e) { + e.printStackTrace(); + } catch (RemoteException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + /** + * + * @param epr + * @return + */ + protected ModelerServicePortType applySecurityEPR(EndpointReferenceType epr) { + try { + ModelerServiceAddressingLocator mSALocator = new ModelerServiceAddressingLocator(); + session.setScope(scope); + modelPortType = ServiceContextManager.applySecurity(mSALocator.getModelerServicePortTypePort(epr),session); + return modelPortType; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + + } + @Override + public String checkVREStatus() throws RemoteException { + return modelPortType.checkStatus(new VOID()); + } + + /** + * + */ + @Override + public void deployVRE() throws RemoteException { + modelPortType.deployVRE(new VOID()); + + } + + public String[] getExistingNamesVREs() { + // TODO Auto-generated method stub + return null; + } + + public FunctionalityNodes getSelectedFunctionality() throws Exception { + FunctionalityNodes list = modelPortType.getFunctionalityNodes(new VOID()); + return list; + } + + @Override + public List getGHNs() throws RemoteException { + + log.debug("Asking gHN list to service"); + + List toReturn = new ArrayList(); + FunctionalityNodes list = modelPortType.getFunctionalityNodes(new VOID()); + + GHNList ghns = list.getSelectableGHNs(); //selezionabili per le missing func. + GHNType[] types = ghns.getList(); + + for (int i = 0; i < types.length; i++) { + try { + log.debug("returned GHN: " + types[i].getHost()); + toReturn.add(new GHNType(types[i].getHost(), types[i].getId(), types[i].getMemory(), types[i].getRelatedRIs(), types[i].isSecurityEnabled(), + types[i].isSelected(), types[i].getSite())); + + } catch (NullPointerException e) { + e.printStackTrace(); + return toReturn; + } + } + return toReturn; + } + + @Override + public GHNsPerFunctionality[] getGHNsPerFunctionality() throws RemoteException { + FunctionalityNodes list = modelPortType.getFunctionalityNodes(new VOID()); + return list.getFunctionalities(); + + } +// RunningInstanceMessage[] ris = list.getFunctionalities()[1].getMissingServices(); //ci sono n RunningInstances (Service) Mancanti +// ris[0]. +// list.getFunctionalities()[1].getGhns(); //verranno aggiunti per la funzionalit + + + @Override + public void setFunctionality(int[] funcIds, SelectedResourceDescriptionType[] selResDesc) throws RemoteException { + SetFunctionality sf = new SetFunctionality(funcIds, selResDesc); + modelPortType.setFunctionality(sf); + } + + @Override + public FunctionalityList getFunctionality() throws Exception { + FunctionalityList list = modelPortType.getFunctionality(new VOID()); + return list; + } + + public String getMetadataRelatedToCollection() throws RemoteException { + return null; + } + + public String getQuality() throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + + /** + * first call + */ + @Override + public VREDescription getVREModel() throws RemoteException { + VREDescription desc = modelPortType.getDescription(new VOID()); + + return desc; + } + + + @Override + public void setGHNs(String[] selectedGHNIds) throws RemoteException { + modelPortType.setUseCloud(false); + GHNArray ghnArray = new GHNArray(selectedGHNIds); + modelPortType.setGHNs(ghnArray); + } + + @Override + public void setVREModel(String VREName, String VREDescription, + String VREDesigner, String VREManager, long startTime, long endTime) + throws RemoteException { + VREDescription vreDesc = new VREDescription(); + vreDesc.setDescription(VREDescription); + vreDesc.setDesigner(VREDesigner); + vreDesc.setManager(VREManager); + vreDesc.setName(VREName); + Calendar start = Calendar.getInstance(); + start.setTimeInMillis(startTime); + vreDesc.setStartTime(start); + Calendar end = Calendar.getInstance(); + end.setTimeInMillis(endTime); + vreDesc.setEndTime(end); + + log.debug("StartTime = " + start.getTime()); + log.debug("EndTime = " + end.getTime()); + + modelPortType.setDescription(vreDesc); + } + + public void setVREtoPendingState() throws RemoteException { + modelPortType.setVREtoPendingState(new VOID()); + } + + /** + * + */ + private synchronized void getModelPortType() { + + EndpointReferenceType serviceEPR = new EndpointReferenceType(); + ModelerFactoryPortType mFPType = null; + + EndpointReferenceType VREEndpointReferenceType; + if (modelPortType == null) { + + log.warn("VREEndpointReferenceType is null"); + ModelerFactoryServiceAddressingLocator mFSLocator = new ModelerFactoryServiceAddressingLocator(); + + EndpointReference[] modelerURIs; + try { + + modelerURIs = RIsManager.getInstance().getISCache(GCUBEScope.getScope(scope)).getEPRsFor("VREManagement", "VREModeler", SrvType.FACTORY.name()); + + + } catch (Exception e1) { + e1.printStackTrace(); + return; + } + log.debug("vre modelers: " + modelerURIs.length); + session.setAttribute(MODELERS_NO, modelerURIs.length); + for (int i = 0; i < modelerURIs.length; i++) { + try { + System.out.println("getModelFactoryPortTypePort(epr)"); + + serviceEPR.setAddress(new Address(modelerURIs[vreId.getAndIncrement() % modelerURIs.length].getAddress().toString())); + session.setScope(scope); + mFPType = ServiceContextManager.applySecurity(mFSLocator.getModelerFactoryPortTypePort(serviceEPR), session); + VREEndpointReferenceType = mFPType.createResource(new VOID()); + mFPType.getAllVREs(new VOID()); + ModelerServiceAddressingLocator mSALocator = new ModelerServiceAddressingLocator(); + session.setScope(scope); + modelPortType = ServiceContextManager.applySecurity(mSALocator.getModelerServicePortTypePort(VREEndpointReferenceType), session); + // Attaching Credential to port type + System.out.println("Attaching Credential to port type"); + break; + } catch (ServiceException e) { + e.printStackTrace(); + } catch (RemoteException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + new Random(System.currentTimeMillis()).nextInt(modelerURIs.length); + } + } + } else + log.debug("modelPortType!=null"); + + } + + /** {@inheritDoc}*/ + public String getVREepr() { + return modelPortType.toString(); + } + + /** + * return the per given an id + * @param id + * @return + */ + private EndpointReferenceType getEprGivenID(String id) { + EndpointReferenceType serviceEPR = new EndpointReferenceType(); + ModelerFactoryPortType mFPType = null; + ModelerFactoryServiceAddressingLocator mFSLocator = new ModelerFactoryServiceAddressingLocator(); + EndpointReference[] modelerURIs; + try { + session.setScope(scope); + modelerURIs = RIsManager.getInstance().getISCache(session.getScope()).getEPRsFor("VREManagement", "VREModeler", SrvType.FACTORY.name()); + } catch (Exception e1) { + e1.printStackTrace(); + return null; + } + for (int i = 0; i < modelerURIs.length; i++) { + try { + log.debug("getModelFactoryPortTypePort(epr)"); + + serviceEPR.setAddress(new Address(modelerURIs[vreId.getAndIncrement() % modelerURIs.length].getAddress().toString())); + session.setScope(scope); + mFPType = (ModelerFactoryPortType) ServiceContextManager.applySecurity(mFSLocator.getModelerFactoryPortTypePort(serviceEPR), session); + return mFPType.getEPRbyId(id); + + } catch (ServiceException e) { + e.printStackTrace(); + } catch (RemoteException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } + + public boolean isCloudAvailable() { + //TODO: check actual availability + return true; + } + + + /** + * + */ + public boolean isCloudSelected() { + System.out.println("isCloudSelected()"); + boolean toReturn = false; + try { + toReturn = modelPortType.isUseCloud(new VOID()); + } catch (RemoteException e) { + e.printStackTrace(); + return false; + } + return toReturn; + } + + + public boolean setCloudDeploy(int virtualMachines) { + try { + log.debug("setUseCloud(true)"); + modelPortType.setUseCloud(true); + log.debug("setCloudVMs #: " + virtualMachines); + modelPortType.setCloudVMs(virtualMachines); + } catch (RemoteException e) { + e.printStackTrace(); + return false; + } + return true; + } + + /** + * + */ + public int getCloudVMSelected() { + int toReturn = -1; + try { + toReturn = modelPortType.getCloudVMs(new VOID()); + } catch (RemoteException e) { + e.printStackTrace(); + return toReturn; + } + return toReturn; + } + + + +}