Add a Configuration Resource

git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/private/alessandro.pieve/resource-management@146420 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Alessandro Pieve 2017-03-29 10:30:15 +00:00
parent cb93d86c84
commit c6bc4af914
10 changed files with 296 additions and 94 deletions

View File

@ -4,6 +4,9 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="rmp-common-library-2.8.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/rmp-common-library-new/rmp-common-library-new">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="resource-management"/>
</wb-module>

View File

@ -443,6 +443,94 @@ public class ContextMenuFactory {
menu.add(undeploy);
}
//NEW REGISTRY
/*************************************************************
* ESERVICE
************************************************************/
if (resType.equals(ResourceTypeDecorator.EService.name())) {
// 0 - GETRELATED button
MenuItem getRelated = new MenuItem("Get Related") {
@Override
protected void onClick(final ComponentEvent be) {
super.onClick(be);
Commands.doGetRelatedResources(ResourceTypeDecorator.EService.name(),
((Object) container.getSelection().get(0).get("ID")).toString(),
StatusHandler.getStatus().getCurrentScope());
}
};
getRelated.setIconStyle("link-icon");
menu.add(getRelated);
// 1 - undeploy
MenuItem undeploy = new MenuItem("Undeploy") {
@Override
protected void onClick(final ComponentEvent be) {
super.onClick(be);
MessageBox.confirm("Running Instance Undeploy", "Are you sure you want to undeploy the selected RI(s)?",
new Listener<MessageBoxEvent>() {
public void handleEvent(final MessageBoxEvent be) {
if (be.getButtonClicked().getItemId().equalsIgnoreCase("yes")) {
Vector<ResourceDescriptor> resources = new Vector<ResourceDescriptor>();
// - THE OPERATION IF CONFIRMED
for (ModelData e : container.getSelection()) {
ConsoleMessageBroker.info(this, "Required undeploy for: " + e.get("Name") + " " + e.get("ID"));
try {
resources.add(new ResourceDescriptor(
ResourceTypeDecorator.EService.name(),
null,
((Object) e.get("ID")).toString(),
((Object) e.get("Name")).toString()));
} catch (Exception ex) {
MessageBox.alert(
"Generic Resource Edit",
"Failure<br/>" + ex.getMessage(),
null);
}
}
try {
ProxyRegistry.getProxyInstance().doOperation(
SupportedOperations.ESERVICE_INSTANCE_UNDEPLOY,
StatusHandler.getStatus().getCurrentScope(),
resources, //lista id risorse selzionati
new AsyncCallback<Void>() {
@Override
public void onSuccess(final Void result) {
Commands.showPopup("Undeployment", "success");
}
@Override
public void onFailure(
final Throwable caught) {
Commands.showPopup("Undeployment", "failure");
}
});
} catch (Exception e) {
MessageBox.alert(
"Generic Resource Edit",
"Failure<br/>" + e.getMessage(),
null);
}
}
}
});
}
};
Commands.evaluateCredentials(
undeploy,
SupportedOperations.ESERVICE_INSTANCE_UNDEPLOY.getPermissions());
undeploy.setIconStyle("delete-icon");
menu.add(undeploy);
}
/*************************************************************
* SERVICE
************************************************************/

View File

@ -195,6 +195,8 @@ public class TaskbarButton extends Component implements IconSupport {
return "#fea500"; //orange
case WSResource:
return "#f6634f"; //red
case EService:
return "#8aacd2"; //blue
default:
return "#CAEBFA"; //azur
}

View File

