Added VirtualService

This commit is contained in:
Giancarlo Panichi 2022-12-19 17:02:31 +01:00
parent 48bd133abc
commit 9dd9943c12
4 changed files with 310 additions and 239 deletions

View File

@ -9,6 +9,9 @@
<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="rrm-common-library-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/rrm-common-library/rrm-common-library">
<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-registry-management"/>

View File

@ -70,8 +70,13 @@ public class ResourceGridFactory {
// For the grid representation
final ColumnModel cm = ResourceDetailModel.getRecordDefinition(resourceType);
if (type == null || cm == null) {
MessageBox.alert("Failure", "the model representation has not been found", null);
if (type == null) {
MessageBox.alert("Failure", "The XML Mapping representation has not been found", null);
return null;
}
if (cm == null) {
MessageBox.alert("Failure", "The Record Definition representation has not been found", null);
return null;
}

View File

@ -109,6 +109,8 @@ public class RegistryClientRequester {
val = "GenericResource";
if (t.getName().equals("HostingNode"))
val = "GHN";
if (t.getName().equals("VirtualService"))
val = "VirtualService";
if (val!=null) {
ArrayList<String> subtrees = new ArrayList<String>();
@ -160,6 +162,11 @@ public class RegistryClientRequester {
logger.info("---------------->GHN ");
resource=UtilityResource.createListHostingNode(resourceRegistryClient, type,subType);
break;
case "VirtualService":
logger.info("---------------->VirtualService ");
resource=UtilityResource.createListVirtualService(resourceRegistryClient, type,subType);
break;
}
return resource;

View File

@ -7,6 +7,7 @@ import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
@ -22,6 +23,7 @@ import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
import org.gcube.resourcemanagement.model.reference.entities.resources.VirtualService;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasPersistentMemory;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
@ -30,9 +32,6 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author pieve mail:alessandro.pieve@isti.cnr.it
@ -42,11 +41,10 @@ public class UtilityResource {
private static Logger logger = LoggerFactory.getLogger(UtilityResource.class);
public static ArrayList<String> getSubResourcesTree(ResourceRegistryClient resourceRegistryClient, String entity, String scope) throws Exception{
public static ArrayList<String> getSubResourcesTree(ResourceRegistryClient resourceRegistryClient, String entity,
String scope) throws Exception {
ArrayList<String> list = new ArrayList<>();
String s = resourceRegistryClient.getInstances(entity, true);
List<Resource> resources = ElementMapper.unmarshalList(Resource.class, s);
@ -68,7 +66,8 @@ public class UtilityResource {
case "Configuration":
if (f instanceof SoftwareFacet) {
// logger.info("------------Configuration--SoftwareFacet-- identified by GenericResource");
// logger.info("------------Configuration--SoftwareFacet--
// identified by GenericResource");
SoftwareFacet sf = (SoftwareFacet) f;
if (!list.contains(sf.getGroup())) {
list.add(sf.getGroup());
@ -78,26 +77,32 @@ public class UtilityResource {
case "EService": // GcoreEndPoint
if (f instanceof SoftwareFacet) {
logger.info("------------EService--SoftwareFacet-- identified by Gcore End point and Service End Point");
logger.info(
"------------EService--SoftwareFacet-- identified by Gcore End point and Service End Point");
SoftwareFacet sf = (SoftwareFacet) f;
if (!list.contains(sf.getGroup()))
list.add(sf.getGroup());
}
break;
case "VirtualService": // Service
if (f instanceof SoftwareFacet) {
logger.info(
"------------VirtualService--SoftwareFacet-- identified Service End Point");
SoftwareFacet sf = (SoftwareFacet) f;
if (!list.contains(sf.getGroup()))
list.add(sf.getGroup());
}
break;
}
}
}
return list;
}
public static ArrayList<String> getSubResourcesTreeQuery(ResourceRegistryClient resourceRegistryClient, String entity) throws Exception{
public static ArrayList<String> getSubResourcesTreeQuery(ResourceRegistryClient resourceRegistryClient,
String entity) throws Exception {
ArrayList<String> list = new ArrayList<>();
String field = null;
@ -119,6 +124,11 @@ public class UtilityResource {
identifiedFacet = "SoftwareFacet";
break;
case "VirtualService": // Service
field = "group";
identifiedFacet = "SoftwareFacet";
break;
default:
return new ArrayList<>(0);
@ -132,7 +142,6 @@ public class UtilityResource {
String result = resourceRegistryClient.rawQuery(query, true);
if (result != null && !result.isEmpty()) {
logger.info("--------result-------->" + result);
JSONArray jsonArray = new JSONArray(result);
@ -149,22 +158,22 @@ public class UtilityResource {
}
/***
* Create a list for configuration (aka GenericResourceObject)
*
* @param scope
* @param typeE
* @return
* @throws Exception
*/
public static List<String> createListConfigurationQuery(ResourceRegistryClient resourceRegistryClient, String typeC, String subTypeC) throws Exception {
public static List<String> createListConfigurationQuery(ResourceRegistryClient resourceRegistryClient, String typeC,
String subTypeC) throws Exception {
String query = null;
if (subTypeC == null) {
query = "SELECT header,name, description FROM (TRAVERSE outE('IsIdentifiedBy'),inV('SoftwareFacet') "
+ " FROM Configuration WHILE $depth<=0)";
}
else{
} else {
query = "SELECT header,name, description FROM (TRAVERSE outE('IsIdentifiedBy'),inV('SoftwareFacet') "
+ " FROM Configuration ) where group='" + subTypeC + "'";
}
@ -183,7 +192,6 @@ public class UtilityResource {
String name = "";
String description = "";
String result = resourceRegistryClient.rawQuery(query, true);
try {
if (result != null && !result.isEmpty()) {
@ -209,12 +217,16 @@ public class UtilityResource {
description = "";
}
GenericResourceObject temp =new GenericResourceObject(id, type, subType, name, description,ScopeProvider.instance.get());
GenericResourceObject temp = new GenericResourceObject(id, type, subType, name, description,
ScopeProvider.instance.get());
StringWriter sw = new StringWriter();
m.marshal(temp, sw);
// ER configurationRegistry=resourceRegistryClient.getInstance(Configuration.class, uuid);
// CacheList.resourceid.put(id, new ResourceObject(name, configurationRegistry.toString()));
// ER
// configurationRegistry=resourceRegistryClient.getInstance(Configuration.class,
// uuid);
// CacheList.resourceid.put(id, new ResourceObject(name,
// configurationRegistry.toString()));
resource.add(sw.toString());
}
@ -229,18 +241,16 @@ public class UtilityResource {
return resource;
}
/***
* Create a list for eservice (aka gcore endpoint)
*
* @param scope
* @param typeE
* @return
* @throws Exception
*/
public static List<String> createListEservice(ResourceRegistryClient resourceRegistryClient, String typeC,String subTypeC) throws Exception {
public static List<String> createListEservice(ResourceRegistryClient resourceRegistryClient, String typeC,
String subTypeC) throws Exception {
JAXBContext context = JAXBContext.newInstance(GcoreEndPointObject.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
@ -282,8 +292,7 @@ public class UtilityResource {
AccessPointFacet af = (AccessPointFacet) c.getTarget();
try {
ghnName = af.getEndpoint().getHost().toString();
}
catch(Exception e){
} catch (Exception e) {
ghnName = "";
}
}
@ -291,14 +300,14 @@ public class UtilityResource {
StateFacet stf = (StateFacet) c.getTarget();
try {
status = stf.getValue().toLowerCase();
}
catch(Exception e){
} catch (Exception e) {
status = "";
}
}
}
}
GcoreEndPointObject temp= new GcoreEndPointObject(id,type,subType,ScopeProvider.instance.get(),serviceClass,serviceName,version,status,ghnName);
GcoreEndPointObject temp = new GcoreEndPointObject(id, type, subType, ScopeProvider.instance.get(),
serviceClass, serviceName, version, status, ghnName);
StringWriter sw = new StringWriter();
m.marshal(temp, sw);
@ -306,27 +315,23 @@ public class UtilityResource {
if (subType.equals(subTypeC)) {
resource.add(sw.toString());
}
}
else
} 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(ResourceRegistryClient resourceRegistryClient,
String typeC, String subTypeC) throws Exception {
public static List<String> createListConfiguration(ResourceRegistryClient resourceRegistryClient, String typeC,
String subTypeC) throws Exception {
JAXBContext context = JAXBContext.newInstance(GenericResourceObject.class);
Marshaller m = context.createMarshaller();
@ -340,7 +345,8 @@ public class UtilityResource {
String subType = "";
String name = "";
String description = "";
List<Configuration> econfiguration = (List<Configuration>) resourceRegistryClient.getInstances(Configuration.class,false);
List<Configuration> econfiguration = (List<Configuration>) resourceRegistryClient
.getInstances(Configuration.class, false);
for (Configuration et : econfiguration) {
id = et.getHeader().getUUID().toString();
List<? extends Facet> facets = et.getIdentificationFacets();
@ -355,7 +361,8 @@ public class UtilityResource {
}
CacheList.resourceid.put(id, new ResourceObject(name, et.toString()));
GenericResourceObject temp =new GenericResourceObject(id, type, subType, name, description,ScopeProvider.instance.get());
GenericResourceObject temp = new GenericResourceObject(id, type, subType, name, description,
ScopeProvider.instance.get());
StringWriter sw = new StringWriter();
m.marshal(temp, sw);
@ -364,8 +371,7 @@ public class UtilityResource {
if (subType.equals(subTypeC)) {
resource.add(sw.toString());
}
}
else
} else
resource.add(sw.toString());
}
@ -373,17 +379,17 @@ public class UtilityResource {
}
/***
* Create a list for hosting node (aka GHN)
*
* @param scope
* @param typeE
* @return
* @throws Exception
* @throws Exception
*/
public static List<String> createListHostingNode(ResourceRegistryClient resourceRegistryClient, String typeC,String subTypeC) throws Exception {
public static List<String> createListHostingNode(ResourceRegistryClient resourceRegistryClient, String typeC,
String subTypeC) throws Exception {
JAXBContext context = JAXBContext.newInstance(HostingNodeObject.class);
Marshaller m = context.createMarshaller();
@ -424,7 +430,8 @@ public class UtilityResource {
CacheList.resourceid.put(id, new ResourceObject(name, eh.toString()));
List<ConsistsOf<? extends Resource, ? extends Facet>> consist = eh.getConsistsOf();
for (ConsistsOf<? extends Resource, ? extends Facet> c : consist) {
//logger.info("------------ConsistsOf--ConsistsOf-- c"+c.toString());
// logger.info("------------ConsistsOf--ConsistsOf--
// c"+c.toString());
if (c instanceof ConsistsOf) {
if (c.getTarget() instanceof SimplePropertyFacet) {
@ -432,8 +439,7 @@ public class UtilityResource {
try {
gcfVersion = sp.getAdditionalProperty("SmartGearsDistribution").toString();
ghnVersion = sp.getAdditionalProperty("SmartGears").toString();
}
catch(Exception e){
} catch (Exception e) {
gcfVersion = "";
ghnVersion = "";
}
@ -444,8 +450,7 @@ public class UtilityResource {
try {
MemoryFacet mfh = (MemoryFacet) hpm.getTarget();
localAvailableSpace = mfh.getSize() - mfh.getUsed();
}
catch(Exception e){
} catch (Exception e) {
localAvailableSpace = 0;
}
}
@ -458,8 +463,7 @@ public class UtilityResource {
virtualAvailable = mf.getSize() - mf.getUsed();
virtualSize = mf.getSize();
}
}
catch(Exception e){
} catch (Exception e) {
virtualAvailable = 0;
virtualSize = 0;
}
@ -469,19 +473,15 @@ public class UtilityResource {
StateFacet st = (StateFacet) c.getTarget();
try {
status = st.getValue();
}
catch(Exception e){
} catch (Exception e) {
status = "";
}
}
}
}
HostingNodeObject temp =new HostingNodeObject( id, type, subType,
status, name, upTime, lastUpdate,
localAvailableSpace, virtualSize,
virtualAvailable, loadLast1Min, loadLast5Min,
loadLast15Min, gcfVersion, ghnVersion,
ScopeProvider.instance.get());
HostingNodeObject temp = new HostingNodeObject(id, type, subType, status, name, upTime, lastUpdate,
localAvailableSpace, virtualSize, virtualAvailable, loadLast1Min, loadLast5Min, loadLast15Min,
gcfVersion, ghnVersion, ScopeProvider.instance.get());
StringWriter sw = new StringWriter();
m.marshal(temp, sw);
@ -490,12 +490,68 @@ public class UtilityResource {
if (subType.equals(subTypeC)) {
resource.add(sw.toString());
}
}
else
} else
resource.add(sw.toString());
}
return resource;
}
public static List<String> createListVirtualService(ResourceRegistryClient resourceRegistryClient, String typeC,
String subTypeC) throws Exception{
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 = "VirtualService";
String subType = "";
String serviceClass = "";
String serviceName = "";
//String version = "";
List<VirtualService> virtualServices = (List<VirtualService>) resourceRegistryClient.getInstances(VirtualService.class, false);
if(virtualServices!=null){
logger.info("VirtualServices found: {}", virtualServices.size());
} else {
logger.info("VirtualServices not found");
return resource;
}
for (VirtualService vs : virtualServices) {
id = vs.getHeader().getUUID().toString();
List<? extends Facet> facets = vs.getIdentificationFacets();
for (Facet f : facets) {
if (f instanceof SoftwareFacet) {
SoftwareFacet sf = (SoftwareFacet) f;
//version = sf.getVersion();
serviceName = sf.getName();
serviceClass = sf.getGroup();
subType = sf.getGroup();
}
}
CacheList.resourceid.put(id, new ResourceObject(serviceName, vs.toString()));
GenericResourceObject temp = new GenericResourceObject(id, type, subType,
serviceName,serviceClass, ScopeProvider.instance.get());
StringWriter sw = new StringWriter();
m.marshal(temp, sw);
if (subTypeC != null) {
if (subType.equals(subTypeC)) {
resource.add(sw.toString());
}
} else
resource.add(sw.toString());
}
logger.info("Virtual Service: {}",resource);
return resource;
}
}