moved to CL and FWS

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/aslvre@82242 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2013-10-01 16:01:25 +00:00
parent f5de2a8a1a
commit 96658d280a
8 changed files with 195 additions and 869 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>applicationSupportLayerVREManagement</name>
<name>asl-vre</name>
<comment></comment>
<projects>
</projects>
@ -16,12 +16,12 @@
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="applicationSupportLayerVREManagement">
<wb-module deploy-name="asl-vre">
<wb-resource deploy-path="/" source-path="/src/main/java"/>
</wb-module>
</project-modules>

View File

@ -0,0 +1,2 @@
disabled=06target
eclipse.preferences.version=1

34
pom.xml
View File

@ -10,7 +10,7 @@
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslvre</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>VRE Management ASL Extension</name>
<description>
@ -29,29 +29,33 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>gcf</artifactId>
<version>[1.5.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<version>[3.2.1-SNAPSHOT, 4.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.vremanagement</groupId>
<artifactId>vremodeler-client-library</artifactId>
<version>[1.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>vremodeler-stubs</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>ghnmanager-stubs</artifactId>
<version>[1.5.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<artifactId>ghn-manager-client</artifactId>
<version>[1.1.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -62,12 +66,10 @@
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -1,121 +0,0 @@
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<XMLResult> queryIS(String query);
/**
* @param type the of the WSs to be retrieved
* @return a list of RPDocuments
*/
public List<RPDocument> 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<GCUBECollection> 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<GCUBEMCollection> 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<RPDocument> 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<RPDocument> 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<RPDocument> 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;
}

View File

@ -3,12 +3,14 @@ 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;
import org.gcube.vremanagement.vremodel.cl.stubs.types.FunctionalityItem;
import org.gcube.vremanagement.vremodel.cl.stubs.types.FunctionalityList;
import org.gcube.vremanagement.vremodel.cl.stubs.types.FunctionalityNodes;
import org.gcube.vremanagement.vremodel.cl.stubs.types.GHN;
import org.gcube.vremanagement.vremodel.cl.stubs.types.GHNsPerFunctionality;
import org.gcube.vremanagement.vremodel.cl.stubs.types.SelectedResourceDescriptionType;
import org.gcube.vremanagement.vremodel.cl.stubs.types.VREDescription;
public interface VREGeneratorInterface {
@ -29,7 +31,7 @@ public interface VREGeneratorInterface {
* @return what the vVRE modeler returns
* @throws RemoteException
*/
List<GHNType> getGHNs() throws RemoteException;
List<GHN> getGHNs() throws RemoteException;
/**
* @return what the vVRE modeler returns
@ -41,7 +43,7 @@ public interface VREGeneratorInterface {
* @return what the vVRE modeler returns
* @throws RemoteException
*/
FunctionalityList getFunctionality() throws Exception;
List<FunctionalityItem> getFunctionality() throws Exception;
FunctionalityNodes getSelectedFunctionality() throws Exception;
@ -80,7 +82,7 @@ public interface VREGeneratorInterface {
* @param functionalityIDElement
* @throws RemoteException
*/
void setFunctionality(int[] funcIds, SelectedResourceDescriptionType[] selResDesc) throws RemoteException;
void setFunctionality(Integer[] funcIds, SelectedResourceDescriptionType[] selResDesc) throws RemoteException;
/**
* @return

View File

@ -1,413 +0,0 @@
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<XMLResult> 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<XMLResult>();
}
/** {@inheritDoc}*/
public List<RPDocument> 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<RPDocument>();
}
/** {@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<XMLResult> 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<GCUBECollection> 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<GCUBEMCollection> 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<RPDocument> 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<RPDocument> 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<RPDocument> 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);
}
}
}

View File

@ -1,40 +1,34 @@
package org.gcube.application.framework.vremanagement.vremanagement.impl;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import static org.gcube.vremanagement.vremodel.cl.plugin.AbstractPlugin.factory;
import static org.gcube.vremanagement.vremodel.cl.plugin.AbstractPlugin.manager;
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;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.vremanagement.vremodel.cl.proxy.Manager;
import org.gcube.vremanagement.vremodel.cl.stubs.types.FunctionalityItem;
import org.gcube.vremanagement.vremodel.cl.stubs.types.FunctionalityNodes;
import org.gcube.vremanagement.vremodel.cl.stubs.types.GHN;
import org.gcube.vremanagement.vremodel.cl.stubs.types.GHNsPerFunctionality;
import org.gcube.vremanagement.vremodel.cl.stubs.types.Report;
import org.gcube.vremanagement.vremodel.cl.stubs.types.SelectedResourceDescriptionType;
import org.gcube.vremanagement.vremodel.cl.stubs.types.VREDescription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.emory.mathcs.backport.java.util.Arrays;
/**
@ -44,15 +38,13 @@ import org.gcube.vremanagement.vremodeler.stubs.service.ModelerServiceAddressing
*/
public class VREGeneratorEvo implements VREGeneratorInterface {
GCUBEClientLog log = new GCUBEClientLog("ASL_VRE");
private static final Logger log = LoggerFactory.getLogger(VREGeneratorEvo.class);
private static final String VRE_MODELER_SERVICE_NAME = "VREModeler";
String scope;
ASLSession session;
ModelerServicePortType modelPortType;
Manager modelPortType;
private final static String MODELERS_NO = "MODELERS_NO";
protected static AtomicInteger vreId = new AtomicInteger(0);
protected static AtomicInteger vreId = new AtomicInteger(0);
/**
* @param session the d4s session
@ -61,62 +53,73 @@ public class VREGeneratorEvo implements VREGeneratorInterface {
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();
log.info("VREGeneratorEvo called on VRE id " + id + " scope: " + session.getScope());
this.scope = session.getScope();
this.session = session;
modelPortType = applySecurityEPR(epr);
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
modelPortType = manager().at(factory().build().getEPRbyId(id)).build();
ScopeProvider.instance.set(currScope);
}
public boolean isVreModelerServiceUp() {
return Integer.parseInt(session.getAttribute(MODELERS_NO).toString()) > 0;
ScopeProvider.instance.set(scope);
SimpleQuery query = queryFor(GCoreEndpoint.class);
query.addCondition("$resource/Profile/ServiceName/text() eq '"+ VRE_MODELER_SERVICE_NAME +"'");
query.addCondition("$resource/Profile/DeploymentData/Status/text() eq 'ready'");
DiscoveryClient<GCoreEndpoint> client = clientFor(GCoreEndpoint.class);
List<GCoreEndpoint> r = client.submit(query);
if (r == null || r.isEmpty())
return false;
return true;
}
/**
* @param session the d4s session
* @param session the session
*/
public VREGeneratorEvo(ASLSession session) {
super();
log.info("VREGeneratorEvo scope: " + session.getScope().toString());
this.scope = session.getScopeName();
this.session = session;
modelPortType = null;
getModelPortType();
modelPortType = manager().at(factory().build().createResource()).build();
}
@Override
public void setVREModel(String name, String desc, String designer, String manager, long startTime, long endTime) throws RemoteException {
Calendar start = Calendar.getInstance();
start.setTimeInMillis(startTime);
Calendar end = Calendar.getInstance();
end.setTimeInMillis(endTime);
log.debug("StartTime = " + start.getTime());
log.debug("EndTime = " + end.getTime());
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
modelPortType.setDescription(name, desc, designer, manager, start, end);
ScopeProvider.instance.set(currScope);
}
@Override
public String getVREepr() {
factory().build();
return null;
}
/**
* @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;
public List<Report> getAllVREs(ASLSession session) {
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
List<Report> toReturn = factory().build().getAllVREs();
ScopeProvider.instance.set(currScope);
return toReturn;
}
/**
@ -124,60 +127,21 @@ public class VREGeneratorEvo implements VREGeneratorInterface {
* @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;
}
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
factory().build().removeVRE(id);
ScopeProvider.instance.set(currScope);
}
@Override
public String checkVREStatus() throws RemoteException {
return modelPortType.checkStatus(new VOID());
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
String toReturn = modelPortType.checkStatus();
ScopeProvider.instance.set(currScope);
return toReturn;
}
/**
@ -185,7 +149,10 @@ public class VREGeneratorEvo implements VREGeneratorInterface {
*/
@Override
public void deployVRE() throws RemoteException {
modelPortType.deployVRE(new VOID());
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
modelPortType.deployVRE();
ScopeProvider.instance.set(currScope);
}
@ -195,55 +162,73 @@ public class VREGeneratorEvo implements VREGeneratorInterface {
}
public FunctionalityNodes getSelectedFunctionality() throws Exception {
FunctionalityNodes list = modelPortType.getFunctionalityNodes(new VOID());
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
FunctionalityNodes list = modelPortType.getFunctionalityNodes();
ScopeProvider.instance.set(currScope);
return list;
}
@Override
public List<GHNType> getGHNs() throws RemoteException {
public List<GHN> getGHNs() throws RemoteException {
log.debug("Asking gHN list to service");
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
List<GHN> toReturn = new ArrayList<GHN>();
FunctionalityNodes list = modelPortType.getFunctionalityNodes();
List<GHNType> toReturn = new ArrayList<GHNType>();
FunctionalityNodes list = modelPortType.getFunctionalityNodes(new VOID());
List<GHN> types = list.selectableGHNs(); //selezionabili per le missing func.
GHNList ghns = list.getSelectableGHNs(); //selezionabili per le missing func.
GHNType[] types = ghns.getList();
for (int i = 0; i < types.length; i++) {
for (int i = 0; i < types.size(); 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()));
log.debug("returned GHN: " + types.get(i).host());
toReturn.add(new GHN( types.get(i).id(),
types.get(i).host(),
types.get(i).securityEnabled(),
types.get(i).memory(),
types.get(i).site(),
types.get(i).relatedRIs(),
types.get(i).selected()));
} catch (NullPointerException e) {
e.printStackTrace();
return toReturn;
}
}
ScopeProvider.instance.set(currScope);
return toReturn;
}
@Override
public GHNsPerFunctionality[] getGHNsPerFunctionality() throws RemoteException {
FunctionalityNodes list = modelPortType.getFunctionalityNodes(new VOID());
return list.getFunctionalities();
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
FunctionalityNodes list = modelPortType.getFunctionalityNodes();
ScopeProvider.instance.set(currScope);
return list.functionalities().toArray(new GHNsPerFunctionality[0]);
}
// RunningInstanceMessage[] ris = list.getFunctionalities()[1].getMissingServices(); //ci sono n RunningInstances (Service) Mancanti
// ris[0].
// list.getFunctionalities()[1].getGhns(); //verranno aggiunti per la funzionalit
// RunningInstanceMessage[] ris = list.getFunctionalities()[1].getMissingServices(); //ci sono n RunningInstances (Service) Mancanti
// ris[0].
// list.getFunctionalities()[1].getGhns(); //verranno aggiunti per la funzionalit
@SuppressWarnings("unchecked")
@Override
public void setFunctionality(int[] funcIds, SelectedResourceDescriptionType[] selResDesc) throws RemoteException {
SetFunctionality sf = new SetFunctionality(funcIds, selResDesc);
modelPortType.setFunctionality(sf);
public void setFunctionality(Integer[] funcIds, SelectedResourceDescriptionType[] selResDesc) throws RemoteException {
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
modelPortType.setFunctionality(Arrays.asList(funcIds), Arrays.asList(selResDesc));
ScopeProvider.instance.set(currScope);
}
@Override
public FunctionalityList getFunctionality() throws Exception {
FunctionalityList list = modelPortType.getFunctionality(new VOID());
public List<FunctionalityItem> getFunctionality() throws Exception {
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
List<FunctionalityItem> list = modelPortType.getFunctionalities();
ScopeProvider.instance.set(currScope);
return list;
}
@ -251,152 +236,35 @@ public class VREGeneratorEvo implements VREGeneratorInterface {
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());
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
VREDescription desc = modelPortType.getDescription();
ScopeProvider.instance.set(currScope);
return desc;
}
@SuppressWarnings("unchecked")
@Override
public void setGHNs(String[] selectedGHNIds) throws RemoteException {
modelPortType.setUseCloud(false);
GHNArray ghnArray = new GHNArray(selectedGHNIds);
modelPortType.setGHNs(ghnArray);
modelPortType.setGHNs(Arrays.asList(selectedGHNIds));
}
@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());
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
modelPortType.setVREtoPendingState();
ScopeProvider.instance.set(currScope);
}
/**
*
*/
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
@ -409,27 +277,19 @@ public class VREGeneratorEvo implements VREGeneratorInterface {
*/
public boolean isCloudSelected() {
System.out.println("isCloudSelected()");
boolean toReturn = false;
try {
toReturn = modelPortType.isUseCloud(new VOID());
} catch (RemoteException e) {
e.printStackTrace();
return false;
}
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
boolean toReturn = modelPortType.isUseCloud();
ScopeProvider.instance.set(currScope);
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;
}
@ -438,15 +298,9 @@ public class VREGeneratorEvo implements VREGeneratorInterface {
*/
public int getCloudVMSelected() {
int toReturn = -1;
try {
toReturn = modelPortType.getCloudVMs(new VOID());
} catch (RemoteException e) {
e.printStackTrace();
toReturn = modelPortType.getCloudVMs();
return toReturn;
}
return toReturn;
}
}