@ -151,6 +151,7 @@ public class TaskbarItem {
type == ResourceTypeDecorator.Collection ||
type == ResourceTypeDecorator.GenericResource ||
type == ResourceTypeDecorator.RunningInstance ||
type == ResourceTypeDecorator.EService ||
type == ResourceTypeDecorator.Service)
) {
MenuItem refresh = new MenuItem("Refresh") {

View File

@ -1,34 +1,21 @@
package org.gcube.portlets.admin.resourcemanagement.server;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource;
import org.gcube.informationsystem.model.entity.facet.NetworkingFacet;
import org.gcube.informationsystem.model.entity.facet.SoftwareFacet;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.client.proxy.ResourceRegistryClient;
import org.gcube.informationsystem.resourceregistry.client.proxy.ResourceRegistryClientFactory;
import org.gcube.informationsystem.types.TypeBinder.TypeDefinition;
import org.gcube.portlets.admin.resourcemanagement.shared.resource.CacheList;
import org.gcube.portlets.admin.resourcemanagement.shared.resource.GcoreEndPointObject;
import org.gcube.portlets.admin.resourcemanagement.shared.resource.UtilityResource;
import org.gcube.resourcemanagement.support.client.views.ResourceTypeDecorator;
import org.gcube.resourcemanagement.support.shared.types.datamodel.CompleteResourceProfile;
import com.google.gwt.json.client.JSONObject;
public class RegistryClientRequester {
private static final String LOG_PREFIX = "[REGISTRY_CLIENT-REQS]";
private static ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
/**
* For all the resource in the scope retrieves their
@ -42,47 +29,19 @@ public class RegistryClientRequester {
public static final HashMap<String, ArrayList<String>> getResourcesTree(final ScopeBean queryScope) throws Exception {
HashMap<String, ArrayList<String>> retval = new HashMap<String, ArrayList<String>>();
ScopeProvider.instance.set(queryScope.toString());
try {
List<TypeDefinition> typeDefinitions = resourceRegistryClient.getSchema(Resource.class, true);
for (TypeDefinition td : typeDefinitions) {
//da eliminare una volta modificato il decoratore
//if (td.getName().equals("HostingNode"))
// retval.put("GHN", UtilityResource.getSubResourcesTree(td.getName()));
if (td.getName().equals("EService"))
retval.put("RunningInstance", UtilityResource.getSubResourcesTree(td.getName()));
// if (td.getName().equals("EService"))
// retval.put("RunningInstance", UtilityResource.getSubResourcesTree(td.getName(),queryScope.toString()));
if (td.getName().equals("Configuration"))
retval.put("GenericResource", UtilityResource.getSubResourcesTree(td.getName()));
// else{
// retval.put(td.getName(), UtilityResource.getSubResourcesTree(td.getName()));
// }
retval.put("GenericResource", UtilityResource.getSubResourcesTree(td.getName(),queryScope.toString()));
}
// System.out.println("Instances ..");
//List<Service> eservices = (List<Service>) resourceRegistryClient.getInstances(Service.NAME, true);
// for (Service et : eservices) {
// List<? extends Facet> facets = et.getIdentificationFacets();
// for (Facet f : facets) {
// if(f instanceof NetworkingFacet){
// NetworkingFacet nf = (NetworkingFacet) f;
// System.out.println(nf.getHostName());
// }
//
// }
//// List<ConsistsOf<?, ?>> coList = et.getConsistsOf();
//// for (ConsistsOf<?, ?> co : coList) {
//// System.out.println(co);
//// }
//
//
//
// }
//
@ -98,27 +57,19 @@ public class RegistryClientRequester {
//list string (xml formatted) for table
public static final List<String> getResourcesByTypeSubType( String scope,String type,String subType) throws Exception {
System.out.println("---------------->getResourcesByTypeSubType scope:"+scope+" type:"+type);
//fare cache di due mappe
//una id- risorsa
//sotto tipo- lista risorse
CacheList.resourceid.clear();
List<String>resource=new ArrayList<String>();
switch (type) {
case "RunningInstance":
System.out.println("---------------->RunningInstance ");
resource=UtilityResource.CreateListEservice(scope,type,subType);
break;
case "GenericResource":
System.out.println("---------------->GenericResource ");
resource=UtilityResource.CreateListConfiguration(scope,type,subType);
break;
}
return resource;
}
@ -132,9 +83,8 @@ public class RegistryClientRequester {
String representation=CacheList.resourceid.get(resID).getBody();
//get resource by id
String title=CacheList.resourceid.get(resID).getTitle();
//riprendo la risorsa da id
String xmlRepresentation="<Resource>"
+ "<ID>"+resID+"</ID>"
+ "<Type>"+type+"</Type>"
@ -142,12 +92,7 @@ public class RegistryClientRequester {
+ "</Resource>";
String htmlRepresentation=representation;
ScopeProvider.instance.set(scope);
return new CompleteResourceProfile(resID, ResourceTypeDecorator.valueOf(type),
title,
xmlRepresentation, htmlRepresentation
);
return new CompleteResourceProfile(resID, ResourceTypeDecorator.valueOf(type),title,xmlRepresentation, htmlRepresentation);
}

View File

@ -22,6 +22,7 @@ import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.resourcemanagement.support.client.utils.CurrentStatus;
import org.gcube.resourcemanagement.support.shared.util.Assertion;
import org.gcube.resourcemanagement.support.server.managers.resources.CollectionManager;
import org.gcube.resourcemanagement.support.server.managers.resources.EServiceManager;
import org.gcube.resourcemanagement.support.server.managers.resources.GHNManager;
import org.gcube.resourcemanagement.support.server.managers.resources.GenericResourceManager;
import org.gcube.resourcemanagement.support.server.managers.resources.RuntimeResourceManager;
@ -207,5 +208,20 @@ public class ResourceCommands {
// new RunningInstanceManager(resource.getID()).undeploy(gscope);
}
}
//NEW REGISTRY
/**********************************************************
* ESERVICE
*********************************************************/
if (opCode.equals(SupportedOperations.ESERVICE_INSTANCE_UNDEPLOY)) {
for (ResourceDescriptor resource : resources) {
ServerConsole.debug(LOG_PREFIX, "Undeploying RI: " + resource.getID());
// FIXME per massi: togli questi commenti per abilitare undeploy
//new EServiceManager(resource.getID()).undeploy(gscope);
}
}
}
}

View File

@ -345,10 +345,7 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro
List<String> request=RegistryClientRequester.getResourcesByTypeSubType(scope, type,null);
//fare cache di due mappe
//una id- risorsa
//sotto tipo- lista risorse
return request;

View File

@ -6,8 +6,10 @@ import java.util.List;
import java.util.Map;
public class CacheList {
//use for get a complete resource from id
public static Map<String,ResourceObject> resourceid = Collections.synchronizedMap(new HashMap());
//public static Map<String,List<String>> resourceTable = Collections.synchronizedMap(new HashMap());
//use from
//type-subtype, list di resource
public static Map<String,List<String>> resourceTable = Collections.synchronizedMap(new HashMap());
}

View File

@ -30,12 +30,13 @@ public class GenericResourceObject {
public GenericResourceObject(){}
public GenericResourceObject(String id, String type, String subType,
String name, String description) {
String name, String description,String scopes) {
super();
this.id = id;
this.type = type;
this.subType = subType;
this.name = name;
this.scopes = scopes;
this.description = description;
}

View File

@ -5,15 +5,18 @@ import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource;
import org.gcube.informationsystem.model.entity.facet.AccessPointFacet;
import org.gcube.informationsystem.model.entity.facet.IdentifierFacet;
import org.gcube.informationsystem.model.entity.facet.NetworkingFacet;
import org.gcube.informationsystem.model.entity.facet.ServiceStateFacet;
import org.gcube.informationsystem.model.entity.facet.SoftwareFacet;
import org.gcube.informationsystem.model.entity.resource.Configuration;
import org.gcube.informationsystem.model.entity.resource.EService;
import org.gcube.informationsystem.model.relation.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
@ -26,14 +29,14 @@ public class UtilityResource {
private static ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
//UTILITY per Calcolare i sotto alberi
public static ArrayList<String> getSubResourcesTree(String entity) throws ResourceRegistryException{
public static ArrayList<String> getSubResourcesTree(String entity, String scope) throws Exception{
ArrayList<String> list = new ArrayList<>();
List<Resource> resources = (List<Resource>) resourceRegistryClient.getInstances(entity, true);
for (Resource et : resources) {
List<? extends Facet> facets = et.getIdentificationFacets();
for (Facet f : facets) {
System.out.println("------------for entity:"+entity+" found a facet f:"+f.toString());
switch (entity) {
/*
case "Software":
@ -93,15 +96,23 @@ public class UtilityResource {
list.add(nf.getHostName());
}
break;
*/
case "Configuration":
if(f instanceof NetworkingFacet){
System.out.println("------------Configuration--NetworkingFacet-- identified by GenericResource");
NetworkingFacet nf = (NetworkingFacet) f;
list.add(nf.getHostName());
if(f instanceof SoftwareFacet){
System.out.println("------------Configuration--SoftwareFacet-- identified by GenericResource");
SoftwareFacet sf = (SoftwareFacet) f;
if (!list.contains(sf.getGroup())){
list.add(sf.getGroup());
System.out.println("------------sf.getGroup()"+sf.getGroup());
}
//creo mappa con tutta la struttura
//passo lo scope
UtilityResource.CreateCacheListConfiguration(scope);
}
break;
/*
case "RunningPlugin":
if(f instanceof NetworkingFacet){
NetworkingFacet nf = (NetworkingFacet) f;
@ -123,7 +134,7 @@ public class UtilityResource {
*/
case "EService": //GcoreEndPoint
if(f instanceof SoftwareFacet){
System.out.println("------------EService--SoftwareFacet-- identified by Gcore End point");
System.out.println("------------EService--SoftwareFacet-- identified by Gcore End point and Service End Point");
SoftwareFacet sf = (SoftwareFacet) f;
if (!list.contains(sf.getGroup()))
list.add(sf.getGroup());
@ -161,6 +172,12 @@ public class UtilityResource {
/***
* Create a list for eservice (aka gcore endpoint)
* @param scope
@ -169,7 +186,7 @@ public class UtilityResource {
* @throws Exception
*/
public static List<String> CreateListEservice(String scope,String typeC,String subTypeC) throws Exception {
ScopeProvider.instance.set(scope.toString());
ScopeProvider.instance.set(scope);
JAXBContext context = JAXBContext.newInstance(GcoreEndPointObject.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
@ -177,7 +194,8 @@ public class UtilityResource {
List<String>resource=new ArrayList<String>();
String id="";
String type="RunningInstance";
String type="EService";
//String type="RunningInstance";
String subType="";
String serviceClass="";
String serviceName="";
@ -201,23 +219,91 @@ public class UtilityResource {
}
CacheList.resourceid.put(id, new ResourceObject(serviceName, et.toString()));
ghnName="";
status="";
List<ConsistsOf<? extends Resource, ? extends Facet>> consist = et.getConsistsOf();
for (ConsistsOf<? extends Resource, ? extends Facet> c : consist) {
if(c instanceof ConsistsOf){
ConsistsOf cf = (ConsistsOf) c;
if (cf.getTarget() instanceof AccessPointFacet){
AccessPointFacet af = (AccessPointFacet) cf.getTarget();
ghnName=af.getEndpoint().getHost().toString();
if (c.getTarget() instanceof AccessPointFacet){
AccessPointFacet af = (AccessPointFacet) c.getTarget();
try {
ghnName=af.getEndpoint().getHost().toString();
}
catch(Exception e){
ghnName="";
}
}
if (cf.getTarget() instanceof ServiceStateFacet){
ServiceStateFacet stf = (ServiceStateFacet) cf.getTarget();
status=stf.getValue();
if (c.getTarget() instanceof ServiceStateFacet){
ServiceStateFacet stf = (ServiceStateFacet) c.getTarget();
try {
status=stf.getValue().toLowerCase();
}
catch(Exception e){
status="";
}
}
}
}
GcoreEndPointObject temp= new GcoreEndPointObject(id,type,
subType,scope,serviceClass,serviceName,version,status,ghnName);
GcoreEndPointObject temp= new GcoreEndPointObject(id,type,subType,scope,serviceClass,serviceName,version,status,ghnName);
StringWriter sw = new StringWriter();
m.marshal(temp,sw);
if (subTypeC!=null){
if (subType.equals(subTypeC)){
resource.add(sw.toString());
}
}
else
resource.add(sw.toString());
}
return resource;
}
/***
* Create a list for configuration (aka GenericResourceObject)
* @param scope
* @param typeE
* @return
* @throws Exception
*/
public static List<String> CreateListConfiguration(String scope,
String typeC, String subTypeC) throws Exception {
ScopeProvider.instance.set(scope);
JAXBContext context = JAXBContext.newInstance(GenericResourceObject.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_FRAGMENT, true);
List<String>resource=new ArrayList<String>();
String id="";
//String type="EService";
String type="GenericResource";
String subType="";
String name="";
String description="";
List<Configuration> econfiguration = (List<Configuration>) resourceRegistryClient.getInstances(Configuration.NAME,false);
for (Configuration et : econfiguration) {
id=et.getHeader().getUUID().toString();
List<? extends Facet> facets = et.getIdentificationFacets();
for (Facet f : facets) {
if(f instanceof SoftwareFacet){
SoftwareFacet sf = (SoftwareFacet) f;
name=sf.getName();
subType=sf.getGroup();
description= sf.getDescription();
}
}
CacheList.resourceid.put(id, new ResourceObject(name, et.toString()));
GenericResourceObject temp =new GenericResourceObject(id, type, subType, name, description,scope);
StringWriter sw = new StringWriter();
m.marshal(temp,sw);
// filter to subtype
@ -231,7 +317,68 @@ public class UtilityResource {
}
return resource;
}
//NOT WORK it's too slow
private static void CreateCacheListConfiguration(String scope) throws Exception {
// TODO Auto-generated method stub
ScopeProvider.instance.set(scope);
JAXBContext context = JAXBContext.newInstance(GenericResourceObject.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_FRAGMENT, true);
List<String>resource=new ArrayList<String>();
String id="";
//String type="EService";
String type="GenericResource";
String subType="";
String name="";
String description="";
List<Configuration> econfiguration = (List<Configuration>) resourceRegistryClient.getInstances(Configuration.NAME,false);
for (Configuration et : econfiguration) {
id=et.getHeader().getUUID().toString();
List<? extends Facet> facets = et.getIdentificationFacets();
for (Facet f : facets) {
if(f instanceof SoftwareFacet){
SoftwareFacet sf = (SoftwareFacet) f;
name=sf.getName();
subType=sf.getGroup();
description= sf.getDescription();
}
}
CacheList.resourceid.put(id, new ResourceObject(name, et.toString()));
GenericResourceObject temp =new GenericResourceObject(id, type, subType, name, description,scope);
StringWriter sw = new StringWriter();
m.marshal(temp,sw);
System.out.println("---------------->sw.toString "+sw.toString());
if (CacheList.resourceTable.containsKey(type+subType)){
List<String> listResource=CacheList.resourceTable.get(type+subType);
if (!listResource.contains(sw.toString()))
listResource.add(sw.toString());
}
else{
List<String>listResource=new ArrayList<String>();
listResource.add(sw.toString());
CacheList.resourceTable.put(type+subType, listResource);
}
}
}
}