Skip to content

Commit

Permalink
#128 re-integrate changes from #188 and #123
Browse files Browse the repository at this point in the history
  • Loading branch information
p-a-s-c-a-l committed Sep 3, 2018
1 parent 2663641 commit 537ac0c
Show file tree
Hide file tree
Showing 12 changed files with 1,071 additions and 167 deletions.
48 changes: 27 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@
<dependency>
<groupId>de.cismet.cids</groupId>
<artifactId>cids-server-rest-types</artifactId>
<version>6.0</version>
<!--
FIXME: replace with release version when action api enhancements have been merged!
-->
<version>6.1-SNAPSHOT</version>
</dependency>
<!-- END: managed cids-dependencies -->
</dependencies>
Expand Down Expand Up @@ -185,6 +188,26 @@
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-util</artifactId>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-lookup</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<!-- END: managed dependencies -->

Expand Down Expand Up @@ -218,31 +241,14 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5-20081211</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util</artifactId>
<version>RELEASE701</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!--
FIXME: add verion to managed dependencies or ext-bom
-->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-903.jdbc4</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-lookup</artifactId>
<version>RELEASE701</version>
</dependency>

<!-- BEGIN: Runtime dependencies -->
<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import Sirius.server.sql.DBConnectionPool;
import Sirius.server.sql.PreparableStatement;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import org.openide.util.Lookup;
Expand Down Expand Up @@ -83,9 +84,10 @@
import de.cismet.cids.utils.ClassloadingHelper;
import de.cismet.cids.utils.serverresources.ServerResourcesLoader;

import de.cismet.cidsx.server.actions.RestApiCidsServerAction;

import de.cismet.connectioncontext.ConnectionContext;
import de.cismet.connectioncontext.ConnectionContextStore;

/**
* DOCUMENT ME!
*
Expand Down Expand Up @@ -194,9 +196,23 @@ public DomainServerImpl(final ServerProperties properties) throws Throwable {
}
}

final Collection<? extends RestApiCidsServerAction> restServerActions = Lookup.getDefault()
.lookupAll(RestApiCidsServerAction.class);
final Collection<? extends ServerAction> serverActions = Lookup.getDefault().lookupAll(ServerAction.class);

for (final ServerAction restServerAction : restServerActions) {
if (logger.isDebugEnabled()) {
logger.debug("Adding REST API Server Action '" + restServerAction.getTaskName() + "'");
}
serverActionMap.put(restServerAction.getTaskName(), restServerAction);
}

for (final ServerAction serverAction : serverActions) {
serverActionMap.put(serverAction.getTaskName(), serverAction);
if (!serverActionMap.containsKey(serverAction.getTaskName())) {
logger.warn("Adding LEGACY Server Action '" + serverAction.getTaskName()
+ "' -> Change to RestApiCidsServerAction");
serverActionMap.put(serverAction.getTaskName(), serverAction);
}
}

MetaClassCache.getInstance().setAllClasses(dbServer.getClasses(), properties.getServerName());
Expand Down Expand Up @@ -1901,6 +1917,8 @@ public Object executeTask(final User user,
final Object body,
final ConnectionContext connectionContext,
final ServerActionParameter... params) throws RemoteException {
logger.info("executing task '" + taskname + "' with " + params.length
+ " server action parameters and body object: " + (body != null));
if (ConnectionContextBackend.getInstance().isEnabled()) {
ConnectionContextBackend.getInstance()
.log(ConnectionContextLog.createForTask(
Expand All @@ -1919,24 +1937,24 @@ public Object executeTask(final User user,
}
if (hasConfigAttr(user, SERVER_ACTION_PERMISSION_ATTRIBUTE_PREFIX + taskname, connectionContext)) {
final ServerAction serverAction = serverActionMap.get(taskname);
if (serverAction instanceof ConnectionContextStore) {
((ConnectionContextStore)serverAction).initWithConnectionContext(connectionContext);
}
if (serverAction != null) {
if (serverAction instanceof ConnectionContextStore) {
((ConnectionContextStore)serverAction).initWithConnectionContext(connectionContext);
}

if (serverAction instanceof MetaServiceStore) {
((MetaServiceStore)serverAction).setMetaService(this);
}
if (serverAction instanceof CatalogueServiceStore) {
((CatalogueServiceStore)serverAction).setCatalogueService(this);
}
if (serverAction instanceof UserServiceStore) {
((UserServiceStore)serverAction).setUserService(this);
}
if (serverAction instanceof Sirius.server.middleware.interfaces.domainserver.UserStore) {
((Sirius.server.middleware.interfaces.domainserver.UserStore)serverAction).setUser(user);
}
if (serverAction instanceof MetaServiceStore) {
((MetaServiceStore)serverAction).setMetaService(this);
}
if (serverAction instanceof CatalogueServiceStore) {
((CatalogueServiceStore)serverAction).setCatalogueService(this);
}
if (serverAction instanceof UserServiceStore) {
((UserServiceStore)serverAction).setUserService(this);
}
if (serverAction instanceof Sirius.server.middleware.interfaces.domainserver.UserStore) {
((Sirius.server.middleware.interfaces.domainserver.UserStore)serverAction).setUser(user);
}

if (serverAction != null) {
if (serverAction instanceof ScheduledServerAction) {
if (ScheduledServerActionManager.isScheduledServerActionFeatureSupported(
dbServer.getActiveDBConnection())) {
Expand All @@ -1957,15 +1975,24 @@ public Object executeTask(final User user,
"this server instance does not support scheduled server action feature"); // NOI18N
}
} else {
return serverAction.execute(body, params);
final long start = System.currentTimeMillis();
final Object result = serverAction.execute(body, params);
if (logger.isDebugEnabled()) {
logger.debug("Server Action '" + taskname + "' successfully executed in "
+ (System.currentTimeMillis() - start) + "ms.");
}
return result;
}
} else {
logger.warn("Server Action '" + taskname + "' not found! Returning null.");
return null;
}
} else {
throw new RemoteException("The user " + user
final String message = "The user " + user
+ "has no permission to execute this task. (Should have an action attribute like this: "
+ SERVER_ACTION_PERMISSION_ATTRIBUTE_PREFIX + taskname);
+ SERVER_ACTION_PERMISSION_ATTRIBUTE_PREFIX + taskname;
logger.error(message);
throw new RemoteException(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public Object executeTask(final User user,
final String taskdomain,
final Object body,
final ServerActionParameter... params) throws RemoteException {
if (LOG.isDebugEnabled()) {
LOG.debug("executing task '" + taskname + "' with " + params.length
+ " server action parameters and body object: " + (body != null)
+ " for user '" + user.getName() + "'");
}
return executeTask(user, taskname, taskdomain, body, ConnectionContext.createDeprecated(), params);
}

Expand All @@ -73,6 +78,12 @@ public Object executeTask(final User user,
final Object body,
final ConnectionContext context,
final ServerActionParameter... params) throws RemoteException {
if (LOG.isDebugEnabled()) {
LOG.debug("executing task '" + taskname + "' with " + params.length
+ " server action parameters and body object: " + (body != null)
+ " for user '" + user.getName() + "' and connection context category '"
+ context.getCategory().toString() + "'");
}
return ((Sirius.server.middleware.interfaces.domainserver.ActionService)activeLocalServers.get(taskdomain))
.executeTask(user, taskname, body, context, params);
}
Expand Down
102 changes: 69 additions & 33 deletions src/main/java/de/cismet/cids/server/actions/BandwidthTestAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
package de.cismet.cids.server.actions;

import Sirius.server.middleware.impls.domainserver.DomainServerImpl;
import Sirius.server.middleware.interfaces.domainserver.MetaService;
import Sirius.server.property.ServerProperties;

import de.cismet.cidsx.base.types.Type;

import de.cismet.cidsx.server.api.types.GenericResourceWithContentType;

/**
* DOCUMENT ME!
*
Expand All @@ -20,50 +23,83 @@
@org.openide.util.lookup.ServiceProvider(service = ServerAction.class)
public class BandwidthTestAction extends DownloadFileAction {

//~ Static fields/initializers ---------------------------------------------
//~ Constructors -----------------------------------------------------------

/**
* Creates a new BandwidthTestAction object.
*/
public BandwidthTestAction() {
super();

public static final String TASK_NAME = "bandwidthTest";
this.actionInfo.setActionKey("bandwidthTest");
this.actionInfo.setName("Bandwidth Test");
this.actionInfo.setDescription("Bandwidth Test");

this.actionInfo.getParameterDescription().get(0).setType(Type.INTEGER);
this.actionInfo.getParameterDescription().get(0).setKey("fileSizeInMb");
this.actionInfo.getParameterDescription().get(0).setDescription("Size of the test file in MB");

this.actionInfo.getBodyDescription().setType(Type.INTEGER);
this.actionInfo.getBodyDescription().setKey("fileSizeInMb");
this.actionInfo.getBodyDescription()
.setDescription("Deprecated, use 'fileSizeInMb' server action parameter instead");
}

//~ Methods ----------------------------------------------------------------

@Override
public String getTaskName() {
return TASK_NAME;
public final String getTaskName() {
return "bandwidthTest";
}

@Override
public Object execute(final Object body, final ServerActionParameter... params) {
if (body == null) {
throw new RuntimeException("The body is missing.");
} else if (!(body instanceof Integer)) {
throw new RuntimeException("Wrong type for body, have to be an Integer.");
} else {
final Integer fileSizeInMb = (Integer)body;

final ServerProperties serverProps = DomainServerImpl.getServerProperties();
final String serverRespath = serverProps.getServerResourcesBasePath();
final String s = serverProps.getFileSeparator();
final String filePath = "/bandwidthTest/" + fileSizeInMb.toString() + "MB.zip";
final Object ret;
if ("/".equals(s)) {
ret = super.execute(serverRespath + filePath);
} else {
ret = super.execute(serverRespath + filePath.replace("/", s));
public GenericResourceWithContentType execute(final Object body, final ServerActionParameter... params) {
int fileSizeInMb = -1;
if ((params != null) && (params.length > 0)) {
for (final ServerActionParameter sap : params) {
if (sap.getKey().equalsIgnoreCase("fileSizeInMb")) {
fileSizeInMb = Integer.valueOf(sap.getValue().toString());
break;
} else {
LOG.warn("unsupported server action parameter:" + sap.toString());
}
}
if (ret == null) {
throw new RuntimeException("Testfile not found.");
}

if (fileSizeInMb == -1) {
LOG.warn("client did not provide ServerActionParameter 'fileSizeInMb'");
if (body != null) {
fileSizeInMb = Integer.valueOf(body.toString());
final String message = "client provided 'fileSizeInMb' as server action "
+ "nor as body parameter!";
throw new RuntimeException(message);
}
return ret;
}
}

@Override
public MetaService getMetaService() {
return ms;
}
final ServerProperties serverProps = DomainServerImpl.getServerProperties();
final String serverRespath = serverProps.getServerResourcesBasePath();
final String s = serverProps.getFileSeparator();
final String filePath = "/bandwidthTest/" + fileSizeInMb + "MB.zip";
final GenericResourceWithContentType ret;
if ("/".equals(s)) {
final ServerActionParameter pathParameter = new ServerActionParameter(
PARAMETER_TYPE.FILEPATH.name(),
serverRespath
+ filePath);
ret = super.execute(null, pathParameter);
} else {
final ServerActionParameter pathParameter = new ServerActionParameter(
PARAMETER_TYPE.FILEPATH.name(),
serverRespath
+ filePath.replace("/", s));
ret = super.execute(null, pathParameter);
}
if (ret == null) {
final String message = "Testfile '" + serverRespath + "' not found.";
LOG.error(message);
throw new RuntimeException(message);
}

@Override
public void setMetaService(final MetaService service) {
ms = service;
return ret;
}
}
Loading

0 comments on commit 537ac0c

Please sign in to comment.