If you are using GitLab outside of the ILL, then you will need to use HTTPS and not SSH for clone/push/pull operations. SSH will work normally if you are using the VPN.

Commit e95140f0 authored by ics's avatar ics

Synchronise list of users' scripts and settings files between Nomad

clients
parent 5d885f2a
......@@ -21,6 +21,7 @@ package fr.ill.ics.bridge;
import java.util.HashMap;
import fr.ill.ics.nscclient.command.CommandZoneAccessor;
import fr.ill.ics.nscclient.dataprovider.ServantManagerAccessor;
import fr.ill.ics.nscclient.servant.ResourceNotFoundException;
......@@ -30,6 +31,9 @@ public class ResourceManager {
public final static String NAME = "name";
public final static String ISDIRECTORY = "isDirectory";
public final static String CHILDREN = "children";
public final static int SCRIPT_FILE = 0;
public final static int SETTINGS_FILE = 1;
private String serverId;
......@@ -90,23 +94,26 @@ public class ResourceManager {
}
public void saveFile(String fileName, String content) {
ServantManagerAccessor.getInstance(serverId).saveFile(fileName, content);
public void saveFile(String fileName, String content, int fileType) {
CommandZoneAccessor.getInstance(serverId).saveFile(fileName, content, fileType);
}
public String getFileContent(String fileName) throws ResourceNotFoundException {
return ServantManagerAccessor.getInstance(serverId).getFileContent(fileName);
return CommandZoneAccessor.getInstance(serverId).getFileContent(fileName);
}
public String getTree(String rootDirectory, String extension) {
return ServantManagerAccessor.getInstance(serverId).getTree(rootDirectory, extension);
return CommandZoneAccessor.getInstance(serverId).getTree(rootDirectory, extension);
}
public void deleteFile(String fileName) {
ServantManagerAccessor.getInstance(serverId).deleteFile(fileName);
System.out.println("Asked to delete " + fileName);
CommandZoneAccessor.getInstance(serverId).deleteFile(fileName);
}
......
......@@ -235,9 +235,19 @@ public class PropertyManager {
}
ConfigManager.getInstance().initControllerProperties(controllerType);
/*
* OK for not multi client and for spies
* */
clientFilesFoundPerControllerType.put(controllerType, true);
return true;
/*
System.err.println("Warning: Fix the problem in PropertyManager !!!");
// OK for multiclient but not for spies
clientFilesFoundPerControllerType.put(controllerType, !(files == null || files.length == 0));
return clientFilesFoundPerControllerType.get(controllerType);
*/
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -1026,108 +1026,4 @@ public class ServantManagerAccessor {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "logUserMessage", "error in parsing response");
}
}
public void saveFile(String fileName, String content) {
// Create the message type.
ServantManagerRequest.Message type = ServantManagerRequest.Message.newBuilder()
.setType(ServantManagerRequest.Message.Type.SaveFile)
.build();
// Create the request.
ServantManagerRequest.SaveFileRequest request = ServantManagerRequest.SaveFileRequest.newBuilder()
.setFileName(fileName)
.setContent(content)
.build();
servantManagerRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse.parseFrom(servantManagerRequester.receive());
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "saveFile", "error in parsing response");
}
}
public String getFileContent(String fileName) throws ResourceNotFoundException {
// Create the message type.
ServantManagerRequest.Message type = ServantManagerRequest.Message.newBuilder()
.setType(ServantManagerRequest.Message.Type.GetFileContent)
.build();
// Create the request.
ServantManagerRequest.GetFileContentRequest request = ServantManagerRequest.GetFileContentRequest.newBuilder()
.setFileName(fileName)
.build();
servantManagerRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.StringResponse response = Common.StringResponse.parseFrom(servantManagerRequester.receive());
if (response.hasError()) {
throw new ResourceNotFoundException(fileName);
}
return response.getValue();
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getFileContent", "error in parsing response");
}
throw new ResourceNotFoundException(fileName);
}
public String getTree(String rootDirectory, String extension) {
// Create the message type.
ServantManagerRequest.Message type = ServantManagerRequest.Message.newBuilder()
.setType(ServantManagerRequest.Message.Type.GetTree)
.build();
// Create the request.
ServantManagerRequest.GetTreeRequest request = ServantManagerRequest.GetTreeRequest.newBuilder()
.setRootDirectory(rootDirectory)
.setExtension(extension)
.build();
servantManagerRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.StringResponse response = Common.StringResponse.parseFrom(servantManagerRequester.receive());
return response.getValue();
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getTree", "error in parsing response");
}
return "";
}
public void deleteFile(String fileName) {
// Create the message type.
ServantManagerRequest.Message type = ServantManagerRequest.Message.newBuilder()
.setType(ServantManagerRequest.Message.Type.DeleteFile)
.build();
// Create the request.
ServantManagerRequest.DeleteFileRequest request = ServantManagerRequest.DeleteFileRequest.newBuilder()
.setFileName(fileName)
.build();
servantManagerRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse.parseFrom(servantManagerRequester.receive());
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "deleteFile", "error in parsing response");
}
}
}
\ No newline at end of file
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.nscclient.notification.commandzone.sync;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* This class is used to synchronise list of users' scripts and settings files between Nomad clients.
*
* @author ortizh
*/
public class CommandZoneFileSync {
private static CommandZoneFileSync instance;
private List<INewScanListener> newScanListeners;
private List<INewSettingsFileListener> newSettingsFileListeners;
public static CommandZoneFileSync getInstance() {
if (instance == null) {
instance = new CommandZoneFileSync();
}
return instance;
}
/**
* <p>Adds a new INewScanListener to the list of listeners.
* If the listener already exists then ignor.
* @param INewScanListener a new listener
*/
public void addNewScanListener(INewScanListener newScanFileListener) {
if (newScanListeners == null) {
this.newScanListeners = new ArrayList<INewScanListener>(2);
}
synchronized (newScanListeners) {
if (!newScanListeners.contains(newScanFileListener)) {
newScanListeners.add(newScanFileListener);
}
}
}
/**
* <p>Removes a INewScanListener.
* <br>If the listener does not exist in the list of listeners then ignor it.
*/
public void removeNewScanListener(INewScanListener newScanFileListener) {
if (newScanListeners != null) {
synchronized (newScanListeners) {
if (newScanListeners.contains(newScanFileListener)) {
newScanListeners.remove(newScanFileListener);
}
if (newScanListeners.isEmpty()) {
newScanListeners = null;
}
}
}
}
/**
* Notifies listeners that a new scan has been created.
*/
public void notifyNewScanListeners(String scanName) {
if (newScanListeners != null) {
synchronized (newScanListeners) {
Iterator<INewScanListener> listenerIterator = newScanListeners.iterator();
while (listenerIterator.hasNext()) {
listenerIterator.next().newScan(scanName);
}
}
}
}
/**
* <p>Adds a new INewSettingsFileListener to the list of listeners to this particular plugin.
* If the listener already exists then ignor.
* @param INewSettingsFileListener a new listener
*/
public void addNewSettingsFileListener(INewSettingsFileListener newSettingsFileListener) {
if (newSettingsFileListeners == null) {
this.newSettingsFileListeners = new ArrayList<INewSettingsFileListener>(2);
}
synchronized (newSettingsFileListeners) {
if (!newSettingsFileListeners.contains(newSettingsFileListener)) {
newSettingsFileListeners.add(newSettingsFileListener);
}
}
}
/**
* <p>Removes a INewSettingsFileListener.
* <br>If the listener does not exist in the list of listeners then ignor it.
*/
public void removeNewSettingsFileListener(INewSettingsFileListener newSettingsFileListener) {
if (newSettingsFileListeners != null) {
synchronized (newSettingsFileListeners) {
if (newSettingsFileListeners.contains(newSettingsFileListener)) {
newSettingsFileListeners.remove(newSettingsFileListener);
}
if (newSettingsFileListeners.isEmpty()) {
newSettingsFileListeners = null;
}
}
}
}
/**
* Notifies listeners that a new settings file has been created.
*/
public void notifyNewSettingsFileListeners(String fileName) {
if (newSettingsFileListeners != null) {
synchronized (newSettingsFileListeners) {
Iterator<INewSettingsFileListener> listenerIterator = newSettingsFileListeners.iterator();
while (listenerIterator.hasNext()) {
listenerIterator.next().newFile(fileName);
}
}
}
}
}
......@@ -25,6 +25,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import fr.ill.ics.bridge.ResourceManager;
import fr.ill.ics.bridge.command.ICommandBoxSyncEventListener;
import fr.ill.ics.bridge.command.ICommandZoneSyncEventListener;
......@@ -542,6 +543,17 @@ public class CommandZoneSyncEventClient {
else if (event instanceof MoveCommandBoxToEnd) {
notifyMoveCommandBoxToEnd((MoveCommandBoxToEnd)event);
}
else if (event instanceof NewFile) {
NewFile newFileEvent = ((NewFile)event);
switch (newFileEvent.getFileType()) {
case ResourceManager.SCRIPT_FILE:
CommandZoneFileSync.getInstance().notifyNewScanListeners(newFileEvent.getFileName());
break;
case ResourceManager.SETTINGS_FILE:
CommandZoneFileSync.getInstance().notifyNewSettingsFileListeners(newFileEvent.getFileName());
break;
}
}
}
}
......
......@@ -362,6 +362,14 @@ public class CommandZoneSyncEventNotifier {
return new RemoveForLoopLine(request.getCommandBoxID(), request.getLineIndex());
}
}
else if (type == CommandZoneRequests.Message.Type.SaveFile) {
CommandZoneRequests.SaveFileRequest request = CommandZoneRequests.SaveFileRequest.parseFrom(message.getSerializedContent());
// Notify only if it is the same client that was the originator of the request.
if (request.getClientID() != getClientID()) {
return new NewFile(request.getFileName(), request.getFileType());
}
}
else {
System.out.println("Unable to process command zone sync message of type " + type);
}
......
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.nscclient.notification.commandzone.sync;
public interface INewScanListener {
public void newScan(String scanName);
}
\ No newline at end of file
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.nscclient.notification.commandzone.sync;
public interface INewSettingsFileListener {
public void newFile(String fileName);
}
\ No newline at end of file
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.nscclient.notification.commandzone.sync;
/**
*
*
* @author ortizh
*/
public class NewFile implements ICommandZoneSyncEvent {
private int fileType;
private String fileName;
public NewFile(String fileName, int fileType) {
super();
this.fileType = fileType;
this.fileName = fileName;
}
public int getFileType() {
return fileType;
}
public String getFileName() {
return fileName;
}
}
\ No newline at end of file
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