git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@16 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ee05967c41
commit
0efe150eed
|
@ -3,6 +3,6 @@
|
|||
<classpathentry excluding="src/" kind="src" path=""/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="org.gcube.informationservice.registry.stubs.jar"/>
|
||||
<classpathentry kind="lib" path="D:/code/GCORE/CONTAINER/lib/org.gcube.common.core.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/CONTAINERLIB"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name = Registry
|
||||
package = org.gcube.informationservice.registry
|
||||
package.dir = org/gcube/informationservice/registry
|
||||
package = org.gcube.informationsystem.registry
|
||||
package.dir = org/gcube/informationsystem/registry
|
||||
lib.dir = SERVICELIBS/GCUBE_ISREGISTRY
|
||||
wsdl.1 = RegistryFactory
|
||||
wsdl.2 = Registry
|
||||
|
|
|
@ -5,8 +5,6 @@ import org.gcube.common.core.contexts.GCUBEStatefulPortTypeContext;
|
|||
|
||||
public class FactoryContext extends GCUBEStatefulPortTypeContext{
|
||||
|
||||
|
||||
|
||||
static private final String PORTTYPE_NAME = "gcube/informationsystem/isregistryfactory";
|
||||
|
||||
static FactoryContext cache = new FactoryContext();
|
||||
|
|
|
@ -1,23 +1,192 @@
|
|||
package org.gcube.informationsystem.registry.impl.core;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
|
||||
import org.gcube.common.core.is.publisher.ISPublisher;
|
||||
import org.gcube.common.core.is.publisher.ISPublisherException;
|
||||
import org.gcube.common.core.node.GHNContext;
|
||||
import org.gcube.common.core.resources.GCUBEHostingNode;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.core.resources.GCUBERunningInstance;
|
||||
import org.gcube.common.core.state.GCUBEWSResource;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.globus.wsrf.ResourceException;
|
||||
|
||||
|
||||
/**
|
||||
* @author Andrea Manzi
|
||||
*
|
||||
*/
|
||||
public class ProfileResource extends GCUBEWSResource {
|
||||
|
||||
private static GCUBELog logger = new GCUBELog(ProfileResource.class.getName());
|
||||
|
||||
private ISPublisher publisher = null;
|
||||
|
||||
ArrayList<QName> listQname = new ArrayList<QName>();
|
||||
|
||||
protected static final String NotificationProfileRP="NotificationProfile";
|
||||
|
||||
protected GCUBEResource gCubeResource;
|
||||
|
||||
protected static final String ProfileRP="Profile";
|
||||
|
||||
@Override
|
||||
protected String[] getPropertyNames() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
protected String[] getTopicNames(){
|
||||
return new String[] {NotificationProfileRP};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getPropertyNames(){
|
||||
return new String[] {ProfileRP};
|
||||
}
|
||||
|
||||
/* Constructor
|
||||
* @throws Exception Exception
|
||||
*/
|
||||
public ProfileResource() throws Exception{};
|
||||
|
||||
|
||||
@Override
|
||||
public void initialise(Object... params) throws ResourceException {
|
||||
|
||||
GCUBEResource resource = (GCUBEResource) params[0];
|
||||
|
||||
//Setting the key
|
||||
this.setID(ProfileContext.getContext().makeKey(resource.getID()));
|
||||
StringWriter writer =new StringWriter();
|
||||
try {
|
||||
resource.store(writer);
|
||||
} catch (Exception e1) {
|
||||
throw new ResourceException();
|
||||
}
|
||||
this.setProfile(writer.toString());
|
||||
this.setNotificationProfile(writer.toString());
|
||||
this.setGCubeResource(resource);
|
||||
|
||||
if (hasToLive(resource)) this.setTerminationTime(null);
|
||||
|
||||
if (hasToLive(resource)) {
|
||||
//registration of Topic To IS-Notifier
|
||||
|
||||
listQname.add(this.generateQName());
|
||||
synchronized(RegistryFactory.notificationMap) {
|
||||
if (!(RegistryFactory.notificationMap.contains(this.getID()))) {
|
||||
try {
|
||||
publisher = GHNContext.getImplementation(ISPublisher.class);
|
||||
publisher.registerToISNotification(this.getEPR(), listQname, GHNContext.getContext().getDefaultScope(), ServiceContext.getContext());
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
throw new ResourceException(e);
|
||||
}
|
||||
|
||||
RegistryFactory.notificationMap.add(this.getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setNotificationProfile(String profile) {
|
||||
this.getResourcePropertySet().get(NotificationProfileRP).clear();
|
||||
this.getResourcePropertySet().get(NotificationProfileRP).add(profile);
|
||||
this.getPersistenceDelegate().store(this);
|
||||
}
|
||||
|
||||
public String getNotificationProfile() {
|
||||
return (String)this.getResourcePropertySet().get(NotificationProfileRP).get(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setProfile(String profile) {
|
||||
this.getResourcePropertySet().get(ProfileRP).clear();
|
||||
this.getResourcePropertySet().get(ProfileRP).add(profile);
|
||||
this.getPersistenceDelegate().store(this);
|
||||
}
|
||||
|
||||
public String getProfile() {
|
||||
return (String)this.getResourcePropertySet().get(ProfileRP).get(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check if the profile has to live or not
|
||||
* return true/false
|
||||
*/
|
||||
private boolean hasToLive(GCUBEResource resource) {
|
||||
if (resource.getType().compareTo(GCUBERunningInstance.TYPE)==0 || resource.getType().compareTo(GCUBEHostingNode.TYPE)==0) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Resource Qname
|
||||
* @return the Resource Qname
|
||||
*/
|
||||
private QName generateQName() {
|
||||
return QName.valueOf(NotificationProfileRP.toString()+"_"+this.getID());
|
||||
}
|
||||
|
||||
public GCUBEResource getGCubeResource() {
|
||||
return this.gCubeResource;
|
||||
}
|
||||
|
||||
|
||||
public void setGCubeResource(GCUBEResource resource) {
|
||||
this.gCubeResource = resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() throws ResourceException{
|
||||
super.remove();
|
||||
logger.info("Resource " + this.getID()+ " is going to be removed.");
|
||||
this.getPersistenceDelegate().remove(this);
|
||||
try {
|
||||
publisher = GHNContext.getImplementation(ISPublisher.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
if (RegistryFactory.notificationMap.contains(this.getID()))
|
||||
{
|
||||
try {
|
||||
|
||||
publisher.unregisterFromISNotification(this.getEPR(),listQname,GHNContext.getContext().getDefaultScope(),ServiceContext.getContext());
|
||||
} catch (ISPublisherException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
synchronized(RegistryFactory.notificationMap) {
|
||||
RegistryFactory.notificationMap.remove(this.getID());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
publisher.removeWSResource(this);
|
||||
} catch (ISPublisherException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void updateResource(GCUBEResource resource) throws Exception{
|
||||
StringWriter writer = new StringWriter();
|
||||
resource.store(writer);
|
||||
this.setProfile(writer.toString());
|
||||
this.setGCubeResource(resource);
|
||||
|
||||
if (this.hasToLive(resource))
|
||||
this.setNotificationProfile(writer.toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,19 @@
|
|||
package org.gcube.informationsystem.registry.impl.core;
|
||||
|
||||
public class Registry {
|
||||
import org.gcube.common.core.faults.GCUBEFault;
|
||||
import org.gcube.informationsystem.registry.stubs.GetProfileString;
|
||||
import org.gcube.informationsystem.registry.impl.core.ProfileResource;
|
||||
import org.globus.wsrf.ResourceException;
|
||||
|
||||
|
||||
public class Registry {
|
||||
|
||||
public String getProfileString(GetProfileString voidType) throws GCUBEFault{
|
||||
try {
|
||||
return ((ProfileResource)ProfileContext.getContext().getWSHome().find()).getProfile();
|
||||
} catch (ResourceException e) {
|
||||
e.printStackTrace();
|
||||
throw new GCUBEFault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,36 +1,73 @@
|
|||
package org.gcube.informationsystem.registry.impl.core;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Method;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.xml.rpc.ServiceException;
|
||||
|
||||
import org.gcube.common.core.contexts.GCUBEServiceContext;
|
||||
import org.gcube.common.core.faults.GCUBEFault;
|
||||
|
||||
import org.gcube.common.core.is.ISException;
|
||||
import org.gcube.common.core.is.client.ISClient.ISInvalidQueryException;
|
||||
import org.gcube.common.core.is.client.ISClient.ISMalformedQueryException;
|
||||
import org.gcube.common.core.node.GHNContext;
|
||||
import org.gcube.common.core.porttypes.GCUBEStartupPortType;
|
||||
import org.gcube.common.core.resources.GCUBEHostingNode;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.common.is.publisher.impl.GCUBEPublisher;
|
||||
import org.gcube.common.is.publisher.impl.GCUBEPublisherException;
|
||||
import org.gcube.common.is.publisher.impl.ProfileManager;
|
||||
import org.gcube.informationsystem.registry.impl.util.RegistryUtil;
|
||||
import org.gcube.informationsystem.registry.stubs.CreateResourceMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.ProfileAlreadyRegisteredFault;
|
||||
import org.gcube.informationsystem.registry.stubs.RegistryPortType;
|
||||
import org.gcube.informationsystem.registry.stubs.RegistryProperty;
|
||||
import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.RemoveResourceResponse;
|
||||
import org.gcube.informationsystem.registry.stubs.SchemaValidationFault;
|
||||
import org.gcube.informationsystem.registry.stubs.StartRegistration;
|
||||
import org.gcube.informationsystem.registry.stubs.StartRegistrationResponse;
|
||||
import org.gcube.informationsystem.registry.stubs.UpdateProfileMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.UpdateResourceResponse;
|
||||
import org.gcube.informationsystem.registry.stubs.service.RegistryServiceAddressingLocator;
|
||||
import org.globus.wsrf.Constants;
|
||||
import org.globus.wsrf.ResourceContext;
|
||||
import org.globus.wsrf.ResourceException;
|
||||
import org.globus.wsrf.ResourceKey;
|
||||
import org.globus.wsrf.impl.SimpleResourceKey;
|
||||
import org.oasis.wsrf.lifetime.Destroy;
|
||||
|
||||
|
||||
/**
|
||||
* @author Andrea Manzi (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
public class RegistryFactory extends GCUBEStartupPortType{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Object logger.
|
||||
* */
|
||||
protected final GCUBELog logger = new GCUBELog(RegistryFactory.class);
|
||||
|
||||
|
||||
/* *
|
||||
*/
|
||||
private RegistryConfiguration config = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public enum operationType {create,update,destroy};
|
||||
|
||||
/**
|
||||
* Map of registration to Notification
|
||||
|
@ -45,13 +82,13 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
*
|
||||
*/
|
||||
protected ResourceContext ctxResource = null;
|
||||
|
||||
|
||||
@Override
|
||||
protected GCUBEServiceContext getServiceContext() {
|
||||
return ServiceContext.getContext();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Factory PT initialization
|
||||
*
|
||||
|
@ -60,7 +97,7 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
*/
|
||||
@Override
|
||||
public void init (Object arg0) throws ServiceException {
|
||||
|
||||
|
||||
super.init(null);
|
||||
//initialization of the Registry Configuration
|
||||
try {
|
||||
|
@ -69,13 +106,16 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
FactoryContext.getContext().getWSHome().create("FactoryResource");
|
||||
} catch (NamingException e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException();
|
||||
throw new ServiceException(e);
|
||||
} catch (ResourceException e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Use to Load from Disk persistence profiles and registers it into the DIS-IC ( in case the DIS-IC is empty)
|
||||
* Use to Load from Disk persistence profiles and registers it into the IS-IC ( in case the IS-IC is empty)
|
||||
*
|
||||
*
|
||||
* @param start same as void
|
||||
|
@ -95,4 +135,351 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
|
||||
}
|
||||
|
||||
|
||||
public String createResource(CreateResourceMessage inputMessage) throws SchemaValidationFault,RemoteException,ProfileAlreadyRegisteredFault {
|
||||
|
||||
GCUBEResource resource = null;
|
||||
|
||||
logSecurityInfo("createResource");
|
||||
String profile = inputMessage.getProfile();
|
||||
|
||||
if (profile == null || profile.compareTo("") == 0) {
|
||||
String msg = "Profile file empty";
|
||||
logger.debug(msg);
|
||||
throw new RemoteException(msg);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
resource.load ( new StringReader(profile));
|
||||
resource.getType();
|
||||
//the parse Profile class allows to extract from profiles information about type/DL/UniqueID
|
||||
//in order to distiguish among different Resource Type
|
||||
|
||||
//Adding scopes to Profile
|
||||
|
||||
String [] scopes = inputMessage.getScopes();
|
||||
if (scopes != null) {
|
||||
for (String scope : scopes) {
|
||||
logger.debug("Adding Scopes to Profile "+ scope);
|
||||
resource.addScope(GCUBEScope.getScope(scope));
|
||||
}
|
||||
}
|
||||
|
||||
//check ID
|
||||
if (resource.getID()== null) resource.setID("puppa");
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error("Error trying to loading profile");
|
||||
ex.printStackTrace();
|
||||
throw new SchemaValidationFault();
|
||||
}
|
||||
|
||||
//check if the Resource already Exist
|
||||
|
||||
if (isResourceCreated(resource.getID())) {
|
||||
String msg ="A Resource with ID "+ resource.getID()+" is already registered";
|
||||
logger.debug(msg);
|
||||
throw new ProfileAlreadyRegisteredFault();
|
||||
}
|
||||
|
||||
//try to create resource
|
||||
try {
|
||||
ProfileContext.getContext().getWSHome().create(resource);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
String msg = "Error creating Resource";
|
||||
logger.error(msg,ex);
|
||||
ex.printStackTrace();
|
||||
throw new RemoteException(msg);
|
||||
}
|
||||
|
||||
try {
|
||||
updateCounterInfo (resource,operationType.create.name(),Calendar.getInstance());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error updating Counting info for resourece with ID " + resource.getID());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
try {
|
||||
resource.store(writer);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return writer.toString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update Resource Profiles ( in case of an update of an ID not present it simply calls the Create resource method)
|
||||
*
|
||||
*
|
||||
* @param mess Complex Object that contains a String representing the xml profile to update and the diligentID
|
||||
* @return UpdateResourceResponse
|
||||
* @throws RemoteException Exception
|
||||
* @throws SchemaValidationException Exception
|
||||
*/
|
||||
public UpdateResourceResponse updateResource(UpdateProfileMessage mess) throws RemoteException,SchemaValidationFault {
|
||||
|
||||
logSecurityInfo("updateResource");
|
||||
|
||||
String ID = mess.getUniqueID();
|
||||
|
||||
String xmlProfile = mess.getXmlProfile();
|
||||
|
||||
GCUBEResource resource = null;
|
||||
|
||||
CreateResourceMessage input =null;
|
||||
|
||||
//validating input parameters
|
||||
|
||||
if (ID == null || ID.compareTo("") ==0) {
|
||||
logger.debug(" ID missing ");
|
||||
throw new RemoteException("Error, ID missing");
|
||||
}
|
||||
|
||||
if (xmlProfile == null || xmlProfile.compareTo("") ==0) {
|
||||
|
||||
logger.debug("Profile missing" );
|
||||
throw new RemoteException("Error, profile missing");
|
||||
|
||||
}
|
||||
|
||||
//check if the profile exist
|
||||
if (!isResourceCreated(ID)) {
|
||||
input = new CreateResourceMessage();
|
||||
input.setProfile(xmlProfile);
|
||||
this.createResource(input);
|
||||
return new UpdateResourceResponse();
|
||||
}
|
||||
|
||||
try {
|
||||
resource.load(new StringReader(xmlProfile));
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
logger.debug("Error parsing profile");
|
||||
throw new RemoteException("Error parsing profile");
|
||||
}
|
||||
|
||||
try{
|
||||
getProfileResource(ID).updateResource(resource);
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
logger.error("Error updating profile for ID "+ e);
|
||||
throw new RemoteException(e.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
updateCounterInfo (resource,operationType.update.name(),Calendar.getInstance());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error updating Counting info for resource with ID " + resource.getID());
|
||||
e.printStackTrace();
|
||||
}
|
||||
logger.info("Profile updated");
|
||||
return new UpdateResourceResponse();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Resource profile given the ID
|
||||
*
|
||||
*
|
||||
* @param inputMessage Defined into WSDL file
|
||||
* @return RemoveResourceResponse
|
||||
* @throws RemoteException Exceptions
|
||||
*/
|
||||
public RemoveResourceResponse removeResource (RemoveResourceMessage inputMessage) throws RemoteException,GCUBEFault{
|
||||
|
||||
logSecurityInfo("removeResource");
|
||||
|
||||
GCUBEResource profile= null;
|
||||
|
||||
String ID = inputMessage.getUniqueID();
|
||||
|
||||
RegistryPortType instancePT = null;
|
||||
|
||||
if (ID == null || ID.compareTo("") ==0) {
|
||||
logger.debug("ID missing ");
|
||||
throw new RemoteException("Error, ID missing");
|
||||
}
|
||||
|
||||
//controls if the UniqueID exist
|
||||
if (!(isResourceCreated(ID))){
|
||||
|
||||
GCUBEResource resource = null;
|
||||
try {
|
||||
resource = RegistryUtil.getProfileFromIS(ID);
|
||||
} catch (ISMalformedQueryException e1) {
|
||||
|
||||
e1.printStackTrace();
|
||||
} catch (ISInvalidQueryException e1) {
|
||||
|
||||
e1.printStackTrace();
|
||||
} catch (ISException e1) {
|
||||
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
if( resource == null) return new RemoveResourceResponse();
|
||||
|
||||
else {
|
||||
|
||||
logger.debug("Try to remove the resource from the ISIC");
|
||||
GCUBEPublisher publisher = new GCUBEPublisher();
|
||||
ProfileManager manager;
|
||||
try {
|
||||
manager = new GCUBEPublisher().getProfileManager(null, GHNContext.getContext().getDefaultScope());
|
||||
manager.removeFromDISIC(ID,ServiceContext.getContext().getCredentials(),resource.getType());
|
||||
} catch (GCUBEPublisherException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
return new RemoveResourceResponse();
|
||||
}
|
||||
|
||||
try{
|
||||
|
||||
ProfileResource resource = getProfileResource(ID );
|
||||
|
||||
profile.load(new StringReader(resource.getProfile()));
|
||||
//remove profile
|
||||
resource.remove();
|
||||
RegistryServiceAddressingLocator locator = new RegistryServiceAddressingLocator();
|
||||
RegistryPortType portType = locator.getRegistryPortTypePort(resource.getEPR());
|
||||
|
||||
//destroy resource
|
||||
portType.destroy(new Destroy());
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error(":Error removing resource for ID "+ e);
|
||||
throw new RemoteException();
|
||||
}
|
||||
|
||||
try {
|
||||
if (profile.getType().compareTo(GCUBEHostingNode.TYPE) == 0) {
|
||||
unregisterRIRelatedToDHN(profile.getID());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Error removing profile related to this GHNID for ID "+ e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
logger.info(" Profile destroyed");
|
||||
try {
|
||||
updateCounterInfo(profile,operationType.destroy.name(),Calendar.getInstance());
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Error updating Counting info for resource with ID " + profile.getID());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return new RemoveResourceResponse();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Log Security info
|
||||
*
|
||||
* @param methodName The Method Name
|
||||
*/
|
||||
private void logSecurityInfo(String methodName) {
|
||||
|
||||
logger.info("Security info for method "+ methodName );
|
||||
|
||||
//String identity = SecurityManager.getManager().getCaller();
|
||||
//logger.info("The caller is: " + identity);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Resource has been created
|
||||
*
|
||||
* @param id the Resource ID
|
||||
* @return the resource ( null if the resource has not been created yet
|
||||
*/
|
||||
protected synchronized ProfileResource getProfileResource(String id ){
|
||||
ProfileResource resource = null;
|
||||
|
||||
ResourceKey key = new SimpleResourceKey(ProfileContext.getContext().getWSHome().getKeyTypeName(), id);
|
||||
|
||||
try {
|
||||
resource = (ProfileResource) ProfileContext.getContext().getWSHome().find(key);
|
||||
}
|
||||
catch (Exception e ){
|
||||
logger.debug("A profile with the given id has not been created yet");
|
||||
return null;
|
||||
}
|
||||
return resource;
|
||||
|
||||
}
|
||||
|
||||
protected synchronized boolean isResourceCreated(String id) {
|
||||
if (getProfileResource(id) != null) return true; else return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Update the Registry Factory RPs
|
||||
*
|
||||
*
|
||||
* @param resource GCUBEResource representing a profile
|
||||
* @param operationType the type of Operation performed on the Profile
|
||||
* @param updateTime The last operation Time
|
||||
* @throws Exception Exception
|
||||
*/
|
||||
|
||||
public synchronized void updateCounterInfo(GCUBEResource resource, String operationType, Calendar updateTime) throws Exception{
|
||||
|
||||
RegistryProperty property = new RegistryProperty();
|
||||
|
||||
property.setUniqueID(resource.getID());
|
||||
property.setOperationType(operationType);
|
||||
property.setChangeTime(updateTime);
|
||||
//select the type of the resource to update
|
||||
for (Method method :((RegistryFactoryResource)FactoryContext.getContext().getWSHome().find()).getClass().getDeclaredMethods()) {
|
||||
if (method.getName().contains(resource.getType()) && method.getName().contains("set")) {
|
||||
method.invoke((RegistryFactoryResource)FactoryContext.getContext().getWSHome().find(),property);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
((RegistryFactoryResource)FactoryContext.getContext().getWSHome().find()).getPersistenceDelegate().store(((RegistryFactoryResource)FactoryContext.getContext().getWSHome().find()));
|
||||
|
||||
|
||||
/* String gLueType= prof.getGlueResourceType();
|
||||
if (gLueType.trim().compareTo("GlueSE")==0) {
|
||||
this.getResource().setGLiteSE(property);
|
||||
|
||||
|
||||
}else if (gLueType.trim().compareTo("GlueCE")==0) {
|
||||
this.getResource().setGLiteCE(property);
|
||||
|
||||
}else if(gLueType.trim().compareTo("GlueSite")==0) {
|
||||
|
||||
this.getResource().setGLiteSite(property);
|
||||
|
||||
}else if (gLueType.trim().compareTo("GlueService")==0) {
|
||||
|
||||
this.getResource().setGLiteService(property);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void unregisterRIRelatedToDHN(String ID){}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -10,17 +10,14 @@ public class RegistryPersistenceDelegate extends GCUBEWSFilePersistenceDelegate<
|
|||
protected void onLoad(ProfileResource resource, ObjectInputStream ois) throws Exception {
|
||||
|
||||
super.onLoad(resource, ois);
|
||||
/*List<String> IDs = (List<String>) ois.readObject();
|
||||
for (String id :IDs) resource.addCollectionID(id);
|
||||
resource.collections= (List<ResourceKey>) ois.readObject();*/
|
||||
|
||||
resource.setProfile((String)ois.readUTF());
|
||||
resource.setNotificationProfile(resource.getProfile());
|
||||
}
|
||||
|
||||
protected void onStore(ProfileResource resource,ObjectOutputStream oos) throws Exception {
|
||||
|
||||
super.onStore(resource, oos);
|
||||
/* oos.writeObject(resource.getCollectionIDs());
|
||||
oos.writeObject(resource.collections);*/
|
||||
oos.writeUTF(resource.getProfile());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,11 @@ import java.util.ArrayList;
|
|||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.gcube.common.core.is.publisher.ISPublisher;
|
||||
import org.gcube.common.core.node.GHNContext;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.informationsystem.registry.impl.core.*;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.informationsystem.registry.impl.core.FactoryContext;
|
||||
import org.gcube.informationsystem.registry.impl.core.ServiceContext;
|
||||
|
||||
/**
|
||||
* Registration Thread class
|
||||
|
@ -21,7 +20,7 @@ public class RegistrationThread implements Runnable{
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static Log logger = LogFactory.getLog(RegistrationThread.class.getName());
|
||||
private static GCUBELog logger = new GCUBELog(RegistrationThread.class.getName());
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -48,7 +47,7 @@ public class RegistrationThread implements Runnable{
|
|||
|
||||
try {
|
||||
|
||||
// This is the time intervall
|
||||
// This is the time interval
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(InterruptedException e){
|
||||
|
@ -56,7 +55,7 @@ public class RegistrationThread implements Runnable{
|
|||
}
|
||||
try {
|
||||
ISPublisher publisher = GHNContext.getImplementation(ISPublisher.class);
|
||||
publisher.registerToISNotification(FactoryContext.getContext().getEPR(),topics, ServiceContext.getContext().getCredentials() , new GCUBEScope(ServiceContext.getContext().getScope()));
|
||||
publisher.registerToISNotification(FactoryContext.getContext().getEPR(),topics, GHNContext.getContext().getDefaultScope(), ServiceContext.getContext() );
|
||||
return;
|
||||
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package org.gcube.informationsystem.registry.impl.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.core.is.ISException;
|
||||
import org.gcube.common.core.is.client.ISClient;
|
||||
import org.gcube.common.core.is.client.ISClient.ISInvalidQueryException;
|
||||
import org.gcube.common.core.is.client.ISClient.ISMalformedQueryException;
|
||||
import org.gcube.common.core.is.client.queries.GCUBEResourceFromIDQuery;
|
||||
import org.gcube.common.core.node.GHNContext;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
|
||||
public class RegistryUtil {
|
||||
|
||||
public static ISClient client = null;
|
||||
|
||||
public RegistryUtil () {
|
||||
try {
|
||||
client = GHNContext.getImplementation(ISClient.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static GCUBEResource getProfileFromIS(String ID) throws ISMalformedQueryException, ISInvalidQueryException, ISException {
|
||||
GCUBEResourceFromIDQuery query =client.getQuery(GCUBEResourceFromIDQuery.class);
|
||||
query.setResourceID(ID);
|
||||
List<GCUBEResource> resource = client.execute(query, GHNContext.getContext().getDefaultScope());
|
||||
if (resource != null) return resource.get(0);
|
||||
else return null;
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue