Commit cdaa3e66 authored by legoc's avatar legoc
Browse files

Implemented the check of client (TOKEN_NOT_OWNED error)

parent 2553e6d4
......@@ -61,7 +61,7 @@
<dependency>
<groupId>fr.ill.ics</groupId>
<artifactId>nomadcommandsystem-messages</artifactId>
<version>0.0.3</version>
<version>0.0.9</version>
</dependency>
<dependency>
<groupId>fr.ill.ics</groupId>
......
......@@ -198,7 +198,10 @@ public class CommandZoneAccessor {
}
else if (type == Common.Error.Type.NO_SUCH_PROPERTY) {
LOGGER.log(Level.SEVERE, "NoSuchPropertyException occured for command box " + containerID);
}
}
else if (type == Common.Error.Type.TOKEN_NOT_OWNED) {
LOGGER.log(Level.SEVERE, "token is not owned");
}
}
private int getClientID() {
......
......@@ -20,6 +20,8 @@ package fr.ill.ics.nscclient.commandline;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.protobuf.InvalidProtocolBufferException;
......@@ -27,10 +29,13 @@ import fr.ill.ics.cameo.Application;
import fr.ill.ics.cameo.RequesterCreationException;
import fr.ill.ics.nomadserver.commandline.CommandLineRequest;
import fr.ill.ics.nomadserver.common.Common;
import fr.ill.ics.nscclient.command.CommandZoneAccessor;
import fr.ill.ics.nscclient.serverconnection.ServerInstance;
import fr.ill.ics.nscclient.sessionmanagement.SessionManager;
public class CommandLineAccessor {
private static final Logger LOGGER = Logger.getLogger(CommandLineAccessor.class.getName());
private static Map<String, CommandLineAccessor> instances = new HashMap<String, CommandLineAccessor>();
......@@ -99,6 +104,7 @@ public class CommandLineAccessor {
// Create the request.
CommandLineRequest.CommandRequest request = CommandLineRequest.CommandRequest.newBuilder()
.setClientID(getClientID())
.setText(text)
.build();
......@@ -106,6 +112,11 @@ public class CommandLineAccessor {
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandLineRequester.receive());
// Test the error.
if (response.hasError()) {
LOGGER.log(Level.SEVERE, "error in executeCommand");
}
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of executeCommand");
......@@ -120,13 +131,19 @@ public class CommandLineAccessor {
.build();
// Create the request.
CommandLineRequest.EmptyRequest request = CommandLineRequest.EmptyRequest.newBuilder()
CommandLineRequest.CommandRequest request = CommandLineRequest.CommandRequest.newBuilder()
.setClientID(getClientID())
.build();
commandLineRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandLineRequester.receive());
// Test the error.
if (response.hasError()) {
LOGGER.log(Level.SEVERE, "error in executeCommand");
}
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of pauseCommands");
......@@ -141,13 +158,19 @@ public class CommandLineAccessor {
.build();
// Create the request.
CommandLineRequest.EmptyRequest request = CommandLineRequest.EmptyRequest.newBuilder()
CommandLineRequest.CommandRequest request = CommandLineRequest.CommandRequest.newBuilder()
.setClientID(getClientID())
.build();
commandLineRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandLineRequester.receive());
// Test the error.
if (response.hasError()) {
LOGGER.log(Level.SEVERE, "error in executeCommand");
}
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of restartCommands");
......@@ -162,13 +185,19 @@ public class CommandLineAccessor {
.build();
// Create the request.
CommandLineRequest.EmptyRequest request = CommandLineRequest.EmptyRequest.newBuilder()
CommandLineRequest.CommandRequest request = CommandLineRequest.CommandRequest.newBuilder()
.setClientID(getClientID())
.build();
commandLineRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandLineRequester.receive());
// Test the error.
if (response.hasError()) {
LOGGER.log(Level.SEVERE, "error in executeCommand");
}
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of stopCommands");
......@@ -183,13 +212,19 @@ public class CommandLineAccessor {
.build();
// Create the request.
CommandLineRequest.EmptyRequest request = CommandLineRequest.EmptyRequest.newBuilder()
CommandLineRequest.CommandRequest request = CommandLineRequest.CommandRequest.newBuilder()
.setClientID(getClientID())
.build();
commandLineRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandLineRequester.receive());
// Test the error.
if (response.hasError()) {
LOGGER.log(Level.SEVERE, "error in executeCommand");
}
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of stopAtEndCommands");
......@@ -255,6 +290,7 @@ public class CommandLineAccessor {
// Create the request.
CommandLineRequest.CommandLineStateRequest request = CommandLineRequest.CommandLineStateRequest.newBuilder()
.setClientID(getClientID())
.setState(state)
.build();
......@@ -262,6 +298,11 @@ public class CommandLineAccessor {
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandLineRequester.receive());
// Test the error.
if (response.hasError()) {
LOGGER.log(Level.SEVERE, "error in executeCommand");
}
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of setCommandLineState");
......
......@@ -32,12 +32,14 @@ import fr.ill.ics.nomadserver.common.Common;
import fr.ill.ics.nomadserver.common.Common.Error.Type;
import fr.ill.ics.nomadserver.condition.ConditionManagerRequest;
import fr.ill.ics.nscclient.serverconnection.ServerInstance;
import fr.ill.ics.nscclient.sessionmanagement.SessionManager;
public class ConditionManagerAccessor {
private static final Logger LOGGER = Logger.getLogger(ConditionManagerAccessor.class.getName());
private String serverId;
private Integer clientId;
private Application.Requester conditionManagerRequester;
private static Map<String, ConditionManagerAccessor> instances = new HashMap<String, ConditionManagerAccessor>();
......@@ -101,6 +103,15 @@ public class ConditionManagerAccessor {
conditionManagerRequester.terminate();
}
private int getClientID() {
if (clientId == null) {
// Get the client id from the session manager.
clientId = SessionManager.getInstance(serverId).getClientId();
}
return clientId;
}
private void processError(Common.ConditionResponse response) throws ConditionExistsException, NoSuchConditionException, InvalidExpressionException, UnremovableConditionException, UnrenamableConditionException {
......@@ -125,6 +136,9 @@ public class ConditionManagerAccessor {
else if (error == Type.UNRENAMABLE_CONDITION) {
throw new UnrenamableConditionException();
}
else if (error == Type.TOKEN_NOT_OWNED) {
LOGGER.log(Level.SEVERE, "error while editing conditions: token is not owned");
}
}
public synchronized void verifyExpression(String expression) throws InvalidExpressionException, ConditionExistsException, NoSuchConditionException, UnremovableConditionException, UnrenamableConditionException {
......@@ -161,6 +175,7 @@ public class ConditionManagerAccessor {
// Create the request.
ConditionManagerRequest.AddAlarmRequest request = ConditionManagerRequest.AddAlarmRequest.newBuilder()
.setClientID(getClientID())
.setName(name)
.setExpression(expression)
.setMessage(message)
......@@ -193,6 +208,7 @@ public class ConditionManagerAccessor {
// Create the request.
ConditionManagerRequest.AddWarningRequest request = ConditionManagerRequest.AddWarningRequest.newBuilder()
.setClientID(getClientID())
.setName(name)
.setExpression(expression)
.setMessage(message)
......@@ -223,6 +239,7 @@ public class ConditionManagerAccessor {
// Create the request.
ConditionManagerRequest.AddWatchdogRequest request = ConditionManagerRequest.AddWatchdogRequest.newBuilder()
.setClientID(getClientID())
.setName(name)
.setExpression(expression)
.setOn(on)
......@@ -251,6 +268,7 @@ public class ConditionManagerAccessor {
// Create the request.
ConditionManagerRequest.RemoveConditionRequest request = ConditionManagerRequest.RemoveConditionRequest.newBuilder()
.setClientID(getClientID())
.setConditionId(conditionId)
.build();
......@@ -276,6 +294,7 @@ public class ConditionManagerAccessor {
// Create the request.
ConditionManagerRequest.SetConditionOnRequest request = ConditionManagerRequest.SetConditionOnRequest.newBuilder()
.setClientID(getClientID())
.setConditionId(conditionId)
.setValue(value)
.build();
......@@ -302,6 +321,7 @@ public class ConditionManagerAccessor {
// Create the request.
ConditionManagerRequest.RenameConditionRequest request = ConditionManagerRequest.RenameConditionRequest.newBuilder()
.setClientID(getClientID())
.setConditionId(conditionId)
.setNewName(newName)
.build();
......@@ -328,6 +348,7 @@ public class ConditionManagerAccessor {
// Create the request.
ConditionManagerRequest.EditAlarmRequest request = ConditionManagerRequest.EditAlarmRequest.newBuilder()
.setClientID(getClientID())
.setConditionId(conditionId)
.setExpression(expression)
.setMessage(message)
......@@ -359,6 +380,7 @@ public class ConditionManagerAccessor {
// Create the request.
ConditionManagerRequest.EditWarningRequest request = ConditionManagerRequest.EditWarningRequest.newBuilder()
.setClientID(getClientID())
.setConditionId(conditionId)
.setExpression(expression)
.setMessage(message)
......@@ -388,6 +410,7 @@ public class ConditionManagerAccessor {
// Create the request.
ConditionManagerRequest.EditWatchdogRequest request = ConditionManagerRequest.EditWatchdogRequest.newBuilder()
.setClientID(getClientID())
.setConditionId(conditionId)
.setExpression(expression)
.setActions(actions)
......@@ -415,6 +438,7 @@ public class ConditionManagerAccessor {
// Create the request.
ConditionManagerRequest.EditCommandZoneTerminationRequest request = ConditionManagerRequest.EditCommandZoneTerminationRequest.newBuilder()
.setClientID(getClientID())
.setMessage(message)
.setMailRecipients(mailRecipients)
.setSmsNumber(smsNumber)
......
......@@ -35,6 +35,7 @@ import fr.ill.ics.nscclient.dataprovider.PortableByteArray.SizeException;
import fr.ill.ics.nscclient.dataprovider.PortableByteArray.TypeException;
import fr.ill.ics.nscclient.servant.Servant.UnknownCommandException;
import fr.ill.ics.nscclient.serverconnection.ServerInstance;
import fr.ill.ics.nscclient.sessionmanagement.SessionManager;
public class DataAccessor {
......@@ -47,6 +48,7 @@ public class DataAccessor {
public enum ClientTokenState {FREE, OWNED};
private String serverId;
private Integer clientId;
private Application.Requester databaseRequester;
private static Map<String, DataAccessor> instances = new HashMap<String, DataAccessor>();
......@@ -93,6 +95,16 @@ public class DataAccessor {
databaseRequester.terminate();
}
private int getClientID() {
if (clientId == null) {
// Get the client id from the session manager.
clientId = SessionManager.getInstance(serverId).getClientId();
}
return clientId;
}
private void logError(String methodName, Common.Error.Type error, int id) {
if (error == Common.Error.Type.NO_SUCH_PROPERTY) {
......@@ -104,6 +116,9 @@ public class DataAccessor {
else if (error == Common.Error.Type.NO_SUCH_COMMAND) {
LOGGER.logp(Level.SEVERE, this.getClass().getName(), methodName, "UnknownCommand with ID " + id);
}
else if (error == Common.Error.Type.TOKEN_NOT_OWNED) {
LOGGER.logp(Level.SEVERE, this.getClass().getName(), methodName, "Token not owned for processing ID " + id);
}
}
public synchronized int getInt32Value(int databaseID, int propertyID) {
......@@ -148,6 +163,7 @@ public class DataAccessor {
// Create the request.
DatabaseRequest.SetInt32ValueRequest request = DatabaseRequest.SetInt32ValueRequest.newBuilder()
.setClientID(getClientID())
.setDatabaseID(databaseID)
.setPropertyID(propertyID)
.setValue(value)
......@@ -215,6 +231,7 @@ public class DataAccessor {
// Create the request.
DatabaseRequest.SetInt64ValueRequest request = DatabaseRequest.SetInt64ValueRequest.newBuilder()
.setClientID(getClientID())
.setDatabaseID(databaseID)
.setPropertyID(propertyID)
.setValue(value)
......@@ -283,6 +300,7 @@ public class DataAccessor {
// Create the request.
DatabaseRequest.SetFloat32ValueRequest request = DatabaseRequest.SetFloat32ValueRequest.newBuilder()
.setClientID(getClientID())
.setDatabaseID(databaseID)
.setPropertyID(propertyID)
.setValue(value)
......@@ -350,6 +368,7 @@ public class DataAccessor {
// Create the request.
DatabaseRequest.SetFloat64ValueRequest request = DatabaseRequest.SetFloat64ValueRequest.newBuilder()
.setClientID(getClientID())
.setDatabaseID(databaseID)
.setPropertyID(propertyID)
.setValue(value)
......@@ -417,6 +436,7 @@ public class DataAccessor {
// Create the request.
DatabaseRequest.SetStringValueRequest request = DatabaseRequest.SetStringValueRequest.newBuilder()
.setClientID(getClientID())
.setDatabaseID(databaseID)
.setPropertyID(propertyID)
.setValue(value)
......@@ -484,6 +504,7 @@ public class DataAccessor {
// Create the request.
DatabaseRequest.SetBooleanValueRequest request = DatabaseRequest.SetBooleanValueRequest.newBuilder()
.setClientID(getClientID())
.setDatabaseID(databaseID)
.setPropertyID(propertyID)
.setValue(value)
......@@ -649,7 +670,7 @@ public class DataAccessor {
.build();
// Create the request.
DatabaseRequest.CommandRequest request = DatabaseRequest.CommandRequest.newBuilder()
DatabaseRequest.GetCommandRequest request = DatabaseRequest.GetCommandRequest.newBuilder()
.setDatabaseID(databaseID)
.setCommandID(commandID)
.build();
......@@ -708,7 +729,7 @@ public class DataAccessor {
.build();
// Create the request.
DatabaseRequest.CommandRequest request = DatabaseRequest.CommandRequest.newBuilder()
DatabaseRequest.GetCommandRequest request = DatabaseRequest.GetCommandRequest.newBuilder()
.setDatabaseID(databaseID)
.setCommandID(commandID)
.build();
......@@ -743,6 +764,7 @@ public class DataAccessor {
// Create the request.
DatabaseRequest.CommandRequest request = DatabaseRequest.CommandRequest.newBuilder()
.setClientID(getClientID())
.setDatabaseID(databaseID)
.setCommandID(commandID)
.build();
......@@ -771,6 +793,7 @@ public class DataAccessor {
// Create the request.
DatabaseRequest.CommandRequest request = DatabaseRequest.CommandRequest.newBuilder()
.setClientID(getClientID())
.setDatabaseID(databaseID)
.setCommandID(commandID)
.build();
......
......@@ -60,6 +60,7 @@ import fr.ill.ics.nscclient.servant.Servant;
import fr.ill.ics.nscclient.servant.SpyPropertyDescriptor;
import fr.ill.ics.nscclient.servant.StandardPropertyDescriptor;
import fr.ill.ics.nscclient.serverconnection.ServerInstance;
import fr.ill.ics.nscclient.sessionmanagement.SessionManager;
public class ServantManagerAccessor {
......@@ -75,6 +76,7 @@ public class ServantManagerAccessor {
private final static String PARAMETERIZABLE_SCAN_1D = "parameterizable_scan_1d";
private String serverId;
private Integer clientId;
private Application.Requester servantManagerRequester;
private static Map<String, ServantManagerAccessor> instances = new HashMap<String, ServantManagerAccessor>();
......@@ -124,12 +126,25 @@ public class ServantManagerAccessor {
// Terminate the requester.
servantManagerRequester.terminate();
}
private int getClientID() {
if (clientId == null) {
// Get the client id from the session manager.
clientId = SessionManager.getInstance(serverId).getClientId();
}
return clientId;
}
private void logError(String methodName, Common.Error.Type error, int id) {
if (error == Common.Error.Type.NO_SUCH_SERVANT) {
LOGGER.logp(Level.SEVERE, this.getClass().getName(), methodName, "UnknownServant with ID " + id);
}
else if (error == Common.Error.Type.TOKEN_NOT_OWNED) {
LOGGER.logp(Level.SEVERE, this.getClass().getName(), methodName, "Token not owned when processing ID " + id);
}
}
private ServantData getWholeConfiguration(int databaseID) throws LoadConfigurationFailure {
......@@ -301,7 +316,8 @@ public class ServantManagerAccessor {
.build();
// Create the request.
ServantManagerRequest.ServantRequest request = ServantManagerRequest.ServantRequest.newBuilder()
ServantManagerRequest.ModifyServantRequest request = ServantManagerRequest.ModifyServantRequest.newBuilder()
.setClientID(getClientID())
.setDatabaseID(0)
.setServantID(servantID)
.build();
......@@ -707,6 +723,7 @@ public class ServantManagerAccessor {
// Create the request.
ServantManagerRequest.PauseSpiesRequest request = ServantManagerRequest.PauseSpiesRequest.newBuilder()
.setClientID(getClientID())
.setIsPaused(isPaused)
.build();
......@@ -714,6 +731,11 @@ public class ServantManagerAccessor {
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(servantManagerRequester.receive());
// Test the error.
if (response.hasError()) {
logError("pauseSpies", response.getError(), 0);
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "pauseSpies", "error in parsing response");
......@@ -744,7 +766,8 @@ public class ServantManagerAccessor {
.build();
// Create the request.
ServantManagerRequest.ServantRequest request = ServantManagerRequest.ServantRequest.newBuilder()
ServantManagerRequest.ModifyServantRequest request = ServantManagerRequest.ModifyServantRequest.newBuilder()
.setClientID(getClientID())
.setDatabaseID(0)
.setServantID(servantID)
.build();
......
......@@ -32,6 +32,7 @@ import fr.ill.ics.nomadserver.common.Common;
import fr.ill.ics.nomadserver.common.Common.Error.Type;
import fr.ill.ics.nomadserver.variable.VariableManagerRequest;
import fr.ill.ics.nscclient.serverconnection.ServerInstance;
import fr.ill.ics.nscclient.sessionmanagement.SessionManager;
/**
*
......@@ -43,6 +44,7 @@ public class VariableManagerAccessor {
private static final Logger LOGGER = Logger.getLogger(VariableManagerAccessor.class.getName());
private String serverId;
private Integer clientId;
private Application.Requester variableManagerRequester;
private static Map<String, VariableManagerAccessor> instances = new HashMap<String, VariableManagerAccessor>();
......@@ -123,6 +125,16 @@ public class VariableManagerAccessor {
variableManagerRequester.terminate();
}
private int getClientID() {
if (clientId == null) {
// Get the client id from the session manager.
clientId = SessionManager.getInstance(serverId).getClientId();
}
return clientId;
}
private void processError(Common.VariableResponse response) throws VariableExistsException, NoSuchVariableException, InvalidExpressionException, UnremovableVariableException, DisabledVariableWarning {
if (!response.hasError()) {
......@@ -146,6 +158,9 @@ public class VariableManagerAccessor {
else if (error == Type.DISABLED_VARIABLE) {
throw new DisabledVariableWarning(response.getMessage());
}
else if (error == Type.TOKEN_NOT_OWNED) {
LOGGER.log(Level.SEVERE, "token not owned");
}
}
public synchronized String getVariablesXMLContent() {
......@@ -208,6 +223,7 @@ public class VariableManagerAccessor {
// Create the request.
VariableManagerRequest.AddVariableRequest request = VariableManagerRequest.AddVariableRequest.newBuilder()
.setClientID(getClientID())
.setName(name)
.setExpression(expression)
.build();
......@@ -234,6 +250,7 @@ public class VariableManagerAccessor {
// Create the request.
VariableManagerRequest.EditVariableRequest request = VariableManagerRequest.EditVariableRequest.newBuilder()
.setClientID(getClientID())
.setName(name)
.setExpression(expression)
.build();
......@@ -260,6 +277,7 @@ public class VariableManagerAccessor {
// Create the request.
VariableManagerRequest.RemoveVariableRequest request = VariableManagerRequest.RemoveVariableRequest.newBuilder()
.setClientID(getClientID())
.setName(name)
.build();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment