use of alma.alarmsystem.Category in project ACS by ACS-Community.
the class CategoryClient method convertAlarmType.
/**
* Convert a CORBA alarm into a client alarm.
*
* @param alarm The CORBA alarm
* @return the client alarm
*/
private Alarm convertAlarmType(alma.alarmsystem.Alarm alarm) {
Source source = new Source();
Building building = new Building(alarm.alarmLocation.buildingNb, alarm.alarmLocation.site, alarm.alarmLocation.zone, alarm.alarmLocation.map);
Location location = new Location(alarm.alarmLocation.locationId, alarm.alarmLocation.floor, alarm.alarmLocation.mnemonic, alarm.alarmLocation.position, alarm.alarmLocation.room);
location.setBuilding(building);
ResponsiblePerson responsiblePerson = new ResponsiblePerson(alarm.alarmResponsiblePerson.responsibleId, alarm.alarmResponsiblePerson.familyName, alarm.alarmResponsiblePerson.firstName, alarm.alarmResponsiblePerson.eMail, alarm.alarmResponsiblePerson.gsmNumber, alarm.alarmResponsiblePerson.phoneNumber);
Properties userProperties = new Properties();
for (org.omg.CosPropertyService.Property prop : alarm.alarmStatus.userProperties) {
userProperties.put(prop.property_name, prop.property_value);
}
Status status = new StatusImpl(Boolean.valueOf(alarm.alarmStatus.active), Boolean.valueOf(alarm.alarmStatus.masked), Boolean.valueOf(alarm.alarmStatus.reduced), Boolean.FALSE, Boolean.FALSE, alarm.alarmStatus.sourceHostname, new Timestamp(alarm.alarmStatus.sourceTimestamp.miliseconds), new Timestamp(alarm.alarmStatus.userTimestamp.miliseconds), new Timestamp(alarm.alarmStatus.systemTimestamp.miliseconds), userProperties);
Triplet triplet = new Triplet(alarm.alarmTriplet.faultFamily, alarm.alarmTriplet.faultMember, alarm.alarmTriplet.faultCode);
Set<cern.laser.business.data.Category> categories = new HashSet<cern.laser.business.data.Category>();
for (Category cat : alarm.categories) {
CategoryImpl catImpl = new CategoryImpl(cat.categoryId, cat.name, cat.description, cat.path, cat.leaf);
categories.add(catImpl);
}
cern.laser.business.data.Alarm businessAlarm = new AlarmImpl(alarm.alarmId, alarm.systemName, alarm.identifier, alarm.problemDescription, Integer.valueOf(alarm.priority), alarm.cause, alarm.action, alarm.consequence, alarm.piquetGSM, alarm.piquetEmail, alarm.helpURL, Boolean.valueOf(alarm.instant), source, location, responsiblePerson, categories, status, triplet, alarm.nodeParent, alarm.multiplicityParent, alarm.nodeChild, alarm.multiplicityChild);
Alarm ret = new cern.laser.client.impl.data.AlarmImpl(businessAlarm);
return ret;
}
use of alma.alarmsystem.Category in project ACS by ACS-Community.
the class TestAlarmService method testGetCategories.
/**
* Test AlarmSerrvice's getCategories
*
* @throws Exception
*/
public void testGetCategories() throws Exception {
Category[] categories = alarmService.getCategories();
assertNotNull(categories);
// CAT1, CAT2 and ROOT
assertEquals(3, categories.length);
for (Category cat : categories) {
if (!cat.name.equals("ROOT") && !cat.name.equals("CATEGORY1") && !cat.name.equals("CATEGORY2")) {
throw new Exception("Inavlid name of category: " + cat.name);
}
assertEquals(cat.name, cat.path);
}
}
use of alma.alarmsystem.Category in project ACS by ACS-Community.
the class CategoryClient method addCategories.
/**
* Add the categories to the configuration i.e. add the categories
* the client wants to listen to
*
* @param config The Configuration
* @param categories The categories to listen to
* If it is null, it adds all the categories returned
* by the alarm system component
* @throws Exception
*/
private void addCategories(Configuration config, Category[] categories) throws Exception {
if (categories == null) {
categories = alarm.getCategories();
}
if (categories.length == 0) {
logger.log(AcsLogLevel.WARNING, "No categories to connect to");
return;
}
Selection selection = config.getSelection();
CategorySelection catSel = selection.createCategorySelection();
for (Category cat : categories) {
cern.laser.business.data.CategoryImpl businessCategory = new cern.laser.business.data.CategoryImpl(cat.categoryId, cat.name, cat.description, cat.path, cat.leaf);
cern.laser.client.impl.data.CategoryImpl cImpl = new cern.laser.client.impl.data.CategoryImpl(businessCategory);
catSel.add(cImpl);
}
selection.setCategorySelection(catSel);
}
use of alma.alarmsystem.Category in project ACS by ACS-Community.
the class LaserComponent method fromBusinessCategoryCollection.
/**
* Helper method.
* @param categories
* @return
*/
private static Category[] fromBusinessCategoryCollection(Collection categories) {
if (categories == null)
return new Category[0];
Category[] retVal = new Category[categories.size()];
int pos = 0;
for (Iterator iter = categories.iterator(); iter.hasNext(); ) {
cern.laser.business.data.Category category = (cern.laser.business.data.Category) iter.next();
retVal[pos++] = fromBusinessCategory(category);
}
return retVal;
}
use of alma.alarmsystem.Category in project ACS by ACS-Community.
the class CategoryClient method connect.
/**
* Create the consumers for the passed categories
*
*
* @param categoriesToConnect The categories to connect to
*/
public void connect(Category[] categoriesToConnect) throws Exception {
if (categoriesToConnect == null || categoriesToConnect.length == 0) {
contSvc.getLogger().log(AcsLogLevel.INFO, "No categories to connect to");
return;
}
consumers = new CategorySubscriber[categoriesToConnect.length];
int t = 0;
Vector<String> failingConnections = new Vector<String>();
for (Category category : categoriesToConnect) {
try {
consumers[t++] = new CategorySubscriber(contSvc, categoryRootTopic, category.path, this);
contSvc.getLogger().log(AcsLogLevel.DEBUG, "Connected to " + categoryRootTopic + "." + category.path);
} catch (Throwable throwable) {
failingConnections.add("Error subscribing to " + categoryRootTopic + "." + category.path + ": " + throwable.getMessage());
}
}
if (failingConnections.size() > 0) {
System.err.println("Error connecting categories: ");
for (String str : failingConnections) {
System.err.println("\t" + str);
}
throw new Exception("Error connecting categories");
}
}
Aggregations