git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@82 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
7d626bdaa3
commit
19cf6a6a3a
|
@ -7,6 +7,8 @@ import java.rmi.RemoteException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.apache.axis.components.uuid.UUIDGen;
|
||||
import org.apache.axis.components.uuid.UUIDGenFactory;
|
||||
import org.apache.axis.utils.XMLUtils;
|
||||
import org.gcube.common.core.contexts.GCUBEServiceContext;
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
|
@ -57,6 +59,11 @@ import org.oasis.wsrf.lifetime.Destroy;
|
|||
public class RegistryFactory extends GCUBEStartupPortType{
|
||||
|
||||
|
||||
/**
|
||||
* The UUIDGen
|
||||
*/
|
||||
private static final UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
|
||||
|
||||
|
||||
/**
|
||||
* Object logger.
|
||||
|
@ -114,12 +121,8 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
* @throws ProfileAlreadyRegisteredFault
|
||||
*/
|
||||
public String createResource(CreateResourceMessage inputMessage) throws SchemaValidationFault,RemoteException,ProfileAlreadyRegisteredFault {
|
||||
|
||||
|
||||
GCUBEResource resource = null;
|
||||
|
||||
logSecurityInfo("createResource");
|
||||
|
||||
String profile = inputMessage.getProfile();
|
||||
|
||||
if (profile == null || profile.compareTo("") == 0) {
|
||||
|
@ -127,16 +130,12 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
logger.debug(msg);
|
||||
throw new RemoteException(msg);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
resource = this.getResourceClass(inputMessage.getType());
|
||||
resource.load(new StringReader(profile));
|
||||
//the parse Profile class allows to extract from profiles information about type/SCOPE/UniqueID
|
||||
//in order to distiguish among different Resource Type
|
||||
|
||||
//Adding scopes to Profile
|
||||
|
||||
String [] scopes = inputMessage.getScopes();
|
||||
if (scopes != null) {
|
||||
for (String scope : scopes) {
|
||||
|
@ -144,10 +143,8 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
resource.addScope(GCUBEScope.getScope(scope));
|
||||
}
|
||||
}
|
||||
|
||||
//check ID
|
||||
if (resource.getID()== null) {}
|
||||
|
||||
if (resource.getID()== null || resource.getID().compareTo("")==0) {resource.setID(uuidgen.nextUUID()); }
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -155,7 +152,6 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
ex.printStackTrace();
|
||||
throw new SchemaValidationFault();
|
||||
}
|
||||
|
||||
//check if the Resource already Exist
|
||||
|
||||
if (isResourceCreated(resource.getID())) {
|
||||
|
@ -163,7 +159,6 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
logger.debug(msg);
|
||||
throw new ProfileAlreadyRegisteredFault();
|
||||
}
|
||||
|
||||
//try to create resource
|
||||
try {
|
||||
ProfileContext.getContext().getWSHome().create(ProfileContext.getContext().makeKey(resource.getID()),resource);
|
||||
|
@ -174,9 +169,8 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
ex.printStackTrace();
|
||||
throw new RemoteException(msg);
|
||||
}
|
||||
|
||||
try {
|
||||
updateCounterInfo (resource,operationType.create.name(),Calendar.getInstance());
|
||||
updateCounterInfo (resource.getID(),inputMessage.getType(),operationType.create.name(),Calendar.getInstance());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error updating Counting info for resource with ID " + resource.getID());
|
||||
e.printStackTrace();
|
||||
|
@ -189,7 +183,6 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
e.printStackTrace();
|
||||
}
|
||||
return writer.toString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -205,29 +198,19 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
public UpdateResourceResponse updateResource(UpdateProfileMessage mess) throws RemoteException,SchemaValidationFault,GCUBEFault {
|
||||
|
||||
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();
|
||||
|
@ -236,27 +219,24 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
this.createResource(input);
|
||||
return new UpdateResourceResponse();
|
||||
}
|
||||
|
||||
try {
|
||||
resource = this.getResourceClass(mess.getType());
|
||||
resource.load(new StringReader(xmlProfile));
|
||||
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());
|
||||
updateCounterInfo (ID,mess.getType(),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();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -268,22 +248,15 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
* @throws RemoteException Exceptions
|
||||
*/
|
||||
public RemoveResourceResponse removeResource (RemoveResourceMessage inputMessage) throws RemoteException,GCUBEFault{
|
||||
|
||||
logSecurityInfo("removeResource");
|
||||
|
||||
GCUBEResource profile= null;
|
||||
|
||||
String ID = inputMessage.getUniqueID();
|
||||
String type = inputMessage.getType();
|
||||
|
||||
if (ID == null || ID.compareTo("") ==0) {
|
||||
logger.debug("ID missing ");
|
||||
throw new RemoteException("Error, ID missing");
|
||||
}
|
||||
|
||||
//controls if the UniqueID exist
|
||||
//check if the UniqueID exist
|
||||
if (!(isResourceCreated(ID))){
|
||||
|
||||
GCUBEResource resource = null;
|
||||
try {
|
||||
resource = RegistryUtil.getProfileFromIS(ID,this.getResourceClass(type).getClass());
|
||||
|
@ -291,31 +264,21 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
logger.error("Error gettign profile from IS ");
|
||||
return new RemoveResourceResponse();
|
||||
}
|
||||
|
||||
|
||||
if( resource == null) return new RemoveResourceResponse();
|
||||
|
||||
else {
|
||||
|
||||
logger.debug("Try to remove the resource from the IS-IC");
|
||||
ProfileManager manager;
|
||||
try {
|
||||
manager = new GCUBEPublisher().getProfileManager(null, GHNContext.getContext().getDefaultScope());
|
||||
manager.removeFromDISIC(ID,ServiceContext.getContext().getCredentials(),resource.getType());
|
||||
manager.removeFromDISIC(ID,resource.getType());
|
||||
} catch (GCUBEPublisherException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
return new RemoveResourceResponse();
|
||||
}
|
||||
|
||||
try{
|
||||
|
||||
ProfileResource resource = getProfileResource(ID );
|
||||
profile = this.getResourceClass(type);
|
||||
profile.load(new StringReader( XMLUtils.DocumentToString(resource.getProfile())));
|
||||
//remove profile
|
||||
resource.removeProfile();
|
||||
RegistryServiceAddressingLocator locator = new RegistryServiceAddressingLocator();
|
||||
RegistryPortType portType = locator.getRegistryPortTypePort(resource.getEPR());
|
||||
|
@ -329,24 +292,21 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
logger.error("Error removing resource for ID "+ e);
|
||||
throw new RemoteException();
|
||||
}
|
||||
|
||||
try {
|
||||
if (profile.getType().compareTo(GCUBEHostingNode.TYPE) == 0) {
|
||||
RegistryUtil.unregisterRIRelatedToDHN(profile.getID(),this);
|
||||
if (type.compareTo(GCUBEHostingNode.TYPE) == 0) {
|
||||
RegistryUtil.unregisterRIRelatedToDHN(ID,this);
|
||||
}
|
||||
}
|
||||
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());
|
||||
updateCounterInfo(ID,type,operationType.destroy.name(),Calendar.getInstance());
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Error updating Counting info for resource with ID " + profile.getID());
|
||||
logger.error("Error updating Counting info for resource with ID " + ID);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
@ -363,7 +323,6 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
private void logSecurityInfo(String methodName) {
|
||||
|
||||
logger.info("Security info for method "+ methodName );
|
||||
|
||||
String identity = SecurityManager.getManager().getCaller();
|
||||
logger.info("The caller is: " + identity);
|
||||
|
||||
|
@ -377,9 +336,7 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
*/
|
||||
protected synchronized ProfileResource getProfileResource(String id ){
|
||||
ProfileResource resource = null;
|
||||
|
||||
ResourceKey key = ProfileContext.getContext().makeKey( id);
|
||||
|
||||
try {
|
||||
resource = (ProfileResource) ProfileContext.getContext().getWSHome().find(key);
|
||||
}
|
||||
|
@ -391,6 +348,11 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
protected synchronized boolean isResourceCreated(String id) {
|
||||
if (getProfileResource(id) != null) return true; else return false;
|
||||
}
|
||||
|
@ -401,33 +363,30 @@ public class RegistryFactory extends GCUBEStartupPortType{
|
|||
* Update the Registry Factory RPs
|
||||
*
|
||||
*
|
||||
* @param resource GCUBEResource representing a profile
|
||||
* @param ID resource ID
|
||||
* @param type the resource type
|
||||
* @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{
|
||||
private synchronized void updateCounterInfo(String ID, String type, String operationType, Calendar updateTime) throws Exception{
|
||||
|
||||
RegistryProperty property = new RegistryProperty();
|
||||
|
||||
property.setUniqueID(resource.getID());
|
||||
property.setUniqueID(ID);
|
||||
property.setOperationType(operationType);
|
||||
property.setChangeTime(updateTime);
|
||||
//select the type of the resource to update
|
||||
for (Method method :this.getResource().getClass().getDeclaredMethods()) {
|
||||
if (method.getName().contains(resource.getType()) && method.getName().contains("set")) {
|
||||
if (method.getName().contains(type) && method.getName().contains("set")) {
|
||||
method.invoke(this.getResource(),property);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
this.getResource().getPersistenceDelegate().store(this.getResource());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return the resource
|
||||
*
|
||||
|
|
|
@ -44,18 +44,14 @@ public class RegistrationThread implements Runnable{
|
|||
public void run() {
|
||||
|
||||
while (true) {
|
||||
|
||||
try {
|
||||
|
||||
// This is the time interval
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch(InterruptedException e){
|
||||
|
||||
}
|
||||
try {
|
||||
ISPublisher publisher = GHNContext.getImplementation(ISPublisher.class);
|
||||
logger.debug("DefaultScope: "+GHNContext.getContext().getDefaultScope() );
|
||||
publisher.registerToISNotification(FactoryContext.getContext().getEPR(),topics, GHNContext.getContext().getDefaultScope(), ServiceContext.getContext() );
|
||||
return;
|
||||
|
||||
|
|
Loading…
Reference in New Issue