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/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <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="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="resource-registry-management"/> <property name="context-root" value="resource-registry-management"/>

View File

@ -70,8 +70,13 @@ public class ResourceGridFactory {
// For the grid representation // For the grid representation
final ColumnModel cm = ResourceDetailModel.getRecordDefinition(resourceType); final ColumnModel cm = ResourceDetailModel.getRecordDefinition(resourceType);
if (type == null || cm == null) { if (type == null) {
MessageBox.alert("Failure", "the model representation has not been found", 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; return null;
} }

View File

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

View File

@ -7,6 +7,7 @@ import java.util.List;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller; import javax.xml.bind.Marshaller;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource; 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.Configuration;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService; 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.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.HasPersistentMemory;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory; import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
@ -30,23 +32,19 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* *
* @author pieve mail:alessandro.pieve@isti.cnr.it * @author pieve mail:alessandro.pieve@isti.cnr.it
* *
*/ */
public class UtilityResource { public class UtilityResource {
private static Logger logger = LoggerFactory.getLogger(UtilityResource.class); 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<>(); ArrayList<String> list = new ArrayList<>();
String s = resourceRegistryClient.getInstances(entity, true); String s = resourceRegistryClient.getInstances(entity, true);
List<Resource> resources = ElementMapper.unmarshalList(Resource.class, s); List<Resource> resources = ElementMapper.unmarshalList(Resource.class, s);
@ -58,46 +56,53 @@ public class UtilityResource {
switch (entity) { switch (entity) {
case "HostingNode": case "HostingNode":
if(f instanceof NetworkingFacet){ if (f instanceof NetworkingFacet) {
NetworkingFacet nf = (NetworkingFacet) f; NetworkingFacet nf = (NetworkingFacet) f;
if (!list.contains(nf.getDomainName())){ if (!list.contains(nf.getDomainName())) {
list.add(nf.getDomainName()); list.add(nf.getDomainName());
} }
} }
break; break;
case "Configuration": case "Configuration":
if(f instanceof SoftwareFacet){ if (f instanceof SoftwareFacet) {
// logger.info("------------Configuration--SoftwareFacet-- identified by GenericResource"); // logger.info("------------Configuration--SoftwareFacet--
// identified by GenericResource");
SoftwareFacet sf = (SoftwareFacet) f; SoftwareFacet sf = (SoftwareFacet) f;
if (!list.contains(sf.getGroup())){ if (!list.contains(sf.getGroup())) {
list.add(sf.getGroup()); list.add(sf.getGroup());
} }
} }
break; break;
case "EService": //GcoreEndPoint case "EService": // GcoreEndPoint
if(f instanceof SoftwareFacet){ 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; SoftwareFacet sf = (SoftwareFacet) f;
if (!list.contains(sf.getGroup())) if (!list.contains(sf.getGroup()))
list.add(sf.getGroup()); list.add(sf.getGroup());
} }
break; break;
} }
} }
} }
return list; 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<>(); ArrayList<String> list = new ArrayList<>();
String field = null; String field = null;
@ -105,18 +110,23 @@ public class UtilityResource {
switch (entity) { switch (entity) {
case "HostingNode": case "HostingNode":
field="domainName"; field = "domainName";
identifiedFacet="NetworkingFacet"; identifiedFacet = "NetworkingFacet";
break; break;
case "Configuration": case "Configuration":
field="group"; field = "group";
identifiedFacet="SoftwareFacet"; identifiedFacet = "SoftwareFacet";
break; break;
case "EService": //GcoreEndPoint case "EService": // GcoreEndPoint
field="group"; field = "group";
identifiedFacet="SoftwareFacet"; identifiedFacet = "SoftwareFacet";
break;
case "VirtualService": // Service
field = "group";
identifiedFacet = "SoftwareFacet";
break; break;
default: default:
@ -125,96 +135,98 @@ public class UtilityResource {
} }
try { try {
String query="SELECT DISTINCT("+field+") AS "+field+" " String query = "SELECT DISTINCT(" + field + ") AS " + field + " "
+ "FROM (TRAVERSE outE('IsIdentifiedBy'),inV('"+identifiedFacet+"') FROM "+entity+")"; + "FROM (TRAVERSE outE('IsIdentifiedBy'),inV('" + identifiedFacet + "') FROM " + entity + ")";
logger.info("------------query----------->"+query); logger.info("------------query----------->" + query);
String result=resourceRegistryClient.rawQuery(query, true); String result = resourceRegistryClient.rawQuery(query, true);
if (result != null && !result.isEmpty()) {
if (result!=null&&!result.isEmpty()) { logger.info("--------result-------->" + result);
logger.info("--------result-------->"+result);
JSONArray jsonArray = new JSONArray(result); JSONArray jsonArray = new JSONArray(result);
for(int i=0;i < jsonArray.length();i++){ for (int i = 0; i < jsonArray.length(); i++) {
list.add(jsonArray.getJSONObject(i).get(field).toString()); list.add(jsonArray.getJSONObject(i).get(field).toString());
} }
} else { } else {
logger.info("--------result-------->Attention invalid result!"); logger.info("--------result-------->Attention invalid result!");
} }
}catch (Exception e) { } catch (Exception e) {
logger.error(e.getLocalizedMessage(),e); logger.error(e.getLocalizedMessage(), e);
} }
return list; return list;
} }
/*** /***
* Create a list for configuration (aka GenericResourceObject) * Create a list for configuration (aka GenericResourceObject)
*
* @param scope * @param scope
* @param typeE * @param typeE
* @return * @return
* @throws Exception * @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; String query = null;
if (subTypeC==null){ if (subTypeC == null) {
query="SELECT header,name, description FROM (TRAVERSE outE('IsIdentifiedBy'),inV('SoftwareFacet') " query = "SELECT header,name, description FROM (TRAVERSE outE('IsIdentifiedBy'),inV('SoftwareFacet') "
+ " FROM Configuration WHILE $depth<=0)"; + " FROM Configuration WHILE $depth<=0)";
} else {
query = "SELECT header,name, description FROM (TRAVERSE outE('IsIdentifiedBy'),inV('SoftwareFacet') "
+ " FROM Configuration ) where group='" + subTypeC + "'";
} }
else{ logger.info("------------query list configuration----------->" + query);
query="SELECT header,name, description FROM (TRAVERSE outE('IsIdentifiedBy'),inV('SoftwareFacet') "
+ " FROM Configuration ) where group='"+subTypeC+"'";
}
logger.info("------------query list configuration----------->"+query);
JAXBContext context = JAXBContext.newInstance(GenericResourceObject.class); JAXBContext context = JAXBContext.newInstance(GenericResourceObject.class);
Marshaller m = context.createMarshaller(); Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_FRAGMENT, true); m.setProperty(Marshaller.JAXB_FRAGMENT, true);
List<String>resource=new ArrayList<String>(); List<String> resource = new ArrayList<String>();
String id=""; String id = "";
//String type="EService"; // String type="EService";
String type="GenericResource"; String type = "GenericResource";
String subType=""; String subType = "";
String name=""; String name = "";
String description=""; String description = "";
String result = resourceRegistryClient.rawQuery(query, true);
String result=resourceRegistryClient.rawQuery(query, true); try {
try{ if (result != null && !result.isEmpty()) {
if (result!=null&&!result.isEmpty()) { logger.info("--------result-------->" + result);
logger.info("--------result-------->"+result);
JSONArray jsonArray = new JSONArray(result); JSONArray jsonArray = new JSONArray(result);
for(int i=0;i < jsonArray.length();i++){ for (int i = 0; i < jsonArray.length(); i++) {
//TODO // TODO
//id=jsonArray.getJSONObject(i).getString("header"); // id=jsonArray.getJSONObject(i).getString("header");
//id="b981efde-18ea-4867-98e7-5d024fcfc0cb"+i; // id="b981efde-18ea-4867-98e7-5d024fcfc0cb"+i;
JSONObject header=new JSONObject(jsonArray.getJSONObject(i).get("header").toString()); JSONObject header = new JSONObject(jsonArray.getJSONObject(i).get("header").toString());
id=(String) header.get("uuid"); id = (String) header.get("uuid");
logger.info("------------id----------->"+id); logger.info("------------id----------->" + id);
try{ try {
name=jsonArray.getJSONObject(i).getString("name"); name = jsonArray.getJSONObject(i).getString("name");
}catch(Exception e){ } catch (Exception e) {
name=""; name = "";
} }
try{ try {
description=jsonArray.getJSONObject(i).getString("description"); description = jsonArray.getJSONObject(i).getString("description");
}catch(Exception e){ } catch (Exception e) {
description=""; 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(); StringWriter sw = new StringWriter();
m.marshal(temp,sw); m.marshal(temp, sw);
// ER configurationRegistry=resourceRegistryClient.getInstance(Configuration.class, uuid); // ER
// CacheList.resourceid.put(id, new ResourceObject(name, configurationRegistry.toString())); // configurationRegistry=resourceRegistryClient.getInstance(Configuration.class,
// uuid);
// CacheList.resourceid.put(id, new ResourceObject(name,
// configurationRegistry.toString()));
resource.add(sw.toString()); resource.add(sw.toString());
} }
@ -223,149 +235,143 @@ public class UtilityResource {
logger.info("--------result-------->Attention invalid result!"); logger.info("--------result-------->Attention invalid result!");
} }
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getLocalizedMessage(),e); logger.error(e.getLocalizedMessage(), e);
} }
return resource; return resource;
} }
/*** /***
* Create a list for eservice (aka gcore endpoint) * Create a list for eservice (aka gcore endpoint)
*
* @param scope * @param scope
* @param typeE * @param typeE
* @return * @return
* @throws Exception * @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); JAXBContext context = JAXBContext.newInstance(GcoreEndPointObject.class);
Marshaller m = context.createMarshaller(); Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_FRAGMENT, true); m.setProperty(Marshaller.JAXB_FRAGMENT, true);
List<String>resource=new ArrayList<String>(); List<String> resource = new ArrayList<String>();
String id=""; String id = "";
String type="EService"; String type = "EService";
//String type="RunningInstance"; // String type="RunningInstance";
String subType=""; String subType = "";
String serviceClass=""; String serviceClass = "";
String serviceName=""; String serviceName = "";
String version=""; String version = "";
String status=""; String status = "";
String ghnName=""; String ghnName = "";
List<EService> eservices = (List<EService>) resourceRegistryClient.getInstances(EService.class,false); List<EService> eservices = (List<EService>) resourceRegistryClient.getInstances(EService.class, false);
for (EService et : eservices) { for (EService et : eservices) {
id=et.getHeader().getUUID().toString(); id = et.getHeader().getUUID().toString();
List<? extends Facet> facets = et.getIdentificationFacets(); List<? extends Facet> facets = et.getIdentificationFacets();
for (Facet f : facets) { for (Facet f : facets) {
if(f instanceof SoftwareFacet){ if (f instanceof SoftwareFacet) {
SoftwareFacet sf = (SoftwareFacet) f; SoftwareFacet sf = (SoftwareFacet) f;
version= sf.getVersion(); version = sf.getVersion();
serviceName=sf.getName(); serviceName = sf.getName();
serviceClass=sf.getGroup(); serviceClass = sf.getGroup();
subType=sf.getGroup(); subType = sf.getGroup();
version=sf.getVersion(); version = sf.getVersion();
} }
} }
CacheList.resourceid.put(id, new ResourceObject(serviceName, et.toString())); CacheList.resourceid.put(id, new ResourceObject(serviceName, et.toString()));
ghnName=""; ghnName = "";
status=""; status = "";
List<ConsistsOf<? extends Resource, ? extends Facet>> consist = et.getConsistsOf(); List<ConsistsOf<? extends Resource, ? extends Facet>> consist = et.getConsistsOf();
for (ConsistsOf<? extends Resource, ? extends Facet> c : consist) { for (ConsistsOf<? extends Resource, ? extends Facet> c : consist) {
if(c instanceof ConsistsOf){ if (c instanceof ConsistsOf) {
if (c.getTarget() instanceof AccessPointFacet){ if (c.getTarget() instanceof AccessPointFacet) {
AccessPointFacet af = (AccessPointFacet) c.getTarget(); AccessPointFacet af = (AccessPointFacet) c.getTarget();
try { try {
ghnName=af.getEndpoint().getHost().toString(); ghnName = af.getEndpoint().getHost().toString();
} } catch (Exception e) {
catch(Exception e){ ghnName = "";
ghnName="";
} }
} }
if (c.getTarget() instanceof StateFacet){ if (c.getTarget() instanceof StateFacet) {
StateFacet stf = (StateFacet) c.getTarget(); StateFacet stf = (StateFacet) c.getTarget();
try { try {
status=stf.getValue().toLowerCase(); status = stf.getValue().toLowerCase();
} } catch (Exception e) {
catch(Exception e){ status = "";
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(); StringWriter sw = new StringWriter();
m.marshal(temp,sw); m.marshal(temp, sw);
if (subTypeC!=null){ if (subTypeC != null) {
if (subType.equals(subTypeC)){ if (subType.equals(subTypeC)) {
resource.add(sw.toString()); resource.add(sw.toString());
} }
} } else
else
resource.add(sw.toString()); resource.add(sw.toString());
} }
return resource; return resource;
} }
/*** /***
* Create a list for configuration (aka GenericResourceObject) * Create a list for configuration (aka GenericResourceObject)
*
* @param scope * @param scope
* @param typeE * @param typeE
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static List<String> createListConfiguration(ResourceRegistryClient resourceRegistryClient, public static List<String> createListConfiguration(ResourceRegistryClient resourceRegistryClient, String typeC,
String typeC, String subTypeC) throws Exception { String subTypeC) throws Exception {
JAXBContext context = JAXBContext.newInstance(GenericResourceObject.class); JAXBContext context = JAXBContext.newInstance(GenericResourceObject.class);
Marshaller m = context.createMarshaller(); Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_FRAGMENT, true); m.setProperty(Marshaller.JAXB_FRAGMENT, true);
List<String>resource=new ArrayList<String>(); List<String> resource = new ArrayList<String>();
String id=""; String id = "";
//String type="EService"; // String type="EService";
String type="GenericResource"; String type = "GenericResource";
String subType=""; String subType = "";
String name=""; String name = "";
String description=""; 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) { for (Configuration et : econfiguration) {
id=et.getHeader().getUUID().toString(); id = et.getHeader().getUUID().toString();
List<? extends Facet> facets = et.getIdentificationFacets(); List<? extends Facet> facets = et.getIdentificationFacets();
for (Facet f : facets) { for (Facet f : facets) {
if(f instanceof SoftwareFacet){ if (f instanceof SoftwareFacet) {
SoftwareFacet sf = (SoftwareFacet) f; SoftwareFacet sf = (SoftwareFacet) f;
name=sf.getName(); name = sf.getName();
subType=sf.getGroup(); subType = sf.getGroup();
description= sf.getDescription(); description = sf.getDescription();
} }
} }
CacheList.resourceid.put(id, new ResourceObject(name, et.toString())); 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(); StringWriter sw = new StringWriter();
m.marshal(temp,sw); m.marshal(temp, sw);
// filter to subtype // filter to subtype
if (subTypeC!=null){ if (subTypeC != null) {
if (subType.equals(subTypeC)){ if (subType.equals(subTypeC)) {
resource.add(sw.toString()); resource.add(sw.toString());
} }
} } else
else
resource.add(sw.toString()); resource.add(sw.toString());
} }
@ -373,129 +379,179 @@ public class UtilityResource {
} }
/*** /***
* Create a list for hosting node (aka GHN) * Create a list for hosting node (aka GHN)
*
* @param scope * @param scope
* @param typeE * @param typeE
* @return * @return
* @throws Exception * @throws Exception
* @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); JAXBContext context = JAXBContext.newInstance(HostingNodeObject.class);
Marshaller m = context.createMarshaller(); Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_FRAGMENT, true); m.setProperty(Marshaller.JAXB_FRAGMENT, true);
List<String>resource=new ArrayList<String>(); List<String> resource = new ArrayList<String>();
String id=""; String id = "";
//String type="HostingNode"; // String type="HostingNode";
String type="GHN"; String type = "GHN";
String subType="";//-- String subType = "";// --
String status="";//--- String status = "";// ---
String name="";// String name = "";//
String upTime="-"; String upTime = "-";
String lastUpdate="-"; String lastUpdate = "-";
long localAvailableSpace = 0; long localAvailableSpace = 0;
long virtualSize=0; long virtualSize = 0;
long virtualAvailable=0; long virtualAvailable = 0;
String loadLast1Min="-"; String loadLast1Min = "-";
String loadLast5Min="-"; String loadLast5Min = "-";
String loadLast15Min="-"; String loadLast15Min = "-";
String gcfVersion=""; String gcfVersion = "";
String ghnVersion=""; String ghnVersion = "";
List<HostingNode> ehosting = (List<HostingNode>) resourceRegistryClient.getInstances(HostingNode.class,false); List<HostingNode> ehosting = (List<HostingNode>) resourceRegistryClient.getInstances(HostingNode.class, false);
for (HostingNode eh : ehosting) { for (HostingNode eh : ehosting) {
id=eh.getHeader().getUUID().toString(); id = eh.getHeader().getUUID().toString();
lastUpdate=eh.getHeader().getLastUpdateTime().toString(); lastUpdate = eh.getHeader().getLastUpdateTime().toString();
List<? extends Facet> facets = eh.getIdentificationFacets(); List<? extends Facet> facets = eh.getIdentificationFacets();
for (Facet f : facets) { for (Facet f : facets) {
if(f instanceof NetworkingFacet){ if (f instanceof NetworkingFacet) {
NetworkingFacet nf = (NetworkingFacet) f; NetworkingFacet nf = (NetworkingFacet) f;
subType=nf.getDomainName(); subType = nf.getDomainName();
name=nf.getHostName(); name = nf.getHostName();
} }
} }
CacheList.resourceid.put(id, new ResourceObject(name, eh.toString())); CacheList.resourceid.put(id, new ResourceObject(name, eh.toString()));
List<ConsistsOf<? extends Resource, ? extends Facet>> consist = eh.getConsistsOf(); List<ConsistsOf<? extends Resource, ? extends Facet>> consist = eh.getConsistsOf();
for (ConsistsOf<? extends Resource, ? extends Facet> c : consist) { for (ConsistsOf<? extends Resource, ? extends Facet> c : consist) {
//logger.info("------------ConsistsOf--ConsistsOf-- c"+c.toString()); // logger.info("------------ConsistsOf--ConsistsOf--
if(c instanceof ConsistsOf){ // c"+c.toString());
if (c instanceof ConsistsOf) {
if (c.getTarget() instanceof SimplePropertyFacet){ if (c.getTarget() instanceof SimplePropertyFacet) {
SimplePropertyFacet sp = (SimplePropertyFacet) c.getTarget(); SimplePropertyFacet sp = (SimplePropertyFacet) c.getTarget();
try { try {
gcfVersion=sp.getAdditionalProperty("SmartGearsDistribution").toString(); gcfVersion = sp.getAdditionalProperty("SmartGearsDistribution").toString();
ghnVersion=sp.getAdditionalProperty("SmartGears").toString(); ghnVersion = sp.getAdditionalProperty("SmartGears").toString();
} } catch (Exception e) {
catch(Exception e){ gcfVersion = "";
gcfVersion=""; ghnVersion = "";
ghnVersion="";
} }
} }
//get disk space // get disk space
if (c instanceof HasPersistentMemory){ if (c instanceof HasPersistentMemory) {
HasPersistentMemory hpm = (HasPersistentMemory) c; HasPersistentMemory hpm = (HasPersistentMemory) c;
try { try {
MemoryFacet mfh = (MemoryFacet) hpm.getTarget(); MemoryFacet mfh = (MemoryFacet) hpm.getTarget();
localAvailableSpace=mfh.getSize()- mfh.getUsed(); localAvailableSpace = mfh.getSize() - mfh.getUsed();
} } catch (Exception e) {
catch(Exception e){ localAvailableSpace = 0;
localAvailableSpace=0;
} }
} }
//get ram space // get ram space
if (c instanceof HasVolatileMemory){ if (c instanceof HasVolatileMemory) {
HasVolatileMemory hvm = (HasVolatileMemory) c; HasVolatileMemory hvm = (HasVolatileMemory) c;
try { try {
if (hvm.getAdditionalProperty("memoryType").equals("RAM")){ if (hvm.getAdditionalProperty("memoryType").equals("RAM")) {
MemoryFacet mf = (MemoryFacet) hvm.getTarget(); MemoryFacet mf = (MemoryFacet) hvm.getTarget();
virtualAvailable=mf.getSize()-mf.getUsed(); virtualAvailable = mf.getSize() - mf.getUsed();
virtualSize=mf.getSize(); virtualSize = mf.getSize();
} }
} } catch (Exception e) {
catch(Exception e){ virtualAvailable = 0;
virtualAvailable=0; virtualSize = 0;
virtualSize=0;
} }
} }
//get status // get status
if (c.getTarget() instanceof StateFacet){ if (c.getTarget() instanceof StateFacet) {
StateFacet st = (StateFacet) c.getTarget(); StateFacet st = (StateFacet) c.getTarget();
try { try {
status=st.getValue(); status = st.getValue();
} } catch (Exception e) {
catch(Exception e){ status = "";
status="";
} }
} }
} }
} }
HostingNodeObject temp =new HostingNodeObject( id, type, subType, HostingNodeObject temp = new HostingNodeObject(id, type, subType, status, name, upTime, lastUpdate,
status, name, upTime, lastUpdate, localAvailableSpace, virtualSize, virtualAvailable, loadLast1Min, loadLast5Min, loadLast15Min,
localAvailableSpace, virtualSize, gcfVersion, ghnVersion, ScopeProvider.instance.get());
virtualAvailable, loadLast1Min, loadLast5Min,
loadLast15Min, gcfVersion, ghnVersion,
ScopeProvider.instance.get());
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
m.marshal(temp,sw); m.marshal(temp, sw);
// filter to subtype // filter to subtype
if (subTypeC!=null){ if (subTypeC != null) {
if (subType.equals(subTypeC)){ if (subType.equals(subTypeC)) {
resource.add(sw.toString()); resource.add(sw.toString());
} }
} } else
else
resource.add(sw.toString()); resource.add(sw.toString());
} }
return resource; 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;
}
} }