use of new tokens added
This commit is contained in:
parent
e066142c7f
commit
e7b910588e
|
@ -1,12 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/resource-management-6.3.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
|
||||
<classpathentry kind="src" output="target/resource-registry-management-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/resource-management-6.3.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
|
||||
<classpathentry excluding="**" kind="src" output="target/resource-registry-management-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
|
@ -40,5 +40,5 @@
|
|||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/>
|
||||
<classpathentry kind="output" path="target/resource-management-6.3.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
<classpathentry kind="output" path="target/resource-registry-management-1.0.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
</classpath>
|
||||
|
|
53
pom.xml
53
pom.xml
|
@ -86,6 +86,12 @@
|
|||
<version>2.9.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>keycloak-client</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- new registry deps -->
|
||||
<!-- Facets Based Resource Model related dependencies -->
|
||||
|
@ -306,7 +312,6 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.1.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>compile</phase>
|
||||
|
@ -322,57 +327,11 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- SA Plugin -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>servicearchive</id>
|
||||
<phase>install</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-profile</id>
|
||||
<phase>install</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>target</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${distroDirectory}</directory>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>profile.xml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
|
|
@ -1,10 +1,22 @@
|
|||
package org.gcube.portlets.admin.resourcemanagement.server;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
|
||||
import org.gcube.common.keycloak.KeycloakClient;
|
||||
import org.gcube.common.keycloak.KeycloakClientFactory;
|
||||
import org.gcube.common.keycloak.model.ModelUtils;
|
||||
import org.gcube.common.keycloak.model.TokenResponse;
|
||||
import org.gcube.common.keycloak.model.AccessToken.Access;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
||||
|
@ -19,7 +31,43 @@ import org.gcube.resourcemanagement.support.shared.types.datamodel.CompleteResou
|
|||
*
|
||||
*/
|
||||
public class RegistryClientRequester {
|
||||
|
||||
private static ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
|
||||
private static KeycloakClient client = KeycloakClientFactory.newInstance();
|
||||
|
||||
private static final String endpoint = "https://accounts.dev.d4science.org/auth/realms/d4science/protocol/openid-connect/token";
|
||||
private static final String clientID = "resource-registry-portlet-expieve";
|
||||
private static final String secret = "179bd3bc-5cc4-11ec-bf63-0242ac130001";
|
||||
|
||||
public static final Set<String> getAvailableContexts() throws Exception {
|
||||
Set<String> contexts = new HashSet<String>();
|
||||
try {
|
||||
TokenResponse response = client.queryOIDCToken(new URL(endpoint), clientID, secret);
|
||||
Map<String, Access> resourceAccess = ModelUtils.getAccessTokenFrom(response).getResourceAccess();
|
||||
for (String context : resourceAccess.keySet()) {
|
||||
try {
|
||||
ScopeBean scope = new ScopeBean(context.replaceAll("%2F", "/"));
|
||||
contexts.add(scope.toString());
|
||||
}catch (IllegalArgumentException e) { }
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return contexts;
|
||||
}
|
||||
|
||||
private static String getTokenForContext(String context) {
|
||||
try {
|
||||
TokenResponse response = client.queryUMAToken(new URL(endpoint), clientID, secret, context, null);
|
||||
return response.getAccessToken();
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("error getting access token for context "+context, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* For all the resource in the scope retrieves their
|
||||
* (type, subtype) values.
|
||||
|
@ -27,65 +75,73 @@ public class RegistryClientRequester {
|
|||
* @return a list of string tuples (type, subtype)
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
|
||||
//list a resource with a sub category
|
||||
public static final HashMap<String, ArrayList<String>> getResourcesTree(String scope) throws Exception {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
HashMap<String, ArrayList<String>> retval = new HashMap<String, ArrayList<String>>();
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
AccessTokenProvider.instance.set(getTokenForContext(scope));
|
||||
try {
|
||||
|
||||
List<Type> types = resourceRegistryClient.getType(Resource.class, true);
|
||||
for (Type t : types) {
|
||||
|
||||
String val = null;
|
||||
if (t.getName().equals("EService"))
|
||||
retval.put("RunningInstance", UtilityResource.getSubResourcesTreeQuery(t.getName(),scope));
|
||||
val= "RunningInstance";
|
||||
if (t.getName().equals("Configuration"))
|
||||
retval.put("GenericResource", UtilityResource.getSubResourcesTreeQuery(t.getName(),scope));
|
||||
val = "GenericResource";
|
||||
if (t.getName().equals("HostingNode"))
|
||||
retval.put("GHN", UtilityResource.getSubResourcesTreeQuery(t.getName(),scope));
|
||||
|
||||
val = "GHN";
|
||||
retval.put(val, UtilityResource.getSubResourcesTreeQuery(resourceRegistryClient, t.getName()));
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
AccessTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//list string (xml formatted) for table
|
||||
public static final List<String> getResourcesByTypeSubType( String scope,String type,String subType) throws Exception {
|
||||
|
||||
|
||||
|
||||
|
||||
//CacheList.resourceid.clear();
|
||||
ScopeProvider.instance.set(scope);
|
||||
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);
|
||||
resource=UtilityResource.CreateListConfigurationQuery(scope,type,subType);
|
||||
break;
|
||||
case "GHN":
|
||||
System.out.println("---------------->GHN ");
|
||||
resource=UtilityResource.CreateListHostingNode(scope,type,subType);
|
||||
break;
|
||||
|
||||
}
|
||||
return resource;
|
||||
|
||||
AccessTokenProvider.instance.set(getTokenForContext(scope));
|
||||
try {
|
||||
|
||||
|
||||
List<String>resource=new ArrayList<String>();
|
||||
|
||||
switch (type) {
|
||||
case "RunningInstance":
|
||||
System.out.println("---------------->RunningInstance ");
|
||||
resource=UtilityResource.createListEservice(resourceRegistryClient, type,subType);
|
||||
break;
|
||||
case "GenericResource":
|
||||
System.out.println("---------------->GenericResource ");
|
||||
//resource=UtilityResource.CreateListConfiguration(scope,type,subType);
|
||||
resource=UtilityResource.createListConfigurationQuery(resourceRegistryClient, type,subType);
|
||||
break;
|
||||
case "GHN":
|
||||
System.out.println("---------------->GHN ");
|
||||
resource=UtilityResource.createListHostingNode(resourceRegistryClient, type,subType);
|
||||
break;
|
||||
|
||||
}
|
||||
return resource;
|
||||
}finally {
|
||||
AccessTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -94,7 +150,7 @@ public class RegistryClientRequester {
|
|||
public static CompleteResourceProfile getResourceByID(
|
||||
String xml2htmlMapping, String scope, String type,
|
||||
String resID) {
|
||||
|
||||
|
||||
String representation=CacheList.resourceid.get(resID).getBody();
|
||||
//get resource by id
|
||||
String title=CacheList.resourceid.get(resID).getTitle();
|
||||
|
|
|
@ -21,16 +21,14 @@ import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
|||
import java.io.File;
|
||||
import java.io.StringReader;
|
||||
import java.security.InvalidParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.crypto.SecretKeyFactory;
|
||||
import javax.crypto.spec.PBEKeySpec;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
@ -41,6 +39,8 @@ import org.gcube.common.scope.impl.ScopeBean;
|
|||
import org.gcube.portlets.admin.resourcemanagement.client.remote.ServiceProxy;
|
||||
import org.gcube.portlets.admin.resourcemanagement.server.gcube.services.StatusHandler;
|
||||
import org.gcube.portlets.admin.resourcemanagement.server.gcube.services.configuration.ConfigurationLoader;
|
||||
import org.gcube.portlets.admin.resourcemanagement.shared.resource.UtilityResource;
|
||||
import org.gcube.portlets.admin.resourcemanagement.shared.utils.BCrypt;
|
||||
import org.gcube.resourcemanagement.support.client.utils.CurrentStatus;
|
||||
import org.gcube.resourcemanagement.support.client.views.ResourceTypeDecorator;
|
||||
import org.gcube.resourcemanagement.support.server.gcube.CacheManager;
|
||||
|
@ -68,11 +68,8 @@ import org.gcube.vremanagement.resourcemanager.client.RMReportingLibrary;
|
|||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
|
||||
import org.gcube.portlets.admin.resourcemanagement.shared.utils.BCrypt;
|
||||
|
||||
/**
|
||||
* @author Daniele Strollo
|
||||
* @author Massimiliano Assante (ISTI-CNR)
|
||||
|
@ -263,11 +260,7 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro
|
|||
ServerConsole.trace(LOG_PREFIX, "[GET-SCOPES] getting available scopes");
|
||||
Vector<String> retval = new Vector<String>();
|
||||
try {
|
||||
Map<String, ScopeBean> scopes = ScopeManager.getAvailableScopes();
|
||||
for (ScopeBean scope : scopes.values())
|
||||
retval.add(scope.toString());
|
||||
|
||||
return retval;
|
||||
//TODO
|
||||
} catch (Exception e) {
|
||||
retval.add("/gcube");
|
||||
retval.add("/gcube/devsec");
|
||||
|
@ -277,40 +270,22 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro
|
|||
return retval;
|
||||
}
|
||||
|
||||
|
||||
public final List<String> getAvailableAddScopes() {
|
||||
List<String> retval = new Vector<String>();
|
||||
try {
|
||||
ScopeBean currScope = ScopeManager.getScope(this.getCurrentStatus().getCurrentScope());
|
||||
List<String> scopes = this.getAvailableScopes();
|
||||
for (String scope : scopes) {
|
||||
if (scope.contains(currScope.toString())) {
|
||||
retval.add(scope);
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
retval.addAll(RegistryClientRequester.getAvailableContexts());
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error(LOG_PREFIX, e);
|
||||
}
|
||||
return null;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**LISTA DI RISORSE*/
|
||||
public final HashMap<String, ArrayList<String>> getResourceTypeTree(final String scope) throws Exception {
|
||||
try {
|
||||
|
||||
|
||||
|
||||
ScopeBean gscope = new ScopeBean(scope);
|
||||
|
||||
//Old Registry
|
||||
//HashMap<String, ArrayList<String>> results = ISClientRequester.getResourcesTree(getCacheManager(this.getCurrentStatus()), gscope);
|
||||
//New Registry
|
||||
|
||||
//before is not necessary
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
||||
HashMap<String, ArrayList<String>> results = RegistryClientRequester.getResourcesTree(scope);
|
||||
|
||||
|
||||
|
||||
return results;
|
||||
} catch (Exception e) {
|
||||
|
@ -318,32 +293,13 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro
|
|||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public final List<String> getRelatedResources(final String type, final String id, final String scope)
|
||||
{
|
||||
try {
|
||||
System.out.println("---------------->getRelatedResources");
|
||||
return ISClientRequester.getRelatedResources(
|
||||
getCacheManager(this.getCurrentStatus()),
|
||||
type,
|
||||
id,
|
||||
new ScopeBean(scope)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
ServerConsole.error(LOG_PREFIX, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//click su icona madre e restituisce lista di stringhe che completano tabella
|
||||
public final List<String> getResourcesByType(final String scope, final String type)
|
||||
{
|
||||
try {
|
||||
System.out.println("---------------->getResourcesByType");
|
||||
ScopeBean gscope = new ScopeBean(scope);
|
||||
//Old Code
|
||||
//List<String> request=ISClientRequester.getResourcesByType(getCacheManager(this.getCurrentStatus()),gscope, type, null);
|
||||
//New code
|
||||
List<String> request=RegistryClientRequester.getResourcesByTypeSubType(scope, type,null);
|
||||
|
||||
return request;
|
||||
|
@ -570,5 +526,11 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro
|
|||
return matched;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRelatedResources(String type, String id, String scope) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,14 +1,25 @@
|
|||
package org.gcube.portlets.admin.resourcemanagement.shared.resource;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Marshaller;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
|
||||
import org.gcube.common.keycloak.KeycloakClient;
|
||||
import org.gcube.common.keycloak.KeycloakClientFactory;
|
||||
import org.gcube.common.keycloak.model.ModelUtils;
|
||||
import org.gcube.common.keycloak.model.TokenResponse;
|
||||
import org.gcube.common.keycloak.model.AccessToken.Access;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||
|
@ -39,185 +50,104 @@ import com.google.gwt.thirdparty.json.JSONObject;
|
|||
*
|
||||
*/
|
||||
public class UtilityResource {
|
||||
|
||||
|
||||
private static ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
|
||||
public static ArrayList<String> getSubResourcesTree(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);
|
||||
|
||||
for (Resource r : resources) {
|
||||
List<? extends IsIdentifiedBy> iibs = r.getConsistsOf(IsIdentifiedBy.class);
|
||||
for (IsIdentifiedBy iib : iibs) {
|
||||
|
||||
Facet f = (Facet) iib.getTarget();
|
||||
|
||||
switch (entity) {
|
||||
/*
|
||||
case "Software":
|
||||
if(f instanceof NetworkingFacet){
|
||||
NetworkingFacet nf = (NetworkingFacet) f;
|
||||
list.add(nf.getHostName());
|
||||
}
|
||||
break;
|
||||
|
||||
case "Resource":
|
||||
if(f instanceof NetworkingFacet){
|
||||
NetworkingFacet nf = (NetworkingFacet) f;
|
||||
list.add(nf.getHostName());
|
||||
}
|
||||
break;
|
||||
case "LegalBody":
|
||||
if(f instanceof NetworkingFacet){
|
||||
NetworkingFacet nf = (NetworkingFacet) f;
|
||||
list.add(nf.getHostName());
|
||||
}
|
||||
break;
|
||||
case "Service":
|
||||
if(f instanceof NetworkingFacet){
|
||||
NetworkingFacet nf = (NetworkingFacet) f;
|
||||
list.add(nf.getHostName());
|
||||
}
|
||||
break;
|
||||
case "Site":
|
||||
if(f instanceof NetworkingFacet){
|
||||
NetworkingFacet nf = (NetworkingFacet) f;
|
||||
list.add(nf.getHostName());
|
||||
}
|
||||
break;
|
||||
*/
|
||||
case "HostingNode":
|
||||
if(f instanceof NetworkingFacet){
|
||||
NetworkingFacet nf = (NetworkingFacet) f;
|
||||
if (!list.contains(nf.getDomainName())){
|
||||
list.add(nf.getDomainName());
|
||||
}
|
||||
}
|
||||
break;
|
||||
/*
|
||||
case "Dataset":
|
||||
if(f instanceof NetworkingFacet){
|
||||
NetworkingFacet nf = (NetworkingFacet) f;
|
||||
list.add(nf.getHostName());
|
||||
}
|
||||
break;
|
||||
case "ConfigurationTemplate":
|
||||
if(f instanceof NetworkingFacet){
|
||||
NetworkingFacet nf = (NetworkingFacet) f;
|
||||
list.add(nf.getHostName());
|
||||
}
|
||||
break;
|
||||
case "ConcreteDataset":
|
||||
if(f instanceof NetworkingFacet){
|
||||
NetworkingFacet nf = (NetworkingFacet) f;
|
||||
list.add(nf.getHostName());
|
||||
}
|
||||
break;
|
||||
*/
|
||||
case "Configuration":
|
||||
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());
|
||||
}
|
||||
}
|
||||
break;
|
||||
/*
|
||||
case "RunningPlugin":
|
||||
if(f instanceof NetworkingFacet){
|
||||
NetworkingFacet nf = (NetworkingFacet) f;
|
||||
list.add(nf.getHostName());
|
||||
}
|
||||
break;
|
||||
case "VirtualService":
|
||||
if(f instanceof IdentifierFacet){
|
||||
IdentifierFacet nf = (IdentifierFacet) f;
|
||||
list.add(nf.getType());
|
||||
}
|
||||
break;
|
||||
case "Actor":
|
||||
if(f instanceof IdentifierFacet){
|
||||
IdentifierFacet nf = (IdentifierFacet) f;
|
||||
nf.getType();
|
||||
}
|
||||
break;
|
||||
*/
|
||||
case "EService": //GcoreEndPoint
|
||||
if(f instanceof SoftwareFacet){
|
||||
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());
|
||||
}
|
||||
break;
|
||||
/*
|
||||
case "Plugin":
|
||||
if(f instanceof IdentifierFacet){
|
||||
IdentifierFacet nf = (IdentifierFacet) f;
|
||||
nf.getType();
|
||||
}
|
||||
break;
|
||||
case "Person":
|
||||
if(f instanceof IdentifierFacet){
|
||||
IdentifierFacet nf = (IdentifierFacet) f;
|
||||
nf.getType();
|
||||
}
|
||||
break;
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static ArrayList<String> getSubResourcesTreeQuery(String entity) 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);
|
||||
|
||||
for (Resource r : resources) {
|
||||
List<? extends IsIdentifiedBy> iibs = r.getConsistsOf(IsIdentifiedBy.class);
|
||||
for (IsIdentifiedBy iib : iibs) {
|
||||
|
||||
Facet f = (Facet) iib.getTarget();
|
||||
|
||||
switch (entity) {
|
||||
case "HostingNode":
|
||||
if(f instanceof NetworkingFacet){
|
||||
NetworkingFacet nf = (NetworkingFacet) f;
|
||||
if (!list.contains(nf.getDomainName())){
|
||||
list.add(nf.getDomainName());
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "Configuration":
|
||||
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());
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "EService": //GcoreEndPoint
|
||||
if(f instanceof SoftwareFacet){
|
||||
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());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static ArrayList<String> getSubResourcesTreeQuery(ResourceRegistryClient resourceRegistryClient, String entity) throws Exception{
|
||||
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
String field = null;
|
||||
String identifiedFacet = null;
|
||||
switch (entity) {
|
||||
|
||||
case "HostingNode":
|
||||
field="domainName";
|
||||
identifiedFacet="NetworkingFacet";
|
||||
break;
|
||||
|
||||
case "Configuration":
|
||||
field="group";
|
||||
identifiedFacet="SoftwareFacet";
|
||||
break;
|
||||
|
||||
case "EService": //GcoreEndPoint
|
||||
field="group";
|
||||
identifiedFacet="SoftwareFacet";
|
||||
break;
|
||||
|
||||
}
|
||||
String query="SELECT DISTINCT("+field+") AS "+field+" "
|
||||
+ "FROM (TRAVERSE outE('IsIdentifiedBy'),inV('"+identifiedFacet+"') FROM "+entity+")";
|
||||
|
||||
System.out.println("------------query----------->"+query);
|
||||
String result=resourceRegistryClient.rawQuery(query, 1000, null);
|
||||
JSONObject jsonObj = new JSONObject(result);
|
||||
JSONArray jsonArray=jsonObj.getJSONArray("result");
|
||||
|
||||
for(int i=0;i < jsonArray.length();i++){
|
||||
list.add(jsonArray.getJSONObject(i).getString(field));
|
||||
}
|
||||
switch (entity) {
|
||||
|
||||
case "HostingNode":
|
||||
field="domainName";
|
||||
identifiedFacet="NetworkingFacet";
|
||||
break;
|
||||
|
||||
case "Configuration":
|
||||
field="group";
|
||||
identifiedFacet="SoftwareFacet";
|
||||
break;
|
||||
|
||||
case "EService": //GcoreEndPoint
|
||||
field="group";
|
||||
identifiedFacet="SoftwareFacet";
|
||||
break;
|
||||
|
||||
}
|
||||
String query="SELECT DISTINCT("+field+") AS "+field+" "
|
||||
+ "FROM (TRAVERSE outE('IsIdentifiedBy'),inV('"+identifiedFacet+"') FROM "+entity+")";
|
||||
|
||||
System.out.println("------------query----------->"+query);
|
||||
|
||||
String result=resourceRegistryClient.rawQuery(query, 1000, null);
|
||||
JSONObject jsonObj = new JSONObject(result);
|
||||
JSONArray jsonArray=jsonObj.getJSONArray("result");
|
||||
|
||||
for(int i=0;i < jsonArray.length();i++){
|
||||
list.add(jsonArray.getJSONObject(i).getString(field));
|
||||
}
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/***
|
||||
* Create a list for configuration (aka GenericResourceObject)
|
||||
* @param scope
|
||||
|
@ -225,14 +155,11 @@ public class UtilityResource {
|
|||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static List<String> CreateListConfigurationQuery(String scope,
|
||||
String typeC, String subTypeC) throws Exception {
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
||||
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') "
|
||||
query="SELECT header,name, description FROM (TRAVERSE outE('IsIdentifiedBy'),inV('SoftwareFacet') "
|
||||
+ " FROM Configuration WHILE $depth<=0)";
|
||||
}
|
||||
else{
|
||||
|
@ -240,12 +167,12 @@ public class UtilityResource {
|
|||
+ " FROM Configuration ) where group='"+subTypeC+"'";
|
||||
}
|
||||
System.out.println("------------query list configuration----------->"+query);
|
||||
|
||||
|
||||
JAXBContext context = JAXBContext.newInstance(GenericResourceObject.class);
|
||||
Marshaller m = context.createMarshaller();
|
||||
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
||||
m.setProperty(Marshaller.JAXB_FRAGMENT, true);
|
||||
|
||||
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";
|
||||
|
@ -253,85 +180,53 @@ public class UtilityResource {
|
|||
String subType="";
|
||||
String name="";
|
||||
String description="";
|
||||
|
||||
|
||||
|
||||
String result=resourceRegistryClient.rawQuery(query, 1000, null);
|
||||
JSONObject jsonObj = new JSONObject(result);
|
||||
JSONArray jsonArray=jsonObj.getJSONArray("result");
|
||||
|
||||
for(int i=0;i < jsonArray.length();i++){
|
||||
//TODO
|
||||
//id=jsonArray.getJSONObject(i).getString("header");
|
||||
//id="b981efde-18ea-4867-98e7-5d024fcfc0cb"+i;
|
||||
JSONObject header=new JSONObject(jsonArray.getJSONObject(i).getString("header"));
|
||||
id=(String) header.get("uuid");
|
||||
System.out.println("------------id----------->"+id);
|
||||
|
||||
try{
|
||||
name=jsonArray.getJSONObject(i).getString("name");
|
||||
}catch(Exception e){
|
||||
name="";
|
||||
}
|
||||
try{
|
||||
description=jsonArray.getJSONObject(i).getString("description");
|
||||
}catch(Exception e){
|
||||
description="";
|
||||
}
|
||||
|
||||
|
||||
|
||||
GenericResourceObject temp =new GenericResourceObject(id, type, subType, name, description,scope);
|
||||
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
m.marshal(temp,sw);
|
||||
|
||||
UUID uuid =UUID.fromString(id);
|
||||
// ER configurationRegistry=resourceRegistryClient.getInstance(Configuration.class, uuid);
|
||||
// CacheList.resourceid.put(id, new ResourceObject(name, configurationRegistry.toString()));
|
||||
|
||||
resource.add(sw.toString());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
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();
|
||||
|
||||
}
|
||||
JSONObject jsonObj = new JSONObject(result);
|
||||
JSONArray jsonArray=jsonObj.getJSONArray("result");
|
||||
|
||||
for(int i=0;i < jsonArray.length();i++){
|
||||
//TODO
|
||||
//id=jsonArray.getJSONObject(i).getString("header");
|
||||
//id="b981efde-18ea-4867-98e7-5d024fcfc0cb"+i;
|
||||
JSONObject header=new JSONObject(jsonArray.getJSONObject(i).getString("header"));
|
||||
id=(String) header.get("uuid");
|
||||
System.out.println("------------id----------->"+id);
|
||||
|
||||
try{
|
||||
name=jsonArray.getJSONObject(i).getString("name");
|
||||
}catch(Exception e){
|
||||
name="";
|
||||
}
|
||||
|
||||
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
|
||||
if (subTypeC!=null){
|
||||
if (subType.equals(subTypeC)){
|
||||
resource.add(sw.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
resource.add(sw.toString());
|
||||
|
||||
try{
|
||||
description=jsonArray.getJSONObject(i).getString("description");
|
||||
}catch(Exception e){
|
||||
description="";
|
||||
}
|
||||
|
||||
|
||||
|
||||
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()));
|
||||
|
||||
resource.add(sw.toString());
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
return resource;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/***
|
||||
* Create a list for eservice (aka gcore endpoint)
|
||||
|
@ -340,12 +235,12 @@ public class UtilityResource {
|
|||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static List<String> CreateListEservice(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);
|
||||
m.setProperty(Marshaller.JAXB_FRAGMENT, true);
|
||||
|
||||
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";
|
||||
|
@ -356,7 +251,7 @@ public class UtilityResource {
|
|||
String version="";
|
||||
String status="";
|
||||
String ghnName="";
|
||||
|
||||
|
||||
List<EService> eservices = (List<EService>) resourceRegistryClient.getInstances(EService.class,false);
|
||||
for (EService et : eservices) {
|
||||
id=et.getHeader().getUUID().toString();
|
||||
|
@ -372,7 +267,7 @@ public class UtilityResource {
|
|||
}
|
||||
}
|
||||
CacheList.resourceid.put(id, new ResourceObject(serviceName, et.toString()));
|
||||
|
||||
|
||||
ghnName="";
|
||||
status="";
|
||||
List<ConsistsOf<? extends Resource, ? extends Facet>> consist = et.getConsistsOf();
|
||||
|
@ -398,18 +293,18 @@ public class UtilityResource {
|
|||
}
|
||||
}
|
||||
}
|
||||
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());
|
||||
|
||||
GcoreEndPointObject temp= new GcoreEndPointObject(id,type,subType,ScopeProvider.instance.get(),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;
|
||||
}
|
||||
|
@ -425,15 +320,14 @@ public class UtilityResource {
|
|||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static List<String> CreateListConfiguration(String scope,
|
||||
public static List<String> createListConfiguration(ResourceRegistryClient resourceRegistryClient,
|
||||
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);
|
||||
|
||||
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";
|
||||
|
@ -451,27 +345,27 @@ public class UtilityResource {
|
|||
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
|
||||
if (subTypeC!=null){
|
||||
if (subType.equals(subTypeC)){
|
||||
resource.add(sw.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
resource.add(sw.toString());
|
||||
|
||||
GenericResourceObject temp =new GenericResourceObject(id, type, subType, name, description,ScopeProvider.instance.get());
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
m.marshal(temp,sw);
|
||||
// filter to subtype
|
||||
if (subTypeC!=null){
|
||||
if (subType.equals(subTypeC)){
|
||||
resource.add(sw.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
resource.add(sw.toString());
|
||||
|
||||
}
|
||||
return resource;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -483,15 +377,14 @@ public class UtilityResource {
|
|||
* @throws Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public static List<String> CreateListHostingNode(String scope, String typeC,String subTypeC) throws Exception {
|
||||
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
public static List<String> createListHostingNode(ResourceRegistryClient resourceRegistryClient, String typeC,String subTypeC) throws Exception {
|
||||
|
||||
|
||||
JAXBContext context = JAXBContext.newInstance(HostingNodeObject.class);
|
||||
Marshaller m = context.createMarshaller();
|
||||
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
||||
m.setProperty(Marshaller.JAXB_FRAGMENT, true);
|
||||
|
||||
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="HostingNode";
|
||||
|
@ -509,7 +402,7 @@ public class UtilityResource {
|
|||
String loadLast15Min="-";
|
||||
String gcfVersion="";
|
||||
String ghnVersion="";
|
||||
|
||||
|
||||
List<HostingNode> ehosting = (List<HostingNode>) resourceRegistryClient.getInstances(HostingNode.class,false);
|
||||
for (HostingNode eh : ehosting) {
|
||||
id=eh.getHeader().getUUID().toString();
|
||||
|
@ -522,13 +415,13 @@ public class UtilityResource {
|
|||
name=nf.getHostName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
//System.out.println("------------ConsistsOf--ConsistsOf-- c"+c.toString());
|
||||
if(c instanceof ConsistsOf){
|
||||
|
||||
|
||||
if (c.getTarget() instanceof SimplePropertyFacet){
|
||||
SimplePropertyFacet sp = (SimplePropertyFacet) c.getTarget();
|
||||
try {
|
||||
|
@ -544,8 +437,8 @@ public class UtilityResource {
|
|||
if (c instanceof HasPersistentMemory){
|
||||
HasPersistentMemory hpm = (HasPersistentMemory) c;
|
||||
try {
|
||||
MemoryFacet mfh = (MemoryFacet) hpm.getTarget();
|
||||
localAvailableSpace=mfh.getSize()- mfh.getUsed();
|
||||
MemoryFacet mfh = (MemoryFacet) hpm.getTarget();
|
||||
localAvailableSpace=mfh.getSize()- mfh.getUsed();
|
||||
}
|
||||
catch(Exception e){
|
||||
localAvailableSpace=0;
|
||||
|
@ -579,23 +472,23 @@ public class UtilityResource {
|
|||
}
|
||||
}
|
||||
HostingNodeObject temp =new HostingNodeObject( id, type, subType,
|
||||
status, name, upTime, lastUpdate,
|
||||
localAvailableSpace, virtualSize,
|
||||
virtualAvailable, loadLast1Min, loadLast5Min,
|
||||
loadLast15Min, gcfVersion, ghnVersion,
|
||||
scope);
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
m.marshal(temp,sw);
|
||||
// filter to subtype
|
||||
if (subTypeC!=null){
|
||||
if (subType.equals(subTypeC)){
|
||||
resource.add(sw.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
resource.add(sw.toString());
|
||||
|
||||
status, name, upTime, lastUpdate,
|
||||
localAvailableSpace, virtualSize,
|
||||
virtualAvailable, loadLast1Min, loadLast5Min,
|
||||
loadLast15Min, gcfVersion, ghnVersion,
|
||||
ScopeProvider.instance.get());
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
m.marshal(temp,sw);
|
||||
// filter to subtype
|
||||
if (subTypeC!=null){
|
||||
if (subType.equals(subTypeC)){
|
||||
resource.add(sw.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
resource.add(sw.toString());
|
||||
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue