diff --git a/pom.xml b/pom.xml
index 6efe483..f65dd1d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
org.gcube.resourcemanagement
whn-manager
- 1.0.1-SNAPSHOT
+ 1.1.0-SNAPSHOT
war
${project.basedir}/src/main/webapp/WEB-INF
diff --git a/src/main/java/org/gcube/vremanagement/whnmanager/jaxws/ws/WhnManagerImpl.java b/src/main/java/org/gcube/vremanagement/whnmanager/jaxws/ws/WhnManagerImpl.java
index 7b22622..349da9e 100644
--- a/src/main/java/org/gcube/vremanagement/whnmanager/jaxws/ws/WhnManagerImpl.java
+++ b/src/main/java/org/gcube/vremanagement/whnmanager/jaxws/ws/WhnManagerImpl.java
@@ -1,21 +1,32 @@
package org.gcube.vremanagement.whnmanager.jaxws.ws;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
import java.util.Arrays;
import java.util.Iterator;
import javax.jws.WebService;
+
+
import org.gcube.smartgears.ContextProvider;
+import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.smartgears.context.container.ContainerContext;
+import org.gcube.smartgears.extensions.resource.ScopesResource.Scope;
import org.gcube.smartgears.handlers.container.lifecycle.ProfilePublisher;
import org.gcube.vremanagement.whnmanager.utils.ValidationUtils;
+//import org.gcube.common.calls.jaxws.Constants;
import org.gcube.common.resources.gcore.HostingNode;
+import org.gcube.common.resources.gcore.Resources;
import org.gcube.common.resources.gcore.ScopeGroup;
+import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.resourcemanagement.whnmanager.api.exception.GCUBEUnrecoverableException;
import org.gcube.resourcemanagement.whnmanager.api.WhnManager;
import org.gcube.resourcemanagement.whnmanager.api.types.AddScopeInputParams;
+import org.gcube.resourcemanagement.whnmanager.api.types.ScopeRIParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -28,7 +39,7 @@ public class WhnManagerImpl implements WhnManager{
private static Logger logger=LoggerFactory.getLogger(WhnManagerImpl.class);
-
+ public static final String SCOPE_HEADER_ENTRY = "gcube-scope";
/**
* Add a scope to the ghn profile and publish it on IS
@@ -56,7 +67,7 @@ public class WhnManagerImpl implements WhnManager{
String scopeFound=(String)it.next();
logger.debug(" - "+scopeFound);
}
- ContainerContext container=context.container();
+ ContainerContext container=context.container()/*.configuration().apps()*/;
ProfilePublisher publisher= new ProfilePublisher(container);
publisher.update();
}else{
@@ -79,7 +90,6 @@ public class WhnManagerImpl implements WhnManager{
logger.debug("this is a VRE scope. The request will be ignored ");
return true;
}
-
ApplicationContext context = ContextProvider.get();
if(context!=null){
HostingNode ghn=context.container().profile(HostingNode.class);
@@ -97,12 +107,23 @@ public class WhnManagerImpl implements WhnManager{
return true;
}
-// @Override
-// public boolean addRIToScope(ScopeRIParams params) throws GCUBEUnrecoverableException{
-// logger.debug("addRIToScope dummy method: Adding scope " + params.getScope() + " to RI <" + params.getClazz() +","+ params.getName() +">");
-//
-// return true;
-// }
+ @Override
+ public boolean addRIToScope(ScopeRIParams params) throws GCUBEUnrecoverableException{
+ logger.debug("addRIToScope method: Adding scope " + params.getScope() + " to RI <" + params.getClazz() +","+ params.getName() +">");
+ try {
+ HttpURLConnection connection =getConnectionToScopeManager(params.name);
+ logger.debug("adding scope: "+params.scope);
+ Scope newScope = new Scope(params.scope);
+ try (OutputStream output = connection.getOutputStream()) {
+ Resources.marshal(newScope, output);
+ }
+ logger.info("addScope operation ended with response code: "+connection.getResponseCode());
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return true;
+ }
//
// @Override
// public boolean activateRI(RIData ri) throws GCUBEUnrecoverableException{
@@ -117,9 +138,85 @@ public class WhnManagerImpl implements WhnManager{
// return true;
// }
//
-// @Override
-// public boolean removeRIFromScope(ScopeRIParams params) throws GCUBEUnrecoverableException{
-// logger.debug("dummy removeRIFromScope method with param "+params);
-// return true;
-// }
+ @Override
+ public boolean removeRIFromScope(ScopeRIParams params) throws GCUBEUnrecoverableException{
+ logger.debug("removeRIFromScope method with param "+params);
+ try {
+ HttpURLConnection connection =getConnectionToScopeManager(params.name);
+ logger.debug("adding scope: "+params.scope);
+ Scope newScope = new Scope(params.scope);
+ newScope.delete=true;
+ try (OutputStream output = connection.getOutputStream()) {
+ Resources.marshal(newScope, output);
+ }
+ logger.info("addScope operation ended with response code: "+connection.getResponseCode());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return true;
+ }
+
+ private void addScope(String appName, String currentScope, String scopeToAdd ) throws Exception{
+ ApplicationContext context = ContextProvider.get();
+ String hostname = context.container().configuration().hostname();
+ int port = context.container().configuration().port();
+ ApplicationConfiguration app=getAppConfiguration(appName, context);
+ if(app!=null){
+ if(logger.isDebugEnabled())
+ logger.debug("http call to: http://"+hostname+":"+port+"/"+app.context()+"/gcube/resource/scopes");
+// URL url = new URL(String.format("http://%s:%d/%s/gcube/resource/scopes", "dlib29.isti.cnr.it", 8080, "authorization-service" ));
+ URL url = new URL(String.format("http://%s:%d/%s/gcube/resource/scopes", hostname, port, app.context()));
+ HttpURLConnection connection = (HttpURLConnection)url.openConnection();
+ connection.setRequestMethod("POST");
+ connection.setDoOutput(true);
+ connection.setDoInput(true);
+ connection.setRequestProperty("Content-Type", "application/xml");
+ connection.setRequestProperty(SCOPE_HEADER_ENTRY, currentScope);
+ Scope newScope = new Scope(scopeToAdd);
+ try (OutputStream output = connection.getOutputStream()) {
+ Resources.marshal(newScope, output);
+ }
+ logger.info("addScope operation ended with response code: "+connection.getResponseCode());
+
+ }else{
+ throw new RuntimeException("applicationConfiguration not found ");
+ }
+ }
+
+ private HttpURLConnection getConnectionToScopeManager(String appName) throws Exception{
+ ApplicationContext context = ContextProvider.get();
+ String hostname = context.container().configuration().hostname();
+ int port = context.container().configuration().port();
+ String currentScope=ScopeProvider.instance.get();
+ ApplicationConfiguration app=getAppConfiguration(appName, context);
+ if(app!=null){
+ if(logger.isDebugEnabled())
+ logger.debug("http call to: http://"+hostname+":"+port+"/"+app.context()+"/gcube/resource/scopes");
+// URL url = new URL(String.format("http://%s:%d/%s/gcube/resource/scopes", "dlib29.isti.cnr.it", 8080, "authorization-service" ));
+ URL url = new URL(String.format("http://%s:%d/%s/gcube/resource/scopes", hostname, port, app.context()));
+ HttpURLConnection connection = (HttpURLConnection)url.openConnection();
+ connection.setRequestMethod("POST");
+ connection.setDoOutput(true);
+ connection.setDoInput(true);
+ connection.setRequestProperty("Content-Type", "application/xml");
+ connection.setRequestProperty(SCOPE_HEADER_ENTRY, currentScope);
+ return connection;
+ }else{
+ throw new RuntimeException("applicationConfiguration not found ");
+ }
+ }
+
+ private ApplicationConfiguration getAppConfiguration(String appName, ApplicationContext context){
+ logger.debug("get application configuration");
+ for (ApplicationConfiguration app : context.container().configuration().apps()){
+ logger.debug("check app "+ app.name());
+ if (app.name().equals(appName)){
+ logger.debug("application configuration is "+app.name());
+ return app;
+ }
+ }
+ return null;
+
+ }
+
}
diff --git a/src/main/webapp/WEB-INF/gcube-app.xml b/src/main/webapp/WEB-INF/gcube-app.xml
index 059a356..e8f4e06 100644
--- a/src/main/webapp/WEB-INF/gcube-app.xml
+++ b/src/main/webapp/WEB-INF/gcube-app.xml
@@ -1,7 +1,7 @@
WhnManager
VREManagement
- 1.0.0-SNAPSHOT
+ 1.1.0-SNAPSHOT
Web Hosting Node Service