update to version 1.1.0

add operations: (add/remove)RI(from/to)Scope

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/whn-manager@115832 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Roberto Cirillo 2015-07-03 12:40:26 +00:00
parent 108b2be42b
commit da98a22499
3 changed files with 113 additions and 16 deletions

View File

@ -8,7 +8,7 @@
</parent>
<groupId>org.gcube.resourcemanagement</groupId>
<artifactId>whn-manager</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<webappDirectory>${project.basedir}/src/main/webapp/WEB-INF</webappDirectory>

View File

@ -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;
}
}

View File

@ -1,7 +1,7 @@
<application mode='online'>
<name>WhnManager</name>
<group>VREManagement</group>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<description>Web Hosting Node Service</description>
<local-persistence location='target' />
</application>