New ResourceRegistration portType implementation, integration with the new Publisher
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@34388 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
5747a6b48f
commit
ab6759a738
|
@ -3,5 +3,6 @@ package = org.gcube.informationsystem.registry
|
|||
lib.dir = Dependencies/ISREGISTRY
|
||||
wsdl.1 = RegistryFactory
|
||||
wsdl.2 = Registry
|
||||
wsdl.3 = ResourceRegistration
|
||||
namespace.1=http://gcube-system.org/namespaces/informationsystem/registry
|
||||
|
||||
|
|
|
@ -31,4 +31,15 @@
|
|||
|
||||
</service>
|
||||
|
||||
<service name="gcube/informationsystem/registry/ResourceRegistration" provider="Handler" use="literal" style="document">
|
||||
<parameter name="className" value="org.gcube.informationsystem.registry.impl.porttypes.ResourceRegistration"/>
|
||||
<wsdlFile>share/schema/org.gcube.informationsystem.registry/ResourceRegistration_service.wsdl</wsdlFile>
|
||||
<parameter name="allowedMethods" value="*"/>
|
||||
<parameter name="handlerClass" value="org.globus.axis.providers.RPCProvider"/>
|
||||
<parameter name="scope" value="Application"/>
|
||||
<parameter name="instance" value="gcube/informationsystem/registry/ResourceRegistration"/>
|
||||
<parameter name="providers" value="GCUBEProvider SubscribeProvider GetCurrentMessageProvider"/>
|
||||
<parameter name="loadOnStartup" value="true"/>
|
||||
|
||||
</service>
|
||||
</deployment>
|
||||
|
|
|
@ -10,96 +10,140 @@
|
|||
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<types>
|
||||
<xsd:schema targetNamespace="http://gcube-system.org/namespaces/informationsystem/registry"
|
||||
<xsd:schema
|
||||
targetNamespace="http://gcube-system.org/namespaces/informationsystem/registry"
|
||||
xmlns:tns="http://gcube-system.org/namespaces/informationsystem/registry"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<xsd:complexType name="SchemaValidationFaultType"/>
|
||||
<xsd:element name="SchemaValidationFault" type="SchemaValidationFaultType"/>
|
||||
<!-- MESSAGES -->
|
||||
|
||||
<xsd:complexType name="ResourceNotAcceptedFaultType"/>
|
||||
<xsd:element name="ResourceNotAcceptedFault" type="ResourceNotAcceptedFaultType"/>
|
||||
<xsd:complexType name="UpdateMessage">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="uniqueID" type="xsd:string" />
|
||||
<xsd:element name="type" type="xsd:string" />
|
||||
<xsd:element name="xmlProfile" type="xsd:string" />
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="CreateFaultType"/>
|
||||
<xsd:element name="CreateFault" type="CreateFaultType"/>
|
||||
|
||||
<xsd:complexType name="UpdateFaultType"/>
|
||||
<xsd:element name="UpdateFault" type="UpdateFaultType"/>
|
||||
<xsd:complexType name="CreateMessage">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="profile" type="xsd:string"
|
||||
minOccurs="1" maxOccurs="1" />
|
||||
<xsd:element name="type" type="xsd:string" />
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="RemoveFaultType"/>
|
||||
<xsd:element name="RemoveFault" type="RemoveFaultType"/>
|
||||
<xsd:complexType name="RemoveMessage">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="uniqueID" type="xsd:string"
|
||||
minOccurs="1" maxOccurs="1" />
|
||||
<xsd:element name="type" type="xsd:string" minOccurs="1"
|
||||
maxOccurs="1" />
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="ResourceDoesNotExistFaultType"/>
|
||||
<xsd:element name="ResourceDoesNotExistFault" type="ResourceDoesNotExistFaultType"/>
|
||||
<xsd:element name="create" type="tns:CreateMessage" />
|
||||
|
||||
<xsd:element name="createResponse">
|
||||
<xsd:complexType />
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="update" type="tns:UpdateMessage" />
|
||||
|
||||
<xsd:element name="updateResponse">
|
||||
<xsd:complexType />
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="remove" type="tns:RemoveMessage" />
|
||||
|
||||
<xsd:element name="removeResponse">
|
||||
<xsd:complexType />
|
||||
</xsd:element>
|
||||
|
||||
<!-- FAULTS -->
|
||||
<xsd:complexType name="InvalidResourceFault" />
|
||||
<xsd:element name="InvalidResourceFaultElement" type="tns:InvalidResourceFault" />
|
||||
|
||||
<xsd:complexType name="ResourceNotAcceptedFault" />
|
||||
<xsd:element name="ResourceNotAcceptedFaultElement" type="tns:ResourceNotAcceptedFault" />
|
||||
|
||||
<xsd:complexType name="CreateFault" />
|
||||
<xsd:element name="CreateFaultElement" type="tns:CreateFault" />
|
||||
|
||||
<xsd:complexType name="UpdateFault"/>
|
||||
<xsd:element name="UpdateFaultElement" type="tns:UpdateFault" />
|
||||
|
||||
<xsd:complexType name="RemoveFault" />
|
||||
<xsd:element name="RemoveFaultElement" type="tns:RemoveFault" />
|
||||
|
||||
<xsd:complexType name="ResourceDoesNotExistFault" />
|
||||
<xsd:element name="ResourceDoesNotExistFaultElement" type="tns:ResourceDoesNotExistFault" />
|
||||
</xsd:schema>
|
||||
</types>
|
||||
|
||||
|
||||
<message name="CreateRequest">
|
||||
<part name="request" element="tns:createResource"/>
|
||||
<part name="request" element="tns:create" />
|
||||
</message>
|
||||
<message name="CreateResponse">
|
||||
<part name="response" element="tns:createResponse"/>
|
||||
<part name="response" element="tns:createResponse" />
|
||||
</message>
|
||||
<message name="UpdateRequest">
|
||||
<part name="request" element="tns:updateResource"/>
|
||||
<part name="request" element="tns:update" />
|
||||
</message>
|
||||
<message name="UpdateResponse">
|
||||
<part name="response" element="tns:updateResponse"/>
|
||||
<part name="response" element="tns:updateResponse" />
|
||||
</message>
|
||||
<message name="RemoveRequest">
|
||||
<part name="request" element="tns:removeResource"/>
|
||||
<part name="request" element="tns:remove" />
|
||||
</message>
|
||||
<message name="RemoveResponse">
|
||||
<part name="response" element="tns:removeResponse"/>
|
||||
<part name="response" element="tns:removeResponse" />
|
||||
</message>
|
||||
<message name="SchemaValidationFaultMessage">
|
||||
<part name="fault" element="tns:SchemaValidationFault"/>
|
||||
<message name="InvalidResourceFaultMessage">
|
||||
<part name="fault" element="tns:InvalidResourceFaultElement" />
|
||||
</message>
|
||||
<message name="ResourceNotAcceptedFaultMessage">
|
||||
<part name="fault" element="tns:ResourceNotAcceptedFault"/>
|
||||
<part name="fault" element="tns:ResourceNotAcceptedFaultElement" />
|
||||
</message>
|
||||
<message name="CreateFaultMessage">
|
||||
<part name="fault" element="tns:CreateFault"/>
|
||||
<part name="fault" element="tns:CreateFaultElement" />
|
||||
</message>
|
||||
<message name="UpdateFaultMessage">
|
||||
<part name="fault" element="tns:UpdateFault"/>
|
||||
<part name="fault" element="tns:UpdateFaultElement" />
|
||||
</message>
|
||||
<message name="RemoveFaultMessage">
|
||||
<part name="fault" element="tns:RemoveFault"/>
|
||||
<part name="fault" element="tns:RemoveFaultElement" />
|
||||
</message>
|
||||
<message name="ResourceDoesNotExistFaultMessage">
|
||||
<part name="fault" element="tns:ResourceDoesNotExistFault"/>
|
||||
<part name="fault" element="tns:ResourceDoesNotExistFaultElement" />
|
||||
</message>
|
||||
|
||||
|
||||
<!--============================================================
|
||||
|
||||
P O R T T Y P E
|
||||
|
||||
============================================================-->
|
||||
<portType name="ResourceRegistrationPortType">
|
||||
<!--========P O R T T Y P E=============== -->
|
||||
<portType name="ResourceRegistrationPortType">
|
||||
|
||||
<operation name="create">
|
||||
<input message="tns:CreateRequest"/>
|
||||
<output message="tns:CreateResponse"/>
|
||||
<fault name="fault" message="tns:SchemaValidationFaultMessage"/>
|
||||
<fault name="fault" message="tns:ResourceNotAcceptedFaultMessage"/>
|
||||
<fault name="fault" message="tns:CreateFaultMessage"/>
|
||||
<input message="tns:CreateRequest" />
|
||||
<output message="tns:CreateResponse" />
|
||||
<fault name="fault" message="tns:InvalidResourceFaultMessage" />
|
||||
<fault name="fault1" message="tns:ResourceNotAcceptedFaultMessage" />
|
||||
<fault name="fault2" message="tns:CreateFaultMessage" />
|
||||
</operation>
|
||||
<operation name="update">
|
||||
<input message="tns:UpdateRequest"/>
|
||||
<output message="tns:UpdateResponse"/>
|
||||
<fault name="fault" message="tns:SchemaValidationFaultMessage"/>
|
||||
<fault name="fault" message="tns:ResourceNotAcceptedFaultMessage"/>
|
||||
<fault name="fault" message="tns:UpdateFaultMessage"/>
|
||||
<input message="tns:UpdateRequest" />
|
||||
<output message="tns:UpdateResponse" />
|
||||
<fault name="fault" message="tns:InvalidResourceFaultMessage" />
|
||||
<fault name="fault1" message="tns:ResourceNotAcceptedFaultMessage" />
|
||||
<fault name="fault2" message="tns:UpdateFaultMessage" />
|
||||
</operation>
|
||||
<operation name="remove">
|
||||
<input message="tns:RemoveRequest"/>
|
||||
<output message="tns:RemoveResponse"/>
|
||||
<fault name="fault" message="tns:RemoveFaultMessage"/>
|
||||
<fault name="fault" message="tns:ResourceDoesNotExistFaultMessage"/>
|
||||
<input message="tns:RemoveRequest" />
|
||||
<output message="tns:RemoveResponse" />
|
||||
<fault name="fault" message="tns:ResourceDoesNotExistFaultMessage" />
|
||||
<fault name="fault1" message="tns:RemoveFaultMessage" />
|
||||
</operation>
|
||||
</portType>
|
||||
</portType>
|
||||
|
||||
</definitions>
|
|
@ -15,7 +15,9 @@ import java.util.List;
|
|||
import org.apache.axis.components.uuid.UUIDGen;
|
||||
import org.apache.axis.components.uuid.UUIDGenFactory;
|
||||
import org.gcube.common.core.contexts.GCUBEServiceContext;
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.faults.GCUBEFault;
|
||||
import org.gcube.common.core.informationsystem.publisher.ISResourcePublisher;
|
||||
import org.gcube.common.core.porttypes.GCUBEPortType;
|
||||
import org.gcube.common.core.resources.GCUBEHostingNode;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
|
@ -28,7 +30,6 @@ import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
|
|||
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
|
||||
import org.gcube.informationsystem.registry.impl.filters.FilterManager;
|
||||
import org.gcube.informationsystem.registry.impl.filters.FilterExecutor.InvalidFilterException;
|
||||
import org.gcube.informationsystem.registry.impl.profilemanagement.ProfileManager;
|
||||
import org.gcube.informationsystem.registry.impl.profilemanagement.GHN;
|
||||
import org.gcube.informationsystem.registry.impl.resourcemanagement.Pair;
|
||||
import org.gcube.informationsystem.registry.impl.state.ProfileResource;
|
||||
|
@ -40,6 +41,7 @@ import org.gcube.informationsystem.registry.stubs.RemoveResourceMessage;
|
|||
import org.gcube.informationsystem.registry.stubs.RemoveResourceResponse;
|
||||
import org.gcube.informationsystem.registry.stubs.ResourceNotAcceptedFault;
|
||||
import org.gcube.informationsystem.registry.stubs.SchemaValidationFault;
|
||||
import org.gcube.informationsystem.registry.stubs.UpdateFault;
|
||||
import org.gcube.informationsystem.registry.stubs.UpdateResourceMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.UpdateResourceResponse;
|
||||
|
||||
|
@ -256,7 +258,6 @@ public class RegistryFactory extends GCUBEPortType {
|
|||
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 ");
|
||||
|
@ -268,7 +269,7 @@ public class RegistryFactory extends GCUBEPortType {
|
|||
}
|
||||
// check if the profile exist
|
||||
if (!isResourceCreated(ID)) {
|
||||
input = new CreateResourceMessage();
|
||||
CreateResourceMessage input = new CreateResourceMessage();
|
||||
input.setProfile(xmlProfile);
|
||||
input.setType(mess.getType());
|
||||
this.createResource(input);
|
||||
|
@ -332,15 +333,14 @@ public class RegistryFactory extends GCUBEPortType {
|
|||
logger.warn("Resource ID is missing, cannot manage the resource");
|
||||
throw new RemoteException("Resource ID is missing, cannot manage the resource");
|
||||
}
|
||||
//TODO: delete the profile with the GCUBEPublisher
|
||||
try {
|
||||
logger.debug("Trying to remove the resource from the IS-IC");
|
||||
new ProfileManager().remove(ID, type, ServiceContext.getContext().getScope(), ServiceContext.getContext());
|
||||
logger.info("Resource removed from the IS-IC");
|
||||
ISResourcePublisher publisher = GHNContext.getImplementation(ISResourcePublisher.class);
|
||||
publisher.remove(ID, type, ServiceContext.getContext().getScope(), ServiceContext.getContext());
|
||||
logger.debug("Resource " + ID+ " successfully removed");
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to remove the resource", e);
|
||||
throw ServiceContext.getContext().getDefaultException("", e).toFault(
|
||||
"Unable to remove the resource: the remote IS-IC returned an error");
|
||||
logger.error("Unable to remove the resource " + ID, e);
|
||||
throw new UpdateFault();
|
||||
}
|
||||
// if the resource is a GHN, remove also the related RIs
|
||||
try {
|
||||
|
|
|
@ -1,11 +1,201 @@
|
|||
package org.gcube.informationsystem.registry.impl.porttypes;
|
||||
|
||||
import org.gcube.common.core.contexts.GCUBEServiceContext;
|
||||
import org.gcube.common.core.porttypes.GCUBEPortType;
|
||||
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
import org.apache.axis.components.uuid.UUIDGen;
|
||||
import org.apache.axis.components.uuid.UUIDGenFactory;
|
||||
import org.gcube.common.core.contexts.GCUBEServiceContext;
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.informationsystem.publisher.ISResourcePublisher;
|
||||
import org.gcube.common.core.porttypes.GCUBEPortType;
|
||||
import org.gcube.common.core.resources.GCUBEHostingNode;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
|
||||
import org.gcube.informationsystem.registry.impl.filters.FilterManager;
|
||||
import org.gcube.informationsystem.registry.impl.filters.FilterExecutor.InvalidFilterException;
|
||||
import org.gcube.informationsystem.registry.impl.profilemanagement.GHN;
|
||||
import org.gcube.informationsystem.registry.impl.state.Definitions.ResourceType;
|
||||
import org.gcube.informationsystem.registry.stubs.CreateFault;
|
||||
import org.gcube.informationsystem.registry.stubs.CreateMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.CreateResponse;
|
||||
import org.gcube.informationsystem.registry.stubs.InvalidResourceFault;
|
||||
import org.gcube.informationsystem.registry.stubs.RemoveFault;
|
||||
import org.gcube.informationsystem.registry.stubs.RemoveMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.RemoveResponse;
|
||||
import org.gcube.informationsystem.registry.stubs.ResourceNotAcceptedFault;
|
||||
import org.gcube.informationsystem.registry.stubs.UpdateFault;
|
||||
import org.gcube.informationsystem.registry.stubs.UpdateMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.UpdateResponse;
|
||||
|
||||
/**
|
||||
*
|
||||
* Implementation of the ResourceRegistration portType
|
||||
*
|
||||
* @author Manuele Simi (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
public class ResourceRegistration extends GCUBEPortType {
|
||||
|
||||
protected final GCUBELog logger = new GCUBELog(ResourceRegistration.class);
|
||||
|
||||
/** The UUIDGen */
|
||||
private static final UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new resource
|
||||
* @param message
|
||||
* @return
|
||||
* @throws SchemaValidationFault
|
||||
* @throws ResourceNotAcceptedFault
|
||||
* @throws CreateFaultType
|
||||
*/
|
||||
public CreateResponse create(CreateMessage message)
|
||||
throws InvalidResourceFault, ResourceNotAcceptedFault, CreateFault {
|
||||
|
||||
logger.info("CreateResource operation invoked in scope " + ServiceContext.getContext().getScope());
|
||||
GCUBEResource resource = this.load(message.getType(),message.getProfile());
|
||||
this.applyFilters(resource);
|
||||
//create the new resource with the publisher
|
||||
try {
|
||||
ISResourcePublisher publisher = GHNContext.getImplementation(ISResourcePublisher.class);
|
||||
publisher.register(resource, ServiceContext.getContext().getScope(), ServiceContext.getContext());
|
||||
logger.debug("Resource " + resource.getID() + " successfully created");
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to register the resource", e);
|
||||
throw new CreateFault();
|
||||
}
|
||||
|
||||
return new CreateResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing resource
|
||||
* @param message
|
||||
* @return
|
||||
* @throws SchemaValidationFault
|
||||
* @throws ResourceNotAcceptedFault
|
||||
* @throws UpdateFaultType
|
||||
*/
|
||||
public UpdateResponse update(UpdateMessage message)
|
||||
throws InvalidResourceFault, ResourceNotAcceptedFault, UpdateFault {
|
||||
|
||||
logger.info("UpdateResource operation invoked in scope " + ServiceContext.getContext().getScope());
|
||||
|
||||
GCUBEResource resource = this.load(message.getType(), message.getXmlProfile(), message.getUniqueID());
|
||||
this.applyFilters(resource);
|
||||
//update the resource with the publisher
|
||||
try {
|
||||
ISResourcePublisher publisher = GHNContext.getImplementation(ISResourcePublisher.class);
|
||||
publisher.register(resource, ServiceContext.getContext().getScope(), ServiceContext.getContext());
|
||||
logger.debug("Resource " + resource.getID() + " successfully updated");
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to update the resource", e);
|
||||
throw new UpdateFault();
|
||||
}
|
||||
return new UpdateResponse();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
* @return
|
||||
* @throws ResourceDoesNotExistFaultType
|
||||
* @throws RemoveFaultType
|
||||
*/
|
||||
public RemoveResponse remove(RemoveMessage message) throws RemoveFault,RemoteException {
|
||||
String ID = message.getUniqueID();
|
||||
String type = message.getType();
|
||||
logger.info("RemoveResource operation invoked on resource ID=" + ID + ", type=" + type);
|
||||
if (ID == null || ID.compareTo("") == 0) {
|
||||
logger.warn("Resource ID is missing, cannot manage the resource");
|
||||
throw new RemoteException("Resource ID is missing, cannot manage the resource");
|
||||
}
|
||||
try {
|
||||
ISResourcePublisher publisher = GHNContext.getImplementation(ISResourcePublisher.class);
|
||||
publisher.remove(ID, type, ServiceContext.getContext().getScope(), ServiceContext.getContext());
|
||||
logger.debug("Resource " + ID+ " successfully removed");
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to remove the resource " + ID, e);
|
||||
throw new UpdateFault();
|
||||
}
|
||||
|
||||
// if the resource is a GHN, remove also the related RIs
|
||||
try {
|
||||
if (type.compareTo(GCUBEHostingNode.TYPE) == 0) {
|
||||
logger.debug("Removing the related RIs");
|
||||
GHN ghn = new GHN(ID);
|
||||
ghn.unregisterHostedRI();
|
||||
logger.debug("Related RIs removed");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while removing RI profiles related to the GHN", e);
|
||||
}
|
||||
|
||||
return new RemoveResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the {@link GCUBEResource} from its serialization
|
||||
* @param type the type of the resource to load
|
||||
* @param profile the serialization
|
||||
* @param id the optional identifier to assign
|
||||
* @return the resource
|
||||
* @throws InvalidResourceFault if the resource was null
|
||||
* @throws ResourceNotAcceptedFault if the resource was not accepted
|
||||
*/
|
||||
private GCUBEResource load(String type, String profile, String ... id)
|
||||
throws InvalidResourceFault,ResourceNotAcceptedFault {
|
||||
|
||||
if (profile == null || profile.compareTo("") == 0) {
|
||||
logger.error("The input resource is null");
|
||||
throw new InvalidResourceFault();
|
||||
}
|
||||
GCUBEResource resource;
|
||||
try {
|
||||
resource = ResourceType.valueOf(type).getResourceClass();
|
||||
resource.load(new BufferedReader(new InputStreamReader( new ByteArrayInputStream(profile.getBytes("UTF-8")),"UTF-8")));
|
||||
resource.addScope(ServiceContext.getContext().getScope());
|
||||
|
||||
// check the ID
|
||||
if (resource.getID() == null || resource.getID().compareTo("") == 0) {
|
||||
String newid = (id != null && id.length>0) ? id[0] : uuidgen.nextUUID();
|
||||
if (!resource.setID(newid)) {
|
||||
logger.error("Unable to set a new ID to the resource");
|
||||
throw new ResourceNotAcceptedFault();
|
||||
}
|
||||
}
|
||||
return resource;
|
||||
} catch (Exception ex) {
|
||||
logger.error("Error trying to load profile", ex);
|
||||
throw new InvalidResourceFault();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the configured filters to the resource
|
||||
* @param resource the resource to filter
|
||||
* @throws ResourceNotAcceptedFault if the resource was not accepted
|
||||
*/
|
||||
private void applyFilters(GCUBEResource resource) throws ResourceNotAcceptedFault {
|
||||
// apply resource filter
|
||||
try {
|
||||
if (!FilterManager.getExecutor(resource.getType()).accept(resource)) {
|
||||
logger.warn("Resource " + resource.getID() + " NOT accepted ");
|
||||
throw new ResourceNotAcceptedFault();
|
||||
}
|
||||
logger.trace("Resource " + resource.getID() + " accepted ");
|
||||
} catch (InvalidFilterException e) {
|
||||
logger.warn("Invalid filter selected, the resource "+ resource.getID() + " CANNOT be filtered ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected GCUBEServiceContext getServiceContext() {
|
||||
return ServiceContext.getContext();
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.gcube.common.core.informationsystem.client.QueryParameter;
|
|||
import org.gcube.common.core.informationsystem.client.XMLResult;
|
||||
import org.gcube.common.core.informationsystem.client.ISClient.ISMalformedQueryException;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery;
|
||||
import org.gcube.common.core.informationsystem.publisher.ISResourcePublisher;
|
||||
import org.gcube.common.core.resources.GCUBERunningInstance;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.informationsystem.registry.impl.porttypes.RegistryFactory;
|
||||
|
@ -39,12 +40,8 @@ public class GHN {
|
|||
/**
|
||||
* Unregisters all the RIs hosted on the gHN
|
||||
*
|
||||
* @param service
|
||||
* @throws ISMalformedQueryException
|
||||
* @throws ISInvalidQueryException
|
||||
* @throws ISException
|
||||
* @throws GCUBEFault
|
||||
* @throws RemoteException
|
||||
* @deprecated
|
||||
*/
|
||||
public void unregisterHostedRIs(RegistryFactory service) throws Exception {
|
||||
if (client == null)
|
||||
|
@ -69,4 +66,30 @@ public class GHN {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterHostedRI() throws Exception {
|
||||
if (client == null)
|
||||
client = GHNContext.getImplementation(ISClient.class);
|
||||
|
||||
GCUBEGenericQuery query = client.getQuery("RIOnGHN");
|
||||
query.addParameters(new QueryParameter("ID", this.id));
|
||||
|
||||
// query to IS on order to retrieve the RI deployed on the GHN;
|
||||
List<XMLResult> resources = client.execute(query, ServiceContext.getContext().getScope());
|
||||
|
||||
if (resources.size() != 0) {
|
||||
for (XMLResult resource : resources) {
|
||||
try {
|
||||
String id = resource.evaluate("/Resource/ID/text()").get(0);
|
||||
ISResourcePublisher publisher = GHNContext.getImplementation(ISResourcePublisher.class);
|
||||
publisher.remove(id, GCUBERunningInstance.TYPE, ServiceContext.getContext().getScope(), ServiceContext.getContext());
|
||||
logger.debug("Resource " + id+ " successfully removed");
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to remove a hosted RI from ghn " + this.id, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,162 +0,0 @@
|
|||
package org.gcube.informationsystem.registry.impl.profilemanagement;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.axis.message.addressing.AttributedURI;
|
||||
import org.apache.axis.message.addressing.EndpointReferenceType;
|
||||
import org.apache.axis.types.URI;
|
||||
|
||||
import org.gcube.common.core.contexts.GCUBERemotePortTypeContext;
|
||||
import org.gcube.common.core.resources.GCUBEResource;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.scope.GCUBEScopeNotSupportedException;
|
||||
import org.gcube.common.core.scope.ServiceMap;
|
||||
import org.gcube.common.core.scope.ServiceMap.ServiceType;
|
||||
import org.gcube.common.core.security.GCUBEServiceSecurityManager;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.informationsystem.collector.stubs.wsdai.DataResourceUnavailableFaultType;
|
||||
import org.gcube.informationsystem.collector.stubs.wsdai.InvalidResourceNameFaultType;
|
||||
import org.gcube.informationsystem.collector.stubs.wsdai.NotAuthorizedFaultType;
|
||||
import org.gcube.informationsystem.collector.stubs.wsdai.ServiceBusyFaultType;
|
||||
import org.gcube.informationsystem.collector.stubs.wsdaix.InvalidCollectionNameFaultType;
|
||||
import org.gcube.informationsystem.collector.stubs.wsdaix.RemoveDocumentRequestWrapper;
|
||||
import org.gcube.informationsystem.collector.stubs.wsdaix.RemoveDocumentsRequest;
|
||||
import org.gcube.informationsystem.collector.stubs.wsdaix.RemoveDocumentsResponse;
|
||||
import org.gcube.informationsystem.collector.stubs.wsdaix.XMLCollectionAccessPT;
|
||||
import org.gcube.informationsystem.collector.stubs.wsdaix.service.WsdaixServiceAddressingLocator;
|
||||
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
|
||||
|
||||
public class ProfileManager {
|
||||
|
||||
protected static final GCUBELog logger = new GCUBELog(ProfileManager.class);
|
||||
|
||||
protected Set<EndpointReferenceType> ICEprs = new HashSet<EndpointReferenceType>();
|
||||
|
||||
protected String VOMapName;
|
||||
|
||||
public enum ResourceTypes {
|
||||
Service, CS, CSInstance, Collection, RunningInstance, ExternalRunningInstance, GHN, gLiteResource, MetadataCollection, GenericResource
|
||||
}
|
||||
|
||||
public ProfileManager() throws Exception {
|
||||
|
||||
GCUBEScope scope = ServiceContext.getContext().getScope();
|
||||
|
||||
ServiceMap map;
|
||||
try {
|
||||
map = scope.getServiceMap();
|
||||
} catch (GCUBEScopeNotSupportedException e1) {
|
||||
logger.error("error retrieving service map for scope "
|
||||
+ scope.toString(), e1);
|
||||
throw new Exception(e1);
|
||||
}
|
||||
this.getSinks(map);
|
||||
VOMapName = scope.getName();
|
||||
}
|
||||
|
||||
|
||||
public void add(GCUBEResource resource, GCUBEScope scope, GCUBEServiceSecurityManager manager) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a {@link GCUBEResource} from the IS
|
||||
*
|
||||
* @param uniqueID the uniqueID to of the GCUBEResource to remove
|
||||
* @param type the type of Profile
|
||||
*
|
||||
* @throws Exception if the unregistration fails
|
||||
*/
|
||||
|
||||
public void remove(String uniqueID, String type, GCUBEScope scope,
|
||||
GCUBEServiceSecurityManager manager) throws Exception {
|
||||
|
||||
for (EndpointReferenceType sink : this.ICEprs) {
|
||||
String isIcAddress = sink.getAddress().toString();
|
||||
// check if the type has been specified
|
||||
if (type != null && type.compareTo("") != 0) {
|
||||
try {
|
||||
logger.debug("Removing profile from sink " + isIcAddress);
|
||||
this.removeDocuments(isIcAddress, scope, new URI("gcube://resource"), new URI("gcube://Profiles/"+ type), uniqueID);
|
||||
} catch (Exception e) {
|
||||
logger.error(
|
||||
"An error occurs while trying to remove the GCUBE Profile with ID "
|
||||
+ uniqueID, e);
|
||||
throw new Exception(
|
||||
"Unregistration failed for the GCUBE Profile with ID "
|
||||
+ uniqueID);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
// the type of the resource to delete is not specified, try
|
||||
// all the resource types
|
||||
logger.debug(" trying to remove profile with UniqueID" + uniqueID);
|
||||
for (int n = 0; n < ResourceTypes.values().length; n++) {
|
||||
this.removeDocuments(isIcAddress, scope, new URI("gcube://resource"),
|
||||
new URI("gcube://Profiles/"+ ResourceTypes.values()[n].toString()), uniqueID);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(
|
||||
" An error occurs while trying to remove the GCUBE Profile with ID "
|
||||
+ uniqueID, e);
|
||||
throw new Exception(
|
||||
"Unregistration failed for the GCUBE Profile with ID "
|
||||
+ uniqueID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the RemoveDocuments operation
|
||||
* @param serviceURL The URL of the data service
|
||||
* @param resourceName The abstract name of the data resource
|
||||
* @param collectionURI The URI of the collection from which documents should be removed
|
||||
* @param documentNames An array of document names that should be removed
|
||||
*/
|
||||
private RemoveDocumentsResponse removeDocuments(String serviceURL, GCUBEScope scope,
|
||||
URI resourceName, URI collectionURI, String documentName)
|
||||
throws DataResourceUnavailableFaultType, MalformedURLException, RemoteException, ServiceBusyFaultType,
|
||||
InvalidResourceNameFaultType, InvalidCollectionNameFaultType, NotAuthorizedFaultType {
|
||||
RemoveDocumentsRequest request = new RemoveDocumentsRequest();
|
||||
request.setDataResourceAbstractName(resourceName);
|
||||
RemoveDocumentRequestWrapper[] wrappers = new RemoveDocumentRequestWrapper[1];
|
||||
wrappers[0] = new RemoveDocumentRequestWrapper();
|
||||
wrappers[0].setDocumentName(documentName);
|
||||
request.setRemoveDocumentRequestWrapper(wrappers);
|
||||
request.setCollectionName(collectionURI);
|
||||
XMLCollectionAccessPT stubs = null;
|
||||
try {
|
||||
stubs = new WsdaixServiceAddressingLocator().getXMLCollectionAccessPTPort(new URL(serviceURL));
|
||||
stubs = GCUBERemotePortTypeContext.getProxy(stubs, scope);
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to get documents", e);
|
||||
}
|
||||
return stubs.removeDocuments(request);
|
||||
}
|
||||
|
||||
private void getSinks(final ServiceMap map) throws Exception {
|
||||
|
||||
Set<EndpointReferenceType> tmpEPRs = new HashSet<EndpointReferenceType>();
|
||||
// get the list of IC where to register the RPs
|
||||
if (map.getEndpoints(ServiceType.ISICProfileQueryPT) != null)
|
||||
tmpEPRs.addAll(map.getEndpoints(ServiceType.ISICProfileQueryPT));
|
||||
|
||||
if (map.getEndpoints(ServiceType.ISICAllQueryPT) != null)
|
||||
tmpEPRs.addAll(map.getEndpoints(ServiceType.ISICAllQueryPT));
|
||||
|
||||
//TODO: temporary patch, to remove when XMLDocumentAccess will be available in the servicemap (gcore >= 0.5.1)
|
||||
for (EndpointReferenceType epr : tmpEPRs) {
|
||||
EndpointReferenceType newepr = new EndpointReferenceType();
|
||||
String path = epr.getAddress().toString();
|
||||
newepr.setAddress(new AttributedURI(path.replace("XQueryAccess", "XMLCollectionAccess")));
|
||||
this.ICEprs.add(newepr);
|
||||
}
|
||||
if (this.ICEprs.size() == 0)
|
||||
throw new Exception("No sink available in the Service Map");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue