IS-Registry test-suite modified for supporting the recursive registration of entire folders of resources
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@48372 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
28985c6293
commit
dbe11e0cdb
|
@ -1,20 +1,13 @@
|
|||
package org.gcube.informationsystem.registry.testsuite;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.File;
|
||||
|
||||
|
||||
import org.apache.axis.message.addressing.Address;
|
||||
import org.apache.axis.message.addressing.EndpointReferenceType;
|
||||
import org.gcube.common.core.contexts.GCUBERemotePortTypeContext;
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.resources.GCUBEGenericResource;
|
||||
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.resources.GCUBEService;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
|
||||
import org.gcube.informationsystem.registry.stubs.resourceregistration.CreateMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.resourceregistration.ResourceRegistrationPortType;
|
||||
import org.gcube.informationsystem.registry.stubs.resourceregistration.service.ResourceRegistrationServiceAddressingLocator;
|
||||
|
||||
|
@ -48,91 +41,70 @@ public class RegistryRegistrationTest {
|
|||
|
||||
for (String param : args) System.out.println("param "+ param);
|
||||
|
||||
// get the scope and the factory URI
|
||||
GCUBEScope scope = GCUBEScope.getScope(args[3]);
|
||||
|
||||
// get the scope and the REGITRATION URI
|
||||
GCUBEScope scope = GCUBEScope.getScope(args[2]);
|
||||
|
||||
//create the porttype
|
||||
EndpointReferenceType factoryEPR = new EndpointReferenceType();
|
||||
try {
|
||||
factoryEPR.setAddress(new Address(args[0]));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Runtime.getRuntime().exit(1);
|
||||
}
|
||||
|
||||
ResourceRegistrationServiceAddressingLocator locator = new ResourceRegistrationServiceAddressingLocator();
|
||||
GCUBESecurityManagerImpl managerSec = new GCUBESecurityManagerImpl() {
|
||||
public boolean isSecurityEnabled() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// load the resource
|
||||
GCUBEResource resource = getResource(args[2], new FileReader(args[1]));
|
||||
ResourceRegistrationPortType registration = null;
|
||||
try {
|
||||
ResourceRegistrationPortType registration = locator.getResourceRegistrationPortTypePort(factoryEPR);
|
||||
factoryEPR.setAddress(new Address(args[0]));
|
||||
registration = locator.getResourceRegistrationPortTypePort(factoryEPR);
|
||||
registration = locator.getResourceRegistrationPortTypePort(factoryEPR);
|
||||
CreateMessage message = new CreateMessage();
|
||||
registration = GCUBERemotePortTypeContext.getProxy(registration, scope, managerSec);
|
||||
StringWriter writer = new StringWriter();
|
||||
resource.store(writer);
|
||||
message.setProfile(writer.toString());
|
||||
message.setType(resource.getType());
|
||||
System.out.println(registration.create(message));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Runtime.getRuntime().exit(1);
|
||||
}
|
||||
|
||||
File param = new File(args[1]);
|
||||
if (param.isDirectory())
|
||||
registerDirectory(registration,args[3],param);
|
||||
else {
|
||||
try {
|
||||
Resource resource = new Resource(param, args[3]);
|
||||
resource.register(registration);
|
||||
} catch (Exception e) {
|
||||
System.err.print("Unable to register " + param.getAbsolutePath());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the specific GCUBEResource class
|
||||
*
|
||||
* @param type
|
||||
* the resource type
|
||||
* @param file
|
||||
* the file representation of the profile
|
||||
* @return the resource class
|
||||
* @throws Exception
|
||||
* if the loading fails
|
||||
* Registers all the resources in a directory, recursively if needed
|
||||
* @param registration
|
||||
* @param resourceType
|
||||
* @param dirToProcess
|
||||
*/
|
||||
static GCUBEResource getResource(String type, FileReader file)
|
||||
throws Exception {
|
||||
if (type.compareTo("Service") == 0) {
|
||||
GCUBEService service = GHNContext
|
||||
.getImplementation(GCUBEService.class);
|
||||
service.load(file);
|
||||
return (GCUBEResource) service;
|
||||
} else if (type.compareTo("RunningInstance") == 0) {
|
||||
GCUBERunningInstance instance = GHNContext
|
||||
.getImplementation(GCUBERunningInstance.class);
|
||||
instance.load(file);
|
||||
return (GCUBEResource) instance;
|
||||
} else if (type.compareTo("GHN") == 0) {
|
||||
GCUBEHostingNode node = GHNContext
|
||||
.getImplementation(GCUBEHostingNode.class);
|
||||
node.load(file);
|
||||
return (GCUBEResource) node;
|
||||
} else if (type.compareTo("GenericResource") == 0) {
|
||||
GCUBEGenericResource generic = GHNContext
|
||||
.getImplementation(GCUBEGenericResource.class);
|
||||
generic.load(file);
|
||||
return (GCUBEResource) generic;
|
||||
static void registerDirectory(ResourceRegistrationPortType registration, String resourceType, File dirToProcess) {
|
||||
for (File f : dirToProcess.listFiles()) {
|
||||
if (f.isDirectory())
|
||||
registerDirectory(registration,resourceType,f);
|
||||
else
|
||||
try {
|
||||
Resource resource = new Resource(f, resourceType);
|
||||
resource.register(registration);
|
||||
} catch (Exception e) {
|
||||
System.err.print("Unable to register " + f.getAbsolutePath());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception(type + " is an invalid resource type");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints tester usage syntax
|
||||
*/
|
||||
static void printUsage() {
|
||||
System.out
|
||||
.println("RegistryRegistrationTest <registration URI> <resource file> <caller scope> <resource type>");
|
||||
System.out
|
||||
.println("allowed types are: RunningInstance/Service/GHN/GenericResource");
|
||||
System.out.println("RegistryRegistrationTest <registration URI> <resource file> <caller scope> <resource type>");
|
||||
System.out.println("allowed types are: RunningInstance/Service/GHN/GenericResource");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
package org.gcube.informationsystem.registry.testsuite;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.resources.GCUBEGenericResource;
|
||||
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.resources.GCUBERuntimeResource;
|
||||
import org.gcube.common.core.resources.GCUBEService;
|
||||
import org.gcube.informationsystem.registry.stubs.resourceregistration.CreateMessage;
|
||||
import org.gcube.informationsystem.registry.stubs.resourceregistration.ResourceRegistrationPortType;
|
||||
|
||||
public class Resource {
|
||||
|
||||
private GCUBEResource resource;
|
||||
private File source;
|
||||
protected Resource (File resource, String type) throws FileNotFoundException,Exception {
|
||||
this.source = resource;
|
||||
this.resource = this.load(type, new FileReader(resource));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Registers the resource in the given portType
|
||||
* @param registration
|
||||
* @param resourceType
|
||||
* @param fileToRegister
|
||||
* @throws Exception
|
||||
*/
|
||||
protected void register(ResourceRegistrationPortType registration) throws Exception {
|
||||
CreateMessage message = new CreateMessage();
|
||||
StringWriter writer = new StringWriter();
|
||||
resource.store(writer);
|
||||
message.setProfile(writer.toString());
|
||||
message.setType(resource.getType());
|
||||
registration.create(message);
|
||||
System.out.println("Resource "+ this.source.getAbsolutePath() +" successuflly registered: " + this.resource.getID());
|
||||
}
|
||||
/**
|
||||
* Loads the specific GCUBEResource class
|
||||
*
|
||||
* @param type the resource type
|
||||
* @param file the file representation of the profile
|
||||
* @return the resource class
|
||||
* @throws Exception
|
||||
* if the loading fails
|
||||
*/
|
||||
private GCUBEResource load(String type, FileReader file) throws Exception {
|
||||
if (type.compareTo("Service") == 0) {
|
||||
GCUBEService service = GHNContext.getImplementation(GCUBEService.class);
|
||||
service.load(file);
|
||||
return (GCUBEResource) service;
|
||||
} else if (type.compareTo("RunningInstance") == 0) {
|
||||
GCUBERunningInstance instance = GHNContext.getImplementation(GCUBERunningInstance.class);
|
||||
instance.load(file);
|
||||
return (GCUBEResource) instance;
|
||||
} else if (type.compareTo("GHN") == 0) {
|
||||
GCUBEHostingNode node = GHNContext.getImplementation(GCUBEHostingNode.class);
|
||||
node.load(file);
|
||||
return (GCUBEResource) node;
|
||||
} else if (type.compareTo("GenericResource") == 0) {
|
||||
GCUBEGenericResource generic = GHNContext.getImplementation(GCUBEGenericResource.class);
|
||||
generic.load(file);
|
||||
return (GCUBEResource) generic;
|
||||
} else if (type.compareTo("RuntimeResource") == 0) {
|
||||
GCUBERuntimeResource rt = GHNContext.getImplementation(GCUBERuntimeResource.class);
|
||||
rt.load(file);
|
||||
return (GCUBEResource) rt;
|
||||
}
|
||||
|
||||
throw new Exception(type + " is an invalid resource type");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue