works like a charm

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/service-endpoint-editor@81630 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2013-09-17 15:08:04 +00:00
parent cf10d3f49c
commit 4036c73816
7 changed files with 117 additions and 155 deletions

11
pom.xml
View File

@ -71,6 +71,11 @@
<artifactId>rmp-common-library</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
@ -89,12 +94,6 @@
<version>[1.2.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>gcf</artifactId>
<version>[1.4.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<!-- Liferay, Servlets Etc -->
<dependency>
<groupId>javax.mail</groupId>

View File

@ -8,10 +8,10 @@ import org.gcube.portlets.admin.sepeditor.shared.FilledRuntimeResource;
import org.gcube.portlets.admin.sepeditor.shared.InitInfo;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
/**
@ -31,8 +31,8 @@ public class RuntimeResourceCreator implements EntryPoint {
mainPanel.setSize("100%","600");
mainPanel.mask("Fetching Scopes, please wait","loading-indicator");
String resourceToEdit = com.google.gwt.user.client.Window.Location.getParameter("rid");
String curscope = com.google.gwt.user.client.Window.Location.getParameter("curscope");
final String resourceToEdit = com.google.gwt.user.client.Window.Location.getParameter("rid");
final String curscope = com.google.gwt.user.client.Window.Location.getParameter("curscope");
runtimeService.getInitialInfo((resourceToEdit != null), resourceToEdit, curscope, new AsyncCallback<InitInfo>() {
@ -42,6 +42,10 @@ public class RuntimeResourceCreator implements EntryPoint {
mainPanel.unmask();
ArrayList<String> scopes = initialInfo.getScopes();
if (initialInfo.getRr2edit() != null) {
if (initialInfo.getRr2edit().getResourceId() == null) {
MessageBox.alert("Service EndPoint Editor", "There is no Resource in the scope " + curscope + " having id: " + resourceToEdit, null);
}
else
initialize(scopes, initialInfo.getRr2edit());
}
else
@ -60,7 +64,6 @@ public class RuntimeResourceCreator implements EntryPoint {
}
public void initialize(ArrayList<String> scopes, FilledRuntimeResource toEdit) {
GWT.log("initialize" + scopes.toString());
if (scopesCache == null)
scopesCache = scopes;
ArrayList<ClientScope> scopesToPass = new ArrayList<ClientScope>();

View File

@ -1,8 +1,5 @@
package org.gcube.portlets.admin.sepeditor.client;
import java.util.ArrayList;
import org.gcube.portlets.admin.sepeditor.shared.Category;
import org.gcube.portlets.admin.sepeditor.shared.FilledRuntimeResource;
import org.gcube.portlets.admin.sepeditor.shared.InitInfo;
@ -14,7 +11,7 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
*/
@RemoteServiceRelativePath("serviceendpointEditor")
public interface RuntimeResourceCreatorService extends RemoteService {
ArrayList<Category> getCategories();
InitInfo getInitialInfo(boolean isEditMode, String idToEdit, String curscope);

View File

@ -1,8 +1,5 @@
package org.gcube.portlets.admin.sepeditor.client;
import java.util.ArrayList;
import org.gcube.portlets.admin.sepeditor.shared.Category;
import org.gcube.portlets.admin.sepeditor.shared.FilledRuntimeResource;
import org.gcube.portlets.admin.sepeditor.shared.InitInfo;
@ -13,8 +10,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
*/
public interface RuntimeResourceCreatorServiceAsync {
void getCategories(AsyncCallback<ArrayList<Category>> callback);
void createRuntimeResource(String scope, FilledRuntimeResource resource, boolean isUpdate,
AsyncCallback<Boolean> callback);

View File

@ -69,10 +69,10 @@ public class AccesPointPanel extends ContentPanel {
desc.setFieldLabel("Description");
desc.setAllowBlank(false);
interfaceEntryNameAttr.setFieldLabel("[Interface] interfaceEntry name ");
interfaceEntryNameAttr.setFieldLabel("Name");
interfaceEntryNameAttr.setAllowBlank(false);
interfaceEndPoint.setFieldLabel("[Interface] interfaceEndPoint ");
interfaceEndPoint.setFieldLabel("Address");
interfaceEndPoint.setAllowBlank(false);
username.setFieldLabel("Username");

View File

@ -60,7 +60,7 @@ public class RuntimeResourceForm extends ContentPanel {
public RuntimeResourceForm(RuntimeResourceCreator caller, ArrayList<ClientScope> scopes) {
this.caller = caller;
this.setHeaderVisible(true);
this.setHeading("Runtime Resource Creation");
this.setHeading("Service EndPoint Editor");
//this.setModal(true);
this.setAutoWidth(true);
this.setHeight(650);
@ -83,7 +83,7 @@ public class RuntimeResourceForm extends ContentPanel {
this.toEdit = toEdit;
this.caller = caller;
this.setHeaderVisible(true);
this.setHeading("Runtime Resource Creation [EDIT MODE]");
this.setHeading("Service EndPoint Editor [EDIT MODE]");
//this.setModal(true);
this.setAutoWidth(true);
this.setHeight(650);
@ -251,18 +251,18 @@ public class RuntimeResourceForm extends ContentPanel {
public void onSuccess(Boolean result) {
form.unmask();
if (result) {
MessageBox.alert("Runtime Resource Creation", "Request for registration successfully sent", null);
MessageBox.info("Service EndPoint Editor", "Request for registration successfully sent", null);
caller.initialize(null, null);
}
else {
MessageBox.alert("Runtime Resource Creation", "Request for registration failed, please check server logs", null);
MessageBox.alert("Service EndPoint Editor", "We're sorry, Request for registration failed on server, please check server logs", null);
}
caller.initialize(null, null);
}
@Override
public void onFailure(Throwable arg0) {
form.unmask();
MessageBox.alert("Runtime Resource Creation", "Request for registration Failed", null);
MessageBox.alert("Service EndPoint Editor", "Request for registration Failed", null);
caller.initialize(null, null);
}
});

View File

@ -10,45 +10,33 @@ import java.io.FileReader;
import java.io.IOException;
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 javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.log4j.Logger;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.informationsystem.ISException;
import org.gcube.common.core.informationsystem.client.AtomicCondition;
import org.gcube.common.core.informationsystem.client.ISClient;
import org.gcube.common.core.informationsystem.client.queries.GCUBERuntimeResourceQuery;
import org.gcube.common.core.informationsystem.publisher.ISPublisher;
import org.gcube.common.core.resources.GCUBERuntimeResource;
import org.gcube.common.core.resources.common.PlatformDescription;
import org.gcube.common.core.resources.runtime.AccessPoint;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.scope.ServiceMap;
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.encryption.StringEncrypter;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.portlets.admin.sepeditor.client.RuntimeResourceCreatorService;
import org.gcube.portlets.admin.sepeditor.shared.Category;
import org.gcube.portlets.admin.sepeditor.shared.FilledRuntimeResource;
import org.gcube.portlets.admin.sepeditor.shared.InitInfo;
import org.gcube.portlets.admin.sepeditor.shared.Property;
import org.gcube.portlets.admin.sepeditor.shared.RRAccessPoint;
import org.gcube.resourcemanagement.support.server.managers.resources.RuntimeResourceManager;
import org.gcube.resourcemanagement.support.server.managers.scope.ScopeManager;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
@ -92,87 +80,76 @@ public class RuntimeResourceCreatorServiceImpl extends RemoteServiceServlet impl
@Override
public Boolean createRuntimeResource(String scope, FilledRuntimeResource rs, boolean isUpdate) {
GCUBERuntimeResource rt;
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
ServiceEndpoint rt;
boolean result = true;
try {
if (!isUpdate) {
_log.info("Trying creating Runtime Resource: " + rs.getResourceName() + " SCOPE: " + scope);
rt =GHNContext.getImplementation(GCUBERuntimeResource.class);
rt = new ServiceEndpoint();
}
else {
ISClient client = GHNContext.getImplementation(ISClient.class);
GCUBERuntimeResourceQuery query = client.getQuery(GCUBERuntimeResourceQuery.class);
query.addAtomicConditions(new AtomicCondition("//ID", rs.getResourceId()));
SimpleQuery query = queryFor(ServiceEndpoint.class);
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
query.addCondition("$resource/ID/text() eq '" + rs.getResourceId() + "'");
_log.info("Trying editing Runtime Resource ID: " + rs.getResourceId());
rt = client.execute(query,GCUBEScope.getScope(scope)).get(0); //only one rr per id
rt = client.submit(query).get(0); //only one rr per id
}
rt.setCategory(rs.getCategory());
rt.setDescription(rs.getDescription());
rt.setGHN(rs.getRuntimegHNUniqueID());
rt.setHostedOn(rs.getRuntimeHostedOn());
rt.setName(rs.getResourceName());
rt.setStatus(rs.getRuntimeStatus());
PlatformDescription platform = new PlatformDescription();
platform.setName(rs.getPlatformName());
platform.setVersion((short) Integer.parseInt( (rs.getPlatformVersion().equals("")) ? "0" : rs.getPlatformVersion()) );
rt.newProfile();
rt.profile().category(rs.getCategory());
rt.profile().description(rs.getDescription());
rt.profile().newRuntime().ghnId(rs.getRuntimegHNUniqueID());
rt.profile().runtime().hostedOn(rs.getRuntimeHostedOn());
rt.profile().name(rs.getResourceName());
rt.profile().runtime().status(rs.getRuntimeStatus());
platform.setMinorVersion((short) Integer.parseInt( (rs.getPlatformMinorVersion().equals("")) ? "0" : rs.getPlatformMinorVersion()) );
platform.setRevisionVersion((short) Integer.parseInt( (rs.getPlatformRevisionVersion().equals("")) ? "0" : rs.getPlatformRevisionVersion()) );
platform.setBuildVersion((short) Integer.parseInt( (rs.getPlatformBuildVersion().equals("")) ? "0" : rs.getPlatformBuildVersion()) );
rt.setPlatform(platform);
rt.profile().newPlatform().name(rs.getPlatformName());
rt.profile().platform().version((short) Integer.parseInt( (rs.getPlatformVersion().equals("")) ? "0" : rs.getPlatformVersion()) );
rt.profile().platform().minorVersion((short) Integer.parseInt( (rs.getPlatformMinorVersion().equals("")) ? "0" : rs.getPlatformMinorVersion()) );
rt.profile().platform().revisionVersion((short) Integer.parseInt( (rs.getPlatformRevisionVersion().equals("")) ? "0" : rs.getPlatformRevisionVersion()) );
rt.profile().platform().buildVersion((short) Integer.parseInt( (rs.getPlatformBuildVersion().equals("")) ? "0" : rs.getPlatformBuildVersion()) );
ArrayList<RRAccessPoint> myAccessPoints = rs.getRRAccessPoints();
List<AccessPoint> accessPoints = new ArrayList<AccessPoint>();
for (RRAccessPoint p : myAccessPoints) {
AccessPoint a = new AccessPoint();
a.setEndpoint(p.getInterfaceEndPoint());
a.setEntryname(p.getInterfaceEntryNameAttr());
a.setDescription(p.getDesc());
a.address(p.getInterfaceEndPoint());
a.name(p.getInterfaceEntryNameAttr());
a.description(p.getDesc());
a.setUsername(p.getUsername());
a.setPassword(p.getPassword());
String encryptedPassword = StringEncrypter.getEncrypter().encrypt(p.getPassword());
a.credentials(encryptedPassword, p.getUsername());
for (Property prop : p.getProperties()) {
a.addProperty(prop.getKey(), prop.getValue(), prop.isCrypted());
String propValue = prop.isCrypted() ? StringEncrypter.getEncrypter().encrypt(prop.getValue()) : prop.getValue();
org.gcube.common.resources.gcore.ServiceEndpoint.Property pToAdd =
new org.gcube.common.resources.gcore.ServiceEndpoint.Property().nameAndValue(prop.getKey(), propValue);
pToAdd.encrypted(prop.isCrypted());
a.properties().add(pToAdd);
}
accessPoints.add(a);
rt.profile().accessPoints().add(a);
}
rt.setAccessPoints(accessPoints );
rt.addScope(GCUBEScope.getScope(scope));
ScopeProvider.instance.set(scope.toString());
RuntimeResourceManager gm = new RuntimeResourceManager();
RegistryPublisher publisher = gm.getRegistryPublisher();
ISPublisher publisher = GHNContext.getImplementation(ISPublisher.class);
if (! isUpdate) {
String xmlProfile = publisher.registerGCUBEResource(rt, GCUBEScope.getScope(scope), new GCUBESecurityManagerImpl() {
@Override
public boolean isSecurityEnabled() {
// TODO Auto-generated method stub
return false;
}
});
System.out.println("Created");
_log.trace("Created new RR sent, Got from publisher: \n" + xmlProfile);
String id = publisher.create(rt).id();
_log.trace("Created new RR sent, Got from publisher: id=" + id);
} else {
System.out.println("Updating " + rs.getResourceId());
for (String scope2Update: rt.getScopes().keySet()) {
GCUBEScope gScope = GCUBEScope.getScope(scope2Update);
ServiceMap map = loadServiceMap(scope2Update);
gScope.setServiceMap(map);
publisher.updateGCUBEResource(rt, gScope, new GCUBESecurityManagerImpl() {
@Override
public boolean isSecurityEnabled() {
return false;
}
});
for (String scope2Update: rt.scopes()) {
ScopeProvider.instance.set(scope2Update);
publisher.update(rt);
System.out.println("Updated " + rs.getResourceId() + " on " + scope2Update);
}
System.out.println("Updated " + rt.getID());
_log.trace("Updated RR sent, id: " + rt.getID());
_log.trace("Updated RR sent");
}
} catch (Throwable e) {
@ -181,6 +158,7 @@ public class RuntimeResourceCreatorServiceImpl extends RemoteServiceServlet impl
return false;
}
_log.info("Registration Request successfully Sent");
ScopeProvider.instance.set(currScope);
return result;
}
/**
@ -227,72 +205,62 @@ public class RuntimeResourceCreatorServiceImpl extends RemoteServiceServlet impl
}
private FilledRuntimeResource getResource2EditById(String id) {
GCUBEScope scope = null;
try {
ISClient client = GHNContext.getImplementation(ISClient.class);
GCUBERuntimeResourceQuery query = client.getQuery(GCUBERuntimeResourceQuery.class);
query.addAtomicConditions(new AtomicCondition("//ID", id));
scope = GCUBEScope.getScope(getASLSession().getScopeName());
GCUBERuntimeResource rRes = client.execute(query,scope).get(0); //only one rr per id
SimpleQuery query = queryFor(ServiceEndpoint.class);
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
query.addCondition("$resource/ID/text() eq '" + id + "'");
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(getASLSession().getScopeName());
List<ServiceEndpoint> resources = client.submit(query);
ScopeProvider.instance.set(currScope);
ServiceEndpoint sEndPoint = null;
try {
sEndPoint = resources.get(0);
} catch (IndexOutOfBoundsException e) {
return new FilledRuntimeResource();
}
ArrayList<RRAccessPoint> acPoints = new ArrayList<RRAccessPoint>();
for (AccessPoint ac : rRes.getAccessPoints()) {
for (AccessPoint ac : sEndPoint.profile().accessPoints()) {
RRAccessPoint rac = new RRAccessPoint();
rac.setInterfaceEndPoint(ac.getEndpoint());
rac.setInterfaceEntryNameAttr(ac.getEntryname());
rac.setDesc(ac.getDescription());
rac.setUsername(ac.getUsername());
rac.setPassword(ac.getPassword());
rac.setInterfaceEndPoint(ac.address());
rac.setInterfaceEntryNameAttr(ac.name());
rac.setDesc(ac.description());
rac.setUsername(ac.username());
String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ac.password());
rac.setPassword(decryptedPassword);
ArrayList<Property> props = new ArrayList<Property>();
for (String prop : ac.getAllPropertyNames()) {
String propValue = ac.getProperty(prop);
props.add(new Property(prop, propValue, ac.isPropertyEncrypted(prop)));
for (org.gcube.common.resources.gcore.ServiceEndpoint.Property prop : ac.properties()) {
String propDecValue = prop.isEncrypted() ? StringEncrypter.getEncrypter().decrypt(prop.value()) :prop.value();
props.add(new Property(prop.name(), propDecValue, prop.isEncrypted()));
}
rac.setProperties(props);
acPoints.add(rac);
}
return new FilledRuntimeResource(id, acPoints, rRes.getName(), rRes.getVersion(), rRes.getCategory(), rRes.getDescription(),
rRes.getPlatform().getName(), ""+rRes.getPlatform().getVersion(), ""+rRes.getPlatform().getMinorVersion(), ""+rRes.getPlatform().getRevisionVersion(),
""+rRes.getPlatform().getBuildVersion(), rRes.getHostedOn(), rRes.getStatus(), rRes.getGHN());
return new FilledRuntimeResource(
id,
acPoints,
sEndPoint.profile().name(),
sEndPoint.profile().version(),
sEndPoint.profile().category(),
sEndPoint.profile().description(),
sEndPoint.profile().platform().name(),
""+sEndPoint.profile().platform().version(),
""+sEndPoint.profile().platform().minorVersion(),
""+sEndPoint.profile().platform().revisionVersion(),
""+sEndPoint.profile().platform().buildVersion(),
sEndPoint.profile().runtime().hostedOn(),
sEndPoint.profile().runtime().status(),
sEndPoint.profile().runtime().ghnId());
}
catch (Exception e) {
e.printStackTrace();
return null;
return new FilledRuntimeResource();
}
}
/**
* NOT USED
*/
@Override
public ArrayList<Category> getCategories() {
Set<Category> mySet = new HashSet<Category>();
ArrayList<Category> toReturn = new ArrayList<Category>();
GCUBEScope scope = null;
scope = GCUBEScope.getScope(getASLSession().getScopeName());
ISClient client;
try {
_log.info("Fetching gCube Runtime resource categories into " + scope.getName());
client = GHNContext.getImplementation(ISClient.class);
GCUBERuntimeResourceQuery query = client.getQuery(GCUBERuntimeResourceQuery.class);
for (GCUBERuntimeResource rRes : client.execute(query,scope)) {
toReturn.add(new Category(rRes.getCategory()));
}
for (Category category : mySet) {
toReturn.add(category);
}
return toReturn;
} catch (Exception e) {
_log.error("Generic Exception for " + scope.getName() + " " + e.getMessage());
return null;
}
}
/**
*
* @return