Skip to content
Snippets Groups Projects
Commit b70eff71 authored by Pascal Verdier's avatar Pascal Verdier
Browse files

First tests done

parent bd40a572
No related branches found
No related merge requests found
.idea
target
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.tango:JTangoServer:9.2.7" level="project" />
<orderEntry type="library" name="Maven: org.jacorb:jacorb:3.8" level="project" />
<orderEntry type="library" name="Maven: org.jacorb:jacorb-omgapi:3.8" level="project" />
<orderEntry type="library" name="Maven: org.jacorb:jacorb-services:3.8" level="project" />
<orderEntry type="library" name="Maven: antlr:antlr:2.7.2" level="project" />
<orderEntry type="library" name="Maven: mx4j:mx4j:3.0.1" level="project" />
<orderEntry type="library" name="Maven: nanocontainer:nanocontainer-remoting:1.0-RC-1" level="project" />
<orderEntry type="library" name="Maven: geronimo-spec:geronimo-spec-ejb:2.1-rc2" level="project" />
<orderEntry type="library" name="Maven: mx4j:mx4j-jmx:2.1.1" level="project" />
<orderEntry type="library" name="Maven: mx4j:mx4j-impl:2.1.1" level="project" />
<orderEntry type="library" name="Maven: jmock:jmock:1.0.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit:3.8.1" level="project" />
<orderEntry type="library" name="Maven: jmock:jmock-cglib:1.0.1" level="project" />
<orderEntry type="library" name="Maven: cglib:cglib-full:2.0" level="project" />
<orderEntry type="library" name="Maven: proxytoys:proxytoys:0.1" level="project" />
<orderEntry type="library" name="Maven: org.beanshell:bsh:2.0b5" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.14" level="project" />
<orderEntry type="library" name="Maven: picocontainer:picocontainer:1.2" level="project" />
<orderEntry type="library" name="Maven: tanukisoft:wrapper:3.1.0" level="project" />
<orderEntry type="library" name="Maven: org.tango:JTangoCommons:9.2.7" level="project" />
<orderEntry type="library" name="Maven: org.tango:TangORB:9.2.7" level="project" />
<orderEntry type="library" name="Maven: org.zeromq:jeromq:0.3.4" level="project" />
<orderEntry type="library" name="Maven: org.tango:TangORB-javacommon:9.2.7" level="project" />
<orderEntry type="library" name="Maven: org.tango:JavaTangoIDL:9.2.7" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.4" level="project" />
<orderEntry type="library" name="Maven: org.tango:JTangoClientLang:9.2.7" level="project" />
<orderEntry type="library" name="Maven: org.mozilla:rhino:1.7.7.1" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.1.1" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.1.1" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-ext:1.6.4" level="project" />
<orderEntry type="library" name="Maven: ch.qos.cal10n:cal10n-api:0.7.4" level="project" />
<orderEntry type="library" name="Maven: net.sf.transmorph:transmorph:3.1.3" level="project" />
<orderEntry type="library" name="Maven: net.sf.ehcache:ehcache-core:2.3.0" level="project" />
<orderEntry type="library" name="Maven: org.quartz-scheduler:quartz:2.2.1" level="project" />
<orderEntry type="library" name="Maven: c3p0:c3p0:0.9.1.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.2" level="project" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="ASCII"?>
<pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://www.esrf.fr/tango/pogo/PogoDsl">
<classes name="HdbAttributeCheck" pogoRevision="9.6">
<description description="This class is able to control an attribute list.&#xA;Its state will be fault if one of these attributes is faulty." title="HDB++ attribute check" sourcePath="/mntdirect/_segfs/tango/jserver/HdbAttributeCheck/src/main/java" language="Java" filestogenerate="XMI file,Code files,Protected Regions,pom.xml" license="GPL" copyright="Copyright (C): 2018&#xA; European Synchrotron Radiation Facility&#xA; BP 220, Grenoble 38043&#xA; France" hasMandatoryProperty="true" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<description description="This class is able to control an attribute list.&#xA;Its state will be fault if one of these attributes is faulty." title="HDB++ attribute check" sourcePath="/mntdirect/_segfs/tango/jserver/HdbAttributeCheck/src/main/java" language="Java" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="Copyright (C): 2018&#xA; European Synchrotron Radiation Facility&#xA; BP 220, Grenoble 38043&#xA; France" hasMandatoryProperty="true" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<inheritances classname="Device_Impl" sourcePath=""/>
<identification contact="at esrf.fr - accelerator-control" author="accelerator-control" emailDomain="esrf.fr" classFamily="System" siteSpecific="" platform="All Platforms" bus="Not Applicable" manufacturer="none" reference=""/>
</description>
<deviceProperties name="AttributeList" mandatory="true" description="Attribute list to be checked">
<type xsi:type="pogoDsl:StringVectorType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</deviceProperties>
<deviceProperties name="ConfiguratorManager" mandatory="true" description="HDB++ Configurator manager device name.">
<type xsi:type="pogoDsl:StringType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</deviceProperties>
......@@ -27,6 +31,18 @@
</argout>
<status abstract="true" inherited="true" concrete="true" concreteHere="false"/>
</commands>
<states name="ON" description="All attributes are OK">
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</states>
<states name="ALARM" description="At least one checked attribute is faulty">
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</states>
<states name="UNKNOWN" description="At least one event subscriber is not responding">
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</states>
<states name="FAULT" description="Reading attribute AttributeErrorList on event subscriber failed.">
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</states>
<preferences docHome="./doc_html" makefileHome="/segfs/tango/cppserver/env"/>
</classes>
</pogoDsl:PogoSystem>
......@@ -42,41 +42,19 @@
package org.tango.hdbattributecheck;
/*----- PROTECTED REGION ID(HdbAttributeCheck.imports) ENABLED START -----*/
import fr.esrf.Tango.DevFailed;
import fr.esrf.Tango.DevState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
import org.tango.DeviceState;
import org.tango.server.InvocationContext;
import org.tango.server.ServerManager;
import org.tango.server.annotation.AroundInvoke;
import org.tango.server.annotation.Attribute;
import org.tango.server.annotation.AttributeProperties;
import org.tango.server.annotation.ClassProperty;
import org.tango.server.annotation.Command;
import org.tango.server.annotation.Delete;
import org.tango.server.annotation.Device;
import org.tango.server.annotation.DeviceProperty;
import org.tango.server.annotation.DynamicManagement;
import org.tango.server.annotation.Init;
import org.tango.server.annotation.State;
import org.tango.server.annotation.StateMachine;
import org.tango.server.annotation.Status;
import org.tango.server.annotation.DeviceManagement;
import org.tango.server.annotation.Pipe;
import org.tango.server.attribute.ForwardedAttribute;import org.tango.server.pipe.PipeValue;
import org.tango.server.dynamic.DynamicManager;
import org.tango.server.annotation.*;
import org.tango.server.device.DeviceManager;
import org.tango.server.dynamic.DynamicManager;
import org.tango.server.events.EventManager;
import org.tango.server.events.EventType;
import org.tango.utils.DevFailedUtils;
// Import Tango IDL types
import fr.esrf.Tango.*;
import fr.esrf.TangoDs.Except;
import fr.esrf.TangoApi.PipeBlob;
import fr.esrf.TangoApi.PipeDataElement;
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.imports
......@@ -101,7 +79,7 @@ public class HdbAttributeCheck {
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.variables
/*----- PROTECTED REGION ID(HdbAttributeCheck.private) ENABLED START -----*/
// Put private variables here
private SubscriberList subscriberList;
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.private
......@@ -113,12 +91,12 @@ public class HdbAttributeCheck {
* Attribute list to be checked
*/
@DeviceProperty(name="AttributeList", description="Attribute list to be checked" , isMandatory=true)
private String attributeList;
private String[] attributeList;
/**
* set property AttributeList
* @param attributeList see description above.
*/
public void setAttributeList(String attributeList) {
public void setAttributeList(String[] attributeList) {
this.attributeList = attributeList;
/*----- PROTECTED REGION ID(HdbAttributeCheck.setAttributeList) ENABLED START -----*/
......@@ -127,6 +105,25 @@ public class HdbAttributeCheck {
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.setAttributeList
}
/**
* Device Property ConfiguratorManager
* HDB++ Configurator manager device name.
*/
@DeviceProperty(name="ConfiguratorManager", description="HDB++ Configurator manager device name." , isMandatory=true)
private String configuratorManager;
/**
* set property ConfiguratorManager
* @param configuratorManager see description above.
*/
public void setConfiguratorManager(String configuratorManager) {
this.configuratorManager = configuratorManager;
/*----- PROTECTED REGION ID(HdbAttributeCheck.setConfiguratorManager) ENABLED START -----*/
// Check property value here
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.setConfiguratorManager
}
//========================================================
......@@ -143,8 +140,17 @@ public class HdbAttributeCheck {
logger.debug("init device " + deviceManager.getName());
/*----- PROTECTED REGION ID(HdbAttributeCheck.initDevice) ENABLED START -----*/
// Put your device initialization code here
// ToDo initialization code here
System.out.println("Attribute checked");
for (String attributeName : attributeList)
System.out.println(attributeName);
subscriberList = new SubscriberList(configuratorManager, attributeList);
try { Thread.sleep(2000); } catch (InterruptedException e) { /* */ }
System.out.println("\n");
System.out.println(subscriberList);
setState(DevState.INIT);
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.initDevice
xlogger.exit();
}
......@@ -228,9 +234,7 @@ public class HdbAttributeCheck {
*/
public final DevState getState() throws DevFailed {
/*----- PROTECTED REGION ID(HdbAttributeCheck.getState) ENABLED START -----*/
// Put state code here
state = subscriberList.getState();
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.getState
return state;
}
......@@ -255,9 +259,7 @@ public class HdbAttributeCheck {
*/
public final String getStatus() throws DevFailed {
/*----- PROTECTED REGION ID(HdbAttributeCheck.getStatus) ENABLED START -----*/
// Put status code here
status = subscriberList.getStatus();
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.getStatus
return status;
}
......
//+======================================================================
// : $
//
// Project: Tango
//
// Description: java source code for Tango manager tool..
//
// : pascal_verdier $
//
// Copyright (C) : 2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This file is part of Tango.
//
// Tango 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 3 of the License, or
// (at your option) any later version.
//
// Tango 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 Tango. If not, see <http://www.gnu.org/licenses/>.
//
// : $
//
//-======================================================================
package org.tango.hdbattributecheck;
/**
* This class is able to model a checked attribute
*
* @author verdier
*/
public class ManagedAttribute {
private String attributeName;
private String error;
private int index;
private final Object monitor = new Object();
//===============================================================
//===============================================================
public ManagedAttribute(String attributeName, int index) {
this.attributeName = attributeName;
this.index = index;
}
//===============================================================
//===============================================================
public boolean hasFailed() {
synchronized (monitor) {
return error!=null;
}
}
//===============================================================
//===============================================================
public String getError() {
synchronized (monitor) {
return error;
}
}
//===============================================================
//===============================================================
public void setError(String error) {
synchronized (monitor) {
this.error = error;
}
}
//===============================================================
//===============================================================
public String getName() {
return attributeName;
}
//===============================================================
//===============================================================
public int getIndex() {
return index;
}
//===============================================================
//===============================================================
public String toString() {
return attributeName + " (" + index +
"): " + (hasFailed()? "faulty" : "OK");
}
//===============================================================
//===============================================================
}
//+======================================================================
// : $
//
// Project: Tango
//
// Description: java source code for Tango manager tool..
//
// : pascal_verdier $
//
// Copyright (C) : 2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This file is part of Tango.
//
// Tango 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 3 of the License, or
// (at your option) any later version.
//
// Tango 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 Tango. If not, see <http://www.gnu.org/licenses/>.
//
// : $
//
//-======================================================================
package org.tango.hdbattributecheck;
import fr.esrf.Tango.DevFailed;
import fr.esrf.Tango.DevState;
import fr.esrf.TangoApi.DeviceAttribute;
import fr.esrf.TangoApi.DeviceProxy;
import fr.esrf.TangoApi.events.ITangoChangeListener;
import fr.esrf.TangoApi.events.TangoChangeEvent;
import fr.esrf.TangoApi.events.TangoEventsAdapter;
import fr.esrf.TangoDs.TangoConst;
import java.util.ArrayList;
import java.util.List;
/**
* This class is able to model an event subscriber
*
* @author verdier
*/
public class Subscriber extends DeviceProxy {
private String name;
private DevState state = DevState.UNKNOWN;
private String status = "";
private List<ManagedAttribute> managedAttributeList = new ArrayList<>();
//===============================================================
//===============================================================
public Subscriber(String deviceName, String[] checkedAttributeList) throws DevFailed {
super(deviceName);
this.name = deviceName;
// Start a thread to check if manage attributes
new AttributeListThread(checkedAttributeList).start();
// Start a thread to check if device is alive
new PingThread().start();
}
//===============================================================
//===============================================================
public DevState getState() {
if (state==DevState.ON) {
for (ManagedAttribute attribute : managedAttributeList)
if (attribute.hasFailed())
return DevState.ALARM;
return DevState.ON;
}
return state;
}
//===============================================================
//===============================================================
public String getStatus() {
StringBuilder sb = new StringBuilder(status+'\n');
for (ManagedAttribute attribute : managedAttributeList) {
if (attribute.hasFailed()) {
sb.append(attribute.getName()).append(": ").append(attribute.getError()).append('\n');
}
}
return sb.toString().trim();
}
//===============================================================
//===============================================================
public boolean manageAttributes() {
return !managedAttributeList.isEmpty();
}
//===============================================================
//===============================================================
private void subscribeEvents() {
try {
TangoEventsAdapter stateAdapter = new TangoEventsAdapter(this);
stateAdapter.addTangoChangeListener(
new AttributeStateChangeListener(),"AttributeErrorList", TangoConst.STATELESS);
}
catch (DevFailed e) {
state = DevState.FAULT;
status = name + ": " + e.errors[0].desc;
}
}
//===============================================================
//===============================================================
public String toString() {
StringBuilder sb = new StringBuilder(name + ": " + state);
for (ManagedAttribute attribute : managedAttributeList)
sb.append("\n ").append(attribute);
return sb.toString();
}
//===============================================================
//===============================================================
//===============================================================
//===============================================================
private class AttributeListThread extends Thread {
private String[] checkedAttributes;
//===========================================================
private AttributeListThread(String[] checkedAttributes) {
this.checkedAttributes = checkedAttributes;
}
//===========================================================
private void checkManageAttributes(String[] attributeList) {
for (String checkedAttribute : checkedAttributes) {
int index = 0;
for (String attribute : attributeList) {
if (attribute.equalsIgnoreCase(checkedAttribute))
managedAttributeList.add(new ManagedAttribute(checkedAttribute, index));
index++;
}
}
if (!managedAttributeList.isEmpty()) {
subscribeEvents();
}
}
//===========================================================
//===========================================================
public void run() {
String[] attributeList = null;
while (attributeList ==null) {
try {
DeviceAttribute attribute = read_attribute("AttributeList");
attributeList = attribute.extractStringArray();
checkManageAttributes(attributeList);
state = DevState.ON;
} catch (DevFailed e) {
System.err.println(name() + ": " + e.errors[0].desc);
}
}
}
//===========================================================
}
//===============================================================
//===============================================================
//===========================================================
//===========================================================
public class AttributeStateChangeListener implements ITangoChangeListener {
@Override
public void change(TangoChangeEvent event) {
try {
// Get the attribute value, name, data
DeviceAttribute attribute = event.getValue();
if (attribute.hasFailed()) {
state = DevState.FAULT;
status = attribute.getName() + " has failed";
}
else {
String[] attributeFaultyArray = attribute.extractStringArray();
for (ManagedAttribute managedAttribute : managedAttributeList) {
String error = attributeFaultyArray[managedAttribute.getIndex()];
if (error.isEmpty())
managedAttribute.setError(null);
else
managedAttribute.setError(error);
}
state = DevState.ON;
status = "";
}
}
catch (DevFailed e) {
state = DevState.UNKNOWN;
status = name + ": " + e.errors[0].desc;
}
}
}
//===========================================================
//===========================================================
//===========================================================
//===========================================================
public class PingThread extends Thread {
@Override
public void run() {
//noinspection InfiniteLoopStatement
while (true) {
try {
ping();
state = DevState.ON;
status = "";
} catch (DevFailed e) {
state = DevState.UNKNOWN;
status = name + ": " + e.errors[0].desc;
}
try { sleep(5000); } catch (InterruptedException e) { /* */ }
}
}
}
//===========================================================
//===========================================================
}
//+======================================================================
// : $
//
// Project: Tango
//
// Description: java source code for Tango manager tool..
//
// : pascal_verdier $
//
// Copyright (C) : 2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This file is part of Tango.
//
// Tango 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 3 of the License, or
// (at your option) any later version.
//
// Tango 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 Tango. If not, see <http://www.gnu.org/licenses/>.
//
// : $
//
//-======================================================================
package org.tango.hdbattributecheck;
import fr.esrf.Tango.DevFailed;
import fr.esrf.Tango.DevState;
import fr.esrf.TangoApi.DeviceAttribute;
import fr.esrf.TangoApi.DeviceProxy;
import java.util.ArrayList;
/**
* This class is able to
*
* @author verdier
*/
public class SubscriberList extends ArrayList<Subscriber> {
private DeviceProxy configuratorProxy;
//===============================================================
//===============================================================
public SubscriberList(String configuratorName, String[] checkedAttributes) throws DevFailed {
this.configuratorProxy = new DeviceProxy(configuratorName);
String[] archivers = getSubscriberNames();
for (String archiver : archivers) {
add(new Subscriber(archiver, checkedAttributes));
}
}
//===============================================================
//===============================================================
private String[] getSubscriberNames() throws DevFailed {
DeviceAttribute attribute = configuratorProxy.read_attribute("ArchiverList");
return attribute.extractStringArray();
}
//===============================================================
//===============================================================
public String getStatus() {
if (status.isEmpty())
return "Attribute storage is OK";
else
return status;
}
//===============================================================
private String status = "";
//===============================================================
public DevState getState() {
StringBuilder sb = new StringBuilder();
int nbUnknown = 0;
int nbFault = 0;
int nbAlarm = 0;
// Check state/status on each subscriber
for (Subscriber subscriber : this) {
if (subscriber.getState()==DevState.UNKNOWN) {
nbUnknown++;
sb.append(subscriber.getStatus()).append('\n');
}
else
if (subscriber.manageAttributes()){
if (subscriber.getState()==DevState.FAULT) {
nbFault++;
sb.append(subscriber.getStatus()).append('\n');
}
else
if (subscriber.getState()==DevState.ALARM) {
sb.append(subscriber.getStatus()).append('\n');
nbAlarm++;
}
}
}
status = sb.toString();
// Check what has higher priority to be returned
if (nbUnknown>0)
return DevState.UNKNOWN;
else
if (nbFault>0)
return DevState.FAULT;
else
if (nbAlarm>0)
return DevState.ALARM;
else
return DevState.ON;
}
//===============================================================
//===============================================================
public String toString() {
StringBuilder sb = new StringBuilder();
for (Subscriber subscriber : this) {
sb.append(subscriber).append('\n');
}
return sb.toString();
}
//===============================================================
//===============================================================
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment