Skip to content

Commit

Permalink
#188 re-integrate action api enhancements from #123
Browse files Browse the repository at this point in the history
  • Loading branch information
p-a-s-c-a-l committed Aug 30, 2018
1 parent 2663641 commit 15243c6
Show file tree
Hide file tree
Showing 12 changed files with 1,050 additions and 142 deletions.
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 @@ -77,6 +78,7 @@
import de.cismet.cids.server.actions.ServerActionParameter;
import de.cismet.cids.server.connectioncontext.ConnectionContextBackend;
import de.cismet.cids.server.connectioncontext.ConnectionContextLog;
import de.cismet.cids.server.search.CidsServerSearch;
import de.cismet.cids.server.search.QueryPostProcessor;
import de.cismet.cids.server.ws.rest.RESTfulService;

Expand All @@ -85,6 +87,8 @@

import de.cismet.connectioncontext.ConnectionContext;
import de.cismet.connectioncontext.ConnectionContextStore;
import de.cismet.cidsx.server.actions.RestApiCidsServerAction;
import de.cismet.cidsx.server.search.RestApiCidsServerSearch;

/**
* DOCUMENT ME!
Expand Down Expand Up @@ -193,10 +197,24 @@ public DomainServerImpl(final ServerProperties properties) throws Throwable {
ex);
}
}
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 @@ -1892,6 +1910,8 @@ public Object executeTask(final User user,
final String taskname,
final Object body,
final ServerActionParameter... params) throws RemoteException {
logger.info("executing task '" + taskname + "' with " + params.length
+ " server action parameters and body object: " + (body != null));
return executeTask(user, taskname, body, ConnectionContext.createDeprecated(), params);
}

Expand Down Expand Up @@ -1923,20 +1943,20 @@ public Object executeTask(final User user,
((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 != null) {
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 ScheduledServerAction) {
if (ScheduledServerActionManager.isScheduledServerActionFeatureSupported(
dbServer.getActiveDBConnection())) {
Expand All @@ -1957,15 +1977,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 @@ -73,6 +73,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() + "'");
}

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
* ... and it just works.
*
****************************************************/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package de.cismet.cids.server.actions;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Loading

0 comments on commit 15243c6

Please sign in to comment.