Skip to content
Snippets Groups Projects
Commit eb338b48 authored by Gwenaelle ABEILLE's avatar Gwenaelle ABEILLE
Browse files

migration to JTango

parent e07f8186
Branches
Tags
No related merge requests found
package org.tango.archiving.server.manager; package org.tango.archiving.server.manager;
import fr.esrf.Tango.DevFailed; import fr.esrf.Tango.DevFailed;
import fr.esrf.Tango.ErrSeverity;
import fr.soleil.archiving.common.api.ConnectionFactory; import fr.soleil.archiving.common.api.ConnectionFactory;
import fr.soleil.archiving.common.api.exception.ArchivingException; import fr.soleil.archiving.common.api.exception.ArchivingException;
import fr.soleil.archiving.common.api.tools.GlobalConst;
import fr.soleil.archiving.hdbtdb.api.ConfigConst; import fr.soleil.archiving.hdbtdb.api.ConfigConst;
import fr.soleil.archiving.hdbtdb.api.HdbTdbConnectionParameters;
import fr.soleil.archiving.hdbtdb.api.manager.ArchivingManagerApiRefFactory; import fr.soleil.archiving.hdbtdb.api.manager.ArchivingManagerApiRefFactory;
import fr.soleil.archiving.hdbtdb.api.manager.IArchivingManagerApiRef; import fr.soleil.archiving.hdbtdb.api.manager.IArchivingManagerApiRef;
import fr.soleil.archiving.hdbtdb.api.tools.ArchivingMessConfig; import fr.soleil.archiving.hdbtdb.api.tools.ArchivingMessConfig;
import fr.soleil.archiving.hdbtdb.api.tools.mode.Mode; import fr.soleil.archiving.hdbtdb.api.tools.mode.Mode;
import fr.soleil.database.connection.AbstractDataBaseConnector; import fr.soleil.database.connection.AbstractDataBaseConnector;
import fr.soleil.database.connection.DataBaseParameters;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.tango.DeviceState; import org.tango.DeviceState;
import org.tango.server.ServerManager; import org.tango.server.ServerManager;
import org.tango.server.annotation.*; import org.tango.server.annotation.*;
import org.tango.utils.DevFailedUtils;
import java.util.Arrays; import java.util.Arrays;
import java.util.ResourceBundle; import java.util.ResourceBundle;
...@@ -92,13 +89,13 @@ public class ArchivingManager { ...@@ -92,13 +89,13 @@ public class ArchivingManager {
* <b>Default value : </b> hdb * <b>Default value : </b> hdb
*/ */
@DeviceProperty @DeviceProperty
private String hdbHost; private String hdbHost = "";
/** /**
* Database name.<br> * Database name.<br>
* <b>Default value : </b> hdb * <b>Default value : </b> hdb
*/ */
@DeviceProperty @DeviceProperty
private String hdbName; private String hdbName = "";
/** /**
* Computer identifier on wich is settled the database TDB. The identifier * Computer identifier on wich is settled the database TDB. The identifier
...@@ -106,34 +103,34 @@ public class ArchivingManager { ...@@ -106,34 +103,34 @@ public class ArchivingManager {
* <b>Default value : </b> tdb * <b>Default value : </b> tdb
*/ */
@DeviceProperty @DeviceProperty
private String tdbHost; private String tdbHost = "";
/** /**
* Database name.<br> * Database name.<br>
* <b>Default value : </b> tdb * <b>Default value : </b> tdb
*/ */
@DeviceProperty @DeviceProperty
private String tdbName; private String tdbName = "";
/** /**
* User identifier (name) used to connect the historical database. * User identifier (name) used to connect the historical database.
*/ */
@DeviceProperty @DeviceProperty
private String hdbUser; private String hdbUser = "";
/** /**
* Password used to connect the historical database. * Password used to connect the historical database.
*/ */
@DeviceProperty @DeviceProperty
private String hdbPassword; private String hdbPassword = "";
/** /**
* User identifier (name) used to connect the temporary database. * User identifier (name) used to connect the temporary database.
*/ */
@DeviceProperty @DeviceProperty
private String tdbUser; private String tdbUser = "";
/** /**
* Password used to connect the temporary database. * Password used to connect the temporary database.
*/ */
@DeviceProperty @DeviceProperty
private String tdbPassword; private String tdbPassword = "";
/** /**
* true if the ORACLE RAC connection is activated. This information is * true if the ORACLE RAC connection is activated. This information is
* appended to all device's (or attributes) name. false otherwise.<br> * appended to all device's (or attributes) name. false otherwise.<br>
...@@ -144,15 +141,17 @@ public class ArchivingManager { ...@@ -144,15 +141,17 @@ public class ArchivingManager {
@DeviceProperty @DeviceProperty
private boolean tdbRacConnection; private boolean tdbRacConnection;
@DeviceProperty @DeviceProperty
private String hdbSchema; private String hdbSchema = "";
@DeviceProperty @DeviceProperty
private String tdbSchema; private String tdbSchema = "";
@State @State
private DeviceState state; private DeviceState state;
@Status @Status
private String status; private String status;
private static String VERSION; private static String VERSION;
private boolean hdbRacOverride = false;
private boolean tdbRacOverride = false;
public static void main(final String[] args) { public static void main(final String[] args) {
VERSION = ResourceBundle.getBundle("application").getString("project.version"); VERSION = ResourceBundle.getBundle("application").getString("project.version");
...@@ -174,11 +173,25 @@ public class ArchivingManager { ...@@ -174,11 +173,25 @@ public class ArchivingManager {
} }
private void connectHdb() throws DevFailed { private void connectHdb() throws DevFailed {
AbstractDataBaseConnector hdbConnector = ConnectionFactory.connectThroughTango("HdbManager",
ConfigConst.HDB_CLASS_DEVICE, hdbHost, hdbName, hdbSchema, hdbUser, hdbPassword, null, null, final DataBaseParameters params = new DataBaseParameters();
hdbRacConnection, false, true); // get default value from class properties of HDBArchiver
hdbManager = ArchivingManagerApiRefFactory.getInstance(true, hdbConnector); params.setParametersFromTango(ConfigConst.HDB_CLASS_DEVICE);
if (!hdbHost.isEmpty())
params.setHost(hdbHost);
if (!hdbUser.isEmpty())
params.setUser(hdbUser);
if (!hdbPassword.isEmpty())
params.setPassword(hdbPassword);
if (!hdbName.isEmpty())
params.setName(hdbName);
if (!hdbSchema.isEmpty())
params.setSchema(hdbSchema);
if (hdbRacOverride)
params.setRac(hdbRacConnection);
try { try {
final AbstractDataBaseConnector hdbConnector = ConnectionFactory.connect(params);
hdbManager = ArchivingManagerApiRefFactory.getInstance(true, hdbConnector);
hdbManager.archivingConfigure(); hdbManager.archivingConfigure();
} catch (ArchivingException e) { } catch (ArchivingException e) {
throw e.toTangoException(); throw e.toTangoException();
...@@ -186,11 +199,23 @@ public class ArchivingManager { ...@@ -186,11 +199,23 @@ public class ArchivingManager {
} }
protected void connectTdb() throws DevFailed { protected void connectTdb() throws DevFailed {
AbstractDataBaseConnector tdbConnector = ConnectionFactory.connectThroughTango("TdbManager", final DataBaseParameters params = new DataBaseParameters();
ConfigConst.TDB_CLASS_DEVICE, tdbHost, tdbName, tdbSchema, tdbUser, tdbPassword, null, null, params.setParametersFromTango(ConfigConst.TDB_CLASS_DEVICE);
tdbRacConnection, false, true); if (!tdbHost.isEmpty())
tdbManager = ArchivingManagerApiRefFactory.getInstance(false, tdbConnector); params.setHost(tdbHost);
if (!tdbUser.isEmpty())
params.setUser(tdbUser);
if (!tdbPassword.isEmpty())
params.setPassword(tdbPassword);
if (!tdbName.isEmpty())
params.setName(tdbName);
if (!tdbSchema.isEmpty())
params.setSchema(tdbSchema);
if (tdbRacOverride)
params.setRac(tdbRacConnection);
try { try {
final AbstractDataBaseConnector connector = ConnectionFactory.connect(params);
tdbManager = ArchivingManagerApiRefFactory.getInstance(false, connector);
tdbManager.archivingConfigure(); tdbManager.archivingConfigure();
} catch (ArchivingException e) { } catch (ArchivingException e) {
throw e.toTangoException(); throw e.toTangoException();
...@@ -203,37 +228,30 @@ public class ArchivingManager { ...@@ -203,37 +228,30 @@ public class ArchivingManager {
try { try {
connectHdb(); connectHdb();
isHdbOK = true; isHdbOK = true;
statusBuilder.append("- HDB Archivers: ").append(Arrays.toString(hdbManager.getMExportedArchiverList()))
.append("\n");
} catch (DevFailed e) { } catch (DevFailed e) {
isHdbOK = false; isHdbOK = false;
statusBuilder.append("HDB connection failed: ").append(DevFailedUtils.toString(e)).append("\n"); statusBuilder.append("- HDB is not available").append("\n");
} }
System.out.println("connect HDB "+isHdbOK );
boolean isTdbOK; boolean isTdbOK;
try { try {
connectTdb(); connectTdb();
isTdbOK = true; isTdbOK = true;
statusBuilder.append("- TDB Archivers: ").append(Arrays.toString(tdbManager.getMExportedArchiverList()))
.append("\n");
} catch (DevFailed e) { } catch (DevFailed e) {
isTdbOK = false; isTdbOK = false;
statusBuilder.append("TDB connection failed: ").append(DevFailedUtils.toString(e)).append("\n"); statusBuilder.append("- TDB is not available").append("\n");
} }
System.out.println("connect TDB "+isTdbOK );
if (!isHdbOK || !isTdbOK) {
state = DeviceState.ALARM;
} else {
state = DeviceState.ON; state = DeviceState.ON;
System.out.println(hdbManager);
System.out.println(tdbManager);
statusBuilder.append("HDB Archivers: ").append(Arrays.toString(hdbManager.getMExportedArchiverList()))
.append("\n");
statusBuilder.append("TDB Archivers: ").append(Arrays.toString(tdbManager.getMExportedArchiverList()))
.append("\n");
}
status = statusBuilder.toString(); status = statusBuilder.toString();
} }
@Init @Init
public void init() throws DevFailed, ArchivingException { public void init() throws DevFailed, ArchivingException {
HdbTdbConnectionParameters.initDbAvailable(); hdbRacOverride = false;
tdbRacOverride = false;
connect(); connect();
} }
...@@ -245,120 +263,6 @@ public class ArchivingManager { ...@@ -245,120 +263,6 @@ public class ArchivingManager {
this.status = status; this.status = status;
} }
/**
* Execute command "ArchivingConfigure" on device. This command configures
* the connection to the historical and temporary databases. It then needs 4
* parameters : a login and password for Hdb + a login and password for Tdb
*
* @param argin <ul>
* <li><var>argin</var>[<code>0</code>], the <em>user name</em> used to logg into the historical
* database.
* <li><var>argin</var>[<code>1</code>], the <em>password</em> used to logg into the historical database.
* <li><var>argin</var>[<code>2</code>], the <em>user name</em> used to logg into the temporary database.
* <li><var>argin</var>[<code>9</code>], the <em>password</em> used to logg into the temporary database.
* </ul>
*/
@Command(name = "ArchivingConfigure")
public void archivingConfigure(final String[] argin) throws DevFailed {
logger.info("Entering archiving_configure()");
String exitMessage = "Exiting archiving_configure()";
if ((argin == null) || (argin.length < 4)) {
String errorMessage = "Invalid argument";
logger.warn(errorMessage);
logger.info(exitMessage);
throw new DevFailed(errorMessage, null);
} else {
// ---Add your Own code to control device here ---
/*
* try { ArchivingManagerApi.ArchivingConfigure(argin[ 0 ] , argin[ 1 ]
* , argin[ 2 ] , argin[ 3 ], argin[ 4 ]); } catch ( ArchivingException
* e ) { get_logger().warn(e.toString() , e); throw
* e.toTangoException(); }
*/
boolean needsToThrow = false;
// TODO maybe update status, and maybe avoid connections to undesired database (HdbTdbConnectionParameters)
ArchivingException hdbArchivingException = null;
IArchivingManagerApiRef previousHdbManager = hdbManager;
try {
String hdbUser = argin[0], hdbPassword = argin[1];
AbstractDataBaseConnector hdbConnector = ConnectionFactory.connectThroughTango("HdbManager",
ConfigConst.HDB_CLASS_DEVICE, hdbHost, hdbName, hdbSchema, hdbUser, hdbPassword, null, null,
hdbRacConnection, false, true);
hdbManager = ArchivingManagerApiRefFactory.getInstance(true, hdbConnector);
hdbManager.archivingConfigure();
} catch (final ArchivingException e) {
logger.warn(e.toString(), e);
// throw e.toTangoException(); CLA 30/10/06 AN EXCEPTION IS NO
// LONGER THROWN, AS BOTH DATABASES ARE INITIALIZED INDEPENDENTLY
hdbArchivingException = e;
needsToThrow = true;
// restore previous manager as this one does not seem to be ok
hdbManager = previousHdbManager;
} catch (DevFailed e) {
logger.warn(DevFailedUtils.toString(e), e);
hdbArchivingException = new ArchivingException(e);
needsToThrow = true;
// restore previous manager as this one does not seem to be ok
hdbManager = previousHdbManager;
}
ArchivingException tdbArchivingException = null;
IArchivingManagerApiRef previousTdbManager = tdbManager;
try {
String tdbUser = argin[2], tdbPassword = argin[3];
AbstractDataBaseConnector tdbConnector = ConnectionFactory.connectThroughTango("TdbManager",
ConfigConst.TDB_CLASS_DEVICE, tdbHost, tdbName, tdbSchema, tdbUser, tdbPassword, null, null,
tdbRacConnection, false, false);
tdbManager = ArchivingManagerApiRefFactory.getInstance(true, tdbConnector);
tdbManager.archivingConfigure();
} catch (final ArchivingException e) {
logger.warn(e.toString(), e);
// throw e.toTangoException(); CLA 30/10/06 AN EXCEPTION IS NO
// LONGER THROWN, AS BOTH DATABASES ARE INITIALIZED INDEPENDENTLY
tdbArchivingException = e;
needsToThrow = true;
// restore previous manager as this one does not seem to be ok
tdbManager = previousTdbManager;
} catch (DevFailed e) {
logger.warn(DevFailedUtils.toString(e), e);
tdbArchivingException = new ArchivingException(e);
needsToThrow = true;
// restore previous manager as this one does not seem to be ok
tdbManager = previousTdbManager;
}
/*
* if ( hdbArchivingException != null ) { String desc =
* "Failed connecting to HDB"; ArchivingException exceptionHDB = new
* ArchivingException (message , reason , ErrSeverity.PANIC , desc , ""
* ); totale.addStack ( desc, exceptionHDB ); } if (
* tdbArchivingException != null ) { String desc =
* "Failed connecting to TDB"; ArchivingException exceptionTDB = new
* ArchivingException (message , reason , ErrSeverity.PANIC , desc , ""
* ); totale.addStack ( desc, exceptionTDB ); }
*/
String desc;
if (hdbArchivingException != null) {
if (tdbArchivingException != null) {
desc = "Failed connecting to HDB and TDB";
} else {
desc = "Failed connecting to HDB";
}
} else if (tdbArchivingException != null) {
desc = "Failed connecting to TDB";
} else {
desc = "";
}
logger.info(exitMessage);
if (needsToThrow) {
final String reason = "Failed while executing ArchivingManager.archiving_configure() method...";
final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : ";
final ArchivingException e = new ArchivingException(message, reason, ErrSeverity.PANIC, desc, "");
throw e.toTangoException();
}
}
}
/** /**
* Execute command "ArchivingStartHdb" on device. Start an historical * Execute command "ArchivingStartHdb" on device. Start an historical
* archiving for the specified attributes, and following the specified mode. * archiving for the specified attributes, and following the specified mode.
...@@ -1029,10 +933,12 @@ public class ArchivingManager { ...@@ -1029,10 +933,12 @@ public class ArchivingManager {
} }
public void setHdbRacConnection(boolean hdbRacConnection) { public void setHdbRacConnection(boolean hdbRacConnection) {
hdbRacOverride = true;
this.hdbRacConnection = hdbRacConnection; this.hdbRacConnection = hdbRacConnection;
} }
public void setTdbRacConnection(boolean tdbRacConnection) { public void setTdbRacConnection(boolean tdbRacConnection) {
tdbRacOverride = true;
this.tdbRacConnection = tdbRacConnection; this.tdbRacConnection = tdbRacConnection;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment