This commit is contained in:
Andrea Manzi 2008-03-28 10:46:45 +00:00
parent 7d626bdaa3
commit 19cf6a6a3a
2 changed files with 28 additions and 73 deletions

View File

@ -7,6 +7,8 @@ import java.rmi.RemoteException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; 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.apache.axis.utils.XMLUtils;
import org.gcube.common.core.contexts.GCUBEServiceContext; import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.contexts.GHNContext; import org.gcube.common.core.contexts.GHNContext;
@ -57,6 +59,11 @@ import org.oasis.wsrf.lifetime.Destroy;
public class RegistryFactory extends GCUBEStartupPortType{ public class RegistryFactory extends GCUBEStartupPortType{
/**
* The UUIDGen
*/
private static final UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
/** /**
* Object logger. * Object logger.
@ -114,12 +121,8 @@ public class RegistryFactory extends GCUBEStartupPortType{
* @throws ProfileAlreadyRegisteredFault * @throws ProfileAlreadyRegisteredFault
*/ */
public String createResource(CreateResourceMessage inputMessage) throws SchemaValidationFault,RemoteException,ProfileAlreadyRegisteredFault { public String createResource(CreateResourceMessage inputMessage) throws SchemaValidationFault,RemoteException,ProfileAlreadyRegisteredFault {
GCUBEResource resource = null; GCUBEResource resource = null;
logSecurityInfo("createResource"); logSecurityInfo("createResource");
String profile = inputMessage.getProfile(); String profile = inputMessage.getProfile();
if (profile == null || profile.compareTo("") == 0) { if (profile == null || profile.compareTo("") == 0) {
@ -127,16 +130,12 @@ public class RegistryFactory extends GCUBEStartupPortType{
logger.debug(msg); logger.debug(msg);
throw new RemoteException(msg); throw new RemoteException(msg);
} }
try { try {
resource = this.getResourceClass(inputMessage.getType()); resource = this.getResourceClass(inputMessage.getType());
resource.load(new StringReader(profile)); resource.load(new StringReader(profile));
//the parse Profile class allows to extract from profiles information about type/SCOPE/UniqueID //the parse Profile class allows to extract from profiles information about type/SCOPE/UniqueID
//in order to distiguish among different Resource Type //in order to distiguish among different Resource Type
//Adding scopes to Profile //Adding scopes to Profile
String [] scopes = inputMessage.getScopes(); String [] scopes = inputMessage.getScopes();
if (scopes != null) { if (scopes != null) {
for (String scope : scopes) { for (String scope : scopes) {
@ -144,10 +143,8 @@ public class RegistryFactory extends GCUBEStartupPortType{
resource.addScope(GCUBEScope.getScope(scope)); resource.addScope(GCUBEScope.getScope(scope));
} }
} }
//check ID //check ID
if (resource.getID()== null) {} if (resource.getID()== null || resource.getID().compareTo("")==0) {resource.setID(uuidgen.nextUUID()); }
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -155,7 +152,6 @@ public class RegistryFactory extends GCUBEStartupPortType{
ex.printStackTrace(); ex.printStackTrace();
throw new SchemaValidationFault(); throw new SchemaValidationFault();
} }
//check if the Resource already Exist //check if the Resource already Exist
if (isResourceCreated(resource.getID())) { if (isResourceCreated(resource.getID())) {
@ -163,7 +159,6 @@ public class RegistryFactory extends GCUBEStartupPortType{
logger.debug(msg); logger.debug(msg);
throw new ProfileAlreadyRegisteredFault(); throw new ProfileAlreadyRegisteredFault();
} }
//try to create resource //try to create resource
try { try {
ProfileContext.getContext().getWSHome().create(ProfileContext.getContext().makeKey(resource.getID()),resource); ProfileContext.getContext().getWSHome().create(ProfileContext.getContext().makeKey(resource.getID()),resource);
@ -174,9 +169,8 @@ public class RegistryFactory extends GCUBEStartupPortType{
ex.printStackTrace(); ex.printStackTrace();
throw new RemoteException(msg); throw new RemoteException(msg);
} }
try { try {
updateCounterInfo (resource,operationType.create.name(),Calendar.getInstance()); updateCounterInfo (resource.getID(),inputMessage.getType(),operationType.create.name(),Calendar.getInstance());
} catch (Exception e) { } catch (Exception e) {
logger.error("Error updating Counting info for resource with ID " + resource.getID()); logger.error("Error updating Counting info for resource with ID " + resource.getID());
e.printStackTrace(); e.printStackTrace();
@ -189,7 +183,6 @@ public class RegistryFactory extends GCUBEStartupPortType{
e.printStackTrace(); e.printStackTrace();
} }
return writer.toString(); return writer.toString();
} }
@ -205,29 +198,19 @@ public class RegistryFactory extends GCUBEStartupPortType{
public UpdateResourceResponse updateResource(UpdateProfileMessage mess) throws RemoteException,SchemaValidationFault,GCUBEFault { public UpdateResourceResponse updateResource(UpdateProfileMessage mess) throws RemoteException,SchemaValidationFault,GCUBEFault {
logSecurityInfo("updateResource"); logSecurityInfo("updateResource");
String ID = mess.getUniqueID(); String ID = mess.getUniqueID();
String xmlProfile = mess.getXmlProfile(); String xmlProfile = mess.getXmlProfile();
GCUBEResource resource = null; GCUBEResource resource = null;
CreateResourceMessage input =null; CreateResourceMessage input =null;
//validating input parameters //validating input parameters
if (ID == null || ID.compareTo("") ==0) { if (ID == null || ID.compareTo("") ==0) {
logger.debug(" ID missing "); logger.debug(" ID missing ");
throw new RemoteException("Error, ID missing"); throw new RemoteException("Error, ID missing");
} }
if (xmlProfile == null || xmlProfile.compareTo("") ==0) { if (xmlProfile == null || xmlProfile.compareTo("") ==0) {
logger.debug("Profile missing" ); logger.debug("Profile missing" );
throw new RemoteException("Error, profile missing"); throw new RemoteException("Error, profile missing");
} }
//check if the profile exist //check if the profile exist
if (!isResourceCreated(ID)) { if (!isResourceCreated(ID)) {
input = new CreateResourceMessage(); input = new CreateResourceMessage();
@ -236,27 +219,24 @@ public class RegistryFactory extends GCUBEStartupPortType{
this.createResource(input); this.createResource(input);
return new UpdateResourceResponse(); return new UpdateResourceResponse();
} }
try { try {
resource = this.getResourceClass(mess.getType()); resource = this.getResourceClass(mess.getType());
resource.load(new StringReader(xmlProfile)); resource.load(new StringReader(xmlProfile));
getProfileResource(ID).updateResource(resource); getProfileResource(ID).updateResource(resource);
} }
catch (Exception e) { catch (Exception e) {
logger.error("Error updating profile for ID "+ e); logger.error("Error updating profile for ID "+ e);
throw new RemoteException(e.toString()); throw new RemoteException(e.toString());
} }
try { try {
updateCounterInfo (resource,operationType.update.name(),Calendar.getInstance()); updateCounterInfo (ID,mess.getType(),operationType.update.name(),Calendar.getInstance());
} catch (Exception e) { } catch (Exception e) {
logger.error("Error updating Counting info for resource with ID " + resource.getID()); logger.error("Error updating Counting info for resource with ID " + resource.getID());
e.printStackTrace(); e.printStackTrace();
} }
logger.info("Profile updated"); logger.info("Profile updated");
return new UpdateResourceResponse(); return new UpdateResourceResponse();
} }
/** /**
@ -268,22 +248,15 @@ public class RegistryFactory extends GCUBEStartupPortType{
* @throws RemoteException Exceptions * @throws RemoteException Exceptions
*/ */
public RemoveResourceResponse removeResource (RemoveResourceMessage inputMessage) throws RemoteException,GCUBEFault{ public RemoveResourceResponse removeResource (RemoveResourceMessage inputMessage) throws RemoteException,GCUBEFault{
logSecurityInfo("removeResource"); logSecurityInfo("removeResource");
GCUBEResource profile= null;
String ID = inputMessage.getUniqueID(); String ID = inputMessage.getUniqueID();
String type = inputMessage.getType(); String type = inputMessage.getType();
if (ID == null || ID.compareTo("") ==0) { if (ID == null || ID.compareTo("") ==0) {
logger.debug("ID missing "); logger.debug("ID missing ");
throw new RemoteException("Error, ID missing"); throw new RemoteException("Error, ID missing");
} }
//check if the UniqueID exist
//controls if the UniqueID exist
if (!(isResourceCreated(ID))){ if (!(isResourceCreated(ID))){
GCUBEResource resource = null; GCUBEResource resource = null;
try { try {
resource = RegistryUtil.getProfileFromIS(ID,this.getResourceClass(type).getClass()); resource = RegistryUtil.getProfileFromIS(ID,this.getResourceClass(type).getClass());
@ -291,31 +264,21 @@ public class RegistryFactory extends GCUBEStartupPortType{
logger.error("Error gettign profile from IS "); logger.error("Error gettign profile from IS ");
return new RemoveResourceResponse(); return new RemoveResourceResponse();
} }
if( resource == null) return new RemoveResourceResponse(); if( resource == null) return new RemoveResourceResponse();
else { else {
logger.debug("Try to remove the resource from the IS-IC"); logger.debug("Try to remove the resource from the IS-IC");
ProfileManager manager; ProfileManager manager;
try { try {
manager = new GCUBEPublisher().getProfileManager(null, GHNContext.getContext().getDefaultScope()); manager = new GCUBEPublisher().getProfileManager(null, GHNContext.getContext().getDefaultScope());
manager.removeFromDISIC(ID,ServiceContext.getContext().getCredentials(),resource.getType()); manager.removeFromDISIC(ID,resource.getType());
} catch (GCUBEPublisherException e) { } catch (GCUBEPublisherException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
return new RemoveResourceResponse(); return new RemoveResourceResponse();
} }
try{ try{
ProfileResource resource = getProfileResource(ID ); ProfileResource resource = getProfileResource(ID );
profile = this.getResourceClass(type);
profile.load(new StringReader( XMLUtils.DocumentToString(resource.getProfile())));
//remove profile
resource.removeProfile(); resource.removeProfile();
RegistryServiceAddressingLocator locator = new RegistryServiceAddressingLocator(); RegistryServiceAddressingLocator locator = new RegistryServiceAddressingLocator();
RegistryPortType portType = locator.getRegistryPortTypePort(resource.getEPR()); RegistryPortType portType = locator.getRegistryPortTypePort(resource.getEPR());
@ -329,24 +292,21 @@ public class RegistryFactory extends GCUBEStartupPortType{
logger.error("Error removing resource for ID "+ e); logger.error("Error removing resource for ID "+ e);
throw new RemoteException(); throw new RemoteException();
} }
try { try {
if (profile.getType().compareTo(GCUBEHostingNode.TYPE) == 0) { if (type.compareTo(GCUBEHostingNode.TYPE) == 0) {
RegistryUtil.unregisterRIRelatedToDHN(profile.getID(),this); RegistryUtil.unregisterRIRelatedToDHN(ID,this);
} }
} }
catch (Exception e) { catch (Exception e) {
logger.error("Error removing profile related to this GHNID for ID "+ e); logger.error("Error removing profile related to this GHNID for ID "+ e);
e.printStackTrace(); e.printStackTrace();
} }
logger.info(" Profile destroyed"); logger.info(" Profile destroyed");
try { try {
updateCounterInfo(profile,operationType.destroy.name(),Calendar.getInstance()); updateCounterInfo(ID,type,operationType.destroy.name(),Calendar.getInstance());
} }
catch (Exception e) { 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(); e.printStackTrace();
} }
@ -363,7 +323,6 @@ public class RegistryFactory extends GCUBEStartupPortType{
private void logSecurityInfo(String methodName) { private void logSecurityInfo(String methodName) {
logger.info("Security info for method "+ methodName ); logger.info("Security info for method "+ methodName );
String identity = SecurityManager.getManager().getCaller(); String identity = SecurityManager.getManager().getCaller();
logger.info("The caller is: " + identity); logger.info("The caller is: " + identity);
@ -377,9 +336,7 @@ public class RegistryFactory extends GCUBEStartupPortType{
*/ */
protected synchronized ProfileResource getProfileResource(String id ){ protected synchronized ProfileResource getProfileResource(String id ){
ProfileResource resource = null; ProfileResource resource = null;
ResourceKey key = ProfileContext.getContext().makeKey( id); ResourceKey key = ProfileContext.getContext().makeKey( id);
try { try {
resource = (ProfileResource) ProfileContext.getContext().getWSHome().find(key); 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) { protected synchronized boolean isResourceCreated(String id) {
if (getProfileResource(id) != null) return true; else return false; if (getProfileResource(id) != null) return true; else return false;
} }
@ -401,33 +363,30 @@ public class RegistryFactory extends GCUBEStartupPortType{
* Update the Registry Factory RPs * 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 operationType the type of Operation performed on the Profile
* @param updateTime The last operation Time * @param updateTime The last operation Time
* @throws Exception Exception * @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(); RegistryProperty property = new RegistryProperty();
property.setUniqueID(resource.getID()); property.setUniqueID(ID);
property.setOperationType(operationType); property.setOperationType(operationType);
property.setChangeTime(updateTime); property.setChangeTime(updateTime);
//select the type of the resource to update //select the type of the resource to update
for (Method method :this.getResource().getClass().getDeclaredMethods()) { 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); method.invoke(this.getResource(),property);
break; break;
} }
} }
this.getResource().getPersistenceDelegate().store(this.getResource()); this.getResource().getPersistenceDelegate().store(this.getResource());
} }
/** /**
* return the resource * return the resource
* *

View File

@ -44,18 +44,14 @@ public class RegistrationThread implements Runnable{
public void run() { public void run() {
while (true) { while (true) {
try { try {
// This is the time interval
// This is the time interval Thread.sleep(10000);
Thread.sleep(10000);
} }
catch(InterruptedException e){ catch(InterruptedException e){
} }
try { try {
ISPublisher publisher = GHNContext.getImplementation(ISPublisher.class); ISPublisher publisher = GHNContext.getImplementation(ISPublisher.class);
logger.debug("DefaultScope: "+GHNContext.getContext().getDefaultScope() );
publisher.registerToISNotification(FactoryContext.getContext().getEPR(),topics, GHNContext.getContext().getDefaultScope(), ServiceContext.getContext() ); publisher.registerToISNotification(FactoryContext.getContext().getEPR(),topics, GHNContext.getContext().getDefaultScope(), ServiceContext.getContext() );
return; return;