Skip to content

Commit

Permalink
Merge pull request #5616 from openmicroscopy/next_infra
Browse files Browse the repository at this point in the history
Re-integrate next_infra into develop
  • Loading branch information
joshmoore authored Jan 18, 2018
2 parents cdd5b36 + 2bfba62 commit 0901b07
Show file tree
Hide file tree
Showing 64 changed files with 1,724 additions and 1,345 deletions.
5 changes: 5 additions & 0 deletions components/blitz/resources/omero/Constants.ice
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ module omero {

};

/**
* Log levels used by {@link RawAccessRequest}'s {@code log} command for {@code path}.
**/
enum LogLevel { Trace, Debug, Info, Warn, Error };

/**
* Namespaces for the {@link omero.api.IMetadata} interface.
**/
Expand Down
1 change: 1 addition & 0 deletions components/blitz/resources/omero/Repositories.ice
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ module omero {
* testing and diagnosis rather than actual client
* functionality.
**/
["deprecate:Not intended for use by production clients. Functionality to be moved from Ice to microservices."]
class RawAccessRequest extends omero::cmd::Request {
string repoUuid;
string command;
Expand Down
5 changes: 1 addition & 4 deletions components/blitz/src/ome/formats/importer/ImportConfig.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/*
* $Id$
*
* Copyright 2009-2016 Glencoe Software, Inc. All rights reserved.
* Use is subject to license terms supplied in LICENSE.txt
*/

package ome.formats.importer;

import static omero.rtypes.rstring;

import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -348,6 +344,7 @@ public void configureDebug(String levelString) {
setLevel("ome.services.blitz", level);
setLevel("ome.system", level);
setLevel("loci", level);
setLevel("org.scijava.nativelib", level);
}

private void setLevel(String loggerName, Level level) {
Expand Down
9 changes: 8 additions & 1 deletion components/blitz/src/ome/formats/importer/ImportLibrary.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2016 University of Dundee & Open Microscopy Environment.
* Copyright (C) 2005-2018 University of Dundee & Open Microscopy Environment.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -496,6 +496,13 @@ public List<Pixels> importImage(final ImportContainer container, int index,
return Collections.emptyList();
}
}
final IObject target = container.getTarget();
if (target != null && !target.getDetails().getPermissions().canLink()) {
/* stop this import before file upload commences */
final String message = "Cannot link to target";
log.error(message);
throw new IllegalArgumentException(message);
}
final ImportProcessPrx proc = createImport(container);
final String[] srcFiles = container.getUsedFiles();
final List<String> checksums = new ArrayList<String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;

import Ice.Current;

import ome.io.nio.FileBuffer;
Expand All @@ -36,6 +39,7 @@
import omero.cmd.IRequest;
import omero.cmd.Response;
import omero.cmd.Unknown;
import omero.constants.LogLevel;
import omero.grid.InternalRepositoryPrx;
import omero.grid.RawAccessRequest;
import omero.grid.RepositoryException;
Expand All @@ -52,13 +56,24 @@ public class RawAccessRequestI extends RawAccessRequest implements IRequest {
private static final long serialVersionUID = -303948503984L;

private static Logger log = LoggerFactory.getLogger(RawAccessRequestI.class);
private static Logger logCmd = LoggerFactory.getLogger(log.getName() + " log cmd");

private static ImmutableMap<String, LogLevel> logLevels;

private final Registry reg;

protected Helper helper;

protected InternalRepositoryPrx repo;

static {
final ImmutableMap.Builder<String, LogLevel> builder = ImmutableMap.builder();
for (final LogLevel value : LogLevel.values()) {
builder.put(value.name().toLowerCase(), value);
}
logLevels = builder.build();
}

public RawAccessRequestI(Registry reg) {
this.reg = reg;
}
Expand Down Expand Up @@ -247,6 +262,31 @@ public void local(AbstractRepositoryI abstractRepositoryI,
throw new omero.ApiUsageException(null, null,
"Command: " + command + " takes just one argument");
}
} else if ("log".equals(command)) {
final LogLevel logLevel = path == null ? null : logLevels.get(path.toLowerCase());
if (logLevel == null) {
throw new omero.ApiUsageException(null, null,
"Command: " + command + " requires path value of: " + Joiner.on(", ").join(logLevels.keySet()));
}
for (final String arg : args) {
switch (logLevel) {
case Trace:
logCmd.trace(arg);
break;
case Debug:
logCmd.debug(arg);
break;
case Info:
logCmd.info(arg);
break;
case Warn:
logCmd.warn(arg);
break;
case Error:
logCmd.error(arg);
break;
}
}
} else {
throw new omero.ApiUsageException(null, null,
"Unknown command: " + command);
Expand Down
101 changes: 62 additions & 39 deletions components/blitz/src/omero/gateway/Gateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -85,7 +86,6 @@
import omero.gateway.util.PojoMapper;
import Glacier2.CannotCreateSessionException;
import Glacier2.PermissionDeniedException;
import Ice.ConnectionRefusedException;
import Ice.DNSException;
import Ice.SocketException;

Expand All @@ -101,7 +101,7 @@
* @since 5.1
*/

public class Gateway {
public class Gateway implements AutoCloseable {

/** Property to indicate that a {@link Connector} has been created */
public static final String PROP_CONNECTOR_CREATED = "PROP_CONNECTOR_CREATED";
Expand Down Expand Up @@ -141,7 +141,7 @@ public class Gateway {

/** Property to indicate that a stateless service has been created */
public static final String PROP_STATELESS_SERVICE_CREATED = "PROP_STATELESS_SERVICE_CREATED";

/** Reference to a {@link Logger} */
private Logger log;

Expand Down Expand Up @@ -179,7 +179,7 @@ public class Gateway {

/** Flag to indicate that executor threads should be shutdown on disconnect */
private boolean executorShutdownOnDisconnect = false;

/**
* Creates a new Gateway instance
* @param log A {@link Logger}
Expand Down Expand Up @@ -400,15 +400,15 @@ public boolean isConnected() {
* @param user
* The user to get the session ID for
* @return See above
* @throws DSOutOfServiceException
* If the connection is broken, or not logged in
*/
public String getSessionId(ExperimenterData user) {
try {
Connector c = getConnector(new SecurityContext(user.getGroupId()),
false, false);
if (c != null) {
return c.getClient().getSessionId();
}
} catch (DSOutOfServiceException e) {
public String getSessionId(ExperimenterData user)
throws DSOutOfServiceException {
Connector c = getConnector(new SecurityContext(user.getGroupId()),
false, false);
if (c != null) {
return c.getClient().getSessionId();
}
return null;
}
Expand Down Expand Up @@ -1030,38 +1030,35 @@ private client createSession(LoginCredentials c)
}
secureClient.setAgent(c.getApplicationName());
ServiceFactoryPrx entryEncrypted = null;
boolean session = false;
ServiceFactoryPrx guestSession = null;
try {
// Check if it is a session first
guestSession = secureClient.createSession("guest", "guest");
guestSession.getSessionService().getSession(username);
session = true;
} catch (Throwable e) {
// thrown if it is not a session, session has expired, or
// the guest login doesn't exist on the server
}
finally {
if (guestSession != null)
secureClient.closeSession();
}
try {
if (session) {

boolean connected = false;
if (isSessionID(username)) {
try {
entryEncrypted = secureClient.joinSession(username);
} else {
connected = true;
} catch (Exception e) {
// Although username looks like a session ID it apparently isn't
// one.
log.warn(this, new LogMessage("Could not join session "
+ username + " , trying username/password login next.",
e));
}
}
if (!connected) {
try {
if (args != null) {
entryEncrypted = secureClient.createSession();
} else {
entryEncrypted = secureClient.createSession(c.getUser()
.getUsername(), c.getUser().getPassword());
}
} catch (Exception e1) {
// close the session again before passing on the exception
secureClient.closeSession();
throw e1;
}
}
catch (Exception e1) {
// close the session again before passing on the exception
secureClient.closeSession();
throw e1;
}

this.pcs.firePropertyChange(PROP_SESSION_CREATED, null,
secureClient.getSessionId());
serverVersion = entryEncrypted.getConfigService().getVersion();
Expand Down Expand Up @@ -1099,6 +1096,23 @@ public void run() {
return secureClient;
}

/**
* Checks if a String could be an ICE session ID.
*
* @param s
* The String to check
* @return <code>true</code> if it could be a session ID, <code>false</code>
* otherwise.
*/
private boolean isSessionID(String s) {
try {
UUID.fromString(s);
} catch (Exception e) {
return false;
}
return true;
}

/**
* Logs in a certain user
*
Expand Down Expand Up @@ -1220,7 +1234,9 @@ private void keepSessionAlive() throws DSOutOfServiceException {
c = i.next();
if (c.needsKeepAlive()) {
if (!c.keepSessionAlive()) {
throw new DSOutOfServiceException("Network not available");
// Session has died, e. g. due to server restart.
// Remove connectors, so new ones will be created as requested.
groupConnectorMap.removeAll(c.getGroupID());
}
}
}
Expand Down Expand Up @@ -1503,9 +1519,10 @@ public Connector getConnector(SecurityContext ctx, boolean recreate,
ConnectionStatus.NETWORK);
}
if (!c.keepSessionAlive()) {
throw new DSOutOfServiceException(
"Network down. Session not alive",
ConnectionStatus.LOST_CONNECTION);
// Session has died, e. g. due to server restart.
// Remove connectors, so a new ones will be created.
groupConnectorMap.removeAll(c.getGroupID());
c = null;
}
}
}
Expand Down Expand Up @@ -1640,4 +1657,10 @@ private Connector createConnector(SecurityContext ctx, boolean permitNull)
}
return c;
}

@Override
public void close() throws Exception {
if (connected)
disconnect();
}
}
69 changes: 69 additions & 0 deletions components/blitz/src/omero/gateway/JoinSessionCredentials.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
*------------------------------------------------------------------------------
* Copyright (C) 2017 University of Dundee. All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*------------------------------------------------------------------------------
*/
package omero.gateway;

import java.util.UUID;

/**
* Holds all necessary information needed for joining an active OMERO server
* session
*
* @author Dominik Lindner &nbsp;&nbsp;&nbsp;&nbsp; <a
* href="mailto:d.lindner@dundee.ac.uk">d.lindner@dundee.ac.uk</a>
*/
public class JoinSessionCredentials extends LoginCredentials {

/**
* Creates a new instance
*
* @param sessionId
* The session ID
* @param host
* The server hostname
*/
public JoinSessionCredentials(String sessionId, String host) {
// simply set the session ID as username, everything else is
// handled in Gateway.createSession(LoginCredentials)
super(sessionId, "", host);

// Check that the sessionId is an UUID
UUID.fromString(sessionId);
}

/**
* Creates a new instance
*
* @param sessionId
* The session ID
* @param host
* The server hostname
* @param port
* The server port
*/
public JoinSessionCredentials(String sessionId, String host, int port) {
// simply set the session ID as username, everything else is
// handled in Gateway.createSession(LoginCredentials)
super(sessionId, "", host, port);

// Check that the sessionId is an UUID
UUID.fromString(sessionId);
}
}
Loading

0 comments on commit 0901b07

Please sign in to comment.